Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sum and split electrical and mechanical power #406

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 72 additions & 14 deletions src/libecalc/application/graph_result.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import copy
import math
import operator
from collections import defaultdict
Expand Down Expand Up @@ -40,6 +41,7 @@
PumpModelResult,
TurbineModelResult,
)
from libecalc.dto.types import ConsumptionType
from libecalc.dto.utils.aggregators import aggregate_emissions, aggregate_is_valid
from libecalc.expression import Expression

Expand Down Expand Up @@ -89,6 +91,38 @@ def _compute_intensity(
)
return emission_intensities

def _compute_aggregated_power(
self,
sub_components: list,
regularity: TimeSeriesFloat,
consumption_type: ConsumptionType,
exclude_components: List[ComponentType],
):
sub_components_consumption_type = []
for sub_component in sub_components:
try:
if self.graph.get_node(sub_component.id).consumes == consumption_type:
sub_components_consumption_type.append(sub_component)
except AttributeError:
pass

return reduce(
operator.add,
[
TimeSeriesRate.from_timeseries_stream_day_rate(component.power, regularity=regularity)
for component in sub_components_consumption_type
if component.power is not None
and self.graph.get_node_info(component.id).component_type not in exclude_components
],
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 @@ -130,22 +164,38 @@ def _evaluate_installations(self, variables_map: dto.VariablesMap) -> List[libec
]

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

# Ensure that only components at individual consumer level are included in aggregation of power,
# to secure that nothing is counted twice:
exclude_components = [
ComponentType.GENERATOR_SET,
ComponentType.ASSET,
ComponentType.INSTALLATION,
ComponentType.COMPRESSOR_SYSTEM,
ComponentType.CONSUMER_SYSTEM_V2,
ComponentType.PUMP_SYSTEM,
ComponentType.TRAIN_V2,
]
power_electrical = self._compute_aggregated_power(
sub_components=sub_components,
regularity=regularity,
consumption_type=ConsumptionType.ELECTRICITY,
exclude_components=exclude_components,
)

power_mechanical = self._compute_aggregated_power(
sub_components=sub_components,
regularity=regularity,
consumption_type=ConsumptionType.FUEL,
exclude_components=exclude_components,
)
frodehk marked this conversation as resolved.
Show resolved Hide resolved

power_sum = [
electrical + mechanical
for electrical, mechanical in zip(power_electrical.values, power_mechanical.values)
]
power = copy.deepcopy(power_electrical)
power.values = power_sum
frodehk marked this conversation as resolved.
Show resolved Hide resolved
energy_usage = (
reduce(
operator.add,
Expand Down Expand Up @@ -182,6 +232,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
Loading