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 WaterUse_hh_INCLUDED
49 : #define WaterUse_hh_INCLUDED
50 :
51 : // ObjexxFCL Headers
52 : #include <ObjexxFCL/Array1D.hh>
53 :
54 : // EnergyPlus Headers
55 : #include <EnergyPlus/Data/BaseData.hh>
56 : #include <EnergyPlus/DataGlobals.hh>
57 : #include <EnergyPlus/EnergyPlus.hh>
58 : #include <EnergyPlus/Plant/PlantLocation.hh>
59 : #include <EnergyPlus/PlantComponent.hh>
60 :
61 : namespace EnergyPlus {
62 :
63 : // Forward declarations
64 : struct EnergyPlusData;
65 :
66 : namespace WaterUse {
67 :
68 : enum class HeatRecovHX
69 : {
70 : Invalid = -1,
71 : Ideal,
72 : CounterFlow,
73 : CrossFlow,
74 : Num
75 : };
76 :
77 : enum class HeatRecovConfig
78 : {
79 : Invalid = -1,
80 : Plant,
81 : Equipment,
82 : PlantAndEquip,
83 : Num
84 : };
85 :
86 : struct WaterEquipmentType
87 : {
88 : std::string Name; // Name of DHW
89 : std::string EndUseSubcatName;
90 : int Connections = 0; // Index for WATER USE CONNECTIONS object
91 : Real64 PeakVolFlowRate = 0.0; // Peak volumetric flow rate, also water consumption rate (m3/s)
92 : Sched::Schedule *flowRateFracSched = nullptr; // pointer to schedule object // Now it is
93 : Real64 ColdVolFlowRate = 0.0;
94 : Real64 HotVolFlowRate = 0.0;
95 : Real64 TotalVolFlowRate = 0.0; // Volumetric flow rate, also water consumption rate (m3/s)
96 : Real64 ColdMassFlowRate = 0.0;
97 : Real64 HotMassFlowRate = 0.0;
98 : Real64 TotalMassFlowRate = 0.0; // Mass flow rate (kg/s)
99 : Real64 DrainMassFlowRate = 0.0;
100 : Sched::Schedule *coldTempSched = nullptr; // schedule object
101 : Sched::Schedule *hotTempSched = nullptr; // schedule object
102 : Sched::Schedule *targetTempSched = nullptr; // schedule object
103 : Real64 ColdTemp = 0.0; // Cold supply water temperature (C)
104 : Real64 HotTemp = 0.0; // Hot supply water temperature (C)
105 : Real64 TargetTemp = 0.0; // Target (mixed) water temperature (C)
106 : Real64 MixedTemp = 0.0; // Actual outlet (mixed) water temperature (C)
107 : Real64 DrainTemp = 0.0;
108 : int CWHWTempErrorCount = 0; // - counter if hot water temp is less than cold water temp
109 : int CWHWTempErrIndex = 0; // - index to recurring error structure for hot water temp
110 : int TargetHWTempErrorCount = 0; // - counter for target water temp error
111 : int TargetHWTempErrIndex = 0; // - index to recurring error structure for target water temp
112 : int TargetCWTempErrorCount = 0; // - counter for target water temp error
113 : int TargetCWTempErrIndex = 0; // - index to recurring error structure for target water temp
114 : int Zone = 0; // Index for zone object
115 : Sched::Schedule *sensibleFracSched = nullptr; // schedule object
116 : Real64 SensibleRate = 0.0;
117 : Real64 SensibleEnergy = 0.0;
118 : Real64 SensibleRateNoMultiplier = 0.0;
119 : Sched::Schedule *latentFracSched = nullptr; // schedule object
120 : Real64 LatentRate = 0.0;
121 : Real64 LatentEnergy = 0.0;
122 : Real64 LatentRateNoMultiplier = 0.0;
123 : Real64 MoistureRate = 0.0;
124 : Real64 MoistureMass = 0.0;
125 : Real64 ColdVolume = 0.0; // Water consumption (m3)
126 : Real64 HotVolume = 0.0; // Water consumption (m3)
127 : Real64 TotalVolume = 0.0; // Water consumption (m3)
128 : Real64 Power = 0.0; // Heating rate required to meet the mixed water temperature (W)
129 : Real64 Energy = 0.0; // Heating energy required to meet the mixed water temperature (J)
130 : bool setupMyOutputVars = true;
131 : bool allowHotControl = false; // only certain configurations will use hot water flow and/or hot water temp schedule
132 :
133 : // Reset Some Values to Zeros
134 2 : void reset()
135 : {
136 2 : SensibleRate = 0.0;
137 2 : SensibleEnergy = 0.0;
138 2 : LatentRate = 0.0;
139 2 : LatentEnergy = 0.0;
140 2 : MixedTemp = 0.0;
141 2 : TotalMassFlowRate = 0.0;
142 2 : DrainTemp = 0.0;
143 2 : }
144 :
145 : void CalcEquipmentFlowRates(EnergyPlusData &state);
146 :
147 : void CalcEquipmentDrainTemp(EnergyPlusData &state);
148 :
149 : void setupOutputVars(EnergyPlusData &state);
150 : };
151 :
152 : struct WaterConnectionsType : PlantComponent
153 : {
154 : std::string Name; // Name of DHW
155 : bool Init = true; // Flag for initialization: TRUE means do the init
156 : bool StandAlone = false; // Flag for operation with no plant connections
157 : int InletNode = 0; // Hot water demand node
158 : int OutletNode = 0; // Cold water supply node
159 : int SupplyTankNum = 0;
160 : int RecoveryTankNum = 0;
161 : int TankDemandID = 0; // array to request flow from supply tank
162 : int TankSupplyID = 0; // array to send flow to recovery tank
163 : bool HeatRecovery = false;
164 : HeatRecovHX HeatRecoveryHX = HeatRecovHX::Ideal;
165 : HeatRecovConfig HeatRecoveryConfig = HeatRecovConfig::Plant;
166 : Real64 HXUA = 0.0;
167 : Real64 Effectiveness = 0.0;
168 : Real64 RecoveryRate = 0.0;
169 : Real64 RecoveryEnergy = 0.0;
170 : Real64 TankMassFlowRate = 0.0; // Mass flow rate (kg/s)
171 : Real64 ColdMassFlowRate = 0.0; // Mass flow rate (kg/s) cold = mains + tank
172 : Real64 HotMassFlowRate = 0.0; // Mass flow rate (kg/s)
173 : Real64 TotalMassFlowRate = 0.0; // Mass flow rate (kg/s) total = cold + hot
174 : Real64 DrainMassFlowRate = 0.0;
175 : Real64 RecoveryMassFlowRate = 0.0;
176 : Real64 PeakVolFlowRate = 0.0; // Volumetric flow rate, also water consumption rate (m3/s)
177 : Real64 TankVolFlowRate = 0.0; // Volumetric flow rate, also water consumption rate (m3/s)
178 : Real64 ColdVolFlowRate = 0.0; // Volumetric flow rate, also water consumption rate (m3/s)
179 : Real64 HotVolFlowRate = 0.0; // Volumetric flow rate, also water consumption rate (m3/s)
180 : Real64 TotalVolFlowRate = 0.0; // Volumetric flow rate, also water consumption rate (m3/s)
181 : Real64 DrainVolFlowRate = 0.0;
182 : Real64 PeakMassFlowRate = 0.0; // Peak Mass flow rate for MassFlowRateMax
183 : Sched::Schedule *coldTempSched = nullptr; // schedule object
184 : Sched::Schedule *hotTempSched = nullptr; // schedule object
185 : Real64 TankTemp = 0.0; // Cold supply water temperature (C)
186 : Real64 ColdSupplyTemp = 0.0; // cold from mains, schedule, or tank, depending
187 : Real64 ColdTemp = 0.0; // Cold supply water temperature (C) actual cold (could be reheated)
188 : Real64 HotTemp = 0.0; // Hot supply water temperature (C)
189 : Real64 DrainTemp = 0.0;
190 : Real64 RecoveryTemp = 0.0;
191 : Real64 ReturnTemp = 0.0;
192 : Real64 WasteTemp = 0.0;
193 : Real64 TempError = 0.0;
194 : Real64 TankVolume = 0.0; // Water consumption (m3)
195 : Real64 ColdVolume = 0.0; // Water consumption (m3)
196 : Real64 HotVolume = 0.0; // Water consumption (m3)
197 : Real64 TotalVolume = 0.0; // Water consumption (m3)
198 : Real64 Power = 0.0; // Heating rate required to raise temperature from cold to hot (W)
199 : Real64 Energy = 0.0; // Heating energy required to raise temperature from cold to hot (J)
200 : int NumWaterEquipment = 0;
201 : int MaxIterationsErrorIndex = 0; // recurring error index
202 : Array1D_int myWaterEquipArr;
203 : PlantLocation plantLoc{};
204 : bool MyEnvrnFlag = true;
205 :
206 : static PlantComponent *factory(EnergyPlusData &state, std::string const &objectName);
207 :
208 : void simulate([[maybe_unused]] EnergyPlusData &state,
209 : const PlantLocation &calledFromLocation,
210 : bool FirstHVACIteration,
211 : Real64 &CurLoad,
212 : bool RunFlag) override;
213 :
214 : void InitConnections(EnergyPlusData &state);
215 :
216 : void CalcConnectionsFlowRates(EnergyPlusData &state, bool FirstHVACIteration);
217 :
218 : void CalcConnectionsDrainTemp(EnergyPlusData &state);
219 :
220 : void CalcConnectionsHeatRecovery(EnergyPlusData &state);
221 :
222 : void UpdateWaterConnections(EnergyPlusData &state);
223 :
224 : void ReportWaterUse(EnergyPlusData &state);
225 :
226 : void setupOutputVars([[maybe_unused]] EnergyPlusData &state);
227 :
228 : void oneTimeInit(EnergyPlusData &state) override;
229 :
230 : void oneTimeInit_new(EnergyPlusData &state) override;
231 : };
232 :
233 : void SimulateWaterUse(EnergyPlusData &state, bool FirstHVACIteration);
234 :
235 : void GetWaterUseInput(EnergyPlusData &state);
236 :
237 : void ReportStandAloneWaterUse(EnergyPlusData &state);
238 :
239 : void CalcWaterUseZoneGains(EnergyPlusData &state);
240 :
241 : Real64 calcH2ODensity(EnergyPlusData &state);
242 :
243 : } // namespace WaterUse
244 :
245 : struct WaterUseData : BaseGlobalStruct
246 : {
247 :
248 : int numWaterEquipment = 0;
249 : int numWaterConnections = 0;
250 : bool getWaterUseInputFlag = true;
251 : bool calcRhoH2O = true;
252 : bool MyEnvrnFlagLocal = true;
253 : Real64 rhoH2OStd = 1000.0;
254 : Array1D_bool CheckEquipName;
255 : EPVector<WaterUse::WaterEquipmentType> WaterEquipment;
256 : EPVector<WaterUse::WaterConnectionsType> WaterConnections;
257 :
258 2126 : void init_constant_state([[maybe_unused]] EnergyPlusData &state) override
259 : {
260 2126 : }
261 :
262 1152 : void init_state([[maybe_unused]] EnergyPlusData &state) override
263 : {
264 1152 : }
265 :
266 2100 : void clear_state() override
267 : {
268 2100 : new (this) WaterUseData();
269 2100 : }
270 : };
271 :
272 : } // namespace EnergyPlus
273 :
274 : #endif
|