InputParser

class geojson_modelica_translator.modelica.input_parser.InputParser(modelica_filename)

Bases: object

Class to read in Modelica files (.mo) and provide basic operations.

__init__(modelica_filename)

Methods

__init__(modelica_filename)

add_connect(a, b, annotation)

Add a new connection of port a to port b.

add_model_object(model_name, model_instance, ...)

Add a new model object to the model

add_parameter(var_type, var_name, value, ...)

Add a new parameter.

find_connect(port_a, port_b)

Find an existing connection that has port_a and/or port_b.

find_model_object(obj_name)

Find a model object in the list of parsed objects :param obj_name: string, name (including the instance) :return: list, index and string of object

init_vars()

parse_mo()

reload()

Reparse the data.

remove_connect_string(a, b)

Remove a connection string that matches the a, b.

remove_object(obj_name)

Remove an object by a name.

replace_connect_string(a, b, new_a, new_b[, ...])

Replace content of the connect string with new_a and/or new_b

replace_model_string(model_name, ...)

Go through the models and find the model_name with a model_instance and change the value in the field to the new_value.

replace_within_string(new_string)

Replacement of the path portion of the within string

save()

Save the resulting file to the same file from which it was initialized

save_as(new_filename)

Save the resulting file with a new filename

serialize()

Serialize the modelica object to a string with line feeds

add_connect(a, b, annotation)

Add a new connection of port a to port b. The annotation will be appended on a new line.

Parameters
  • a – string, port a

  • b – string, port b

  • annotation – string, description

add_model_object(model_name, model_instance, data)

Add a new model object to the model

Parameters
  • model_name – string

  • model_instance – string

  • data – list of strings

add_parameter(var_type, var_name, value, description)

Add a new parameter. Will be prepended to the top of the models list

Parameters
  • var_type – string, type of Modelica variable, Real, Integer, String, Modelica.Units.SI.Area, etc.

  • var_name – string, name of the variable. Note that this does not check for conflicts.

  • value – variant, value to set the variable name to.

  • description – string, description of the parameter

find_connect(port_a, port_b)

Find an existing connection that has port_a and/or port_b. If there are more than one, then it will only return the first.

Parameters
  • port_a

  • port_b

Returns

find_model_object(obj_name)

Find a model object in the list of parsed objects :param obj_name: string, name (including the instance) :return: list, index and string of object

reload()

Reparse the data. This will remove any unsaved changes.

remove_connect_string(a, b)

Remove a connection string that matches the a, b.

Parameters
  • a – string, existing port a

  • b – string, existing port b

remove_object(obj_name)

Remove an object by a name. Can be any part of the object name.

Parameters

obj_name – string, object name to match

Returns

replace_connect_string(a, b, new_a, new_b, replace_all=False)

Replace content of the connect string with new_a and/or new_b

Parameters
  • a – string, existing port a

  • b – string, existing port b

  • new_a – string, new port (or none)

  • new_b – string, new port b (or none

  • replace_all – boolean, allow replacemnt of all strings

replace_model_string(model_name, model_instance, old_string, new_string)

Go through the models and find the model_name with a model_instance and change the value in the field to the new_value. This will replace the entire value of the model field.

This will not work with arrays or lists (e.g., {…}, […])

Parameters
  • model_name – string, name of the model

  • model_instance – string, instance of the model

  • old_string – string, name of the old string to replace

  • new_string – string, the new string

replace_within_string(new_string)

Replacement of the path portion of the within string

Parameters

new_string – string, what to replace the existing within string with.

save()

Save the resulting file to the same file from which it was initialized

Returns

save_as(new_filename)

Save the resulting file with a new filename

Parameters

new_filename

Returns

serialize()

Serialize the modelica object to a string with line feeds

Returns

string