Formatters module

This module contains all the languages formatters used to convert symbolic expressions into computing language expressions.

Base classes for formatting symbolic equations output

Defines base classes to format tendencies and Jacobian symbolic equations output.

Description of the classes

class layercake.formatters.base.EquationFormatter(lang_translation=None)[source]

Bases: ABC

Base class for symbolic equations formatting.

Parameters:

lang_translation (dict(str)) – Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the target language.

lang_translation

Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the target language.

Type:

dict(str)

index_offset

Number that accesses the first element in an array. Defaults to 0.

Type:

int

__call__(tensor, variable='U', tendencies='F')[source]

Convert a model symbolic tendencies terms tensor to a list of symbolic equations in string format.

Parameters:
  • tensor (ImmutableSparseNDimArray) – Symbolic tendencies terms tensor to convert.

  • variable (str) – Name of the state variable to use for the output equations strings. Default to ‘U’.

  • tendencies (str) – Name of the tendencies variable to use for the output equations strings. Default to ‘F.

abstract property closing_character

Character closing the arrays specification index in the target language. Must be defined in the subclasses.

Type:

str

abstract property opening_character

Character opening the arrays specification index in the target language. Must be defined in the subclasses.

Type:

str

class layercake.formatters.base.JacobianEquationFormatter(lang_translation=None)[source]

Bases: EquationFormatter

Base class for symbolic Jacobian equations formatting.

Parameters:

lang_translation (dict(str)) – Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the target language.

lang_translation

Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the target language.

Type:

dict(str)

index_offset

Number that accesses the first element in an array. Defaults to 0.

Type:

int

__call__(tensor, variable='U', tendencies='J')[source]

Convert a model Jacobian symbolic tendencies terms tensor to a list of symbolic equations in string format.

Parameters:
  • tensor (ImmutableSparseNDimArray) – Jacobian symbolic tendencies terms tensor to convert.

  • variable (str) – Name of the state variable to use for the output equations strings. Default to ‘U’.

  • tendencies (str) – Name of the tendencies variable to use for the output equations strings. Default to ‘F.

Classes for formatting symbolic equations output in Fortran

Defines classes to format tendencies and Jacobian symbolic equations output in Fortran.

Description of the classes

class layercake.formatters.fortran.FortranEquationFormatter(lang_translation=None)[source]

Bases: EquationFormatter

Class for symbolic equations formatting in Fortran.

Parameters:

lang_translation (dict(str)) – Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Fortran language.

lang_translation

Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Fortran language.

Type:

dict(str)

index_offset

Number that accesses the first element in an array. In Fortran the base index is 1.

Type:

int

property closing_character

Character closing the arrays specification index in the Fortran language.

Type:

str

property opening_character

Character opening the arrays specification index in the Fortran language.

Type:

str

class layercake.formatters.fortran.FortranJacobianEquationFormatter(lang_translation=None)[source]

Bases: JacobianEquationFormatter

Class for symbolic Jacobian equations formatting in Fortran.

Parameters:

lang_translation (dict(str)) – Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Fortran language.

lang_translation

Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Fortran language.

Type:

dict(str)

index_offset

Number that accesses the first element in an array. In Fortran the base index is 1.

Type:

int

property closing_character

Character closing the arrays specification index in the Fortran language.

Type:

str

property opening_character

Character opening the arrays specification index in the Fortran language.

Type:

str

Classes for formatting symbolic equations output in Python

Defines classes to format tendencies and Jacobian symbolic equations output in Python.

Description of the classes

class layercake.formatters.python.PythonEquationFormatter(lang_translation=None)[source]

Bases: EquationFormatter

Class for symbolic equations formatting in Python.

Parameters:

lang_translation (dict(str)) – Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Python language.

lang_translation

Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Python language.

Type:

dict(str)

index_offset

Number that accesses the first element in an array. In Python the index base is 0.

Type:

int

property closing_character

Character closing the arrays specification index in the Python language.

Type:

str

property opening_character

Character opening the arrays specification index in the Python language.

Type:

str

class layercake.formatters.python.PythonJacobianEquationFormatter(lang_translation=None)[source]

Bases: JacobianEquationFormatter

Class for symbolic Jacobian equations formatting in Python.

Parameters:

lang_translation (dict(str)) – Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Python language.

lang_translation

Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Python language.

Type:

dict(str)

index_offset

Number that accesses the first element in an array. In Python the index base is 0.

Type:

int

property closing_character

Character closing the arrays specification index in the Python language.

Type:

str

property opening_character

Character opening the arrays specification index in the Python language.

Type:

str

Classes for formatting symbolic equations output in Julia

Defines classes to format tendencies and Jacobian symbolic equations output in Julia.

Description of the classes

class layercake.formatters.julia.JuliaEquationFormatter(lang_translation=None)[source]

Bases: EquationFormatter

Class for symbolic equations formatting in Julia.

Parameters:

lang_translation (dict(str)) – Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Julia language.

lang_translation

Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Julia language.

Type:

dict(str)

index_offset

Number that accesses the first element in an array. In Julia the index base is 1.

Type:

int

property closing_character

Character closing the arrays specification index in the Julia language.

Type:

str

property opening_character

Character opening the arrays specification index in the Julia language.

Type:

str

class layercake.formatters.julia.JuliaJacobianEquationFormatter(lang_translation=None)[source]

Bases: JacobianEquationFormatter

Class for symbolic Jacobian equations formatting in Julia.

Parameters:

lang_translation (dict(str)) – Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Julia language.

lang_translation

Language translation mapping dictionary, mapping replacements for converting Sympy symbolic output strings to the Julia language.

Type:

dict(str)

index_offset

Number that accesses the first element in an array. In Julia the index base is 1.

Type:

int

property closing_character

Character closing the arrays specification index in the Julia language.

Type:

str

property opening_character

Character opening the arrays specification index in the Julia language.

Type:

str