MsxModel#

module wntr.msx.model

class MsxModel[source]#

Bases: QualityModelBase

Multi-species water quality model

Parameters:

msx_file_name (str, optional) – MSX file to to load into the MsxModel object, by default None


__init__(msx_file_name=None)[source]#

QualityModel ABC init method.

Make sure you call this method from your concrete subclass __init__ method:

super().__init__(filename=filename)
Parameters:

filename (str, optional) – File to use to populate the initial data

add_constant(name, value, units=None, note=None)[source]#

Add a constant coefficient to the model

Parameters:
  • name (str) – Name of the coefficient

  • value (float) – Constant value of the coefficient

  • units (str, optional) – Units for this coefficient, by default None

  • note (NoteType, optional) – Supplementary information regarding this variable, by default None

Raises:

KeyExistsError – Variable with this name already exists

Returns:

New constant coefficient

Return type:

Constant

add_parameter(name, global_value, units=None, note=None)[source]#

Add a parameterized coefficient to the model

Parameters:
  • name (str) – Name of the parameter

  • global_value (float) – Global value of the coefficient (can be overridden for specific pipes/tanks)

  • units (str, optional) – Units for the coefficient, by default None

  • note (NoteType, optional keyword) – Supplementary information regarding this variable, by default None (see also ENcomment).

Raises:

KeyExistsError – If a variable with this name already exists

Returns:

New parameterized coefficient

Return type:

Parameter

add_reaction(species_name, reaction_type, expression_type, expression, note=None)[source]#

Add a reaction to a species in the model

Note that all species need to have both a pipe and tank reaction defined unless all species are bulk species and the tank reactions are identical to the pipe reactions. However, it is not recommended that users take this approach.

Once added, access the reactions from the species’ object.

Parameters:
  • species_name (Species or str) – Species (or name of species) the reaction is being defined for

  • reaction_type (ReactionType) – Reaction type (location), from {PIPE, TANK}

  • expression_type (ExpressionType) – Expression type (left-hand-side) of the equation, from {RATE, EQUIL, FORMULA}

  • expression (str) – Expression defining the reaction

  • note (NoteType, optional keyword) – Supplementary information regarding this reaction, by default None (see also ENcomment)

Raises:

TypeError – If a variable that is not species is passed

Returns:

New reaction object

Return type:

MsxReactionSystem

add_species(name, species_type, units, atol=None, rtol=None, note=None, diffusivity=None)[source]#

Add a species to the model

Parameters:
  • name (str) – Species name

  • species_type (SpeciesType) – Type of species, either BULK or WALL

  • units (str) – Mass units for this species

  • atol (float, optional unless rtol is not None) – Absolute solver tolerance for this species, by default None

  • rtol (float, optional unless atol is not None) – Relative solver tolerance for this species, by default None

  • note (NoteType, optional keyword) – Supplementary information regarding this variable, by default None (see also ENcomment)

  • diffusivity (float, optional) – Diffusivity of this species in water

Raises:
Returns:

New species

Return type:

Species

add_term(name, expression, note=None)[source]#

Add a named expression (term) to the model

Parameters:
  • name (str) – Name of the functional term to be added

  • expression (str) – Expression that the term defines

  • note (NoteType, optional keyword) – Supplementary information regarding this variable, by default None (see also ENcomment)

Raises:

KeyExistsError – if a variable with this name already exists

Returns:

New term

Return type:

Term

classmethod from_dict(data)[source]#

Create a new multi-species water quality model from a dictionary

Parameters:

data (dict) – Model data

remove_constant(variable_or_name)[source]#

Remove a constant coefficient from the model

Parameters:

variable_or_name (Constant or str) – Constant (or name of the constant) to be removed

Raises:

KeyError – If variable_or_name is not a constant coefficient in the model

remove_parameter(variable_or_name)[source]#

Remove a parameterized coefficient from the model

Parameters:

variable_or_name (Parameter or str) – Parameter (or name of the parameter) to be removed

Raises:

KeyError – If variable_or_name is not a parameter in the model

remove_reaction(species_name, reaction_type)[source]#

Remove a reaction at a specified location from a species

Parameters:
  • species (Species or str) – Species (or name of the species) of the reaction to remove

  • reaction_type (ReactionType) – Reaction type (location) of the reaction to remove

remove_species(variable_or_name)[source]#

Remove a species from the model

Removes from both the reaction_system and the network_data.

Parameters:

variable_or_name (Species or str) – Species (or name of the species) to be removed

Raises:

KeyError – If variable_or_name is not a species in the model

remove_term(variable_or_name)[source]#

Remove a named expression (term) from the model

Parameters:

variable_or_name (Term or str) – Term (or name of the term) to be deleted

Raises:

KeyError – If variable_or_name is not a term in the model

to_dict()[source]#

Dictionary representation of the MsxModel

property constant_name_list: List[str]#

Get a list of coefficient names

description: str#

Longer description; note that multi-line descriptions may not be represented well in dictionary form

name: str#

Name for the model, or the MSX model filename (no spaces allowed)

property network_data: MsxNetworkData#

Network-specific values added to this model

property options: MsxSolverOptions#

MSX model options

property parameter_name_list: List[str]#

Get a list of coefficient names

property reaction_system: MsxReactionSystem#

Reaction variables defined for this model

property references: List[str | Dict[str, str]]#

List of strings or mappings that provide references for this model

Note

This property is a list, and should be modified using append/insert/remove. Members of the list should be json serializable (i.e., strings or dicts of strings).

property species_name_list: List[str]#

Get a list of species names

property term_name_list: List[str]#

Get a list of function (MSX ‘terms’) names

title: str#

Title line from the MSX file, must be a single line