LCOV - code coverage report
Current view: top level - EnergyPlus - CurveManager.hh (source / functions) Hit Total Coverage
Test: lcov.output.filtered Lines: 9 12 75.0 %
Date: 2023-01-17 19:17:23 Functions: 13 17 76.5 %

          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             : #ifndef CurveManager_hh_INCLUDED
      49             : #define CurveManager_hh_INCLUDED
      50             : 
      51             : // C++ Headers
      52             : #include <map>
      53             : #include <vector>
      54             : 
      55             : // ObjexxFCL Headers
      56             : #include <ObjexxFCL/Array1D.hh>
      57             : #include <ObjexxFCL/Array2D.hh>
      58             : #include <ObjexxFCL/Array2S.hh>
      59             : #include <ObjexxFCL/Optional.hh>
      60             : 
      61             : #include <nlohmann/json.hpp>
      62             : 
      63             : // Btwxt Headers
      64             : #include <btwxt.h>
      65             : #include <griddeddata.h>
      66             : 
      67             : // EnergyPlus Headers
      68             : #include <EnergyPlus/Data/BaseData.hh>
      69             : #include <EnergyPlus/DataBranchAirLoopPlant.hh>
      70             : #include <EnergyPlus/DataGlobals.hh>
      71             : #include <EnergyPlus/EnergyPlus.hh>
      72             : #include <EnergyPlus/FileSystem.hh>
      73             : 
      74             : namespace EnergyPlus {
      75             : 
      76             : // Forward declarations
      77             : struct EnergyPlusData;
      78             : 
      79             : namespace Curve {
      80             : 
      81             :     // Curve Type parameters, these can differ from object types (e.g. a CurveType_TableOneIV can be linear, quadratic, etc)
      82             : 
      83             :     enum class CurveType
      84             :     {
      85             :         Invalid = -1,
      86             :         Linear,
      87             :         Quadratic,
      88             :         BiQuadratic,
      89             :         Cubic,
      90             :         QuadraticLinear,
      91             :         BiCubic,
      92             :         TriQuadratic,
      93             :         Exponent,
      94             :         Quartic,
      95             :         FanPressureRise,
      96             :         ExponentialSkewNormal,
      97             :         Sigmoid,
      98             :         RectangularHyperbola1,
      99             :         RectangularHyperbola2,
     100             :         ExponentialDecay,
     101             :         DoubleExponentialDecay,
     102             :         QuadLinear,
     103             :         QuintLinear,
     104             :         CubicLinear,
     105             :         ChillerPartLoadWithLift,
     106             :         Num
     107             :     };
     108             : 
     109             :     constexpr std::array<std::string_view, static_cast<int>(CurveType::Num)> objectNames = {
     110             :         "Curve:Linear",
     111             :         "Curve:Quadratic",
     112             :         "Curve:Biquadratic",
     113             :         "Curve:Cubic",
     114             :         "Curve:QuadLinear",
     115             :         "Curve:Bicubic",
     116             :         "Curve:Triquadratic",
     117             :         "Curve:Exponent",
     118             :         "Curve:Quartic",
     119             :         "Curve:FanPressureRise",
     120             :         "Curve:ExponentialSkewNormal",
     121             :         "Curve:Sigmoid",
     122             :         "Curve:RectangularHyperbola1",
     123             :         "Curve:RectangularHyperbola2",
     124             :         "Curve:ExponentialDecay",
     125             :         "Curve:DoubleExponentialDecay",
     126             :         "Curve:QuadraticLinear",
     127             :         "Curve:QuintLinear",
     128             :         "Curve:CubicLinear",
     129             :         "Curve:ChillerPartLoadWithLift",
     130             :     }; // namespace Curve
     131             : 
     132             :     enum class InterpType
     133             :     {
     134             :         Invalid = -1,
     135             :         EvaluateCurveToLimits,
     136             :         BtwxtMethod,
     137             :         Num
     138             :     };
     139             : 
     140         679 :     struct Limits
     141             :     {
     142             :         Real64 min = 0.0;
     143             :         Real64 max = 0.0;
     144             :         bool minPresent = false;
     145             :         bool maxPresent = false;
     146             :     };
     147             : 
     148       14800 :     struct PerformanceCurveData
     149             :     {
     150             :         // Basic data
     151             :         std::string Name;                         // Curve Name
     152             :         CurveType curveType = CurveType::Invalid; // Curve type (see parameter definitions above)
     153             :         // Table data stuff
     154             :         InterpType interpolationType = InterpType::Invalid; // Table interpolation method
     155             :         int TableIndex = 0;     // Index to tabular data (0 if a standard curve object) OR Index of RGI for new Table:Lookup
     156             :         int numDims = 0;        // Number of dimensions (AKA, independent variables)
     157             :         int GridValueIndex = 0; // Index of output within RGI for new Table:Lookup
     158             :         // input coefficients
     159             :         std::array<Real64, 12> coeff = {0.0}; // curve coefficients
     160             :         std::array<Real64, 27> tri2ndOrder;   // 27 coefficient full triquadratic (!)
     161             :         // independent variables
     162             :         std::array<Real64, 6> inputs = {0.0}; // curve inputs
     163             :         std::array<Limits, 6> inputLimits;    // min/max of independent variables
     164             :         // dependent (output) variable
     165             :         Real64 output = 0.0; // curve output or result
     166             :         Limits outputLimits; // min/max of curve output
     167             :         // EMS override
     168             :         bool EMSOverrideOn = false;         // if TRUE, then EMS is calling to override curve value
     169             :         Real64 EMSOverrideCurveValue = 0.0; // Value of curve result EMS is directing to use
     170             :     };
     171             : 
     172             :     // Table file objects
     173           4 :     class TableFile
     174             :     {
     175             :     public:
     176             :         fs::path filePath;
     177             :         std::vector<std::vector<std::string>> contents;
     178             :         std::map<std::pair<std::size_t, std::size_t>, std::vector<double>> arrays;
     179             :         bool load(EnergyPlusData &state, fs::path const &path); // Note: this returns 'True' if ErrorsFound
     180             :         std::vector<double> &getArray(EnergyPlusData &state, std::pair<std::size_t, std::size_t> colAndRow);
     181             : 
     182             :     private:
     183             :         std::size_t numRows = 0u;
     184             :         std::size_t numColumns = 0u;
     185             :     };
     186             : 
     187             :     // Container for Btwxt N-d Objects
     188        1542 :     class BtwxtManager
     189             :     {
     190             :     public:
     191             :         using json = nlohmann::json;
     192             :         static std::map<std::string, Btwxt::Method> interpMethods;
     193             :         static std::map<std::string, Btwxt::Method> extrapMethods;
     194             :         // Map RGI collection to string name of independent variable list
     195         192 :         int addGrid(const std::string &indVarListName, Btwxt::GriddedData grid)
     196             :         {
     197         192 :             grids.emplace_back(grid);
     198         192 :             gridMap.emplace(indVarListName, grids.size() - 1);
     199         192 :             return static_cast<int>(grids.size()) - 1;
     200             :         };
     201             :         double normalizeGridValues(int gridIndex, int outputIndex, const std::vector<double> &target, double scalar = 1.0);
     202             :         int addOutputValues(int gridIndex, std::vector<double> values);
     203             :         int getGridIndex(EnergyPlusData &state, std::string &indVarListName, bool &ErrorsFound);
     204             :         int getNumGridDims(int gridIndex);
     205             :         double getGridValue(int gridIndex, int outputIndex, const std::vector<double> &target);
     206             :         std::map<std::string, const json &> independentVarRefs;
     207             :         std::map<fs::path, TableFile> tableFiles;
     208             :         void clear();
     209             : 
     210             :     private:
     211             :         std::map<std::string, std::size_t> gridMap;
     212             :         std::vector<Btwxt::RegularGridInterpolator> grids;
     213             :     };
     214             : 
     215             :     void BtwxtMessageCallback(Btwxt::MsgLevel messageType, std::string message, void *contextPtr);
     216             : 
     217             :     void ResetPerformanceCurveOutput(EnergyPlusData &state);
     218             : 
     219             :     Real64 CurveValue(EnergyPlusData &state,
     220             :                       int CurveIndex,                  // index of curve in curve array
     221             :                       Real64 Var1,                     // 1st independent variable
     222             :                       Optional<Real64 const> Var2 = _, // 2nd independent variable
     223             :                       Optional<Real64 const> Var3 = _, // 3rd independent variable
     224             :                       Optional<Real64 const> Var4 = _, // 4th independent variable
     225             :                       Optional<Real64 const> Var5 = _, // 5th independent variable
     226             :                       Optional<Real64 const> Var6 = _  // 6th independent variable
     227             :     );
     228             : 
     229             :     void GetCurveInput(EnergyPlusData &state);
     230             : 
     231             :     void GetCurveInputData(EnergyPlusData &state, bool &ErrorsFound);
     232             : 
     233             :     void InitCurveReporting(EnergyPlusData &state);
     234             : 
     235             :     Real64 PerformanceCurveObject(EnergyPlusData &state,
     236             :                                   int CurveIndex,                  // index of curve in curve array
     237             :                                   Real64 Var1,                     // 1st independent variable
     238             :                                   Optional<Real64 const> Var2 = _, // 2nd independent variable
     239             :                                   Optional<Real64 const> Var3 = _, // 3rd independent variable
     240             :                                   Optional<Real64 const> Var4 = _, // 4th independent variable
     241             :                                   Optional<Real64 const> Var5 = _  // 5th independent variable
     242             :     );
     243             : 
     244             :     Real64 BtwxtTableInterpolation(EnergyPlusData &state,
     245             :                                    int CurveIndex,                  // index of curve in curve array
     246             :                                    Real64 Var1,                     // 1st independent variable
     247             :                                    Optional<Real64 const> Var2 = _, // 2nd independent variable
     248             :                                    Optional<Real64 const> Var3 = _, // 3rd independent variable
     249             :                                    Optional<Real64 const> Var4 = _, // 4th independent variable
     250             :                                    Optional<Real64 const> Var5 = _, // 5th independent variable
     251             :                                    Optional<Real64 const> Var6 = _);
     252             : 
     253             :     bool IsCurveInputTypeValid(std::string const &InInputType); // index of curve in curve array
     254             : 
     255             :     bool IsCurveOutputTypeValid(std::string const &InOutputType); // index of curve in curve array
     256             : 
     257             :     bool CheckCurveDims(EnergyPlusData &state,
     258             :                         int CurveIndex,
     259             :                         std::vector<int> validDims,
     260             :                         std::string_view routineName,
     261             :                         std::string_view objectType,
     262             :                         std::string_view objectName,
     263             :                         std::string_view curveFieldText);
     264             : 
     265             :     std::string GetCurveName(EnergyPlusData &state, int CurveIndex); // index of curve in curve array
     266             : 
     267             :     Real64 GetNormalPoint(int CurveIndex);
     268             : 
     269             :     int GetCurveIndex(EnergyPlusData &state, std::string const &CurveName); // name of the curve
     270             : 
     271             :     // This utility function grabs a curve index and performs the
     272             :     // error checking
     273             : 
     274             :     int GetCurveCheck(EnergyPlusData &state,
     275             :                       std::string const &alph, // curve name
     276             :                       bool &errFlag,
     277             :                       std::string const &ObjName // parent object of curve
     278             :     );
     279             : 
     280             :     void GetCurveMinMaxValues(EnergyPlusData &state,
     281             :                               int CurveIndex,               // index of curve in curve array
     282             :                               Real64 &Var1Min,              // Minimum values of 1st independent variable
     283             :                               Real64 &Var1Max,              // Maximum values of 1st independent variable
     284             :                               Optional<Real64> Var2Min = _, // Minimum values of 2nd independent variable
     285             :                               Optional<Real64> Var2Max = _, // Maximum values of 2nd independent variable
     286             :                               Optional<Real64> Var3Min = _, // Minimum values of 3rd independent variable
     287             :                               Optional<Real64> Var3Max = _, // Maximum values of 3rd independent variable
     288             :                               Optional<Real64> Var4Min = _, // Minimum values of 4th independent variable
     289             :                               Optional<Real64> Var4Max = _, // Maximum values of 4th independent variable
     290             :                               Optional<Real64> Var5Min = _, // Minimum values of 5th independent variable
     291             :                               Optional<Real64> Var5Max = _, // Maximum values of 5th independent variable
     292             :                               Optional<Real64> Var6Min = _, // Minimum values of 6th independent variable
     293             :                               Optional<Real64> Var6Max = _  // Maximum values of 6th independent variable
     294             :     );
     295             : 
     296             :     void SetCurveOutputMinMaxValues(EnergyPlusData &state,
     297             :                                     int CurveIndex,                      // index of curve in curve array
     298             :                                     bool &ErrorsFound,                   // TRUE when errors occur
     299             :                                     Optional<Real64 const> CurveMin = _, // Minimum value of curve output
     300             :                                     Optional<Real64 const> CurveMax = _  // Maximum values of curve output
     301             :     );
     302             : 
     303             :     void GetPressureSystemInput(EnergyPlusData &state);
     304             : 
     305             :     void GetPressureCurveTypeAndIndex(EnergyPlusData &state,
     306             :                                       std::string const &PressureCurveName, // name of the curve
     307             :                                       DataBranchAirLoopPlant::PressureCurveType &PressureCurveType,
     308             :                                       int &PressureCurveIndex);
     309             : 
     310             :     Real64 PressureCurveValue(EnergyPlusData &state, int PressureCurveIndex, Real64 MassFlow, Real64 Density, Real64 Viscosity);
     311             : 
     312             :     Real64 CalculateMoodyFrictionFactor(EnergyPlusData &state, Real64 ReynoldsNumber, Real64 RoughnessRatio);
     313             : 
     314             :     void checkCurveIsNormalizedToOne(EnergyPlusData &state,
     315             :                                      const std::string &callingRoutineObj, // calling routine with object type
     316             :                                      const std::string &objectName,        // parent object where curve is used
     317             :                                      int curveIndex,                       // index to curve object
     318             :                                      const std::string &cFieldName,        // object field name
     319             :                                      const std::string &cFieldValue,       // user input curve name
     320             :                                      Real64 Var1,                          // required 1st independent variable
     321             :                                      Optional<Real64 const> Var2 = _);     // 2nd independent variable
     322             : 
     323             : } // namespace Curve
     324             : 
     325        1542 : struct CurveManagerData : BaseGlobalStruct
     326             : {
     327             :     int NumCurves = 0;
     328             :     bool GetCurvesInputFlag = true;
     329             :     bool CurveValueMyBeginTimeStepFlag = false;
     330             :     bool FrictionFactorErrorHasOccurred = false;
     331             :     Array1D<Curve::PerformanceCurveData> PerfCurve;
     332             :     Curve::BtwxtManager btwxtManager;
     333             :     std::unordered_map<std::string, std::string> UniqueCurveNames;
     334             : 
     335           0 :     void clear_state() override
     336             :     {
     337           0 :         *this = CurveManagerData();
     338           0 :     }
     339             : };
     340             : 
     341             : } // namespace EnergyPlus
     342             : 
     343             : #endif

Generated by: LCOV version 1.13