Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 18 additions & 0 deletions docs/docs/about/migration_guides/v12.0_to_v13.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: v12.0 to v13.0
description: v12.0 to v13.0 migration
sidebar_position: -16
---

# v12.0 to v13.0

### Migration overview

#### Migrate ADJUSTMENT section for FACILITY_INPUTS

If you have been using [ADJUSTMENT](../references/ADJUSTMENT) section for `FACILITY_INPUTS`, you will need to adjust your input data accordingly, as this section has been removed in v13.0).

- **a.** If you have only loaded the file being used with `ADJUSTMENT` once, you can simply modify the original data file to include the adjustments directly. This can e.g. be done by copying data into Excel and apply the `Ax+b` formula directly to the data (ie. `data_value * factor + constant`), and save the file/overwrite the data in-place.
- **b.** If you have loaded the file more than once, or used different `ADJUSTMENT` settings for different instances, you will need to create separate data files for each instance, with the adjustments applied directly to the data in each file. Make sure that you
rerun your file after you have applied and saved the adjustments to the file, compare with original data, and see that there are no differences in the results.

12 changes: 8 additions & 4 deletions docs/docs/about/references/ADJUSTMENT.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# ADJUSTMENT
# ADJUSTMENT (removed in v13.0)
[eCalc Model](index.md)
/ [FACILITY_INPUTS](FACILITY_INPUTS)
/ [ADJUSTMENT](ADJUSTMENT)

| Required | Child of | Children/Options |
|----------|-----------------|------------------|
| No | FACILITY_INPUTS | CONSTANT <br /> FACTOR |
| Required | Child of | Children/Options | Removed |
|----------|-----------------|------------------|------------------|
| No | FACILITY_INPUTS | CONSTANT <br /> FACTOR | Removed in v13.0 |

:::warning
`ADJUSTMENT` has been removed in v13.0. See [Migration Guide](../migration_guides/v12.0_to_v13.0.md) on how to adjust your input data accordingly in >= v13.0
:::

## Description
For various reasons (degenerated equipment, liquid pumps, etc.), the predicted energy usage from
Expand Down
6 changes: 6 additions & 0 deletions docs/drafts/next.draft.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ sidebar_position: -59

## Breaking changes

### Facility Inputs Adjustments

`ADJUSTMENT` section for `FACILITY_INPUTS` has been removed. This section was rarely used and was of limited usefulness. The original data was adjusted early in the process,
and users would not get any extra functionality from using this section, rather than being able to reuse the same original data with different adjustments, or to make it easy to adjust
data on-the-fly, to e.g. reflect deterioration over time. See migration guide for how to adjust data now.

### CLI

- `--csv` will no longer disable the csv file, `--no-csv` should be used instead.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import numpy as np

from libecalc.common.interpolation import setup_interpolator_1d
from libecalc.common.list.adjustment import transform_linear
from libecalc.common.string.string_utils import generate_id
from libecalc.domain.infrastructure.energy_components.generator_set.generator_set_validator import GeneratorSetValidator
from libecalc.domain.resource import Resource
Expand All @@ -21,25 +20,16 @@ def __init__(
self,
name: str,
resource: Resource,
energy_usage_adjustment_constant: float,
energy_usage_adjustment_factor: float,
):
self._name = name
self._id = generate_id(self._name)
self.resource = resource
self.energy_usage_adjustment_constant = energy_usage_adjustment_constant
self.energy_usage_adjustment_factor = energy_usage_adjustment_factor
self.validator = GeneratorSetValidator(resource=self.resource)
self.validator.validate()

# Initialize the generator model
fuel_values = self.electricity2fuel_fuel_axis
power_values = self.electricity2fuel_power_axis
fuel_values = transform_linear(
np.array(fuel_values),
constant=energy_usage_adjustment_constant,
factor=energy_usage_adjustment_factor,
)
self._func = setup_interpolator_1d(
variable=np.array(power_values),
function_values=np.array(fuel_values),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ def __init__(
self,
headers: list[str],
data: list[list[float]],
energy_usage_adjustment_constant: float,
energy_usage_adjustment_factor: float,
variables: list[TimeSeriesVariable],
power_loss_factor: TimeSeriesPowerLossFactor | None = None,
):
Expand All @@ -53,8 +51,6 @@ def __init__(
self._tabular_energy_function = TabularEnergyFunction(
headers=headers,
data=data,
energy_usage_adjustment_constant=energy_usage_adjustment_constant,
energy_usage_adjustment_factor=energy_usage_adjustment_factor,
)
self._variables = variables

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from libecalc.common.energy_usage_type import EnergyUsageType
from libecalc.common.errors.exceptions import InvalidColumnException
from libecalc.common.interpolation import setup_interpolator_1d, setup_interpolator_n_dimensional
from libecalc.common.list.adjustment import transform_linear
from libecalc.domain.component_validation_error import (
ProcessEqualLengthValidationException,
ProcessHeaderValidationException,
Expand Down Expand Up @@ -40,31 +39,19 @@ def __init__(
self,
headers: list[str],
data: list[list[float]],
energy_usage_adjustment_constant: float,
energy_usage_adjustment_factor: float,
):
self.headers = headers
self.data = data
self.energy_usage_adjustment_constant = energy_usage_adjustment_constant
self.energy_usage_adjustment_factor = energy_usage_adjustment_factor
self.validate_headers()
self.validate_data()

"""Tabular consumer energy function [MW] or [Sm3/day]."""
function_values = self.get_function_values()
function_values = np.asarray(self.get_function_values(), dtype=np.float64)
variables = [Variable(name=name, values=values) for name, values in self.get_variables().items()]

self.required_variables = [variable.name for variable in variables]
function_values_adjusted = transform_linear(
values=np.reshape(np.asarray(function_values), -1),
constant=self.energy_usage_adjustment_constant,
factor=self.energy_usage_adjustment_factor,
)
# If function_values_adjusted can be a float, convert it to a 0-dim array:
if isinstance(function_values_adjusted, float):
function_values_adjusted = np.array([function_values_adjusted])

self._func = self._setup_interpolator(variables, function_values_adjusted)

self._func = self._setup_interpolator(variables, function_values)
self.energy_usage_type = self.get_energy_usage_type()

def interpolate(self, variables_array: np.ndarray) -> np.ndarray:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from libecalc.common.decorators.feature_flags import Feature
from libecalc.common.energy_usage_type import EnergyUsageType
from libecalc.common.errors.exceptions import InvalidColumnException
from libecalc.common.list.adjustment import transform_linear
from libecalc.common.list.list_utils import array_to_list
from libecalc.common.logger import logger
from libecalc.common.units import Unit
Expand Down Expand Up @@ -55,8 +54,6 @@ class CompressorModelSampled:

def __init__(
self,
energy_usage_adjustment_constant: float,
energy_usage_adjustment_factor: float,
energy_usage_type: EnergyUsageType,
energy_usage_values: list[float],
rate_values: list[float] | None = None,
Expand All @@ -83,21 +80,12 @@ def __init__(
self.validate_equal_list_lengths()
self.validate_non_negative_values()

function_values_adjusted: NDArray[np.float64] = transform_linear(
values=np.reshape(np.array(energy_usage_values).astype(float), -1),
constant=energy_usage_adjustment_constant,
factor=energy_usage_adjustment_factor,
)
function_values = np.asarray(energy_usage_values, dtype=np.float64)

self.fuel_values: NDArray[np.float64] | None = None

self.fuel_values_adjusted: NDArray[np.float64] | None = None
self.power_interpolation_values_adjusted: NDArray[np.float64] | None = None
if not self.function_values_are_power and self.power_interpolation_values:
self.fuel_values_adjusted = function_values_adjusted
self.power_interpolation_values_adjusted = transform_linear(
values=np.reshape(self.power_interpolation_values, -1),
constant=energy_usage_adjustment_constant,
factor=energy_usage_adjustment_factor,
)
self.fuel_values = np.asarray(energy_usage_values, dtype=np.float64)

variables: dict[str, list[float]] = {}
if rate_values is not None:
Expand All @@ -110,7 +98,7 @@ def __init__(
self.required_variables = list(variables.keys())

function_value_header = "ENERGY_USAGE"
sampled_data = pd.DataFrame(np.asarray(list(variables.values()) + [list(function_values_adjusted)]).transpose())
sampled_data = pd.DataFrame(np.asarray(list(variables.values()) + [list(function_values)]).transpose())
sampled_data.columns = list(variables.keys()) + [function_value_header]

apparent_dimension: int = len(self.required_variables)
Expand Down Expand Up @@ -258,7 +246,12 @@ def evaluate(
discharge_pressure=pd_to_evaluate,
)

turbine = self.Turbine(self.fuel_values_adjusted, self.power_interpolation_values_adjusted)
turbine = self.Turbine(
fuel_values=self.fuel_values,
power_values=np.asarray(self.power_interpolation_values, dtype=np.float64)
if self.power_interpolation_values is not None
else None,
)
turbine_result = turbine.calculate_turbine_power_usage(interpolated_consumer_values)
turbine_energy_result = turbine_result.get_energy_result() if turbine_result is not None else None
turbine_power = turbine_energy_result.power.values if turbine_energy_result is not None else None
Expand Down
10 changes: 2 additions & 8 deletions src/libecalc/domain/process/pump/pump.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,16 @@ class PumpModel:
pump_chart (ChartData): Data for pump chart with speed, head, rate and efficiency
head_margin (float, optional): Margin for accepting head values above maximum head from pump chart.
Values above within margin will be set to maximum. Defaults to 0.0.
energy_usage_adjustment_constant (float, optional): Constant to be added to the computed power. Defaults to 0.0.
energy_usage_adjustment_factor (float, optional): Factor to be multiplied to computed power. Defaults to 1.0.
"""

def __init__(
self,
pump_chart: ChartData,
head_margin: float = 0.0,
energy_usage_adjustment_constant: float = 0.0,
energy_usage_adjustment_factor: float = 1.0,
):
assert isinstance(pump_chart, ChartData)
self._pump_chart = Chart(pump_chart)
self._head_margin = head_margin
self._energy_usage_adjustment_constant = energy_usage_adjustment_constant
self._energy_usage_adjustment_factor = energy_usage_adjustment_factor

def get_max_standard_rates(
self,
Expand Down Expand Up @@ -199,7 +193,7 @@ def simulate(
:return: power [MW], head [J/kg], failure status
"""
if rate <= 0:
return self._energy_usage_adjustment_constant, 0.0, PumpFailureStatus.NO_FAILURE
return 0.0, 0.0, PumpFailureStatus.NO_FAILURE

# Reservoir rates: m3/day, pumpchart rates: m3/h
rate_m3_per_hour = rate / UnitConstants.HOURS_PER_DAY
Expand Down Expand Up @@ -257,7 +251,7 @@ def simulate(
)
power = power_before_efficiency_is_applied / efficiency[0]

power_out = power * self._energy_usage_adjustment_factor + self._energy_usage_adjustment_constant
power_out = power

return power_out, operational_head, failure_status

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ FACILITY_INPUTS:
EFFICIENCY: FRACTION
HEAD: M
RATE: AM3_PER_HOUR
ADJUSTMENT:
CONSTANT: 1.0
FACTOR: 0.8
- NAME: compressor_sampled_1d
FILE: einput/compressor_sampled_1d.csv
TYPE: COMPRESSOR_TABULAR
Expand Down
5 changes: 0 additions & 5 deletions src/libecalc/presentation/yaml/mappers/component_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
ConsumerFunctionMapper,
InvalidEnergyUsageModelException,
)
from libecalc.presentation.yaml.mappers.facility_input import _get_adjustment_constant, _get_adjustment_factor
from libecalc.presentation.yaml.mappers.yaml_mapping_context import MappingContext
from libecalc.presentation.yaml.mappers.yaml_path import YamlPath
from libecalc.presentation.yaml.model_validation_exception import ModelValidationException
Expand Down Expand Up @@ -255,15 +254,11 @@ def _resolve_fuel(
def _create_generator_set_model(self, reference: str) -> GeneratorSetModel:
model = self._references.get_generator_set_model(reference)
resource = self._get_resource(model.file, reference)
adjustment_constant = _get_adjustment_constant(model)
adjustment_factor = _get_adjustment_factor(model)

try:
return GeneratorSetModel(
name=model.name,
resource=resource,
energy_usage_adjustment_constant=adjustment_constant,
energy_usage_adjustment_factor=adjustment_factor,
)
except DomainValidationException as e:
raise ModelValidationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@
from libecalc.presentation.yaml.mappers.facility_input import (
_create_pump_chart_variable_speed_dto_model_data,
_create_pump_model_single_speed_dto_model_data,
_get_adjustment_constant,
_get_adjustment_factor,
_get_float_column_or_none,
)
from libecalc.presentation.yaml.mappers.fluid_mapper import (
Expand Down Expand Up @@ -788,8 +786,6 @@ def _create_compressor_sampled(self, model: YamlCompressorTabularModel, referenc
power_interpolation_values = _get_float_column_or_none(resource, power_header)

return CompressorModelSampled(
energy_usage_adjustment_constant=_get_adjustment_constant(data=model),
energy_usage_adjustment_factor=_get_adjustment_factor(data=model),
energy_usage_type=EnergyUsageType.FUEL if energy_usage_header == fuel_header else EnergyUsageType.POWER,
energy_usage_values=energy_usage_values,
rate_values=rate_values,
Expand Down Expand Up @@ -877,8 +873,6 @@ def create_tabular_model(self, reference: str) -> TabularEnergyFunction:
return TabularEnergyFunction(
headers=resource_headers,
data=resource_data,
energy_usage_adjustment_factor=_get_adjustment_factor(data=tabular_model),
energy_usage_adjustment_constant=_get_adjustment_constant(data=tabular_model),
)
except DomainValidationException as e:
raise ModelValidationException(errors=[self._create_error(str(e), reference=reference)]) from e
Expand Down Expand Up @@ -1064,8 +1058,6 @@ def _map_tabular(
return TabularConsumerFunction(
headers=energy_model.headers,
data=energy_model.data,
energy_usage_adjustment_constant=energy_model.energy_usage_adjustment_constant,
energy_usage_adjustment_factor=energy_model.energy_usage_adjustment_factor,
variables=variables,
power_loss_factor=power_loss_factor,
)
Expand Down
22 changes: 0 additions & 22 deletions src/libecalc/presentation/yaml/mappers/facility_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,12 @@
from libecalc.domain.resource import Resource
from libecalc.presentation.yaml.mappers.charts.user_defined_chart_data import UserDefinedChartData
from libecalc.presentation.yaml.yaml_types.facility_model.yaml_facility_model import (
YamlFacilityAdjustment,
YamlFacilityModelBase,
YamlGeneratorSetModel,
YamlPumpChartSingleSpeed,
YamlPumpChartVariableSpeed,
)


def _get_adjustment_constant(data: YamlFacilityModelBase) -> float:
if data.adjustment is None:
return YamlFacilityAdjustment().constant
return data.adjustment.constant


def _get_adjustment_factor(data: YamlFacilityModelBase) -> float:
if data.adjustment is None:
return YamlFacilityAdjustment().factor
return data.adjustment.factor


def _get_float_column_or_none(resource: Resource, header: str) -> list[float] | None:
try:
return resource.get_float_column(header)
Expand All @@ -38,8 +24,6 @@ def _create_pump_model_single_speed_dto_model_data(
pump_chart = UserDefinedChartData.from_resource(resource, units=facility_data.units, is_single_speed=True)
return PumpModel(
pump_chart=pump_chart,
energy_usage_adjustment_constant=_get_adjustment_constant(facility_data),
energy_usage_adjustment_factor=_get_adjustment_factor(facility_data),
head_margin=facility_data.head_margin,
)

Expand All @@ -51,8 +35,6 @@ def _create_pump_chart_variable_speed_dto_model_data(
pump_chart = UserDefinedChartData.from_resource(resource, units=facility_data.units, is_single_speed=False)
return PumpModel(
pump_chart=pump_chart,
energy_usage_adjustment_constant=_get_adjustment_constant(facility_data),
energy_usage_adjustment_factor=_get_adjustment_factor(facility_data),
head_margin=facility_data.head_margin,
)

Expand All @@ -62,13 +44,9 @@ def _create_generator_set_model(
facility_data: YamlGeneratorSetModel,
) -> GeneratorSetModel:
# Extract adjustment constants from facility data
adjustment_constant = _get_adjustment_constant(facility_data)
adjustment_factor = _get_adjustment_factor(facility_data)

# Create and return the GeneratorSetProcessUnit instance
return GeneratorSetModel(
name=facility_data.name,
resource=resource,
energy_usage_adjustment_constant=adjustment_constant,
energy_usage_adjustment_factor=adjustment_factor,
)
Loading
Loading