LCOV - code coverage report
Current view: top level - EnergyPlus/api - func.cc (source / functions) Coverage Total Hit
Test: lcov.output.filtered Lines: 23.9 % 117 28
Test Date: 2025-06-02 07:23:51 Functions: 22.5 % 40 9

            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            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_constant_state(*thisState);
      65            0 :     thisState->init_state(*thisState);
      66            0 : }
      67              : 
      68            0 : const char *apiVersionFromEPlus(EnergyPlusState)
      69              : {
      70            0 :     return EnergyPlus::DataStringGlobals::PythonAPIVersion.c_str();
      71              : }
      72            0 : const char *energyPlusVersion()
      73              : {
      74            0 :     return EnergyPlus::DataStringGlobals::VerString.c_str();
      75              : }
      76              : 
      77            0 : void registerErrorCallback(EnergyPlusState state, std::function<void(EnergyPlus::Error, const std::string &)> f)
      78              : {
      79            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
      80            0 :     thisState->dataGlobal->errorCallback = f;
      81            0 : }
      82              : 
      83            0 : void registerErrorCallback(EnergyPlusState state, void (*f)(int, const char *))
      84              : {
      85            0 :     const auto stdf = [f](EnergyPlus::Error e, const std::string &message) { f(static_cast<int>(e), message.c_str()); };
      86            0 :     registerErrorCallback(state, stdf);
      87            0 : }
      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            0 : void glycolDelete(EnergyPlusState, Glycol glycol)
      96              : {
      97            0 : }
      98              : 
      99        42435 : Real64 glycolSpecificHeat(EnergyPlusState state, Glycol glycol, Real64 temperature)
     100              : {
     101        42435 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     102        42435 :     return reinterpret_cast<EnergyPlus::Fluid::GlycolProps *>(glycol)->getSpecificHeat(*thisState, temperature, "C-API");
     103              : }
     104          195 : Real64 glycolDensity(EnergyPlusState state, Glycol glycol, Real64 temperature)
     105              : {
     106          195 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     107          195 :     return reinterpret_cast<EnergyPlus::Fluid::GlycolProps *>(glycol)->getDensity(*thisState, temperature, "C-API");
     108              : }
     109            0 : Real64 glycolConductivity(EnergyPlusState state, Glycol glycol, Real64 temperature)
     110              : {
     111            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     112            0 :     return reinterpret_cast<EnergyPlus::Fluid::GlycolProps *>(glycol)->getConductivity(*thisState, temperature, "C-API");
     113              : }
     114            0 : Real64 glycolViscosity(EnergyPlusState state, Glycol glycol, Real64 temperature)
     115              : {
     116            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     117            0 :     return reinterpret_cast<EnergyPlus::Fluid::GlycolProps *>(glycol)->getViscosity(*thisState, temperature, "C-API");
     118              : }
     119              : 
     120            0 : Refrigerant refrigerantNew(EnergyPlusState state, const char *refrigerantName)
     121              : {
     122            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     123            0 :     auto *refrigerant = EnergyPlus::Fluid::GetRefrig(*thisState, EnergyPlus::Util::makeUPPER(refrigerantName));
     124            0 :     return reinterpret_cast<Refrigerant>(refrigerant);
     125              : }
     126            0 : void refrigerantDelete(EnergyPlusState, Refrigerant refrigerant)
     127              : {
     128            0 : }
     129              : 
     130            0 : Real64 refrigerantSaturationPressure(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature)
     131              : {
     132            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     133            0 :     return reinterpret_cast<EnergyPlus::Fluid::RefrigProps *>(refrigerant)->getSatPressure(*thisState, temperature, "C-API");
     134              : }
     135            0 : Real64 refrigerantSaturationTemperature(EnergyPlusState state, Refrigerant refrigerant, Real64 pressure)
     136              : {
     137            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     138            0 :     return reinterpret_cast<EnergyPlus::Fluid::RefrigProps *>(refrigerant)->getSatTemperature(*thisState, pressure, "C-API");
     139              : }
     140            0 : Real64 refrigerantSaturatedEnthalpy(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature, Real64 quality)
     141              : {
     142            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     143            0 :     return reinterpret_cast<EnergyPlus::Fluid::RefrigProps *>(refrigerant)->getSatEnthalpy(*thisState, temperature, quality, "C-API");
     144              : }
     145            0 : Real64 refrigerantSaturatedDensity(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature, Real64 quality)
     146              : {
     147            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     148            0 :     return reinterpret_cast<EnergyPlus::Fluid::RefrigProps *>(refrigerant)->getSatDensity(*thisState, temperature, quality, "C-API");
     149              : }
     150            0 : Real64 refrigerantSaturatedSpecificHeat(EnergyPlusState state, Refrigerant refrigerant, Real64 temperature, Real64 quality)
     151              : {
     152            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     153            0 :     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         2035 : 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         2035 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     171         2035 :     return EnergyPlus::Psychrometrics::PsyRhoAirFnPbTdbW_fast(*thisState, pb, tdb, dw);
     172              : }
     173            0 : Real64 psyHfgAirFnWTdb(EnergyPlusState, Real64 const T)
     174              : {
     175              :     // input temperature {Celsius}
     176            0 :     return EnergyPlus::Psychrometrics::PsyHfgAirFnWTdb(0.0, T); // humidity ratio is not used
     177              : }
     178            0 : Real64 psyHgAirFnWTdb(EnergyPlusState, Real64 const T)
     179              : {
     180              :     // input temperature {Celsius}
     181            0 :     return EnergyPlus::Psychrometrics::PsyHgAirFnWTdb(0.0, T); // humidity ratio is not used
     182              : }
     183         8140 : Real64 psyHFnTdbW(EnergyPlusState, Real64 const TDB, Real64 const dW)
     184              : {
     185              :     // dry-bulb temperature {C}
     186              :     // humidity ratio
     187         8140 :     return EnergyPlus::Psychrometrics::PsyHFnTdbW_fast(TDB, dW);
     188              : }
     189            0 : Real64 psyCpAirFnW(EnergyPlusState, Real64 const dw)
     190              : {
     191              :     // humidity ratio {kgWater/kgDryAir}
     192              :     // input temperature {Celsius}
     193            0 :     return EnergyPlus::Psychrometrics::PsyCpAirFnW(dw);
     194              : }
     195        14715 : Real64 psyTdbFnHW(EnergyPlusState, Real64 const H, Real64 const dW)
     196              : {
     197              :     // enthalpy {J/kg}
     198              :     // humidity ratio
     199        14715 :     return EnergyPlus::Psychrometrics::PsyTdbFnHW(H, dW);
     200              : }
     201            0 : 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            0 :     return EnergyPlus::Psychrometrics::PsyRhovFnTdbWPb_fast(Tdb, dW, PB);
     207              : }
     208         3379 : 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         3379 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     214         3379 :     return EnergyPlus::Psychrometrics::PsyTwbFnTdbWPb(*thisState, Tdb, W, Pb);
     215              : }
     216            0 : 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            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     222            0 :     return EnergyPlus::Psychrometrics::PsyVFnTdbWPb(*thisState, TDB, dW, PB);
     223              : }
     224         4070 : Real64 psyWFnTdbH(EnergyPlusState state, Real64 const TDB, Real64 const H)
     225              : {
     226              :     // dry-bulb temperature {C}
     227              :     // enthalpy {J/kg}
     228         4070 :     std::string dummyString;
     229         4070 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     230         8140 :     return EnergyPlus::Psychrometrics::PsyWFnTdbH(*thisState, TDB, H, dummyString, true);
     231         4070 : }
     232            0 : Real64 psyPsatFnTemp(EnergyPlusState state, Real64 const T)
     233              : {
     234              :     // dry-bulb temperature {C}
     235            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     236            0 :     return EnergyPlus::Psychrometrics::PsyPsatFnTemp(*thisState, T);
     237              : }
     238         2035 : Real64 psyTsatFnHPb(EnergyPlusState state, Real64 const H, Real64 const Pb)
     239              : {
     240              :     // enthalpy {J/kg}
     241              :     // barometric pressure {Pascals}
     242         2035 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     243         2035 :     return EnergyPlus::Psychrometrics::PsyTsatFnHPb(*thisState, H, Pb);
     244              : }
     245            0 : 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            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     250            0 :     return EnergyPlus::Psychrometrics::PsyRhovFnTdbRh(*thisState, Tdb, RH);
     251              : }
     252            0 : Real64 psyRhFnTdbRhov(EnergyPlusState state, Real64 const Tdb, Real64 const Rhovapor)
     253              : {
     254              :     // dry-bulb temperature {C}
     255              :     // vapor density in air {kg/m3}
     256            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     257            0 :     return EnergyPlus::Psychrometrics::PsyRhFnTdbRhov(*thisState, Tdb, Rhovapor);
     258              : }
     259            0 : 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            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     265            0 :     return EnergyPlus::Psychrometrics::PsyRhFnTdbWPb(*thisState, TDB, dW, PB);
     266              : }
     267            0 : Real64 psyWFnTdpPb(EnergyPlusState state, Real64 const TDP, Real64 const PB)
     268              : {
     269              :     // dew-point temperature {C}
     270              :     // barometric pressure {Pascals}
     271            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     272            0 :     return EnergyPlus::Psychrometrics::PsyWFnTdpPb(*thisState, TDP, PB);
     273              : }
     274            0 : 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            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     280            0 :     return EnergyPlus::Psychrometrics::PsyWFnTdbRhPb(*thisState, TDB, RH, PB);
     281              : }
     282            0 : 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            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     288            0 :     return EnergyPlus::Psychrometrics::PsyWFnTdbTwbPb(*thisState, TDB, TWBin, PB);
     289              : }
     290            0 : 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            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     296            0 :     return EnergyPlus::Psychrometrics::PsyHFnTdbRhPb(*thisState, TDB, RH, PB);
     297              : }
     298            0 : Real64 psyTdpFnWPb(EnergyPlusState state, Real64 const W, Real64 const PB)
     299              : {
     300              :     // humidity ratio
     301              :     // barometric pressure (N/M**2) {Pascals}
     302            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     303            0 :     return EnergyPlus::Psychrometrics::PsyTdpFnWPb(*thisState, W, PB);
     304              : }
     305            0 : 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            0 :     auto *thisState = reinterpret_cast<EnergyPlus::EnergyPlusData *>(state);
     311            0 :     return EnergyPlus::Psychrometrics::PsyTdpFnTdbTwbPb(*thisState, TDB, TWB, PB);
     312              : }
        

Generated by: LCOV version 2.0-1