Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
663 changes: 260 additions & 403 deletions openstudiocore/src/contam/ForwardTranslator.cpp

Large diffs are not rendered by default.

122 changes: 52 additions & 70 deletions openstudiocore/src/contam/ForwardTranslator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ class ProgressBar;

namespace contam{

/** CvFile is a container for data that is to be written to a CONTAM CVF.
*
* CvFile contains time series data that is to be written to a CONTAM
* Continuous Values File, which is documented here:
*
* www.bfrl.nist.gov/IAQanalysis/CONTAM/manual/Content/html/IDH_UsingControls_CVF.htm
*
* Data is input as TimeSeries that should cover the entire time period to
* be simulated.
*
*/
class CONTAM_API CvFile
{
public:
Expand All @@ -50,6 +61,7 @@ class CONTAM_API CvFile
Date end() const {return m_end;}
void setEnd(Date date){m_end=date;}
bool isEmpty() {return m_names.size() == 0;}
void clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasondegraw Any reason you would need this public? Can't it just be called on translateModel?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macumber I'd like to keep this one public. There are a couple of use cases where someone might want to do some different things with the file. Since we're only allowed one CVF per model, there isn't a lot of flexibility there.


private:
std::vector<std::string> m_names;
Expand All @@ -59,85 +71,56 @@ class CONTAM_API CvFile
Date m_end;
};

class CONTAM_API ForwardTranslator : public Model
/** ForwardTranslator translates an OpenStudio model into a CONTAM model.
*
* ForwardTranslator translates an OpenStudio energy model into a CONTAM
* airflow model using a streamlined approach. Each wall is assigned an
* overall leakage rate, and individual components are not presently
* represented.
*
*/
class CONTAM_API ForwardTranslator
{
public:
ForwardTranslator(const openstudio::model::Model& model, bool translateHVAC=true, ProgressBar* progressBar=NULL);
ForwardTranslator(const openstudio::model::Model& model, std::string leakageDescriptor, bool translateHVAC=true,
ProgressBar* progressBar=NULL);
ForwardTranslator(const openstudio::model::Model& model, double flow, double n, double deltaP,
bool translateHVAC=true, ProgressBar* progressBar=NULL);
ForwardTranslator(const openstudio::model::Model& model, double returnSupplyRatio, bool translateHVAC=true,
ProgressBar* progressBar=NULL);
ForwardTranslator(const openstudio::model::Model& model, double returnSupplyRatio, std::string leakageDescriptor,
bool translateHVAC=true, ProgressBar* progressBar=NULL);
ForwardTranslator(const openstudio::model::Model& model, double returnSupplyRatio, double flow, double n,
double deltaP, bool translateHVAC=true, ProgressBar* progressBar=NULL);

std::string toString();
bool toPrj(const openstudio::path& path);
ForwardTranslator();

// Clear out the translator and reset to the defaults
void clear();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasondegraw Any reason you would need this public? Can't it just be called on translateModel?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macumber I can't think of any, so I'll make it private.


// Translator
boost::optional<contam::PrjModel> translate(model::Model model);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasondegraw Nit-picky, can we rename to translateModel to match E+ translator?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macumber Yes.


// Static translation function
static bool modelToPrj(const openstudio::model::Model& model, const openstudio::path& path,
bool translateHVAC=true, std::string leakageDescriptor="Average", ProgressBar* progressBar=NULL);

// Secondary translation functions - need to add more of these by chopping out parts of the main translation function
// Secondary translation functions - this doesn't really fit here any more, so maybe it needs
// to be moved elsewhere, could be made static
boost::optional<EpwFile> translateEpw(openstudio::path epwpath, openstudio::path outpath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasondegraw Does this need to be a translator function? It seems like it is just implemented at the EpwFile level?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macumber I am not sure what to do with it. It made a lot more sense with the previous version of the object. I think we should either make it static (and keep it) or remove it. I'd vote for static, but I'll defer to you on this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasondegraw Let's remove it please.


bool ready() const {return m_ready && valid();}
// Accessors to the element maps
std::map <Handle, int> surfaceMap() const {return m_surfaceMap;}
std::map <Handle, int> zoneMap() const {return m_zoneMap;}

// Getters and setters - the setters modify how translation is done or modify the model after translation (eventually).
// Getters and setters - the setters modify how translation
// Setters that could fail return a boolean
boost::optional<std::string> airtightnessLevel() const;
bool setAirtightnessLevel(std::string level);
double exteriorFlowRate() const;
double exteriorExponent() const;
double exteriorDeltaP() const;
bool setExteriorFlowRate(double flow,double n=0.65,double deltaP=75.0);

// Getters and setters
double returnSupplyRatio() const
{
return m_returnSupplyRatio;
}
void setReturnSupplyRatio(double returnSupplyRatio)
{
m_returnSupplyRatio = fabs(returnSupplyRatio);
}

bool ratioOverride() const
{
return m_ratioOverride;
}
/*
void setRatioOverride(bool ratioOverride)
{
m_ratioOverride = ratioOverride;
}
*/

//boost::optional<EpwFile> epwFile() const
//{
// return m_epwFile;
//}

boost::optional<DateTime> startDateTime() const
{
return m_startDateTime;
}

boost::optional<DateTime> endDateTime() const
{
return m_endDateTime;
}
// Postprocessing Functions
//boost::optional<std::vector<TimeSeries> > zoneInfiltration(openstudio::path simPath);
void setAirtightnessLevel(std::string level);
boost::optional<double> exteriorFlowRate() const;
boost::optional<double> exteriorExponent() const;
boost::optional<double> exteriorDeltaP() const;
bool setExteriorFlowRate(double flow, double n, double deltaP);
double returnSupplyRatio() const;
void setReturnSupplyRatio(double returnSupplyRatio);
bool ratioOverride() const;
void setRatioOverride(bool ratioOverride);
bool translateHVAC() const;
void setTranslateHVAC(bool translateHVAC);
boost::optional<DateTime> startDateTime() const;
boost::optional<DateTime> endDateTime() const;

// We may need more functions like this that modify the CONTAM model
bool setSteadyWeather(double windSpeed, double windDirection);
int addNewAirflowElement(std::string name,double flow,double n=0.65,double deltaP=75.0);
int addNewAirflowElement(contam::PrjModel prjModel,std::string name,double flow,double n=0.65,double deltaP=75.0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasondegraw I am a little leary of this one, can this move to be a method of the PrjModel?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macumber I don't really like it either, so I don't want to move it to PrjModel. How about I keep it in ForwardTranslator, but make it private?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasondegraw private in ForwardTranslator would be great, thanks!


// Write control files
bool writeCvFile(openstudio::path filepath);
Expand All @@ -149,8 +132,8 @@ class CONTAM_API ForwardTranslator : public Model
std::vector<LogMessage> errors() const;

private:
// Translators
bool translate(bool translateHVAC=true);
bool applyExteriorFlowRate(contam::PrjModel prjModel);
bool applyAirtightnessLevel(contam::PrjModel prjModel);

// Really need to look at these and determine if they are really needed
int tableLookup(QMap<std::string,int> map, std::string str, const char *name);
Expand All @@ -159,8 +142,6 @@ class CONTAM_API ForwardTranslator : public Model
std::string reverseLookup(QMap<std::string,int> map, int nr, const char *name);
Handle reverseLookup(QMap<Handle,int> map, int nr, const char *name);

void init();

// Maps - will be populated after a call of translateToPrj
// All map to the CONTAM index (1,2,...,nElement)
std::map<std::string,int> m_afeMap; // Map from descriptor ("exterior", "floor", etc.) to CONTAM airflow element index
Expand All @@ -171,15 +152,16 @@ class CONTAM_API ForwardTranslator : public Model
std::map <Handle, int> m_surfaceMap; // Surface paths stored by handle
QMap <Handle, int> m_ahsMap; // Airloop to AHS map by handle

openstudio::model::Model m_model;
CvFile m_cvf;
//boost::optional<EpwFile> m_epwFile;
boost::optional<DateTime> m_startDateTime;
boost::optional<DateTime> m_endDateTime;
bool m_ready;
boost::optional<std::string> m_leakageDescriptor;
boost::optional<double> m_flow;
boost::optional<double> m_n;
boost::optional<double> m_deltaP;
double m_returnSupplyRatio;
bool m_ratioOverride;
bool m_translateHVAC;

ProgressBar* m_progressBar;

Expand Down
8 changes: 2 additions & 6 deletions openstudiocore/src/contam/PrjDefines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@
#define RX_IS_STRING

#ifdef RX_IS_STRING
#ifndef STD_STRING
#define RX QString
#define RX_C(v) v
#define RX_INIT(v) QString(#v)
#else
#define RX std::string
#define RX_C(v) v
#define RX_INIT(v) std::string(#v)
#endif
#endif

#define NOFILELINE

Expand Down Expand Up @@ -174,6 +168,8 @@
#define EXP_2 253 /* FD 375 exponent 2 */
#define SUB_2 254 /* FE 376 subscript 2 */

// The defines below were mainly for the ReverseTranslator object - so
// can be eliminated if that object doesn't ever come back.
// Directional icon defines: E=1, N=2, W=4, S=8
#define BIT_E 1
#define BIT_N 2
Expand Down
Loading