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 : #ifndef GeneralRoutines_hh_INCLUDED
49 : #define GeneralRoutines_hh_INCLUDED
50 :
51 : // ObjexxFCL Headers
52 : #include <ObjexxFCL/Array2S.hh>
53 : #include <ObjexxFCL/Optional.hh>
54 :
55 : // EnergyPlus Headers
56 : #include <EnergyPlus/Data/BaseData.hh>
57 : #include <EnergyPlus/EnergyPlus.hh>
58 : #include <EnergyPlus/Plant/Enums.hh>
59 : #include <EnergyPlus/Plant/PlantLocation.hh>
60 : #include <EnergyPlus/ScheduleManager.hh>
61 :
62 : namespace EnergyPlus {
63 :
64 : // Forward declarations
65 : struct EnergyPlusData;
66 :
67 : struct IntervalHalf
68 : {
69 : // Members
70 : Real64 MaxFlow;
71 : Real64 MinFlow;
72 : Real64 MaxResult;
73 : Real64 MinResult;
74 : Real64 MidFlow;
75 : Real64 MidResult;
76 : bool MaxFlowCalc;
77 : bool MinFlowCalc;
78 : bool MinFlowResult;
79 : bool NormFlowCalc;
80 :
81 : // Default Constructor
82 : IntervalHalf() = default;
83 :
84 : // Member Constructor
85 2129 : IntervalHalf(Real64 const MaxFlow,
86 : Real64 const MinFlow,
87 : Real64 const MaxResult,
88 : Real64 const MinResult,
89 : Real64 const MidFlow,
90 : Real64 const MidResult,
91 : bool const MaxFlowCalc,
92 : bool const MinFlowCalc,
93 : bool const MinFlowResult,
94 : bool const NormFlowCalc)
95 2129 : : MaxFlow(MaxFlow), MinFlow(MinFlow), MaxResult(MaxResult), MinResult(MinResult), MidFlow(MidFlow), MidResult(MidResult),
96 2129 : MaxFlowCalc(MaxFlowCalc), MinFlowCalc(MinFlowCalc), MinFlowResult(MinFlowResult), NormFlowCalc(NormFlowCalc)
97 : {
98 2129 : }
99 : };
100 :
101 : struct ZoneEquipControllerProps
102 : {
103 : // Members
104 : Real64 SetPoint; // Desired setpoint;
105 : Real64 MaxSetPoint; // The maximum setpoint; either user input or reset per time step by simulation
106 : Real64 MinSetPoint; // The minimum setpoint; either user input or reset per time step by simulation
107 : Real64 SensedValue; // The sensed control variable of any type
108 : Real64 CalculatedSetPoint; // The Calculated SetPoint or new control actuated value
109 :
110 : // Default Constructor
111 : ZoneEquipControllerProps() = default;
112 :
113 : // Member Constructor
114 2129 : ZoneEquipControllerProps(Real64 const SetPoint, // Desired setpoint;
115 : Real64 const MaxSetPoint, // The maximum setpoint; either user input or reset per time step by simulation
116 : Real64 const MinSetPoint, // The minimum setpoint; either user input or reset per time step by simulation
117 : Real64 const SensedValue, // The sensed control variable of any type
118 : Real64 const CalculatedSetPoint // The Calculated SetPoint or new control actuated value
119 : )
120 2129 : : SetPoint(SetPoint), MaxSetPoint(MaxSetPoint), MinSetPoint(MinSetPoint), SensedValue(SensedValue), CalculatedSetPoint(CalculatedSetPoint)
121 : {
122 2129 : }
123 : };
124 :
125 : void ControlCompOutput(EnergyPlusData &state,
126 : std::string const &CompName, // the component Name
127 : std::string const &CompType, // Type of component
128 : int &CompNum, // Index of component in component array
129 : bool const FirstHVACIteration, // flag for 1st HVAV iteration in the time step
130 : Real64 const QZnReq, // zone load to be met
131 : int const ActuatedNode, // node that controls unit output
132 : Real64 const MaxFlow, // maximum water flow
133 : Real64 const MinFlow, // minimum water flow
134 : Real64 const ControlOffset, // really the tolerance
135 : int &ControlCompTypeNum, // Internal type num for CompType
136 : int &CompErrIndex, // for Recurring error call
137 : ObjexxFCL::Optional_int_const TempInNode = _, // inlet node for output calculation
138 : ObjexxFCL::Optional_int_const TempOutNode = _, // outlet node for output calculation
139 : ObjexxFCL::Optional<Real64 const> AirMassFlow = _, // air mass flow rate
140 : ObjexxFCL::Optional_int_const Action = _, // 1=reverse; 2=normal
141 : ObjexxFCL::Optional_int_const EquipIndex = _, // Identifier for equipment of Outdoor Air Unit "ONLY"
142 : PlantLocation const &plantLoc = {}, // for plant components, Location
143 : ObjexxFCL::Optional_int_const ControlledZoneIndex = _ // controlled zone index for the zone containing the component
144 : );
145 :
146 : bool BBConvergeCheck(int const SimCompNum, Real64 const MaxFlow, Real64 const MinFlow);
147 :
148 : void CheckSysSizing(EnergyPlusData &state,
149 : std::string_view const CompType, // Component Type (e.g. Chiller:Electric)
150 : std::string const &CompName // Component Name (e.g. Big Chiller)
151 : );
152 :
153 : void CheckThisAirSystemForSizing(EnergyPlusData &state, int const AirLoopNum, bool &AirLoopWasSized);
154 :
155 : void CheckZoneSizing(EnergyPlusData &state,
156 : std::string_view CompType, // Component Type (e.g. Chiller:Electric)
157 : std::string_view CompName // Component Name (e.g. Big Chiller)
158 : );
159 :
160 : void CheckThisZoneForSizing(EnergyPlusData &state,
161 : int const ZoneNum, // zone index to be checked
162 : bool &ZoneWasSized);
163 :
164 : void ValidateComponent(EnergyPlusData &state,
165 : std::string_view CompType, // Component Type (e.g. Chiller:Electric)
166 : std::string const &CompName, // Component Name (e.g. Big Chiller)
167 : bool &IsNotOK, // .TRUE. if this component pair is invalid
168 : std::string_view CallString // Context of this pair -- for error message
169 : );
170 :
171 : void ValidateComponent(EnergyPlusData &state,
172 : std::string_view CompType, // Component Type (e.g. Chiller:Electric)
173 : std::string const &CompValType, // Component "name" field type
174 : std::string const &CompName, // Component Name (e.g. Big Chiller)
175 : bool &IsNotOK, // .TRUE. if this component pair is invalid
176 : std::string_view CallString // Context of this pair -- for error message
177 : );
178 :
179 : // Why is this in GeneralRoutines? Asking for a friend
180 : void CalcBasinHeaterPower(EnergyPlusData &state,
181 : Real64 const Capacity, // Basin heater capacity per degree C below setpoint (W/C)
182 : Sched::Schedule *sched, // Pointer to basin heater schedule
183 : Real64 const SetPointTemp, // setpoint temperature for basin heater operation (C)
184 : Real64 &Power // Basin heater power (W)
185 : );
186 :
187 : void TestAirPathIntegrity(EnergyPlusData &state, bool &ErrFound);
188 :
189 : void TestSupplyAirPathIntegrity(EnergyPlusData &state, bool &ErrFound);
190 :
191 : void TestReturnAirPathIntegrity(EnergyPlusData &state, bool &ErrFound, Array2S_int ValRetAPaths);
192 :
193 : void CalcComponentSensibleLatentOutput(Real64 const MassFlow, // air mass flow rate, {kg/s}
194 : Real64 const TDB2, // dry-bulb temperature at state 2 {C}
195 : Real64 const W2, // humidity ratio at state 2
196 : Real64 const TDB1, // dry-bulb temperature at at state 1 {C}
197 : Real64 const W1, // humidity ratio at state 1
198 : Real64 &SensibleOutput, // sensible output rate (state 2 -> State 1), {W}
199 : Real64 &LatentOutput, // latent output rate (state 2 -> State 1), {W}
200 : Real64 &TotalOutput // total = sensible + latent putput rate (state 2 -> State 1), {W}
201 : );
202 :
203 : void CalcZoneSensibleLatentOutput(Real64 const MassFlow, // air mass flow rate, {kg/s}
204 : Real64 const TDBEquip, // dry-bulb temperature at equipment outlet {C}
205 : Real64 const WEquip, // humidity ratio at equipment outlet
206 : Real64 const TDBZone, // dry-bulb temperature at zone air node {C}
207 : Real64 const WZone, // humidity ratio at zone air node
208 : Real64 &SensibleOutput, // sensible output rate (state 2 -> State 1), {W}
209 : Real64 &LatentOutput, // latent output rate (state 2 -> State 1), {W}
210 : Real64 &TotalOutput // total = sensible + latent putput rate (state 2 -> State 1), {W}
211 : );
212 :
213 : Real64 calcZoneSensibleOutput(Real64 const MassFlow, // air mass flow rate, {kg/s}
214 : Real64 const TDBEquip, // dry-bulb temperature at equipment outlet {C}
215 : Real64 const TDBZone, // dry-bulb temperature at zone air node {C}
216 : Real64 const WZone);
217 :
218 : struct GeneralRoutinesData : BaseGlobalStruct
219 : {
220 :
221 : bool MyICSEnvrnFlag = true;
222 : IntervalHalf ZoneInterHalf = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, false, false, false, false};
223 : ZoneEquipControllerProps ZoneController = {0.0, 0.0, 0.0, 0.0, 0.0};
224 :
225 2126 : void init_constant_state([[maybe_unused]] EnergyPlusData &state) override
226 : {
227 2126 : }
228 :
229 1152 : void init_state([[maybe_unused]] EnergyPlusData &state) override
230 : {
231 1152 : }
232 :
233 2100 : void clear_state() override
234 : {
235 2100 : this->MyICSEnvrnFlag = true;
236 2100 : }
237 : };
238 :
239 : } // namespace EnergyPlus
240 :
241 : #endif
|