Linear Solvers and Systems Interface¶
Linear Systems¶
-
class
LinearSystem
¶ Subclassed by sierra::nalu::HypreLinearSystem, sierra::nalu::TpetraLinearSystem
Public Functions
-
virtual void
buildDirichletNodeGraph
(const stk::mesh::PartVector&)¶ Process nodes that belong to Dirichlet-type BC.
-
virtual void
buildDirichletNodeGraph
(const std::vector<stk::mesh::Entity>&)¶ Process nodes as belonging to a Dirichlet-type row.
See the documentation/implementation of sierra::nalu::FixPressureAtNodeAlgorithm for an example of this use case.
-
virtual void
resetRows
(std::vector<stk::mesh::Entity> nodeList, const unsigned beginPos, const unsigned endPos) = 0¶ Reset LHS and RHS for the given set of nodes to 0.
- Parameters
nodeList
: A list of STK node entities whose rows are zeroed outbeginPos
: Starting index (usually 0)endPos
: Terminating index (1 for scalar quantities; nDim for vectors)
-
virtual void
-
class
TpetraLinearSystem
: public sierra::nalu::LinearSystem¶ Public Functions
-
virtual void
resetRows
(const std::vector<stk::mesh::Entity> nodeList, const unsigned beginPos, const unsigned endPos)¶ Reset LHS and RHS for the given set of nodes to 0.
- Parameters
nodeList
: A list of STK node entities whose rows are zeroed outbeginPos
: Starting index (usually 0)endPos
: Terminating index (1 for scalar quantities; nDim for vectors)
-
virtual void
-
class
HypreLinearSystem
: public sierra::nalu::LinearSystem¶ Nalu interface to populate a Hypre Linear System.
This class provides an interface to the HYPRE IJMatrix and IJVector data structures. It is responsible for creating, resetting, and destroying the Hypre data structures and provides the HypreLinearSystem::sumInto interface used by Nalu Kernels and SupplementalAlgorithms to populate entries into the linear system. The HypreLinearSystem::solve method interfaces with sierra::nalu::HypreDirectSolver that is responsible for the actual solution of the system using the required solver and preconditioner combination.
Public Functions
-
HypreLinearSystem
(Realm &realm, const unsigned numDof, EquationSystem *eqSys, LinearSolver *linearSolver)¶ - Parameters
[in] realm
: The realm instance that holds the EquationSystem being solved[in] numDof
: The degrees of freedom for the equation system created (Default: 1)[in] eqSys
: The equation system instance[in] linearSolver
: Handle to the HypreDirectSolver instance
-
virtual void
buildDirichletNodeGraph
(const stk::mesh::PartVector&)¶ Tag rows that must be handled as a Dirichlet BC node.
- Parameters
[in] partVec
: List of parts that contain the Dirichlet nodes
-
virtual void
buildDirichletNodeGraph
(const std::vector<stk::mesh::Entity>&)¶ Tag rows that must be handled as a Dirichlet node.
- See
sierra::nalu::FixPressureAtNodeAlgorithm
- Parameters
[in] entities
: List of nodes where Dirichlet conditions are applied
-
virtual void
zeroSystem
()¶ Reset the matrix and rhs data structures for the next iteration/timestep.
Update coefficients of a particular row(s) in the linear system.
The core method of this class, it updates the matrix and RHS based on the inputs from the various algorithms. Note that, unlike TpetraLinearSystem, this method skips over the fringe points of Overset mesh and the Dirichlet nodes rather than resetting them afterward.
This overloaded method deals with Kernels designed with Kokkos::View arrays.
- Parameters
[in] numEntities
: The total number of nodes where data is to be updated[in] entities
: A list of STK node entities[in] rhs
: Array containing RHS entries to be summed into [numEntities * numDof][in] lhs
: Array containing LHS entries to be summed into. [numEntities * numDof, numEntities * numDof][in] localIds
: Work array for storing local row IDs[in] sortPermutation
: Work array for sorting row IDs[in] trace_tag
: Debugging message
-
virtual void
sumInto
(const std::vector<stk::mesh::Entity> &sym_meshobj, std::vector<int> &scratchIds, std::vector<double> &scratchVals, const std::vector<double> &rhs, const std::vector<double> &lhs, const char *trace_tag)¶ Update coefficients of a particular row(s) in the linear system.
The core method of this class, it updates the matrix and RHS based on the inputs from the various algorithms. Note that, unlike TpetraLinearSystem, this method skips over the fringe points of Overset mesh and the Dirichlet nodes rather than resetting them afterward.
This overloaded method deals with classic SupplementalAlgorithms
- Parameters
[in] sym_meshobj
: A list of STK node entities[in] scratchIds
: Work array for row IDs[in] scratchVals
: Work array for row entries[in] rhs
: Array containing RHS entries to be summed into [numEntities * numDof][in] lhs
: Array containing LHS entries to be summed into. [numEntities * numDof * numEntities * numDof][in] trace_tag
: Debugging message
-
virtual void
applyDirichletBCs
(stk::mesh::FieldBase *solutionField, stk::mesh::FieldBase *bcValuesField, const stk::mesh::PartVector &parts, const unsigned beginPos, const unsigned endPos)¶ Populate the LHS and RHS for the Dirichlet rows in linear system.
-
virtual void
prepareConstraints
(const unsigned, const unsigned)¶ Prepare assembly for overset fringe nodes.
The overset fringe nodes are skipped over by the sumInto method during normal assembly process. This method toggles the flag to instruct sumInto that the constraint rows are being filled at this stage.
-
virtual void
resetRows
(std::vector<stk::mesh::Entity>, const unsigned, const unsigned)¶ Prepare assembly for Dirichlet-type rows.
Dirichlet rows are skipped over by the sumInto method when the interior parts are processed. This method toggles the flag alerting the sumInto method that the Dirichlet rows will be processed next and sumInto can proceed.
-
virtual int
solve
(stk::mesh::FieldBase *linearSolutionField)¶ Solve the system Ax = b.
The solution vector is returned in linearSolutionField
- Parameters
[out] linearSolutionField
: STK field where the solution is populated
-
virtual void
loadComplete
()¶ Finalize construction of the linear system matrix and rhs vector.
This method calls the appropriate Hypre functions to assemble the matrix and rhs in a parallel run, as well as registers the matrix and rhs with the solver preconditioner.
-
Linear Solvers Interface¶
-
class
LinearSolver
¶ An abstract representation of a linear solver in Nalu.
Defines the basic API supported by the linear solvers for use within Nalu. See concrete implementations such as sierra::nalu::TpetraLinearSolver for more details.
Subclassed by sierra::nalu::HypreDirectSolver, sierra::nalu::TpetraLinearSolver
Public Functions
-
virtual PetraType
getType
() = 0¶ Type of solver instance as defined in sierra::nalu::PetraType.
-
virtual void
destroyLinearSolver
() = 0¶ Utility method to cleanup solvers during simulation.
-
bool &
recomputePreconditioner
()¶ Flag indicating whether the preconditioner is recomputed on each invocation.
-
bool &
reusePreconditioner
()¶ Flag indicating whether the preconditioner is reused on each invocation.
-
void
zero_timer_precond
()¶ Reset the preconditioner timer to 0.0 for future accumulation.
-
double
get_timer_precond
()¶ Get the preconditioner timer for the last invocation.
-
bool &
activeMueLu
()¶ Flag indicating whether the user has activated MueLU.
-
LinearSolverConfig *
getConfig
()¶ Get the solver configuration specified in the input file.
Public Members
-
std::string
name_
¶ User-friendly identifier for this particular solver instance.
-
virtual PetraType
-
class
TpetraLinearSolver
: public sierra::nalu::LinearSolver¶ Public Functions
-
TpetraLinearSolver
(std::string solverName, TpetraLinearSolverConfig *config, const Teuchos::RCP<Teuchos::ParameterList> params, const Teuchos::RCP<Teuchos::ParameterList> paramsPrecond, LinearSolvers *linearSolvers)¶ - Parameters
[in] solverName
: The name of the solver[in] config
: Solver configuration
-
virtual void
destroyLinearSolver
()¶ Utility method to cleanup solvers during simulation.
-
void
setMueLu
()¶ Initialize the MueLU preconditioner before solve.
-
int
residual_norm
(int whichNorm, Teuchos::RCP<LinSys::Vector> sln, double &norm)¶ Compute the norm of the non-linear solution vector.
- Parameters
[in] whichNorm
: [0, 1, 2] norm to be computed[in] sln
: The solution vector[out] norm
: The norm of the solution vector
-
int
solve
(Teuchos::RCP<LinSys::Vector> sln, int &iterationCount, double &scaledResidual, bool isFinalOuterIter)¶ Solve the linear system Ax = b.
- Parameters
[out] sln
: The solution vector[out] iterationCount
: The number of linear solver iterations to convergence[out] scaledResidual
: The final residual norm[in] isFinalOuterIter
: Is this the final outer iteration
-
virtual PetraType
getType
()¶ Type of solver instance as defined in sierra::nalu::PetraType.
-
-
class
HypreDirectSolver
: public sierra::nalu::LinearSolver¶ Nalu interface to Hypre Solvers and Preconditioners.
This class is responsible creation, initialization, execution, and clean up of Hypre solver and preconditioner data structures during the simulation. It provides an abstraction layer so that the user can choose different Hypre solvers via input parameters. This class interacts with rest of Nalu solely via sierra::nalu::HypreLinearSystem. The configuration of Hypre solver is controlled via user input parameters processed in sierra::nalu::HypreLinearSolverConfig
Users are referred to the Hypre Reference Manual for detailed documentation on the Hypre functions and data structures used in this class.
Public Functions
-
virtual void
destroyLinearSolver
()¶ Clean up Hypre data structures during simulation.
-
int
solve
(int&, double&, bool)¶ Solves the linear system and updates the solution vector.
- Parameters
iters
: The number of linear iterations performednorm
: The norm of the final relative residual
-
virtual PetraType
getType
()¶ Return the type of solver instance.
-
virtual void
-
class
LinearSolvers
¶ Collection of solvers and their associated configuration.
This class performs the following actions within a Nalu simulation:
Parse the
linear_solvers
section and create a mapping of user-defined configurations.Create solvers for specific equation system and update the mapping
Public Functions
-
void
load
(const YAML::Node &node)¶ Parse the
linear_solvers
section from Nalu input file.
-
LinearSolver *
create_solver
(std::string solverBlockName, EquationType theEQ)¶ Create a solver for the EquationSystem.
- Parameters
[in] solverBlockName
: The name specified in the input file, e.g., solve_scalar[in] theEQ
: The type of equation
Public Members
-
SolverMap
solvers_
¶ Mapping of solver instances to the EquationType.
-
SolverTpetraConfigMap
solverTpetraConfig_
¶ A lookup table of solver configurations against the names provided in the input file when the
type
istpetra
-
HypreSolverConfigMap
solverHypreConfig_
¶ A lookup table of solver configurations against the names provided in the input file when
type
ishypre
ortpetra_hypre
-
Simulation &
sim_
¶ Reference to the sierra::nalu::Simulation instance.
Solver Configuration¶
-
class
LinearSolverConfig
¶ Subclassed by sierra::nalu::HypreLinearSolverConfig, sierra::nalu::TpetraLinearSolverConfig
-
class
TpetraLinearSolverConfig
: public sierra::nalu::LinearSolverConfig¶
-
class
HypreLinearSolverConfig
: public sierra::nalu::LinearSolverConfig¶ User configuration parmeters for Hypre solvers and preconditioners.
Public Functions
-
virtual void
load
(const YAML::Node&)¶ Process and validate the user inputs and register calls to appropriate Hypre functions to configure the solver and preconditioner.
-
virtual void