Skip to content

Commit

Permalink
feat: add eletrical- and mechanical power to asset (#479)
Browse files Browse the repository at this point in the history
* feat: add eletrical- and mechanical power to asset

ECALC-1157
  • Loading branch information
frodehk authored May 10, 2024
1 parent 1c390a6 commit 464047f
Show file tree
Hide file tree
Showing 11 changed files with 753 additions and 79 deletions.
42 changes: 42 additions & 0 deletions src/libecalc/application/graph_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,10 +1321,48 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult:
else None
)

asset_power_electrical_core = (
reduce(
operator.add,
[
installation.power_electrical
for installation in installation_results
if installation.power_electrical is not None
],
)
if installation_results
else None
)

asset_power_mechanical_core = (
reduce(
operator.add,
[
installation.power_mechanical
for installation in installation_results
if installation.power_mechanical is not None
],
)
if installation_results
else None
)

asset_power_cumulative = (
asset_power_core.to_volumes().to_unit(Unit.GIGA_WATT_HOURS).cumulative() if installation_results else None
)

asset_power_electrical_cumulative = (
asset_power_electrical_core.to_volumes().to_unit(Unit.GIGA_WATT_HOURS).cumulative()
if asset_power_electrical_core
else None
)

asset_power_mechanical_cumulative = (
asset_power_mechanical_core.to_volumes().to_unit(Unit.GIGA_WATT_HOURS).cumulative()
if asset_power_mechanical_core
else None
)

asset_energy_usage_core = (
reduce(
operator.add,
Expand Down Expand Up @@ -1352,6 +1390,10 @@ def get_asset_result(self) -> libecalc.dto.result.EcalcModelResult:
),
power=asset_power_core,
power_cumulative=asset_power_cumulative,
power_electrical=asset_power_electrical_core,
power_electrical_cumulative=asset_power_electrical_cumulative,
power_mechanical=asset_power_mechanical_core,
power_mechanical_cumulative=asset_power_mechanical_cumulative,
energy_usage=asset_energy_usage_core,
energy_usage_cumulative=asset_energy_usage_cumulative,
hydrocarbon_export_rate=asset_hydrocarbon_export_rate_core,
Expand Down
28 changes: 19 additions & 9 deletions src/libecalc/fixtures/cases/ltp_export/installation_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ def no_el_consumption() -> dto.ElectricityConsumer:
)


def simple_direct_el_consumer() -> dto.ElectricityConsumer:
def simple_direct_el_consumer(name: str = "direct_consumer") -> dto.ElectricityConsumer:
return dto.ElectricityConsumer(
name="direct_consumer",
name=name,
component_type=dto.base.ComponentType.GENERIC,
user_defined_category={datetime(1900, 1, 1): ConsumerUserDefinedCategoryType.FIXED_PRODUCTION_LOAD},
energy_usage_model={
Expand Down Expand Up @@ -260,9 +260,9 @@ def boiler_heater() -> dto.FuelConsumer:
)


def compressor() -> dto.FuelConsumer:
def compressor(name: str = "single_1d_compressor_sampled") -> dto.FuelConsumer:
return dto.FuelConsumer(
name="single_1d_compressor_sampled",
name=name,
component_type=dto.base.ComponentType.COMPRESSOR,
fuel={datetime(2027, 1, 1): fuel_turbine()},
user_defined_category={
Expand Down Expand Up @@ -307,9 +307,11 @@ def generator_set_offshore_wind_temporal_model() -> dto.GeneratorSet:
)


def generator_set_compressor_temporal_model(consumers: List[dto.ElectricityConsumer]) -> dto.GeneratorSet:
def generator_set_compressor_temporal_model(
consumers: List[dto.ElectricityConsumer], name: str = "genset"
) -> dto.GeneratorSet:
return dto.GeneratorSet(
name="genset",
name=name,
user_defined_category={date1: ConsumerUserDefinedCategoryType.TURBINE_GENERATOR},
fuel={date1: fuel_turbine()},
generator_set_model={date1: generator_set_fuel()},
Expand Down Expand Up @@ -464,12 +466,20 @@ def installation_offshore_wind_dto() -> dto.Installation:
)


def installation_compressor_dto(el_consumers: List[dto.ElectricityConsumer]) -> dto.Installation:
def installation_compressor_dto(
el_consumers: List[dto.ElectricityConsumer],
installation_name: str = "INSTALLATION_A",
genset_name: str = "genset",
compressor_name: str = "compressor",
) -> dto.Installation:
return dto.Installation(
name="INSTALLATION_A",
name=installation_name,
regularity=regularity_temporal_installation,
hydrocarbon_export={datetime(1900, 1, 1): Expression.setup_from_expression(0)},
fuel_consumers=[generator_set_compressor_temporal_model(el_consumers), compressor()],
fuel_consumers=[
generator_set_compressor_temporal_model(el_consumers, name=genset_name),
compressor(name=compressor_name),
],
user_defined_category=dto.base.InstallationUserDefinedCategoryType.FIXED,
)

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.

Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,270 @@
8975.092
]
},
"power_electrical": {
"rate_type": "STREAM_DAY",
"regularity": [
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0
],
"timesteps": [
"2020-01-01 00:00:00",
"2020-06-01 00:00:00",
"2021-01-01 00:00:00",
"2022-01-01 00:00:00",
"2023-01-01 00:00:00",
"2024-01-01 00:00:00",
"2025-01-01 00:00:00",
"2026-01-01 00:00:00",
"2027-01-01 00:00:00",
"2028-01-01 00:00:00",
"2029-01-01 00:00:00",
"2030-01-01 00:00:00",
"2031-01-01 00:00:00",
"2032-01-01 00:00:00",
"2033-01-01 00:00:00",
"2034-01-01 00:00:00",
"2035-01-01 00:00:00",
"2036-01-01 00:00:00",
"2037-01-01 00:00:00",
"2038-01-01 00:00:00",
"2039-01-01 00:00:00",
"2040-01-01 00:00:00",
"2041-01-01 00:00:00"
],
"unit": "MW",
"values": [
49.23593,
49.23593,
49.23593,
49.23593,
49.23593,
48.284,
48.0512,
48.59026,
61.73769,
61.86475,
48.5642,
47.80468,
46.36791,
46.4423,
46.36791,
46.2054,
46.08558,
46.08558,
46.08558,
46.08558,
46.08558,
46.08558,
15.2
]
},
"power_electrical_cumulative": {
"timesteps": [
"2020-01-01 00:00:00",
"2020-06-01 00:00:00",
"2021-01-01 00:00:00",
"2022-01-01 00:00:00",
"2023-01-01 00:00:00",
"2024-01-01 00:00:00",
"2025-01-01 00:00:00",
"2026-01-01 00:00:00",
"2027-01-01 00:00:00",
"2028-01-01 00:00:00",
"2029-01-01 00:00:00",
"2030-01-01 00:00:00",
"2031-01-01 00:00:00",
"2032-01-01 00:00:00",
"2033-01-01 00:00:00",
"2034-01-01 00:00:00",
"2035-01-01 00:00:00",
"2036-01-01 00:00:00",
"2037-01-01 00:00:00",
"2038-01-01 00:00:00",
"2039-01-01 00:00:00",
"2040-01-01 00:00:00",
"2041-01-01 00:00:00"
],
"unit": "GWh",
"values": [
0.0,
179.6127,
432.4884,
863.7952,
1295.102,
1726.409,
2150.535,
2571.464,
2997.114,
3537.937,
4081.357,
4506.779,
4925.548,
5331.731,
5739.68,
6145.863,
6550.622,
6954.332,
7359.148,
7762.857,
8166.567,
8570.277,
8975.092
]
},
"power_mechanical": {
"rate_type": "STREAM_DAY",
"regularity": [
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0,
1.0
],
"timesteps": [
"2020-01-01 00:00:00",
"2020-06-01 00:00:00",
"2021-01-01 00:00:00",
"2022-01-01 00:00:00",
"2023-01-01 00:00:00",
"2024-01-01 00:00:00",
"2025-01-01 00:00:00",
"2026-01-01 00:00:00",
"2027-01-01 00:00:00",
"2028-01-01 00:00:00",
"2029-01-01 00:00:00",
"2030-01-01 00:00:00",
"2031-01-01 00:00:00",
"2032-01-01 00:00:00",
"2033-01-01 00:00:00",
"2034-01-01 00:00:00",
"2035-01-01 00:00:00",
"2036-01-01 00:00:00",
"2037-01-01 00:00:00",
"2038-01-01 00:00:00",
"2039-01-01 00:00:00",
"2040-01-01 00:00:00",
"2041-01-01 00:00:00"
],
"unit": "MW",
"values": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
]
},
"power_mechanical_cumulative": {
"timesteps": [
"2020-01-01 00:00:00",
"2020-06-01 00:00:00",
"2021-01-01 00:00:00",
"2022-01-01 00:00:00",
"2023-01-01 00:00:00",
"2024-01-01 00:00:00",
"2025-01-01 00:00:00",
"2026-01-01 00:00:00",
"2027-01-01 00:00:00",
"2028-01-01 00:00:00",
"2029-01-01 00:00:00",
"2030-01-01 00:00:00",
"2031-01-01 00:00:00",
"2032-01-01 00:00:00",
"2033-01-01 00:00:00",
"2034-01-01 00:00:00",
"2035-01-01 00:00:00",
"2036-01-01 00:00:00",
"2037-01-01 00:00:00",
"2038-01-01 00:00:00",
"2039-01-01 00:00:00",
"2040-01-01 00:00:00",
"2041-01-01 00:00:00"
],
"unit": "GWh",
"values": [
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
0.0
]
},
"timesteps": [
"2020-01-01 00:00:00",
"2020-06-01 00:00:00",
Expand Down
Loading

0 comments on commit 464047f

Please sign in to comment.