Skip to content

Commit

Permalink
refactor: remove temporal operational settings system v2 (#244)
Browse files Browse the repository at this point in the history
It is unclear if it is needed, and it causes confusion. We want users to
use temporal variables instead in most cases. Removing ensures we
actually capture the need when it would be used.
  • Loading branch information
jsolaas authored Oct 19, 2023
1 parent 419c2e9 commit a1d2ce6
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 20,887 deletions.
8 changes: 2 additions & 6 deletions src/libecalc/core/consumers/consumer_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import networkx as nx
import numpy as np
from libecalc.common.stream import Stream
from libecalc.common.temporal_model import TemporalModel
from libecalc.common.units import Unit
from libecalc.common.utils.rates import (
TimeSeriesBoolean,
Expand Down Expand Up @@ -133,7 +132,7 @@ def _get_operational_settings_adjusted_for_crossover(
def evaluate(
self,
variables_map: VariablesMap,
temporal_operational_settings: TemporalModel[List[Union[SystemOperationalSettings]]],
operational_settings: List[Union[SystemOperationalSettings]],
) -> EcalcModelResult:
"""
Evaluating a consumer system that may be composed of both consumers and other consumer systems. It will default
Expand All @@ -149,15 +148,12 @@ def evaluate(
operational_settings_used = TimeSeriesInt(
timesteps=variables_map.time_vector, values=[0] * len(variables_map.time_vector), unit=Unit.NONE
)
operational_settings_results: Dict[datetime, Dict[int, Dict[str, EcalcModelResult]]] = defaultdict(
dict
) # map operational settings index and consumer id to consumer result.
operational_settings_results: Dict[datetime, Dict[int, Dict[str, EcalcModelResult]]] = defaultdict(dict)

for timestep_index, timestep in enumerate(variables_map.time_vector):
variables_map_for_timestep = variables_map.get_subset_for_timestep(timestep)
operational_settings_results[timestep] = defaultdict(dict)

operational_settings = temporal_operational_settings.get_model(timestep)
for operational_setting_index, operational_setting in enumerate(operational_settings):
operational_setting_for_timestep = operational_setting.for_timestep(timestep)
adjusted_operational_settings = self._get_operational_settings_adjusted_for_crossover(
Expand Down
4 changes: 2 additions & 2 deletions src/libecalc/core/ecalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def evaluate_energy_usage(self, variables_map: dto.VariablesMap) -> Dict[str, Ec
variables_map=variables_map,
)
system_result = pump_system.evaluate(
variables_map=variables_map, temporal_operational_settings=evaluated_operational_settings
variables_map=variables_map, operational_settings=evaluated_operational_settings
)
consumer_results[component_dto.id] = system_result
for consumer_result in system_result.sub_components:
Expand All @@ -80,7 +80,7 @@ def evaluate_energy_usage(self, variables_map: dto.VariablesMap) -> Dict[str, Ec
variables_map=variables_map,
)
system_result = compressor_system.evaluate(
variables_map=variables_map, temporal_operational_settings=evaluated_operational_settings
variables_map=variables_map, operational_settings=evaluated_operational_settings
)
consumer_results[component_dto.id] = system_result
for consumer_result in system_result.sub_components:
Expand Down
187 changes: 86 additions & 101 deletions src/libecalc/dto/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class SystemComponentConditions(EcalcBaseModel):
class CompressorSystem(BaseConsumer):
component_type: Literal[ComponentType.COMPRESSOR_SYSTEM_V2] = ComponentType.COMPRESSOR_SYSTEM_V2
component_conditions: SystemComponentConditions
operational_settings: Dict[datetime, List[CompressorSystemOperationalSetting]]
operational_settings: List[CompressorSystemOperationalSetting]
compressors: List[CompressorComponent]

def get_graph(self) -> Graph:
Expand All @@ -225,70 +225,60 @@ def get_graph(self) -> Graph:
def evaluate_operational_settings(
self,
variables_map: VariablesMap,
) -> TemporalModel[List[EvaluatedCompressorSystemOperationalSettings]]:
) -> List[EvaluatedCompressorSystemOperationalSettings]:
"""Parameters
----------
variables_map
operational_settings
Returns
-------
"""
evaluated_regularity = TemporalExpression.evaluate(
temporal_expression=TemporalModel(self.regularity), variables_map=variables_map
)
evaluated_temporal_operational_settings: Dict[datetime, List[EvaluatedCompressorSystemOperationalSettings]] = {}
for period, operational_settings in TemporalModel(self.operational_settings).items():
period_start, period_end = period.get_timestep_indices(variables_map.time_vector)
regularity_for_period = evaluated_regularity[period_start:period_end]
evaluated_operational_settings: List[EvaluatedCompressorSystemOperationalSettings] = []
for operational_setting in operational_settings:
rates: List[TimeSeriesRate] = [
TimeSeriesRate(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
regularity=regularity_for_period,
unit=Unit.STANDARD_CUBIC_METER_PER_DAY,
)
for rate in operational_setting.rates
]

inlet_pressure = [
TimeSeriesFloat(
values=list(
pressure.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))
),
timesteps=variables_map.time_vector,
unit=Unit.BARA,
)
for pressure in operational_setting.inlet_pressures
]
outlet_pressure = [
TimeSeriesFloat(
values=list(
pressure.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))
),
timesteps=variables_map.time_vector,
unit=Unit.BARA,
)
for pressure in operational_setting.outlet_pressures
]

evaluated_operational_settings.append(
EvaluatedCompressorSystemOperationalSettings(
rates=rates,
inlet_pressures=inlet_pressure,
outlet_pressures=outlet_pressure,
)
evaluated_operational_settings: List[EvaluatedCompressorSystemOperationalSettings] = []
for operational_setting in self.operational_settings:
rates: List[TimeSeriesRate] = [
TimeSeriesRate(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
regularity=evaluated_regularity,
unit=Unit.STANDARD_CUBIC_METER_PER_DAY,
)
for rate in operational_setting.rates
]

inlet_pressure = [
TimeSeriesFloat(
values=list(pressure.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
unit=Unit.BARA,
)
evaluated_temporal_operational_settings[period.start] = evaluated_operational_settings
for pressure in operational_setting.inlet_pressures
]
outlet_pressure = [
TimeSeriesFloat(
values=list(pressure.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
unit=Unit.BARA,
)
for pressure in operational_setting.outlet_pressures
]

evaluated_operational_settings.append(
EvaluatedCompressorSystemOperationalSettings(
rates=rates,
inlet_pressures=inlet_pressure,
outlet_pressures=outlet_pressure,
)
)

return TemporalModel(evaluated_temporal_operational_settings)
return evaluated_operational_settings


class PumpSystem(BaseConsumer):
component_type: Literal[ComponentType.PUMP_SYSTEM_V2] = ComponentType.PUMP_SYSTEM_V2
component_conditions: SystemComponentConditions
operational_settings: Dict[datetime, List[PumpSystemOperationalSetting]]
operational_settings: List[PumpSystemOperationalSetting]
pumps: List[PumpComponent]

def get_graph(self) -> Graph:
Expand All @@ -307,65 +297,60 @@ def get_graph(self) -> Graph:
def evaluate_operational_settings(
self,
variables_map: VariablesMap,
) -> TemporalModel[List[EvaluatedPumpSystemOperationalSettings]]:
) -> List[EvaluatedPumpSystemOperationalSettings]:
evaluated_regularity = TemporalExpression.evaluate(
temporal_expression=TemporalModel(self.regularity),
variables_map=variables_map,
)

evaluated_temporal_operational_settings: Dict[datetime, List[EvaluatedPumpSystemOperationalSettings]] = {}
for period, operational_settings in TemporalModel(self.operational_settings).items():
period_start, period_end = period.get_timestep_indices(variables_map.time_vector)
regularity_for_period = evaluated_regularity[period_start:period_end]
evaluated_operational_settings: List[EvaluatedPumpSystemOperationalSettings] = []
for operational_setting in operational_settings:
rates: List[TimeSeriesRate] = [
TimeSeriesRate(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
regularity=regularity_for_period,
unit=Unit.STANDARD_CUBIC_METER_PER_DAY,
)
for rate in operational_setting.rates
]

inlet_pressure = [
TimeSeriesFloat(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
unit=Unit.BARA,
)
for rate in operational_setting.inlet_pressures
]
outlet_pressure = [
TimeSeriesFloat(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
unit=Unit.BARA,
)
for rate in operational_setting.outlet_pressures
]

fluid_density = [
TimeSeriesFloat(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
unit=Unit.KG_SM3,
)
for rate in operational_setting.fluid_density
]

evaluated_operational_settings.append(
EvaluatedPumpSystemOperationalSettings(
rates=rates,
inlet_pressures=inlet_pressure,
outlet_pressures=outlet_pressure,
fluid_density=fluid_density,
)
evaluated_operational_settings: List[EvaluatedPumpSystemOperationalSettings] = []
for operational_setting in self.operational_settings:
rates: List[TimeSeriesRate] = [
TimeSeriesRate(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
regularity=evaluated_regularity,
unit=Unit.STANDARD_CUBIC_METER_PER_DAY,
)
for rate in operational_setting.rates
]

inlet_pressure = [
TimeSeriesFloat(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
unit=Unit.BARA,
)
evaluated_temporal_operational_settings[period.start] = evaluated_operational_settings
for rate in operational_setting.inlet_pressures
]
outlet_pressure = [
TimeSeriesFloat(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
unit=Unit.BARA,
)
for rate in operational_setting.outlet_pressures
]

fluid_density = [
TimeSeriesFloat(
values=list(rate.evaluate(variables_map.variables, fill_length=len(variables_map.time_vector))),
timesteps=variables_map.time_vector,
unit=Unit.KG_SM3,
)
for rate in operational_setting.fluid_density
]

evaluated_operational_settings.append(
EvaluatedPumpSystemOperationalSettings(
rates=rates,
inlet_pressures=inlet_pressure,
outlet_pressures=outlet_pressure,
fluid_density=fluid_density,
)
)

return TemporalModel(evaluated_temporal_operational_settings)
return evaluated_operational_settings


class GeneratorSet(BaseEquipment):
Expand Down
Loading

0 comments on commit a1d2ce6

Please sign in to comment.