www.mooseframework.org
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
NonlinearSystemBase Class Referenceabstract

Nonlinear system to be solved. More...

#include <NonlinearSystemBase.h>

Inheritance diagram for NonlinearSystemBase:
[legend]

Public Member Functions

 NonlinearSystemBase (FEProblemBase &problem, System &sys, const std::string &name)
 
virtual ~NonlinearSystemBase ()
 
virtual void init () override
 Initialize the system. More...
 
void turnOffJacobian ()
 Turn off the Jacobian (must be called before equation system initialization) More...
 
virtual void addExtraVectors () override
 Method called during initialSetup to add extra system vector if they are required by the simulation. More...
 
virtual void solve () override=0
 Solve the system (using libMesh magic) More...
 
virtual void restoreSolutions () override
 Restore current solutions (call after your solve failed) More...
 
virtual void stopSolve ()=0
 Quit the current solve as soon as possible. More...
 
virtual NonlinearSolver< Number > * nonlinearSolver ()=0
 
virtual unsigned int getCurrentNonlinearIterationNumber ()=0
 
virtual bool computingInitialResidual ()
 Returns true if this system is currently computing the initial residual for a solve. More...
 
virtual void initialSetup ()
 
virtual void timestepSetup ()
 
virtual void setupFiniteDifferencedPreconditioner ()=0
 
void setupFieldDecomposition ()
 
bool haveFiniteDifferencedPreconditioner ()
 
bool haveFieldSplitPreconditioner ()
 
virtual bool converged ()=0
 Returns the convergence state. More...
 
void addTimeIntegrator (const std::string &type, const std::string &name, InputParameters parameters)
 Add a time integrator. More...
 
virtual void addKernel (const std::string &kernel_name, const std::string &name, InputParameters parameters)
 Adds a kernel. More...
 
virtual void addEigenKernels (std::shared_ptr< KernelBase >, THREAD_ID)
 
virtual void addNodalKernel (const std::string &kernel_name, const std::string &name, InputParameters parameters)
 Adds a NodalKernel. More...
 
void addScalarKernel (const std::string &kernel_name, const std::string &name, InputParameters parameters)
 Adds a scalar kernel. More...
 
void addBoundaryCondition (const std::string &bc_name, const std::string &name, InputParameters parameters)
 Adds a boundary condition. More...
 
void addConstraint (const std::string &c_name, const std::string &name, InputParameters parameters)
 Adds a Constraint. More...
 
void addDiracKernel (const std::string &kernel_name, const std::string &name, InputParameters parameters)
 Adds a Dirac kernel. More...
 
void addDGKernel (std::string dg_kernel_name, const std::string &name, InputParameters parameters)
 Adds a DG kernel. More...
 
void addInterfaceKernel (std::string interface_kernel_name, const std::string &name, InputParameters parameters)
 Adds an interface kernel. More...
 
void addDamper (const std::string &damper_name, const std::string &name, InputParameters parameters)
 Adds a damper. More...
 
void addSplit (const std::string &split_name, const std::string &name, InputParameters parameters)
 Adds a split. More...
 
std::shared_ptr< SplitgetSplit (const std::string &name)
 Retrieves a split by name. More...
 
void zeroVectorForResidual (const std::string &vector_name)
 
void setInitialSolution ()
 
void setConstraintSlaveValues (NumericVector< Number > &solution, bool displaced)
 Sets the value of constrained variables in the solution vector. More...
 
void constraintResiduals (NumericVector< Number > &residual, bool displaced)
 Add residual contributions from Constraints. More...
 
void computeResidual (NumericVector< Number > &residual, Moose::KernelType type=Moose::KT_ALL)
 Computes residual. More...
 
void findImplicitGeometricCouplingEntries (GeometricSearchData &geom_search_data, std::map< dof_id_type, std::vector< dof_id_type >> &graph)
 Finds the implicit sparsity graph between geometrically related dofs. More...
 
void addImplicitGeometricCouplingEntries (SparseMatrix< Number > &jacobian, GeometricSearchData &geom_search_data)
 Adds entries to the Jacobian in the correct positions for couplings coming from dofs being coupled that are related geometrically (i.e. More...
 
void constraintJacobians (SparseMatrix< Number > &jacobian, bool displaced)
 Add jacobian contributions from Constraints. More...
 
void setVariableGlobalDoFs (const std::string &var_name)
 set all the global dof indices for a nonlinear variable More...
 
const std::vector< dof_id_type > & getVariableGlobalDoFs ()
 
void computeJacobian (SparseMatrix< Number > &jacobian, Moose::KernelType kernel_type=Moose::KT_ALL)
 Computes Jacobian. More...
 
void computeJacobianBlocks (std::vector< JacobianBlock * > &blocks)
 Computes several Jacobian blocks simultaneously, summing their contributions into smaller preconditioning matrices. More...
 
Real computeDamping (const NumericVector< Number > &solution, const NumericVector< Number > &update)
 Compute damping. More...
 
void computeTimeDerivatives ()
 Computes the time derivative vector. More...
 
void onTimestepBegin ()
 Called at the beginning of the time step. More...
 
virtual void subdomainSetup (SubdomainID subdomain, THREAD_ID tid)
 Called from assembling when we hit a new subdomain. More...
 
virtual void setSolution (const NumericVector< Number > &soln)
 
void updateActive (THREAD_ID tid)
 Update active objects of Warehouses owned by NonlinearSystemBase. More...
 
virtual void setSolutionUDot (const NumericVector< Number > &udot)
 Set transient term used by residual and Jacobian evaluation. More...
 
virtual NumericVector< Number > & solutionUDot () override
 
virtual NumericVector< Number > & residualVector (Moose::KernelType type) override
 
virtual bool hasResidualVector (Moose::KernelType type) const override
 
virtual const NumericVector< Number > *& currentSolution () override
 The solution vector that is currently being operated on. More...
 
virtual void serializeSolution ()
 
virtual NumericVector< Number > & serializedSolution () override
 Returns a reference to a serialized version of the solution vector for this subproblem. More...
 
virtual NumericVector< Number > & residualCopy () override
 
virtual NumericVector< Number > & residualGhosted () override
 
virtual NumericVector< Number > & RHS ()=0
 
virtual void augmentSparsity (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. More...
 
void setPreconditioner (std::shared_ptr< MoosePreconditioner > pc)
 Sets a preconditioner. More...
 
void useFiniteDifferencedPreconditioner (bool use=true)
 If called with true this system will use a finite differenced form of the Jacobian as the preconditioner. More...
 
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. More...
 
void useFieldSplitPreconditioner (bool use=true)
 If called with true this system will use a field split preconditioner matrix. More...
 
void addImplicitGeometricCouplingEntriesToJacobian (bool add=true)
 If called with true this will add entries into the jacobian to link together degrees of freedom that are found to be related through the geometric search system. More...
 
void assembleConstraintsSeparately (bool separately=true)
 Indicates whether to assemble residual and Jacobian after each constraint application. More...
 
void setupDampers ()
 Setup damping stuff (called before we actually start) More...
 
void reinitIncrementAtQpsForDampers (THREAD_ID tid, const std::set< MooseVariable * > &damped_vars)
 Compute the incremental change in variables at QPs for dampers. More...
 
void reinitIncrementAtNodeForDampers (THREAD_ID tid, const std::set< MooseVariable * > &damped_vars)
 Compute the incremental change in variables at nodes for dampers. More...
 
unsigned int nNonlinearIterations ()
 Return the number of non-linear iterations. More...
 
unsigned int nLinearIterations ()
 Return the number of linear iterations. More...
 
unsigned int nResidualEvaluations ()
 Return the total number of residual evaluations done so far in this calculation. More...
 
Real finalNonlinearResidual ()
 Return the final nonlinear residual. More...
 
Real nonlinearNorm ()
 Return the last nonlinear norm. More...
 
void printAllVariableNorms (bool state)
 Force the printing of all variable norms after each solve. More...
 
void debuggingResiduals (bool state)
 
void setPredictor (std::shared_ptr< Predictor > predictor)
 
PredictorgetPredictor ()
 
TimeIntegratorgetTimeIntegrator ()
 
void setPCSide (MooseEnum pcs)
 
Moose::PCSideType getPCSide ()
 
void setMooseKSPNormType (MooseEnum kspnorm)
 
Moose::MooseKSPNormType getMooseKSPNormType ()
 
bool needMaterialOnSide (BoundaryID bnd_id, THREAD_ID tid) const
 Indicated whether this system needs material properties on boundaries. More...
 
bool needMaterialOnSide (SubdomainID subdomain_id, THREAD_ID tid) const
 Indicates whether this system needs material properties on internal sides. More...
 
bool doingDG () const
 Getter for _doing_dg. More...
 
bool hasSaveIn () const
 Weather or not the nonlinear system has save-ins. More...
 
bool hasDiagSaveIn () const
 Weather or not the nonlinear system has diagonal Jacobian save-ins. More...
 
virtual NumericVector< Number > & solution () override
 
virtual System & system () override
 Get the reference to the libMesh system. More...
 
virtual const System & system () const override
 
virtual NumericVector< Number > * solutionPreviousNewton () override
 
virtual void setPreviousNewtonSolution (const NumericVector< Number > &soln)
 
virtual unsigned int number ()
 Gets the number of this system. More...
 
virtual MooseMeshmesh ()
 
virtual SubProblemsubproblem ()
 
virtual DofMap & dofMap ()
 Gets the dof map. More...
 
virtual void initializeObjects ()
 Called only once, just before the solve begins so objects can do some precalculations. More...
 
virtual void update ()
 Update the system (doing libMesh magic) More...
 
virtual void copyOldSolutions ()
 Shifts the solutions backwards in time. More...
 
virtual NumericVector< Number > & solutionOld ()=0
 
virtual NumericVector< Number > & solutionOlder ()=0
 
virtual Number & duDotDu ()
 
virtual void saveOldSolutions ()
 Save the old and older solutions. More...
 
virtual void restoreOldSolutions ()
 Restore the old and older solutions when the saved solutions present. More...
 
virtual bool hasVector (const std::string &name)
 Check if the named vector exists in the system. More...
 
virtual NumericVector< Number > & getVector (const std::string &name)
 Get a raw NumericVector. More...
 
virtual void augmentSendList (std::vector< dof_id_type > &send_list)
 Will modify the send_list to add all of the extra ghosted dofs for this system. More...
 
virtual void addVariable (const std::string &var_name, const FEType &type, Real scale_factor, const std::set< SubdomainID > *const active_subdomains=NULL)
 Adds a variable to the system. More...
 
virtual bool hasVariable (const std::string &var_name)
 Query a system for a variable. More...
 
virtual bool hasScalarVariable (const std::string &var_name)
 
virtual bool isScalarVariable (unsigned int var_name)
 
virtual MooseVariablegetVariable (THREAD_ID tid, const std::string &var_name)
 Gets a reference to a variable of with specified name. More...
 
virtual MooseVariablegetVariable (THREAD_ID tid, unsigned int var_number)
 Gets a reference to a variable with specified number. More...
 
virtual MooseVariableScalargetScalarVariable (THREAD_ID tid, const std::string &var_name)
 Gets a reference to a scalar variable with specified number. More...
 
virtual MooseVariableScalargetScalarVariable (THREAD_ID tid, unsigned int var_number)
 Gets a reference to a variable with specified number. More...
 
virtual const std::set< SubdomainID > * getVariableBlocks (unsigned int var_number)
 Get the block where a variable of this system is defined. More...
 
virtual unsigned int nVariables ()
 Get the number of variables in this system. More...
 
virtual void addVariableToZeroOnResidual (std::string var_name)
 Adds this variable to the list of variables to be zeroed during each residual evaluation. More...
 
virtual void addVariableToZeroOnJacobian (std::string var_name)
 Adds this variable to the list of variables to be zeroed during each Jacobian evaluation. More...
 
virtual void zeroVariables (std::vector< std::string > &vars_to_be_zeroed)
 Zero out the solution for the list of variables passed in. More...
 
virtual void zeroVariablesForResidual ()
 Zero out the solution for the variables that were registered as needing to have their solutions zeroed on out on residual evaluation by a call to addVariableToZeroOnResidual() More...
 
virtual void zeroVariablesForJacobian ()
 Zero out the solution for the variables that were registered as needing to have their solutions zeroed on out on Jacobian evaluation by a call to addVariableToZeroOnResidual() More...
 
virtual Order getMinQuadratureOrder ()
 Get minimal quadrature order needed for integrating variables in this system. More...
 
virtual void prepare (THREAD_ID tid)
 Prepare the system for use. More...
 
virtual void prepareFace (THREAD_ID tid, bool resize_data)
 Prepare the system for use on sides. More...
 
virtual void prepareNeighbor (THREAD_ID tid)
 Prepare the system for use. More...
 
virtual void reinitElem (const Elem *elem, THREAD_ID tid)
 Reinit an element assembly info. More...
 
virtual void reinitElemFace (const Elem *elem, unsigned int side, BoundaryID bnd_id, THREAD_ID tid)
 Reinit assembly info for a side of an element. More...
 
virtual void reinitNeighborFace (const Elem *elem, unsigned int side, BoundaryID bnd_id, THREAD_ID tid)
 Compute the values of the variables at all the current points. More...
 
virtual void reinitNeighbor (const Elem *elem, THREAD_ID tid)
 Compute the values of the variables at all the current points. More...
 
virtual void reinitNode (const Node *node, THREAD_ID tid)
 Reinit nodal assembly info. More...
 
virtual void reinitNodeFace (const Node *node, BoundaryID bnd_id, THREAD_ID tid)
 Reinit nodal assembly info on a face. More...
 
virtual void reinitNodeNeighbor (const Node *node, THREAD_ID tid)
 Reinit nodal assembly info for neighbor node. More...
 
virtual void reinitNodes (const std::vector< dof_id_type > &nodes, THREAD_ID tid)
 Reinit variables at a set of nodes. More...
 
virtual void reinitNodesNeighbor (const std::vector< dof_id_type > &nodes, THREAD_ID tid)
 Reinit variables at a set of neighbor nodes. More...
 
virtual void reinitScalars (THREAD_ID tid)
 Reinit scalar varaibles. More...
 
virtual void addVariableToCopy (const std::string &dest_name, const std::string &source_name, const std::string &timestep)
 Add info about variable that will be copied. More...
 
const std::vector< MooseVariable * > & getVariables (THREAD_ID tid)
 
const std::vector< MooseVariableScalar * > & getScalarVariables (THREAD_ID tid)
 
const std::set< SubdomainID > & getSubdomainsForVar (unsigned int var_number) const
 
virtual void removeVector (const std::string &name)
 Remove a vector from the system with the given name. More...
 
virtual NumericVector< Number > & addVector (const std::string &vector_name, const bool project, const ParallelType type)
 Adds a solution length vector to the system. More...
 
virtual const std::string & name ()
 
virtual void addScalarVariable (const std::string &var_name, Order order, Real scale_factor, const std::set< SubdomainID > *const active_subdomains=NULL)
 Adds a scalar variable. More...
 
const std::vector< VariableName > & getVariableNames () const
 
virtual void computeVariables (const NumericVector< Number > &)
 
void copyVars (ExodusII_IO &io)
 
virtual void copySolutionsBackwards ()
 Copy current solution into old and older. More...
 
void checkKernelCoverage (const std::set< SubdomainID > &mesh_subdomains) const
 
bool containsTimeKernel ()
 
const KernelWarehousegetKernelWarehouse ()
 Access functions to Warehouses from outside NonlinearSystemBase. More...
 
const KernelWarehousegetTimeKernelWarehouse ()
 
const KernelWarehousegetNonTimeKernelWarehouse ()
 
const KernelWarehousegetEigenKernelWarehouse ()
 
const KernelWarehousegetNonEigenKernelWarehouse ()
 
const MooseObjectWarehouse< DGKernel > & getDGKernelWarehouse ()
 
const MooseObjectWarehouse< InterfaceKernel > & getInterfaceKernelWarehouse ()
 
const MooseObjectWarehouse< DiracKernel > & getDiracKernelWarehouse ()
 
const MooseObjectWarehouse< NodalKernel > & getNodalKernelWarehouse (THREAD_ID tid)
 
const MooseObjectWarehouse< IntegratedBC > & getIntegratedBCWarehouse ()
 
const MooseObjectWarehouse< ElementDamper > & getElementDamperWarehouse ()
 
const MooseObjectWarehouse< NodalDamper > & getNodalDamperWarehouse ()
 
const ConstraintWarehousegetConstraintWarehouse ()
 

Public Attributes

unsigned int _num_residual_evaluations
 
FEProblemBase_fe_problem
 
System & _sys
 
Real _last_rnorm
 
Real _last_nl_rnorm
 
Real _l_abs_step_tol
 
Real _initial_residual_before_preset_bcs
 
Real _initial_residual_after_preset_bcs
 
std::vector< unsigned int > _current_l_its
 
unsigned int _current_nl_its
 
bool _compute_initial_residual_before_preset_bcs
 
const ConsoleStream _console
 An instance of helper class to write streams to the Console objects. More...
 

Protected Member Functions

void computeResidualInternal (Moose::KernelType type=Moose::KT_ALL)
 Compute the residual. More...
 
void computeNodalBCs (NumericVector< Number > &residual, Moose::KernelType type=Moose::KT_ALL)
 Enforces nodal boundary conditions. More...
 
void computeJacobianInternal (SparseMatrix< Number > &jacobian, Moose::KernelType kernel_type)
 
void computeDiracContributions (SparseMatrix< Number > *jacobian=NULL)
 
void computeScalarKernelsJacobians (SparseMatrix< Number > &jacobian)
 
void enforceNodalConstraintsResidual (NumericVector< Number > &residual)
 Enforce nodal constraints. More...
 
void enforceNodalConstraintsJacobian (SparseMatrix< Number > &jacobian)
 
void getNodeDofs (dof_id_type node_id, std::vector< dof_id_type > &dofs)
 

Protected Attributes

const NumericVector< Number > * _current_solution
 solution vector from nonlinear solver More...
 
NumericVector< Number > * _residual_ghosted
 ghosted form of the residual More...
 
NumericVector< Number > & _serialized_solution
 Serialized version of the solution vector. More...
 
NumericVector< Number > * _solution_previous_nl
 Solution vector of the previous nonlinear iterate. More...
 
NumericVector< Number > & _residual_copy
 Copy of the residual vector. More...
 
std::shared_ptr< TimeIntegrator_time_integrator
 Time integrator. More...
 
NumericVector< Number > * _u_dot
 solution vector for u^dot More...
 
Number _du_dot_du
 \( {du^dot}\over{du} \) More...
 
NumericVector< Number > * _Re_time
 residual vector for time contributions More...
 
NumericVector< Number > * _Re_non_time
 residual vector for non-time contributions More...
 
MooseObjectWarehouse< DiracKernel_dirac_kernels
 Dirac Kernel storage for each thread. More...
 
MooseObjectWarehouse< ElementDamper_element_dampers
 Element Dampers for each thread. More...
 
MooseObjectWarehouse< NodalDamper_nodal_dampers
 Nodal Dampers for each thread. More...
 
MooseObjectWarehouse< GeneralDamper_general_dampers
 General Dampers. More...
 
MooseObjectWarehouse< NodalKernel_nodal_kernels
 NodalKernels for each thread. More...
 
MooseObjectWarehouseBase< Split_splits
 Decomposition splits. More...
 
ConstraintWarehouse _constraints
 Constraints storage object. More...
 
NumericVector< Number > * _increment_vec
 increment vector More...
 
std::shared_ptr< MoosePreconditioner_preconditioner
 Preconditioner. More...
 
Moose::PCSideType _pc_side
 Preconditioning side. More...
 
Moose::MooseKSPNormType _ksp_norm
 KSP norm type. More...
 
bool _use_finite_differenced_preconditioner
 Whether or not to use a finite differenced preconditioner. More...
 
MatFDColoring _fdcoloring
 
bool _have_decomposition
 Whether or not the system can be decomposed into splits. More...
 
std::string _decomposition_split
 Name of the top-level split of the decomposition. More...
 
bool _use_field_split_preconditioner
 Whether or not to use a FieldSplitPreconditioner matrix based on the decomposition. More...
 
bool _add_implicit_geometric_coupling_entries_to_jacobian
 Whether or not to add implicit geometric couplings to the Jacobian for FDP. More...
 
bool _assemble_constraints_separately
 Whether or not to assemble the residual and Jacobian after the application of each constraint. More...
 
bool _need_serialized_solution
 Whether or not a copy of the residual needs to be made. More...
 
bool _need_residual_copy
 Whether or not a copy of the residual needs to be made. More...
 
bool _need_residual_ghosted
 Whether or not a ghosted copy of the residual needs to be made. More...
 
bool _debugging_residuals
 true if debugging residuals More...
 
bool _doing_dg
 true if DG is active (optimization reasons) More...
 
std::vector< std::string > _vecs_to_zero_for_residual
 vectors that will be zeroed before a residual computation More...
 
unsigned int _n_iters
 
unsigned int _n_linear_iters
 
unsigned int _n_residual_evaluations
 Total number of residual evaluations that have been performed. More...
 
Real _final_residual
 
std::shared_ptr< Predictor_predictor
 If predictor is active, this is non-NULL. More...
 
bool _computing_initial_residual
 
bool _print_all_var_norms
 
bool _has_save_in
 If there is any Kernel or IntegratedBC having save_in. More...
 
bool _has_diag_save_in
 If there is any Kernel or IntegratedBC having diag_save_in. More...
 
bool _has_nodalbc_save_in
 If there is a nodal BC having save_in. More...
 
bool _has_nodalbc_diag_save_in
 If there is a nodal BC having diag_save_in. More...
 
std::vector< dof_id_type > _var_all_dof_indices
 
SubProblem_subproblem
 
MooseApp_app
 
Factory_factory
 
MooseMesh_mesh
 
std::string _name
 The name of this system. More...
 
std::vector< VariableWarehouse_vars
 Variable warehouses (one for each thread) More...
 
std::map< unsigned int, std::set< SubdomainID > > _var_map
 Map of variables (variable id -> array of subdomains where it lives) More...
 
std::vector< std::string > _vars_to_be_zeroed_on_residual
 
std::vector< std::string > _vars_to_be_zeroed_on_jacobian
 
NumericVector< Number > * _dummy_vec
 
NumericVector< Real > * _saved_old
 
NumericVector< Real > * _saved_older
 
Moose::VarKindType _var_kind
 default kind of variables in this system More...
 
std::vector< VarCopyInfo_var_to_copy
 
KernelWarehouse _kernels
 
MooseObjectWarehouse< ScalarKernel_scalar_kernels
 
MooseObjectWarehouse< ScalarKernel_time_scalar_kernels
 
MooseObjectWarehouse< ScalarKernel_non_time_scalar_kernels
 
MooseObjectWarehouse< DGKernel_dg_kernels
 
MooseObjectWarehouse< InterfaceKernel_interface_kernels
 
KernelWarehouse _time_kernels
 
KernelWarehouse _non_time_kernels
 
KernelWarehouse _eigen_kernels
 
KernelWarehouse _non_eigen_kernels
 
MooseObjectWarehouse< IntegratedBC_integrated_bcs
 
MooseObjectWarehouse< NodalBC_nodal_bcs
 
MooseObjectWarehouse< PresetNodalBC_preset_nodal_bcs
 

Detailed Description

Nonlinear system to be solved.

It is a part of FEProblemBase ;-)

Definition at line 60 of file NonlinearSystemBase.h.

Constructor & Destructor Documentation

EXTERN_C_END NonlinearSystemBase::NonlinearSystemBase ( FEProblemBase problem,
System &  sys,
const std::string &  name 
)

Definition at line 98 of file NonlinearSystemBase.C.

101  : SystemBase(fe_problem, name, Moose::VAR_NONLINEAR),
102  ConsoleStreamInterface(fe_problem.getMooseApp()),
103  _fe_problem(fe_problem),
104  _sys(sys),
105  _last_rnorm(0.),
106  _last_nl_rnorm(0.),
107  _l_abs_step_tol(1e-10),
110  _current_nl_its(0),
112  _current_solution(NULL),
113  _residual_ghosted(NULL),
114  _serialized_solution(*NumericVector<Number>::build(_communicator).release()),
115  _solution_previous_nl(NULL),
116  _residual_copy(*NumericVector<Number>::build(_communicator).release()),
117  _u_dot(&addVector("u_dot", true, GHOSTED)),
118  _Re_time(NULL),
119  _Re_non_time(&addVector("Re_non_time", false, GHOSTED)),
120  _scalar_kernels(/*threaded=*/false),
121  _nodal_bcs(/*threaded=*/false),
122  _preset_nodal_bcs(/*threaded=*/false),
123  _splits(/*threaded=*/false),
124  _increment_vec(NULL),
128  _have_decomposition(false),
133  _need_residual_copy(false),
134  _need_residual_ghosted(false),
135  _debugging_residuals(false),
136  _doing_dg(false),
137  _n_iters(0),
138  _n_linear_iters(0),
140  _final_residual(0.),
142  _print_all_var_norms(false),
143  _has_save_in(false),
144  _has_diag_save_in(false),
145  _has_nodalbc_save_in(false),
147 {
148 }
NumericVector< Number > * _Re_time
residual vector for time contributions
bool _debugging_residuals
true if debugging residuals
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
bool _assemble_constraints_separately
Whether or not to assemble the residual and Jacobian after the application of each constraint...
virtual NumericVector< Number > & addVector(const std::string &vector_name, const bool project, const ParallelType type)
Adds a solution length vector to the system.
Definition: SystemBase.C:490
bool _has_nodalbc_diag_save_in
If there is a nodal BC having diag_save_in.
virtual const std::string & name()
Definition: SystemBase.h:453
MooseObjectWarehouse< NodalBC > _nodal_bcs
MooseObjectWarehouseBase< Split > _splits
Decomposition splits.
NumericVector< Number > & _serialized_solution
Serialized version of the solution vector.
bool _has_nodalbc_save_in
If there is a nodal BC having save_in.
Moose::MooseKSPNormType _ksp_norm
KSP norm type.
bool _has_save_in
If there is any Kernel or IntegratedBC having save_in.
bool _have_decomposition
Whether or not the system can be decomposed into splits.
bool _need_residual_ghosted
Whether or not a ghosted copy of the residual needs to be made.
NumericVector< Number > & _residual_copy
Copy of the residual vector.
bool _doing_dg
true if DG is active (optimization reasons)
Use whatever we have in PETSc.
Definition: MooseTypes.h:227
FEProblemBase & _fe_problem
ConsoleStreamInterface(MooseApp &app)
A class for providing a helper stream object for writting message to all the Output objects...
bool _use_finite_differenced_preconditioner
Whether or not to use a finite differenced preconditioner.
MooseObjectWarehouse< ScalarKernel > _scalar_kernels
bool _need_serialized_solution
Whether or not a copy of the residual needs to be made.
bool _add_implicit_geometric_coupling_entries_to_jacobian
Whether or not to add implicit geometric couplings to the Jacobian for FDP.
bool _compute_initial_residual_before_preset_bcs
unsigned int _n_residual_evaluations
Total number of residual evaluations that have been performed.
SystemBase(SubProblem &subproblem, const std::string &name, Moose::VarKindType var_kind)
Definition: SystemBase.C:84
bool _has_diag_save_in
If there is any Kernel or IntegratedBC having diag_save_in.
bool _need_residual_copy
Whether or not a copy of the residual needs to be made.
NumericVector< Number > * _solution_previous_nl
Solution vector of the previous nonlinear iterate.
Moose::PCSideType _pc_side
Preconditioning side.
const NumericVector< Number > * _current_solution
solution vector from nonlinear solver
NumericVector< Number > * _residual_ghosted
ghosted form of the residual
NumericVector< Number > * _increment_vec
increment vector
bool _use_field_split_preconditioner
Whether or not to use a FieldSplitPreconditioner matrix based on the decomposition.
NumericVector< Number > * _u_dot
solution vector for u^dot
MooseObjectWarehouse< PresetNodalBC > _preset_nodal_bcs
NonlinearSystemBase::~NonlinearSystemBase ( )
virtual

Definition at line 150 of file NonlinearSystemBase.C.

151 {
152  delete &_serialized_solution;
153  delete &_residual_copy;
154 }
NumericVector< Number > & _serialized_solution
Serialized version of the solution vector.
NumericVector< Number > & _residual_copy
Copy of the residual vector.

Member Function Documentation

void NonlinearSystemBase::addBoundaryCondition ( const std::string &  bc_name,
const std::string &  name,
InputParameters  parameters 
)

Adds a boundary condition.

Parameters
bc_nameThe type of the boundary condition
nameThe name of the boundary condition
parametersBoundary condition parameters

Definition at line 344 of file NonlinearSystemBase.C.

347 {
348  // ThreadID
349  THREAD_ID tid = 0;
350 
351  // Create the object
352  std::shared_ptr<BoundaryCondition> bc =
353  _factory.create<BoundaryCondition>(bc_name, name, parameters, tid);
354 
355  // Active BoundaryIDs for the object
356  const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
357  _vars[tid].addBoundaryVar(boundary_ids, &bc->variable());
358 
359  // Cast to the various types of BCs
360  std::shared_ptr<NodalBC> nbc = std::dynamic_pointer_cast<NodalBC>(bc);
361  std::shared_ptr<IntegratedBC> ibc = std::dynamic_pointer_cast<IntegratedBC>(bc);
362 
363  // NodalBC
364  if (nbc)
365  {
366  _nodal_bcs.addObject(nbc);
367  _vars[tid].addBoundaryVars(boundary_ids, nbc->getCoupledVars());
368 
369  if (parameters.get<std::vector<AuxVariableName>>("save_in").size() > 0)
370  _has_nodalbc_save_in = true;
371  if (parameters.get<std::vector<AuxVariableName>>("diag_save_in").size() > 0)
373 
374  // PresetNodalBC
375  std::shared_ptr<PresetNodalBC> pnbc = std::dynamic_pointer_cast<PresetNodalBC>(bc);
376  if (pnbc)
378  }
379 
380  // IntegratedBC
381  else if (ibc)
382  {
383  _integrated_bcs.addObject(ibc, tid);
384  _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
385 
386  if (parameters.get<std::vector<AuxVariableName>>("save_in").size() > 0)
387  _has_save_in = true;
388  if (parameters.get<std::vector<AuxVariableName>>("diag_save_in").size() > 0)
389  _has_diag_save_in = true;
390 
391  for (tid = 1; tid < libMesh::n_threads(); tid++)
392  {
393  // Create the object
394  bc = _factory.create<BoundaryCondition>(bc_name, name, parameters, tid);
395 
396  // Active BoundaryIDs for the object
397  const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
398  _vars[tid].addBoundaryVar(boundary_ids, &bc->variable());
399 
400  ibc = std::static_pointer_cast<IntegratedBC>(bc);
401 
402  _integrated_bcs.addObject(ibc, tid);
403  _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
404  }
405  }
406 
407  else
408  mooseError("Unknown BoundaryCondition type for object named ", bc->name());
409 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
bool _has_nodalbc_diag_save_in
If there is a nodal BC having diag_save_in.
virtual const std::string & name()
Definition: SystemBase.h:453
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
MooseObjectWarehouse< NodalBC > _nodal_bcs
Factory & _factory
Definition: SystemBase.h:481
bool _has_nodalbc_save_in
If there is a nodal BC having save_in.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
Base class for deriving any boundary condition that works at nodes.
Definition: NodalBC.h:38
bool _has_save_in
If there is any Kernel or IntegratedBC having save_in.
Base class for deriving any boundary condition of a integrated type.
Definition: IntegratedBC.h:33
Base class for creating new types of boundary conditions.
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
bool _has_diag_save_in
If there is any Kernel or IntegratedBC having diag_save_in.
MooseObjectWarehouse< IntegratedBC > _integrated_bcs
unsigned int THREAD_ID
Definition: MooseTypes.h:79
MooseObjectWarehouse< PresetNodalBC > _preset_nodal_bcs
void NonlinearSystemBase::addConstraint ( const std::string &  c_name,
const std::string &  name,
InputParameters  parameters 
)

Adds a Constraint.

Parameters
c_nameThe type of the constraint
nameThe name of the constraint
parametersConstraint parameters

Definition at line 412 of file NonlinearSystemBase.C.

415 {
416  std::shared_ptr<Constraint> constraint = _factory.create<Constraint>(c_name, name, parameters);
417  _constraints.addObject(constraint);
418 
419  if (constraint && constraint->addCouplingEntriesToJacobian())
421 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
void addImplicitGeometricCouplingEntriesToJacobian(bool add=true)
If called with true this will add entries into the jacobian to link together degrees of freedom that ...
virtual const std::string & name()
Definition: SystemBase.h:453
Base class for all Constraint types.
Definition: Constraint.h:42
Factory & _factory
Definition: SystemBase.h:481
void addObject(std::shared_ptr< Constraint > object, THREAD_ID tid=0)
Add Constraint object to the warehouse.
ConstraintWarehouse _constraints
Constraints storage object.
void NonlinearSystemBase::addDamper ( const std::string &  damper_name,
const std::string &  name,
InputParameters  parameters 
)

Adds a damper.

Parameters
damper_nameThe type of the damper
nameThe name of the damper
parametersDamper parameters

Definition at line 472 of file NonlinearSystemBase.C.

475 {
476  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
477  {
478  std::shared_ptr<Damper> damper = _factory.create<Damper>(damper_name, name, parameters, tid);
479 
480  // Attempt to cast to the damper types
481  std::shared_ptr<ElementDamper> ed = std::dynamic_pointer_cast<ElementDamper>(damper);
482  std::shared_ptr<NodalDamper> nd = std::dynamic_pointer_cast<NodalDamper>(damper);
483  std::shared_ptr<GeneralDamper> gd = std::dynamic_pointer_cast<GeneralDamper>(damper);
484 
485  if (gd)
486  {
488  break; // not threaded
489  }
490  else if (ed)
491  _element_dampers.addObject(ed, tid);
492  else if (nd)
493  _nodal_dampers.addObject(nd, tid);
494  else
495  mooseError("Invalid damper type");
496  }
497 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
Base class for deriving general dampers.
Definition: GeneralDamper.h:34
virtual const std::string & name()
Definition: SystemBase.h:453
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
Factory & _factory
Definition: SystemBase.h:481
MooseObjectWarehouse< NodalDamper > _nodal_dampers
Nodal Dampers for each thread.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
Base class for deriving nodal dampers.
Definition: NodalDamper.h:37
Base class for deriving element dampers.
Definition: ElementDamper.h:37
MooseObjectWarehouse< ElementDamper > _element_dampers
Element Dampers for each thread.
Base class for deriving dampers.
Definition: Damper.h:35
MooseObjectWarehouse< GeneralDamper > _general_dampers
General Dampers.
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void NonlinearSystemBase::addDGKernel ( std::string  dg_kernel_name,
const std::string &  name,
InputParameters  parameters 
)

Adds a DG kernel.

Parameters
dg_kernel_nameThe type of the DG kernel
nameThe name of the DG kernel
parametersDG kernel parameters

Definition at line 437 of file NonlinearSystemBase.C.

440 {
441  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
442  {
443  std::shared_ptr<DGKernel> dg_kernel =
444  _factory.create<DGKernel>(dg_kernel_name, name, parameters, tid);
445  _dg_kernels.addObject(dg_kernel, tid);
446  }
447 
448  _doing_dg = true;
449 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
virtual const std::string & name()
Definition: SystemBase.h:453
Factory & _factory
Definition: SystemBase.h:481
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
bool _doing_dg
true if DG is active (optimization reasons)
The DGKernel class is responsible for calculating the residuals for various physics on internal sides...
Definition: DGKernel.h:47
MooseObjectWarehouse< DGKernel > _dg_kernels
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void NonlinearSystemBase::addDiracKernel ( const std::string &  kernel_name,
const std::string &  name,
InputParameters  parameters 
)

Adds a Dirac kernel.

Parameters
kernel_nameThe type of the dirac kernel
nameThe name of the Dirac kernel
parametersDirac kernel parameters

Definition at line 424 of file NonlinearSystemBase.C.

427 {
428  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
429  {
430  std::shared_ptr<DiracKernel> kernel =
431  _factory.create<DiracKernel>(kernel_name, name, parameters, tid);
432  _dirac_kernels.addObject(kernel, tid);
433  }
434 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
virtual const std::string & name()
Definition: SystemBase.h:453
Factory & _factory
Definition: SystemBase.h:481
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
MooseObjectWarehouse< DiracKernel > _dirac_kernels
Dirac Kernel storage for each thread.
A DiracKernel is used when you need to add contributions to the residual by means of multiplying some...
Definition: DiracKernel.h:50
unsigned int THREAD_ID
Definition: MooseTypes.h:79
virtual void NonlinearSystemBase::addEigenKernels ( std::shared_ptr< KernelBase ,
THREAD_ID   
)
inlinevirtual

Reimplemented in NonlinearEigenSystem.

Definition at line 126 of file NonlinearSystemBase.h.

Referenced by addKernel().

126 {};
void NonlinearSystemBase::addExtraVectors ( )
overridevirtual

Method called during initialSetup to add extra system vector if they are required by the simulation.

Reimplemented from SystemBase.

Definition at line 179 of file NonlinearSystemBase.C.

180 {
182  _solution_previous_nl = &addVector("u_previous_newton", true, GHOSTED);
183 }
virtual NumericVector< Number > & addVector(const std::string &vector_name, const bool project, const ParallelType type)
Adds a solution length vector to the system.
Definition: SystemBase.C:490
FEProblemBase & _fe_problem
void needsPreviousNewtonIteration(bool state)
Set a flag that indicated that user required values for the previous Newton iterate.
NumericVector< Number > * _solution_previous_nl
Solution vector of the previous nonlinear iterate.
void NonlinearSystemBase::addImplicitGeometricCouplingEntries ( SparseMatrix< Number > &  jacobian,
GeometricSearchData geom_search_data 
)

Adds entries to the Jacobian in the correct positions for couplings coming from dofs being coupled that are related geometrically (i.e.

near each other across a gap).

Definition at line 1441 of file NonlinearSystemBase.C.

Referenced by computeJacobianInternal().

1443 {
1444  std::map<dof_id_type, std::vector<dof_id_type>> graph;
1445 
1446  findImplicitGeometricCouplingEntries(geom_search_data, graph);
1447 
1448  for (const auto & it : graph)
1449  {
1450  dof_id_type dof = it.first;
1451  const std::vector<dof_id_type> & row = it.second;
1452 
1453  for (const auto & coupled_dof : row)
1454  jacobian.add(dof, coupled_dof, 0);
1455  }
1456 }
void findImplicitGeometricCouplingEntries(GeometricSearchData &geom_search_data, std::map< dof_id_type, std::vector< dof_id_type >> &graph)
Finds the implicit sparsity graph between geometrically related dofs.
void NonlinearSystemBase::addImplicitGeometricCouplingEntriesToJacobian ( bool  add = true)
inline

If called with true this will add entries into the jacobian to link together degrees of freedom that are found to be related through the geometric search system.

These entries are really only used by the Finite Difference Preconditioner and the constraint system right now.

Definition at line 382 of file NonlinearSystemBase.h.

Referenced by addConstraint(), and FiniteDifferencePreconditioner::FiniteDifferencePreconditioner().

383  {
385  }
bool _add_implicit_geometric_coupling_entries_to_jacobian
Whether or not to add implicit geometric couplings to the Jacobian for FDP.
void NonlinearSystemBase::addInterfaceKernel ( std::string  interface_kernel_name,
const std::string &  name,
InputParameters  parameters 
)

Adds an interface kernel.

Parameters
interface_kernel_nameThe type of the interface kernel
nameThe name of the interface kernel
parametersinterface kernel parameters

Definition at line 452 of file NonlinearSystemBase.C.

455 {
456  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
457  {
458  std::shared_ptr<InterfaceKernel> interface_kernel =
459  _factory.create<InterfaceKernel>(interface_kernel_name, name, parameters, tid);
460 
461  const std::set<BoundaryID> & boundary_ids = interface_kernel->boundaryIDs();
462  _vars[tid].addBoundaryVar(boundary_ids, &interface_kernel->variable());
463 
464  _interface_kernels.addObject(interface_kernel, tid);
465  _vars[tid].addBoundaryVars(boundary_ids, interface_kernel->getCoupledVars());
466  }
467 
468  _doing_dg = true;
469 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
virtual const std::set< BoundaryID > & boundaryIDs() const
Return the boundary IDs for this object.
virtual const std::string & name()
Definition: SystemBase.h:453
Factory & _factory
Definition: SystemBase.h:481
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
bool _doing_dg
true if DG is active (optimization reasons)
MooseObjectWarehouse< InterfaceKernel > _interface_kernels
InterfaceKernel is responsible for interfacing physics across subdomains.
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void NonlinearSystemBase::addKernel ( const std::string &  kernel_name,
const std::string &  name,
InputParameters  parameters 
)
virtual

Adds a kernel.

Parameters
kernel_nameThe type of the kernel
nameThe name of the kernel
parametersKernel parameters

Reimplemented in MooseEigenSystem.

Definition at line 279 of file NonlinearSystemBase.C.

282 {
283  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
284  {
285  // Create the kernel object via the factory and add to warehouse
286  std::shared_ptr<KernelBase> kernel =
287  _factory.create<KernelBase>(kernel_name, name, parameters, tid);
288  _kernels.addObject(kernel, tid);
289 
290  // Store time/non-time kernels separately
291  std::shared_ptr<TimeKernel> t_kernel = std::dynamic_pointer_cast<TimeKernel>(kernel);
292  if (t_kernel)
293  _time_kernels.addObject(kernel, tid);
294  else
295  _non_time_kernels.addObject(kernel, tid);
296 
297  addEigenKernels(kernel, tid);
298  }
299 
300  if (parameters.get<std::vector<AuxVariableName>>("save_in").size() > 0)
301  _has_save_in = true;
302  if (parameters.get<std::vector<AuxVariableName>>("diag_save_in").size() > 0)
303  _has_diag_save_in = true;
304 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
virtual const std::string & name()
Definition: SystemBase.h:453
Factory & _factory
Definition: SystemBase.h:481
bool _has_save_in
If there is any Kernel or IntegratedBC having save_in.
This is the common base class for the two main kernel types implemented in MOOSE, EigenKernel and Ker...
Definition: KernelBase.h:47
KernelWarehouse _kernels
bool _has_diag_save_in
If there is any Kernel or IntegratedBC having diag_save_in.
All time kernels should inherit from this class.
Definition: TimeKernel.h:30
void addObject(std::shared_ptr< KernelBase > object, THREAD_ID tid=0) override
Add Kernel to the storage structure.
KernelWarehouse _time_kernels
virtual void addEigenKernels(std::shared_ptr< KernelBase >, THREAD_ID)
unsigned int THREAD_ID
Definition: MooseTypes.h:79
KernelWarehouse _non_time_kernels
void NonlinearSystemBase::addNodalKernel ( const std::string &  kernel_name,
const std::string &  name,
InputParameters  parameters 
)
virtual

Adds a NodalKernel.

Parameters
kernel_nameThe type of the nodal kernel
nameThe name of the kernel
parametersKernel parameters

Definition at line 307 of file NonlinearSystemBase.C.

310 {
311  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
312  {
313  // Create the kernel object via the factory and add to the warehouse
314  std::shared_ptr<NodalKernel> kernel =
315  _factory.create<NodalKernel>(kernel_name, name, parameters, tid);
316  _nodal_kernels.addObject(kernel, tid);
317  }
318 
319  if (parameters.get<std::vector<AuxVariableName>>("save_in").size() > 0)
320  _has_save_in = true;
321  if (parameters.get<std::vector<AuxVariableName>>("diag_save_in").size() > 0)
322  _has_diag_save_in = true;
323 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
virtual const std::string & name()
Definition: SystemBase.h:453
Factory & _factory
Definition: SystemBase.h:481
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
bool _has_save_in
If there is any Kernel or IntegratedBC having save_in.
MooseObjectWarehouse< NodalKernel > _nodal_kernels
NodalKernels for each thread.
bool _has_diag_save_in
If there is any Kernel or IntegratedBC having diag_save_in.
Base class for creating new types of boundary conditions.
Definition: NodalKernel.h:50
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void NonlinearSystemBase::addScalarKernel ( const std::string &  kernel_name,
const std::string &  name,
InputParameters  parameters 
)

Adds a scalar kernel.

Parameters
kernel_nameThe type of the kernel
nameThe name of the kernel
parametersKernel parameters

Definition at line 326 of file NonlinearSystemBase.C.

329 {
330  std::shared_ptr<ScalarKernel> kernel =
331  _factory.create<ScalarKernel>(kernel_name, name, parameters);
332  _scalar_kernels.addObject(kernel);
333 
334  // Store time/non-time ScalarKernels separately
335  ODETimeKernel * t_kernel = dynamic_cast<ODETimeKernel *>(kernel.get());
336 
337  if (t_kernel)
339  else
341 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
virtual const std::string & name()
Definition: SystemBase.h:453
Factory & _factory
Definition: SystemBase.h:481
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
MooseObjectWarehouse< ScalarKernel > _time_scalar_kernels
MooseObjectWarehouse< ScalarKernel > _non_time_scalar_kernels
MooseObjectWarehouse< ScalarKernel > _scalar_kernels
Base class for ODEKernels that contribute to the time residual vector.
Definition: ODETimeKernel.h:30
void SystemBase::addScalarVariable ( const std::string &  var_name,
Order  order,
Real  scale_factor,
const std::set< SubdomainID > *const  active_subdomains = NULL 
)
virtualinherited

Adds a scalar variable.

Parameters
var_nameThe name of the variable
orderThe order of the variable
scale_factorThe scaling factor to be used with this scalar variable

Definition at line 530 of file SystemBase.C.

Referenced by DisplacedProblem::addAuxScalarVariable(), and DisplacedProblem::addScalarVariable().

534 {
535  FEType type(order, SCALAR);
536  unsigned int var_num = system().add_variable(var_name, type, active_subdomains);
537  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
538  {
539  // FIXME: we cannot refer fetype in libMesh at this point, so we will just make a copy in
540  // MooseVariableBase.
541  MooseVariableScalar * var =
542  new MooseVariableScalar(var_num, type, *this, _subproblem.assembly(tid), _var_kind);
543  var->scalingFactor(scale_factor);
544  _vars[tid].add(var_name, var);
545  }
546  if (active_subdomains == NULL)
547  _var_map[var_num] = std::set<SubdomainID>();
548  else
549  for (std::set<SubdomainID>::iterator it = active_subdomains->begin();
550  it != active_subdomains->end();
551  ++it)
552  _var_map[var_num].insert(*it);
553 }
virtual Assembly & assembly(THREAD_ID tid)=0
SubProblem & _subproblem
Definition: SystemBase.h:478
Moose::VarKindType _var_kind
default kind of variables in this system
Definition: SystemBase.h:504
virtual System & system()=0
Get the reference to the libMesh system.
std::map< unsigned int, std::set< SubdomainID > > _var_map
Map of variables (variable id -> array of subdomains where it lives)
Definition: SystemBase.h:490
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
MatType type
Class for scalar variables (they are different).
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void scalingFactor(Real factor)
Set the scaling factor for this variable.
void NonlinearSystemBase::addSplit ( const std::string &  split_name,
const std::string &  name,
InputParameters  parameters 
)

Adds a split.

Parameters
split_nameThe type of the split
nameThe name of the split
parametersSplit parameters

Definition at line 500 of file NonlinearSystemBase.C.

503 {
504  std::shared_ptr<Split> split = _factory.create<Split>(split_name, name, parameters);
505  _splits.addObject(split);
506 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
Base class for split-based preconditioners.
Definition: Split.h:30
virtual const std::string & name()
Definition: SystemBase.h:453
Factory & _factory
Definition: SystemBase.h:481
MooseObjectWarehouseBase< Split > _splits
Decomposition splits.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0)
Adds an object to the storage structure.
void NonlinearSystemBase::addTimeIntegrator ( const std::string &  type,
const std::string &  name,
InputParameters  parameters 
)

Add a time integrator.

Parameters
typeType of the integrator
nameThe name of the integrator
parametersIntegrator params

Definition at line 268 of file NonlinearSystemBase.C.

271 {
272  parameters.set<SystemBase *>("_sys") = this;
273 
274  std::shared_ptr<TimeIntegrator> ti = _factory.create<TimeIntegrator>(type, name, parameters);
275  _time_integrator = ti;
276 }
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, InputParameters parameters, THREAD_ID tid=0, bool print_deprecated=true)
Build an object (must be registered) - THIS METHOD IS DEPRECATED (Use create<T>()) ...
Definition: Factory.C:46
virtual const std::string & name()
Definition: SystemBase.h:453
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
Factory & _factory
Definition: SystemBase.h:481
Base class for a system (of equations)
Definition: SystemBase.h:91
std::shared_ptr< TimeIntegrator > _time_integrator
Time integrator.
MatType type
Base class for time integrators.
void SystemBase::addVariable ( const std::string &  var_name,
const FEType &  type,
Real  scale_factor,
const std::set< SubdomainID > *const  active_subdomains = NULL 
)
virtualinherited

Adds a variable to the system.

Parameters
var_namename of the variable
typeFE type of the variable
scale_factorthe scaling factor for the variable
active_subdomainsa list of subdomain ids this variable is active on

Reimplemented in AuxiliarySystem.

Definition at line 500 of file SystemBase.C.

Referenced by DisplacedProblem::addAuxVariable(), AuxiliarySystem::addVariable(), and DisplacedProblem::addVariable().

504 {
505  unsigned int var_num = system().add_variable(var_name, type, active_subdomains);
506  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
507  {
508  // FIXME: we cannot refer fetype in libMesh at this point, so we will just make a copy in
509  // MooseVariableBase.
510  MooseVariableBase * var;
511  if (type == FEType(0, MONOMIAL))
512  var = new MooseVariableConstMonomial(
513  var_num, type, *this, _subproblem.assembly(tid), _var_kind);
514  else
515  var = new MooseVariable(var_num, type, *this, _subproblem.assembly(tid), _var_kind);
516 
517  var->scalingFactor(scale_factor);
518  _vars[tid].add(var_name, var);
519  }
520  if (active_subdomains == NULL)
521  _var_map[var_num] = std::set<SubdomainID>();
522  else
523  for (std::set<SubdomainID>::iterator it = active_subdomains->begin();
524  it != active_subdomains->end();
525  ++it)
526  _var_map[var_num].insert(*it);
527 }
Class for stuff related to variables.
Definition: MooseVariable.h:43
virtual Assembly & assembly(THREAD_ID tid)=0
SubProblem & _subproblem
Definition: SystemBase.h:478
Moose::VarKindType _var_kind
default kind of variables in this system
Definition: SystemBase.h:504
virtual System & system()=0
Get the reference to the libMesh system.
std::map< unsigned int, std::set< SubdomainID > > _var_map
Map of variables (variable id -> array of subdomains where it lives)
Definition: SystemBase.h:490
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
MatType type
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void scalingFactor(Real factor)
Set the scaling factor for this variable.
void SystemBase::addVariableToCopy ( const std::string &  dest_name,
const std::string &  source_name,
const std::string &  timestep 
)
virtualinherited

Add info about variable that will be copied.

Parameters
dest_nameName of the nodal variable being used for copying into (name is from the exodusII file)
source_nameName of the nodal variable being used for copying from (name is from the exodusII file)
timestepTimestep in the file being used

Definition at line 616 of file SystemBase.C.

Referenced by CopyNodalVarsAction::act().

619 {
620  _var_to_copy.push_back(VarCopyInfo(dest_name, source_name, timestep));
621 }
std::vector< VarCopyInfo > _var_to_copy
Definition: SystemBase.h:506
Information about variables that will be copied.
Definition: SystemBase.h:73
void SystemBase::addVariableToZeroOnJacobian ( std::string  var_name)
virtualinherited

Adds this variable to the list of variables to be zeroed during each Jacobian evaluation.

Parameters
var_nameThe name of the variable to be zeroed.

Reimplemented in DisplacedSystem.

Definition at line 156 of file SystemBase.C.

Referenced by DisplacedSystem::addVariableToZeroOnJacobian(), DGKernel::DGKernel(), IntegratedBC::IntegratedBC(), InterfaceKernel::InterfaceKernel(), KernelBase::KernelBase(), NodalBC::NodalBC(), and NodalKernel::NodalKernel().

157 {
158  _vars_to_be_zeroed_on_jacobian.push_back(var_name);
159 }
std::vector< std::string > _vars_to_be_zeroed_on_jacobian
Definition: SystemBase.h:493
void SystemBase::addVariableToZeroOnResidual ( std::string  var_name)
virtualinherited

Adds this variable to the list of variables to be zeroed during each residual evaluation.

Parameters
var_nameThe name of the variable to be zeroed.

Reimplemented in DisplacedSystem.

Definition at line 150 of file SystemBase.C.

Referenced by DisplacedSystem::addVariableToZeroOnResidual(), DGKernel::DGKernel(), IntegratedBC::IntegratedBC(), InterfaceKernel::InterfaceKernel(), KernelBase::KernelBase(), NodalBC::NodalBC(), and NodalKernel::NodalKernel().

151 {
152  _vars_to_be_zeroed_on_residual.push_back(var_name);
153 }
std::vector< std::string > _vars_to_be_zeroed_on_residual
Definition: SystemBase.h:492
NumericVector< Number > & SystemBase::addVector ( const std::string &  vector_name,
const bool  project,
const ParallelType  type 
)
virtualinherited

Adds a solution length vector to the system.

Parameters
vector_nameThe name of the vector.
projectWhether or not to project this vector when doing mesh refinement. If the vector is just going to be recomputed then there is no need to project it.
typeWhat type of parallel vector. This is usually either PARALLEL or GHOSTED. GHOSTED is needed if you are going to be accessing off-processor entries. The ghosting pattern is the same as the solution vector.

Reimplemented in AuxiliarySystem.

Definition at line 490 of file SystemBase.C.

Referenced by addExtraVectors(), AStableDirk4::AStableDirk4(), FEProblemBase::initNullSpaceVectors(), LStableDirk3::LStableDirk3(), LStableDirk4::LStableDirk4(), residualGhosted(), residualVector(), SystemBase::saveOldSolutions(), and Transient::Transient().

491 {
492  if (hasVector(vector_name))
493  return getVector(vector_name);
494 
495  NumericVector<Number> * vec = &system().add_vector(vector_name, project, type);
496  return *vec;
497 }
virtual bool hasVector(const std::string &name)
Check if the named vector exists in the system.
Definition: SystemBase.C:589
virtual System & system()=0
Get the reference to the libMesh system.
MatType type
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector.
Definition: SystemBase.C:598
void NonlinearSystemBase::assembleConstraintsSeparately ( bool  separately = true)
inline

Indicates whether to assemble residual and Jacobian after each constraint application.

When true, enables "transitive" constraint application: subsequent constraints can use prior constraints' results.

Definition at line 392 of file NonlinearSystemBase.h.

393  {
395  }
bool _assemble_constraints_separately
Whether or not to assemble the residual and Jacobian after the application of each constraint...
void SystemBase::augmentSendList ( std::vector< dof_id_type > &  send_list)
virtualinherited

Will modify the send_list to add all of the extra ghosted dofs for this system.

Reimplemented in DisplacedSystem.

Definition at line 401 of file SystemBase.C.

Referenced by DisplacedSystem::augmentSendList(), and extraSendList().

402 {
403  std::set<dof_id_type> & ghosted_elems = _subproblem.ghostedElems();
404 
405  DofMap & dof_map = dofMap();
406 
407  std::vector<dof_id_type> dof_indices;
408 
409  System & sys = system();
410 
411  unsigned int sys_num = sys.number();
412 
413  unsigned int n_vars = sys.n_vars();
414 
415  for (const auto & elem_id : ghosted_elems)
416  {
417  Elem * elem = _mesh.elemPtr(elem_id);
418 
419  if (elem->active())
420  {
421  dof_map.dof_indices(elem, dof_indices);
422 
423  // Only need to ghost it if it's actually not on this processor
424  for (const auto & dof : dof_indices)
425  if (dof < dof_map.first_dof() || dof >= dof_map.end_dof())
426  send_list.push_back(dof);
427 
428  // Now add the DoFs from all of the nodes. This is necessary because of block
429  // restricted variables. A variable might not live _on_ this element but it
430  // might live on nodes connected to this element.
431  for (unsigned int n = 0; n < elem->n_nodes(); n++)
432  {
433  Node * node = elem->node_ptr(n);
434 
435  // Have to get each variable's dofs
436  for (unsigned int v = 0; v < n_vars; v++)
437  {
438  const Variable & var = sys.variable(v);
439  unsigned int var_num = var.number();
440  unsigned int n_comp = var.n_components();
441 
442  // See if this variable has any dofs at this node
443  if (node->n_dofs(sys_num, var_num) > 0)
444  {
445  // Loop over components of the variable
446  for (unsigned int c = 0; c < n_comp; c++)
447  send_list.push_back(node->dof_number(sys_num, var_num, c));
448  }
449  }
450  }
451  }
452  }
453 }
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2115
virtual DofMap & dofMap()
Gets the dof map.
Definition: SystemBase.C:610
DofMap & dof_map
SubProblem & _subproblem
Definition: SystemBase.h:478
virtual std::set< dof_id_type > & ghostedElems()
Return the list of elements that should have their DoFs ghosted to this processor.
Definition: SubProblem.h:400
virtual System & system()=0
Get the reference to the libMesh system.
MooseMesh & _mesh
Definition: SystemBase.h:483
PetscInt n
void NonlinearSystemBase::augmentSparsity ( SparsityPattern::Graph &  sparsity,
std::vector< dof_id_type > &  n_nz,
std::vector< dof_id_type > &  n_oz 
)
overridevirtual

Will modify the sparsity pattern to add logical geometric connections.

Implements SystemBase.

Definition at line 2361 of file NonlinearSystemBase.C.

2364 {
2366  {
2368 
2369  std::map<dof_id_type, std::vector<dof_id_type>> graph;
2370 
2372 
2375  graph);
2376 
2377  const dof_id_type first_dof_on_proc = dofMap().first_dof(processor_id());
2378  const dof_id_type end_dof_on_proc = dofMap().end_dof(processor_id());
2379 
2380  // The total number of dofs on and off processor
2381  const dof_id_type n_dofs_on_proc = dofMap().n_local_dofs();
2382  const dof_id_type n_dofs_not_on_proc = dofMap().n_dofs() - dofMap().n_local_dofs();
2383 
2384  for (const auto & git : graph)
2385  {
2386  dof_id_type dof = git.first;
2387  dof_id_type local_dof = dof - first_dof_on_proc;
2388 
2389  if (dof < first_dof_on_proc || dof >= end_dof_on_proc)
2390  continue;
2391 
2392  const std::vector<dof_id_type> & row = git.second;
2393 
2394  SparsityPattern::Row & sparsity_row = sparsity[local_dof];
2395 
2396  unsigned int original_row_length = sparsity_row.size();
2397 
2398  sparsity_row.insert(sparsity_row.end(), row.begin(), row.end());
2399 
2400  SparsityPattern::sort_row(
2401  sparsity_row.begin(), sparsity_row.begin() + original_row_length, sparsity_row.end());
2402 
2403  // Fix up nonzero arrays
2404  for (const auto & coupled_dof : row)
2405  {
2406  if (coupled_dof < first_dof_on_proc || coupled_dof >= end_dof_on_proc)
2407  {
2408  if (n_oz[local_dof] < n_dofs_not_on_proc)
2409  n_oz[local_dof]++;
2410  }
2411  else
2412  {
2413  if (n_nz[local_dof] < n_dofs_on_proc)
2414  n_nz[local_dof]++;
2415  }
2416  }
2417  }
2418  }
2419 }
void findImplicitGeometricCouplingEntries(GeometricSearchData &geom_search_data, std::map< dof_id_type, std::vector< dof_id_type >> &graph)
Finds the implicit sparsity graph between geometrically related dofs.
virtual GeometricSearchData & geomSearchData() override
virtual DofMap & dofMap()
Gets the dof map.
Definition: SystemBase.C:610
FEProblemBase & _fe_problem
virtual std::shared_ptr< DisplacedProblem > getDisplacedProblem()
const std::vector< numeric_index_type > & n_nz
virtual void updateGeomSearch(GeometricSearchData::GeometricSearchType type=GeometricSearchData::ALL) override
bool _add_implicit_geometric_coupling_entries_to_jacobian
Whether or not to add implicit geometric couplings to the Jacobian for FDP.
const std::vector< numeric_index_type > & n_oz
void NonlinearSystemBase::checkKernelCoverage ( const std::set< SubdomainID > &  mesh_subdomains) const

System Integrity Checks

Definition at line 2493 of file NonlinearSystemBase.C.

2494 {
2495  // Check kernel coverage of subdomains (blocks) in your mesh
2496  std::set<SubdomainID> input_subdomains;
2497  std::set<std::string> kernel_variables;
2498 
2499  bool global_kernels_exist = _kernels.hasActiveBlockObjects(Moose::ANY_BLOCK_ID);
2500  global_kernels_exist |= _scalar_kernels.hasActiveObjects();
2501  global_kernels_exist |= _nodal_kernels.hasActiveObjects();
2502 
2503  _kernels.subdomainsCovered(input_subdomains, kernel_variables);
2504  _nodal_kernels.subdomainsCovered(input_subdomains, kernel_variables);
2505  _scalar_kernels.subdomainsCovered(input_subdomains, kernel_variables);
2506  _constraints.subdomainsCovered(input_subdomains, kernel_variables);
2507 
2508  if (!global_kernels_exist)
2509  {
2510  std::set<SubdomainID> difference;
2511  std::set_difference(mesh_subdomains.begin(),
2512  mesh_subdomains.end(),
2513  input_subdomains.begin(),
2514  input_subdomains.end(),
2515  std::inserter(difference, difference.end()));
2516 
2517  if (!difference.empty())
2518  {
2519  std::stringstream missing_block_ids;
2520  std::copy(difference.begin(),
2521  difference.end(),
2522  std::ostream_iterator<unsigned int>(missing_block_ids, " "));
2523  mooseError("Each subdomain must contain at least one Kernel.\nThe following block(s) lack an "
2524  "active kernel: " +
2525  missing_block_ids.str());
2526  }
2527  }
2528 
2529  std::set<VariableName> variables(getVariableNames().begin(), getVariableNames().end());
2530 
2531  std::set<VariableName> difference;
2532  std::set_difference(variables.begin(),
2533  variables.end(),
2534  kernel_variables.begin(),
2535  kernel_variables.end(),
2536  std::inserter(difference, difference.end()));
2537 
2538  if (!difference.empty())
2539  {
2540  std::stringstream missing_kernel_vars;
2541  std::copy(difference.begin(),
2542  difference.end(),
2543  std::ostream_iterator<std::string>(missing_kernel_vars, " "));
2544  mooseError("Each variable must be referenced by at least one active Kernel.\nThe following "
2545  "variable(s) lack an active kernel: " +
2546  missing_kernel_vars.str());
2547  }
2548 }
void subdomainsCovered(std::set< SubdomainID > &subdomains_covered, std::set< std::string > &unique_variables, THREAD_ID tid=0) const
Update supplied subdomain and variable coverate containters.
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
MooseObjectWarehouse< NodalKernel > _nodal_kernels
NodalKernels for each thread.
MooseObjectWarehouse< ScalarKernel > _scalar_kernels
bool hasActiveObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
ConstraintWarehouse _constraints
Constraints storage object.
KernelWarehouse _kernels
const SubdomainID ANY_BLOCK_ID
Definition: MooseTypes.h:117
bool hasActiveBlockObjects(THREAD_ID tid=0) const
const std::vector< VariableName > & getVariableNames() const
Definition: SystemBase.h:466
void subdomainsCovered(std::set< SubdomainID > &subdomains_covered, std::set< std::string > &unique_variables, THREAD_ID tid=0) const
Populates a set of covered subdomains and the associated variable names.
Real NonlinearSystemBase::computeDamping ( const NumericVector< Number > &  solution,
const NumericVector< Number > &  update 
)

Compute damping.

Parameters
solutionThe trail solution vector
updateThe incremental update to the solution vector
Returns
returns The damping factor

Definition at line 2249 of file NonlinearSystemBase.C.

2251 {
2252  Moose::perf_log.push("compute_dampers()", "Execution");
2253 
2254  // Default to no damping
2255  Real damping = 1.0;
2256  bool has_active_dampers = false;
2257 
2259  {
2260  has_active_dampers = true;
2263  Threads::parallel_reduce(*_mesh.getActiveLocalElementRange(), cid);
2264  damping = std::min(cid.damping(), damping);
2265  }
2266 
2268  {
2269  has_active_dampers = true;
2272  Threads::parallel_reduce(*_mesh.getLocalNodeRange(), cndt);
2273  damping = std::min(cndt.damping(), damping);
2274  }
2275 
2277  {
2278  has_active_dampers = true;
2279  const auto & gdampers = _general_dampers.getActiveObjects();
2280  for (const auto & damper : gdampers)
2281  {
2282  Real gd_damping = damper->computeDamping(solution, update);
2283  try
2284  {
2285  damper->checkMinDamping(gd_damping);
2286  }
2287  catch (MooseException & e)
2288  {
2290  }
2291  damping = std::min(gd_damping, damping);
2292  }
2293  }
2294 
2295  _communicator.min(damping);
2296 
2297  if (has_active_dampers && damping < 1.0)
2298  _console << " Damping factor: " << damping << "\n";
2299 
2300  Moose::perf_log.pop("compute_dampers()", "Execution");
2301 
2302  return damping;
2303 }
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
Definition: MooseMesh.C:724
virtual void setException(const std::string &message)
Set an exception.
MooseObjectWarehouse< NodalDamper > _nodal_dampers
Nodal Dampers for each thread.
ConstNodeRange * getLocalNodeRange()
Definition: MooseMesh.C:753
virtual const char * what() const
Get out the error message.
virtual void update()
Update the system (doing libMesh magic)
Definition: SystemBase.C:665
FEProblemBase & _fe_problem
PerfLog perf_log
Perflog to be used by applications.
bool hasActiveObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
Provides a way for users to bail out of the current solve.
MooseMesh & _mesh
Definition: SystemBase.h:483
MooseObjectWarehouse< ElementDamper > _element_dampers
Element Dampers for each thread.
NumericVector< Number > * _increment_vec
increment vector
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread...
MooseObjectWarehouse< GeneralDamper > _general_dampers
General Dampers.
void NonlinearSystemBase::computeDiracContributions ( SparseMatrix< Number > *  jacobian = NULL)
protected

Definition at line 2306 of file NonlinearSystemBase.C.

Referenced by computeJacobianInternal(), and computeResidualInternal().

2307 {
2309 
2310  std::set<const Elem *> dirac_elements;
2311 
2313  {
2314  Moose::perf_log.push("computeDiracContributions()", "Execution");
2315 
2316  // TODO: Need a threading fix... but it's complicated!
2317  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); ++tid)
2318  {
2319  const auto & dkernels = _dirac_kernels.getActiveObjects(tid);
2320  for (const auto & dkernel : dkernels)
2321  {
2322  dkernel->clearPoints();
2323  dkernel->addPoints();
2324  }
2325  }
2326 
2327  ComputeDiracThread cd(_fe_problem, jacobian);
2328 
2329  _fe_problem.getDiracElements(dirac_elements);
2330 
2331  DistElemRange range(dirac_elements.begin(), dirac_elements.end(), 1);
2332  // TODO: Make Dirac work thread!
2333  // Threads::parallel_reduce(range, cd);
2334 
2335  cd(range);
2336 
2337  Moose::perf_log.pop("computeDiracContributions()", "Execution");
2338  }
2339 
2340  if (jacobian == NULL)
2341  _Re_non_time->close();
2342 }
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
virtual void getDiracElements(std::set< const Elem * > &elems) override
Fills "elems" with the elements that should be looped over for Dirac Kernels.
FEProblemBase & _fe_problem
PerfLog perf_log
Perflog to be used by applications.
bool hasActiveObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
virtual void clearDiracInfo() override
Gets called before Dirac Kernels are asked to add the points they are supposed to be evaluated in...
MooseObjectWarehouse< DiracKernel > _dirac_kernels
Dirac Kernel storage for each thread.
StoredRange< std::set< const Elem * >::const_iterator, const Elem * > DistElemRange
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread...
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void NonlinearSystemBase::computeJacobian ( SparseMatrix< Number > &  jacobian,
Moose::KernelType  kernel_type = Moose::KT_ALL 
)

Computes Jacobian.

Parameters
jacobianJacobian is formed in here

Definition at line 2096 of file NonlinearSystemBase.C.

2097 {
2098  Moose::perf_log.push("compute_jacobian()", "Execution");
2099 
2100  Moose::enableFPE();
2101 
2102  try
2103  {
2104  jacobian.zero();
2105  computeJacobianInternal(jacobian, kernel_type);
2106  }
2107  catch (MooseException & e)
2108  {
2109  // The buck stops here, we have already handled the exception by
2110  // calling stopSolve(), it is now up to PETSc to return a
2111  // "diverged" reason during the next solve.
2112  }
2113 
2114  Moose::enableFPE(false);
2115 
2116  Moose::perf_log.pop("compute_jacobian()", "Execution");
2117 }
void computeJacobianInternal(SparseMatrix< Number > &jacobian, Moose::KernelType kernel_type)
PerfLog perf_log
Perflog to be used by applications.
Provides a way for users to bail out of the current solve.
void enableFPE(bool on=true)
Definition: Moose.C:1252
void NonlinearSystemBase::computeJacobianBlocks ( std::vector< JacobianBlock * > &  blocks)

Computes several Jacobian blocks simultaneously, summing their contributions into smaller preconditioning matrices.

Used by Physics-based preconditioning

Parameters
blocksThe blocks to fill in (JacobianBlock is defined in ComputeJacobianBlocksThread)

Definition at line 2120 of file NonlinearSystemBase.C.

2121 {
2122  Moose::perf_log.push("compute_jacobian_block()", "Execution");
2123 
2124  Moose::enableFPE();
2125 
2126  for (unsigned int i = 0; i < blocks.size(); i++)
2127  {
2128  SparseMatrix<Number> & jacobian = blocks[i]->_jacobian;
2129 
2130 #ifdef LIBMESH_HAVE_PETSC
2131 // Necessary for speed
2132 #if PETSC_VERSION_LESS_THAN(3, 0, 0)
2133  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS);
2134 #elif PETSC_VERSION_LESS_THAN(3, 1, 0)
2135  // In Petsc 3.0.0, MatSetOption has three args...the third arg
2136  // determines whether the option is set (true) or unset (false)
2137  MatSetOption(
2138  static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS, PETSC_TRUE);
2139 #else
2140  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
2141  MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
2142  PETSC_TRUE);
2143 #endif
2144 #if PETSC_VERSION_LESS_THAN(3, 3, 0)
2145 #else
2147  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
2148  MAT_NEW_NONZERO_ALLOCATION_ERR,
2149  PETSC_FALSE);
2150 #endif
2151 
2152 #endif
2153 
2154  jacobian.zero();
2155  }
2156 
2157  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
2159 
2160  PARALLEL_TRY
2161  {
2162  ConstElemRange & elem_range = *_mesh.getActiveLocalElementRange();
2164  Threads::parallel_reduce(elem_range, cjb);
2165  }
2166  PARALLEL_CATCH;
2167 
2168  for (unsigned int i = 0; i < blocks.size(); i++)
2169  blocks[i]->_jacobian.close();
2170 
2171  for (unsigned int i = 0; i < blocks.size(); i++)
2172  {
2173  libMesh::System & precond_system = blocks[i]->_precond_system;
2174  SparseMatrix<Number> & jacobian = blocks[i]->_jacobian;
2175 
2176  unsigned int ivar = blocks[i]->_ivar;
2177  unsigned int jvar = blocks[i]->_jvar;
2178 
2179  // Dirichlet BCs
2180  std::vector<numeric_index_type> zero_rows;
2181  PARALLEL_TRY
2182  {
2183  ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
2184  for (const auto & bnode : bnd_nodes)
2185  {
2186  BoundaryID boundary_id = bnode->_bnd_id;
2187  Node * node = bnode->_node;
2188 
2189  if (_nodal_bcs.hasActiveBoundaryObjects(boundary_id))
2190  {
2191  const auto & bcs = _nodal_bcs.getActiveBoundaryObjects(boundary_id);
2192 
2193  if (node->processor_id() == processor_id())
2194  {
2195  _fe_problem.reinitNodeFace(node, boundary_id, 0);
2196 
2197  for (const auto & bc : bcs)
2198  if (bc->variable().number() == ivar && bc->shouldApply())
2199  {
2200  // The first zero is for the variable number... there is only one variable in each
2201  // mini-system
2202  // The second zero only works with Lagrange elements!
2203  zero_rows.push_back(node->dof_number(precond_system.number(), 0, 0));
2204  }
2205  }
2206  }
2207  }
2208  }
2209  PARALLEL_CATCH;
2210 
2211  jacobian.close();
2212 
2213  // This zeroes the rows corresponding to Dirichlet BCs and puts a 1.0 on the diagonal
2214  if (ivar == jvar)
2215  jacobian.zero_rows(zero_rows, 1.0);
2216  else
2217  jacobian.zero_rows(zero_rows, 0.0);
2218 
2219  jacobian.close();
2220  }
2221 
2222  Moose::enableFPE(false);
2223 
2224  Moose::perf_log.pop("compute_jacobian_block()", "Execution");
2225 }
bool errorOnJacobianNonzeroReallocation()
Will return True if the user wants to get an error when a nonzero is reallocated in the Jacobian by P...
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
Definition: MooseMesh.C:724
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
MooseObjectWarehouse< NodalBC > _nodal_bcs
Specialization for filling multiple "small" preconditioning matrices simulatenously.
FEProblemBase & _fe_problem
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
PerfLog perf_log
Perflog to be used by applications.
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, THREAD_ID tid) override
virtual void reinitScalars(THREAD_ID tid) override
MooseMesh & _mesh
Definition: SystemBase.h:483
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
Definition: MooseMesh.h:1213
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:763
void enableFPE(bool on=true)
Definition: Moose.C:1252
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
void NonlinearSystemBase::computeJacobianInternal ( SparseMatrix< Number > &  jacobian,
Moose::KernelType  kernel_type 
)
protected

Definition at line 1816 of file NonlinearSystemBase.C.

Referenced by computeJacobian().

1818 {
1819 #ifdef LIBMESH_HAVE_PETSC
1820 // Necessary for speed
1821 #if PETSC_VERSION_LESS_THAN(3, 0, 0)
1822  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS);
1823 #elif PETSC_VERSION_LESS_THAN(3, 1, 0)
1824  // In Petsc 3.0.0, MatSetOption has three args...the third arg
1825  // determines whether the option is set (true) or unset (false)
1826  MatSetOption(
1827  static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS, PETSC_TRUE);
1828 #else
1829  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
1830  MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
1831  PETSC_TRUE);
1832 #endif
1833 #if PETSC_VERSION_LESS_THAN(3, 3, 0)
1834 #else
1836  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
1837  MAT_NEW_NONZERO_ALLOCATION_ERR,
1838  PETSC_FALSE);
1839 #endif
1840 
1841 #endif
1842 
1843  // jacobianSetup /////
1844  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
1845  {
1846  _kernels.jacobianSetup(tid);
1849  if (_doing_dg)
1855  }
1860 
1861  // reinit scalar variables
1862  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
1864 
1865  PARALLEL_TRY
1866  {
1867  ConstElemRange & elem_range = *_mesh.getActiveLocalElementRange();
1868  switch (_fe_problem.coupling())
1869  {
1870  case Moose::COUPLING_DIAG:
1871  {
1872  ComputeJacobianThread cj(_fe_problem, jacobian, kernel_type);
1873  Threads::parallel_reduce(elem_range, cj);
1874 
1875  unsigned int n_threads = libMesh::n_threads();
1876  for (unsigned int i = 0; i < n_threads;
1877  i++) // Add any Jacobian contributions still hanging around
1878  _fe_problem.addCachedJacobian(jacobian, i);
1879 
1880  // Block restricted Nodal Kernels
1882  {
1884  ConstNodeRange & range = *_mesh.getLocalNodeRange();
1885  Threads::parallel_reduce(range, cnkjt);
1886 
1887  unsigned int n_threads = libMesh::n_threads();
1888  for (unsigned int i = 0; i < n_threads;
1889  i++) // Add any cached jacobians that might be hanging around
1891  }
1892 
1893  // Boundary restricted Nodal Kernels
1895  {
1897  ConstBndNodeRange & bnd_range = *_mesh.getBoundaryNodeRange();
1898 
1899  Threads::parallel_reduce(bnd_range, cnkjt);
1900  unsigned int n_threads = libMesh::n_threads();
1901  for (unsigned int i = 0; i < n_threads;
1902  i++) // Add any cached jacobians that might be hanging around
1904  }
1905  }
1906  break;
1907 
1908  default:
1910  {
1911  ComputeFullJacobianThread cj(_fe_problem, jacobian, kernel_type);
1912  Threads::parallel_reduce(elem_range, cj);
1913  unsigned int n_threads = libMesh::n_threads();
1914 
1915  for (unsigned int i = 0; i < n_threads; i++)
1916  _fe_problem.addCachedJacobian(jacobian, i);
1917 
1918  // Block restricted Nodal Kernels
1920  {
1922  ConstNodeRange & range = *_mesh.getLocalNodeRange();
1923  Threads::parallel_reduce(range, cnkjt);
1924 
1925  unsigned int n_threads = libMesh::n_threads();
1926  for (unsigned int i = 0; i < n_threads;
1927  i++) // Add any cached jacobians that might be hanging around
1929  }
1930 
1931  // Boundary restricted Nodal Kernels
1933  {
1935  ConstBndNodeRange & bnd_range = *_mesh.getBoundaryNodeRange();
1936 
1937  Threads::parallel_reduce(bnd_range, cnkjt);
1938 
1939  unsigned int n_threads = libMesh::n_threads();
1940  for (unsigned int i = 0; i < n_threads;
1941  i++) // Add any cached jacobians that might be hanging around
1943  }
1944  }
1945  break;
1946  }
1947 
1948  computeDiracContributions(&jacobian);
1950 
1951  static bool first = true;
1952 
1953  // This adds zeroes into geometric coupling entries to ensure they stay in the matrix
1955  {
1956  first = false;
1958 
1961  _fe_problem.getDisplacedProblem()->geomSearchData());
1962  }
1963  }
1964  PARALLEL_CATCH;
1965  jacobian.close();
1966 
1967  PARALLEL_TRY
1968  {
1969  // Add in Jacobian contributions from Constraints
1971  {
1972  // Nodal Constraints
1974 
1975  // Undisplaced Constraints
1976  constraintJacobians(jacobian, false);
1977 
1978  // Displaced Constraints
1980  constraintJacobians(jacobian, true);
1981  }
1982  }
1983  PARALLEL_CATCH;
1984  jacobian.close();
1985 
1986  // We need to close the save_in variables on the aux system before NodalBCs clear the dofs on
1987  // boundary nodes
1988  if (_has_diag_save_in)
1990 
1991  PARALLEL_TRY
1992  {
1993  // Cache the information about which BCs are coupled to which
1994  // variables, so we don't have to figure it out for each node.
1995  std::map<std::string, std::set<unsigned int>> bc_involved_vars;
1996  const std::set<BoundaryID> & all_boundary_ids = _mesh.getBoundaryIDs();
1997  for (const auto & bid : all_boundary_ids)
1998  {
1999  // Get reference to all the NodalBCs for this ID. This is only
2000  // safe if there are NodalBCs there to be gotten...
2002  {
2003  const auto & bcs = _nodal_bcs.getActiveBoundaryObjects(bid);
2004  for (const auto & bc : bcs)
2005  {
2006  const std::vector<MooseVariable *> & coupled_moose_vars = bc->getCoupledMooseVars();
2007 
2008  // Create the set of "involved" MOOSE nonlinear vars, which includes all coupled vars and
2009  // the BC's own variable
2010  std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2011  for (const auto & coupled_var : coupled_moose_vars)
2012  if (coupled_var->kind() == Moose::VAR_NONLINEAR)
2013  var_set.insert(coupled_var->number());
2014 
2015  var_set.insert(bc->variable().number());
2016  }
2017  }
2018  }
2019 
2020  // Get variable coupling list. We do all the NodalBC stuff on
2021  // thread 0... The couplingEntries() data structure determines
2022  // which variables are "coupled" as far as the preconditioner is
2023  // concerned, not what variables a boundary condition specifically
2024  // depends on.
2025  std::vector<std::pair<MooseVariable *, MooseVariable *>> & coupling_entries =
2026  _fe_problem.couplingEntries(/*_tid=*/0);
2027 
2028  // Compute Jacobians for NodalBCs
2029  ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
2030  for (const auto & bnode : bnd_nodes)
2031  {
2032  BoundaryID boundary_id = bnode->_bnd_id;
2033  Node * node = bnode->_node;
2034 
2035  if (_nodal_bcs.hasActiveBoundaryObjects(boundary_id) &&
2036  node->processor_id() == processor_id())
2037  {
2038  _fe_problem.reinitNodeFace(node, boundary_id, 0);
2039 
2040  const auto & bcs = _nodal_bcs.getActiveBoundaryObjects(boundary_id);
2041  for (const auto & bc : bcs)
2042  {
2043  // Get the set of involved MOOSE vars for this BC
2044  std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2045 
2046  // Loop over all the variables whose Jacobian blocks are
2047  // actually being computed, call computeOffDiagJacobian()
2048  // for each one which is actually coupled (otherwise the
2049  // value is zero.)
2050  for (const auto & it : coupling_entries)
2051  {
2052  unsigned int ivar = it.first->number(), jvar = it.second->number();
2053 
2054  // We are only going to call computeOffDiagJacobian() if:
2055  // 1.) the BC's variable is ivar
2056  // 2.) jvar is "involved" with the BC (including jvar==ivar), and
2057  // 3.) the BC should apply.
2058  if ((bc->variable().number() == ivar) && var_set.count(jvar) && bc->shouldApply())
2059  bc->computeOffDiagJacobian(jvar);
2060  }
2061  }
2062  }
2063  } // end loop over boundary nodes
2064 
2065  // For the matrix in the right side of generalized eigenvalue problems, its conresponding
2066  // rows are zeroed if homogeneous Dirichlet boundary conditions are used.
2067  if (kernel_type == Moose::KT_EIGEN)
2069  // Set the cached NodalBC values in the Jacobian matrix
2070  else
2072  }
2073  PARALLEL_CATCH;
2074  jacobian.close();
2075 
2076  // We need to close the save_in variables on the aux system before NodalBCs clear the dofs on
2077  // boundary nodes
2080 
2081  if (hasDiagSaveIn())
2083 }
bool errorOnJacobianNonzeroReallocation()
Will return True if the user wants to get an error when a nonzero is reallocated in the Jacobian by P...
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
Definition: MooseMesh.C:724
void computeScalarKernelsJacobians(SparseMatrix< Number > &jacobian)
void enforceNodalConstraintsJacobian(SparseMatrix< Number > &jacobian)
virtual Assembly & assembly(THREAD_ID tid) override
bool _has_nodalbc_diag_save_in
If there is a nodal BC having diag_save_in.
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
Definition: MooseMesh.C:1990
MooseObjectWarehouse< NodalBC > _nodal_bcs
MooseObjectWarehouse< NodalDamper > _nodal_dampers
Nodal Dampers for each thread.
ConstNodeRange * getLocalNodeRange()
Definition: MooseMesh.C:753
virtual GeometricSearchData & geomSearchData() override
virtual void update()
Update the system (doing libMesh magic)
Definition: SystemBase.C:665
MooseObjectWarehouse< NodalKernel > _nodal_kernels
NodalKernels for each thread.
bool _doing_dg
true if DG is active (optimization reasons)
FEProblemBase & _fe_problem
virtual std::shared_ptr< DisplacedProblem > getDisplacedProblem()
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
virtual void jacobianSetup(THREAD_ID tid=0) const
MooseObjectWarehouse< InterfaceKernel > _interface_kernels
void constraintJacobians(SparseMatrix< Number > &jacobian, bool displaced)
Add jacobian contributions from Constraints.
MooseObjectWarehouse< ScalarKernel > _scalar_kernels
virtual void addCachedJacobian(SparseMatrix< Number > &jacobian, THREAD_ID tid) override
AuxiliarySystem & getAuxiliarySystem()
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, THREAD_ID tid) override
MooseObjectWarehouse< DGKernel > _dg_kernels
void zeroCachedJacobianContributions(SparseMatrix< Number > &jacobian)
Zero out previously-cached Jacobian rows.
Definition: Assembly.C:1927
ConstraintWarehouse _constraints
Constraints storage object.
void addImplicitGeometricCouplingEntries(SparseMatrix< Number > &jacobian, GeometricSearchData &geom_search_data)
Adds entries to the Jacobian in the correct positions for couplings coming from dofs being coupled th...
bool _add_implicit_geometric_coupling_entries_to_jacobian
Whether or not to add implicit geometric couplings to the Jacobian for FDP.
virtual NumericVector< Number > & solution() override
KernelWarehouse _kernels
std::vector< std::pair< MooseVariable *, MooseVariable * > > & couplingEntries(THREAD_ID tid)
void addCachedJacobianContributions(SparseMatrix< Number > &jacobian)
Adds previously-cached Jacobian values via SparseMatrix::add() calls.
Definition: Assembly.C:1937
MooseObjectWarehouse< DiracKernel > _dirac_kernels
Dirac Kernel storage for each thread.
virtual void reinitScalars(THREAD_ID tid) override
bool _has_diag_save_in
If there is any Kernel or IntegratedBC having diag_save_in.
bool hasDiagSaveIn() const
Weather or not the nonlinear system has diagonal Jacobian save-ins.
MooseMesh & _mesh
Definition: SystemBase.h:483
MooseObjectWarehouse< ElementDamper > _element_dampers
Element Dampers for each thread.
Moose::CouplingType coupling()
bool hasActiveBlockObjects(THREAD_ID tid=0) const
MooseObjectWarehouse< IntegratedBC > _integrated_bcs
bool _has_constraints
Whether or not this system has any Constraints.
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
Definition: MooseMesh.h:1213
MooseObjectWarehouse< GeneralDamper > _general_dampers
General Dampers.
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:763
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void computeDiracContributions(SparseMatrix< Number > *jacobian=NULL)
void setCachedJacobianContributions(SparseMatrix< Number > &jacobian)
Sets previously-cached Jacobian values via SparseMatrix::set() calls.
Definition: Assembly.C:1911
void NonlinearSystemBase::computeNodalBCs ( NumericVector< Number > &  residual,
Moose::KernelType  type = Moose::KT_ALL 
)
protected

Enforces nodal boundary conditions.

Parameters
residualResidual where nodal BCs are enforced (input/output)

Definition at line 1263 of file NonlinearSystemBase.C.

Referenced by computeResidual().

1265 {
1266  // We need to close the diag_save_in variables on the aux system before NodalBCs clear the dofs on
1267  // boundary nodes
1268  if (_has_save_in)
1270 
1271  PARALLEL_TRY
1272  {
1273  ConstBndNodeRange & bnd_nodes = *_mesh.getBoundaryNodeRange();
1274 
1275  if (!bnd_nodes.empty())
1276  {
1277  Moose::perf_log.push("computeNodalBCs()", "Execution");
1278 
1279  for (const auto & bnode : bnd_nodes)
1280  {
1281  BoundaryID boundary_id = bnode->_bnd_id;
1282  Node * node = bnode->_node;
1283 
1284  if (node->processor_id() == processor_id())
1285  {
1286  // reinit variables in nodes
1287  _fe_problem.reinitNodeFace(node, boundary_id, 0);
1288 
1289  if (_nodal_bcs.hasActiveBoundaryObjects(boundary_id))
1290  {
1291  const auto & bcs = _nodal_bcs.getActiveBoundaryObjects(boundary_id);
1292  for (const auto & nbc : bcs)
1293  if (nbc->shouldApply())
1294  {
1295  if (kernel_type == Moose::KT_EIGEN)
1296  nbc->setBCOnEigen(true);
1297  else
1298  nbc->setBCOnEigen(false);
1299 
1300  nbc->computeResidual(residual);
1301  }
1302  }
1303  }
1304  }
1305 
1306  Moose::perf_log.pop("computeNodalBCs()", "Execution");
1307  }
1308  }
1309  PARALLEL_CATCH;
1310 
1311  residual.close();
1312  if (_Re_time)
1313  _Re_time->close();
1314  _Re_non_time->close();
1315 }
NumericVector< Number > * _Re_time
residual vector for time contributions
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
MooseObjectWarehouse< NodalBC > _nodal_bcs
bool _has_save_in
If there is any Kernel or IntegratedBC having save_in.
FEProblemBase & _fe_problem
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
PerfLog perf_log
Perflog to be used by applications.
AuxiliarySystem & getAuxiliarySystem()
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, THREAD_ID tid) override
virtual NumericVector< Number > & solution() override
MooseMesh & _mesh
Definition: SystemBase.h:483
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
Definition: MooseMesh.h:1213
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:763
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
void NonlinearSystemBase::computeResidual ( NumericVector< Number > &  residual,
Moose::KernelType  type = Moose::KT_ALL 
)

Computes residual.

Parameters
residualResidual is formed in here
typeThe type of kernels for which the residual is to be computed.

Definition at line 525 of file NonlinearSystemBase.C.

526 {
527  Moose::perf_log.push("compute_residual()", "Execution");
528 
530 
532 
533  for (const auto & numeric_vec : _vecs_to_zero_for_residual)
534  if (hasVector(numeric_vec))
535  {
536  NumericVector<Number> & vec = getVector(numeric_vec);
537  vec.close();
538  vec.zero();
539  }
540 
541  try
542  {
543  residual.zero();
544  if (_Re_time)
545  _Re_time->zero();
546  _Re_non_time->zero();
548  if (_Re_time)
549  _Re_time->close();
550  _Re_non_time->close();
551  if (_time_integrator)
552  _time_integrator->postStep(residual);
553  else
554  residual += *_Re_non_time;
555  residual.close();
556 
557  computeNodalBCs(residual, type);
558 
559  // If we are debugging residuals we need one more assignment to have the ghosted copy up to date
561  {
562  *_residual_ghosted = residual;
563  _residual_ghosted->close();
564  }
565 
566  // Need to close and update the aux system in case residuals were saved to it.
569  if (hasSaveIn())
571  }
572  catch (MooseException & e)
573  {
574  // The buck stops here, we have already handled the exception by
575  // calling stopSolve(), it is now up to PETSc to return a
576  // "diverged" reason during the next solve.
577  }
578 
579  Moose::enableFPE(false);
580 
581  Moose::perf_log.pop("compute_residual()", "Execution");
582 }
NumericVector< Number > * _Re_time
residual vector for time contributions
bool _debugging_residuals
true if debugging residuals
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
bool _has_nodalbc_save_in
If there is a nodal BC having save_in.
std::shared_ptr< TimeIntegrator > _time_integrator
Time integrator.
virtual void update()
Update the system (doing libMesh magic)
Definition: SystemBase.C:665
bool _need_residual_ghosted
Whether or not a ghosted copy of the residual needs to be made.
virtual bool hasVector(const std::string &name)
Check if the named vector exists in the system.
Definition: SystemBase.C:589
FEProblemBase & _fe_problem
std::vector< std::string > _vecs_to_zero_for_residual
vectors that will be zeroed before a residual computation
PerfLog perf_log
Perflog to be used by applications.
AuxiliarySystem & getAuxiliarySystem()
bool hasSaveIn() const
Weather or not the nonlinear system has save-ins.
virtual NumericVector< Number > & solution() override
void computeResidualInternal(Moose::KernelType type=Moose::KT_ALL)
Compute the residual.
Provides a way for users to bail out of the current solve.
MatType type
unsigned int _n_residual_evaluations
Total number of residual evaluations that have been performed.
void computeNodalBCs(NumericVector< Number > &residual, Moose::KernelType type=Moose::KT_ALL)
Enforces nodal boundary conditions.
NumericVector< Number > * _residual_ghosted
ghosted form of the residual
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector.
Definition: SystemBase.C:598
void enableFPE(bool on=true)
Definition: Moose.C:1252
void NonlinearSystemBase::computeResidualInternal ( Moose::KernelType  type = Moose::KT_ALL)
protected

Compute the residual.

Parameters
typeThe type of kernels for which the residual is to be computed.

Definition at line 1073 of file NonlinearSystemBase.C.

Referenced by computeResidual().

1074 {
1075  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
1076  {
1077  _kernels.residualSetup(tid);
1080  if (_doing_dg)
1086  }
1091 
1092  // reinit scalar variables
1093  for (unsigned int tid = 0; tid < libMesh::n_threads(); tid++)
1095 
1096  // residual contributions from the domain
1097  PARALLEL_TRY
1098  {
1099  Moose::perf_log.push("computeKernels()", "Execution");
1100 
1101  ConstElemRange & elem_range = *_mesh.getActiveLocalElementRange();
1102 
1104 
1105  Threads::parallel_reduce(elem_range, cr);
1106 
1107  unsigned int n_threads = libMesh::n_threads();
1108  for (unsigned int i = 0; i < n_threads;
1109  i++) // Add any cached residuals that might be hanging around
1111 
1112  Moose::perf_log.pop("computeKernels()", "Execution");
1113  }
1114  PARALLEL_CATCH;
1115 
1116  // residual contributions from the scalar kernels
1117  PARALLEL_TRY
1118  {
1119  // do scalar kernels (not sure how to thread this)
1121  {
1122  Moose::perf_log.push("computScalarKernels()", "Execution");
1123 
1124  const std::vector<std::shared_ptr<ScalarKernel>> * scalars;
1125 
1126  // Use the right subset of ScalarKernels depending on the KernelType.
1127  switch (type)
1128  {
1129  case Moose::KT_ALL:
1130  scalars = &(_scalar_kernels.getActiveObjects());
1131  break;
1132 
1133  case Moose::KT_TIME:
1134  scalars = &(_time_scalar_kernels.getActiveObjects());
1135  break;
1136 
1137  case Moose::KT_NONTIME:
1139  break;
1140 
1141  default:
1142  mooseError("Unrecognized KernelType in computeResidualInternal().");
1143  }
1144 
1145  bool have_scalar_contributions = false;
1146  for (const auto & scalar_kernel : *scalars)
1147  {
1148  scalar_kernel->reinit();
1149  const std::vector<dof_id_type> & dof_indices = scalar_kernel->variable().dofIndices();
1150  const DofMap & dof_map = scalar_kernel->variable().dofMap();
1151  const dof_id_type first_dof = dof_map.first_dof();
1152  const dof_id_type end_dof = dof_map.end_dof();
1153  for (dof_id_type dof : dof_indices)
1154  {
1155  if (dof >= first_dof && dof < end_dof)
1156  {
1157  scalar_kernel->computeResidual();
1158  have_scalar_contributions = true;
1159  break;
1160  }
1161  }
1162  }
1163  if (have_scalar_contributions)
1165 
1166  Moose::perf_log.pop("computScalarKernels()", "Execution");
1167  }
1168  }
1169  PARALLEL_CATCH;
1170 
1171  // residual contributions from Block NodalKernels
1172  PARALLEL_TRY
1173  {
1175  {
1176  Moose::perf_log.push("computNodalKernels()", "Execution");
1177 
1179 
1180  ConstNodeRange & range = *_mesh.getLocalNodeRange();
1181 
1182  if (range.begin() != range.end())
1183  {
1184  _fe_problem.reinitNode(*range.begin(), 0);
1185 
1186  Threads::parallel_reduce(range, cnk);
1187 
1188  unsigned int n_threads = libMesh::n_threads();
1189  for (unsigned int i = 0; i < n_threads;
1190  i++) // Add any cached residuals that might be hanging around
1192  }
1193 
1194  Moose::perf_log.pop("computNodalKernels()", "Execution");
1195  }
1196  }
1197  PARALLEL_CATCH;
1198 
1199  // residual contributions from boundary NodalKernels
1200  PARALLEL_TRY
1201  {
1203  {
1204  Moose::perf_log.push("computNodalKernelBCs()", "Execution");
1205 
1207 
1208  ConstBndNodeRange & bnd_node_range = *_mesh.getBoundaryNodeRange();
1209 
1210  Threads::parallel_reduce(bnd_node_range, cnk);
1211 
1212  unsigned int n_threads = libMesh::n_threads();
1213  for (unsigned int i = 0; i < n_threads;
1214  i++) // Add any cached residuals that might be hanging around
1216 
1217  Moose::perf_log.pop("computNodalKernelBCs()", "Execution");
1218  }
1219  }
1220  PARALLEL_CATCH;
1221 
1222  if (_need_residual_copy)
1223  {
1224  _Re_non_time->close();
1225  _Re_non_time->localize(_residual_copy);
1226  }
1227 
1229  {
1230  _Re_non_time->close();
1232  _residual_ghosted->close();
1233  }
1234 
1235  PARALLEL_TRY { computeDiracContributions(); }
1236  PARALLEL_CATCH;
1237 
1239  {
1240  PARALLEL_TRY { enforceNodalConstraintsResidual(*_Re_non_time); }
1241  PARALLEL_CATCH;
1242  _Re_non_time->close();
1243  }
1244 
1245  // Add in Residual contributions from Constraints
1247  {
1248  PARALLEL_TRY
1249  {
1250  // Undisplaced Constraints
1252 
1253  // Displaced Constraints
1256  }
1257  PARALLEL_CATCH;
1258  _Re_non_time->close();
1259  }
1260 }
ConstElemRange * getActiveLocalElementRange()
Return pointers to range objects for various types of ranges (local nodes, boundary elems...
Definition: MooseMesh.C:724
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
MooseObjectWarehouse< NodalBC > _nodal_bcs
MooseObjectWarehouse< NodalDamper > _nodal_dampers
Nodal Dampers for each thread.
ConstNodeRange * getLocalNodeRange()
Definition: MooseMesh.C:753
virtual void addResidualScalar(THREAD_ID tid=0)
MooseObjectWarehouse< ScalarKernel > _time_scalar_kernels
void constraintResiduals(NumericVector< Number > &residual, bool displaced)
Add residual contributions from Constraints.
MooseObjectWarehouse< NodalKernel > _nodal_kernels
NodalKernels for each thread.
bool _need_residual_ghosted
Whether or not a ghosted copy of the residual needs to be made.
NumericVector< Number > & _residual_copy
Copy of the residual vector.
bool _doing_dg
true if DG is active (optimization reasons)
FEProblemBase & _fe_problem
MooseObjectWarehouse< ScalarKernel > _non_time_scalar_kernels
virtual std::shared_ptr< DisplacedProblem > getDisplacedProblem()
virtual void addCachedResidual(THREAD_ID tid) override
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
MooseObjectWarehouse< InterfaceKernel > _interface_kernels
DofMap & dof_map
PerfLog perf_log
Perflog to be used by applications.
MooseObjectWarehouse< ScalarKernel > _scalar_kernels
bool hasActiveObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
virtual void residualSetup(THREAD_ID tid=0) const
MooseObjectWarehouse< DGKernel > _dg_kernels
ConstraintWarehouse _constraints
Constraints storage object.
KernelWarehouse _kernels
MooseObjectWarehouse< DiracKernel > _dirac_kernels
Dirac Kernel storage for each thread.
MatType type
virtual void reinitScalars(THREAD_ID tid) override
MooseMesh & _mesh
Definition: SystemBase.h:483
bool _need_residual_copy
Whether or not a copy of the residual needs to be made.
MooseObjectWarehouse< ElementDamper > _element_dampers
Element Dampers for each thread.
NumericVector< Number > * _residual_ghosted
ghosted form of the residual
bool hasActiveBlockObjects(THREAD_ID tid=0) const
MooseObjectWarehouse< IntegratedBC > _integrated_bcs
bool _has_constraints
Whether or not this system has any Constraints.
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > ConstBndNodeRange
Some useful StoredRange typedefs.
Definition: MooseMesh.h:1213
virtual void reinitNode(const Node *node, THREAD_ID tid) override
void enforceNodalConstraintsResidual(NumericVector< Number > &residual)
Enforce nodal constraints.
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread...
MooseObjectWarehouse< GeneralDamper > _general_dampers
General Dampers.
StoredRange< MooseMesh::const_bnd_node_iterator, const BndNode * > * getBoundaryNodeRange()
Definition: MooseMesh.C:763
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void computeDiracContributions(SparseMatrix< Number > *jacobian=NULL)
void NonlinearSystemBase::computeScalarKernelsJacobians ( SparseMatrix< Number > &  jacobian)
protected

Definition at line 1781 of file NonlinearSystemBase.C.

Referenced by computeJacobianInternal().

1782 {
1783  // Compute the diagonal block for scalar variables
1785  {
1786  const auto & scalars = _scalar_kernels.getActiveObjects();
1787 
1788  _fe_problem.reinitScalars(/*tid=*/0);
1789 
1790  bool have_scalar_contributions = false;
1791  for (const auto & kernel : scalars)
1792  {
1793  kernel->reinit();
1794  const std::vector<dof_id_type> & dof_indices = kernel->variable().dofIndices();
1795  const DofMap & dof_map = kernel->variable().dofMap();
1796  const dof_id_type first_dof = dof_map.first_dof();
1797  const dof_id_type end_dof = dof_map.end_dof();
1798  for (dof_id_type dof : dof_indices)
1799  {
1800  if (dof >= first_dof && dof < end_dof)
1801  {
1802  kernel->computeJacobian();
1803  _fe_problem.addJacobianOffDiagScalar(jacobian, kernel->variable().number());
1804  have_scalar_contributions = true;
1805  break;
1806  }
1807  }
1808  }
1809 
1810  if (have_scalar_contributions)
1811  _fe_problem.addJacobianScalar(jacobian);
1812  }
1813 }
virtual void addJacobianOffDiagScalar(SparseMatrix< Number > &jacobian, unsigned int ivar, THREAD_ID tid=0)
FEProblemBase & _fe_problem
virtual void addJacobianScalar(SparseMatrix< Number > &jacobian, THREAD_ID tid=0)
DofMap & dof_map
MooseObjectWarehouse< ScalarKernel > _scalar_kernels
bool hasActiveObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
virtual void reinitScalars(THREAD_ID tid) override
const std::vector< std::shared_ptr< T > > & getActiveObjects(THREAD_ID tid=0) const
Retrieve complete vector to the active all/block/boundary restricted objects for a given thread...
void NonlinearSystemBase::computeTimeDerivatives ( )

Computes the time derivative vector.

Definition at line 692 of file NonlinearSystemBase.C.

693 {
694  if (_time_integrator)
695  {
696  _time_integrator->preStep();
697  _time_integrator->computeTimeDerivatives();
698  }
699 }
std::shared_ptr< TimeIntegrator > _time_integrator
Time integrator.
virtual void SystemBase::computeVariables ( const NumericVector< Number > &  )
inlinevirtualinherited

Definition at line 468 of file SystemBase.h.

468 {};
virtual bool NonlinearSystemBase::computingInitialResidual ( )
inlinevirtual

Returns true if this system is currently computing the initial residual for a solve.

Returns
Whether or not we are currently computing the initial residual.

Definition at line 90 of file NonlinearSystemBase.h.

void NonlinearSystemBase::constraintJacobians ( SparseMatrix< Number > &  jacobian,
bool  displaced 
)

Add jacobian contributions from Constraints.

Parameters
jacobianreference to the Jacobian matrix
displacedControls whether to do the displaced Constraints or non-displaced

Definition at line 1459 of file NonlinearSystemBase.C.

Referenced by computeJacobianInternal().

1460 {
1461 #if PETSC_VERSION_LESS_THAN(3, 3, 0)
1462 #else
1464  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
1465  MAT_NEW_NONZERO_ALLOCATION_ERR,
1466  PETSC_FALSE);
1468  MatSetOption(
1469  static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE);
1470 #endif
1471 
1472  std::vector<numeric_index_type> zero_rows;
1473  std::map<std::pair<unsigned int, unsigned int>, PenetrationLocator *> * penetration_locators =
1474  NULL;
1475 
1476  if (!displaced)
1477  {
1478  GeometricSearchData & geom_search_data = _fe_problem.geomSearchData();
1479  penetration_locators = &geom_search_data._penetration_locators;
1480  }
1481  else
1482  {
1483  GeometricSearchData & displaced_geom_search_data =
1484  _fe_problem.getDisplacedProblem()->geomSearchData();
1485  penetration_locators = &displaced_geom_search_data._penetration_locators;
1486  }
1487 
1488  bool constraints_applied;
1490  constraints_applied = false;
1491  for (const auto & it : *penetration_locators)
1492  {
1494  {
1495  // Reset the constraint_applied flag before each new constraint, as they need to be assembled
1496  // separately
1497  constraints_applied = false;
1498  }
1499  PenetrationLocator & pen_loc = *(it.second);
1500 
1501  std::vector<dof_id_type> & slave_nodes = pen_loc._nearest_node._slave_nodes;
1502 
1503  BoundaryID slave_boundary = pen_loc._slave_boundary;
1504 
1505  zero_rows.clear();
1506  if (_constraints.hasActiveNodeFaceConstraints(slave_boundary, displaced))
1507  {
1508  const auto & constraints =
1509  _constraints.getActiveNodeFaceConstraints(slave_boundary, displaced);
1510 
1511  for (const auto & slave_node_num : slave_nodes)
1512  {
1513  Node & slave_node = _mesh.nodeRef(slave_node_num);
1514 
1515  if (slave_node.processor_id() == processor_id())
1516  {
1517  if (pen_loc._penetration_info[slave_node_num])
1518  {
1519  PenetrationInfo & info = *pen_loc._penetration_info[slave_node_num];
1520 
1521  const Elem * master_elem = info._elem;
1522  unsigned int master_side = info._side_num;
1523 
1524  // reinit variables at the node
1525  _fe_problem.reinitNodeFace(&slave_node, slave_boundary, 0);
1526 
1529 
1530  std::vector<Point> points;
1531  points.push_back(info._closest_point);
1532 
1533  // reinit variables on the master element's face at the contact point
1534  _fe_problem.setNeighborSubdomainID(master_elem, 0);
1535  _fe_problem.reinitNeighborPhys(master_elem, master_side, points, 0);
1536  for (const auto & nfc : constraints)
1537  {
1538  nfc->_jacobian = &jacobian;
1539 
1540  if (nfc->shouldApply())
1541  {
1542  constraints_applied = true;
1543 
1544  nfc->subProblem().prepareShapes(nfc->variable().number(), 0);
1545  nfc->subProblem().prepareNeighborShapes(nfc->variable().number(), 0);
1546 
1547  nfc->computeJacobian();
1548 
1549  if (nfc->overwriteSlaveJacobian())
1550  {
1551  // Add this variable's dof's row to be zeroed
1552  zero_rows.push_back(nfc->variable().nodalDofIndex());
1553  }
1554 
1555  std::vector<dof_id_type> slave_dofs(1, nfc->variable().nodalDofIndex());
1556 
1557  // Cache the jacobian block for the slave side
1559  slave_dofs,
1560  nfc->_connected_dof_indices,
1561  nfc->variable().scalingFactor());
1562 
1563  // Cache the jacobian block for the master side
1564  if (nfc->addCouplingEntriesToJacobian())
1566  nfc->_Kne,
1567  nfc->masterVariable().dofIndicesNeighbor(),
1568  nfc->_connected_dof_indices,
1569  nfc->variable().scalingFactor());
1570 
1572  if (nfc->addCouplingEntriesToJacobian())
1574 
1575  // Do the off-diagonals next
1576  const std::vector<MooseVariable *> coupled_vars = nfc->getCoupledMooseVars();
1577  for (const auto & jvar : coupled_vars)
1578  {
1579  // Only compute jacobians for nonlinear variables
1580  if (jvar->kind() != Moose::VAR_NONLINEAR)
1581  continue;
1582 
1583  // Only compute Jacobian entries if this coupling is being used by the
1584  // preconditioner
1585  if (nfc->variable().number() == jvar->number() ||
1586  !_fe_problem.areCoupled(nfc->variable().number(), jvar->number()))
1587  continue;
1588 
1589  // Need to zero out the matrices first
1591 
1592  nfc->subProblem().prepareShapes(nfc->variable().number(), 0);
1593  nfc->subProblem().prepareNeighborShapes(jvar->number(), 0);
1594 
1595  nfc->computeOffDiagJacobian(jvar->number());
1596 
1597  // Cache the jacobian block for the slave side
1599  slave_dofs,
1600  nfc->_connected_dof_indices,
1601  nfc->variable().scalingFactor());
1602 
1603  // Cache the jacobian block for the master side
1604  if (nfc->addCouplingEntriesToJacobian())
1606  nfc->variable().dofIndicesNeighbor(),
1607  nfc->_connected_dof_indices,
1608  nfc->variable().scalingFactor());
1609 
1611  if (nfc->addCouplingEntriesToJacobian())
1613  }
1614  }
1615  }
1616  }
1617  }
1618  }
1619  }
1621  {
1622  // See if constraints were applied anywhere
1623  _communicator.max(constraints_applied);
1624 
1625  if (constraints_applied)
1626  {
1627 #ifdef LIBMESH_HAVE_PETSC
1628 // Necessary for speed
1629 #if PETSC_VERSION_LESS_THAN(3, 0, 0)
1630  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS);
1631 #elif PETSC_VERSION_LESS_THAN(3, 1, 0)
1632  // In Petsc 3.0.0, MatSetOption has three args...the third arg
1633  // determines whether the option is set (true) or unset (false)
1634  MatSetOption(
1635  static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS, PETSC_TRUE);
1636 #else
1637  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
1638  MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
1639  PETSC_TRUE);
1640 #endif
1641 #endif
1642 
1643  jacobian.close();
1644  jacobian.zero_rows(zero_rows, 0.0);
1645  jacobian.close();
1646  _fe_problem.addCachedJacobian(jacobian, 0);
1647  jacobian.close();
1648  }
1649  }
1650  }
1652  {
1653  // See if constraints were applied anywhere
1654  _communicator.max(constraints_applied);
1655 
1656  if (constraints_applied)
1657  {
1658 #ifdef LIBMESH_HAVE_PETSC
1659 // Necessary for speed
1660 #if PETSC_VERSION_LESS_THAN(3, 0, 0)
1661  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS);
1662 #elif PETSC_VERSION_LESS_THAN(3, 1, 0)
1663  // In Petsc 3.0.0, MatSetOption has three args...the third arg
1664  // determines whether the option is set (true) or unset (false)
1665  MatSetOption(
1666  static_cast<PetscMatrix<Number> &>(jacobian).mat(), MAT_KEEP_ZEROED_ROWS, PETSC_TRUE);
1667 #else
1668  MatSetOption(static_cast<PetscMatrix<Number> &>(jacobian).mat(),
1669  MAT_KEEP_NONZERO_PATTERN, // This is changed in 3.1
1670  PETSC_TRUE);
1671 #endif
1672 #endif
1673 
1674  jacobian.close();
1675  jacobian.zero_rows(zero_rows, 0.0);
1676  jacobian.close();
1677  _fe_problem.addCachedJacobian(jacobian, 0);
1678  jacobian.close();
1679  }
1680  }
1681 
1682  THREAD_ID tid = 0;
1683  // go over mortar interfaces
1684  auto & ifaces = _mesh.getMortarInterfaces();
1685  for (const auto & iface : ifaces)
1686  {
1687  if (_constraints.hasActiveFaceFaceConstraints(iface->_name))
1688  {
1689  // FaceFaceConstraint objects
1690  const auto & face_constraints = _constraints.getActiveFaceFaceConstraints(iface->_name);
1691 
1692  // go over elements on that interface
1693  const std::vector<Elem *> & elems = iface->_elems;
1694  for (const auto & elem : elems)
1695  {
1696  // for each element process constraints on the
1697  for (const auto & ffc : face_constraints)
1698  {
1700  _fe_problem.prepare(elem, tid);
1701  _fe_problem.reinitElem(elem, tid);
1702  ffc->reinit();
1703  ffc->subProblem().prepareShapes(ffc->variable().number(), tid);
1704  ffc->computeJacobian();
1706 
1707  ffc->reinitSide(Moose::Master);
1708  ffc->computeJacobianSide(Moose::Master);
1710 
1711  ffc->reinitSide(Moose::Slave);
1712  ffc->computeJacobianSide(Moose::Slave);
1714  }
1715 
1716  _fe_problem.addCachedJacobian(jacobian, tid);
1717  }
1718  }
1719  }
1720 
1721  // go over element-element constraint interface
1722  std::map<unsigned int, std::shared_ptr<ElementPairLocator>> * element_pair_locators = nullptr;
1723 
1724  if (!displaced)
1725  {
1726  GeometricSearchData & geom_search_data = _fe_problem.geomSearchData();
1727  element_pair_locators = &geom_search_data._element_pair_locators;
1728  }
1729  else
1730  {
1731  GeometricSearchData & displaced_geom_search_data =
1732  _fe_problem.getDisplacedProblem()->geomSearchData();
1733  element_pair_locators = &displaced_geom_search_data._element_pair_locators;
1734  }
1735 
1736  for (const auto & it : *element_pair_locators)
1737  {
1738  ElementPairLocator & elem_pair_loc = *(it.second);
1739 
1741  {
1742  // ElemElemConstraint objects
1743  const auto & _element_constraints = _constraints.getActiveElemElemConstraints(it.first);
1744 
1745  // go over pair elements
1746  const std::list<std::pair<const Elem *, const Elem *>> & elem_pairs =
1747  elem_pair_loc.getElemPairs();
1748  for (const auto & pr : elem_pairs)
1749  {
1750  const Elem * elem1 = pr.first;
1751  const Elem * elem2 = pr.second;
1752 
1753  if (elem1->processor_id() != processor_id())
1754  continue;
1755 
1756  const ElementPairInfo & info = elem_pair_loc.getElemPairInfo(pr);
1757 
1758  // for each element process constraints on the
1759  for (const auto & ec : _element_constraints)
1760  {
1761  _fe_problem.setCurrentSubdomainID(elem1, tid);
1763  _fe_problem.setNeighborSubdomainID(elem2, tid);
1765 
1766  ec->subProblem().prepareShapes(ec->variable().number(), tid);
1767  ec->subProblem().prepareNeighborShapes(ec->variable().number(), tid);
1768 
1769  ec->reinit(info);
1770  ec->computeJacobian();
1773  }
1774  _fe_problem.addCachedJacobian(jacobian, tid);
1775  }
1776  }
1777  }
1778 }
bool errorOnJacobianNonzeroReallocation()
Will return True if the user wants to get an error when a nonzero is reallocated in the Jacobian by P...
virtual void prepare(const Elem *elem, THREAD_ID tid) override
void cacheJacobianBlock(DenseMatrix< Number > &jac_block, std::vector< dof_id_type > &idof_indices, std::vector< dof_id_type > &jdof_indices, Real scaling_factor)
Definition: Assembly.C:1522
virtual void reinitElemPhys(const Elem *elem, std::vector< Point > phys_points_in_elem, THREAD_ID tid) override
bool _assemble_constraints_separately
Whether or not to assemble the residual and Jacobian after the application of each constraint...
Data structure used to hold penetration information.
virtual Assembly & assembly(THREAD_ID tid) override
bool ignoreZerosInJacobian()
std::map< dof_id_type, PenetrationInfo * > & _penetration_info
Data structure of nodes and their associated penetration information.
virtual void reinitElem(const Elem *elem, THREAD_ID tid) override
virtual GeometricSearchData & geomSearchData() override
std::vector< std::unique_ptr< MooseMesh::MortarInterface > > & getMortarInterfaces()
Definition: MooseMesh.h:805
FEProblemBase & _fe_problem
std::vector< dof_id_type > _slave_nodes
virtual std::shared_ptr< DisplacedProblem > getDisplacedProblem()
std::vector< Point > _elem1_constraint_q_point
const std::vector< std::shared_ptr< ElemElemConstraint > > & getActiveElemElemConstraints(InterfaceID interface_id) const
const Elem * _elem
virtual void cacheJacobian(THREAD_ID tid) override
std::map< unsigned int, std::shared_ptr< ElementPairLocator > > _element_pair_locators
const ElementPairInfo & getElemPairInfo(std::pair< const Elem *, const Elem * > elem_pair) const
unsigned int _side_num
bool areCoupled(unsigned int ivar, unsigned int jvar)
This is the ElementPairLocator class.
This is the ElementPairInfo class.
virtual void addCachedJacobian(SparseMatrix< Number > &jacobian, THREAD_ID tid) override
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, THREAD_ID tid) override
ConstraintWarehouse _constraints
Constraints storage object.
std::map< std::pair< unsigned int, unsigned int >, PenetrationLocator * > _penetration_locators
virtual void prepareAssembly(THREAD_ID tid) override
MooseMesh & _mesh
Definition: SystemBase.h:483
virtual void setCurrentSubdomainID(const Elem *elem, THREAD_ID tid) override
virtual void cacheJacobianNeighbor(THREAD_ID tid) override
bool hasActiveElemElemConstraints(const InterfaceID interface_id) const
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:437
const ElementPairList & getElemPairs() const
std::vector< Point > _elem2_constraint_q_point
const std::vector< std::shared_ptr< FaceFaceConstraint > > & getActiveFaceFaceConstraints(const std::string &interface) const
virtual void reinitOffDiagScalars(THREAD_ID tid) override
bool hasActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
const std::vector< std::shared_ptr< NodeFaceConstraint > > & getActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
bool hasActiveFaceFaceConstraints(const std::string &interface) const
unsigned int THREAD_ID
Definition: MooseTypes.h:79
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
NearestNodeLocator & _nearest_node
virtual void setNeighborSubdomainID(const Elem *elem, unsigned int side, THREAD_ID tid) override
virtual void reinitNeighborPhys(const Elem *neighbor, unsigned int neighbor_side, const std::vector< Point > &physical_points, THREAD_ID tid) override
void NonlinearSystemBase::constraintResiduals ( NumericVector< Number > &  residual,
bool  displaced 
)

Add residual contributions from Constraints.

Parameters
residual- reference to the residual vector where constraint contributions will be computed
displacedControls whether to do the displaced Constraints or non-displaced

Definition at line 833 of file NonlinearSystemBase.C.

Referenced by computeResidualInternal().

834 {
835  // Make sure the residual is in a good state
836  residual.close();
837 
838  std::map<std::pair<unsigned int, unsigned int>, PenetrationLocator *> * penetration_locators =
839  NULL;
840 
841  if (!displaced)
842  {
843  GeometricSearchData & geom_search_data = _fe_problem.geomSearchData();
844  penetration_locators = &geom_search_data._penetration_locators;
845  }
846  else
847  {
848  GeometricSearchData & displaced_geom_search_data =
849  _fe_problem.getDisplacedProblem()->geomSearchData();
850  penetration_locators = &displaced_geom_search_data._penetration_locators;
851  }
852 
853  bool constraints_applied;
854  bool residual_has_inserted_values = false;
856  constraints_applied = false;
857  for (const auto & it : *penetration_locators)
858  {
860  {
861  // Reset the constraint_applied flag before each new constraint, as they need to be assembled
862  // separately
863  constraints_applied = false;
864  }
865  PenetrationLocator & pen_loc = *(it.second);
866 
867  std::vector<dof_id_type> & slave_nodes = pen_loc._nearest_node._slave_nodes;
868 
869  BoundaryID slave_boundary = pen_loc._slave_boundary;
870 
871  if (_constraints.hasActiveNodeFaceConstraints(slave_boundary, displaced))
872  {
873  const auto & constraints =
874  _constraints.getActiveNodeFaceConstraints(slave_boundary, displaced);
875 
876  for (unsigned int i = 0; i < slave_nodes.size(); i++)
877  {
878  dof_id_type slave_node_num = slave_nodes[i];
879  Node & slave_node = _mesh.nodeRef(slave_node_num);
880 
881  if (slave_node.processor_id() == processor_id())
882  {
883  if (pen_loc._penetration_info[slave_node_num])
884  {
885  PenetrationInfo & info = *pen_loc._penetration_info[slave_node_num];
886 
887  const Elem * master_elem = info._elem;
888  unsigned int master_side = info._side_num;
889 
890  // *These next steps MUST be done in this order!*
891 
892  // This reinits the variables that exist on the slave node
893  _fe_problem.reinitNodeFace(&slave_node, slave_boundary, 0);
894 
895  // This will set aside residual and jacobian space for the variables that have dofs on
896  // the slave node
898 
899  std::vector<Point> points;
900  points.push_back(info._closest_point);
901 
902  // reinit variables on the master element's face at the contact point
903  _fe_problem.setNeighborSubdomainID(master_elem, 0);
904  _fe_problem.reinitNeighborPhys(master_elem, master_side, points, 0);
905 
906  for (const auto & nfc : constraints)
907  if (nfc->shouldApply())
908  {
909  constraints_applied = true;
910  nfc->computeResidual();
911 
912  if (nfc->overwriteSlaveResidual())
913  {
914  _fe_problem.setResidual(residual, 0);
915  residual_has_inserted_values = true;
916  }
917  else
920  }
921  }
922  }
923  }
924  }
926  {
927  // Make sure that slave contribution to master are assembled, and ghosts have been exchanged,
928  // as current masters might become slaves on next iteration
929  // and will need to contribute their former slaves' contributions
930  // to the future masters.
931  // See if constraints were applied anywhere
932  _communicator.max(constraints_applied);
933 
934  if (constraints_applied)
935  {
936  // If any of the above constraints inserted values in the residual, it needs to be assembled
937  // before adding the cached residuals below.
938  _communicator.max(residual_has_inserted_values);
939  if (residual_has_inserted_values)
940  {
941  residual.close();
942  residual_has_inserted_values = false;
943  }
945  residual.close();
946 
948  *_residual_ghosted = residual;
949  }
950  }
951  }
953  {
954  _communicator.max(constraints_applied);
955 
956  if (constraints_applied)
957  {
958  // If any of the above constraints inserted values in the residual, it needs to be assembled
959  // before adding the cached residuals below.
960  _communicator.max(residual_has_inserted_values);
961  if (residual_has_inserted_values)
962  residual.close();
963 
965  residual.close();
966 
968  *_residual_ghosted = residual;
969  }
970  }
971 
972  THREAD_ID tid = 0;
973  // go over mortar interfaces
974  auto & ifaces = _mesh.getMortarInterfaces();
975  for (const auto & iface : ifaces)
976  {
977  if (_constraints.hasActiveFaceFaceConstraints(iface->_name))
978  {
979  const auto & face_constraints = _constraints.getActiveFaceFaceConstraints(iface->_name);
980 
981  // go over elements on that interface
982  const std::vector<Elem *> & elems = iface->_elems;
983  for (const auto & elem : elems)
984  {
985  // for each element process constraints on the
987  _fe_problem.prepare(elem, tid);
988  _fe_problem.reinitElem(elem, tid);
989 
990  for (const auto & ffc : face_constraints)
991  {
992  ffc->reinit();
993  ffc->computeResidual();
994  }
996 
997  // evaluate residuals that go into master and slave side
998  for (const auto & ffc : face_constraints)
999  {
1000  ffc->reinitSide(Moose::Master);
1001  ffc->computeResidualSide(Moose::Master);
1003 
1004  ffc->reinitSide(Moose::Slave);
1005  ffc->computeResidualSide(Moose::Slave);
1007  }
1008  }
1010  }
1011  }
1012 
1013  // go over element-element constraint interface
1014  std::map<unsigned int, std::shared_ptr<ElementPairLocator>> * element_pair_locators = nullptr;
1015 
1016  if (!displaced)
1017  {
1018  GeometricSearchData & geom_search_data = _fe_problem.geomSearchData();
1019  element_pair_locators = &geom_search_data._element_pair_locators;
1020  }
1021  else
1022  {
1023  GeometricSearchData & displaced_geom_search_data =
1024  _fe_problem.getDisplacedProblem()->geomSearchData();
1025  element_pair_locators = &displaced_geom_search_data._element_pair_locators;
1026  }
1027 
1028  for (const auto & it : *element_pair_locators)
1029  {
1030  ElementPairLocator & elem_pair_loc = *(it.second);
1031 
1033  {
1034  // ElemElemConstraint objects
1035  const auto & _element_constraints = _constraints.getActiveElemElemConstraints(it.first);
1036 
1037  // go over pair elements
1038  const std::list<std::pair<const Elem *, const Elem *>> & elem_pairs =
1039  elem_pair_loc.getElemPairs();
1040  for (const auto & pr : elem_pairs)
1041  {
1042  const Elem * elem1 = pr.first;
1043  const Elem * elem2 = pr.second;
1044 
1045  if (elem1->processor_id() != processor_id())
1046  continue;
1047 
1048  const ElementPairInfo & info = elem_pair_loc.getElemPairInfo(pr);
1049 
1050  // for each element process constraints on the
1051  for (const auto & ec : _element_constraints)
1052  {
1053  _fe_problem.setCurrentSubdomainID(elem1, tid);
1055  _fe_problem.setNeighborSubdomainID(elem2, tid);
1057 
1058  ec->subProblem().prepareShapes(ec->variable().number(), tid);
1059  ec->subProblem().prepareNeighborShapes(ec->variable().number(), tid);
1060 
1061  ec->reinit(info);
1062  ec->computeResidual();
1065  }
1067  }
1068  }
1069  }
1070 }
virtual void addCachedResidualDirectly(NumericVector< Number > &residual, THREAD_ID tid)
Allows for all the residual contributions that are currently cached to be added directly into the vec...
virtual void prepare(const Elem *elem, THREAD_ID tid) override
virtual void reinitElemPhys(const Elem *elem, std::vector< Point > phys_points_in_elem, THREAD_ID tid) override
bool _assemble_constraints_separately
Whether or not to assemble the residual and Jacobian after the application of each constraint...
Data structure used to hold penetration information.
std::map< dof_id_type, PenetrationInfo * > & _penetration_info
Data structure of nodes and their associated penetration information.
virtual void reinitElem(const Elem *elem, THREAD_ID tid) override
virtual GeometricSearchData & geomSearchData() override
bool _need_residual_ghosted
Whether or not a ghosted copy of the residual needs to be made.
std::vector< std::unique_ptr< MooseMesh::MortarInterface > > & getMortarInterfaces()
Definition: MooseMesh.h:805
FEProblemBase & _fe_problem
std::vector< dof_id_type > _slave_nodes
virtual std::shared_ptr< DisplacedProblem > getDisplacedProblem()
std::vector< Point > _elem1_constraint_q_point
const std::vector< std::shared_ptr< ElemElemConstraint > > & getActiveElemElemConstraints(InterfaceID interface_id) const
const Elem * _elem
virtual void addCachedResidual(THREAD_ID tid) override
std::map< unsigned int, std::shared_ptr< ElementPairLocator > > _element_pair_locators
const ElementPairInfo & getElemPairInfo(std::pair< const Elem *, const Elem * > elem_pair) const
unsigned int _side_num
This is the ElementPairLocator class.
This is the ElementPairInfo class.
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, THREAD_ID tid) override
ConstraintWarehouse _constraints
Constraints storage object.
std::map< std::pair< unsigned int, unsigned int >, PenetrationLocator * > _penetration_locators
virtual void prepareAssembly(THREAD_ID tid) override
MooseMesh & _mesh
Definition: SystemBase.h:483
virtual void setCurrentSubdomainID(const Elem *elem, THREAD_ID tid) override
bool hasActiveElemElemConstraints(const InterfaceID interface_id) const
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:437
NumericVector< Number > * _residual_ghosted
ghosted form of the residual
const ElementPairList & getElemPairs() const
std::vector< Point > _elem2_constraint_q_point
const std::vector< std::shared_ptr< FaceFaceConstraint > > & getActiveFaceFaceConstraints(const std::string &interface) const
virtual void cacheResidual(THREAD_ID tid) override
bool hasActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
const std::vector< std::shared_ptr< NodeFaceConstraint > > & getActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
bool hasActiveFaceFaceConstraints(const std::string &interface) const
unsigned int THREAD_ID
Definition: MooseTypes.h:79
boundary_id_type BoundaryID
Definition: MooseTypes.h:75
NearestNodeLocator & _nearest_node
virtual void setNeighborSubdomainID(const Elem *elem, unsigned int side, THREAD_ID tid) override
virtual void setResidual(NumericVector< Number > &residual, THREAD_ID tid) override
virtual void cacheResidualNeighbor(THREAD_ID tid) override
virtual void reinitNeighborPhys(const Elem *neighbor, unsigned int neighbor_side, const std::vector< Point > &physical_points, THREAD_ID tid) override
bool NonlinearSystemBase::containsTimeKernel ( )

Definition at line 2551 of file NonlinearSystemBase.C.

Referenced by Steady::checkIntegrity(), and EigenExecutionerBase::checkIntegrity().

2552 {
2554 }
bool hasActiveObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
KernelWarehouse _time_kernels
virtual bool NonlinearSystemBase::converged ( )
pure virtual

Returns the convergence state.

Returns
true if converged, otherwise false

Implemented in NonlinearEigenSystem, NonlinearEigenSystem, and NonlinearSystem.

Referenced by DT2::step().

void SystemBase::copyOldSolutions ( )
virtualinherited

Shifts the solutions backwards in time.

Definition at line 693 of file SystemBase.C.

Referenced by EigenExecutionerBase::inversePowerIteration().

694 {
699 }
virtual NumericVector< Number > & solutionOld()=0
virtual NumericVector< Number > * solutionPreviousNewton()=0
virtual NumericVector< Number > & solutionOlder()=0
virtual const NumericVector< Number > *& currentSolution()=0
The solution vector that is currently being operated on.
void SystemBase::copySolutionsBackwards ( )
virtualinherited

Copy current solution into old and older.

Definition at line 680 of file SystemBase.C.

681 {
682  system().update();
687 }
virtual NumericVector< Number > & solutionOld()=0
virtual NumericVector< Number > * solutionPreviousNewton()=0
virtual System & system()=0
Get the reference to the libMesh system.
virtual NumericVector< Number > & solutionOlder()=0
virtual const NumericVector< Number > *& currentSolution()=0
The solution vector that is currently being operated on.
void SystemBase::copyVars ( ExodusII_IO &  io)
inherited

Definition at line 624 of file SystemBase.C.

625 {
626  int n_steps = io.get_num_time_steps();
627 
628  bool did_copy = false;
629  for (std::vector<VarCopyInfo>::iterator it = _var_to_copy.begin(); it != _var_to_copy.end(); ++it)
630  {
631  VarCopyInfo & vci = *it;
632  int timestep = -1;
633 
634  if (vci._timestep == "LATEST")
635  // Use the last time step in the file from which to retrieve the solution
636  timestep = n_steps;
637  else
638  {
639  std::istringstream ss(vci._timestep);
640  if (!((ss >> timestep) && ss.eof()) || timestep > n_steps)
641  mooseError("Invalid value passed as \"initial_from_file_timestep\". Expected \"LATEST\" or "
642  "a valid integer between 1 and ",
643  n_steps,
644  " inclusive, received ",
645  vci._timestep);
646  }
647 
648  did_copy = true;
649  if (getVariable(0, vci._dest_name).isNodal())
650  io.copy_nodal_solution(system(), vci._dest_name, vci._source_name, timestep);
651  else
652  io.copy_elemental_solution(system(), vci._dest_name, vci._source_name, timestep);
653  }
654 
655  if (did_copy)
656  solution().close();
657 }
std::string _source_name
Definition: SystemBase.h:83
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
virtual bool isNodal() const override
Is this variable nodal.
std::vector< VarCopyInfo > _var_to_copy
Definition: SystemBase.h:506
virtual MooseVariable & getVariable(THREAD_ID tid, const std::string &var_name)
Gets a reference to a variable of with specified name.
Definition: SystemBase.C:103
Information about variables that will be copied.
Definition: SystemBase.h:73
std::string _dest_name
Definition: SystemBase.h:82
virtual System & system()=0
Get the reference to the libMesh system.
std::string _timestep
Definition: SystemBase.h:84
virtual NumericVector< Number > & solution()=0
virtual const NumericVector<Number>*& NonlinearSystemBase::currentSolution ( )
inlineoverridevirtual

The solution vector that is currently being operated on.

This is typically a ghosted vector that comes in from the Nonlinear solver.

Implements SystemBase.

Definition at line 333 of file NonlinearSystemBase.h.

Referenced by Transient::keepGoing(), DT2::preSolve(), Transient::relativeSolutionDifferenceNorm(), DT2::step(), AB2PredictorCorrector::step(), DisplacedProblem::syncSolutions(), and DisplacedProblem::updateMesh().

333 { return _current_solution; }
const NumericVector< Number > * _current_solution
solution vector from nonlinear solver
void NonlinearSystemBase::debuggingResiduals ( bool  state)
inline

Definition at line 454 of file NonlinearSystemBase.h.

454 { _debugging_residuals = state; }
bool _debugging_residuals
true if debugging residuals
DofMap & SystemBase::dofMap ( )
virtualinherited
bool NonlinearSystemBase::doingDG ( ) const

Getter for _doing_dg.

Definition at line 2600 of file NonlinearSystemBase.C.

2601 {
2602  return _doing_dg;
2603 }
bool _doing_dg
true if DG is active (optimization reasons)
virtual Number& SystemBase::duDotDu ( )
inlinevirtualinherited
void NonlinearSystemBase::enforceNodalConstraintsJacobian ( SparseMatrix< Number > &  jacobian)
protected

Definition at line 727 of file NonlinearSystemBase.C.

Referenced by computeJacobianInternal().

728 {
729  THREAD_ID tid = 0; // constraints are going to be done single-threaded
730  jacobian.close();
732  {
733  const auto & ncs = _constraints.getActiveNodalConstraints();
734  for (const auto & nc : ncs)
735  {
736  std::vector<dof_id_type> & slave_node_ids = nc->getSlaveNodeId();
737  std::vector<dof_id_type> & master_node_ids = nc->getMasterNodeId();
738 
739  if ((slave_node_ids.size() > 0) && (master_node_ids.size() > 0))
740  {
741  _fe_problem.reinitNodes(master_node_ids, tid);
742  _fe_problem.reinitNodesNeighbor(slave_node_ids, tid);
743  nc->computeJacobian(jacobian);
744  }
745  }
746  _fe_problem.addCachedJacobian(jacobian, tid);
747  jacobian.close();
748  }
749 }
virtual void reinitNodesNeighbor(const std::vector< dof_id_type > &nodes, THREAD_ID tid) override
FEProblemBase & _fe_problem
virtual void addCachedJacobian(SparseMatrix< Number > &jacobian, THREAD_ID tid) override
virtual void reinitNodes(const std::vector< dof_id_type > &nodes, THREAD_ID tid) override
ConstraintWarehouse _constraints
Constraints storage object.
const std::vector< std::shared_ptr< NodalConstraint > > & getActiveNodalConstraints() const
Access methods for active objects.
bool hasActiveNodalConstraints() const
Deterimine if active objects exist.
unsigned int THREAD_ID
Definition: MooseTypes.h:79
void NonlinearSystemBase::enforceNodalConstraintsResidual ( NumericVector< Number > &  residual)
protected

Enforce nodal constraints.

Definition at line 702 of file NonlinearSystemBase.C.

Referenced by computeResidualInternal().

703 {
704  THREAD_ID tid = 0; // constraints are going to be done single-threaded
705  residual.close();
707  {
708  const auto & ncs = _constraints.getActiveNodalConstraints();
709  for (const auto & nc : ncs)
710  {
711  std::vector<dof_id_type> & slave_node_ids = nc->getSlaveNodeId();
712  std::vector<dof_id_type> & master_node_ids = nc->getMasterNodeId();
713 
714  if ((slave_node_ids.size() > 0) && (master_node_ids.size() > 0))
715  {
716  _fe_problem.reinitNodes(master_node_ids, tid);
717  _fe_problem.reinitNodesNeighbor(slave_node_ids, tid);
718  nc->computeResidual(residual);
719  }
720  }
721  _fe_problem.addCachedResidualDirectly(residual, tid);
722  residual.close();
723  }
724 }
virtual void addCachedResidualDirectly(NumericVector< Number > &residual, THREAD_ID tid)
Allows for all the residual contributions that are currently cached to be added directly into the vec...
virtual void reinitNodesNeighbor(const std::vector< dof_id_type > &nodes, THREAD_ID tid) override
FEProblemBase & _fe_problem
virtual void reinitNodes(const std::vector< dof_id_type > &nodes, THREAD_ID tid) override
ConstraintWarehouse _constraints
Constraints storage object.
const std::vector< std::shared_ptr< NodalConstraint > > & getActiveNodalConstraints() const
Access methods for active objects.
bool hasActiveNodalConstraints() const
Deterimine if active objects exist.
unsigned int THREAD_ID
Definition: MooseTypes.h:79
Real NonlinearSystemBase::finalNonlinearResidual ( )
inline

Return the final nonlinear residual.

Definition at line 440 of file NonlinearSystemBase.h.

440 { return _final_residual; }
void NonlinearSystemBase::findImplicitGeometricCouplingEntries ( GeometricSearchData geom_search_data,
std::map< dof_id_type, std::vector< dof_id_type >> &  graph 
)

Finds the implicit sparsity graph between geometrically related dofs.

Definition at line 1331 of file NonlinearSystemBase.C.

Referenced by addImplicitGeometricCouplingEntries(), and augmentSparsity().

1333 {
1334  std::map<std::pair<unsigned int, unsigned int>, NearestNodeLocator *> & nearest_node_locators =
1335  geom_search_data._nearest_node_locators;
1336 
1337  const auto & node_to_elem_map = _mesh.nodeToElemMap();
1338  for (const auto & it : nearest_node_locators)
1339  {
1340  std::vector<dof_id_type> & slave_nodes = it.second->_slave_nodes;
1341 
1342  for (const auto & slave_node : slave_nodes)
1343  {
1344  std::set<dof_id_type> unique_slave_indices;
1345  std::set<dof_id_type> unique_master_indices;
1346 
1347  auto node_to_elem_pair = node_to_elem_map.find(slave_node);
1348  if (node_to_elem_pair != node_to_elem_map.end())
1349  {
1350  const std::vector<dof_id_type> & elems = node_to_elem_pair->second;
1351 
1352  // Get the dof indices from each elem connected to the node
1353  for (const auto & cur_elem : elems)
1354  {
1355  std::vector<dof_id_type> dof_indices;
1356  dofMap().dof_indices(_mesh.elemPtr(cur_elem), dof_indices);
1357 
1358  for (const auto & dof : dof_indices)
1359  unique_slave_indices.insert(dof);
1360  }
1361  }
1362 
1363  std::vector<dof_id_type> master_nodes = it.second->_neighbor_nodes[slave_node];
1364 
1365  for (const auto & master_node : master_nodes)
1366  {
1367  auto master_node_to_elem_pair = node_to_elem_map.find(master_node);
1368  mooseAssert(master_node_to_elem_pair != node_to_elem_map.end(),
1369  "Missing entry in node to elem map");
1370  const std::vector<dof_id_type> & master_node_elems = master_node_to_elem_pair->second;
1371 
1372  // Get the dof indices from each elem connected to the node
1373  for (const auto & cur_elem : master_node_elems)
1374  {
1375  std::vector<dof_id_type> dof_indices;
1376  dofMap().dof_indices(_mesh.elemPtr(cur_elem), dof_indices);
1377 
1378  for (const auto & dof : dof_indices)
1379  unique_master_indices.insert(dof);
1380  }
1381  }
1382 
1383  for (const auto & slave_id : unique_slave_indices)
1384  for (const auto & master_id : unique_master_indices)
1385  {
1386  graph[slave_id].push_back(master_id);
1387  graph[master_id].push_back(slave_id);
1388  }
1389  }
1390  }
1391 
1392  // handle node-to-node constraints
1393  const auto & ncs = _constraints.getActiveNodalConstraints();
1394  for (const auto & nc : ncs)
1395  {
1396  std::vector<dof_id_type> master_dofs;
1397  std::vector<dof_id_type> & master_node_ids = nc->getMasterNodeId();
1398  for (const auto & node_id : master_node_ids)
1399  {
1400  Node * node = _mesh.queryNodePtr(node_id);
1401  if (node && node->processor_id() == this->processor_id())
1402  {
1403  getNodeDofs(node_id, master_dofs);
1404  }
1405  }
1406 
1407  _communicator.allgather(master_dofs);
1408 
1409  std::vector<dof_id_type> slave_dofs;
1410  std::vector<dof_id_type> & slave_node_ids = nc->getSlaveNodeId();
1411  for (const auto & node_id : slave_node_ids)
1412  {
1413  Node * node = _mesh.queryNodePtr(node_id);
1414  if (node && node->processor_id() == this->processor_id())
1415  {
1416  getNodeDofs(node_id, slave_dofs);
1417  }
1418  }
1419 
1420  _communicator.allgather(slave_dofs);
1421 
1422  for (const auto & master_id : master_dofs)
1423  for (const auto & slave_id : slave_dofs)
1424  {
1425  graph[master_id].push_back(slave_id);
1426  graph[slave_id].push_back(master_id);
1427  }
1428  }
1429 
1430  // Make every entry sorted and unique
1431  for (auto & it : graph)
1432  {
1433  std::vector<dof_id_type> & row = it.second;
1434  std::sort(row.begin(), row.end());
1435  std::vector<dof_id_type>::iterator uit = std::unique(row.begin(), row.end());
1436  row.resize(uit - row.begin());
1437  }
1438 }
virtual Elem * elemPtr(const dof_id_type i)
Definition: MooseMesh.C:2115
Finds the nearest node to each node in boundary1 to each node in boundary2 and the other way around...
void getNodeDofs(dof_id_type node_id, std::vector< dof_id_type > &dofs)
virtual const Node * queryNodePtr(const dof_id_type i) const
Definition: MooseMesh.C:473
virtual DofMap & dofMap()
Gets the dof map.
Definition: SystemBase.C:610
ConstraintWarehouse _constraints
Constraints storage object.
MooseMesh & _mesh
Definition: SystemBase.h:483
std::map< std::pair< unsigned int, unsigned int >, NearestNodeLocator * > _nearest_node_locators
const std::vector< std::shared_ptr< NodalConstraint > > & getActiveNodalConstraints() const
Access methods for active objects.
const std::map< dof_id_type, std::vector< dof_id_type > > & nodeToElemMap()
If not already created, creates a map from every node to all elements to which they are connected...
Definition: MooseMesh.C:681
const ConstraintWarehouse& NonlinearSystemBase::getConstraintWarehouse ( )
inline

Definition at line 510 of file NonlinearSystemBase.h.

510 { return _constraints; };
ConstraintWarehouse _constraints
Constraints storage object.
virtual unsigned int NonlinearSystemBase::getCurrentNonlinearIterationNumber ( )
pure virtual

Implemented in NonlinearEigenSystem, and NonlinearSystem.

const MooseObjectWarehouse<DGKernel>& NonlinearSystemBase::getDGKernelWarehouse ( )
inline

Definition at line 497 of file NonlinearSystemBase.h.

497 { return _dg_kernels; }
MooseObjectWarehouse< DGKernel > _dg_kernels
const MooseObjectWarehouse<DiracKernel>& NonlinearSystemBase::getDiracKernelWarehouse ( )
inline

Definition at line 502 of file NonlinearSystemBase.h.

502 { return _dirac_kernels; }
MooseObjectWarehouse< DiracKernel > _dirac_kernels
Dirac Kernel storage for each thread.
const KernelWarehouse& NonlinearSystemBase::getEigenKernelWarehouse ( )
inline
const MooseObjectWarehouse<ElementDamper>& NonlinearSystemBase::getElementDamperWarehouse ( )
inline

Definition at line 505 of file NonlinearSystemBase.h.

Referenced by ComputeElemDampingThread::onElement().

506  {
507  return _element_dampers;
508  }
MooseObjectWarehouse< ElementDamper > _element_dampers
Element Dampers for each thread.
const MooseObjectWarehouse<IntegratedBC>& NonlinearSystemBase::getIntegratedBCWarehouse ( )
inline

Definition at line 504 of file NonlinearSystemBase.h.

504 { return _integrated_bcs; }
MooseObjectWarehouse< IntegratedBC > _integrated_bcs
const MooseObjectWarehouse<InterfaceKernel>& NonlinearSystemBase::getInterfaceKernelWarehouse ( )
inline

Definition at line 498 of file NonlinearSystemBase.h.

499  {
500  return _interface_kernels;
501  }
MooseObjectWarehouse< InterfaceKernel > _interface_kernels
const KernelWarehouse& NonlinearSystemBase::getKernelWarehouse ( )
inline
Order SystemBase::getMinQuadratureOrder ( )
virtualinherited

Get minimal quadrature order needed for integrating variables in this system.

Returns
The minimal order of quadrature

Reimplemented in AuxiliarySystem.

Definition at line 199 of file SystemBase.C.

200 {
201  Order order = CONSTANT;
202  std::vector<MooseVariable *> vars = _vars[0].variables();
203  for (const auto & var : vars)
204  {
205  FEType fe_type = var->feType();
206  if (fe_type.default_quadrature_order() > order)
207  order = fe_type.default_quadrature_order();
208  }
209 
210  return order;
211 }
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
Moose::MooseKSPNormType NonlinearSystemBase::getMooseKSPNormType ( )
inline

Definition at line 469 of file NonlinearSystemBase.h.

Referenced by Moose::PetscSupport::petscSetDefaultKSPNormType().

469 { return _ksp_norm; }
Moose::MooseKSPNormType _ksp_norm
KSP norm type.
const MooseObjectWarehouse<NodalDamper>& NonlinearSystemBase::getNodalDamperWarehouse ( )
inline

Definition at line 509 of file NonlinearSystemBase.h.

Referenced by ComputeNodalDampingThread::onNode().

509 { return _nodal_dampers; }
MooseObjectWarehouse< NodalDamper > _nodal_dampers
Nodal Dampers for each thread.
const MooseObjectWarehouse<NodalKernel>& NonlinearSystemBase::getNodalKernelWarehouse ( THREAD_ID  tid)
void NonlinearSystemBase::getNodeDofs ( dof_id_type  node_id,
std::vector< dof_id_type > &  dofs 
)
protected

Definition at line 1318 of file NonlinearSystemBase.C.

Referenced by findImplicitGeometricCouplingEntries().

1319 {
1320  const Node & node = _mesh.nodeRef(node_id);
1321  unsigned int s = number();
1322  if (node.has_dofs(s))
1323  {
1324  for (unsigned int v = 0; v < nVariables(); v++)
1325  for (unsigned int c = 0; c < node.n_comp(s, v); c++)
1326  dofs.push_back(node.dof_number(s, v, c));
1327  }
1328 }
virtual unsigned int number()
Gets the number of this system.
Definition: SystemBase.C:604
MooseMesh & _mesh
Definition: SystemBase.h:483
virtual const Node & nodeRef(const dof_id_type i) const
Definition: MooseMesh.C:437
virtual unsigned int nVariables()
Get the number of variables in this system.
Definition: SystemBase.C:580
const KernelWarehouse& NonlinearSystemBase::getNonEigenKernelWarehouse ( )
inline
const KernelWarehouse& NonlinearSystemBase::getNonTimeKernelWarehouse ( )
inline
Moose::PCSideType NonlinearSystemBase::getPCSide ( )
inline

Definition at line 465 of file NonlinearSystemBase.h.

Referenced by Moose::PetscSupport::petscSetDefaultPCSide().

465 { return _pc_side; }
Moose::PCSideType _pc_side
Preconditioning side.
Predictor* NonlinearSystemBase::getPredictor ( )
inline

Definition at line 459 of file NonlinearSystemBase.h.

Referenced by AB2PredictorCorrector::estimateTimeError().

459 { return _predictor.get(); }
std::shared_ptr< Predictor > _predictor
If predictor is active, this is non-NULL.
MooseVariableScalar & SystemBase::getScalarVariable ( THREAD_ID  tid,
const std::string &  var_name 
)
virtualinherited

Gets a reference to a scalar variable with specified number.

Parameters
tidThread id
var_nameA string which is the name of the variable to get.
Returns
reference the variable (class)

Definition at line 121 of file SystemBase.C.

Referenced by Assembly::addJacobianOffDiagScalar(), IntegratedBC::computeJacobianBlockScalar(), ODEKernel::computeOffDiagJacobian(), Kernel::computeOffDiagJacobianScalar(), and DisplacedProblem::getScalarVariable().

122 {
123  MooseVariableScalar * var = dynamic_cast<MooseVariableScalar *>(_vars[tid].getVariable(var_name));
124  if (var == NULL)
125  mooseError("Scalar variable '" + var_name + "' does not exist in this system");
126  return *var;
127 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
Class for scalar variables (they are different).
MooseVariableScalar & SystemBase::getScalarVariable ( THREAD_ID  tid,
unsigned int  var_number 
)
virtualinherited

Gets a reference to a variable with specified number.

Parameters
tidThread id
var_numberlibMesh variable number
Returns
reference the variable (class)

Definition at line 130 of file SystemBase.C.

131 {
132  MooseVariableScalar * var =
133  dynamic_cast<MooseVariableScalar *>(_vars[tid].getVariable(var_number));
134  if (var == NULL)
135  mooseError("variable #" + Moose::stringify(var_number) + " does not exist in this system");
136  return *var;
137 }
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:66
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
Class for scalar variables (they are different).
const std::vector<MooseVariableScalar *>& SystemBase::getScalarVariables ( THREAD_ID  tid)
inlineinherited
std::shared_ptr< Split > NonlinearSystemBase::getSplit ( const std::string &  name)

Retrieves a split by name.

Parameters
nameThe name of the split

Definition at line 509 of file NonlinearSystemBase.C.

Referenced by Split::setup(), and setupFieldDecomposition().

510 {
511  return _splits.getActiveObject(name);
512 }
std::shared_ptr< T > getActiveObject(const std::string &name, THREAD_ID tid=0) const
virtual const std::string & name()
Definition: SystemBase.h:453
MooseObjectWarehouseBase< Split > _splits
Decomposition splits.
const std::set<SubdomainID>& SystemBase::getSubdomainsForVar ( unsigned int  var_number) const
inlineinherited

Definition at line 427 of file SystemBase.h.

428  {
429  return _var_map.at(var_number);
430  }
std::map< unsigned int, std::set< SubdomainID > > _var_map
Map of variables (variable id -> array of subdomains where it lives)
Definition: SystemBase.h:490
TimeIntegrator* NonlinearSystemBase::getTimeIntegrator ( )
inline

Definition at line 461 of file NonlinearSystemBase.h.

Referenced by DT2::computeDT(), and AB2PredictorCorrector::estimateTimeError().

461 { return _time_integrator.get(); }
std::shared_ptr< TimeIntegrator > _time_integrator
Time integrator.
const KernelWarehouse& NonlinearSystemBase::getTimeKernelWarehouse ( )
inline
MooseVariable & SystemBase::getVariable ( THREAD_ID  tid,
const std::string &  var_name 
)
virtualinherited

Gets a reference to a variable of with specified name.

Parameters
tidThread id
var_namevariable name
Returns
reference the variable (class)

Definition at line 103 of file SystemBase.C.

Referenced by AdaptivityAction::act(), Assembly::addJacobianBlock(), Assembly::addJacobianBlockNonlocal(), Assembly::addJacobianNeighbor(), NonlocalIntegratedBC::computeJacobianBlock(), NonlocalKernel::computeNonlocalOffDiagJacobian(), NonlocalIntegratedBC::computeNonlocalOffDiagJacobian(), NonlocalKernel::computeOffDiagJacobian(), Assembly::copyFaceShapes(), Assembly::copyNeighborShapes(), Assembly::copyShapes(), SystemBase::copyVars(), FieldSplitPreconditioner::FieldSplitPreconditioner(), FiniteDifferencePreconditioner::FiniteDifferencePreconditioner(), NodeFaceConstraint::getConnectedDofIndices(), Marker::getMarkerValue(), DisplacedProblem::getVariable(), NodalNormalsPreprocessor::initialize(), FDKernel::perturbedResidual(), PhysicsBasedPreconditioner::PhysicsBasedPreconditioner(), AddPeriodicBCAction::setPeriodicVars(), SingleMatrixPreconditioner::SingleMatrixPreconditioner(), and UpdateErrorVectorsThread::UpdateErrorVectorsThread().

104 {
105  MooseVariable * var = dynamic_cast<MooseVariable *>(_vars[tid].getVariable(var_name));
106  if (var == NULL)
107  mooseError("Variable '" + var_name + "' does not exist in this system");
108  return *var;
109 }
Class for stuff related to variables.
Definition: MooseVariable.h:43
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
MooseVariable & SystemBase::getVariable ( THREAD_ID  tid,
unsigned int  var_number 
)
virtualinherited

Gets a reference to a variable with specified number.

Parameters
tidThread id
var_numberlibMesh variable number
Returns
reference the variable (class)

Definition at line 112 of file SystemBase.C.

113 {
114  MooseVariable * var = dynamic_cast<MooseVariable *>(_vars[tid].getVariable(var_number));
115  if (var == NULL)
116  mooseError("variable #" + Moose::stringify(var_number) + " does not exist in this system");
117  return *var;
118 }
Class for stuff related to variables.
Definition: MooseVariable.h:43
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
std::string stringify(const T &t)
conversion to string
Definition: Conversion.h:66
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
const std::set< SubdomainID > * SystemBase::getVariableBlocks ( unsigned int  var_number)
virtualinherited

Get the block where a variable of this system is defined.

Parameters
var_numberThe number of the variable
Returns
the set of subdomain ids where the variable is active (defined)

Definition at line 140 of file SystemBase.C.

Referenced by PhysicsBasedPreconditioner::addSystem().

141 {
142  mooseAssert(_var_map.find(var_number) != _var_map.end(), "Variable does not exist.");
143  if (_var_map[var_number].empty())
144  return NULL;
145  else
146  return &_var_map[var_number];
147 }
std::map< unsigned int, std::set< SubdomainID > > _var_map
Map of variables (variable id -> array of subdomains where it lives)
Definition: SystemBase.h:490
const std::vector<dof_id_type>& NonlinearSystemBase::getVariableGlobalDoFs ( )
inline

Definition at line 270 of file NonlinearSystemBase.h.

270 { return _var_all_dof_indices; }
std::vector< dof_id_type > _var_all_dof_indices
const std::vector<VariableName>& SystemBase::getVariableNames ( ) const
inlineinherited

Definition at line 466 of file SystemBase.h.

Referenced by MooseEigenSystem::buildSystemDoFIndices(), checkKernelCoverage(), and AddPeriodicBCAction::setPeriodicVars().

466 { return _vars[0].names(); };
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
const std::vector<MooseVariable *>& SystemBase::getVariables ( THREAD_ID  tid)
inlineinherited
NumericVector< Number > & SystemBase::getVector ( const std::string &  name)
virtualinherited

Get a raw NumericVector.

Get a raw NumericVector with the given name.

Reimplemented in DisplacedSystem.

Definition at line 598 of file SystemBase.C.

Referenced by AuxiliarySystem::addVector(), SystemBase::addVector(), computeResidual(), DisplacedSystem::getVector(), and Transient::solveStep().

599 {
600  return system().get_vector(name);
601 }
virtual const std::string & name()
Definition: SystemBase.h:453
virtual System & system()=0
Get the reference to the libMesh system.
bool NonlinearSystemBase::hasDiagSaveIn ( ) const
inline

Weather or not the nonlinear system has diagonal Jacobian save-ins.

Definition at line 521 of file NonlinearSystemBase.h.

Referenced by computeJacobianInternal().

bool _has_nodalbc_diag_save_in
If there is a nodal BC having diag_save_in.
bool _has_diag_save_in
If there is any Kernel or IntegratedBC having diag_save_in.
bool NonlinearSystemBase::hasResidualVector ( Moose::KernelType  type) const
overridevirtual

Reimplemented from SystemBase.

Definition at line 675 of file NonlinearSystemBase.C.

Referenced by DisplacedProblem::addResidual(), and DisplacedProblem::addResidualNeighbor().

676 {
677  switch (type)
678  {
679  case Moose::KT_TIME:
680  return _Re_time;
681  case Moose::KT_NONTIME:
682  return _Re_non_time;
683  case Moose::KT_ALL:
684  return _Re_non_time;
685 
686  default:
687  mooseError("Trying to get residual vector that is not available");
688  }
689 }
NumericVector< Number > * _Re_time
residual vector for time contributions
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
void mooseError(Args &&...args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:182
MatType type
bool NonlinearSystemBase::hasSaveIn ( ) const
inline

Weather or not the nonlinear system has save-ins.

Definition at line 516 of file NonlinearSystemBase.h.

Referenced by computeResidual().

516 { return _has_save_in || _has_nodalbc_save_in; }
bool _has_nodalbc_save_in
If there is a nodal BC having save_in.
bool _has_save_in
If there is any Kernel or IntegratedBC having save_in.
bool SystemBase::hasScalarVariable ( const std::string &  var_name)
virtualinherited

Definition at line 565 of file SystemBase.C.

Referenced by ComputeFullJacobianThread::computeFaceJacobian(), ComputeFullJacobianThread::computeJacobian(), DisplacedProblem::getScalarVariable(), and DisplacedProblem::hasScalarVariable().

566 {
567  if (system().has_variable(var_name))
568  return system().variable_type(var_name).family == SCALAR;
569  else
570  return false;
571 }
virtual System & system()=0
Get the reference to the libMesh system.
bool SystemBase::hasVariable ( const std::string &  var_name)
virtualinherited

Query a system for a variable.

Parameters
var_namename of the variable
Returns
true if the variable exists

Definition at line 556 of file SystemBase.C.

Referenced by DGKernel::DGKernel(), FEProblemBase::duplicateVariableCheck(), DisplacedProblem::getSystem(), DisplacedProblem::getVariable(), DisplacedProblem::hasVariable(), InterfaceKernel::InterfaceKernel(), and KernelBase::KernelBase().

557 {
558  if (system().has_variable(var_name))
559  return system().variable_type(var_name).family != SCALAR;
560  else
561  return false;
562 }
virtual System & system()=0
Get the reference to the libMesh system.
bool SystemBase::hasVector ( const std::string &  name)
virtualinherited

Check if the named vector exists in the system.

Definition at line 589 of file SystemBase.C.

Referenced by AuxiliarySystem::addVector(), SystemBase::addVector(), and computeResidual().

590 {
591  return system().have_vector(name);
592 }
virtual const std::string & name()
Definition: SystemBase.h:453
virtual System & system()=0
Get the reference to the libMesh system.
bool NonlinearSystemBase::haveFieldSplitPreconditioner ( )
inline

Definition at line 100 of file NonlinearSystemBase.h.

Referenced by Moose::PetscSupport::petscSetOptions().

bool _use_field_split_preconditioner
Whether or not to use a FieldSplitPreconditioner matrix based on the decomposition.
bool NonlinearSystemBase::haveFiniteDifferencedPreconditioner ( )
inline

Definition at line 99 of file NonlinearSystemBase.h.

bool _use_finite_differenced_preconditioner
Whether or not to use a finite differenced preconditioner.
void NonlinearSystemBase::init ( )
overridevirtual

Initialize the system.

Reimplemented from SystemBase.

Definition at line 157 of file NonlinearSystemBase.C.

158 {
159  if (_fe_problem.hasDampers())
160  setupDampers();
161 
162  _current_solution = _sys.current_local_solution.get();
163 
165  _serialized_solution.init(_sys.n_dofs(), false, SERIAL);
166 
168  _residual_copy.init(_sys.n_dofs(), false, SERIAL);
169 }
void setupDampers()
Setup damping stuff (called before we actually start)
NumericVector< Number > & _serialized_solution
Serialized version of the solution vector.
bool hasDampers()
Whether or not this system has dampers.
NumericVector< Number > & _residual_copy
Copy of the residual vector.
FEProblemBase & _fe_problem
bool _need_serialized_solution
Whether or not a copy of the residual needs to be made.
bool _need_residual_copy
Whether or not a copy of the residual needs to be made.
const NumericVector< Number > * _current_solution
solution vector from nonlinear solver
virtual void SystemBase::initializeObjects ( )
inlinevirtualinherited

Called only once, just before the solve begins so objects can do some precalculations.

Definition at line 124 of file SystemBase.h.

124 {};
void NonlinearSystemBase::initialSetup ( )
virtual

Definition at line 195 of file NonlinearSystemBase.C.

196 {
197  for (THREAD_ID tid = 0; tid < libMesh::n_threads(); tid++)
198  {
199  _kernels.initialSetup(tid);
202  if (_doing_dg)
208  }
213 }
MooseObjectWarehouse< NodalBC > _nodal_bcs
MooseObjectWarehouse< NodalDamper > _nodal_dampers
Nodal Dampers for each thread.
MooseObjectWarehouse< NodalKernel > _nodal_kernels
NodalKernels for each thread.
bool _doing_dg
true if DG is active (optimization reasons)
MooseObjectWarehouse< InterfaceKernel > _interface_kernels
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
MooseObjectWarehouse< ScalarKernel > _scalar_kernels
MooseObjectWarehouse< DGKernel > _dg_kernels
ConstraintWarehouse _constraints
Constraints storage object.
KernelWarehouse _kernels
MooseObjectWarehouse< DiracKernel > _dirac_kernels
Dirac Kernel storage for each thread.
MooseObjectWarehouse< ElementDamper > _element_dampers
Element Dampers for each thread.
MooseObjectWarehouse< IntegratedBC > _integrated_bcs
MooseObjectWarehouse< GeneralDamper > _general_dampers
General Dampers.
unsigned int THREAD_ID
Definition: MooseTypes.h:79
bool SystemBase::isScalarVariable ( unsigned int  var_name)
virtualinherited

Definition at line 574 of file SystemBase.C.

Referenced by ODEKernel::computeOffDiagJacobian().

575 {
576  return (system().variable(var_num).type().family == SCALAR);
577 }
virtual System & system()=0
Get the reference to the libMesh system.
MatType type
virtual MooseMesh& SystemBase::mesh ( )
inlinevirtualinherited
virtual const std::string& SystemBase::name ( )
inlinevirtualinherited
bool NonlinearSystemBase::needMaterialOnSide ( BoundaryID  bnd_id,
THREAD_ID  tid 
) const

Indicated whether this system needs material properties on boundaries.

Returns
Boolean if IntegratedBCs are active

Definition at line 2589 of file NonlinearSystemBase.C.

2590 {
2591  return _integrated_bcs.hasActiveBoundaryObjects(bnd_id, tid);
2592 }
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
MooseObjectWarehouse< IntegratedBC > _integrated_bcs
bool NonlinearSystemBase::needMaterialOnSide ( SubdomainID  subdomain_id,
THREAD_ID  tid 
) const

Indicates whether this system needs material properties on internal sides.

Returns
Boolean if DGKernels are active

Definition at line 2594 of file NonlinearSystemBase.C.

2595 {
2596  return _doing_dg;
2597 }
bool _doing_dg
true if DG is active (optimization reasons)
unsigned int NonlinearSystemBase::nLinearIterations ( )
inline

Return the number of linear iterations.

Definition at line 430 of file NonlinearSystemBase.h.

Referenced by IterationAdaptiveDT::acceptStep().

430 { return _n_linear_iters; }
unsigned int NonlinearSystemBase::nNonlinearIterations ( )
inline

Return the number of non-linear iterations.

Definition at line 425 of file NonlinearSystemBase.h.

Referenced by IterationAdaptiveDT::acceptStep().

425 { return _n_iters; }
Real NonlinearSystemBase::nonlinearNorm ( )
inline

Return the last nonlinear norm.

Returns
A Real containing the last computed residual norm

Definition at line 446 of file NonlinearSystemBase.h.

Referenced by Console::writeVariableNorms().

446 { return _last_nl_rnorm; }
virtual NonlinearSolver<Number>* NonlinearSystemBase::nonlinearSolver ( )
pure virtual
unsigned int NonlinearSystemBase::nResidualEvaluations ( )
inline

Return the total number of residual evaluations done so far in this calculation.

Definition at line 435 of file NonlinearSystemBase.h.

Referenced by NumResidualEvaluations::getValue().

435 { return _n_residual_evaluations; }
unsigned int _n_residual_evaluations
Total number of residual evaluations that have been performed.
unsigned int SystemBase::number ( )
virtualinherited
unsigned int SystemBase::nVariables ( )
virtualinherited

Get the number of variables in this system.

Returns
the number of variables

Definition at line 580 of file SystemBase.C.

Referenced by AdaptivityAction::act(), FieldSplitPreconditioner::FieldSplitPreconditioner(), FiniteDifferencePreconditioner::FiniteDifferencePreconditioner(), getNodeDofs(), Assembly::init(), PhysicsBasedPreconditioner::PhysicsBasedPreconditioner(), and SingleMatrixPreconditioner::SingleMatrixPreconditioner().

581 {
582  return _vars[0].names().size();
583 }
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
void NonlinearSystemBase::onTimestepBegin ( )

Called at the beginning of the time step.

Definition at line 585 of file NonlinearSystemBase.C.

586 {
587  if (_time_integrator)
588  _time_integrator->preSolve();
589  if (_predictor.get())
590  _predictor->timestepSetup();
591 }
std::shared_ptr< TimeIntegrator > _time_integrator
Time integrator.
std::shared_ptr< Predictor > _predictor
If predictor is active, this is non-NULL.
void SystemBase::prepare ( THREAD_ID  tid)
virtualinherited

Prepare the system for use.

Parameters
tidID of the thread

Definition at line 214 of file SystemBase.C.

Referenced by DisplacedProblem::prepare(), DisplacedProblem::reinitDirac(), and DisplacedProblem::reinitElemPhys().

215 {
217  {
218  const std::set<MooseVariable *> & active_elemental_moose_variables =
220  const std::vector<MooseVariable *> & vars = _vars[tid].variables();
221  for (const auto & var : vars)
222  var->clearDofIndices();
223 
224  for (const auto & var : active_elemental_moose_variables)
225  if (&(var->sys()) == this)
226  var->prepare();
227  }
228  else
229  {
230  const std::vector<MooseVariable *> & vars = _vars[tid].variables();
231  for (const auto & var : vars)
232  var->prepare();
233  }
234 }
virtual bool hasActiveElementalMooseVariables(THREAD_ID tid)
Whether or not a list of active elemental moose variables has been set.
Definition: SubProblem.C:67
SubProblem & _subproblem
Definition: SystemBase.h:478
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
virtual const std::set< MooseVariable * > & getActiveElementalMooseVariables(THREAD_ID tid)
Get the MOOSE variables to be reinited on each element.
Definition: SubProblem.C:61
void SystemBase::prepareFace ( THREAD_ID  tid,
bool  resize_data 
)
virtualinherited

Prepare the system for use on sides.

This will try to reuse the preparation done on the element.

Parameters
tidID of the thread
resize_dataPass True if this system needs to resize residual and jacobian datastructures based on preparing this face

Definition at line 237 of file SystemBase.C.

Referenced by DisplacedProblem::prepareFace().

238 {
240  tid)) // We only need to do something if the element prepare was restricted
241  {
242  const std::set<MooseVariable *> & active_elemental_moose_variables =
244 
245  std::vector<MooseVariable *> newly_prepared_vars;
246 
247  const std::vector<MooseVariable *> & vars = _vars[tid].variables();
248  for (const auto & var : vars)
249  {
250  if (&(var->sys()) == this &&
251  !active_elemental_moose_variables.count(
252  var)) // If it wasnt in the active list we need to prepare it
253  {
254  var->prepare();
255  newly_prepared_vars.push_back(var);
256  }
257  }
258 
259  // Make sure to resize the residual and jacobian datastructures for all the new variables
260  if (resize_data)
261  for (unsigned int i = 0; i < newly_prepared_vars.size(); i++)
262  {
263  _subproblem.assembly(tid).prepareVariable(newly_prepared_vars[i]);
265  _subproblem.assembly(tid).prepareVariableNonlocal(newly_prepared_vars[i]);
266  }
267  }
268 }
virtual Assembly & assembly(THREAD_ID tid)=0
virtual bool hasActiveElementalMooseVariables(THREAD_ID tid)
Whether or not a list of active elemental moose variables has been set.
Definition: SubProblem.C:67
void prepareVariable(MooseVariable *var)
Used for preparing the dense residual and jacobian blocks for one particular variable.
Definition: Assembly.C:1076
SubProblem & _subproblem
Definition: SystemBase.h:478
virtual bool checkNonlocalCouplingRequirement()
Definition: SubProblem.h:62
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
void prepareVariableNonlocal(MooseVariable *var)
Definition: Assembly.C:1098
virtual const std::set< MooseVariable * > & getActiveElementalMooseVariables(THREAD_ID tid)
Get the MOOSE variables to be reinited on each element.
Definition: SubProblem.C:61
void SystemBase::prepareNeighbor ( THREAD_ID  tid)
virtualinherited

Prepare the system for use.

Parameters
tidID of the thread

Definition at line 271 of file SystemBase.C.

Referenced by DisplacedProblem::reinitNeighbor(), and DisplacedProblem::reinitNeighborPhys().

272 {
273  const std::vector<MooseVariable *> & vars = _vars[tid].variables();
274  for (const auto & var : vars)
275  var->prepareNeighbor();
276 }
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
void NonlinearSystemBase::printAllVariableNorms ( bool  state)
inline

Force the printing of all variable norms after each solve.

Definition at line 452 of file NonlinearSystemBase.h.

void SystemBase::reinitElem ( const Elem *  elem,
THREAD_ID  tid 
)
virtualinherited

Reinit an element assembly info.

Parameters
elemWhich element we are reinitializing for
tidID of the thread

Reimplemented in AuxiliarySystem.

Definition at line 279 of file SystemBase.C.

Referenced by DisplacedProblem::reinitElem().

280 {
281 
283  {
284  const std::set<MooseVariable *> & active_elemental_moose_variables =
286  for (const auto & var : active_elemental_moose_variables)
287  if (&(var->sys()) == this)
288  var->computeElemValues();
289  }
290  else
291  {
292  const std::vector<MooseVariable *> & vars = _vars[tid].variables();
293  for (const auto & var : vars)
294  var->computeElemValues();
295  }
296 }
virtual bool hasActiveElementalMooseVariables(THREAD_ID tid)
Whether or not a list of active elemental moose variables has been set.
Definition: SubProblem.C:67
SubProblem & _subproblem
Definition: SystemBase.h:478
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
virtual const std::set< MooseVariable * > & getActiveElementalMooseVariables(THREAD_ID tid)
Get the MOOSE variables to be reinited on each element.
Definition: SubProblem.C:61
void SystemBase::reinitElemFace ( const Elem *  elem,
unsigned int  side,
BoundaryID  bnd_id,
THREAD_ID  tid 
)
virtualinherited

Reinit assembly info for a side of an element.

Parameters
elemThe element
sideSide of of the element
bnd_idBoundary id on that side
tidThread ID

Reimplemented in AuxiliarySystem.

Definition at line 299 of file SystemBase.C.

Referenced by DisplacedProblem::reinitElemFace(), and DisplacedProblem::reinitNeighbor().

303 {
304  const std::vector<MooseVariable *> & vars = _vars[tid].variables();
305  for (const auto & var : vars)
306  var->computeElemValuesFace();
307 }
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Definition: SystemBase.h:488
void NonlinearSystemBase::reinitIncrementAtNodeForDampers ( THREAD_ID  tid,
const std::set< MooseVariable * > &  damped_vars 
)

Compute the incremental change in variables at nodes for dampers.

Called before we use damping

Parameters
tidThread ID
damped_varsSet of variables for which increment is to be computed

Definition at line 2485 of file NonlinearSystemBase.C.

Referenced by ComputeNodalDampingThread::onNode().

2487 {
2488  for (const auto & var : damped_vars)
2489  var->computeIncrementAtNode(*_increment_vec);
2490 }
NumericVector< Number > * _increment_vec
increment vector
void NonlinearSystemBase::reinitIncrementAtQpsForDampers ( THREAD_ID  tid,
const std::set< MooseVariable * > &  damped_vars 
)

Compute the incremental change in variables at QPs for dampers.

Called before we use damping

Parameters
tidThread ID
damped_varsSet of variables for which increment is to be computed

Definition at line 2477 of file NonlinearSystemBase.C.

Referenced by ComputeElemDampingThread::onElement().

2479 {
2480  for (const auto & var : damped_vars)
2481  var->computeIncrementAtQps(*_increment_vec);
2482 }
NumericVector< Number > * _increment_vec
increment vector
void SystemBase::reinitNeighbor ( const Elem *  elem,
THREAD_ID  tid 
)
virtualinherited

Compute the values of the variables at all the curr