pg_utils.pg_model.expansion.SystemEquations

class pg_utils.pg_model.expansion.SystemEquations(names: List[str], expansion_recipe: ExpansionRecipe, **fields)[source]

Bases: LabeledCollection

The top-level class for system of equations to be solved The equations are always assumed to be written in the first-order form in time, i.e. LHS = d()/dt

Variables:

expansion_recipe (ExpansionRecipe) – expansion recipe used for the eq

__init__(names: List[str], expansion_recipe: ExpansionRecipe, **fields) None[source]

Initialization

Methods

__init__(names, expansion_recipe, **fields)

Initialization

apply(fun[, inplace, metadata])

Apply a function iteratively to all collection items

as_empty()

Overriding base.LabeledCollection.as_empty

collect_matrices([factor_lhs, factor_rhs])

Collect the coefficient matrices of the equations

copy()

Overriding base.LabeledCollection.copy

deserialize(obj[, parser])

Deserialize an object

generate_collection(index_array)

Generate a new collection based on indices

load_json(fp[, parser])

Load LabeledCollection object from json

save_json(fp[, serializer])

Serialize the object in string format and save to json file

serialize([serializer])

Serialize the object

subs(sub_map[, inplace])

Substitute variables iteratively in all fields.

to_fourier_domain([inplace])

Convert expression into Fourier domain

to_inner_product([factor_lhs, factor_rhs, ...])

Collect the radial equations to inner product form

to_radial([inplace])

Introduce radial expansion to the equations.

Attributes

iter_filter

iter_filter: bool determines whether None fields are skipped.

iter_name

iter_name: bool determines whether the string of the field is also returned.

apply(fun: Callable[[...], Any], inplace: bool = False, metadata: bool = False) LabeledCollection[source]

Apply a function iteratively to all collection items

Parameters:
  • fun (Callable) – determines how the collection entries are processed. The signature of the function should take the form fun(type(self[i])) when metadata is False, and the form fun(str, type(self[i])) when metadata is True

  • inplace (bool) – whether to write changes in situ.

  • metadata (bool) – whether to pass field name to the function

Returns:

Updated object. If inplace, then the current object itself is returned.

Return type:

LabeledCollection

as_empty()[source]

Overriding base.LabeledCollection.as_empty

collect_matrices(factor_lhs: Expr = 1, factor_rhs: Expr = 1) List[SystemMatrix][source]

Collect the coefficient matrices of the equations

Parameters:
  • factor_lhs (sympy.Expr) – sympy.Expr, allows the user to choose which factor should be moved out of the inner product on LHS

  • factor_rhs – ditto, but for RHS

copy()[source]

Overriding base.LabeledCollection.copy

static deserialize(obj: ~typing.List[tuple], parser: ~typing.Callable[[str], ~typing.Any] = <function LabeledCollection.<lambda>>) LabeledCollection[source]

Deserialize an object

Parameters:
  • obj (List[tuple]) – a serialized object of LabeledCollection

  • parser (Callable[[str], Any]) – a parser that defines how each string can be parsed into meaningful objects

Returns:

LabeledCollection, that is deserialized from the input object

Warning

Sanitized input needed. Unexpected behaviour if input is not a legitimate serialized object

generate_collection(index_array: List[bool]) LabeledCollection[source]

Generate a new collection based on indices

Parameters:

index_array (List[bool]) – array of booleans indicating whether a field is to be included in the new collection

Returns:

new collection with elements specified by index_array

property iter_filter[source]

iter_filter: bool determines whether None fields are skipped.

property iter_name[source]

iter_name: bool determines whether the string of the field is also returned.

static load_json(fp: ~typing.TextIO, parser: ~typing.Callable[[str], ~typing.Any] = <function LabeledCollection.<lambda>>) LabeledCollection[source]

Load LabeledCollection object from json

convenient wrapper for deserialize

save_json(fp: ~typing.TextIO, serializer: ~typing.Callable[[~typing.Any], str] = <class 'str'>) None[source]

Serialize the object in string format and save to json file

Parameters:
  • fp (TextIO) – file handle of the output file

  • serializer (Callable[[Any], str]) – a callable that maps an element to a string. Default is the str method.

serialize(serializer: ~typing.Callable[[~typing.Any], str] = <class 'str'>) List[tuple][source]

Serialize the object

Parameters:

serializer (Callable[[Any],str]) – a callable that maps an element to a string. Default is the str method.

Returns:

a list of serialized objects, in the format [(fname_1, serialized_element_1), (fname_2, serialized_element_2), …]

subs(sub_map: dict, inplace: bool = False)[source]

Substitute variables iteratively in all fields. This utility is for collections with sympy.Expr elements. See warning below.

Parameters:
  • sub_map (dict) – a substitution map

  • inplace (bool) – whether the change is made in place; default is False

Warning

To use this method, all elements in the collection need to have implemented the subs method. This is intended for a collection of which all elements are sympy.Expr type. Then, this method calls apply internally to substitute all the variables.

to_fourier_domain(inplace: bool = False) SystemEquations[source]

Convert expression into Fourier domain

Uses the bases and coefficients defined in recipe.fourier_ansatz

Parameters:

inplace (bool) – whether the operation is made in situ

to_inner_product(factor_lhs: Expr = 1, factor_rhs: Expr = 1, inplace: bool = False) SystemEquations[source]

Collect the radial equations to inner product form

Parameters:
  • factor_lhs (sympy.Expr) – allows the user to choose which factor should be moved out of the inner product on LHS

  • factor_rhs – ditto, but for RHS

  • inplace (bool) – whether the operation is made in situ

Warning

Functions/fields that are not expanded with an coefficient (elements from recipe.rad_xpd.coeffs) will no longer be collected properly and may be lost in linear system formation!

to_radial(inplace: bool = False) SystemEquations[source]

Introduce radial expansion to the equations.

Parameters:

inplace (bool) – whether the operation is made in situ