Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
322 commits
Select commit Hold shift + click to select a range
387cac6
Adjust IO to account for attrs of DataArrays in a Dataset
FBumann Jun 24, 2025
27734cf
Rename transforming and connection methods in FlowSystem
FBumann Jun 24, 2025
4915b81
Compacted IO methods
FBumann Jun 24, 2025
fc5549a
Remove infos()
FBumann Jun 24, 2025
299ff43
remove from_dict() and to_dict()
FBumann Jun 24, 2025
abc22b1
Update __str__ of Interface
FBumann Jun 24, 2025
9b4c44c
Improve str and repr
FBumann Jun 24, 2025
0ab7ea6
Improve str and repr
FBumann Jun 24, 2025
1dcbbb0
Add docstring
FBumann Jun 24, 2025
9aec990
Unify IO stuff in Interface class
FBumann Jun 24, 2025
e370311
Improve test tu utilize __eq__ method
FBumann Jun 24, 2025
793e820
Make Interface class more robust and improve exceptions
FBumann Jun 24, 2025
b87d979
Add option to copy Interfaces (And the FlowSystem)
FBumann Jun 24, 2025
8ec265e
Make a copy of a FLowSytsem that gets reused in a second Calculation
FBumann Jun 25, 2025
a46fe64
Remove test_timeseries.py
FBumann Jun 25, 2025
201d066
Reorganizing Datatypes
FBumann Jun 25, 2025
10d2925
Remove TImeSeries and TimeSeriesCollection entirely
FBumann Jun 25, 2025
cf9d17f
Remove old method
FBumann Jun 25, 2025
bd52e05
Add option to get structure with stats of dataarrays
FBumann Jun 25, 2025
aa36689
Change __str__ method
FBumann Jun 25, 2025
63b1c92
Remove old methods
FBumann Jun 25, 2025
29062fa
remove old imports
FBumann Jun 25, 2025
18c43e4
Add isel, sel and resample methods to FlowSystem
FBumann Jun 26, 2025
1f9ef07
Remove need for timeseries with extra timestep
FBumann Jun 26, 2025
5d88fde
Simplify IO of FLowSystem
FBumann Jun 26, 2025
1e94de3
Remove parameter timesteps from IO
FBumann Jun 26, 2025
e5828ad
Improve Exceptions and Docstrings
FBumann Jun 26, 2025
870efee
Improve isel sel and resample methods
FBumann Jun 26, 2025
e97ec5f
Change test
FBumann Jun 26, 2025
f15113e
Bugfix
FBumann Jun 26, 2025
284072e
Improve
FBumann Jun 26, 2025
ebbb5dd
Improve
FBumann Jun 26, 2025
a501e05
Add test for Storage Bounds
FBumann Jun 26, 2025
1825089
Add test for Storage Bounds
FBumann Jun 26, 2025
126b07f
CHANGELOG.md
FBumann Jun 26, 2025
94d841d
ruff check
FBumann Jun 26, 2025
c19edc8
Improve types
FBumann Jun 26, 2025
36cf47d
CHANGELOG.md
FBumann Jun 26, 2025
8f1261d
Bugfix in Storage
FBumann Jun 26, 2025
89d69f0
Revert changes in example_calculation_types.py
FBumann Jun 26, 2025
76f51a8
Revert changes in simple_example.py
FBumann Jun 26, 2025
0ff4d29
Add convenient access to Elements in FlowSystem
FBumann Jun 26, 2025
84c850b
Get Aggregated Calculation Working
FBumann Jun 27, 2025
8b9dabb
Segmented running with wrong results
FBumann Jun 27, 2025
7e72ab5
Use new persistent FLowSystem to create Calculations upfront
FBumann Jun 27, 2025
17632f3
Improve SegmentedCalcualtion
FBumann Jun 27, 2025
3c355c9
Improve SegmentedCalcualtion
FBumann Jun 27, 2025
f473ce5
Fix SegmentedResults IO
FBumann Jun 27, 2025
7869a72
ruff check
FBumann Jun 27, 2025
bb29ef2
Update example
FBumann Jun 27, 2025
8d96a49
Updated logger essages to use .label_full instead of .label
FBumann Jun 27, 2025
8240da1
Re-add parameters. Use deprecation warning instead
FBumann Jun 27, 2025
8ac2664
Update changelog
FBumann Jun 27, 2025
43a64ea
Improve warning message
FBumann Jun 27, 2025
7b67f8d
Merge branch 'unify-timesteps' into scenarios-no-ts/main
FBumann Jun 27, 2025
b3fe443
Merge
FBumann Jun 27, 2025
483ba12
Merge
FBumann Jun 28, 2025
dee1de4
Fit scenario weights to model coords when transforming
FBumann Jun 28, 2025
4ec3914
Merge
FBumann Jun 28, 2025
2554d8a
Removing logic between minimum, maximum and fixed size from InvestPar…
FBumann Jun 28, 2025
d062727
Remove selected_timesteps
FBumann Jun 28, 2025
6dc23f5
Improve TypeHints
FBumann Jun 28, 2025
e6100d6
New property on InvestParameters for min/max/fixed size
FBumann Jun 28, 2025
46f2035
Move logic for InvestParameters in Transmission to from Model to Inte…
FBumann Jun 28, 2025
6baeb8e
Make transformation of data more hierarchical (Flows after Components)
FBumann Jun 28, 2025
aeaaa83
Add scenario validation
FBumann Jun 28, 2025
15fd124
Change Transmission to have a "balanced" attribute. Change Tests acco…
FBumann Jun 28, 2025
d0b231d
Improve index validations
FBumann Jun 28, 2025
4ebe6a5
rename method in tests
FBumann Jun 29, 2025
6b56dac
Update DataConverter
FBumann Jun 29, 2025
a7ec994
Add DataFrame Support back
FBumann Jun 29, 2025
2a75ed3
Add copy() to DataConverter
FBumann Jun 29, 2025
dae9f01
Update fit_to_model_coords to take a list of coords
FBumann Jun 29, 2025
ba195ff
Make the DataConverter more universal by accepting a list of coords/dims
FBumann Jun 29, 2025
605f034
Update DataConverter for n-d arrays
FBumann Jun 29, 2025
6560006
Update DataConverter for n-d arrays
FBumann Jun 29, 2025
78132ef
Add extra tests for 3-dims
FBumann Jun 29, 2025
a53c116
Add FLowSystemDimension Type
FBumann Jun 30, 2025
2cb551b
Revert some logic about the fit_to_model coords
FBumann Jun 30, 2025
d7be766
Adjust FLowSystem IO for scenarios
FBumann Jun 30, 2025
e60dd07
BUGFIX: Raise Exception instead of logging
FBumann Jun 30, 2025
bd2f1b8
Change usage of TimeSeriesData
FBumann Jun 30, 2025
a7da9d2
Adjust logic to handle non scalars
FBumann Jun 30, 2025
b8f0e22
Adjust logic to _resolve_dataarray_reference into separate method
FBumann Jun 30, 2025
7123b6b
Update IO of FlowSystem
FBumann Jun 30, 2025
fa5475d
Improve get_coords()
FBumann Jul 2, 2025
80cb161
Adjust FlowSystem init for correct IO
FBumann Jul 2, 2025
81ad3ba
Add scenario to sel and isel methods, and dont normalize scenario wei…
FBumann Jul 2, 2025
691a45e
Improve scenario_weights_handling
FBumann Jul 2, 2025
3931ac5
Add warning for not scaled weights
FBumann Jul 2, 2025
75a45e1
Update test_scenarios.py
FBumann Jul 2, 2025
2882147
Improve util method
FBumann Jul 2, 2025
50491ff
Add objective to solution dataset.
FBumann Jul 2, 2025
4f3a798
Update handling of scenario_weights update tests
FBumann Jul 2, 2025
314aef9
Ruff check. Fix type hints
FBumann Jul 2, 2025
0302947
Fix type hints and improve None handling
FBumann Jul 3, 2025
40c437a
Fix coords in AggregatedCalculation
FBumann Jul 3, 2025
8d2d208
Improve Error Messages of DataConversion
FBumann Jul 3, 2025
9c0c95f
Allow multi dim data conversion and broadcasting by length
FBumann Jul 3, 2025
d568ad6
Improve DataConverter to handle multi-dim arrays
FBumann Jul 3, 2025
ffc196a
Rename methods and remove unused code
FBumann Jul 5, 2025
6142f44
Improve DataConverter by better splitting handling per datatype. Seri…
FBumann Jul 5, 2025
cec7367
Add test for error handling
FBumann Jul 5, 2025
eba1ec4
Update scenario example
FBumann Jul 5, 2025
5f97bf3
Fix Handling of TimeSeriesData
FBumann Jul 7, 2025
9351083
Improve DataConverter
FBumann Jul 7, 2025
99e6b19
Fix resampling of the FlowSystem
FBumann Jul 15, 2025
4981a9c
Improve Warning Message
FBumann Jul 15, 2025
516f45b
Add example that leverages resampling
FBumann Jul 15, 2025
ef0acfc
Add example that leverages resampling adn fixing of Investments
FBumann Jul 16, 2025
706c1ec
Add flag to Calculation if its modeled
FBumann Jul 16, 2025
a4cdb43
Make flag for connected_and_transformed FLowSystem public
FBumann Jul 16, 2025
148a852
Make Calcualtion Methods return themselfes to make them chainable
FBumann Jul 16, 2025
61755f9
Improve example
FBumann Jul 16, 2025
66f6a86
Improve Unreleased CHANGELOG.md
FBumann Jul 16, 2025
a757e7f
Add year coord to FlowSystem
FBumann Jul 8, 2025
941d93f
Improve dimension handling
FBumann Jul 8, 2025
745e885
Change plotting to use an indexer instead
FBumann Jul 8, 2025
c9bae2a
Change plotting to use an indexer instead
FBumann Jul 15, 2025
d1b5509
Use tuples to set dimensions in Models
FBumann Jul 16, 2025
c7568dd
Bugfix in validation logic and test
FBumann Jul 16, 2025
fc62634
Improve Errors
FBumann Jul 16, 2025
e320b9f
Improve weights handling and rescaling if None
FBumann Jul 16, 2025
33a22aa
Fix typehint
FBumann Jul 16, 2025
904211f
Update Broadcasting in Storage Bounds and improve type hints
FBumann Jul 16, 2025
3c6c08b
Make .get_model_coords() return an actual xr.Coordinates Object
FBumann Jul 16, 2025
22a1cef
Improve get_coords()
FBumann Jul 17, 2025
44dbefc
Rename SystemModel to FlowSystemModel
FBumann Jul 17, 2025
f82556a
First steps
FBumann Jul 18, 2025
33460a0
Improve Feature Patterns
FBumann Jul 18, 2025
ff70674
Improve acess to variables via short names
FBumann Jul 18, 2025
fa5e30a
Improve
FBumann Jul 18, 2025
a3511f9
Add naming options to big_m_binary_bounds()
FBumann Jul 18, 2025
404dc03
Fix and improve FLowModeling with Investment
FBumann Jul 18, 2025
1ad74ce
Improve
FBumann Jul 18, 2025
d1408a4
Tyring to improve the Methods for bounding variables in different sce…
FBumann Jul 18, 2025
ab000ca
Improve BoundingPatterns
FBumann Jul 18, 2025
2afc24e
Improve BoundingPatterns
FBumann Jul 18, 2025
b248f58
Improve BoundingPatterns
FBumann Jul 18, 2025
d34445c
Fix duration Modeling
FBumann Jul 18, 2025
bde07b4
Fix On + Size
FBumann Jul 18, 2025
5861b28
Fix InvestmentModel
FBumann Jul 19, 2025
7809ee4
Fix Models
FBumann Jul 19, 2025
2bbdb44
Update constraint names in test
FBumann Jul 19, 2025
2a01abe
Fix OnOffModel for multiple Flows
FBumann Jul 19, 2025
1f1ebb7
Update constraint names in tests
FBumann Jul 19, 2025
c7b351f
Simplify
FBumann Jul 19, 2025
5d9b591
Improve handling of vars/cons and models
FBumann Jul 19, 2025
5c56b63
Revising the basic structure of a class Model
FBumann Jul 20, 2025
9d242b6
Revising the basic structure of a class Model
FBumann Jul 20, 2025
0997843
Simplify and focus more on own Model class
FBumann Jul 21, 2025
1d6ef97
Update tests
FBumann Jul 21, 2025
972cb90
Improve state computation in ModelingUtilities
FBumann Jul 21, 2025
29bec8c
Improve handling of previous flowrates
FBumann Jul 21, 2025
370ac94
Imropove repr and submodel acess
FBumann Jul 21, 2025
0f89ff0
Update access pattern in tests
FBumann Jul 21, 2025
4781cff
Fix PiecewiseEffects and StorageModel
FBumann Jul 21, 2025
333ab83
Fix StorageModel and Remove PreventSimultaniousUseModel
FBumann Jul 21, 2025
9702303
Fix Aggregation and SegmentedCalculation
FBumann Jul 21, 2025
91bd461
Update tests
FBumann Jul 21, 2025
94314c3
Loosen precision in tests
FBumann Jul 21, 2025
50cc2cb
Update test_on_hours_computation.py and some types
FBumann Jul 21, 2025
e52f800
Rename class Model to Submodel
FBumann Jul 21, 2025
9281256
rename sub_model to submodel everywhere
FBumann Jul 21, 2025
9001c6a
rename self.model to self.submodel everywhere
FBumann Jul 21, 2025
286a8b7
Rename .model with .submodel if its only a submodel
FBumann Jul 21, 2025
ae1752b
Rename .sub_models with .submodels
FBumann Jul 21, 2025
1822384
Improve repr
FBumann Jul 22, 2025
2aa9d4b
Improve repr
FBumann Jul 22, 2025
5ca9707
Include def do_modeling() into __init__() of models
FBumann Jul 22, 2025
7e04399
Make properties private
FBumann Jul 22, 2025
4f95ebc
Improve Inheritance of Models
FBumann Jul 22, 2025
f73fe99
Merge branch 'main' into v3.0.0/main
FBumann Jul 22, 2025
2d9c920
V3.0.0/plotting (#285)
FBumann Jul 22, 2025
5fd05e3
ruff check
FBumann Jul 22, 2025
20a1964
Improve typehints
FBumann Jul 22, 2025
9b05f8f
Update CHANGELOG.md
FBumann Jul 22, 2025
4d7fd29
Bugfix from renaming to .submodel
FBumann Jul 22, 2025
3626517
Bugfix from renaming to .submodel
FBumann Jul 23, 2025
50fbb67
Improve indexer in results plotting
FBumann Jul 23, 2025
9368985
rename register_submodel() to .add_submodels() adn add SUbmodels coll…
FBumann Jul 23, 2025
e4ec410
Add nice repr to FlowSystemModel and Submodel
FBumann Jul 23, 2025
66283cb
Bugfix .variables and .constraints
FBumann Jul 23, 2025
a84dfad
Add type checks to modeling.py
FBumann Jul 23, 2025
d2182aa
Improve assertion in tests
FBumann Jul 23, 2025
75c05ee
Improve docstrings and register ElementModels directly in FlowSystemM…
FBumann Jul 23, 2025
66a6ff1
Improve __repr__()
FBumann Jul 23, 2025
e2e1f13
ruff check
FBumann Jul 23, 2025
62b18b6
Use new method to compare sets in tests
FBumann Jul 23, 2025
5f0b503
ruff check
FBumann Jul 23, 2025
15a08e9
Update Contribute.md, some dependencies and add pre-commit
FBumann Jul 23, 2025
97de53c
Pre commit hook
FBumann Jul 23, 2025
25f726e
Run Pre-Commit Hook for the first time
FBumann Jul 23, 2025
1716607
Fix link in README.md
FBumann Jul 23, 2025
b4a9236
Update Effect name in tests to be 'costs' instead of 'Costs' Everywhere
FBumann Jul 23, 2025
b7734f8
Improve some of the modeling and coord handling
FBumann Jul 23, 2025
e06692b
Add tests with years and scenarios
FBumann Jul 23, 2025
cf0186c
Update tests to run with multiple coords
FBumann Jul 23, 2025
5510297
Fix Effects dataset computation in case of empty effects
FBumann Jul 23, 2025
b694dbe
Update Test for multiple dims
FBumann Jul 24, 2025
262e8b4
Fix test with multiple dims
FBumann Jul 28, 2025
2a469f1
Fix test with multiple dims
FBumann Jul 28, 2025
159bcb3
New test
FBumann Jul 28, 2025
e764a13
New test for previous flow_rates
FBumann Jul 28, 2025
20f74f3
Merge pull request #286 from flixOpt/v3.0.0/testing
FBumann Jul 28, 2025
2c1c750
Add Model for YearAwareInvestments
FBumann Jul 29, 2025
70979fb
Add FlowSystem.years_per_year attribute and "years_of_last_year" para…
FBumann Jul 29, 2025
c9c4ddf
Add YearAwareInvestmentModel
FBumann Jul 29, 2025
85ec956
Add new Interface
FBumann Jul 29, 2025
18146c2
Improve YearAwareInvestmentModel
FBumann Jul 29, 2025
015aa1d
Rename and improve
FBumann Jul 30, 2025
e6da5ad
Move piecewise_effects
FBumann Jul 30, 2025
aafe95b
COmbine TImingInvestment into a single interface
FBumann Jul 30, 2025
9316d8a
Add model tests for investment
FBumann Jul 30, 2025
5ecb3c9
Add size_changes variables
FBumann Jul 31, 2025
b1c9b71
Add size_changes variables
FBumann Jul 31, 2025
3c98553
Improve InvestmentModel
FBumann Jul 31, 2025
5688c8f
Improve InvestmentModel
FBumann Aug 4, 2025
84c8f15
Rename parameters
FBumann Aug 4, 2025
566bcdf
remove old code
FBumann Aug 4, 2025
c334515
Add a duration_in_years to the InvestTimingParameters
FBumann Aug 4, 2025
98216e2
Improve handling of fixed_duration
FBumann Aug 5, 2025
7b45a19
Improve validation and make Investment/divestment optional by default
FBumann Aug 5, 2025
b919c0a
Rename some vars and improve previous handling
FBumann Aug 5, 2025
8e21165
Add validation for previous size
FBumann Aug 5, 2025
c2ce728
Change fit_to_model_coords to work with a Collection of dims
FBumann Aug 5, 2025
02c1f31
Improve fit_to_model_coords
FBumann Aug 5, 2025
5f85887
Improve test
FBumann Aug 5, 2025
815b8bf
Update transform_data()
FBumann Aug 6, 2025
1ffe27f
Add new "year of investment" coord to FlowSystem
FBumann Aug 7, 2025
3632965
Add 'year_of_investment' dimension to FlowSystem
FBumann Aug 7, 2025
9d78314
Improve InvestmentTiming
FBumann Aug 7, 2025
ca6fb06
Improve InvestmentTiming
FBumann Aug 7, 2025
abbe534
Add specific_effect back
FBumann Aug 7, 2025
6f550dd
add effects_by_investment_year back
FBumann Aug 7, 2025
b618578
Add year_of_investment to FLowSystem.sel()
FBumann Aug 7, 2025
4ff3e31
Improve Interface
FBumann Aug 7, 2025
98b6072
Handle selection of years properly again
FBumann Aug 7, 2025
fa4c107
Temp
FBumann Aug 7, 2025
f29dcde
Make ModelingPrimitives.consecutive_duration_tracking() dim-agnostic
FBumann Aug 13, 2025
d7574d8
Use new lifetime variable and constraining methods
FBumann Aug 13, 2025
1e61937
Improve Plausibility check
FBumann Aug 13, 2025
da3f29f
Improve InvestmentTImingParameters
FBumann Aug 13, 2025
331ed06
Improve weights
FBumann Aug 13, 2025
16c7481
Adjust test
FBumann Aug 13, 2025
e9e5e04
Remove old classes
FBumann Aug 13, 2025
1474af6
V3.0.0/main fit to model coords improve (#295)
FBumann Aug 13, 2025
d81a150
Merge branch 'v3.0.0/main' into v3.0.0/invest
FBumann Aug 13, 2025
3f03d22
ruff format
FBumann Sep 2, 2025
299f629
Merge remote-tracking branch 'origin/v3.0.0/invest' into dev
FBumann Sep 13, 2025
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
1 change: 1 addition & 0 deletions flixopt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
FlowSystem,
FullCalculation,
InvestParameters,
InvestTimingParameters,
LinearConverter,
OnOffParameters,
Piece,
Expand Down
8 changes: 5 additions & 3 deletions flixopt/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .config import CONFIG
from .core import DataConverter, Scalar, TimeSeriesData, drop_constant_arrays
from .elements import Component
from .features import InvestmentModel
from .features import InvestmentModel, InvestmentTimingModel
from .flow_system import FlowSystem
from .results import CalculationResults, SegmentedCalculationResults
from .solvers import _Solver
Expand Down Expand Up @@ -113,13 +113,15 @@ def main_results(self) -> Dict[str, Union[Scalar, Dict]]:
model.label_of_element: model.size.solution
for component in self.flow_system.components.values()
for model in component.submodel.all_submodels
if isinstance(model, InvestmentModel) and model.size.solution.max() >= CONFIG.modeling.EPSILON
if isinstance(model, (InvestmentModel, InvestmentTimingModel))
and model.size.solution.max() >= CONFIG.modeling.EPSILON
},
'Not invested': {
model.label_of_element: model.size.solution
for component in self.flow_system.components.values()
for model in component.submodel.all_submodels
if isinstance(model, InvestmentModel) and model.size.solution.max() < CONFIG.modeling.EPSILON
if isinstance(model, (InvestmentModel, InvestmentTimingModel))
and model.size.solution.max() < CONFIG.modeling.EPSILON
},
},
'Buses with excess': [
Expand Down
11 changes: 10 additions & 1 deletion flixopt/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
from .effects import Effect
from .elements import Bus, Flow
from .flow_system import FlowSystem
from .interface import InvestParameters, OnOffParameters, Piece, Piecewise, PiecewiseConversion, PiecewiseEffects
from .interface import (
InvestParameters,
InvestTimingParameters,
OnOffParameters,
Piece,
Piecewise,
PiecewiseConversion,
PiecewiseEffects,
)

__all__ = [
'TimeSeriesData',
Expand Down Expand Up @@ -48,4 +56,5 @@
'results',
'linear_converters',
'solvers',
'InvestTimingParameters',
]
6 changes: 3 additions & 3 deletions flixopt/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _plausibility_checks(self) -> None:
f'(in {self.label_full}) and variable size is uncommon. Please check if this is intended!'
)

def transform_data(self, flow_system: 'FlowSystem'):
def transform_data(self, flow_system: 'FlowSystem', name_prefix: str = '') -> None:
super().transform_data(flow_system)
if self.conversion_factors:
self.conversion_factors = self._transform_conversion_factors(flow_system)
Expand Down Expand Up @@ -207,7 +207,7 @@ def create_model(self, model: FlowSystemModel) -> 'StorageModel':
self.submodel = StorageModel(model, self)
return self.submodel

def transform_data(self, flow_system: 'FlowSystem') -> None:
def transform_data(self, flow_system: 'FlowSystem', name_prefix: str = '') -> None:
super().transform_data(flow_system)
self.relative_minimum_charge_state = flow_system.fit_to_model_coords(
f'{self.label_full}|relative_minimum_charge_state',
Expand Down Expand Up @@ -393,7 +393,7 @@ def create_model(self, model) -> 'TransmissionModel':
self.submodel = TransmissionModel(model, self)
return self.submodel

def transform_data(self, flow_system: 'FlowSystem') -> None:
def transform_data(self, flow_system: 'FlowSystem', name_prefix: str = '') -> None:
super().transform_data(flow_system)
self.relative_losses = flow_system.fit_to_model_coords(
f'{self.label_full}|relative_losses', self.relative_losses
Expand Down
4 changes: 2 additions & 2 deletions flixopt/effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np
import xarray as xr

from .core import Scalar, TemporalData, TemporalDataUser
from .core import NonTemporalDataUser, Scalar, TemporalData, TemporalDataUser
from .features import ShareAllocationModel
from .structure import Element, ElementModel, FlowSystemModel, Interface, Submodel, register_class_for_io

Expand Down Expand Up @@ -192,7 +192,7 @@ def _do_modeling(self):
TemporalEffectsUser = Union[TemporalDataUser, Dict[str, TemporalDataUser]] # User-specified Shares to Effects
""" This datatype is used to define a temporal share to an effect by a certain attribute. """

NonTemporalEffectsUser = Union[Scalar, Dict[str, Scalar]] # User-specified Shares to Effects
NonTemporalEffectsUser = Union[NonTemporalDataUser, Dict[str, NonTemporalDataUser]] # User-specified Shares to Effects
""" This datatype is used to define a scalar share to an effect by a certain attribute. """

TemporalEffects = Dict[str, TemporalData] # User-specified Shares to Effects
Expand Down
51 changes: 32 additions & 19 deletions flixopt/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from .config import CONFIG
from .core import PlausibilityError, Scalar, TemporalData, TemporalDataUser
from .effects import TemporalEffectsUser
from .features import InvestmentModel, ModelingPrimitives, OnOffModel
from .interface import InvestParameters, OnOffParameters
from .features import InvestmentModel, InvestmentTimingModel, ModelingPrimitives, OnOffModel
from .interface import InvestParameters, InvestTimingParameters, OnOffParameters
from .modeling import BoundingPatterns, ModelingUtilitiesAbstract
from .structure import Element, ElementModel, FlowSystemModel, register_class_for_io

Expand Down Expand Up @@ -70,7 +70,7 @@ def create_model(self, model: FlowSystemModel) -> 'ComponentModel':
self.submodel = ComponentModel(model, self)
return self.submodel

def transform_data(self, flow_system: 'FlowSystem') -> None:
def transform_data(self, flow_system: 'FlowSystem', name_prefix: str = '') -> None:
if self.on_off_parameters is not None:
self.on_off_parameters.transform_data(flow_system, self.label_full)

Expand Down Expand Up @@ -118,7 +118,7 @@ def create_model(self, model: FlowSystemModel) -> 'BusModel':
self.submodel = BusModel(model, self)
return self.submodel

def transform_data(self, flow_system: 'FlowSystem'):
def transform_data(self, flow_system: 'FlowSystem', name_prefix: str = '') -> None:
self.excess_penalty_per_flow_hour = flow_system.fit_to_model_coords(
f'{self.label_full}|excess_penalty_per_flow_hour', self.excess_penalty_per_flow_hour
)
Expand Down Expand Up @@ -158,7 +158,7 @@ def __init__(
self,
label: str,
bus: str,
size: Union[Scalar, InvestParameters] = None,
size: Union[Scalar, InvestParameters, InvestTimingParameters] = None,
fixed_relative_profile: Optional[TemporalDataUser] = None,
relative_minimum: TemporalDataUser = 0,
relative_maximum: TemporalDataUser = 1,
Expand Down Expand Up @@ -238,7 +238,7 @@ def create_model(self, model: FlowSystemModel) -> 'FlowModel':
self.submodel = FlowModel(model, self)
return self.submodel

def transform_data(self, flow_system: 'FlowSystem'):
def transform_data(self, flow_system: 'FlowSystem', name_prefix: str = '') -> None:
self.relative_minimum = flow_system.fit_to_model_coords(
f'{self.label_full}|relative_minimum', self.relative_minimum
)
Expand Down Expand Up @@ -266,7 +266,7 @@ def transform_data(self, flow_system: 'FlowSystem'):

if self.on_off_parameters is not None:
self.on_off_parameters.transform_data(flow_system, self.label_full)
if isinstance(self.size, InvestParameters):
if isinstance(self.size, (InvestParameters, InvestTimingParameters)):
self.size.transform_data(flow_system, self.label_full)
else:
self.size = flow_system.fit_to_model_coords(f'{self.label_full}|size', self.size, dims=['year', 'scenario'])
Expand All @@ -276,7 +276,7 @@ def _plausibility_checks(self) -> None:
if np.any(self.relative_minimum > self.relative_maximum):
raise PlausibilityError(self.label_full + ': Take care, that relative_minimum <= relative_maximum!')

if not isinstance(self.size, InvestParameters) and (
if not isinstance(self.size, (InvestParameters, InvestTimingParameters)) and (
np.any(self.size == CONFIG.modeling.BIG) and self.fixed_relative_profile is not None
): # Default Size --> Most likely by accident
logger.warning(
Expand Down Expand Up @@ -377,15 +377,28 @@ def _create_on_off_model(self):
)

def _create_investment_model(self):
self.add_submodels(
InvestmentModel(
model=self._model,
label_of_element=self.label_of_element,
parameters=self.element.size,
label_of_model=self.label_of_element,
),
'investment',
)
if isinstance(self.element.size, InvestParameters):
self.add_submodels(
InvestmentModel(
model=self._model,
label_of_element=self.label_of_element,
parameters=self.element.size,
label_of_model=self.label_of_element,
),
'investment',
)
elif isinstance(self.element.size, InvestTimingParameters):
self.add_submodels(
InvestmentTimingModel(
model=self._model,
label_of_element=self.label_of_element,
parameters=self.element.size,
label_of_model=self.label_of_element,
),
'investment',
)
else:
raise ValueError(f'Invalid InvestParameters type: {type(self.element.size)}')

def _constraint_flow_rate(self):
if not self.with_investment and not self.with_on_off:
Expand Down Expand Up @@ -435,7 +448,7 @@ def with_on_off(self) -> bool:

@property
def with_investment(self) -> bool:
return isinstance(self.element.size, InvestParameters)
return isinstance(self.element.size, (InvestParameters, InvestTimingParameters))

# Properties for clean access to variables
@property
Expand Down Expand Up @@ -508,7 +521,7 @@ def absolute_flow_rate_bounds(self) -> Tuple[TemporalData, TemporalData]:
if not self.with_investment:
# Basic case without investment and without OnOff
lb = lb_relative * self.element.size
elif not self.element.size.optional:
elif isinstance(self.element.size, InvestParameters) and not self.element.size.optional:
# With non-optional Investment
lb = lb_relative * self.element.size.minimum_or_fixed_size

Expand Down
Loading
Loading