proteus.LinearSolvers module
A hierarchy of classes for linear algebraic system solvers.
- class proteus.LinearSolvers.LinearSolver(L, rtol_r=0.0001, atol_r=1e-16, rtol_du=0.0001, atol_du=1e-16, maxIts=100, norm=<function l2Norm>, convergenceTest='r', computeRates=True, printInfo=False)[source]
Bases:
object
The base class for linear solvers.
- L
proteus.superluWrappers.SparseMatrix
This is the system matrix.
- L
- class proteus.LinearSolvers.LU(L, computeEigenvalues=False, computeEigenvectors=None)[source]
Bases:
proteus.LinearSolvers.LinearSolver
A wrapper for pysparse’s wrapper for superlu.
- class proteus.LinearSolvers.KSP_petsc4py(L, par_L, rtol_r=0.0001, atol_r=1e-16, maxIts=100, norm=<function l2Norm>, convergenceTest='r', computeRates=True, printInfo=False, prefix=None, Preconditioner=None, connectionList=None, linearSolverLocalBlockSize=1, preconditionerOptions=None)[source]
Bases:
proteus.LinearSolvers.LinearSolver
A class that interfaces Proteus with PETSc KSP.
Initialize a petsc4py KSP object.
- Parameters
- class proteus.LinearSolvers.SchurOperatorConstructor(linear_smoother, pde_type='general_saddle_point')[source]
Bases:
object
Generate matrices for use in Schur complement preconditioner operators.
Initialize a Schur Operator constructor.
- Parameters
linear_smoother (class) – Provides the data about the problem.
pde_type (str) – Currently supports Stokes and navierStokes
- initializeTwoPhaseCp_rho()[source]
Initialize a two phase scaled advection operator Cp.
- Returns
two_phase_Cp_rho
- Return type
matrix
- initializeTwoPhaseInvScaledAp()[source]
Initialize a two phase scaled laplace operator Ap.
- Returns
two_phase_Ap_inv
- Return type
matrix
- initializeTwoPhaseQp_rho()[source]
Initialize a two phase scaled mass matrix.
- Returns
two_phase_Ap_inv
- Return type
matrix
- initializeTwoPhaseInvScaledQp()[source]
Initialize a two phase scaled mass operator Qp.
- Returns
two_phase_Ap_inv
- Return type
matrix
- updateQ(output_matrix=False)[source]
Update the mass matrix operator.
- Parameters
output_matrix (bool) – Save updated mass operator.
- updateNp_rho(density_scaling=True, output_matrix=False)[source]
Update the two-phase advection operator.
- updateInvScaledAp(output_matrix=False)[source]
Update the two-phase laplace operator.
- Parameters
output_matrix (bool) – Save updated laplace operator.
- updateTwoPhaseQp_rho(density_scaling=True, lumped=True, output_matrix=False)[source]
Update the two-phase inverse viscosity scaled mass matrix.
- Parameters
- updateTwoPhaseInvScaledQp_visc(numerical_viscosity=True, lumped=True, output_matrix=False)[source]
Update the two-phase inverse viscosity scaled mass matrix.
- Parameters
numerical_viscosity (bool) – Indicates whether the numerical viscosity should be included with the mass operator (True to include, False to exclude)
lumped (bool) – Flag indicating whether the mass operator should be calculated as a lumped matrix (True) or as a full matrix (False).
output_matrix (bool) – Save updated mass operator.
- class proteus.LinearSolvers.KSP_Preconditioner[source]
Bases:
object
Base class for PETSc KSP precondtioners.
- class proteus.LinearSolvers.petsc_ASM(L, prefix=None)[source]
Bases:
proteus.LinearSolvers.KSP_Preconditioner
ASM PETSc preconditioner class.
This class provides an ASM preconditioners for PETSc4py KSP objects.
Initializes the ASMpreconditioner for use with PETSc.
- Parameters
L (the global system matrix.) –
prefix (str) – Prefix handle for PETSc options.
- class proteus.LinearSolvers.petsc_LU(L, prefix=None)[source]
Bases:
proteus.LinearSolvers.KSP_Preconditioner
LU PETSc preconditioner class.
This class provides an LU preconditioner for PETSc4py KSP objects. Provided the LU decomposition is successful, the KSP iterative will converge in a single step.
Initializes the LU preconditioner for use with PETSc.
- Parameters
L (the global system matrix.) –
prefix (str) – Prefix handle for PETSc options.
- class proteus.LinearSolvers.DofOrderInfo(dof_order_type, model_info='no model info set')[source]
Bases:
object
Base class for managing DOF ordering information
Parameters dof_order_type : str
This describes the type of dof ordering that will be constructed. Currently supports: ‘blocked’ and ‘interlaced’.
- class proteus.LinearSolvers.BlockedDofOrderType(n_DOF_pressure, model_info='no model info set')[source]
Bases:
proteus.LinearSolvers.DofOrderInfo
Manages the DOF for blocked velocity and pressure ordering.
- Parameters
n_DOF_pressure (int) – Number of pressure degrees of freedom.
Notes
Blocked degree of freedom ordering occurs when all the pressure unknowns appear first, followed by all the u-components of the velocity and then all the v-components of the velocity etc.
- class proteus.LinearSolvers.InterlacedDofOrderType(model_info='no model info set')[source]
Bases:
proteus.LinearSolvers.DofOrderInfo
Manages the DOF for interlaced velocity and pressure ordering.
Notes
Interlaced degrees of occur when the degrees of freedom are ordered as (p[0], u[0], v[0], p[1], u[1], …, p[n], u[n], v[n]).
- create_DOF_lists(ownership_range, num_equations, num_components)[source]
Build interlaced velocity and pressure DOF arrays.
- Parameters
- Returns
DOF_output – This function returns a list of arrays with the DOF order. [velocityDOF, pressureDOF]
- Return type
lst of arrays
- create_vel_DOF_IS(ownership_range, num_equations, num_components)[source]
Build interlaced DOF arrays for the components of the velocity.
- Parameters
- Returns
DOF_output – Each element of this list corresponds to a component of the velocity. E.g. for u, v, w : [vel_u,vel_v,vel_w].
- Return type
lst of arrays
- create_no_dirichlet_bdy_nodes_is(ownership_range, num_equations, num_components, bdy_nodes)[source]
Build block velocity DOF arrays excluding Dirichlet bdy nodes.
- Parameters
bdy_nodes (lst) – This is a list of lists with the local dof index for strongly enforced Dirichlet boundary conditions on the velocity components.
- class proteus.LinearSolvers.ModelInfo(dof_order_type, num_components, L_range=None, neqns=None, n_DOF_pressure=None, bdy_null_space=False)[source]
Bases:
object
This class stores the model information needed to initialize a Schur preconditioner class.
- Parameters
num_components (int) – The number of model components
dof_order_type (str) – String variable with the dof_order_type (‘blocked’ or ‘interlaced’)
n_DOF_pressure (int) – Number of pressure degrees of freedom (required for blocked dof_order_type)
bdy_null_space (bool) – Indicates whether boundary condition creates a global null space
- class proteus.LinearSolvers.SchurPrecon(L, prefix=None, solver_info=None)[source]
Bases:
proteus.LinearSolvers.KSP_Preconditioner
Base class for PETSc Schur complement preconditioners.
Initializes the Schur complement preconditioner for use with PETSc.
This class creates a KSP PETSc solver object and initializes flags the pressure and velocity unknowns for a general saddle point problem.
- Parameters
- class proteus.LinearSolvers.Schur_Sp(L, prefix, velocity_block_preconditioner=False, solver_info=None)[source]
Bases:
proteus.LinearSolvers.NavierStokesSchur
Implements the SIMPLE Schur complement approximation proposed in 2009 by Rehman, Vuik and Segal.
- Parameters
L (
p4pyPETSc.Mat
) –prefix (str) – Specifies PETSc preconditioner prefix for setting options
Notes
This Schur complement approximation is also avaliable in PETSc by the name selfp.
One drawback of this operator is that it must be constructed from the component pieces. For small problems this is okay, but for large problems this process may not scale well and often a pure Laplace operator will prove a more effective choice of preconditioner.
Initializes the Schur complement preconditioner for use with PETSc.
This class creates a KSP PETSc solver object and initializes flags the pressure and velocity unknowns for a general saddle point problem.
- Parameters
- class proteus.LinearSolvers.Schur_Qp(L, prefix=None)[source]
Bases:
proteus.LinearSolvers.SchurPrecon
A Navier-Stokes (or Stokes) preconditioner which uses the viscosity scaled pressure mass matrix.
Initializes the pressure mass matrix class.
- Parameters
L (petsc4py matrix) – Defines the problem’s operator.
prefix (str) – Specifies PETSc preconditioner prefix for setting options
Bases:
proteus.LinearSolvers.SchurPrecon
Schur complement preconditioners for Navier-Stokes problems.
This class is derived from SchurPrecond and serves as the base class for all NavierStokes preconditioners which use the Schur complement method.
Initializes a base class for Navier-Stokes Schur complement preconditioners.
- Parameters
L (petsc4py matrix) – Defines the problem’s operator
prefix (str) – Specifies PETSc preconditioner prefix for setting options
velocity_block_preconditioner (Bool) – Indicates whether the velocity block should be solved as a block preconditioner
Bases:
proteus.LinearSolvers.NavierStokesSchur
Two-phase PCD Schur complement approximation class. Details of this operator are in the forthcoming paper ‘Preconditioners for Two-Phase Incompressible Navier-Stokes Flow’, Bootland et. al. 2017.
Since the two-phase Navier-Stokes problem used in the MPRANS module of Proteus has some additional features not include in the above paper, a few additional flags and options are avaliable.
density scaling - This flag allows the user to specify whether the advection and mass terms in the second term of the PCD operator should use the actual density or the scale with the number one.
numerical viscosity - This flag specifies whether the additional viscosity introduced from shock capturing stabilization should be included as part of the viscosity coefficient.
mass form - This flag allows the user to specify what form the mass matrix takes, lumped (True) or full (False).
number chebyshev its - This integer allows the user to specify how many Chebyshev its to use if a full mass matrix is used and a direct solver is not applied.
Initialize the two-phase PCD preconditioning class.
- Parameters
L (petsc4py Matrix) – Defines the problem’s operator.
prefix (str) – String allowing PETSc4py options.
density_scaling (bool) – Indicates whether mass and advection terms should be scaled with the density (True) or 1 (False).
numerical_viscosity (bool) – Indicates whether the viscosity used to calculate the inverse scaled mass matrix should include numerical viscosity (True) or not (False).
lumped (bool) – Indicates whether the viscosity and density mass matrices should be lumped (True) or full (False).
num_chebyshev_its (int) – This flag allows the user to apply the mass matrices with a chebyshev semi-iteration. 0 indicates the semi- iteration should not be used, where as a number 1,2,… indicates the number of iterations the method should take.
laplace_null_space (bool) – Indicates whether the laplace operator inside the two-phase PCD operator has a constant null space.
velocity_block_preconditioner (bool) – Indicates whether to use a block preconditioner for the velocity solve.
Set up the NavierStokesSchur preconditioner.
Nothing needs to be done here for a generic NSE preconditioner. Preconditioner arguments can be set with PETSc command line.
- class proteus.LinearSolvers.Schur_LSC(L, prefix=None)[source]
Bases:
proteus.LinearSolvers.SchurPrecon
The Least-Squares Communtator preconditioner for saddle point problems.
Initializes the pressure mass matrix class.
- Parameters
L (petsc4py matrix) – Defines the problem’s operator.
prefix (str) – Specifies PETSc preconditioner prefix for setting options
Bases:
proteus.LinearSolvers.NavierStokesSchur
Initializes a base class for Navier-Stokes Schur complement preconditioners.
- Parameters
L (petsc4py matrix) – Defines the problem’s operator
prefix (str) – Specifies PETSc preconditioner prefix for setting options
velocity_block_preconditioner (Bool) – Indicates whether the velocity block should be solved as a block preconditioner
Set up the NavierStokesSchur preconditioner.
Nothing needs to be done here for a generic NSE preconditioner. Preconditioner arguments can be set with PETSc command line.
alias of
proteus.LinearSolvers.NavierStokes3D
Bases:
proteus.LinearSolvers.NavierStokesSchur
Initializes a base class for Navier-Stokes Schur complement preconditioners.
- Parameters
L (petsc4py matrix) – Defines the problem’s operator
prefix (str) – Specifies PETSc preconditioner prefix for setting options
velocity_block_preconditioner (Bool) – Indicates whether the velocity block should be solved as a block preconditioner
Set up the NavierStokesSchur preconditioner.
Nothing needs to be done here for a generic NSE preconditioner. Preconditioner arguments can be set with PETSc command line.
alias of
proteus.LinearSolvers.NavierStokes2D
Bases:
object
- class proteus.LinearSolvers.Jacobi(L, weight=1.0, rtol_r=0.0001, atol_r=1e-16, rtol_du=0.0001, atol_du=1e-16, maxIts=100, norm=<function l2Norm>, convergenceTest='r', computeRates=True, printInfo=True)[source]
Bases:
proteus.LinearSolvers.LinearSolver
Damped Jacobi iteration.
- class proteus.LinearSolvers.GaussSeidel(connectionList, L, weight=0.33, sym=False, rtol_r=0.0001, atol_r=1e-16, rtol_du=0.0001, atol_du=1e-16, maxIts=100, norm=<function l2Norm>, convergenceTest='r', computeRates=True, printInfo=True)[source]
Bases:
proteus.LinearSolvers.LinearSolver
Damped Gauss-Seidel.
- class proteus.LinearSolvers.StarILU(connectionList, L, weight=1.0, sym=False, rtol_r=0.0001, atol_r=1e-16, rtol_du=0.0001, atol_du=1e-16, maxIts=100, norm=<function l2Norm>, convergenceTest='r', computeRates=True, printInfo=True)[source]
Bases:
proteus.LinearSolvers.LinearSolver
Alternating Schwarz Method on node stars.
- class proteus.LinearSolvers.StarBILU(connectionList, L, bs=1, weight=1.0, sym=False, rtol_r=0.0001, atol_r=1e-16, rtol_du=0.0001, atol_du=1e-16, maxIts=100, norm=<function l2Norm>, convergenceTest='r', computeRates=True, printInfo=True)[source]
Bases:
proteus.LinearSolvers.LinearSolver
Alternating Schwarz Method on ‘blocks’ consisting of consectutive rows in system for things like dg …
- class proteus.LinearSolvers.TwoLevel(prolong, restrict, coarseL, preSmoother, postSmoother, coarseSolver, L, prepareCoarse=False, rtol_r=0.0001, atol_r=1e-16, rtol_du=0.0001, atol_du=1e-16, maxIts=100, norm=<function l2Norm>, convergenceTest='r', computeRates=True, printInfo=True)[source]
Bases:
proteus.LinearSolvers.LinearSolver
A generic two-level multiplicative Schwarz solver.
- class proteus.LinearSolvers.MultilevelLinearSolver(levelLinearSolverList, computeRates=False, printInfo=False)[source]
Bases:
object
A generic multilevel solver.
- class proteus.LinearSolvers.MGM(prolongList, restrictList, LList, preSmootherList, postSmootherList, coarseSolver, mgItsList=[], printInfo=False, computeRates=False)[source]
Bases:
proteus.LinearSolvers.MultilevelLinearSolver
A generic multigrid W cycle.
- class proteus.LinearSolvers.NI(solverList, prolongList, restrictList, maxIts=None, tolList=None, atol=None, computeRates=True, printInfo=False)[source]
Bases:
proteus.LinearSolvers.MultilevelLinearSolver
A generic nested iteration solver.
- proteus.LinearSolvers.multilevelLinearSolverChooser(linearOperatorList, par_linearOperatorList, multilevelLinearSolverType=<class 'proteus.LinearSolvers.NI'>, relativeToleranceList=None, absoluteTolerance=1e-08, solverConvergenceTest='r', solverMaxIts=500, printSolverInfo=False, computeSolverRates=False, levelLinearSolverType=<class 'proteus.LinearSolvers.MGM'>, printLevelSolverInfo=False, computeLevelSolverRates=False, smootherType=<class 'proteus.LinearSolvers.Jacobi'>, prolongList=None, restrictList=None, connectivityListList=None, cycles=3, preSmooths=3, postSmooths=3, printSmootherInfo=False, computeSmootherRates=False, smootherConvergenceTest='its', relaxationFactor=None, computeEigenvalues=False, parallelUsesFullOverlap=True, par_duList=None, solver_options_prefix=None, linearSolverLocalBlockSize=1, linearSmootherOptions=())[source]
- class proteus.LinearSolvers.StorageSet(initializer=[], shape=(0,), storageType='d')[source]
Bases:
set
- class proteus.LinearSolvers.OperatorConstructor(model)[source]
Bases:
object
Base class for operator constructors.
- class proteus.LinearSolvers.OperatorConstructor_rans2p(levelModel)[source]
Bases:
proteus.LinearSolvers.OperatorConstructor
A class for building common discrete rans2p operators.
- LevelModel
proteus.mprans.RANS2P.LevelModel
Level transport model derived from the rans2p class.
- updateTPAdvectionOperator(density_scaling)[source]
Update the discrete two-phase advection operator matrix.
- Parameters
density_scaling (bool) – Indicates whether advection terms should be scaled with the density (True) or 1 (False)
- LevelModel
- class proteus.LinearSolvers.OperatorConstructor_oneLevel(OLT)[source]
Bases:
proteus.LinearSolvers.OperatorConstructor
A class for building common discrete operators from one-level transport models.
- Parameters
OLT (
proteus.Transport.OneLevelTransport
) – One level transport class from which operator construction will be based.
- class proteus.LinearSolvers.ChebyshevSemiIteration(A, alpha, beta, save_iterations=False)[source]
Bases:
proteus.LinearSolvers.LinearSolver
Class for implementing the ChebyshevSemiIteration.
Notes
The Chebyshev semi-iteration was developed in the 1960s by Golub and Varga. It is an iterative technique for solving linear systems Ax = b with the property of preserving linearity with respect to the Krylov solves (see Wathen, Rees 2009 - Chebyshev semi-iteration in preconditioning for problems including the mass matrix). This makes the method particularly well suited for solving sub-problems that arise in more complicated block preconditioners such as the Schur complement, provided one has an aprior bound on the systems eigenvalues (see Wathen 1987 - Realisitc eigenvalue bounds for Galerkin mass matrix).
When implementing this method it is important you first have tight aprior bounds on the eigenvalues (denoted here as alpha and beta). This can be a challenge, but the references above do provide these results for many relevant mass matrices.
Also, when implementing this method, the residual b - Ax0 will be preconditioned with the inverse of diag(A). Your eigenvalue bounds should reflect the spectrum of this preconditioned system.
- A:class: p4pyPETSc.Mat
The linear system matrix
- alphafloat
A’s smallest eigenvalue
- betafloat
A’s largest eigenvalue
- save_iterationsbool
A flag indicating whether to store each solution iteration
Notes
The Chebyshev semi-iteration is often used to solve subproblems of larger linear systems. Thus, it is common that this class will use petsc4py matrices and vectors. Currently this is the only case that is implemented, but an additional constructor has been included in the API for superlu matrices for future implementations.
- classmethod chebyshev_superlu_constructor()[source]
Future home of a Chebyshev constructor for superlu matrices.
- apply(b, x, k=5)[source]
This function applies the Chebyshev-semi iteration.
- Parameters
b – The righthand side vector
x – An initial guess for the solution. Note that the solution will be returned in the vector too.
k (int) – Number of iterations
- Returns
x – The result of the Chebyshev semi-iteration.
- Return type
p4pyPETSc.Vec
Bases:
proteus.LinearSolvers.SolverNullSpace
Applies the global null space created from a pure Neumann boundary problem.
- Parameters
par_b (:vec:`petsc4py_vec`) –
- class proteus.LinearSolvers.ConstantNullSpace(proteus_ksp)[source]
Bases:
proteus.LinearSolvers.SolverNullSpace
- apply_ns(par_b)[source]
Applies the global null space created from a pure Neumann boundary problem.
- Parameters
par_b (:vec:`petsc4py_vec`) –