Line data Source code
1 : // EnergyPlus, Copyright (c) 1996-2025, 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 3 : void initializeFunctionalAPI(EnergyPlusState state)
59 : {
60 3 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
61 3 : if (!thisState->dataInputProcessing->inputProcessor) {
62 0 : thisState->dataInputProcessing->inputProcessor = EnergyPlus::InputProcessor::factory();
63 : }
64 3 : thisState->init_constant_state(*thisState);
65 3 : thisState->init_state(*thisState);
66 3 : }
67 :
68 0 : const char *apiVersionFromEPlus(EnergyPlusState)
69 : {
70 0 : return EnergyPlus::DataStringGlobals::PythonAPIVersion.c_str();
71 : }
72 1 : const char *energyPlusVersion()
73 : {
74 1 : return EnergyPlus::DataStringGlobals::VerString.c_str();
75 : }
76 :
77 4 : void registerErrorCallback(EnergyPlusState state, std::function<void(EnergyPlus::Error, const std::string &)> f)
78 : {
79 4 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
80 4 : thisState->dataGlobal->errorCallback = f;
81 4 : }
82 :
83 4 : void registerErrorCallback(EnergyPlusState state, void (*f)(int, const char *))
84 : {
85 29 : const auto stdf = [f](EnergyPlus::Error e, const std::string &message) { f(static_cast<int>(e), message.c_str()); };
86 4 : registerErrorCallback(state, stdf);
87 4 : }
88 :
89 2 : Glycol glycolNew(EnergyPlusState state, const char *glycolName)
90 : {
91 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
92 2 : auto *glycol = EnergyPlus::Fluid::GetGlycol(*thisState, EnergyPlus::Util::makeUPPER(glycolName));
93 2 : return reinterpret_cast<Glycol>(glycol);
94 : }
95 2 : void glycolDelete(EnergyPlusState, Glycol glycol)
96 : {
97 2 : }
98 :
99 6 : Real64 glycolSpecificHeat(EnergyPlusState state, Glycol glycol, Real64 temperature)
100 : {
101 6 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
102 6 : return reinterpret_cast<EnergyPlus::Fluid::GlycolProps *>(glycol)->getSpecificHeat(*thisState, temperature, "C-API");
103 : }
104 6 : Real64 glycolDensity(EnergyPlusState state, Glycol glycol, Real64 temperature)
105 : {
106 6 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
107 6 : return reinterpret_cast<EnergyPlus::Fluid::GlycolProps *>(glycol)->getDensity(*thisState, temperature, "C-API");
108 : }
109 6 : Real64 glycolConductivity(EnergyPlusState state, Glycol glycol, Real64 temperature)
110 : {
111 6 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
112 6 : return reinterpret_cast<EnergyPlus::Fluid::GlycolProps *>(glycol)->getConductivity(*thisState, temperature, "C-API");
113 : }
114 6 : Real64 glycolViscosity(EnergyPlusState state, Glycol glycol, Real64 temperature)
115 : {
116 6 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
117 6 : return reinterpret_cast<EnergyPlus::Fluid::GlycolProps *>(glycol)->getViscosity(*thisState, temperature, "C-API");
118 : }
119 :
120 2 : Refrigerant refrigerantNew(EnergyPlusState state, const char *refrigerantName)
121 : {
122 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
123 2 : auto *refrigerant = EnergyPlus::Fluid::GetRefrig(*thisState, EnergyPlus::Util::makeUPPER(refrigerantName));
124 2 : return reinterpret_cast<Refrigerant>(refrigerant);
125 : }
126 2 : void refrigerantDelete(EnergyPlusState, Refrigerant refrigerant)
127 : {
128 2 : }
129 :
130 2 : Real64 refrigerantSaturationPressure(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature)
131 : {
132 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
133 2 : return reinterpret_cast<EnergyPlus::Fluid::RefrigProps *>(refrigerant)->getSatPressure(*thisState, temperature, "C-API");
134 : }
135 2 : Real64 refrigerantSaturationTemperature(EnergyPlusState state, Refrigerant refrigerant, Real64 pressure)
136 : {
137 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
138 2 : return reinterpret_cast<EnergyPlus::Fluid::RefrigProps *>(refrigerant)->getSatTemperature(*thisState, pressure, "C-API");
139 : }
140 4 : Real64 refrigerantSaturatedEnthalpy(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature, Real64 quality)
141 : {
142 4 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
143 4 : return reinterpret_cast<EnergyPlus::Fluid::RefrigProps *>(refrigerant)->getSatEnthalpy(*thisState, temperature, quality, "C-API");
144 : }
145 4 : Real64 refrigerantSaturatedDensity(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature, Real64 quality)
146 : {
147 4 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
148 4 : return reinterpret_cast<EnergyPlus::Fluid::RefrigProps *>(refrigerant)->getSatDensity(*thisState, temperature, quality, "C-API");
149 : }
150 4 : Real64 refrigerantSaturatedSpecificHeat(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature, Real64 quality)
151 : {
152 4 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
153 4 : return reinterpret_cast<EnergyPlus::Fluid::RefrigProps *>(refrigerant)->getSatSpecificHeat(*thisState, temperature, quality, "C-API");
154 : }
155 : // Real64 refrigerantSuperHeatedEnthalpy(EnergyPlusState, Refrigerant refrigerant, Real64 temperature, Real64 pressure) {
156 : // return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->superHeatedEnthalpy(temperature, pressure);
157 : //}
158 : // Real64 refrigerantSuperHeatedPressure(EnergyPlusState, Refrigerant refrigerant, Real64 temperature, Real64 enthalpy) {
159 : // return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->superHeatedPressure(temperature, enthalpy);
160 : //}
161 : // Real64 refrigerantSuperHeatedDensity(EnergyPlusState, Refrigerant refrigerant, Real64 temperature, Real64 pressure) {
162 : // return reinterpret_cast<EnergyPlus::FluidProperties::RefrigerantAPI *>(refrigerant)->superHeatedDensity(temperature, pressure);
163 : //}
164 :
165 2030 : Real64 psyRhoFnPbTdbW(EnergyPlusState state, Real64 const pb, Real64 const tdb, Real64 const dw)
166 : {
167 : // barometric pressure (Pascals)
168 : // dry bulb temperature (Celsius)
169 : // humidity ratio (kgWater/kgDryAir)
170 2030 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
171 2030 : return EnergyPlus::Psychrometrics::PsyRhoAirFnPbTdbW_fast(*thisState, pb, tdb, dw);
172 : }
173 2 : Real64 psyHfgAirFnWTdb(EnergyPlusState, Real64 const T)
174 : {
175 : // input temperature {Celsius}
176 2 : return EnergyPlus::Psychrometrics::PsyHfgAirFnWTdb(0.0, T); // humidity ratio is not used
177 : }
178 2 : Real64 psyHgAirFnWTdb(EnergyPlusState, Real64 const T)
179 : {
180 : // input temperature {Celsius}
181 2 : return EnergyPlus::Psychrometrics::PsyHgAirFnWTdb(0.0, T); // humidity ratio is not used
182 : }
183 8114 : Real64 psyHFnTdbW(EnergyPlusState, Real64 const TDB, Real64 const dW)
184 : {
185 : // dry-bulb temperature {C}
186 : // humidity ratio
187 8114 : return EnergyPlus::Psychrometrics::PsyHFnTdbW_fast(TDB, dW);
188 : }
189 2 : Real64 psyCpAirFnW(EnergyPlusState, Real64 const dw)
190 : {
191 : // humidity ratio {kgWater/kgDryAir}
192 : // input temperature {Celsius}
193 2 : return EnergyPlus::Psychrometrics::PsyCpAirFnW(dw);
194 : }
195 14639 : Real64 psyTdbFnHW(EnergyPlusState, Real64 const H, Real64 const dW)
196 : {
197 : // enthalpy {J/kg}
198 : // humidity ratio
199 14639 : return EnergyPlus::Psychrometrics::PsyTdbFnHW(H, dW);
200 : }
201 2 : Real64 psyRhovFnTdbWPb(EnergyPlusState, Real64 const Tdb, Real64 const dW, Real64 const PB)
202 : {
203 : // dry-bulb temperature {C}
204 : // humidity ratio
205 : // Barometric Pressure {Pascals}
206 2 : return EnergyPlus::Psychrometrics::PsyRhovFnTdbWPb_fast(Tdb, dW, PB);
207 : }
208 2030 : Real64 psyTwbFnTdbWPb(EnergyPlusState state, Real64 const Tdb, Real64 const W, Real64 const Pb)
209 : {
210 : // dry-bulb temperature {C}
211 : // humidity ratio
212 : // barometric pressure {Pascals}
213 2030 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
214 2030 : return EnergyPlus::Psychrometrics::PsyTwbFnTdbWPb(*thisState, Tdb, W, Pb);
215 : }
216 2 : Real64 psyVFnTdbWPb(EnergyPlusState state, Real64 const TDB, Real64 const dW, Real64 const PB)
217 : {
218 : // dry-bulb temperature {C}
219 : // humidity ratio
220 : // barometric pressure {Pascals}
221 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
222 2 : return EnergyPlus::Psychrometrics::PsyVFnTdbWPb(*thisState, TDB, dW, PB);
223 : }
224 4058 : Real64 psyWFnTdbH(EnergyPlusState state, Real64 const TDB, Real64 const H)
225 : {
226 : // dry-bulb temperature {C}
227 : // enthalpy {J/kg}
228 4058 : std::string dummyString;
229 4058 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
230 8116 : return EnergyPlus::Psychrometrics::PsyWFnTdbH(*thisState, TDB, H, dummyString, true);
231 4058 : }
232 2 : Real64 psyPsatFnTemp(EnergyPlusState state, Real64 const T)
233 : {
234 : // dry-bulb temperature {C}
235 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
236 2 : return EnergyPlus::Psychrometrics::PsyPsatFnTemp(*thisState, T);
237 : }
238 2030 : Real64 psyTsatFnHPb(EnergyPlusState state, Real64 const H, Real64 const Pb)
239 : {
240 : // enthalpy {J/kg}
241 : // barometric pressure {Pascals}
242 2030 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
243 2030 : return EnergyPlus::Psychrometrics::PsyTsatFnHPb(*thisState, H, Pb);
244 : }
245 2 : Real64 psyRhovFnTdbRh(EnergyPlusState state, Real64 const Tdb, Real64 const RH)
246 : {
247 : // dry-bulb temperature {C}
248 : // relative humidity value (0.0-1.0)
249 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
250 2 : return EnergyPlus::Psychrometrics::PsyRhovFnTdbRh(*thisState, Tdb, RH);
251 : }
252 2 : Real64 psyRhFnTdbRhov(EnergyPlusState state, Real64 const Tdb, Real64 const Rhovapor)
253 : {
254 : // dry-bulb temperature {C}
255 : // vapor density in air {kg/m3}
256 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
257 2 : return EnergyPlus::Psychrometrics::PsyRhFnTdbRhov(*thisState, Tdb, Rhovapor);
258 : }
259 2 : Real64 psyRhFnTdbWPb(EnergyPlusState state, Real64 const TDB, Real64 const dW, Real64 const PB)
260 : {
261 : // dry-bulb temperature {C}
262 : // humidity ratio
263 : // barometric pressure {Pascals}
264 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
265 2 : return EnergyPlus::Psychrometrics::PsyRhFnTdbWPb(*thisState, TDB, dW, PB);
266 : }
267 2 : Real64 psyWFnTdpPb(EnergyPlusState state, Real64 const TDP, Real64 const PB)
268 : {
269 : // dew-point temperature {C}
270 : // barometric pressure {Pascals}
271 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
272 2 : return EnergyPlus::Psychrometrics::PsyWFnTdpPb(*thisState, TDP, PB);
273 : }
274 2 : Real64 psyWFnTdbRhPb(EnergyPlusState state, Real64 const TDB, Real64 const RH, Real64 const PB)
275 : {
276 : // dry-bulb temperature {C}
277 : // relative humidity value (0.0-1.0)
278 : // barometric pressure {Pascals}
279 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
280 2 : return EnergyPlus::Psychrometrics::PsyWFnTdbRhPb(*thisState, TDB, RH, PB);
281 : }
282 2 : Real64 psyWFnTdbTwbPb(EnergyPlusState state, Real64 const TDB, Real64 const TWBin, Real64 const PB)
283 : {
284 : // dry-bulb temperature {C}
285 : // wet-bulb temperature {C}
286 : // barometric pressure {Pascals}
287 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
288 2 : return EnergyPlus::Psychrometrics::PsyWFnTdbTwbPb(*thisState, TDB, TWBin, PB);
289 : }
290 2 : Real64 psyHFnTdbRhPb(EnergyPlusState state, Real64 const TDB, Real64 const RH, Real64 const PB)
291 : {
292 : // dry-bulb temperature {C}
293 : // relative humidity value (0.0 - 1.0)
294 : // barometric pressure (N/M**2) {Pascals}
295 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
296 2 : return EnergyPlus::Psychrometrics::PsyHFnTdbRhPb(*thisState, TDB, RH, PB);
297 : }
298 2 : Real64 psyTdpFnWPb(EnergyPlusState state, Real64 const W, Real64 const PB)
299 : {
300 : // humidity ratio
301 : // barometric pressure (N/M**2) {Pascals}
302 2 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
303 2 : return EnergyPlus::Psychrometrics::PsyTdpFnWPb(*thisState, W, PB);
304 : }
305 4 : Real64 psyTdpFnTdbTwbPb(EnergyPlusState state, Real64 const TDB, Real64 const TWB, Real64 const PB)
306 : {
307 : // dry-bulb temperature {C}
308 : // wet-bulb temperature {C}
309 : // barometric pressure (N/M**2) {Pascals}
310 4 : auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
311 4 : return EnergyPlus::Psychrometrics::PsyTdpFnTdbTwbPb(*thisState, TDB, TWB, PB);
312 : }
|