uesgraphs.systemmodels.templates

This module includes the UESModel graph to write Modelica code from uesgraphs

Functions

check_variable_name(name[, max_attempts])

set_up_logger(name[, log_dir, level])

Classes

Connector(type)

ModelInfoExtractor(path_library[, log_level])

A class to extract model information from OpenModelica classes.

Parameter(value, type[, category, ...])

A named tuple representing a modelica parameter.

UESTemplates(model_name, model_type[, ...])

A class to handle templates for model generation with uesgraphs.

uesgraphs.systemmodels.templates.check_variable_name(name, max_attempts=5)[source]
uesgraphs.systemmodels.templates.set_up_logger(name, log_dir=None, level=40)[source]
class uesgraphs.systemmodels.templates.UESTemplates(model_name, model_type, template_path=None)[source]

A class to handle templates for model generation with uesgraphs.

model_name

Name of the modelica model. (e.g. AixLib.Fluid.DistrictHeatingCooling.Supplies.OpenLoop.SourceIdeal)

Type:

str

model_type

Choose from [Supply, Demand, Pipe]

Type:

str

template_path

optional: sets the template path to a specific path

Type:

str

__init__(model_name, model_type, template_path=None)[source]
call_function(function_string)[source]

Calls function in template .. attribute:: function_string

Name of the function in the .mako file.

type:

str

generate_new_template(path_library)[source]

Generates a new template based on parameter and package information of the given class :param path_library: Path to package.mo of the used library (e.g. C:...Aixlibpackage.mo)

or list of paths to multiple used libraries

render(node_data, i=None, number_of_instances=None, package_name=None)[source]

Write Modelica code for Demands.OpenLoop.HeatPumpCarnot

Parameters:
  • node_data (dict) – information of systemmodel node

  • i (int) – Counter of instances

  • number_of_instances (int) – Number of total nodes of this type in graph

Returns:

mo – Rendered Modelica code

Return type:

str

classmethod generate_bulk(models_dict: Dict[str, List[str]], library_path: str | List[str], workspace: str | None = None, rigorous: bool = False) Dict[str, str][source]

Generate multiple templates in bulk.

Parameters:
  • models_dict – Dictionary mapping model types to lists of model names. Example: {“Demand”: [“Model1”, “Model2”], “Pipe”: [“Model3”]}

  • library_path – Path to Modelica library or list of library paths

  • workspace – Directory for generated templates (optional)

  • rigorous – If True, auto-overwrite existing templates without confirmation

Returns:

Dictionary mapping model names to their template paths or error messages

Example

>>> results = UESTemplates.generate_bulk(
...     {"Demand": ["AixLib.Fluid.SomeModel"]},
...     "/path/to/aixlib"
... )
classmethod generate_from_config(config_file: str, library_path: str | List[str] | None = None, **kwargs) Dict[str, str][source]

Generate templates from JSON configuration file.

Parameters:
  • config_file – Path to JSON configuration file

  • library_path – Path to Modelica library, list of paths, or None for auto-detection

  • **kwargs – Additional arguments passed to generate_bulk (workspace, rigorous, etc.)

Returns:

Dictionary mapping model names to template paths or error messages

Example

>>> results = UESTemplates.generate_from_config(
...     "data/templates/template_aixlib_components.json"
... )
class uesgraphs.systemmodels.templates.Parameter(value: Any, type: str, category: str = '', description: str = '', unit: str = '')[source]

A named tuple representing a modelica parameter.

value

The value of the parameter.

Type:

Any

type

The type of the parameter in model. Like Modelica.Units.SI.SpecificHeatCapacity or Boolean

Type:

str

category

The category of the parameter. Either “optional” or “mandatory”. Specified in _extract_parameters. Important for the template generation.

Type:

str, optional

description

A brief description of the parameter. Defaults to “”. Not needed yet.

Type:

str, optional

unit

The unit of measurement for the parameter. Defaults to “”. Not needed yet.

Type:

str, optional

Example

>>> param = Parameter(value=42, type="Integer", category="mandatory",
...                   description="The answer to life, the universe, and everything",
...                   unit="")
>>> print(param.value)
42
>>> print(param.category)
mandatory
value: Any

Alias for field number 0

type: str

Alias for field number 1

category: str

Alias for field number 2

description: str

Alias for field number 3

unit: str

Alias for field number 4

class uesgraphs.systemmodels.templates.Connector(type)[source]
type: str

Alias for field number 0

class uesgraphs.systemmodels.templates.ModelInfoExtractor(path_library: str, log_level: int = 20)[source]

A class to extract model information from OpenModelica classes.

__init__(path_library: str, log_level: int = 20)[source]
list_main_models()[source]

Lists all main models in the loaded library.

This method queries OpenModelica for a list of all main models in the currently loaded library. It returns a list of class names that can be used for further analysis.

Returns:

List[str]

A list of class names representing the main models in the loaded library.

Notes:

  • The method logs debug information about the found classes.

extract_model_info(model_name: str) Dict[str, Any][source]

Extracts parameters, connectors and packages from OpenModelica-classes.

Parameters:

model_name – Liste der zu untersuchenden Klassennamen

Returns:

Dictionary mit extrahierten Informationen (Parameters, Connectors, Packages)