porepy.numerics.mixed_dim.assembler module

The module contains the Assembler class, which is responsible for assembly of system matrix and right hand side for a general multi-domain, multi-physics problem.

class Assembler(mdg, dof_manager=None)[source]

Bases: object

A class that assembles multi-physics problems on mixed-dimensional domains.

The class is designed to combine different variables on different grids, different discretizations for the same variable, various coupling schemes between the grids etc. To use the functionality, discretization schemes for the individual terms in the equation must be defined and follow certain rules. For further description, see the documentation of self.assemble_matrix_rhs().

Parameters
assemble_matrix_rhs(filt=None, matrix_format='csr', add_matrices=True, only_matrix=False, only_rhs=False)[source]

Assemble the system matrix and right hand side for a general linear multi-physics problem, and return a block matrix and right hand side.

For examples on how to use the assembler, confer the tutorial parameter_assignment_assembler_setup.ipynb. Here, we list the main capabilities of the assembler:

  • Assign an arbitrary number of variables on each subdomain and interface in the mixed-dimensional. Allow for general couplings between the variables internal to each subdomain / interface.

  • Assign general coupling schemes between interfaces and one or both neighboring subdomains. There are no limitations on variable naming conventions in the coupling.

  • Construct a system matrix that only consideres a subset of the variables

    defined in the MixedDimensionalGrid data dictionary.

  • Return either a single discretization matrix covering all variables and terms, or one matrix per term per variable. The latter is useful e.g. in operator splitting or time stepping schemes.

The latter two effects can be achieved by applying a filter to the assembly operation, see for instance pp.assembler_filters.ListFilter.

In all cases, it is assumed that a discretization object for the relevant terms is available. It is up to the user to ensure that the resulting problem is well posed.

Parameters
  • filt (pp.assembler_filters.AssemblerFilter, optional) – Filter to invoke selected discretizations. Defaults to a PassAllFilter, which will lead to discretization of all terms in the entire MixedDimensionalGrid.

  • matrix_format (str, optional) – Matrix format used for the system matrix. Defaults to CSR.

  • add_matrices (boolean, optional) – If True, a single system matrix is added, else, separate matrices for each variable and term are returned in a dictionary.

  • only_matrix (boolean, optional) – Note that some discretization methods will still invoke its full assemble_matrix_rhs method. This method will still return a (zero) rhs vector.

  • only_rhs (boolean, optional) – Note that some discretization methods will still invoke its full assemble_matrix_rhs method. This method will still return a (zero) discretization matrix.

Returns

Discretization matrix,

dictionary is returned if add_matrices=False.

np.ndarray, or dictionary of arrays: Right hand side terms. Dictionary is

returned if add_matrices=False.

Return type

scipy sparse matrix, or dictionary of matrices

assemble_operator(keyword, operator_name)[source]

Assemble a global agebraic operator from the local algebraic operators on the subdomains or interfaces of a mixed-dimensional grid. The global operator is a block diagonal matrix with the local operators on the diagonal.

Parameters
  • keyword (string) – Keyword for the dictionary in d[pp.DISCRETIZATION_MATRICES] for which the operator is stored.

  • operator_name (string) – keyword for the operator in the d[pp.DISCRETIZATION_MATRICES][keyword] dictionary.

Returns

Global algebraic operator.

Return type

Operator (sps.block_diag)

assemble_parameter(keyword, parameter_name)[source]

Assemble a global parameter from the local parameters defined on the subdomains or interfaces of a mixed-dimensional grid. The global parameter is a nd-vector of the stacked local parameters.

Parameters
  • keyword (string) – Keyword to access the dictionary d[pp.PARAMETERS][keyword] for which the parameters are stored.

  • parameter_name (string) – keyword of the parameter. Will access d[pp.DISCRETIZATION_MATRICES][keyword][parameter].

Returns

Global parameter.

Return type

Operator (np.ndarray)

discretize(filt=None)[source]

Run the discretization operation on discretizations specified in the mixed-dimensional grid.

Discretization can be applied selectively to specific discretization objects in the MixedDimensionalGrid by passing an appropriate filter. See pp.assembler_filters for details, in particular the class ListFilter.

Parameters

filt (pp.assembler_filters.AssemblerFilter, optional) – Filter to invoke selected discretizations. Defaults to a PassAllFilter, which will lead to discretization of all terms in the entire MixedDimensionalGrid.

Return type

None

distribute_variable(values, variable_names=None)[source]

Distribute a vector to the subdomains and interfaces in the MixedDimensionalGrid.

The intended use is to split a multi-physics solution vector into its component parts.

Parameters
  • values (np.array) – Vector to be split. It is assumed that it corresponds to the ordering implied in block_dof and full_dof, e.g. that it is the solution of a linear system assembled with the assembler.

  • variable_names (list of str, optional) – Names of the variable to be distributed. If not provided, all variables found in block_dof will be distributed

Return type

None

num_dof()[source]

Get total number of unknowns of the identified variables.

Returns

Number of unknowns. Size of solution vector.

Return type

np.int_

update_discretization(filt=None)[source]

Update discretizations without a full rediscretization.

The method will invoke the update_discretization() method on discretizations on all grids which have the parameter partial_update set to True in its data dictionary. If a Filter is given to this function, the partial update will be used as an additional filter.

Parameters

filt (pp.assembler_filters.AssemblerFilter, optional) – Filter.

Return type

None

update_dof_count()[source]

Update the count of degrees of freedom related to a MixedDimensionalGrid.

The method loops through the defined combinations of grids (standard or mortar) and variables, and updates the number of fine-scale degree of freedom for this combination. The system size will be updated if the grid has changed or (perhaps less realistically) a variable has had its number of dofs per grid quantity changed.

The method will not identify any new variables, for this, the preferred approach is to define a new assembler object.

Return type

None

variables_of_grid(g)[source]

Get all variables defined for a given subdomain or interface.

Parameters

g (Union[pp.Grid, Tuple[pp.Grid, pp.Grid]]) – Target subdomain, or an interface.

Returns

List of all variables known for this entity.

Return type

List[str]

class CouplingVariableTerm(coupling, interface, primary, secondary, term)

Bases: tuple

coupling

Alias for field number 0

interface

Alias for field number 1

primary

Alias for field number 2

secondary

Alias for field number 3

term

Alias for field number 4

class GridVariableTerm(grid, row, col, term)

Bases: tuple

GridVariableTerm(grid, row, col, term)Combinations of grids variables and terms found in MixedDimensionalGrid

col

Variable name of the column for this term. Differs from row for variable couplings.

grid

Item in MixedDimensionalGrid. Can be subdomain or interface.

row

Variable name of the row for this term.

term

Term for this discretization