porepy.models.solution_strategy module

Solution strategy classes.

This class is a modified version of relevant parts of AbstractModel. In the future, it may be possible to merge the two classes. For now, we keep them separate, to avoid breaking existing code (legacy models).

class SolutionStrategy(params=None)[source]

Bases: ABC

This is a class that specifies methods that a model must implement to be compatible with the linearization and time stepping methods.

Parameters

params (Optional[dict]) –

after_newton_convergence(solution, errors, iteration_counter)[source]

Wrap for legacy reasons. Call after_nonlinear_convergence() instead.

Parameters
  • solution (ndarray) – The new solution state, as computed by the non-linear solver.

  • errors (float) – The error in the solution, as computed by the non-linear solver.

  • iteration_counter (int) – The number of iterations performed by the non-linear solver.

Return type

None

after_newton_failure(solution, errors, iteration_counter)[source]

Method to be called if the non-linear solver fails to converge.

Parameters
  • solution (ndarray) – The new solution state, as computed by the non-linear solver.

  • errors (float) – The error in the solution, as computed by the non-linear solver.

  • iteration_counter (int) – The number of iterations performed by the non-linear solver.

Return type

None

after_newton_iteration(solution_vector)[source]

Wrap for legacy reasons. Call after_nonlinear_iteration() instead.

Parameters

solution_vector (ndarray) – The new solution state, as computed by the non-linear solver.

after_nonlinear_convergence(solution, errors, iteration_counter)[source]

Method to be called after every non-linear iteration.

Possible usage is to distribute information on the solution, visualization, etc.

Parameters
  • solution (ndarray) – The new solution state, as computed by the non-linear solver.

  • errors (float) – The error in the solution, as computed by the non-linear solver.

  • iteration_counter (int) – The number of iterations performed by the non-linear solver.

Return type

None

after_nonlinear_failure(solution, errors, iteration_counter)[source]

Method to be called if the non-linear solver fails to converge.

Parameters
  • solution (ndarray) – The new solution state, as computed by the non-linear solver.

  • errors (float) – The error in the solution, as computed by the non-linear solver.

  • iteration_counter (int) – The number of iterations performed by the non-linear solver.

Return type

None

after_nonlinear_iteration(solution_vector)[source]

Method to be called after every non-linear iteration.

Possible usage is to distribute information on the new trial state, visualize the current approximation etc.

Parameters

solution_vector (ndarray) – The new solution state, as computed by the non-linear solver.

Return type

None

after_simulation()[source]

Run at the end of simulation. Can be used for cleanup etc.

Return type

None

assemble_linear_system()[source]

Assemble the linearized system and store it in linear_system.

The linear system is defined by the current state of the model.

Return type

None

before_newton_iteration()[source]

Wrap for legacy reasons. Call before_nonlinear_iteration() instead.

Return type

None

before_newton_loop()[source]

Wrap for legacy reasons. Call before_nonlinear_loop() instead.

Return type

None

before_nonlinear_iteration()[source]

Method to be called at the start of every non-linear iteration.

Possible usage is to update non-linear parameters, discretizations etc.

Return type

None

before_nonlinear_loop()[source]

Method to be called before entering the non-linear solver, thus at the start of a new time step.

Possible usage is to update time-dependent parameters, discretizations etc.

Return type

None

check_convergence(solution, prev_solution, init_solution, nl_params)[source]

Implements a convergence check, to be called by a non-linear solver.

Parameters
  • solution (ndarray) – Newly obtained solution vector prev_solution: Solution obtained in

  • init_solution (ndarray) – Solution obtained from the

  • nl_params (dict[str, Any]) – Dictionary of parameters used for the

  • check. (convergence) – Which items are required will depend on the convergence test to be implemented.

  • prev_solution (ndarray) –

  • init_solution

  • nl_params

Returns

float:

Error, computed to the norm in question.

boolean:

True if the solution is converged according to the test implemented by this method.

boolean:

True if the solution is diverged according to the test implemented by this method.

Return type

The method returns the following tuple

discretize()[source]

Discretize all terms.

Return type

None

initial_condition()[source]

Set the initial condition for the problem.

Return type

None

prepare_simulation()[source]

Run at the start of simulation. Used for initialization etc.

Return type

None

set_discretization_parameters()[source]

Set parameters for the discretization.

This method is called before the discretization is performed. It is intended to be used to set parameters for the discretization, such as the permeability, the porosity, etc.

Return type

None

set_equation_system_manager()[source]

Create an equation_system manager on the mixed-dimensional grid.

Return type

None

set_materials()[source]

Set material parameters.

In addition to adjusting the units (see ::method::set_units), materials are defined through ::class::pp.Material and the constants passed when initializing the materials. For most purposes, a user needs only pass the desired parameter values in params[“material_constants”] when initializing a solution strategy, and should not need to modify the material classes. However, if a user wishes to modify to e.g. provide additional material parameters, this can be done by passing modified material classes in params[“fluid”] and params[“solid”].

solve_linear_system()[source]

Solve linear system.

Default method is a direct solver. The linear solver is chosen in the initialize_linear_solver of this model. Implemented options are

  • scipy.sparse.spsolve with and without call to umfpack

  • pypardiso.spsolve

See also

initialize_linear_solver()

Returns

Solution vector.

Return type

np.ndarray

update_time_dependent_ad_arrays(initial)[source]

Update the time dependent arrays for the mechanics boundary conditions.

Parameters

initial (bool) – If True, the array generating method is called for both state and iterate. If False, the array generating method is called only for the iterate, and the state is updated by copying the iterate.

Return type

None

convergence_status: bool

Whether the non-linear iteration has converged.

create_variables: Callable[[], None]

Create variables. Normally provided by a mixin instance of a Variable class relevant to the model.

domain_bounds: dict

Bounding box of the domain. Will normally be set by a mixin instance of ModelGeometry.

equation_system: EquationSystem

Equation system manager. Will be set by set_equation_system_manager().

exporter: Exporter

Exporter for visualization.

finalize_data_saving: Callable[[], None]

Finalize data saving. Normally provided by a mixin instance of DataSavingMixin.

fluid: FluidConstants

Fluid constants. See also set_materials().

initialize_data_saving: Callable[[], None]

Initialize data saving. Normally provided by a mixin instance of DataSavingMixin.

linear_system: tuple[scipy.sparse._base.spmatrix, numpy.ndarray]

The linear system to be solved in each iteration of the non-linear solver. The tuple contains the sparse matrix and the right hand side residual vector.

mdg: MixedDimensionalGrid

Mixed-dimensional grid. Will normally be set by a mixin instance of ModelGeometry.

nd: int

Ambient dimension of the problem. Normally set by a mixin instance of porepy.models.geometry.ModelGeometry.

params

Dictionary of parameters.

save_data_time_step: Callable[[], None]

Save data at a time step. Normally provided by a mixin instance of DataSavingMixin.

set_equations: Callable[[], None]

Set the governing equations of the model. Normally provided by the solution strategy of a specific model (i.e. a subclass of this class).

set_geometry: Callable[[], None]

Set the geometry of the model. Normally provided by a mixin instance of ModelGeometry.

solid: SolidConstants

Solid constants. See also set_materials().

time_manager

Time manager for the simulation.

units: Units

Units of the model. See also set_units().