porepy.params.data module

Contains class for storing data / parameters associated with a grid.

At present, the Parameters class is a simple wrapper around a dictionary.

The Parameters will be stored as a dictionary identified by pp.PARAMETERS in an “outer” dictionary (e.g. the data on the subdomains or interfaces). In the Parameters object, there will be one dictionary containing parameters for each keyword. The keywords link parameters to discretization operators. For example, the operator

discr = pp.Tpfa(keyword=”flow”)

will access parameters under the keyword “flow”. If outer_dictionary is the above mentioned outer dictionary, these parameters will be found in

outer_dictionary[pp.PARAMETERS][“flow’],

and the boundary values are extracted from this dictionary as

bc = outer_dictionary[pp.PARAMETERS][“flow’][“bc_values”]

There is a (not entirely clear) distinction between two types of parameters: “Mathematical” parameters are those operated on by the discretization objects, and should be thought of as corresponding to the terms of the mathematical equation. “Physical” parameters are the actual physical properties of the media. As an example, the standard incompressible convection-diffusion equation for temperature

c

ho dT/dt + v cdot abla T - abla cdot (D abla T) = f

has the physical parameters c (specific heat capacity) and ho (density). But from the mathematical point of view, these combine to the parameter “mass_weight”. Similarly, the heat diffusion tensor (“physical” name) corresponds to the “second_order_tensor” (“mathematical” name). If we consider the Darcy equation as another example, the “second_order_tensor” is commonly termed the permeability (“physical”). Since the discretization schemes do not know the physical terminology, the dictionary passed to these has to have the _mathematical_ parameters defined. Solving (systems of) equations with multiple instances of the same mathematical parameter (e.g. both thermal diffusivity and permeability) is handled by the use of multiple keywords (e.g. “transport” and “flow”).

Some default inner dictionaries are provided in pp.params.parameter_dictionaries.

For most instances, a convenient way to set up the parameters is:

specified_parameters = {pm_1: val_1, …, pm_n: val_n} data = pp.initialize_default_data(grid, {}, keyword, specified_parameters)

This will assign val_i to the specified parameters pm_i and default parameters to other required parameters. If the data directory already exists as d (e.g. in the mixed-dimensional grid), consider:

pp.initialize_default_data(grid, d, keyword, specified_parameters)

Also contains a function for setting the state. The state is all data associated with the previous time step or iteration, and is stored in data[pp.STATE]. The solution of a variable is stored in

data[pp.STATE][variable_name],

whereas data such as BC values are stored similarly to in the Parameters class, in

data[pp.STATE][keyword][“bc_values”].

class Parameters(grid=None, keywords=None, dictionaries=None)[source]

Bases: Dict

Class to store all physical parameters used by solvers.

The intention is to provide a unified way of passing around parameters, and also circumvent the issue of using a solver for multiple physical processes (e.g. different types of boundary conditions in multi-physics applications). The keyword assigned to parameters and discretization operators ensures that the right data is used: An operator will always use the parameters stored with under the keyword it has been assigned.

The parameter class is a thin wrapper around a dictionary. This dictionary contains one sub-dictionary for each keyword.

Parameters
  • grid (Optional[Union[pp.Grid, pp.MortarGrid]]) –

  • keywords (Optional[list[str]]) –

  • dictionaries (Optional[list[dict]]) –

expand_scalars(n_vals, keyword, parameters, defaults=None)[source]

Expand parameters assigned as a single scalar to n_vals arrays. Used e.g. for parameters which may be heterogeneous in space (cellwise), but are often homogeneous and assigned as a scalar.

Parameters
  • n_vals (int) – Size of the expanded arrays. E.g. g.num_cells

  • keyword (str) – The parameter keyword.

  • parameters (list[str]) – List of parameters.

  • defaults (list, optional) – List of default values, one for each parameter. If not set, no default values will be provided and an error will ensue if one of the listed parameters is not present in the dictionary. This avoids assigning None to unset mandatory parameters.

Return type

list

modify_parameters(keyword, parameters, values)[source]

Modify the values of some parameters of a given keyword.

Usage: Ensure consistent parameter updates, see set_from_other. Does not work on Numbers.

Parameters
  • keyword (str) – Keyword addressing the physical process.

  • parameters (list[str]) – List of (existing) parameters to be updated.

  • values (list) – List of new values. There are implicit assumptions on the values; in particular that the type and length of the new and old values agree, see modify_variable.

Return type

None

overwrite_shared_parameters(parameters, values)[source]

Updates the given parameter for all keywords.

Brute force method to ensure a parameter is updated/overwritten for all keywords where they are defined.

Parameters
  • parameters (list[str]) – List of (existing) parameters to be overwritten.

  • values (list) – List of new values (bool, scalars, arrays etc.).

Return type

None

set_from_other(keyword_add, keyword_get, parameters)[source]

Add parameters from existing values for a different keyword.

Typical usage: Ensure parameters like aperture and porosity are consistent between keywords, by making reference the same object. Subsequent calls to modify_parameters should update the parameters for both keywords. Note that this will not work for Numbers, which are immutable in Python.

Parameters
  • keyword_add (str) – The keyword to whose dictionary the parameters are to be added.

  • keyword_get (str) – The keyword from whose dictionary the parameters are to be

  • obtained.

  • parameters (list) – List of parameters (accessed via strings) to be set.

Return type

None

update_dictionaries(keywords, dictionaries=None)[source]

Update the dictionaries corresponding to some keywords.

Use either the dictionaries OR the property_ids / values.

Parameters
  • keywords (list) – list of n_phys strings addressing different physical processes.

  • dictionaries (list of dictionaries, optional) – list of n_phys dictionaries with the properties to be updated. If not provided, empty dictionaries are used for all keywords.

Return type

None

Example

keywords = [‘flow’, ‘heat’] ones = np.ones(g.num_cells) dicts = [{‘porosity’: 0.3 * ones, ‘density’: 42 * ones},

{‘heat_capacity’: 1.5 * np.ones}]

param.upate(keywords, dicts)

add_discretization_matrix_keyword(dictionary, keyword)[source]

Ensure presence of sub-dictionaries.

Specific method ensuring that there is a sub-dictionary for discretization matrices, and that this contains a sub-sub-dictionary for the given key. Called previous to discretization matrix storage in discretization operators (e.g. the storage of “flux” by the Tpfa().discretize function).

Parameters
  • dictionary (dict) – Main dictionary, typically stored on a subdomain.

  • keyword (str) – The keyword used for linking parameters and discretization operators.

Returns

Matrix dictionary of discretization matrices.

Return type

dict

add_nonpresent_dictionary(dictionary, key)[source]

Check if key is in the dictionary, if not add it with an empty dictionary.

Parameters
  • dictionary (dict) – Dictionary to be updated.

  • key (str) – Keyword to be added to the dictionary if missing.

Return type

None

initialize_data(grid, data, keyword, specified_parameters=None)[source]

Initialize a data dictionary for a single keyword.

The initialization consists of adding a parameter dictionary and initializing a matrix dictionary in the proper fields of data. If there is a Parameters object in data, the new keyword is added using the update_dictionaries method.

Parameters
  • grid (pp.Grid or pp.MortarGrid) – Grid to which data should be attached.

  • data (dict) – Outer data dictionary, to which the parameters will be added.

  • keyword (str) – String identifying the parameters.

  • specified_parameters (dict, optional) – A dictionary with specified parameters, defaults to empty dictionary.

Returns

The filled dictionary.

Return type

dict

initialize_default_data(grid, data, parameter_type, specified_parameters=None, keyword=None)[source]

Initialize a data dictionary for a single keyword.

The initialization consists of adding a parameter dictionary and initializing a matrix dictionary in the proper fields of data. Default data are added for a certain set of “basic” parameters, depending on the type chosen.

Parameters
  • grid (pp.Grid or pp.MortarGrid) – Grid to which data should be attached.

  • data (dict) – Outer data dictionary, to which the parameters will be added.

  • parameter_type (str) – Which type of parameters to use for the default assignment. Must be one of the following: “flow”, “transport” and “mechanics”.

  • specified_parameters (dict, optional) – A dictionary with specified parameters, overriding the default values. Defaults to an empty dictionary (only default values).

  • keyword – String to identify the parameters. Defaults to the parameter type.

Raises

KeyError if an unknown parameter type is passed.

Return type

dict

modify_variable(variable, new_value)[source]

Changes the value (not id) of the stored parameter.

Mutes the value of a variable to new_value. Note that this method cannot be extended to cover Numbers, as these are immutable in Python. Note that there are implicit assumptions on the arguments, in particular that the new value is of the same type as the variable. Further, if variable is a

list, the lists should have the same length np.ndarray, the arrays should have the same shape, and new_value must be

convertible to variable.dtype

Parameters
  • variable – The variable.

  • new_value – The new value to be assigned to the variable.

Raises
  • TypeError if the variable is a number.

  • NotImplementedError if a variable of unknown type is passed.

Return type

None

set_iterate(data, iterate=None)[source]

Initialize or update an iterate dictionary.

Same as set_state for subfield pp.ITERATE Also checks whether pp.STATE field is set, and adds it if not, see set_state.

Parameters
  • data (dict) – Outer data dictionary, to which the parameters will be added.

  • iterate (dict, Optional) – A dictionary with the state, set to an empty dictionary if not provided.

Returns

The filled dictionary.

Return type

dict

set_state(data, state=None)[source]

Initialize or update a state dictionary.

The initialization consists of adding a state dictionary in the proper field of the data dictionary. If there is a state dictionary in data, the new state is added using the update method of dictionaries.

Parameters
  • data (dict) – Outer data dictionary, to which the parameters will be added.

  • state (dict, Optional) – A dictionary with the state, set to an empty dictionary if not provided.

Returns

The filled dictionary.

Return type

dict