power_balance.core#
Source: power_balance/core.py
Class PowerBalance#
PowerBalance(config: str = '/home/runner/work/powerbalance/powerbalance/power_balance/configs/default_config.toml', no_browser: bool = False, modelica_file_dir: str = 'Default', profiles_directory: str = 'Default', parameter_directory: str = 'Default', print_intro: bool = False) -> None
Main Power Balance class for running the Modelica models contained within the 'models' submodule. This class handles compiling and running, as well as the setting of parameter values.
Attributes#
-
power_data
:Dict[str, pd.DataFrame]
,typing.
power data stored after a simulation run (else None)
-
configuration
:Dict[str, typing.Any]
,typing.
current configuration options as dictionary
Methods#
add_models#
add_models(self, model_path: str, model_names: List[str] = None) -> None
Read model(s) from a given OM file and add to simulation list.
Parameters#
-
model_path
:str
file address of the modelica file containing the models
-
model_names
:typing.List
, defaultNone
list of models to import by name, by default all
apply_model_configuration#
apply_model_configuration(self, model_name: str) -> None
Applies the configuration within the configuration options provided.
Parameters#
-
model_name
:str
name of model to apply configuration to
clear_cache#
clear_cache(self) -> None
Clear the PyDelica session cache As we do not use pydelica.Session as a context manager we need to do the cache clear manually (else risking leaving a lot of temporary directories on Windows)
get_parameters#
get_parameters(self, model: str = None, include_undefined: bool = False) -> Any
Retrieve all model parameters including those that cannot be modified
Parameters#
-
model
:str
, defaultNone
name of model to retrieve parameters from, by default first compiled
-
include_undefined
:bool
, defaultFalse
include parameters with a value of 'None', by default False
Returns#
-
typing.Any
a dictionary of the model parameters and their values
get_power#
get_power(self, model_name: str) -> pandas.core.frame.DataFrame
Retrieve the power results from a Modelica model after simulation
Parameters#
-
model_name
:str
name of the Modelica model
Returns#
-
pandas.core.frame.DataFrame
dataframe containing the power values for each of the subsystems
launch_browser#
launch_browser(self) -> None
Opens local web browser to view result plots
load_parameters#
load_parameters(self, directory: str) -> None
Load parameters from a given directory specifying which file is the simulation options file
Parameters#
-
directory
:str
directory containing all parameter TOML files
modifiable_parameters#
modifiable_parameters(self) -> List[str]
Get a list of parameters that can be modified by the user
Returns#
-
typing.List
list of parameters which can be modified
plot_results#
plot_results(self, output_directory: str) -> List[str]
Create all plots images for all power variables.
Parameters#
-
output_directory
:str
directory to save created images.
Returns#
-
typing.List
list of output plot file names
read_models_from_directory#
read_models_from_directory(self) -> None
Read all Modelica '.mo' files from the directory given Reads the models from the directory given within the configuration this directory is changed to a temporary directory if any templating of the Modelica models is required (e.g. addition of PF magnets)
remove_models#
remove_models(self, model_names: List[str]) -> None
Remove models from the power_balance.PowerBalance
instance so they are not run during simulation
Parameters#
-
model_names
:typing.List
list of names of models to remove
run_simulation#
run_simulation(self, output_directory: str = '', sweep_dict: Optional[Dict[str, Any]] = None) -> None
Acts as a driver for the back end functions handling the interface with OpenModelica
Parameters#
-
output_directory
:str
, default ````directory for output files
-
sweep_dict
:typing.Optional
, defaultNone
perform sweep for the given parameters using a dictionary containing range information, by default None (no sweep)
save_configuration#
save_configuration(self, output_directory: str) -> None
Save configuration for the session so it can be loaded later
Parameters#
-
output_directory
:str
directory to save the config folder to
save_parameters#
save_parameters(self, output_directory: str) -> None
Save parameters for the session so they can be loaded later
Parameters#
-
output_directory
:str
directory to save the parameter sets to
save_profiles#
save_profiles(self, output_directory: str) -> None
Save profiles for the session so they can be loaded later
Parameters#
-
output_directory
:str
directory to save the profile folder to
set_model_parameters#
set_model_parameters(self, model_name: str, allow_param_failure: bool = False) -> None
Read parameters from the parameter set object within the API and then assign them to the given Modelica System
Parameters#
-
model_name
:str
the name of the model
-
allow_param_failure
:bool
, defaultFalse
whether or not a failed parameter search during assignment throws an exception, by default False
set_parameter_value#
set_parameter_value(self, parameter_name: str, value: Any) -> Any
typing.Tuple a parameter within the parameter set to a given value.
Parameters#
-
parameter_name
:str
name of the parameter to be modified
-
value
:typing.Any
new value to assign to that parameter
Returns#
-
typing.Any
the value read from the parameter after it has been set
update_model_input_paths#
update_model_input_paths(self) -> None
Replace all variables defined as 'Path' variables with an absolute path in order to correctly read in the required inputs.
write_data#
write_data(self, output_directory: str) -> None
Write the resulting data frames to a HDF5 file which allows inclusion of various key metadata alongside the datasets
Parameters#
-
output_directory
:str
location to write output data files
get_plugins#
get_plugins(plugin_order_list: List[str] = None) -> Tuple[str, ...]
save_plugin_displays#
save_plugin_displays(output_directory: str) -> None
Save the plugin display files so they can be loaded later
Parameters#
-
output_directory
:str
directory to save the display folder to