OpenSimula 0.8.10__tar.gz → 0.10.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. {opensimula-0.8.10/src/opensimula.egg-info → opensimula-0.10.0}/PKG-INFO +15 -1
  2. {opensimula-0.8.10 → opensimula-0.10.0}/README.md +12 -0
  3. {opensimula-0.8.10 → opensimula-0.10.0}/pyproject.toml +10 -1
  4. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/Project.py +44 -7
  5. opensimula-0.10.0/src/opensimula/components/Boiler.py +125 -0
  6. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Building.py +7 -1
  7. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Calculator.py +15 -3
  8. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/File_data.py +4 -8
  9. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/HVAC_DX_system.py +1 -1
  10. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/HVAC_MZW_system.py +53 -8
  11. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/HVAC_SZW_system.py +9 -7
  12. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/HVAC_perfect_system.py +1 -1
  13. opensimula-0.10.0/src/opensimula/components/HVAC_water_circuit.py +224 -0
  14. opensimula-0.10.0/src/opensimula/components/HVAC_water_generator.py +251 -0
  15. opensimula-0.10.0/src/opensimula/components/HVAC_water_system.py +662 -0
  16. opensimula-0.10.0/src/opensimula/components/Load_space.py +198 -0
  17. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Space.py +12 -182
  18. opensimula-0.10.0/src/opensimula/components/Thermal_zone.py +298 -0
  19. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/__init__.py +7 -0
  20. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/editor/__init__.py +2 -0
  21. opensimula-0.10.0/src/opensimula/editor/results.py +312 -0
  22. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/editor/static/editor.css +177 -1
  23. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/editor/static/editor.js +589 -73
  24. opensimula-0.10.0/src/opensimula/editor/static/plotly3d.js +1966 -0
  25. opensimula-0.10.0/src/opensimula/editor/static/results.css +360 -0
  26. opensimula-0.10.0/src/opensimula/editor/static/results.js +4 -0
  27. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/editor/widget.py +12 -2
  28. opensimula-0.10.0/src/opensimula/examples/01_schedules.json +70 -0
  29. opensimula-0.10.0/src/opensimula/examples/02_weather.json +98 -0
  30. opensimula-0.10.0/src/opensimula/examples/03_walls.json +310 -0
  31. opensimula-0.10.0/src/opensimula/examples/04_windows_and_gains.json +369 -0
  32. opensimula-0.10.0/src/opensimula/examples/05_ideal_system.json +402 -0
  33. opensimula-0.10.0/src/opensimula/examples/06_dx_system.json +423 -0
  34. opensimula-0.10.0/src/opensimula/examples/07_fan_coil.json +471 -0
  35. opensimula-0.10.0/src/opensimula/examples/08_load_records.json +180 -0
  36. opensimula-0.10.0/src/opensimula/examples/09_water_plant.json +305 -0
  37. opensimula-0.10.0/src/opensimula/examples/__init__.py +1 -0
  38. opensimula-0.10.0/src/opensimula/examples/office_loads.csv +8761 -0
  39. opensimula-0.10.0/src/opensimula/examples/sevilla.met +8762 -0
  40. opensimula-0.10.0/src/opensimula/gui/__init__.py +119 -0
  41. opensimula-0.10.0/src/opensimula/gui/app.py +213 -0
  42. {opensimula-0.8.10 → opensimula-0.10.0/src/opensimula.egg-info}/PKG-INFO +15 -1
  43. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula.egg-info/SOURCES.txt +35 -0
  44. opensimula-0.10.0/src/opensimula.egg-info/entry_points.txt +2 -0
  45. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula.egg-info/requires.txt +3 -0
  46. opensimula-0.10.0/test/test_Boiler.py +65 -0
  47. opensimula-0.10.0/test/test_Calculator.py +73 -0
  48. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_Case_600FF.py +11 -3
  49. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_Case_610.py +4 -4
  50. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_File_data.py +17 -0
  51. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_HVAC_DX_system.py +11 -11
  52. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_HVAC_FAN_COIL_water_system.py +24 -18
  53. opensimula-0.10.0/test/test_HVAC_MZW_water_system.py +103 -0
  54. opensimula-0.10.0/test/test_HVAC_water_circuit.py +140 -0
  55. opensimula-0.10.0/test/test_HVAC_water_generator.py +117 -0
  56. opensimula-0.10.0/test/test_HVAC_water_header.py +170 -0
  57. opensimula-0.10.0/test/test_HVAC_water_sequencing.py +135 -0
  58. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_HVAC_water_system_process.py +58 -23
  59. opensimula-0.10.0/test/test_Load_space.py +123 -0
  60. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_Project.py +16 -0
  61. opensimula-0.10.0/test/test_Thermal_zone.py +28 -0
  62. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_editor_widget.py +32 -4
  63. opensimula-0.10.0/test/test_examples.py +133 -0
  64. opensimula-0.10.0/test/test_gui.py +65 -0
  65. opensimula-0.10.0/test/test_results_viewer.py +233 -0
  66. opensimula-0.8.10/src/opensimula/components/HVAC_water_system.py +0 -314
  67. opensimula-0.8.10/test/test_Calculator.py +0 -40
  68. {opensimula-0.8.10 → opensimula-0.10.0}/LICENSE +0 -0
  69. {opensimula-0.8.10 → opensimula-0.10.0}/setup.cfg +0 -0
  70. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/Child.py +0 -0
  71. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/Component.py +0 -0
  72. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/Iterative_process.py +0 -0
  73. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/Message.py +0 -0
  74. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/Parameter_container.py +0 -0
  75. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/Parameters.py +0 -0
  76. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/Simulation.py +0 -0
  77. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/Variable.py +0 -0
  78. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/__init__.py +0 -0
  79. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Building_surface.py +0 -0
  80. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Chiller_heat_pump.py +0 -0
  81. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Construction.py +0 -0
  82. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/DX_unit.py +0 -0
  83. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Day_schedule.py +0 -0
  84. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Fan.py +0 -0
  85. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/File_met.py +0 -0
  86. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Frame.py +0 -0
  87. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Glazing.py +0 -0
  88. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Material.py +0 -0
  89. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Opening.py +0 -0
  90. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Opening_type.py +0 -0
  91. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Pump.py +0 -0
  92. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Solar_surface.py +0 -0
  93. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Space_type.py +0 -0
  94. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Surface.py +0 -0
  95. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Test_component.py +0 -0
  96. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Water_coil.py +0 -0
  97. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Week_schedule.py +0 -0
  98. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/components/Year_schedule.py +0 -0
  99. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/editor/schema.py +0 -0
  100. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/editor/validation.py +0 -0
  101. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/visual_3D/Environment_3D.py +0 -0
  102. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula/visual_3D/Polygon_3D.py +0 -0
  103. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula.egg-info/dependency_links.txt +0 -0
  104. {opensimula-0.8.10 → opensimula-0.10.0}/src/opensimula.egg-info/top_level.txt +0 -0
  105. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_Construction.py +0 -0
  106. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_File_met.py +0 -0
  107. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_HVAC_DX_Equipment.py +0 -0
  108. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_Iterative_process.py +0 -0
  109. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_Schedules.py +0 -0
  110. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_editor_schema.py +0 -0
  111. {opensimula-0.8.10 → opensimula-0.10.0}/test/test_underground_repeated_simulation.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opensimula
3
- Version: 0.8.10
3
+ Version: 0.10.0
4
4
  Summary: Component-based time simulation environment in Python
5
5
  Author: Luis Pérez-Lombard, Ismael R. Maestre
6
6
  Author-email: "Juan F. Coronel" <jfc@us.es>
@@ -20,6 +20,8 @@ Requires-Dist: psychrolib>=2.5.0
20
20
  Requires-Dist: scipy>=1.16.2
21
21
  Requires-Dist: shapely>=2.1.1
22
22
  Requires-Dist: tqdm>=4.67.1
23
+ Provides-Extra: gui
24
+ Requires-Dist: marimo>=0.19.0; extra == "gui"
23
25
  Dynamic: license-file
24
26
 
25
27
  ![Logo](https://jfcoronel.github.io/OpenSimula/img/logo_opensimula.png)
@@ -127,6 +129,18 @@ each component's own schema, together with an interactive 3D view of the buildin
127
129
 
128
130
  ![Project editor example](https://jfcoronel.github.io/OpenSimula/img/editor_3d.png)
129
131
 
132
+ The editor, a results viewer and a Simulate button also come together in an app that opens in
133
+ the browser, with no notebook to write ([details](https://jfcoronel.github.io/OpenSimula/user_guide/#opensimula-app)):
134
+
135
+ ```bash
136
+ pip install "opensimula[gui]"
137
+ opensimula gui project.json
138
+ ```
139
+
140
+ To start, nine progressive [examples](https://jfcoronel.github.io/OpenSimula/examples/), from a
141
+ schedule to a water plant with a heat pump and a boiler, come with the package: `opensimula examples` copies them to
142
+ a folder, ready to open with `opensimula gui`.
143
+
130
144
  ## Component types
131
145
 
132
146
  Components are grouped by what they define:
@@ -103,6 +103,18 @@ each component's own schema, together with an interactive 3D view of the buildin
103
103
 
104
104
  ![Project editor example](https://jfcoronel.github.io/OpenSimula/img/editor_3d.png)
105
105
 
106
+ The editor, a results viewer and a Simulate button also come together in an app that opens in
107
+ the browser, with no notebook to write ([details](https://jfcoronel.github.io/OpenSimula/user_guide/#opensimula-app)):
108
+
109
+ ```bash
110
+ pip install "opensimula[gui]"
111
+ opensimula gui project.json
112
+ ```
113
+
114
+ To start, nine progressive [examples](https://jfcoronel.github.io/OpenSimula/examples/), from a
115
+ schedule to a water plant with a heat pump and a boiler, come with the package: `opensimula examples` copies them to
116
+ a folder, ready to open with `opensimula gui`.
117
+
106
118
  ## Component types
107
119
 
108
120
  Components are grouped by what they define:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "opensimula"
3
- version = "0.8.10"
3
+ version = "0.10.0"
4
4
  requires-python = ">=3.12"
5
5
  authors = [
6
6
  { name="Juan F. Coronel", email="jfc@us.es" },
@@ -27,6 +27,13 @@ dependencies = [
27
27
  "tqdm>=4.67.1",
28
28
  ]
29
29
 
30
+ [project.optional-dependencies]
31
+ # the app started by `opensimula gui`
32
+ gui = ["marimo>=0.19.0"]
33
+
34
+ [project.scripts]
35
+ opensimula = "opensimula.gui:main"
36
+
30
37
  [dependency-groups]
31
38
  dev = [
32
39
  "ipykernel>=6.30.1",
@@ -45,6 +52,8 @@ where = ["src"]
45
52
  [tool.setuptools.package-data]
46
53
  # The widget loads these at runtime; without this they are left out of the wheel.
47
54
  "opensimula.editor" = ["static/*.js", "static/*.css"]
55
+ # the examples copied by `opensimula examples`
56
+ "opensimula.examples" = ["*.json", "*.met", "*.csv"]
48
57
 
49
58
  [build-system]
50
59
  requires = ["setuptools>=61.2", "wheel"]
@@ -4,6 +4,7 @@ import numpy as np
4
4
  import pandas as pd
5
5
  import psychrolib as sicro
6
6
  from tqdm import trange
7
+ from opensimula.Component import Component
7
8
  from opensimula.Message import Message
8
9
  from opensimula.Parameter_container import Parameter_container
9
10
  from opensimula.Parameters import (
@@ -205,13 +206,13 @@ class Project(Parameter_container):
205
206
  Component: The new component with its default parameters, None if the type
206
207
  does not exist.
207
208
  """
208
- try:
209
- clase = globals()[comp_type]
210
- comp = clase(name, self)
211
- self._components_.append(comp)
212
- return comp
213
- except KeyError:
209
+ # globals() also holds modules (e.g. the base class module Thermal_zone)
210
+ clase = globals().get(comp_type)
211
+ if not (isinstance(clase, type) and issubclass(clase, Component)) or clase is Component:
214
212
  return None
213
+ comp = clase(name, self)
214
+ self._components_.append(comp)
215
+ return comp
215
216
 
216
217
  def duplicate_component(self, component_name, new_name):
217
218
  """Duplicate an existing component with a new name
@@ -499,13 +500,21 @@ class Project(Parameter_container):
499
500
 
500
501
  return errors
501
502
 
502
- def simulate(self):
503
+ def simulate(self, progress=None):
503
504
  """Run the time simulation of the project
504
505
 
505
506
  Orders the components, runs pre_simulation() on them and then, for each of the
506
507
  `n_time_steps` time steps, the pre-iteration, the iterations until every component
507
508
  converges (at most `n_max_iteration`) and the post-iteration. Results are stored in
508
509
  the variables of the components.
510
+
511
+ The progress is printed with a tqdm bar; `progress` reports it elsewhere as well,
512
+ such as a progress bar of a notebook or an app.
513
+
514
+ Args:
515
+ progress (callable, optional): called after each time step as
516
+ `progress(step, n_time_steps)`, with step from 1 to n_time_steps.
517
+ Defaults to None.
509
518
  """
510
519
  n = self.parameter("n_time_steps").value
511
520
  date = dt.datetime.strptime(
@@ -585,6 +594,8 @@ class Project(Parameter_container):
585
594
  self._sim_df.at[i, "converged"] = converge
586
595
  self._post_iteration_(i, date, daylight_saving, converge)
587
596
  date = date + dt.timedelta(0, delta_t)
597
+ if progress is not None:
598
+ progress(i + 1, n)
588
599
 
589
600
  n_not_converged = (
590
601
  len(self._sim_df["converged"]) - self._sim_df["converged"].sum()
@@ -675,6 +686,32 @@ class Project(Parameter_container):
675
686
 
676
687
  return ProjectEditor(self)
677
688
 
689
+ def results(self, *variables, height=600, chart_height=300, show_3d=False):
690
+ """Interactive viewer of the simulation results.
691
+
692
+ Returns an anywidget that works in Jupyter and, wrapped in
693
+ mo.ui.anywidget(), in Marimo: the variables of the components are listed
694
+ on the left and the selected ones plotted on the right, one chart per
695
+ unit, with the frequency, aggregation and interval chosen in its toolbar.
696
+
697
+ Args:
698
+ *variables (str): variables to show from the start, as
699
+ "component.variable", e.g. "spaces_1.temperature".
700
+ height (int, optional): height of the whole widget, in pixels. Defaults to 600.
701
+ chart_height (int, optional): height of each chart, in pixels. Defaults to 300.
702
+ show_3d (bool, optional): show the 3D view of the project above the
703
+ charts; clicking a surface there opens its variables. Defaults to False.
704
+
705
+ Returns:
706
+ ResultsViewer: widget; its dataframe() method returns what it shows.
707
+ """
708
+ from opensimula.editor import ResultsViewer
709
+
710
+ viewer = ResultsViewer(self, height=height, chart_height=chart_height, show_3d=show_3d)
711
+ if variables:
712
+ viewer.select(*variables)
713
+ return viewer
714
+
678
715
  def create_3D_environment(self, env_3D):
679
716
  """Add the polygons of the project's surfaces and openings to a 3D environment
680
717
 
@@ -0,0 +1,125 @@
1
+ from opensimula.Component import Component
2
+ from opensimula.Message import Message
3
+ from opensimula.Parameters import (
4
+ Parameter_float,
5
+ Parameter_float_list,
6
+ Parameter_math_exp,
7
+ Parameter_options,
8
+ )
9
+
10
+ FUELS = ["NATURAL_GAS", "LPG", "DIESEL", "BIOMASS", "ELECTRICITY"]
11
+
12
+
13
+ class Boiler(Component):
14
+ """Boiler equipment manufacturer information.
15
+
16
+ Equipment data, like DX_unit or Chiller_heat_pump: it is not simulated by
17
+ itself but used by a water generator to know the heat it can give and the
18
+ fuel it uses. Capacities, powers and efficiencies are on the lower heating
19
+ value (LHV) of the fuel.
20
+
21
+ The efficiency is the nominal one multiplied by ``efficiency_expression``, a
22
+ function of the part load ``F_load`` and of the water temperatures, return
23
+ ``T_wi`` and supply ``T_wo``, and of the water flow fraction ``F_water``: a
24
+ condensing boiler is more efficient with a cold return.
25
+ """
26
+
27
+ def __init__(self, name, project):
28
+ Component.__init__(self, name, project)
29
+ self.parameter("type").value = "Boiler"
30
+ self.parameter("description").value = "Boiler equipment manufacturer information"
31
+ self.add_parameter(Parameter_options("fuel", "NATURAL_GAS", FUELS))
32
+ self.add_parameter(Parameter_float("nominal_heating_capacity", 0, "W", min=0))
33
+ self.add_parameter(Parameter_float("nominal_efficiency", 0.9, "frac", min=0.01))
34
+ self.add_parameter(Parameter_float("nominal_water_flow", 1, "dm³/s", min=0))
35
+ self.add_parameter(Parameter_float("max_supply_temperature", 80, "°C"))
36
+ self.add_parameter(Parameter_math_exp("efficiency_expression", "1", "frac"))
37
+ self.add_parameter(Parameter_float("auxiliary_power", 0, "W", min=0))
38
+ # T_wi, T_wo, F_water, F_load
39
+ self.add_parameter(Parameter_float_list("expression_max_values", [100, 100, 1.5, 1], "-"))
40
+ self.add_parameter(Parameter_float_list("expression_min_values", [0, 0, 0, 0], "-"))
41
+
42
+ def check(self):
43
+ errors = super().check()
44
+ for key in ("expression_max_values", "expression_min_values"):
45
+ if len(self.parameter(key).value) != 4:
46
+ msg = f"Error: {self.parameter('name').value}, {key} size must be 4 (T_wi, T_wo, F_water, F_load)"
47
+ errors.append(Message(msg, "ERROR"))
48
+ return errors
49
+
50
+ def get_heating_load(self, T_wo, T_wi, water_flow, Q_required):
51
+ """Heat the boiler gives for a required load.
52
+
53
+ Args:
54
+ T_wo (float): supply (outlet) water temperature (°C).
55
+ T_wi (float): return (inlet) water temperature (°C).
56
+ water_flow (float): water flow (dm³/s).
57
+ Q_required (float): heat required (W).
58
+
59
+ Returns:
60
+ tuple: (Q, F_load), heat given (W), at most the nominal capacity, and part
61
+ load fraction (0-1). (0, 0) if no heat is required, the capacity is 0
62
+ or the supply temperature is above the maximum.
63
+ """
64
+ capacity = self.parameter("nominal_heating_capacity").value
65
+ if Q_required <= 0 or capacity <= 0:
66
+ return (0, 0)
67
+ if T_wo > self.parameter("max_supply_temperature").value:
68
+ return (0, 0)
69
+ if Q_required >= capacity:
70
+ return (capacity, 1)
71
+ return (Q_required, Q_required / capacity)
72
+
73
+ def get_efficiency(self, T_wo, T_wi, water_flow, F_load):
74
+ """Efficiency on the LHV at the given conditions.
75
+
76
+ Args:
77
+ T_wo (float): supply water temperature (°C).
78
+ T_wi (float): return water temperature (°C).
79
+ water_flow (float): water flow (dm³/s).
80
+ F_load (float): part load fraction (0-1).
81
+
82
+ Returns:
83
+ float: efficiency (heat given / fuel power).
84
+ """
85
+ F_water = water_flow / self.parameter("nominal_water_flow").value
86
+ var_dic = self._var_state_dic([T_wi, T_wo, F_water, F_load])
87
+ return self.parameter("nominal_efficiency").value * self.parameter(
88
+ "efficiency_expression"
89
+ ).evaluate(var_dic)
90
+
91
+ def get_fuel_power(self, T_wo, T_wi, water_flow, Q_required):
92
+ """Fuel the boiler uses for a required load.
93
+
94
+ Args:
95
+ T_wo (float): supply water temperature (°C).
96
+ T_wi (float): return water temperature (°C).
97
+ water_flow (float): water flow (dm³/s).
98
+ Q_required (float): heat required (W).
99
+
100
+ Returns:
101
+ tuple: (fuel_power, efficiency), fuel power on the LHV (W) and efficiency;
102
+ (0, 0) if the boiler gives no heat.
103
+ """
104
+ Q, F_load = self.get_heating_load(T_wo, T_wi, water_flow, Q_required)
105
+ if Q == 0:
106
+ return (0, 0)
107
+ efficiency = self.get_efficiency(T_wo, T_wi, water_flow, F_load)
108
+ return (Q / efficiency, efficiency)
109
+
110
+ def get_auxiliary_power(self, Q):
111
+ """Electric power of the burner fan and controls.
112
+
113
+ Args:
114
+ Q (float): heat given (W).
115
+
116
+ Returns:
117
+ float: auxiliary_power while the boiler gives heat, 0 otherwise (W).
118
+ """
119
+ return self.parameter("auxiliary_power").value if Q > 0 else 0
120
+
121
+ def _var_state_dic(self, values):
122
+ maximum = self.parameter("expression_max_values").value
123
+ minimum = self.parameter("expression_min_values").value
124
+ values = [min(max(v, lo), hi) for v, lo, hi in zip(values, minimum, maximum)]
125
+ return {"T_wi": values[0], "T_wo": values[1], "F_water": values[2], "F_load": values[3]}
@@ -498,8 +498,14 @@ class Building(Component):
498
498
  self.TS_vector = np.matmul(self.KS_inv_matrix, self.FS_vector) - np.matmul(self.KS_inv_matrix, np.matmul(self.KSZ_matrix,T_spaces))
499
499
 
500
500
  # Store TS
501
+ # Openings too: their T_s1 (and, for interior ones, T_s0) is only known here,
502
+ # and Opening.post_iteration() computes T_s0 and the heat fluxes from it.
501
503
  for i in range(self._n_surfaces):
502
- if self.surfaces[i].parameter("type").value == "Building_surface" and self.surfaces[i].parameter("surface_type").value != "VIRTUAL":
504
+ surface = self.surfaces[i]
505
+ s_type = surface.parameter("type").value
506
+ if s_type == "Opening" or (
507
+ s_type == "Building_surface" and surface.parameter("surface_type").value != "VIRTUAL"
508
+ ):
503
509
  if self.sides[i] == 0:
504
510
  self.surfaces[i].variable("T_s0").values[time_i] = self.TS_vector[i]
505
511
  else:
@@ -40,10 +40,22 @@ class Calculator(Component):
40
40
 
41
41
  def pre_iteration(self, time_index, date, daylight_saving):
42
42
  super().pre_iteration(time_index, date, daylight_saving)
43
- # variables dictonary
43
+ # Already here, for the components that use the outputs during the
44
+ # time step (e.g. a schedule built from the weather)
45
+ self._calculate_(time_index)
46
+
47
+ def post_iteration(self, time_index, date, daylight_saving, converged):
48
+ super().post_iteration(time_index, date, daylight_saving, converged)
49
+ # Again with the final values of the time step: the variables that the
50
+ # other components compute during it (the loads of a space, the power
51
+ # of a system...) were not there yet in pre_iteration. The calculators
52
+ # are the last in the simulation order, so they are all final now.
53
+ # The base pre_iteration copies the input variables again.
54
+ Component.pre_iteration(self, time_index, date, daylight_saving)
55
+ self._calculate_(time_index)
56
+
57
+ def _calculate_(self, time_index):
44
58
  var_dic = self.get_parameter_variable_dictionary(time_index)
45
-
46
- # Output variables
47
59
  for i in range(len(self.parameter("output_variables").value)):
48
60
  calculated_value = self.parameter(
49
61
  "output_expressions").evaluate(i, var_dic)
@@ -59,16 +59,12 @@ class File_data(Component):
59
59
  self.data_array = self._df_.select_dtypes(include=np.number).to_numpy()
60
60
 
61
61
  if self.parameter("file_step").value == "SIMULATION":
62
- i = 0
63
- k = 0
62
+ # one row per time step, from the first row of the file for every column,
63
+ # starting again from the first row if the file is shorter than the simulation
64
64
  n = len(self._df_)
65
- for key, var in self._variables_.items():
65
+ for i, var in enumerate(self._variables_.values()):
66
66
  for j in range(n_time_steps):
67
- var.values[j] = self.data_array[k][i]
68
- k = k + 1
69
- if k == n:
70
- k = 0
71
- i = i + 1
67
+ var.values[j] = self.data_array[j % n][i]
72
68
  elif self.parameter("file_step").value == "OWN":
73
69
  n = len(self._df_)
74
70
  self._initial_date_ = dt.datetime.strptime(
@@ -11,7 +11,7 @@ class HVAC_DX_system(Component):
11
11
  self.parameter("type").value = "HVAC_DX_system"
12
12
  self.parameter("description").value = "HVAC Direct Expansion system for time simulation"
13
13
  self.add_parameter(Parameter_component("equipment", "not_defined", ["DX_unit"]))
14
- self.add_parameter(Parameter_component("spaces", "not_defined", ["Space"])) # Space, TODO: Add Air_distribution, Energy_load
14
+ self.add_parameter(Parameter_component("spaces", "not_defined", ["Space", "Load_space"])) # Space, TODO: Add Air_distribution, Energy_load
15
15
  self.add_parameter(Parameter_float("air_flow", 1, "m³/s", min=0))
16
16
  self.add_parameter(Parameter_math_exp("outdoor_air_fraction", "0", "frac"))
17
17
  self.add_parameter(Parameter_variable_list("input_variables", []))
@@ -23,7 +23,7 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
23
23
  self.parameter("description").value = "HVAC Multizone Water system"
24
24
  self.add_parameter(
25
25
  Parameter_component_list(
26
- "spaces", ["not_defined", "not_defined"], ["Space"]
26
+ "spaces", ["not_defined", "not_defined"], ["Space", "Load_space"]
27
27
  )
28
28
  )
29
29
  self.add_parameter(
@@ -80,10 +80,10 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
80
80
  Parameter_options("water_source", "UNKNOWN", ["UNKNOWN", "WATER_SYSTEM"])
81
81
  )
82
82
  self.add_parameter(
83
- Parameter_component("cooling_water_system", "not_defined", ["HVAC_water_system"])
83
+ Parameter_component("cooling_water_system", "not_defined", ["HVAC_water_system", "HVAC_water_circuit"])
84
84
  )
85
85
  self.add_parameter(
86
- Parameter_component("heating_water_system", "not_defined", ["HVAC_water_system"])
86
+ Parameter_component("heating_water_system", "not_defined", ["HVAC_water_system", "HVAC_water_circuit"])
87
87
  )
88
88
  self.add_parameter(Parameter_float("cooling_water_flow", 1, "dm³/s", min=0))
89
89
  self.add_parameter(Parameter_float("heating_water_flow", 1, "dm³/s", min=0))
@@ -122,7 +122,7 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
122
122
  Parameter_options("reheat_water_source", "UNKNOWN", ["UNKNOWN", "WATER_SYSTEM"])
123
123
  )
124
124
  self.add_parameter(
125
- Parameter_component("reheat_water_system", "not_defined", ["HVAC_water_system"])
125
+ Parameter_component("reheat_water_system", "not_defined", ["HVAC_water_system", "HVAC_water_circuit"])
126
126
  )
127
127
 
128
128
 
@@ -267,6 +267,13 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
267
267
  self.heating_water_flow = self.parameter("heating_water_flow").value/1000 # Convert to m³/s
268
268
  self.cooling_water_temp = self.parameter("inlet_cooling_water_temp").value
269
269
  self.heating_water_temp = self.parameter("inlet_heating_water_temp").value
270
+ self.reheat_water_temp = self.heating_water_temp
271
+ # Water systems: the inlet water temperatures come from them in each iteration
272
+ from_system = self.parameter("water_source").value == "WATER_SYSTEM"
273
+ self.heating_ws = self.parameter("heating_water_system").component if from_system else None
274
+ self.cooling_ws = self.parameter("cooling_water_system").component if from_system else None
275
+ reheat_from_system = self.parameter("reheat_water_source").value == "WATER_SYSTEM"
276
+ self.reheat_ws = self.parameter("reheat_water_system").component if reheat_from_system else None
270
277
  self.rho_MA = self.props["RHO_A"]
271
278
  # Fan operation
272
279
  self.fan_operation = self.parameter("fan_operation").value
@@ -340,8 +347,26 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
340
347
  self._calculate_required_Q()
341
348
  self._simulate_system()
342
349
  self._send_air_to_spaces(time_index)
350
+ self._send_water_to_systems()
343
351
  return True
344
352
 
353
+ def _send_water_to_systems(self):
354
+ # Loads of the coils to the water systems (positive when the coil heats the
355
+ # water); flow: the design one the fraction of the time (ON_OFF) or of the
356
+ # flow (PROPORTIONAL, estimated) the coil works
357
+ if self.heating_ws is not None and self.state in (1, 2):
358
+ self.heating_ws.add_coil_load(
359
+ -self.Q_coil, self.parameter("heating_water_flow").value * self.F_load
360
+ )
361
+ elif self.cooling_ws is not None and self.state in (-1, -2):
362
+ self.cooling_ws.add_coil_load(
363
+ -self.Q_coil, self.parameter("cooling_water_flow").value * self.F_load
364
+ )
365
+ if self.reheat_ws is not None and self.is_reheat:
366
+ Q = float(np.sum(self.Q_reheat))
367
+ if Q > 0:
368
+ self.reheat_ws.add_coil_load(-Q, self._reheat_flow)
369
+
345
370
  def _calculate_return_air(self, time_index):
346
371
  v_return = 0
347
372
  self.T_ZA = 0
@@ -362,6 +387,9 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
362
387
  # Calculate F_OA based on return air flow
363
388
  if self.is_vav:
364
389
  self.F_OA = (self.air_flow * self.F_flow_total - v_return) / (self.air_flow* self.F_flow_total)
390
+ # with the return equal to the supply the rounding may leave it slightly
391
+ # negative, and the mixed air humidity with it
392
+ self.F_OA = min(max(self.F_OA, 0.0), 1.0)
365
393
  elif self.V_OA > 0:
366
394
  self._set_outdoor_air_from_flow(rho_ZA)
367
395
 
@@ -475,9 +503,19 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
475
503
  self.F_econo = 0.0
476
504
 
477
505
  def _simulate_system(self):
478
- if self.h_coil is not None and self.Q_required > 0: # Heating
506
+ heating = self.h_coil is not None and self.Q_required > 0
507
+ cooling = self.c_coil is not None and self.Q_required < 0
508
+ # From a water system: no heating (cooling) if it is off or its water is
509
+ # colder (warmer) than the mixed air
510
+ if heating and self.heating_ws is not None:
511
+ self.heating_water_temp = self.heating_ws.get_heating_coil_inlet_T()
512
+ heating = self.heating_ws.can_heat() and self.heating_water_temp >= self.T_MA
513
+ if cooling and self.cooling_ws is not None:
514
+ self.cooling_water_temp = self.cooling_ws.get_cooling_coil_inlet_T()
515
+ cooling = self.cooling_ws.can_cool() and self.cooling_water_temp <= self.T_MA
516
+ if heating:
479
517
  self._simulate_heating()
480
- elif self.c_coil is not None and self.Q_required < 0: # Cooling
518
+ elif cooling:
481
519
  self._simulate_cooling()
482
520
  else: # Venting
483
521
  self.state = 3
@@ -564,6 +602,11 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
564
602
 
565
603
  def _send_air_to_spaces(self, time_index):
566
604
  self.Q_reheat = np.zeros(len(self.spaces))
605
+ self._reheat_flow = 0 # dm³/s, to the reheat water system
606
+ reheat_available = True
607
+ if self.is_reheat and self.reheat_ws is not None:
608
+ self.reheat_water_temp = self.reheat_ws.get_heating_coil_inlet_T()
609
+ reheat_available = self.reheat_ws.can_heat() and self.reheat_water_temp > self.T_SA
567
610
  self.F_flow_total = 0
568
611
  self.rho_CA = 1 / sicro.GetMoistAirVolume(
569
612
  self.T_CA, self.w_CA / 1000, self.props["ATM_PRESSURE"]
@@ -610,7 +653,7 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
610
653
  # Reheat control
611
654
  if self.is_reheat:
612
655
  reheat_coil = self.reheat_coils[i]
613
- if reheat_coil is not None and reheat_needed:
656
+ if reheat_coil is not None and reheat_needed and reheat_available:
614
657
  # Reheat coil
615
658
  water_flow = reheat_coil.parameter(
616
659
  "nominal_heating_water_flow"
@@ -618,7 +661,7 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
618
661
  capacity, epsilon = reheat_coil.get_heating_capacity(
619
662
  self.T_SA,
620
663
  self.T_SAwb,
621
- self.heating_water_temp,
664
+ self.reheat_water_temp,
622
665
  self.air_flow * f_air_flow,
623
666
  water_flow,
624
667
  )
@@ -627,6 +670,8 @@ class HVAC_MZW_system(Component): # HVAC Multizone Water system
627
670
  self.Q_reheat[i] = Q_reheat_required
628
671
  else:
629
672
  self.Q_reheat[i] = capacity
673
+ if capacity > 0:
674
+ self._reheat_flow += water_flow * 1000 * self.Q_reheat[i] / capacity
630
675
  space.set_control_system(
631
676
  {
632
677
  "M_a": 0,
@@ -17,7 +17,7 @@ class HVAC_SZW_system(Component): # HVAC Single Zone Water system
17
17
  self.parameter("type").value = "HVAC_SZW_system"
18
18
  self.parameter("description").value = "HVAC Single Zone Water system"
19
19
  self.add_parameter(
20
- Parameter_component("space", "not_defined", ["Space"])
20
+ Parameter_component("space", "not_defined", ["Space", "Load_space"])
21
21
  ) # Space
22
22
  self.add_parameter(
23
23
  Parameter_component("cooling_coil", "not_defined", ["Water_coil"])
@@ -43,12 +43,12 @@ class HVAC_SZW_system(Component): # HVAC Single Zone Water system
43
43
  )
44
44
  self.add_parameter(
45
45
  Parameter_component(
46
- "cooling_water_system", "not_defined", ["HVAC_water_system"]
46
+ "cooling_water_system", "not_defined", ["HVAC_water_system", "HVAC_water_circuit"]
47
47
  )
48
48
  )
49
49
  self.add_parameter(
50
50
  Parameter_component(
51
- "heating_water_system", "not_defined", ["HVAC_water_system"]
51
+ "heating_water_system", "not_defined", ["HVAC_water_system", "HVAC_water_circuit"]
52
52
  )
53
53
  )
54
54
  self.add_parameter(Parameter_float("cooling_water_flow", 1, "dm³/s", min=0))
@@ -383,7 +383,7 @@ class HVAC_SZW_system(Component): # HVAC Single Zone Water system
383
383
  "heating_water_system"
384
384
  ).component.get_heating_coil_inlet_T()
385
385
  if (
386
- not self.parameter("heating_water_system").component.on_off
386
+ not self.parameter("heating_water_system").component.can_heat()
387
387
  or heating_Tw < self.T_MA
388
388
  ):
389
389
  self.state = 3
@@ -435,7 +435,7 @@ class HVAC_SZW_system(Component): # HVAC Single Zone Water system
435
435
  "cooling_water_system"
436
436
  ).component.get_cooling_coil_inlet_T()
437
437
  if (
438
- not self.parameter("cooling_water_system").component.on_off
438
+ not self.parameter("cooling_water_system").component.can_cool()
439
439
  or cooling_Tw > self.T_MA
440
440
  ):
441
441
  self.state = 3
@@ -513,13 +513,15 @@ class HVAC_SZW_system(Component): # HVAC Single Zone Water system
513
513
 
514
514
  def _send_water_to_system(self):
515
515
  if self.parameter("water_source").value == "WATER_SYSTEM": # from water system
516
+ # water flow through the coil: the design one the fraction of the time
517
+ # (ON_OFF) or of the flow (PROPORTIONAL, estimated) it works
516
518
  if self.state == 1 or self.state == 2: # Heating
517
519
  self.parameter("heating_water_system").component.add_coil_load(
518
- -self.Q_coil
520
+ -self.Q_coil, self.parameter("heating_water_flow").value * self.F_load
519
521
  )
520
522
  elif self.state == -1 or self.state == -2: # Cooling
521
523
  self.parameter("cooling_water_system").component.add_coil_load(
522
- -self.Q_coil
524
+ -self.Q_coil, self.parameter("cooling_water_flow").value * self.F_load
523
525
  )
524
526
 
525
527
  def _update_supply_mass_flow(self):
@@ -10,7 +10,7 @@ class HVAC_perfect_system(Component):
10
10
  Component.__init__(self, name, project)
11
11
  self.parameter("type").value = "HVAC_perfect_system"
12
12
  self.parameter("description").value = "HVAC Perfect system for cooling and heating load"
13
- self.add_parameter(Parameter_component("spaces", "not_defined", ["Space"]))
13
+ self.add_parameter(Parameter_component("spaces", "not_defined", ["Space", "Load_space"]))
14
14
  self.add_parameter(Parameter_variable_list("input_variables", []))
15
15
  self.add_parameter(Parameter_math_exp("outdoor_air_flow", "0", "m³/s"))
16
16
  self.add_parameter(Parameter_math_exp("heating_setpoint", "20", "°C"))