Skip to content

Commit

Permalink
fixed bugs thermostat and sage
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophGehbauer committed Apr 3, 2024
1 parent 797d04c commit 7479d7a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Standard usage of the AFC package follows the sequence of steps outlined in the
The AFC package requires sets of parameters and inputs that describe the optimization problem. On the one hand, the parameters are quantities that describe the physical system on which the optimization is performed. Parameters include, for example, the location and size of the building, its number of windows or the number of occupants in the room. On the other hand, data inputs describe the climatic context of the optimization. These are essentially exogeneous meteorological forecasts of the sun's irradiance on the building. Unlike parameters, data inputs are time-dependent variables.

#### 1.1 Define system parameters
The `parameter` object is a dictionary containing parameter values describing the system to be controlled by AFC. The built-in function `defaultConfing` contains default parameters which can be helpful to get started. Users can modify the parameters to create a setup that meets their specific building. An alternative way to establish the parameters is through a JSON test file. For more information see [here](docs/json_configuration.md).
The `parameter` object is a dictionary containing parameter values describing the system to be controlled by AFC. The built-in function `defaultConfing` contains default parameters which can be helpful to get started. Users can modify the parameters to create a setup that meets their specific building. An alternative way to establish the parameters is through a JSON text file. For more information see [here](docs/json_configuration.md).

```python
# initialize afc with default parameters
Expand Down Expand Up @@ -122,7 +122,7 @@ The AFC controller provides a variety of outputs ranging from the desired contro
# get all outputs
ctrl.get_output()
# get only facade setpoints
ctrl.get_output(keys=['output-data'])
ctrl.get_output(keys=['ctrl-facade'])
```

These full list of outputs is here:
Expand Down
9 changes: 7 additions & 2 deletions afc/ctrlWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,14 @@ def compute(self):
self.output['glaremode'] = list(gmodes)

# Compute thermostat setpoints
thermostat = compute_thermostat_setpoints(df, self.output['valid'], True, False)
thermostat = compute_thermostat_setpoints(
df, cool_set, heat_set, self.output['valid'], True, False
)
self.output['ctrl-thermostat'] = thermostat
self.output['ctrl-troom'] = float(df['Temperature 0 [C]'].values[1])
if objective:
self.output['ctrl-troom'] = float(df['Temperature 0 [C]'].values[1])
else:
self.output['ctrl-troom'] = None

# Compute shade state
if objective:
Expand Down
6 changes: 4 additions & 2 deletions afc/glare/sage3zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def do_step(self, ts, ctrl_input={}):
if dni + dhi > 0:
alt, azi_shift, inci, azi = self.get_solar(ts, weather_forecast)
if inci != 0:
self.glare_mode(alt, azi_shift, inci)
self.glare_mode_many(alt, azi_shift, inci)
self.bot_gmode = self.gmodes[0]
self.mid_gmode = self.gmodes[0]
self.top_gmode = self.gmodes[0]
ctrl = self.daylight_mode_c(self.bot_gmode, self.mid_gmode, self.top_gmode, inci)
#ctrl = self.daylight_mode_b(mo, self.bot_gmode, self.mid_gmode, self.top_gmode, inci)
else:
Expand Down Expand Up @@ -259,7 +262,6 @@ def glare_mode_many(self, alt, azi, inci):
self.gmodes[ix] = gmodes[ix]
return self.gmodes


if __name__ == '__main__':
import pandas as pd
import datetime as dt
Expand Down
17 changes: 11 additions & 6 deletions afc/utility/thermostat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
Thermostat control module.
"""

# pylint: disable=too-many-arguments

def afc_to_hvac_setpoint(ctrl_outputs, tdead=0.5):
"""Utility to convert from AFC to thermostat setpoints."""

Expand Down Expand Up @@ -44,14 +46,17 @@ def afc_to_hvac_setpoint(ctrl_outputs, tdead=0.5):
'csp': new_cool_set,
'hsp': new_heat_set}

def compute_thermostat_setpoints(df, feasible, control_hvac, occupied):
def compute_thermostat_setpoints(df, cool_set, heat_set, feasible, control_hvac, occupied):
"""wrapper to compute thermostat setpoints"""

cool_set = df['Temperature 0 Max [C]'].values[0]
heat_set = df['Temperature 0 Min [C]'].values[0]
t_room = df['Temperature 0 [C]'].values[1]
power_cool = df['Power Cooling [W]'].iloc[0]
power_heat = df['Power Heating [W]'].iloc[0]
if feasible:
t_room = df['Temperature 0 [C]'].values[1]
power_cool = df['Power Cooling [W]'].iloc[0]
power_heat = df['Power Heating [W]'].iloc[0]
else:
t_room = 0
power_cool = 0
power_heat = 0

ctrl_outputs = {
'hvac_control': control_hvac,
Expand Down
17 changes: 11 additions & 6 deletions dev/Development-ControllerWrapper.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 1,
"metadata": {
"scrolled": true
},
Expand Down Expand Up @@ -60,15 +60,15 @@
"text": [
"All Input variables: dict_keys(['input-data', 'wf-all', 'facade-initial', 'temps-initial', 'parameter'])\n",
"Log-message:\n",
" Duration [s]\t\t0.2\n",
" Duration [s]\t\t0.21\n",
"Objective [$]\t\t20.29\t\t\t7.58 (Total Cost)\n",
"Cost [$]\t\t13.31 (Energy)\t6.98 (Demand)\n",
"CO2 Emissions [kg]\t\t0.0\n",
"\n",
"Duration:\n",
" {'duration': {'radiance': 28.713886737823486, 'glare': 68.22607159614563, 'varts': 0.12781977653503418, 'optall': 0.5022704601287842, 'outputs': 0.0056383609771728516, 'all': 101.4219479560852}}\n",
" {'duration': {'radiance': 30.761962890625, 'glare': 70.15064311027527, 'varts': 0.13178372383117676, 'optall': 0.5088160037994385, 'outputs': 0.0061244964599609375, 'all': 105.49714946746826}}\n",
"Optimization:\n",
" {'opt-stats': {'duration': 0.20232176780700684, 'termination': 'optimal', 'objective': 20.28974844}}\n"
" {'opt-stats': {'duration': 0.20841765403747559, 'termination': 'optimal', 'objective': 20.28974844}}\n"
]
},
{
Expand Down Expand Up @@ -445,9 +445,14 @@
" self.output['glaremode'] = list(gmodes)\n",
"\n",
" # Compute thermostat setpoints\n",
" thermostat = compute_thermostat_setpoints(df, self.output['valid'], True, False)\n",
" thermostat = compute_thermostat_setpoints(\n",
" df, cool_set, heat_set, self.output['valid'], True, False\n",
" )\n",
" self.output['ctrl-thermostat'] = thermostat\n",
" self.output['ctrl-troom'] = float(df['Temperature 0 [C]'].values[1])\n",
" if objective:\n",
" self.output['ctrl-troom'] = float(df['Temperature 0 [C]'].values[1])\n",
" else:\n",
" self.output['ctrl-troom'] = None\n",
"\n",
" # Compute shade state\n",
" if objective:\n",
Expand Down

0 comments on commit 7479d7a

Please sign in to comment.