src/airflow/contam/ForwardTranslator.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef AIRFLOW_CONTAM_FORWARDTRANSLATOR_HPP | ||
| 7 | #define AIRFLOW_CONTAM_FORWARDTRANSLATOR_HPP | ||
| 8 | |||
| 9 | #include "../AirflowAPI.hpp" | ||
| 10 | |||
| 11 | #include "PrjModel.hpp" | ||
| 12 | #include "ContamEnums.hpp" | ||
| 13 | #include "../SurfaceNetworkBuilder.hpp" | ||
| 14 | |||
| 15 | //#include "../model/Model.hpp" | ||
| 16 | #include "../../utilities/idf/Handle.hpp" | ||
| 17 | #include "../../utilities/core/Path.hpp" | ||
| 18 | #include "../../utilities/core/Optional.hpp" | ||
| 19 | #include "../../utilities/core/Logger.hpp" | ||
| 20 | #include "../../utilities/core/StringStreamLogSink.hpp" | ||
| 21 | #include "../../utilities/data/TimeSeries.hpp" | ||
| 22 | #include "../../utilities/time/Date.hpp" | ||
| 23 | #include "../../utilities/filetypes/EpwFile.hpp" | ||
| 24 | |||
| 25 | namespace openstudio { | ||
| 26 | class ProgressBar; | ||
| 27 | namespace model { | ||
| 28 | class Model; | ||
| 29 | class Space; | ||
| 30 | class ThermalZone; | ||
| 31 | class SubSurface; | ||
| 32 | class Surface; | ||
| 33 | } // namespace model | ||
| 34 | |||
| 35 | namespace contam { | ||
| 36 | |||
| 37 | /** CvFile is a container for data that is to be written to a CONTAM CVF. | ||
| 38 | * | ||
| 39 | * CvFile contains time series data that is to be written to a CONTAM | ||
| 40 | * Continuous Values File, which is documented here: | ||
| 41 | * | ||
| 42 | * www.bfrl.nist.gov/IAQanalysis/CONTAM/manual/Content/html/IDH_UsingControls_CVF.htm | ||
| 43 | * | ||
| 44 | * Data is input as TimeSeries that should cover the entire time period to | ||
| 45 | * be simulated. TimeSeries with Celcius units will be converted to Kelvin | ||
| 46 | * on output. All other TimeSeries should be in the units CONTAM expects. | ||
| 47 | * | ||
| 48 | */ | ||
| 49 | class AIRFLOW_API CvFile | ||
| 50 | { | ||
| 51 | public: | ||
| 52 | /** Construct a new, empty object. */ | ||
| 53 | CvFile(); | ||
| 54 | /** Add a time series to the data contained in the object */ | ||
| 55 | void addTimeSeries(std::string name, TimeSeries series); | ||
| 56 | /** Write out CVF-formatted data to the specified path. */ | ||
| 57 | bool write(openstudio::path filepath); | ||
| 58 | /** Returns the start date of the data that will be written. */ | ||
| 59 | ✗ | Date start() const { | |
| 60 | ✗ | return m_start; | |
| 61 | } | ||
| 62 | /** Set the start date of the data that will be written. */ | ||
| 63 | ✗ | void setStart(Date date) { | |
| 64 | ✗ | m_start = date; | |
| 65 | ✗ | } | |
| 66 | /** Returns the end date of the data that will be written. */ | ||
| 67 | ✗ | Date end() const { | |
| 68 | ✗ | return m_end; | |
| 69 | } | ||
| 70 | /** Set the end date of the data that will be written. */ | ||
| 71 | ✗ | void setEnd(Date date) { | |
| 72 | ✗ | m_end = date; | |
| 73 | ✗ | } | |
| 74 | /** Returns true if the object has no time series. */ | ||
| 75 | ✗ | bool isEmpty() { | |
| 76 | ✗ | return m_names.empty(); | |
| 77 | } | ||
| 78 | /** Clear the object and make it empty. */ | ||
| 79 | void clear(); | ||
| 80 | |||
| 81 | private: | ||
| 82 | std::vector<std::string> m_names; | ||
| 83 | std::vector<TimeSeries> m_series; | ||
| 84 | |||
| 85 | Date m_start; | ||
| 86 | Date m_end; | ||
| 87 | }; | ||
| 88 | |||
| 89 | /** ForwardTranslator translates an OpenStudio model into a CONTAM model. | ||
| 90 | * | ||
| 91 | * ForwardTranslator translates an OpenStudio energy model into a CONTAM | ||
| 92 | * airflow model using a streamlined approach. Each wall is assigned an | ||
| 93 | * overall leakage rate and individual components are not directly represented. | ||
| 94 | * | ||
| 95 | */ | ||
| 96 | class AIRFLOW_API ForwardTranslator : public airflow::SurfaceNetworkBuilder | ||
| 97 | { | ||
| 98 | public: | ||
| 99 | /** @name Constructors and Destructors */ | ||
| 100 | //@{ | ||
| 101 | /** Construct a new, empty translator. */ | ||
| 102 | ForwardTranslator(); | ||
| 103 | /** Destroy the translator.*/ | ||
| 104 | 4 | ~ForwardTranslator() = default; | |
| 105 | |||
| 106 | //@} | ||
| 107 | /** @name Translation Functions */ | ||
| 108 | //@{ | ||
| 109 | |||
| 110 | /** Translates an OpenStudio thermal model into a CONTAM airflow model. */ | ||
| 111 | boost::optional<contam::IndexModel> translateModel(model::Model model); | ||
| 112 | |||
| 113 | /** Static translation function to translate an OpenStudio into a CONTAM airflow model and write it to a path. */ | ||
| 114 | static bool modelToPrj(const openstudio::model::Model& model, const openstudio::path& path, bool translateHVAC = true, | ||
| 115 | std::string leakageDescriptor = "Average", ProgressBar* progressBar = nullptr); | ||
| 116 | |||
| 117 | //@} | ||
| 118 | /** @name Getters and Setters */ | ||
| 119 | //@{ | ||
| 120 | |||
| 121 | /** Returns a map from the OpenStudio surface handles to the CONTAM airflow path index (which runs from 1 to the number of surfaces). */ | ||
| 122 | ✗ | std::map<Handle, int> surfaceMap() const { | |
| 123 | ✗ | return m_surfaceMap; | |
| 124 | } | ||
| 125 | /** Returns a map from the OpenStudio thermal zone handles to the CONTAM airflow zone index (which runs from 1 to the number of airflow zones). */ | ||
| 126 | 1 | std::map<Handle, int> zoneMap() const { | |
| 127 | 1 | return m_zoneMap; | |
| 128 | } | ||
| 129 | |||
| 130 | // Getters and setters - the setters modify how translation is done | ||
| 131 | // Setters that could fail return a boolean | ||
| 132 | /** Returns the airtightness level as a string if it has been set. */ | ||
| 133 | boost::optional<std::string> airtightnessLevel() const; | ||
| 134 | /** Set the airtightness level. Three levels are supported: Leaky, Average, and Tight. */ | ||
| 135 | void setAirtightnessLevel(std::string level); | ||
| 136 | /** Returns the test data flow rate of envelope flow paths if it has been set. */ | ||
| 137 | boost::optional<double> exteriorFlowRate() const; | ||
| 138 | /** Returns the test data flow exponent of envelope flow paths if it has been set. */ | ||
| 139 | boost::optional<double> exteriorExponent() const; | ||
| 140 | /** Returns the test data pressure difference of envelope flow paths if it has been set. */ | ||
| 141 | boost::optional<double> exteriorDeltaP() const; | ||
| 142 | /** Set the test data point for envelope flow paths. */ | ||
| 143 | bool setExteriorFlowRate(double flow, double n, double deltaP); | ||
| 144 | /** Returns the return-to-supply ratio. */ | ||
| 145 | double returnSupplyRatio() const; | ||
| 146 | /** Sets the return-to-supply ratio. */ | ||
| 147 | void setReturnSupplyRatio(double returnSupplyRatio); | ||
| 148 | /** Returns true if the return/supply ratio will be used to set return flows, false otherwise. */ | ||
| 149 | bool ratioOverride() const; | ||
| 150 | /** Set the behavior of the translator in setting return flows. */ | ||
| 151 | void setRatioOverride(bool ratioOverride); | ||
| 152 | /** Returns true if HVAC will be translated, false otherwise. */ | ||
| 153 | bool translateHVAC() const; | ||
| 154 | /** Set the translator's HVAC translation behavior. */ | ||
| 155 | void setTranslateHVAC(bool translateHVAC); | ||
| 156 | /** Returns the simulation start time of the translated model. */ | ||
| 157 | boost::optional<openstudio::DateTime> startDateTime() const; | ||
| 158 | /** Returns the simulation end time of the translated model. */ | ||
| 159 | boost::optional<openstudio::DateTime> endDateTime() const; | ||
| 160 | |||
| 161 | //@} | ||
| 162 | /** @name Miscellaneous Functions */ | ||
| 163 | //@{ | ||
| 164 | |||
| 165 | /** Write out any continuous value file information to the specified path */ | ||
| 166 | bool writeCvFile(openstudio::path filepath); | ||
| 167 | |||
| 168 | /** Returns warning messages generated by the last translation. */ | ||
| 169 | std::vector<LogMessage> warnings() const; | ||
| 170 | |||
| 171 | /** Returns error messages generated by the last translation. */ | ||
| 172 | std::vector<LogMessage> errors() const; | ||
| 173 | |||
| 174 | //@} | ||
| 175 | |||
| 176 | protected: | ||
| 177 | virtual bool linkExteriorSurface(openstudio::model::ThermalZone zone, openstudio::model::Space space, | ||
| 178 | openstudio::model::Surface surface) override; | ||
| 179 | virtual bool linkExteriorSubSurface(openstudio::model::ThermalZone zone, openstudio::model::Space space, openstudio::model::Surface surface, | ||
| 180 | openstudio::model::SubSurface subSurface) override; | ||
| 181 | virtual bool linkInteriorSurface(openstudio::model::ThermalZone zone, openstudio::model::Space space, openstudio::model::Surface surface, | ||
| 182 | openstudio::model::Surface adjacentSurface, openstudio::model::Space adjacentSpace, | ||
| 183 | openstudio::model::ThermalZone adjacentZone) override; | ||
| 184 | virtual bool linkInteriorSubSurface(openstudio::model::ThermalZone zone, openstudio::model::Space space, openstudio::model::Surface surface, | ||
| 185 | openstudio::model::SubSurface subSurface, openstudio::model::SubSurface adjacentSubSurface, | ||
| 186 | openstudio::model::Surface adjacentSurface, openstudio::model::Space adjacentSpace, | ||
| 187 | openstudio::model::ThermalZone adjacentZone) override; | ||
| 188 | |||
| 189 | private: | ||
| 190 | // Do the work to set up the leakage paths | ||
| 191 | bool applyExteriorFlowRate(contam::IndexModel prjModel); | ||
| 192 | bool applyAirtightnessLevel(contam::IndexModel prjModel); | ||
| 193 | |||
| 194 | // Convenience function to add a new one-point test airflow element to the model | ||
| 195 | int addNewAirflowElement(contam::IndexModel model, std::string name, double flow, double n = 0.65, double deltaP = 75.0); | ||
| 196 | |||
| 197 | // Clear out the translator and reset to the defaults | ||
| 198 | void clear() override; | ||
| 199 | |||
| 200 | // Really need to look at these and determine if they are really needed | ||
| 201 | int tableLookup(std::map<std::string, int> map, std::string str, const char* name); | ||
| 202 | int tableLookup(std::map<Handle, int> map, Handle handle, const char* name); | ||
| 203 | std::string reverseLookup(std::map<std::string, int> map, int nr, const char* name); | ||
| 204 | Handle reverseLookup(std::map<Handle, int> map, int nr, const char* name); | ||
| 205 | |||
| 206 | contam::IndexModel m_prjModel; | ||
| 207 | |||
| 208 | // Maps - will be populated after a call of translateModel | ||
| 209 | // All map to the CONTAM index (1,2,...,nElement) | ||
| 210 | std::map<std::string, int> m_afeMap; // Map from descriptor ("exterior", "floor", etc.) to CONTAM airflow element index | ||
| 211 | std::map<Handle, int> m_levelMap; // Building story to level map by handle | ||
| 212 | std::map<Handle, int> m_zoneMap; // Thermal zone to airflow zone map by handle | ||
| 213 | //std::map <std::string, int> volumeMap; // Map of AHS volumes - may not be needed | ||
| 214 | std::map<std::string, int> m_pathMap; // AHS paths stored by name | ||
| 215 | std::map<Handle, int> m_surfaceMap; // Surface paths stored by handle | ||
| 216 | std::map<Handle, int> m_ahsMap; // Airloop to AHS map by handle | ||
| 217 | |||
| 218 | CvFile m_cvf; | ||
| 219 | boost::optional<openstudio::DateTime> m_startDateTime; | ||
| 220 | boost::optional<openstudio::DateTime> m_endDateTime; | ||
| 221 | boost::optional<std::string> m_leakageDescriptor; | ||
| 222 | boost::optional<double> m_flow; | ||
| 223 | boost::optional<double> m_n; | ||
| 224 | boost::optional<double> m_deltaP; | ||
| 225 | double m_returnSupplyRatio; | ||
| 226 | bool m_ratioOverride; | ||
| 227 | bool m_translateHVAC; | ||
| 228 | |||
| 229 | StringStreamLogSink m_logSink; | ||
| 230 | |||
| 231 | − | REGISTER_LOGGER("openstudio.contam.ForwardTranslator"); | |
| 232 | }; | ||
| 233 | |||
| 234 | } // namespace contam | ||
| 235 | } // namespace openstudio | ||
| 236 | |||
| 237 | #endif // AIRFLOW_CONTAM_FORWARDTRANSLATOR_HPP | ||
| 238 |