20 #include "libmesh/transient_system.h" 21 #include "libmesh/nonlinear_implicit_system.h" 22 #include "libmesh/linear_solver.h" 72 virtual void preInit()
override;
81 virtual void solve()
override = 0;
117 virtual void addKernel(
const std::string & kernel_name,
118 const std::string &
name,
127 virtual void addHDGKernel(
const std::string & kernel_name,
128 const std::string &
name,
138 const std::string &
name,
148 const std::string &
name,
158 const std::string &
name,
177 const std::string &
name,
196 const std::string &
name,
205 void addDamper(
const std::string & damper_name,
206 const std::string &
name,
222 std::shared_ptr<Split>
getSplit(
const std::string &
name);
302 const std::set<TagID> & matrix_tags);
309 const std::set<TagID> & matrix_tags);
433 std::vector<dof_id_type> & n_nz,
434 std::vector<dof_id_type> & n_oz)
override;
510 const std::set<MooseVariable *> & damped_vars);
555 void setPredictor(std::shared_ptr<Predictor> predictor);
761 const std::set<TagID> & vector_tags,
762 const std::set<TagID> & matrix_tags);
793 const bool displaced);
988 std::unordered_map<
dof_id_type, std::vector<dof_id_type>> & graph);
virtual void setSolutionUDotDotOld(const NumericVector< Number > &u_dotdot_old)
const ConstraintWarehouse & getConstraintWarehouse() const
NumericVector< Number > & getResidualTimeVector()
Return a numeric vector that is associated with the time tag.
MooseObjectTagWarehouse< NodalKernelBase > _nodal_kernels
NodalKernels for each thread.
NumericVector< Number > * _Re_time
residual vector for time contributions
void computeJacobianBlocks(std::vector< JacobianBlock *> &blocks)
Computes several Jacobian blocks simultaneously, summing their contributions into smaller preconditio...
unsigned int nLinearIterations() const
Return the number of linear iterations.
Helper class for holding the preconditioning blocks to fill.
TagID _Re_time_tag
Tag for time contribution residual.
virtual void addKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a kernel.
virtual void setSolutionUDotDot(const NumericVector< Number > &udotdot)
Set transient term used by residual and Jacobian evaluation.
const MooseObjectTagWarehouse< NodalBCBase > & getNodalBCWarehouse() const
Return the NodalBCBase warehouse.
A kernel for hybridized finite element formulations.
void reinitIncrementAtNodeForDampers(THREAD_ID tid, const std::set< MooseVariable *> &damped_vars)
Compute the incremental change in variables at nodes for dampers.
void overwriteNodeFace(NumericVector< Number > &soln)
Called from explicit time stepping to overwrite boundary positions (explicit dynamics).
Base class for deriving general dampers.
bool _use_pre_smo_residual
Whether to use the pre-SMO initial residual in the relative convergence check.
MoosePreconditioner const * getPreconditioner() const
void findImplicitGeometricCouplingEntries(GeometricSearchData &geom_search_data, std::unordered_map< dof_id_type, std::vector< dof_id_type >> &graph)
Finds the implicit sparsity graph between geometrically related dofs.
void setupDampers()
Setup damping stuff (called before we actually start)
Real _initial_residual
The initial (i.e., 0th nonlinear iteration) residual, see setPreSMOResidual for a detailed explanatio...
std::vector< bool > _variable_autoscaled
Container to hold flag if variable is to participate in autoscaling.
void zeroVectorForResidual(const std::string &vector_name)
Base class for split-based preconditioners.
void computeNodalBCsResidualAndJacobian()
compute the residual and Jacobian for nodal boundary conditions
bool computeScalingOnce() const
bool _debugging_residuals
true if debugging residuals
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
Real computeDamping(const NumericVector< Number > &solution, const NumericVector< Number > &update)
Compute damping.
virtual void setPreviousNewtonSolution(const NumericVector< Number > &soln)
void enforceNodalConstraintsJacobian()
bool _assemble_constraints_separately
Whether or not to assemble the residual and Jacobian after the application of each constraint...
const MooseObjectWarehouse< ElementDamper > & getElementDamperWarehouse() const
TagID systemMatrixTag() const override
Return the Matrix Tag ID for System.
NumericVector< Number > & solution()
MooseObjectTagWarehouse< DGKernelBase > _dg_kernels
Predictor * getPredictor()
void reinitIncrementAtQpsForDampers(THREAD_ID tid, const std::set< MooseVariable *> &damped_vars)
Compute the incremental change in variables at QPs for dampers.
void computeResidualAndJacobianInternal(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Compute residual and Jacobian from contributions not related to constraints, such as nodal boundary c...
void addImplicitGeometricCouplingEntriesToJacobian(bool add=true)
If called with true this will add entries into the jacobian to link together degrees of freedom that ...
bool haveFieldSplitPreconditioner() const
Base class for predictors.
unsigned int _n_linear_iters
virtual void initialSetup() override
Setup Functions.
Data structure used to hold penetration information.
bool _has_nodalbc_diag_save_in
If there is a nodal BC having diag_save_in.
Base class for automatic differentiation Dirichlet BCs.
void setupDM()
Setup the PETSc DM object (when appropriate)
void checkKernelCoverage(const std::set< SubdomainID > &mesh_subdomains) const
void addDGKernel(std::string dg_kernel_name, const std::string &name, InputParameters ¶meters)
Adds a DG kernel.
void computeJacobian(libMesh::SparseMatrix< Number > &jacobian, const std::set< TagID > &tags)
Associate jacobian to systemMatrixTag, and then form a matrix for all the tags.
void setupFieldDecomposition()
std::vector< NumericVector< Number > * > _solution_state
The current states of the solution (0 = current, 1 = old, etc)
const MooseObjectTagWarehouse< KernelBase > & getKernelWarehouse() const
void getNodeDofs(dof_id_type node_id, std::vector< dof_id_type > &dofs)
MooseObjectTagWarehouse< KernelBase > & getKernelWarehouse()
Access functions to Warehouses from outside NonlinearSystemBase.
std::set< TagID > _nl_vector_tags
Vector tags to temporarily store all tags associated with the current system.
std::vector< std::string > _ignore_variables_for_autoscaling
A container for variables that do not partipate in autoscaling.
TagID nonTimeVectorTag() const override
Base boundary condition of a Dirichlet type.
MooseObjectTagWarehouse< NodalBCBase > _nodal_bcs
void setDecomposition(const std::vector< std::string > &decomposition)
If called with a single string, it is used as the name of a the top-level decomposition split...
bool needSubdomainMaterialOnSide(SubdomainID subdomain_id, THREAD_ID tid) const
Indicates whether this system needs material properties on internal sides.
void debuggingResiduals(bool state)
MooseObjectWarehouseBase< Split > _splits
Decomposition splits.
bool _has_nodalbc_save_in
If there is a nodal BC having save_in.
MooseObjectWarehouse< NodalDamper > _nodal_dampers
Nodal Dampers for each thread.
virtual libMesh::NonlinearSolver< Number > * nonlinearSolver()=0
void useFieldSplitPreconditioner(bool use=true)
If called with true this system will use a field split preconditioner matrix.
MooseObjectTagWarehouse< IntegratedBCBase > & getIntegratedBCWarehouse()
Real preSMOResidual() const
The pre-SMO residual.
std::unique_ptr< libMesh::DiagonalMatrix< Number > > _scaling_matrix
A diagonal matrix used for computing scaling.
virtual void setSolutionUDotOld(const NumericVector< Number > &u_dot_old)
bool hasDiagSaveIn() const
Weather or not the nonlinear system has diagonal Jacobian save-ins.
Real initialResidual() const
The initial residual.
virtual void attachPreconditioner(libMesh::Preconditioner< Number > *preconditioner)=0
Attach a customized preconditioner that requires physics knowledge.
void computeScalingOnce(bool compute_scaling_once)
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
bool needInterfaceMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid) const
Indicated whether this system needs material properties on interfaces.
std::size_t _num_scaling_groups
The number of scaling groups.
bool _print_all_var_norms
const MooseObjectTagWarehouse< IntegratedBCBase > & getIntegratedBCWarehouse() const
Return the IntegratedBCBase warehouse.
Real _pre_smo_residual
The pre-SMO residual, see setPreSMOResidual for a detailed explanation.
MooseObjectTagWarehouse< HDGKernel > & getHDGKernelWarehouse()
Real finalNonlinearResidual() const
Return the final nonlinear residual.
bool _compute_scaling_once
Whether the scaling factors should only be computed once at the beginning of the simulation through a...
void computeResidualTags(const std::set< TagID > &tags)
Form multiple tag-associated residual vectors for all the given tags.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool _has_save_in
If there is any Kernel or IntegratedBC having save_in.
TagID _Ke_non_time_tag
Tag for non-time contribution Jacobian.
TagID _Ke_system_tag
Tag for system contribution Jacobian.
bool _have_decomposition
Whether or not the system can be decomposed into splits.
Serves as a base class for DGKernel and ADDGKernel.
void constraintResiduals(NumericVector< Number > &residual, bool displaced)
Add residual contributions from Constraints.
Base class for MOOSE preconditioners.
std::unordered_map< std::pair< BoundaryID, BoundaryID >, ComputeMortarFunctor > _undisplaced_mortar_functors
Functors for computing undisplaced mortar constraints.
const MooseObjectTagWarehouse< ScalarKernelBase > & getScalarKernelWarehouse() const
void update()
Update the system (doing libMesh magic)
void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a scalar kernel.
void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters ¶meters)
Adds a boundary condition.
void computeResidual(NumericVector< Number > &residual, TagID tag_id)
Form a residual vector for a given tag.
MooseObjectTagWarehouse< InterfaceKernelBase > & getInterfaceKernelWarehouse()
bool _need_residual_ghosted
Whether or not a ghosted copy of the residual needs to be made.
Nonlinear system to be solved.
virtual const std::string & name() const
virtual bool containsTimeKernel() override
If the system has a kernel that corresponds to a time derivative.
void onTimestepBegin()
Called at the beginning of the time step.
MooseObjectTagWarehouse< DiracKernelBase > _dirac_kernels
Dirac Kernel storage for each thread.
TagID _Re_non_time_tag
Tag for non-time contribution residual.
std::set< TagID > _nl_matrix_tags
Matrix tags to temporarily store all tags associated with the current system.
void setPredictor(std::shared_ptr< Predictor > predictor)
Real _resid_vs_jac_scaling_param
The param that indicates the weighting of the residual vs the Jacobian in determining variable scalin...
bool _auto_scaling_initd
Whether we've initialized the automatic scaling data structures.
virtual void computeScalingResidual()=0
Compute a "residual" for automatic scaling purposes.
virtual void setupFiniteDifferencedPreconditioner()=0
bool _doing_dg
true if DG is active (optimization reasons)
bool computedScalingJacobian() const
void useFiniteDifferencedPreconditioner(bool use=true)
If called with true this system will use a finite differenced form of the Jacobian as the preconditio...
void computeResidualAndJacobianTags(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Form possibly multiple tag-associated vectors and matrices.
bool needBoundaryMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid) const
Indicated whether this system needs material properties on boundaries.
MooseObjectWarehouse< DirichletBCBase > _preset_nodal_bcs
std::unordered_map< unsigned int, unsigned int > _var_to_group_var
A map from variable index to group variable index and it's associated (inverse) scaling factor...
std::vector< unsigned int > _current_l_its
void offDiagonalsInAutoScaling(bool off_diagonals_in_auto_scaling)
void scalingGroupVariables(const std::vector< std::vector< std::string >> &scaling_group_variables)
This is the common base class for the three main kernel types implemented in MOOSE, Kernel, VectorKernel and ArrayKernel.
void computeDiracContributions(const std::set< TagID > &tags, bool is_jacobian)
void updateActive(THREAD_ID tid)
Update active objects of Warehouses owned by NonlinearSystemBase.
std::unordered_map< std::pair< BoundaryID, BoundaryID >, ComputeMortarFunctor > _displaced_mortar_functors
Functors for computing displaced mortar constraints.
unsigned int _current_nl_its
boundary_id_type BoundaryID
Real referenceResidual() const
The reference residual used in relative convergence check.
void addSplit(const std::string &split_name, const std::string &name, InputParameters ¶meters)
Adds a split.
MatFDColoring _fdcoloring
void computeJacobianTags(const std::set< TagID > &tags)
Computes multiple (tag associated) Jacobian matricese.
std::shared_ptr< MoosePreconditioner > _preconditioner
Preconditioner.
void ignoreVariablesForAutoscaling(const std::vector< std::string > &ignore_variables_for_autoscaling)
std::vector< std::string > _vecs_to_zero_for_residual
vectors that will be zeroed before a residual computation
std::shared_ptr< Split > getSplit(const std::string &name)
Retrieves a split by name.
void setInitialSolution()
bool haveFiniteDifferencedPreconditioner() const
virtual const libMesh::System & system() const override
void addImplicitGeometricCouplingEntries(GeometricSearchData &geom_search_data)
Adds entries to the Jacobian in the correct positions for couplings coming from dofs being coupled th...
bool _use_finite_differenced_preconditioner
Whether or not to use a finite differenced preconditioner.
virtual void addHDGKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a hybridized discontinuous Galerkin (HDG) kernel.
MooseObjectTagWarehouse< KernelBase > _kernels
bool shouldEvaluatePreSMOResidual() const
We offer the option to check convergence against the pre-SMO residual.
Base class for deriving nodal dampers.
bool computingPreSMOResidual()
Returns true if this system is currently computing the pre-SMO residual for a solve.
virtual void computeScalingJacobian()=0
Compute a "Jacobian" for automatic scaling purposes.
bool _computing_pre_smo_residual
void setupScalingData()
Setup group scaling containers.
const bool & usePreSMOResidual() const
Whether we are using pre-SMO residual in relative convergence checks.
MooseObjectTagWarehouse< HDGKernel > _hybridized_kernels
Base class for deriving any boundary condition that works at nodes.
void computeResidualInternal(const std::set< TagID > &tags)
Compute the residual for a given tag.
bool computeScaling()
Method used to obtain scaling factors for variables.
Interface for objects interacting with the PerfGraph.
void destroyColoring()
Destroy the coloring object if it exists.
virtual void solve() override=0
Solve the system (using libMesh magic)
ConstraintWarehouse _constraints
Constraints storage object.
virtual void turnOffJacobian()
Turn off the Jacobian (must be called before equation system initialization)
TagID residualVectorTag() const override
MooseObjectTagWarehouse< DiracKernelBase > & getDiracKernelWarehouse()
virtual void customSetup(const ExecFlagType &exec_type) override
ComputeType
The type of nonlinear computation being performed.
Base class for deriving element dampers.
bool offDiagonalsInAutoScaling() const
bool _add_implicit_geometric_coupling_entries_to_jacobian
Whether or not to add implicit geometric couplings to the Jacobian for FDP.
virtual void addNodalKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a NodalKernel.
Base class for creating new types of boundary conditions.
unsigned int nNonlinearIterations() const
Return the number of non-linear iterations.
void printAllVariableNorms(bool state)
Force the printing of all variable norms after each solve.
virtual NumericVector< Number > & RHS()=0
unsigned int _n_residual_evaluations
Total number of residual evaluations that have been performed.
void addDiracKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a Dirac kernel.
void computeJacobianInternal(const std::set< TagID > &tags)
Form multiple matrices for all the tags.
bool _has_diag_save_in
If there is any Kernel or IntegratedBC having diag_save_in.
Base class for creating new types of nodal kernels.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This is the common base class for objects that give residual contributions.
Base class for time integrators.
std::unique_ptr< NumericVector< Number > > _residual_copy
Copy of the residual vector, or nullptr if a copy is not needed.
virtual void subdomainSetup()
bool hasSaveIn() const
Weather or not the nonlinear system has save-ins.
TagID timeVectorTag() const override
Ideally, we should not need this API.
Class for containing MooseEnum item information.
virtual std::vector< std::string > timeKernelVariableNames() override
Returns the names of the variables that have time derivative kernels in the system.
NonlinearSystemBase(FEProblemBase &problem, libMesh::System &sys, const std::string &name)
virtual unsigned int getCurrentNonlinearIterationNumber()=0
MooseObjectWarehouse< ElementDamper > _element_dampers
Element Dampers for each thread.
virtual void setSolutionUDot(const NumericVector< Number > &udot)
Set transient term used by residual and Jacobian evaluation.
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, THREAD_ID tid)
Reinit nodal assembly info on a face.
Real nonlinearNorm() const
Return the last nonlinear norm.
virtual void augmentSparsity(libMesh::SparsityPattern::Graph &sparsity, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz) override
Will modify the sparsity pattern to add logical geometric connections.
void computeScalarKernelsJacobians(const std::set< TagID > &tags)
void setInitialResidual(Real r)
Record the initial residual (for later relative convergence check)
Base class shared by AD and non-AD scalar kernels.
void addDamper(const std::string &damper_name, const std::string &name, InputParameters ¶meters)
Adds a damper.
virtual void postAddResidualObject(ResidualObject &)
Called after any ResidualObject-derived objects are added to the system.
virtual void timestepSetup() override
bool _off_diagonals_in_auto_scaling
Whether to include off diagonals when determining automatic scaling factors.
void reinitNodeFace(const Node &secondary_node, const BoundaryID secondary_boundary, const PenetrationInfo &info, const bool displaced)
Reinitialize quantities such as variables, residuals, Jacobians, materials for node-face constraints...
Base class for deriving any boundary condition of a integrated type.
NumericVector< Number > * _residual_ghosted
ghosted form of the residual
TagID _Re_tag
Used for the residual vector from PETSc.
MooseObjectWarehouseBase< Split > & getSplits()
Retrieves all splits.
void computeNodalBCs(NumericVector< Number > &residual)
Enforces nodal boundary conditions.
void mortarConstraints(Moose::ComputeType compute_type, const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Do mortar constraint residual/jacobian computations.
NumericVector< Number > * _increment_vec
increment vector
InterfaceKernelBase is the base class for all InterfaceKernel type classes.
bool doingDG() const
Getter for _doing_dg.
void computeResidualTag(NumericVector< Number > &residual, TagID tag_id)
Computes residual for a given tag.
void addConstraint(const std::string &c_name, const std::string &name, InputParameters ¶meters)
Adds a Constraint.
bool _use_field_split_preconditioner
Whether or not to use a FieldSplitPreconditioner matrix based on the decomposition.
void constraintJacobians(const SparseMatrix< Number > &jacobian_to_view, bool displaced)
Add jacobian contributions from Constraints.
const MooseObjectTagWarehouse< NodalKernelBase > & getNodalKernelWarehouse() const
bool preSolve()
Perform some steps to get ready for the solver.
virtual void residualAndJacobianTogether()=0
Call this method if you want the residual and Jacobian to be computed simultaneously.
bool _computed_scaling
Flag used to indicate whether we have already computed the scaling Jacobian.
void assembleConstraintsSeparately(bool separately=true)
Indicates whether to assemble residual and Jacobian after each constraint application.
const MooseObjectWarehouse< NodalDamper > & getNodalDamperWarehouse() const
unsigned int nResidualEvaluations() const
Return the total number of residual evaluations done so far in this calculation.
std::string _decomposition_split
Name of the top-level split of the decomposition.
MooseObjectTagWarehouse< InterfaceKernelBase > _interface_kernels
MooseObjectTagWarehouse< DGKernelBase > & getDGKernelWarehouse()
NumericVector< Number > & residualVector(TagID tag)
Return a residual vector that is associated with the residual tag.
void autoScalingParam(Real resid_vs_jac_scaling_param)
Sets the param that indicates the weighting of the residual vs the Jacobian in determining variable s...
NumericVector< Number > & getResidualNonTimeVector()
Return a numeric vector that is associated with the nontime tag.
std::shared_ptr< Predictor > _predictor
If predictor is active, this is non-NULL.
void enforceNodalConstraintsResidual(NumericVector< Number > &residual)
Enforce nodal constraints.
unsigned int _num_residual_evaluations
MooseObjectWarehouse< GeneralDamper > _general_dampers
General Dampers.
virtual void potentiallySetupFiniteDifferencing()
Create finite differencing contexts for assembly of the Jacobian and/or approximating the action of t...
MooseObjectTagWarehouse< IntegratedBCBase > _integrated_bcs
virtual void jacobianSetup() override
std::vector< std::vector< std::string > > _scaling_group_variables
A container of variable groupings that can be used in scaling calculations.
void addInterfaceKernel(std::string interface_kernel_name, const std::string &name, InputParameters ¶meters)
Adds an interface kernel.
virtual NumericVector< Number > & residualCopy() override
virtual NumericVector< Number > & residualGhosted() override
DiracKernelBase is the base class for all DiracKernel type classes.
void setPreSMOResidual(bool use)
Set whether to evaluate the pre-SMO residual and use it in the subsequent relative convergence checks...
void assembleScalingVector()
Assemble the numeric vector of scaling factors such that it can be used during assembly of the system...
Warehouse for storing constraints.
MooseObjectTagWarehouse< ScalarKernelBase > _scalar_kernels
void setConstraintSecondaryValues(NumericVector< Number > &solution, bool displaced)
Sets the value of constrained variables in the solution vector.
virtual ~NonlinearSystemBase()
virtual void preInit() override
This is called prior to the libMesh system has been init'd.
virtual void residualSetup() override
void setPreconditioner(std::shared_ptr< MoosePreconditioner > pc)
Sets a preconditioner.
MooseObjectWarehouse< ADDirichletBCBase > _ad_preset_nodal_bcs
virtual libMesh::System & system() override
Get the reference to the libMesh system.