https://mooseframework.inl.gov
NonlinearSystemBase.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "SolverSystem.h"
13 #include "ConstraintWarehouse.h"
14 #include "MooseObjectWarehouse.h"
16 #include "PerfGraphInterface.h"
17 #include "ComputeMortarFunctor.h"
18 #include "MooseHashing.h"
19 
20 #include "libmesh/transient_system.h"
21 #include "libmesh/nonlinear_implicit_system.h"
22 #include "libmesh/linear_solver.h"
23 
24 // Forward declarations
25 class FEProblemBase;
27 class JacobianBlock;
28 class TimeIntegrator;
29 class Predictor;
30 class ElementDamper;
31 class NodalDamper;
32 class GeneralDamper;
34 class IntegratedBCBase;
35 class NodalBCBase;
36 class DirichletBCBase;
37 class ADDirichletBCBase;
38 class DGKernelBase;
40 class ScalarKernelBase;
41 class DiracKernelBase;
42 class NodalKernelBase;
43 class Split;
44 class KernelBase;
45 class HDGKernel;
46 class BoundaryCondition;
47 class ResidualObject;
48 class PenetrationInfo;
50 
51 // libMesh forward declarations
52 namespace libMesh
53 {
54 template <typename T>
55 class NumericVector;
56 template <typename T>
57 class SparseMatrix;
58 template <typename T>
59 class DiagonalMatrix;
60 class DofMapBase;
61 } // namespace libMesh
62 
69 {
70 public:
71  NonlinearSystemBase(FEProblemBase & problem, libMesh::System & sys, const std::string & name);
72  virtual ~NonlinearSystemBase();
73 
74  virtual void preInit() override;
76  void reinitMortarFunctors();
77 
78  bool computedScalingJacobian() const { return _computed_scaling; }
79 
83  virtual void turnOffJacobian();
84 
85  virtual void solve() override = 0;
86 
88 
89  virtual SNES getSNES() = 0;
90 
91  virtual unsigned int getCurrentNonlinearIterationNumber() = 0;
92 
98 
99  // Setup Functions ////
100  virtual void initialSetup() override;
101  virtual void timestepSetup() override;
102  virtual void customSetup(const ExecFlagType & exec_type) override;
103  virtual void residualSetup() override;
104  virtual void jacobianSetup() override;
105 
106  virtual void setupFiniteDifferencedPreconditioner() = 0;
107 
109  {
111  }
112  bool haveFieldSplitPreconditioner() const { return _fsp; }
113 
120  virtual void addKernel(const std::string & kernel_name,
121  const std::string & name,
122  InputParameters & parameters);
123 
130  virtual void addHDGKernel(const std::string & kernel_name,
131  const std::string & name,
132  InputParameters & parameters);
133 
140  virtual void addNodalKernel(const std::string & kernel_name,
141  const std::string & name,
142  InputParameters & parameters);
143 
150  void addScalarKernel(const std::string & kernel_name,
151  const std::string & name,
152  InputParameters & parameters);
153 
160  void addBoundaryCondition(const std::string & bc_name,
161  const std::string & name,
162  InputParameters & parameters);
163 
164 #ifdef MOOSE_KOKKOS_ENABLED
165 
171  virtual void addKokkosKernel(const std::string & kernel_name,
172  const std::string & name,
173  InputParameters & parameters);
174 
181  virtual void addKokkosNodalKernel(const std::string & kernel_name,
182  const std::string & name,
183  InputParameters & parameters);
184 
191  void addKokkosBoundaryCondition(const std::string & bc_name,
192  const std::string & name,
193  InputParameters & parameters);
194 #endif
195 
202  void
203  addConstraint(const std::string & c_name, const std::string & name, InputParameters & parameters);
204 
211  void addDiracKernel(const std::string & kernel_name,
212  const std::string & name,
213  InputParameters & parameters);
214 
221  void
222  addDGKernel(std::string dg_kernel_name, const std::string & name, InputParameters & parameters);
223 
230  void addInterfaceKernel(std::string interface_kernel_name,
231  const std::string & name,
232  InputParameters & parameters);
233 
240  void addDamper(const std::string & damper_name,
241  const std::string & name,
242  InputParameters & parameters);
243 
250  void
251  addSplit(const std::string & split_name, const std::string & name, InputParameters & parameters);
252 
257  std::shared_ptr<Split> getSplit(const std::string & name);
258 
263 
270  bool shouldEvaluatePreSMOResidual() const;
271 
286  void setPreSMOResidual(bool use) { _use_pre_smo_residual = use; }
287 
289  const bool & usePreSMOResidual() const { return _use_pre_smo_residual; }
290 
292  Real referenceResidual() const;
293 
295  Real preSMOResidual() const;
296 
298  Real initialResidual() const;
299 
301  void setInitialResidual(Real r);
302 
303  void zeroVectorForResidual(const std::string & vector_name);
304 
305  void setInitialSolution();
306 
307 #ifdef MOOSE_KOKKOS_ENABLED
309 #endif
310 
315 
323  void constraintResiduals(NumericVector<Number> & residual, bool displaced);
324 
330  void computeResidualTag(NumericVector<Number> & residual, TagID tag_id);
331 
335  void computeResidualTags(const std::set<TagID> & tags);
336 
340  void computeResidualAndJacobianTags(const std::set<TagID> & vector_tags,
341  const std::set<TagID> & matrix_tags);
342 
347  void computeResidualAndJacobianInternal(const std::set<TagID> & vector_tags,
348  const std::set<TagID> & matrix_tags);
349 
353  void computeResidual(NumericVector<Number> & residual, TagID tag_id);
354 
361 
368  void constraintJacobians(const SparseMatrix<Number> & jacobian_to_view, bool displaced);
369 
373  void computeJacobianTags(const std::set<TagID> & tags);
374 
379  bool computeScaling();
380 
384  void computeJacobian(libMesh::SparseMatrix<Number> & jacobian, const std::set<TagID> & tags);
385 
390 
399  void computeJacobianBlocks(std::vector<JacobianBlock *> & blocks);
400 
401  void computeJacobianBlocks(std::vector<JacobianBlock *> & blocks, const std::set<TagID> & tags);
402 
410 
414  void onTimestepBegin();
415 
422  virtual void subdomainSetup(SubdomainID subdomain, THREAD_ID tid);
423 
429 
433  void updateActive(THREAD_ID tid);
434 
441  virtual void setSolutionUDot(const NumericVector<Number> & udot);
442 
449  virtual void setSolutionUDotDot(const NumericVector<Number> & udotdot);
450 
455 
460 
465 
466  virtual NumericVector<Number> & residualCopy() override;
467  virtual NumericVector<Number> & residualGhosted() override;
468 
469  virtual NumericVector<Number> & RHS() = 0;
470 
471  virtual void augmentSparsity(libMesh::SparsityPattern::Graph & sparsity,
472  std::vector<dof_id_type> & n_nz,
473  std::vector<dof_id_type> & n_oz) override;
474 
479  void setPreconditioner(std::shared_ptr<MoosePreconditioner> pc);
480  MoosePreconditioner const * getPreconditioner() const;
481 
487  {
489  }
490 
495 
501 
511  {
513  }
514 
520  void assembleConstraintsSeparately(bool separately = true)
521  {
523  }
524 
529  virtual void attachPreconditioner(libMesh::Preconditioner<Number> * preconditioner) = 0;
530 
534  void setupDampers();
540  void reinitIncrementAtQpsForDampers(THREAD_ID tid, const std::set<MooseVariable *> & damped_vars);
541 
548  const std::set<MooseVariable *> & damped_vars);
549 
552  void checkKernelCoverage(const std::set<SubdomainID> & mesh_subdomains) const;
553  virtual bool containsTimeKernel() override;
554  virtual std::vector<std::string> timeKernelVariableNames() override;
556 
560  unsigned int nNonlinearIterations() const { return _n_iters; }
561 
565  unsigned int nLinearIterations() const { return _n_linear_iters; }
566 
570  unsigned int nResidualEvaluations() const { return _n_residual_evaluations; }
571 
576 
581  Real nonlinearNorm() const { return _last_nl_rnorm; }
582 
587  void printAllVariableNorms(bool state) { _print_all_var_norms = state; }
588 
589  void debuggingResiduals(bool state) { _debugging_residuals = state; }
590 
592 
593  void setPredictor(std::shared_ptr<Predictor> predictor);
594  Predictor * getPredictor() { return _predictor.get(); }
595 
600  bool needBoundaryMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid) const;
601 
606  bool needInterfaceMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid) const;
607 
612  bool needInternalNeighborSideMaterial(SubdomainID subdomain_id, THREAD_ID tid) const;
613 
617  bool doingDG() const;
618 
620 
627  {
628  return _interface_kernels;
629  }
633  {
634  return _scalar_kernels;
635  }
637  {
638  return _nodal_kernels;
639  }
642  {
643  return _element_dampers;
644  }
646  {
647  return _nodal_dampers;
648  }
650 
655 
660  {
661  return _integrated_bcs;
662  }
663 
664 #ifdef MOOSE_KOKKOS_ENABLED
669  {
670  return _kokkos_nodal_kernels;
671  }
673  {
674  return _kokkos_nodal_bcs;
675  }
677  {
678  return _kokkos_integrated_bcs;
679  }
681 #endif
682 
684 
688  bool hasSaveIn() const { return _has_save_in || _has_nodalbc_save_in; }
689 
694 
695  virtual libMesh::System & system() override { return _sys; }
696  virtual const libMesh::System & system() const override { return _sys; }
697 
698  virtual void setSolutionUDotOld(const NumericVector<Number> & u_dot_old);
699 
700  virtual void setSolutionUDotDotOld(const NumericVector<Number> & u_dotdot_old);
701 
702  virtual void setPreviousNewtonSolution(const NumericVector<Number> & soln);
703 
704  TagID timeVectorTag() const override { return _Re_time_tag; }
705  TagID nonTimeVectorTag() const override { return _Re_non_time_tag; }
706  TagID residualVectorTag() const override { return _Re_tag; }
707  TagID systemMatrixTag() const override { return _Ke_system_tag; }
708 
712  virtual void residualAndJacobianTogether() = 0;
713 
714  bool computeScalingOnce() const { return _compute_scaling_once; }
715  void computeScalingOnce(bool compute_scaling_once)
716  {
717  _compute_scaling_once = compute_scaling_once;
718  }
719 
725  void autoScalingParam(Real resid_vs_jac_scaling_param)
726  {
727  _resid_vs_jac_scaling_param = resid_vs_jac_scaling_param;
728  }
729 
730  void scalingGroupVariables(const std::vector<std::vector<std::string>> & scaling_group_variables)
731  {
732  _scaling_group_variables = scaling_group_variables;
733  }
734 
735  void
736  ignoreVariablesForAutoscaling(const std::vector<std::string> & ignore_variables_for_autoscaling)
737  {
738  _ignore_variables_for_autoscaling = ignore_variables_for_autoscaling;
739  }
740 
742  void offDiagonalsInAutoScaling(bool off_diagonals_in_auto_scaling)
743  {
744  _off_diagonals_in_auto_scaling = off_diagonals_in_auto_scaling;
745  }
746 
748  // FIXME: make these protected and create getters/setters
750  std::vector<unsigned int> _current_l_its;
751  unsigned int _current_nl_its;
752 
756  void setupDM();
757 
759 
765 
769  void destroyColoring();
770 
771 protected:
776  void computeResidualInternal(const std::set<TagID> & tags);
777 
781 #ifdef MOOSE_KOKKOS_ENABLED
782  void computeKokkosResidual(const std::set<TagID> & tags);
783 #endif
784 
789  void computeNodalBCs(NumericVector<Number> & residual);
790 
794  void computeNodalBCs(NumericVector<Number> & residual, const std::set<TagID> & tags);
795 
799  void computeNodalBCs(const std::set<TagID> & tags);
800 
805 
809  void computeJacobianInternal(const std::set<TagID> & tags);
810 
814 #ifdef MOOSE_KOKKOS_ENABLED
815  void computeKokkosJacobian(const std::set<TagID> & tags);
816 #endif
817 
818  void computeDiracContributions(const std::set<TagID> & tags, bool is_jacobian);
819 
820  void computeScalarKernelsJacobians(const std::set<TagID> & tags);
821 
827 
831  void mortarConstraints(Moose::ComputeType compute_type,
832  const std::set<TagID> & vector_tags,
833  const std::set<TagID> & matrix_tags);
834 
838  virtual void computeScalingJacobian() = 0;
839 
843  virtual void computeScalingResidual() = 0;
844 
849  void assembleScalingVector();
850 
856 
861  void reinitNodeFace(const Node & secondary_node,
862  const BoundaryID secondary_boundary,
863  const PenetrationInfo & info,
864  const bool displaced);
865 
875  bool preSolve();
876 
879 
881  std::unique_ptr<NumericVector<Number>> _residual_copy;
882 
887 
890 
892  std::set<TagID> _nl_vector_tags;
893 
895  std::set<TagID> _nl_matrix_tags;
896 
899 
904 
907 
910 
913 
922 
930 
931 #ifdef MOOSE_KOKKOS_ENABLED
940 #endif
941 
944 
947 
950 
953 
956 
958  MooseObjectWarehouseBase<Split> _splits; // use base b/c there are no setup methods
959 
962 
966  std::shared_ptr<MoosePreconditioner> _preconditioner;
967 
970 
971  MatFDColoring _fdcoloring;
972 
975 
978 
981 
986 
988  bool _doing_dg;
989 
991  std::vector<std::string> _vecs_to_zero_for_residual;
992 
993  unsigned int _n_iters;
994  unsigned int _n_linear_iters;
995 
998 
1000 
1002  std::shared_ptr<Predictor> _predictor;
1003 
1005 
1012 
1014 
1017 
1020 
1023 
1026 
1027  void getNodeDofs(dof_id_type node_id, std::vector<dof_id_type> & dofs);
1028 
1031 
1036 
1041 
1045  std::vector<std::vector<std::string>> _scaling_group_variables;
1046 
1048  std::vector<bool> _variable_autoscaled;
1049 
1051  std::vector<std::string> _ignore_variables_for_autoscaling;
1052 
1055 
1057  std::unique_ptr<libMesh::DiagonalMatrix<Number>> _scaling_matrix;
1058 
1059 private:
1064  GeometricSearchData & geom_search_data,
1065  std::unordered_map<dof_id_type, std::vector<dof_id_type>> & graph);
1066 
1070  void setupScalingData();
1071 
1073  std::unordered_map<std::pair<BoundaryID, BoundaryID>, ComputeMortarFunctor>
1075 
1077  std::unordered_map<std::pair<BoundaryID, BoundaryID>, ComputeMortarFunctor>
1079 
1081  std::vector<NumericVector<Number> *> _solution_state;
1082 
1085 
1087  std::unordered_map<unsigned int, unsigned int> _var_to_group_var;
1088 
1090  std::size_t _num_scaling_groups;
1091 };
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 &parameters)
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.
Definition: HDGKernel.h:17
MooseObjectTagWarehouse< ResidualObject > _kokkos_nodal_kernels
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.
Definition: GeneralDamper.h:21
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)
MooseObjectTagWarehouse< ResidualObject > & getKokkosIntegratedBCWarehouse()
Base class for split-based preconditioners.
Definition: Split.h:25
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
MooseObjectTagWarehouse< ResidualObject > _kokkos_kernels
unsigned int TagID
Definition: MooseTypes.h:210
Real computeDamping(const NumericVector< Number > &solution, const NumericVector< Number > &update)
Compute damping.
virtual void setPreviousNewtonSolution(const NumericVector< Number > &soln)
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.
MPI_Info info
NumericVector< Number > & solution()
Definition: SystemBase.h:196
MooseObjectTagWarehouse< DGKernelBase > _dg_kernels
char ** blocks
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...
virtual SNES getSNES()=0
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.
Definition: Predictor.h:28
MooseObjectTagWarehouse< ResidualObject > & getKokkosKernelWarehouse()
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 &parameters)
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.
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 debuggingResiduals(bool state)
MooseObjectWarehouseBase< Split > _splits
Decomposition splits.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void addKokkosKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds a Kokkos kernel.
MooseObjectTagWarehouse< ResidualObject > & getKokkosNodalKernelWarehouse()
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
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.
virtual void addKokkosNodalKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds a Kokkos nodal kernel.
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.
MooseObjectWarehouse< ResidualObject > _kokkos_preset_nodal_bcs
std::size_t _num_scaling_groups
The number of scaling groups.
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.
Serves as a base class for DGKernel and ADDGKernel.
Definition: DGKernelBase.h:32
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)
Definition: SystemBase.C:1243
void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds a scalar kernel.
void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters &parameters)
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
Definition: SystemBase.C:1340
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&#39;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&#39;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.
Definition: KernelBase.h:23
void computeDiracContributions(const std::set< TagID > &tags, bool is_jacobian)
void updateActive(THREAD_ID tid)
Update active objects of Warehouses owned by NonlinearSystemBase.
FieldSplitPreconditionerBase & getFieldSplitPreconditioner()
std::unordered_map< std::pair< BoundaryID, BoundaryID >, ComputeMortarFunctor > _displaced_mortar_functors
Functors for computing displaced mortar constraints.
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 &parameters)
Adds a split.
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.
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 &parameters)
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.
Definition: NodalDamper.h:27
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.
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.
Definition: NodalBCBase.h:26
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)
void computeKokkosJacobian(const std::set< TagID > &tags)
Compute Jacobian with Kokkos objects.
TagID residualVectorTag() const override
MooseObjectTagWarehouse< DiracKernelBase > & getDiracKernelWarehouse()
virtual void customSetup(const ExecFlagType &exec_type) override
ComputeType
The type of nonlinear computation being performed.
Definition: MooseTypes.h:781
Base class for deriving element dampers.
Definition: ElementDamper.h:33
Base interface for field split preconditioner.
bool offDiagonalsInAutoScaling() const
bool _add_implicit_geometric_coupling_entries_to_jacobian
Whether or not to add implicit geometric couplings to the Jacobian for FDP.
MooseObjectTagWarehouse< ResidualObject > _kokkos_integrated_bcs
virtual void addNodalKernel(const std::string &kernel_name, const std::string &name, InputParameters &parameters)
Adds a NodalKernel.
Base class for creating new types of boundary conditions.
MooseObjectTagWarehouse< ResidualObject > & getKokkosNodalBCWarehouse()
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 &parameters)
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()
Definition: SystemBase.C:1592
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.
Definition: MooseEnumItem.h:18
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.
Definition: SystemBase.C:410
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)
void addKokkosBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters &parameters)
Adds a Kokkos boundary condition.
bool needInternalNeighborSideMaterial(SubdomainID subdomain_id, THREAD_ID tid) const
Indicates whether this system needs material properties on internal sides.
void computeKokkosResidual(const std::set< TagID > &tags)
Compute residual with Kokkos objects.
Base class shared by AD and non-AD scalar kernels.
void addDamper(const std::string &damper_name, const std::string &name, InputParameters &parameters)
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.
libMesh::System & _sys
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 &parameters)
Adds a Constraint.
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
Real Number
unsigned int nResidualEvaluations() const
Return the total number of residual evaluations done so far in this calculation.
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...
void setKokkosInitialSolution()
MooseObjectTagWarehouse< IntegratedBCBase > _integrated_bcs
void useFieldSplitPreconditioner(FieldSplitPreconditionerBase *fsp)
If called with a non-null object true this system will use a field split preconditioner matrix...
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 &parameters)
Adds an interface kernel.
FieldSplitPreconditionerBase * _fsp
The field split preconditioner if this sytem is using one.
virtual NumericVector< Number > & residualCopy() override
void reinitMortarFunctors()
Update the mortar functors if the mesh has changed.
virtual NumericVector< Number > & residualGhosted() override
DiracKernelBase is the base class for all DiracKernel type classes.
MooseObjectTagWarehouse< ResidualObject > _kokkos_nodal_bcs
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.
unsigned int THREAD_ID
Definition: MooseTypes.h:209
uint8_t dof_id_type
virtual ~NonlinearSystemBase()
virtual void preInit() override
This is called prior to the libMesh system has been init&#39;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.