porepy.models.abstract_model module
Contains the mother class for all models, that is, standardized setups for complex problems.
Some methods may raise NotImplementedErrors instead of being abstract methods. This is because they are only needed for some model types (typically nonlinear ones).
Note on running simulations: We provide run_time_dependent_model and run_stationary_model. Both call the Model’s prepare_simulation and after_simulation methods, as well as the solve method of either a LinearSolver or NewtonSolver (the only non-linear solver available for the time being). The Solvers call methods before_newton_loop, check_convergence, after_newton_convergence/after_newton_divergence, (only NewtonSolver:) before_newton_iteration, after_newton_iteration. The name “newton” is there for legacy reasons, a more fitting and general name would be something like “equation_solve”.
- class AbstractModel(params=None)[source]
Bases:
object
This is a class that specifies methods that a model must implement to be compatible with the Newton and time stepping methods.
- Public attributes:
- params (Dict): Simulation specific parameters. Which items are admissible
depends on the model in question.
convergence_status (bool): Whether the non-linear iteration has converged. linear_solver (str): Specification of linear solver. Only known permissible
value is ‘direct’.
dof_manager (pp.DofManager): Degree of freedom manager.
- Parameters
params (Optional[Dict]) –
- after_newton_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.
- after_newton_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
np.array – The new solution state, as computed by the non-linear solver.
solution_vector (ndarray) –
- 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.
The linear system is defined by the current state of the model.
- Return type
None
- linear_system is assigned.
- before_newton_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_newton_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 (
np.array
) – Newly obtained solution vectorprev_solution (
np.array
) – Solution obtained in the previous non-linear iteration.init_solution (
np.array
) – Solution obtained from the previous time-step.nl_params (
dict
) – Dictionary of parameters used for the convergence check. Which items are required will depend on the convergence test to be implemented.
- Returns
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
- Raises: NotImplementedError if the problem is nonlinear and AD is not used.
Convergence criteria are more involved in this case, so we do not risk providing a general method.
- create_grid()[source]
Create the grid bucket.
A unit square grid with no fractures is assigned by default.
- The method assigns the following attributes to self:
mdg (pp.MixedDimensionalGrid): The produced grid bucket. box (dict): The bounding box of the domain, defined through minimum and
maximum values in each dimension.
- Return type
None
- prepare_simulation()[source]
Method called prior to the start of time stepping, or prior to entering the non-linear solver for stationary problems.
The intended use is to define parameters, geometry and grid, discretize linear and time-independent terms, and generally prepare for the simulation.
- Return type
None
- 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
- Returns
Solution vector.
- Return type
np.ndarray