11import os
22import tempfile
3+ import warnings
34from pathlib import Path
45
56import pandas as pd
@@ -15,7 +16,6 @@ def __init__(
1516 self ,
1617 model_path : Path | str ,
1718 simulation_options : dict [str , float | str | int ] = None ,
18- x : pd .DataFrame = None ,
1919 output_list : list [str ] = None ,
2020 simulation_path : Path = None ,
2121 x_combitimetable_name : str = None ,
@@ -33,9 +33,6 @@ def __init__(
3333 - simulation_options (dict[str, float | str | int], optional):
3434 Options for the simulation. May include values for "startTime",
3535 "stopTime", "stepSize", "tolerance", "solver", "outputFormat".
36- - x (pd.DataFrame, optional): Input data for the simulation. Index shall
37- be a DatetimeIndex or integers. Columns must match the combi time table
38- used to specify boundary conditions in the Modelica System.
3936 - output_list (list[str], optional): List of output variables. Default
4037 will output all available variables.
4138 - simulation_path (Path, optional): Path to run the simulation and
@@ -57,7 +54,7 @@ def __init__(
5754 if not os .path .exists (self ._simulation_path ):
5855 os .mkdir (simulation_path )
5956
60- self ._x = x if x is not None else pd .DataFrame ()
57+ self ._x = pd .DataFrame ()
6158 self .output_list = output_list
6259 self .omc = OMCSessionZMQ ()
6360 self .omc .sendExpression (f'cd("{ self ._simulation_path .as_posix ()} ")' )
@@ -105,6 +102,13 @@ def simulate(
105102 self .set_param_dict (parameter_dict )
106103
107104 if simulation_options is not None :
105+ if x is not None and 'x' in simulation_options :
106+ warnings .warn (
107+ "Boundary file 'x' specified both in simulation_options and as a direct parameter."
108+ " The 'x' provided in simulate() will be used." ,
109+ UserWarning
110+ )
111+
108112 self ._set_simulation_options (simulation_options )
109113
110114 if x is not None :
@@ -172,18 +176,24 @@ def get_parameters(self):
172176 return self .model .getParameters ()
173177
174178 def _set_simulation_options (self , simulation_options ):
175- self .model .setSimulationOptions (
176- [
177- f'startTime={ simulation_options ["startTime" ]} ' ,
178- f'stopTime={ simulation_options ["stopTime" ]} ' ,
179- f'stepSize={ simulation_options ["stepSize" ]} ' ,
180- f'tolerance={ simulation_options ["tolerance" ]} ' ,
181- f'solver={ simulation_options ["solver" ]} ' ,
182- f'outputFormat={ simulation_options ["outputFormat" ]} ' ,
183- ]
184- )
179+ standard_options = {
180+ 'startTime' : simulation_options .get ('startTime' ),
181+ 'stopTime' : simulation_options .get ('stopTime' ),
182+ 'stepSize' : simulation_options .get ('stepSize' ),
183+ 'tolerance' : simulation_options .get ('tolerance' ),
184+ 'solver' : simulation_options .get ('solver' ),
185+ 'outputFormat' : simulation_options .get ('outputFormat' )
186+ }
187+
188+ # Filtrer les options None
189+ options = [f'{ k } ={ v } ' for k , v in standard_options .items () if v is not None ]
190+ self .model .setSimulationOptions (options )
185191 self .simulation_options = simulation_options
186192
193+ # Gérer x s'il est présent dans les options
194+ if 'x' in simulation_options :
195+ self ._set_x (simulation_options ['x' ])
196+
187197 def _set_x (self , df : pd .DataFrame ):
188198 """Sets the input data for the simulation and updates the corresponding file."""
189199 if not self ._x .equals (df ):
@@ -244,3 +254,4 @@ def library_contents(library_path):
244254 for file in files :
245255 file_path = os .path .join (root , file )
246256 print (file_path )
257+
0 commit comments