LCOV - code coverage report
Current view: top level - EnergyPlus/api - func.cc (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 28 118 23.7 %
Date: 2023-01-17 19:17:23 Functions: 11 42 26.2 %

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

Generated by: LCOV version 1.13