Line data Source code
1 : // EnergyPlus, Copyright (c) 1996-2024, The Board of Trustees of the University of Illinois,
2 : // The Regents of the University of California, through Lawrence Berkeley National Laboratory
3 : // (subject to receipt of any required approvals from the U.S. Dept. of Energy), Oak Ridge
4 : // National Laboratory, managed by UT-Battelle, Alliance for Sustainable Energy, LLC, and other
5 : // contributors. All rights reserved.
6 : //
7 : // NOTICE: This Software was developed under funding from the U.S. Department of Energy and the
8 : // U.S. Government consequently retains certain rights. As such, the U.S. Government has been
9 : // granted for itself and others acting on its behalf a paid-up, nonexclusive, irrevocable,
10 : // worldwide license in the Software to reproduce, distribute copies to the public, prepare
11 : // derivative works, and perform publicly and display publicly, and to permit others to do so.
12 : //
13 : // Redistribution and use in source and binary forms, with or without modification, are permitted
14 : // provided that the following conditions are met:
15 : //
16 : // (1) Redistributions of source code must retain the above copyright notice, this list of
17 : // conditions and the following disclaimer.
18 : //
19 : // (2) Redistributions in binary form must reproduce the above copyright notice, this list of
20 : // conditions and the following disclaimer in the documentation and/or other materials
21 : // provided with the distribution.
22 : //
23 : // (3) Neither the name of the University of California, Lawrence Berkeley National Laboratory,
24 : // the University of Illinois, U.S. Dept. of Energy nor the names of its contributors may be
25 : // used to endorse or promote products derived from this software without specific prior
26 : // written permission.
27 : //
28 : // (4) Use of EnergyPlus(TM) Name. If Licensee (i) distributes the software in stand-alone form
29 : // without changes from the version obtained under this License, or (ii) Licensee makes a
30 : // reference solely to the software portion of its product, Licensee must refer to the
31 : // software as "EnergyPlus version X" software, where "X" is the version number Licensee
32 : // obtained under this License and may not use a different name for the software. Except as
33 : // specifically required in this Section (4), Licensee shall not use in a company name, a
34 : // product name, in advertising, publicity, or other promotional activities any name, trade
35 : // name, trademark, logo, or other designation of "EnergyPlus", "E+", "e+" or confusingly
36 : // similar designation, without the U.S. Department of Energy's prior written consent.
37 : //
38 : // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
39 : // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
40 : // AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
41 : // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
42 : // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
43 : // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 : // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
45 : // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46 : // POSSIBILITY OF SUCH DAMAGE.
47 :
48 : #include <EnergyPlus/Data/EnergyPlusData.hh>
49 : #include <EnergyPlus/DataStringGlobals.hh>
50 : #include <EnergyPlus/FluidProperties.hh>
51 : #include <EnergyPlus/InputProcessing/IdfParser.hh>
52 : #include <EnergyPlus/InputProcessing/InputProcessor.hh>
53 : #include <EnergyPlus/InputProcessing/InputValidation.hh>
54 : #include <EnergyPlus/Psychrometrics.hh>
55 : #include <EnergyPlus/api/func.h>
56 : #include <EnergyPlus/api/state.h>
57 :
58 0 : void initializeFunctionalAPI(EnergyPlusState state)
59 : {
60 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
61 0 : if (!thisState->dataInputProcessing->inputProcessor) {
62 0 : thisState->dataInputProcessing->inputProcessor = EnergyPlus::InputProcessor::factory();
63 : }
64 0 : thisState->init_state(*thisState);
65 0 : }
66 :
67 0 : const char *apiVersionFromEPlus(EnergyPlusState)
68 : {
69 0 : return EnergyPlus::DataStringGlobals::PythonAPIVersion.c_str();
70 : }
71 0 : const char *energyPlusVersion()
72 : {
73 0 : return EnergyPlus::DataStringGlobals::VerString.c_str();
74 : }
75 :
76 0 : void registerErrorCallback(EnergyPlusState state, std::function<void(EnergyPlus::Error, const std::string &)> f)
77 : {
78 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
79 0 : thisState->dataGlobal->errorCallback = f;
80 0 : }
81 :
82 0 : void registerErrorCallback(EnergyPlusState state, void (*f)(int, const char *))
83 : {
84 0 : const auto stdf = [f](EnergyPlus::Error e, const std::string &message) { f(static_cast<int>(e), message.c_str()); };
85 0 : registerErrorCallback(state, stdf);
86 0 : }
87 :
88 2 : Glycol glycolNew(EnergyPlusState state, const char *glycolName)
89 : {
90 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
91 2 : auto *glycol = new EnergyPlus::FluidProperties::GlycolAPI(*thisState, glycolName);
92 2 : return reinterpret_cast<Glycol>(glycol);
93 : }
94 0 : void glycolDelete(EnergyPlusState, Glycol glycol)
95 : {
96 0 : delete reinterpret_cast<EnergyPlus::FluidProperties::GlycolAPI *>(glycol);
97 0 : }
98 42435 : Real64 glycolSpecificHeat(EnergyPlusState state, Glycol glycol, Real64 temperature)
99 : {
100 42435 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
101 42435 : return reinterpret_cast<EnergyPlus::FluidProperties::GlycolAPI *>(glycol)->specificHeat(*thisState, temperature);
102 : }
103 195 : Real64 glycolDensity(EnergyPlusState state, Glycol glycol, Real64 temperature)
104 : {
105 195 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
106 195 : return reinterpret_cast<EnergyPlus::FluidProperties::GlycolAPI *>(glycol)->density(*thisState, temperature);
107 : }
108 0 : Real64 glycolConductivity(EnergyPlusState state, Glycol glycol, Real64 temperature)
109 : {
110 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
111 0 : return reinterpret_cast<EnergyPlus::FluidProperties::GlycolAPI *>(glycol)->conductivity(*thisState, temperature);
112 : }
113 0 : Real64 glycolViscosity(EnergyPlusState state, Glycol glycol, Real64 temperature)
114 : {
115 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
116 0 : return reinterpret_cast<EnergyPlus::FluidProperties::GlycolAPI *>(glycol)->viscosity(*thisState, temperature);
117 : }
118 :
119 0 : Refrigerant refrigerantNew(EnergyPlusState state, const char *refrigerantName)
120 : {
121 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
122 0 : auto *refrigerant = new EnergyPlus::FluidProperties::RefrigerantAPI(*thisState, refrigerantName);
123 0 : return reinterpret_cast<Refrigerant>(refrigerant);
124 : }
125 0 : void refrigerantDelete(EnergyPlusState, Refrigerant refrigerant)
126 : {
127 0 : delete reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant);
128 0 : }
129 0 : Real64 refrigerantSaturationPressure(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature)
130 : {
131 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
132 0 : return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->saturationPressure(*thisState, temperature);
133 : }
134 0 : Real64 refrigerantSaturationTemperature(EnergyPlusState state, Refrigerant refrigerant, Real64 pressure)
135 : {
136 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
137 0 : return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->saturationTemperature(*thisState, pressure);
138 : }
139 0 : Real64 refrigerantSaturatedEnthalpy(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature, Real64 quality)
140 : {
141 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
142 0 : return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->saturatedEnthalpy(*thisState, temperature, quality);
143 : }
144 0 : Real64 refrigerantSaturatedDensity(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature, Real64 quality)
145 : {
146 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
147 0 : return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->saturatedDensity(*thisState, temperature, quality);
148 : }
149 0 : Real64 refrigerantSaturatedSpecificHeat(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature, Real64 quality)
150 : {
151 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
152 0 : return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->saturatedSpecificHeat(*thisState, temperature, quality);
153 : }
154 : // Real64 refrigerantSuperHeatedEnthalpy(EnergyPlusState, Refrigerant refrigerant, Real64 temperature, Real64 pressure) {
155 : // return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->superHeatedEnthalpy(temperature, pressure);
156 : //}
157 : // Real64 refrigerantSuperHeatedPressure(EnergyPlusState, Refrigerant refrigerant, Real64 temperature, Real64 enthalpy) {
158 : // return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->superHeatedPressure(temperature, enthalpy);
159 : //}
160 : // Real64 refrigerantSuperHeatedDensity(EnergyPlusState, Refrigerant refrigerant, Real64 temperature, Real64 pressure) {
161 : // return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->superHeatedDensity(temperature, pressure);
162 : //}
163 :
164 2035 : Real64 psyRhoFnPbTdbW(EnergyPlusState state, Real64 const pb, Real64 const tdb, Real64 const dw)
165 : {
166 : // barometric pressure (Pascals)
167 : // dry bulb temperature (Celsius)
168 : // humidity ratio (kgWater/kgDryAir)
169 2035 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
170 2035 : return EnergyPlus::Psychrometrics::PsyRhoAirFnPbTdbW_fast(*thisState, pb, tdb, dw);
171 : }
172 0 : Real64 psyHfgAirFnWTdb(EnergyPlusState, Real64 const T)
173 : {
174 : // input temperature {Celsius}
175 0 : return EnergyPlus::Psychrometrics::PsyHfgAirFnWTdb(0.0, T); // humidity ratio is not used
176 : }
177 0 : Real64 psyHgAirFnWTdb(EnergyPlusState, Real64 const T)
178 : {
179 : // input temperature {Celsius}
180 0 : return EnergyPlus::Psychrometrics::PsyHgAirFnWTdb(0.0, T); // humidity ratio is not used
181 : }
182 8140 : Real64 psyHFnTdbW(EnergyPlusState, Real64 const TDB, Real64 const dW)
183 : {
184 : // dry-bulb temperature {C}
185 : // humidity ratio
186 8140 : return EnergyPlus::Psychrometrics::PsyHFnTdbW_fast(TDB, dW);
187 : }
188 0 : Real64 psyCpAirFnW(EnergyPlusState, Real64 const dw)
189 : {
190 : // humidity ratio {kgWater/kgDryAir}
191 : // input temperature {Celsius}
192 0 : return EnergyPlus::Psychrometrics::PsyCpAirFnW(dw);
193 : }
194 14715 : Real64 psyTdbFnHW(EnergyPlusState, Real64 const H, Real64 const dW)
195 : {
196 : // enthalpy {J/kg}
197 : // humidity ratio
198 14715 : return EnergyPlus::Psychrometrics::PsyTdbFnHW(H, dW);
199 : }
200 0 : Real64 psyRhovFnTdbWPb(EnergyPlusState, Real64 const Tdb, Real64 const dW, Real64 const PB)
201 : {
202 : // dry-bulb temperature {C}
203 : // humidity ratio
204 : // Barometric Pressure {Pascals}
205 0 : return EnergyPlus::Psychrometrics::PsyRhovFnTdbWPb_fast(Tdb, dW, PB);
206 : }
207 3379 : Real64 psyTwbFnTdbWPb(EnergyPlusState state, Real64 const Tdb, Real64 const W, Real64 const Pb)
208 : {
209 : // dry-bulb temperature {C}
210 : // humidity ratio
211 : // barometric pressure {Pascals}
212 3379 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
213 3379 : return EnergyPlus::Psychrometrics::PsyTwbFnTdbWPb(*thisState, Tdb, W, Pb);
214 : }
215 0 : Real64 psyVFnTdbWPb(EnergyPlusState state, Real64 const TDB, Real64 const dW, Real64 const PB)
216 : {
217 : // dry-bulb temperature {C}
218 : // humidity ratio
219 : // barometric pressure {Pascals}
220 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
221 0 : return EnergyPlus::Psychrometrics::PsyVFnTdbWPb(*thisState, TDB, dW, PB);
222 : }
223 4070 : Real64 psyWFnTdbH(EnergyPlusState state, Real64 const TDB, Real64 const H)
224 : {
225 : // dry-bulb temperature {C}
226 : // enthalpy {J/kg}
227 4070 : std::string dummyString;
228 4070 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
229 8140 : return EnergyPlus::Psychrometrics::PsyWFnTdbH(*thisState, TDB, H, dummyString, true);
230 4070 : }
231 0 : Real64 psyPsatFnTemp(EnergyPlusState state, Real64 const T)
232 : {
233 : // dry-bulb temperature {C}
234 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
235 0 : return EnergyPlus::Psychrometrics::PsyPsatFnTemp(*thisState, T);
236 : }
237 2035 : Real64 psyTsatFnHPb(EnergyPlusState state, Real64 const H, Real64 const Pb)
238 : {
239 : // enthalpy {J/kg}
240 : // barometric pressure {Pascals}
241 2035 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
242 2035 : return EnergyPlus::Psychrometrics::PsyTsatFnHPb(*thisState, H, Pb);
243 : }
244 0 : Real64 psyRhovFnTdbRh(EnergyPlusState state, Real64 const Tdb, Real64 const RH)
245 : {
246 : // dry-bulb temperature {C}
247 : // relative humidity value (0.0-1.0)
248 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
249 0 : return EnergyPlus::Psychrometrics::PsyRhovFnTdbRh(*thisState, Tdb, RH);
250 : }
251 0 : Real64 psyRhFnTdbRhov(EnergyPlusState state, Real64 const Tdb, Real64 const Rhovapor)
252 : {
253 : // dry-bulb temperature {C}
254 : // vapor density in air {kg/m3}
255 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
256 0 : return EnergyPlus::Psychrometrics::PsyRhFnTdbRhov(*thisState, Tdb, Rhovapor);
257 : }
258 0 : Real64 psyRhFnTdbWPb(EnergyPlusState state, Real64 const TDB, Real64 const dW, Real64 const PB)
259 : {
260 : // dry-bulb temperature {C}
261 : // humidity ratio
262 : // barometric pressure {Pascals}
263 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
264 0 : return EnergyPlus::Psychrometrics::PsyRhFnTdbWPb(*thisState, TDB, dW, PB);
265 : }
266 0 : Real64 psyWFnTdpPb(EnergyPlusState state, Real64 const TDP, Real64 const PB)
267 : {
268 : // dew-point temperature {C}
269 : // barometric pressure {Pascals}
270 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
271 0 : return EnergyPlus::Psychrometrics::PsyWFnTdpPb(*thisState, TDP, PB);
272 : }
273 0 : Real64 psyWFnTdbRhPb(EnergyPlusState state, Real64 const TDB, Real64 const RH, Real64 const PB)
274 : {
275 : // dry-bulb temperature {C}
276 : // relative humidity value (0.0-1.0)
277 : // barometric pressure {Pascals}
278 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
279 0 : return EnergyPlus::Psychrometrics::PsyWFnTdbRhPb(*thisState, TDB, RH, PB);
280 : }
281 0 : Real64 psyWFnTdbTwbPb(EnergyPlusState state, Real64 const TDB, Real64 const TWBin, Real64 const PB)
282 : {
283 : // dry-bulb temperature {C}
284 : // wet-bulb temperature {C}
285 : // barometric pressure {Pascals}
286 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
287 0 : return EnergyPlus::Psychrometrics::PsyWFnTdbTwbPb(*thisState, TDB, TWBin, PB);
288 : }
289 0 : Real64 psyHFnTdbRhPb(EnergyPlusState state, Real64 const TDB, Real64 const RH, Real64 const PB)
290 : {
291 : // dry-bulb temperature {C}
292 : // relative humidity value (0.0 - 1.0)
293 : // barometric pressure (N/M**2) {Pascals}
294 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
295 0 : return EnergyPlus::Psychrometrics::PsyHFnTdbRhPb(*thisState, TDB, RH, PB);
296 : }
297 0 : Real64 psyTdpFnWPb(EnergyPlusState state, Real64 const W, Real64 const PB)
298 : {
299 : // humidity ratio
300 : // barometric pressure (N/M**2) {Pascals}
301 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
302 0 : return EnergyPlus::Psychrometrics::PsyTdpFnWPb(*thisState, W, PB);
303 : }
304 0 : Real64 psyTdpFnTdbTwbPb(EnergyPlusState state, Real64 const TDB, Real64 const TWB, Real64 const PB)
305 : {
306 : // dry-bulb temperature {C}
307 : // wet-bulb temperature {C}
308 : // barometric pressure (N/M**2) {Pascals}
309 0 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
310 0 : return EnergyPlus::Psychrometrics::PsyTdpFnTdbTwbPb(*thisState, TDB, TWB, PB);
311 : }
|