Skip to content

Commit

Permalink
chore: sum and split electrical and mechanical power (#406)
Browse files Browse the repository at this point in the history
* chore: sum and split electrical and mechanical power at installation level
ECALC-881
  • Loading branch information
frodehk committed Mar 15, 2024
1 parent 0f1e6f8 commit 86754cc
Show file tree
Hide file tree
Showing 10 changed files with 1,018 additions and 137 deletions.
69 changes: 55 additions & 14 deletions src/libecalc/application/graph_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,27 @@ def _compute_intensity(
)
return emission_intensities

def _compute_aggregated_power(
self,
regularity: TimeSeriesFloat,
power_components: list,
):
return reduce(
operator.add,
[
TimeSeriesRate.from_timeseries_stream_day_rate(component.power, regularity=regularity)
for component in power_components
if component.power is not None
],
TimeSeriesRate(
values=[0.0] * self.variables_map.length,
timesteps=self.variables_map.time_vector,
unit=Unit.MEGA_WATT,
rate_type=RateType.STREAM_DAY,
regularity=regularity.values,
), # Initial value, handle no power output from components
)

def _evaluate_installations(self, variables_map: dto.VariablesMap) -> List[libecalc.dto.result.InstallationResult]:
"""
All subcomponents have already been evaluated, here we basically collect and aggregate the results
Expand Down Expand Up @@ -129,23 +150,35 @@ def _evaluate_installations(self, variables_map: dto.VariablesMap) -> List[libec
if component_id in self.consumer_results
]

power_components = [
self.consumer_results[component_id].component_result
for component_id in self.graph.get_successors(installation.id, recursively=False)
if component_id in self.consumer_results
]

electrical_components = []
fuel_components = []

for component in power_components:
if self.graph.get_node_info(component.id).component_type == ComponentType.GENERATOR_SET:
electrical_components.append(component)
else:
fuel_components.append(component)

installation_node_info = self.graph.get_node_info(installation.id)
power = reduce(
operator.add,
[
TimeSeriesRate.from_timeseries_stream_day_rate(component.power, regularity=regularity)
for component in sub_components
if self.graph.get_node_info(component.id).component_type == ComponentType.GENERATOR_SET
],
TimeSeriesRate(
values=[0.0] * self.variables_map.length,
timesteps=self.variables_map.time_vector,
unit=Unit.MEGA_WATT,
rate_type=RateType.STREAM_DAY,
regularity=regularity.values,
), # Initial value, handle no power output from components

power_electrical = self._compute_aggregated_power(
power_components=electrical_components,
regularity=regularity,
)

power_mechanical = self._compute_aggregated_power(
power_components=fuel_components,
regularity=regularity,
)

power = power_electrical + power_mechanical

energy_usage = (
reduce(
operator.add,
Expand Down Expand Up @@ -182,6 +215,14 @@ def _evaluate_installations(self, variables_map: dto.VariablesMap) -> List[libec
),
power=power,
power_cumulative=power.to_volumes().to_unit(Unit.GIGA_WATT_HOURS).cumulative(),
power_electrical=power_electrical,
power_electrical_cumulative=power_electrical.to_volumes()
.to_unit(Unit.GIGA_WATT_HOURS)
.cumulative(),
power_mechanical=power_mechanical,
power_mechanical_cumulative=power_mechanical.to_volumes()
.to_unit(Unit.GIGA_WATT_HOURS)
.cumulative(),
energy_usage=energy_usage.to_calendar_day()
if energy_usage.unit == Unit.STANDARD_CUBIC_METER_PER_DAY
else energy_usage.to_stream_day(),
Expand Down
4 changes: 4 additions & 0 deletions src/libecalc/dto/result/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ class AssetResult(ComponentResultBase):
componentType: Literal[ComponentType.ASSET]
hydrocarbon_export_rate: TimeSeriesRate
emission_intensities: List[EmissionIntensityResult]
power_electrical: Optional[TimeSeriesRate] = None
power_electrical_cumulative: Optional[TimeSeriesVolumesCumulative] = None
power_mechanical: Optional[TimeSeriesRate] = None
power_mechanical_cumulative: Optional[TimeSeriesVolumesCumulative] = None


class InstallationResult(AssetResult):
Expand Down
26 changes: 13 additions & 13 deletions src/tests/ecalc_cli/snapshots/test_app/test_csv_default/test.csv

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions src/tests/ecalc_cli/snapshots/test_app/test_full_csv/results.csv

Large diffs are not rendered by default.

Loading

0 comments on commit 86754cc

Please sign in to comment.