88#include "libmesh/nonlinear_solver.h"
89#include "libmesh/quadrature_gauss.h"
90#include "libmesh/dense_vector.h"
91#include "libmesh/boundary_info.h"
92#include "libmesh/petsc_matrix.h"
93#include "libmesh/petsc_vector.h"
94#include "libmesh/petsc_nonlinear_solver.h"
95#include "libmesh/numeric_vector.h"
96#include "libmesh/mesh.h"
97#include "libmesh/dense_subvector.h"
98#include "libmesh/dense_submatrix.h"
99#include "libmesh/dof_map.h"
100#include "libmesh/sparse_matrix.h"
101#include "libmesh/petsc_matrix.h"
102#include "libmesh/default_coupling.h"
103#include "libmesh/diagonal_matrix.h"
104#include "libmesh/fe_interface.h"
105#include "libmesh/petsc_solver_exception.h"
108#include <type_traits>
110#include "petscsnes.h"
121 const std::string & system_name,
122 const unsigned int system_number,
124 std::vector<SetupInterface *> & results)
126 static_assert(std::is_base_of_v<MooseObject, T>);
127 static_assert(std::is_base_of_v<SetupInterface, T>);
129 std::vector<T *> objects;
131 .template condition<AttribSystem>(system_name)
132 .template condition<AttribSysNum>(system_number)
133 .template condition<AttribThread>(tid)
136 for (
auto *
object : objects)
137 results.push_back(
object);
143 const std::string & name)
149 _residual_ghosted(NULL),
152 _Re_non_time_tag(-1),
154 _kernels(numThreads()),
155 _hybridized_kernels(numThreads()),
157 _dg_kernels(numThreads()),
158 _interface_kernels(numThreads()),
159 _integrated_bcs(numThreads()),
161 _preset_nodal_bcs(1),
162 _ad_preset_nodal_bcs(1),
163#ifdef MOOSE_KOKKOS_ENABLED
165 _kokkos_integrated_bcs(1),
166 _kokkos_nodal_bcs(1),
167 _kokkos_preset_nodal_bcs(1),
168 _kokkos_nodal_kernels(1),
170 _dirac_kernels(numThreads()),
171 _element_dampers(numThreads()),
172 _nodal_dampers(numThreads()),
174 _nodal_kernels(numThreads()),
176 _increment_vec(NULL),
177 _use_finite_differenced_preconditioner(false),
178 _fdcoloring(nullptr),
180 _add_implicit_geometric_coupling_entries_to_jacobian(false),
181 _assemble_constraints_separately(false),
182 _need_residual_ghosted(false),
183 _debugging_residuals(false),
187 _n_residual_evaluations(0),
189 _computing_pre_smo_residual(false),
190 _pre_smo_residual(0),
191 _initial_residual(0),
192 _use_pre_smo_residual(false),
193 _print_all_var_norms(false),
195 _has_diag_save_in(false),
196 _has_nodalbc_save_in(false),
197 _has_nodalbc_diag_save_in(false),
198 _computed_scaling(false),
199 _compute_scaling_once(true),
200 _resid_vs_jac_scaling_param(0),
201 _off_diagonals_in_auto_scaling(false),
202 _auto_scaling_initd(false)
220 dof_map.set_implicit_neighbor_dofs(
false);
237#ifdef MOOSE_KOKKOS_ENABLED
252 functor.second.setupMortarMaterials();
254 functor.second.setupMortarMaterials();
264std::vector<SetupInterface *>
267 std::vector<SetupInterface *> fv_objects;
270 appendFVSetupObjects<FVElementalKernel>(
271 warehouse,
"FVElementalKernel",
number(), tid, fv_objects);
272 appendFVSetupObjects<FVFluxKernel>(warehouse,
"FVFluxKernel",
number(), tid, fv_objects);
273 appendFVSetupObjects<FVBoundaryCondition>(warehouse,
"FVDirichletBC",
number(), tid, fv_objects);
274 appendFVSetupObjects<FVBoundaryCondition>(warehouse,
"FVFluxBC",
number(), tid, fv_objects);
275 appendFVSetupObjects<FVInterfaceKernel>(
276 warehouse,
"FVInterfaceKernel",
number(), tid, fv_objects);
284 TIME_SECTION(
"nlInitialSetup", 2,
"Setting Up Nonlinear System");
289 TIME_SECTION(
"kernelsInitialSetup", 2,
"Setting Up Kernels/BCs/Constraints");
306 fv_object->initialSetup();
316#ifdef MOOSE_KOKKOS_ENABLED
325 TIME_SECTION(
"mortarSetup", 2,
"Initializing Mortar Interfaces");
327 auto create_mortar_functors = [
this](
const bool displaced)
331 for (
const auto & [primary_secondary_boundary_pair, interface_config] : mortar_interfaces)
336 auto & mortar_constraints =
342 auto & mortar_functors =
345 mortar_functors.emplace(primary_secondary_boundary_pair,
347 *interface_config.amg,
355 create_mortar_functors(
false);
356 create_mortar_functors(
true);
390 fv_object->timestepSetup();
399#ifdef MOOSE_KOKKOS_ENABLED
426 fv_object->customSetup(exec_type);
435#ifdef MOOSE_KOKKOS_ENABLED
452 const std::string & name,
458 std::shared_ptr<KernelBase> kernel =
466 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
468 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
474 const std::string & name,
491 const std::string & name,
497 std::shared_ptr<NodalKernelBase> kernel =
505 if (parameters.
have_parameter<std::vector<AuxVariableName>>(
"save_in") &&
506 parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
508 if (parameters.
have_parameter<std::vector<AuxVariableName>>(
"save_in") &&
509 parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
515 const std::string & name,
518 std::shared_ptr<ScalarKernelBase> kernel =
528 const std::string & name,
535 std::shared_ptr<BoundaryCondition> bc =
540 const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
542 _vars[tid].addBoundaryVar(boundary_ids, bc_var);
545 std::shared_ptr<NodalBCBase> nbc = std::dynamic_pointer_cast<NodalBCBase>(bc);
546 std::shared_ptr<IntegratedBCBase> ibc = std::dynamic_pointer_cast<IntegratedBCBase>(bc);
551 if (nbc->checkNodalVar() && !nbc->variable().isNodal())
552 mooseError(
"Trying to use nodal boundary condition '",
554 "' on a non-nodal variable '",
555 nbc->variable().name(),
561 _vars[tid].addBoundaryVars(boundary_ids, nbc->getCoupledVars());
563 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
565 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
569 std::shared_ptr<DirichletBCBase> dbc = std::dynamic_pointer_cast<DirichletBCBase>(bc);
570 if (dbc && dbc->preset())
573 std::shared_ptr<ADDirichletBCBase> addbc = std::dynamic_pointer_cast<ADDirichletBCBase>(bc);
574 if (addbc && addbc->preset())
584 _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
586 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
588 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
591 for (tid = 1; tid < this->
numThreads(); tid++)
600 const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
601 _vars[tid].addBoundaryVar(boundary_ids, bc_var);
603 ibc = std::static_pointer_cast<IntegratedBCBase>(bc);
606 _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
611 mooseError(
"Unknown BoundaryCondition type for object named ", bc->name());
616 const std::string & name,
624 if (constraint && constraint->addCouplingEntriesToJacobian())
630 const std::string & name,
635 std::shared_ptr<DiracKernelBase> kernel =
646 const std::string & name,
660 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
662 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
668 const std::string & name,
673 std::shared_ptr<InterfaceKernelBase> interface_kernel =
677 const std::set<BoundaryID> & boundary_ids = interface_kernel->boundaryIDs();
679 _vars[tid].addBoundaryVar(boundary_ids, ik_var);
684 _vars[tid].addBoundaryVars(boundary_ids, interface_kernel->getCoupledVars());
690 const std::string & name,
698 std::shared_ptr<ElementDamper> ed = std::dynamic_pointer_cast<ElementDamper>(damper);
699 std::shared_ptr<NodalDamper> nd = std::dynamic_pointer_cast<NodalDamper>(damper);
700 std::shared_ptr<GeneralDamper> gd = std::dynamic_pointer_cast<GeneralDamper>(damper);
718 const std::string & name,
727std::shared_ptr<Split>
745 if (
_app.
parameters().
get<
bool>(
"use_legacy_initial_residual_evaluation_behavior"))
761 mooseError(
"pre-SMO residual is requested but not evaluated.");
813 parallel_object_only();
815 TIME_SECTION(
"nl::computeResidualTags", 5);
820 bool required_residual = tags.find(
residualVectorTag()) == tags.end() ? false :
true;
832 NumericVector<Number> & vec =
getVector(numeric_vec);
843 if (required_residual)
849 ti->postResidual(residual);
892 const std::set<TagID> & matrix_tags)
894 const bool required_residual =
904 if (required_residual)
910 ti->postResidual(residual);
944 NumericVector<Number> & initial_solution(
solution());
949 TIME_SECTION(
"applyPredictor", 2,
"Applying Predictor");
955 _console <<
" Skipping predictor this step" << std::endl;
960 TIME_SECTION(
"initialBCs", 2,
"Applying BCs To Initial Condition");
963 for (
const auto & bnode : bnd_nodes)
966 Node * node = bnode->_node;
974 if (has_preset_nodal_bcs || has_ad_preset_nodal_bcs)
977 if (has_preset_nodal_bcs)
980 for (
const auto & preset_bc : preset_bcs)
981 preset_bc->computeValue(initial_solution);
983 if (has_ad_preset_nodal_bcs)
986 for (
const auto & preset_bc : preset_bcs_res)
987 preset_bc->computeValue(initial_solution);
993#ifdef MOOSE_KOKKOS_ENABLED
1025NumericVector<Number> &
1048NumericVector<Number> &
1071NumericVector<Number> &
1084 mooseError(
"The required residual vector is not available");
1096 for (
const auto & nc : ncs)
1098 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
1099 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
1101 if ((secondary_node_ids.size() > 0) && (primary_node_ids.size() > 0))
1103 nc->reinitConstraintNodes();
1104 nc->computeResidual(residual);
1123 for (
const auto & nc : ncs)
1125 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
1126 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
1128 if ((secondary_node_ids.size() > 0) && (primary_node_ids.size() > 0))
1130 nc->reinitConstraintNodes();
1131 nc->computeJacobian(jacobian_to_view);
1146 const bool displaced)
1151 const Elem * primary_elem = info._elem;
1152 unsigned int primary_side = info._side_num;
1153 std::vector<Point> points;
1154 points.push_back(info._closest_point);
1175 const Elem *
const undisplaced_primary_elem =
1176 displaced ?
_mesh.
elemPtr(primary_elem->id()) : primary_elem;
1177 const Point undisplaced_primary_physical_point =
1178 [&points, displaced, primary_elem, undisplaced_primary_elem]()
1182 const Point reference_point =
1183 FEMap::inverse_map(primary_elem->dim(), primary_elem, points[0]);
1184 return FEMap::map(primary_elem->dim(), undisplaced_primary_elem, reference_point);
1193 undisplaced_primary_elem, primary_side, {undisplaced_primary_physical_point}, 0);
1210 "If we're calling this method with displaced = true, then we better well have a "
1211 "displaced problem");
1216 bool constraints_applied =
false;
1218 for (
const auto & it : penetration_locators)
1229 const auto & constraints =
1231 std::unordered_set<unsigned int> needed_mat_props;
1232 for (
const auto & constraint : constraints)
1234 const auto & mp_deps = constraint->getMatPropDependencies();
1235 needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
1239 for (
unsigned int i = 0; i < secondary_nodes.size(); i++)
1241 dof_id_type secondary_node_num = secondary_nodes[i];
1242 Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
1250 reinitNodeFace(secondary_node, secondary_boundary, info, displaced);
1252 for (
const auto & nfc : constraints)
1254 if (nfc->isExplicitConstraint())
1260 if (nfc->secondaryBoundary() != secondary_boundary ||
1261 nfc->primaryBoundary() != primary_boundary)
1264 if (nfc->shouldApply())
1266 constraints_applied =
true;
1267 nfc->computeSecondaryValue(
solution);
1270 if (nfc->hasWritableCoupledVariables())
1273 for (
auto * var : nfc->getWritableCoupledVariables())
1275 if (var->isNodalDefined())
1287 std::set<dof_id_type> unique_secondary_node_ids;
1295 const auto & constraints =
1299 unique_secondary_node_ids.clear();
1301 for (
const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
1302 meshhelper.active_subdomain_elements_end(secondary_id)))
1304 for (
auto & n : elem->node_ref_range())
1305 unique_secondary_node_ids.insert(n.id());
1308 for (
auto secondary_node_id : unique_secondary_node_ids)
1310 Node & secondary_node =
_mesh.
nodeRef(secondary_node_id);
1322 for (
const auto & nec : constraints)
1324 if (nec->shouldApply())
1326 constraints_applied =
true;
1327 nec->computeSecondaryValue(
solution);
1339 if (constraints_applied)
1354 "If we're calling this method with displaced = true, then we better well have a "
1355 "displaced problem");
1360 bool constraints_applied;
1361 bool residual_has_inserted_values =
false;
1363 constraints_applied =
false;
1364 for (
const auto & it : penetration_locators)
1370 constraints_applied =
false;
1379 bool has_writable_variables(
false);
1383 const auto & constraints =
1386 for (
unsigned int i = 0; i < secondary_nodes.size(); i++)
1388 dof_id_type secondary_node_num = secondary_nodes[i];
1389 Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
1397 reinitNodeFace(secondary_node, secondary_boundary, info, displaced);
1399 for (
const auto & nfc : constraints)
1405 if (nfc->secondaryBoundary() != secondary_boundary ||
1406 nfc->primaryBoundary() != primary_boundary)
1409 if (nfc->shouldApply())
1411 constraints_applied =
true;
1412 nfc->computeResidual();
1414 if (nfc->overwriteSecondaryResidual())
1420 const auto & secondary_var = nfc->variable();
1421 const auto & secondary_dofs = secondary_var.dofIndices();
1422 mooseAssert(secondary_dofs.size() == secondary_var.count(),
1423 "We are on a node so there should only be one dof per variable (for "
1424 "an ArrayVariable we should have a number of dofs equal to the "
1425 "number of components");
1431 std::vector<Number>
values = {nfc->secondaryResidual()};
1432 residual.insert(
values, secondary_dofs);
1433 residual_has_inserted_values =
true;
1439 if (nfc->hasWritableCoupledVariables())
1442 has_writable_variables =
true;
1443 for (
auto * var : nfc->getWritableCoupledVariables())
1445 if (var->isNodalDefined())
1456 if (has_writable_variables)
1474 if (constraints_applied)
1479 if (residual_has_inserted_values)
1482 residual_has_inserted_values =
false;
1496 if (constraints_applied)
1501 if (residual_has_inserted_values)
1515 for (
const auto & it : element_pair_locators)
1522 const auto & element_constraints =
1526 const std::list<std::pair<const Elem *, const Elem *>> & elem_pairs =
1528 for (
const auto & pr : elem_pairs)
1530 const Elem * elem1 = pr.first;
1531 const Elem * elem2 = pr.second;
1539 for (
const auto & ec : element_constraints)
1546 ec->prepareShapes(ec->variable().number());
1547 ec->prepareNeighborShapes(ec->variable().number());
1550 ec->computeResidual();
1560 std::set<dof_id_type> unique_secondary_node_ids;
1562 constraints_applied =
false;
1563 residual_has_inserted_values =
false;
1564 bool has_writable_variables =
false;
1571 const auto & constraints =
1575 unique_secondary_node_ids.clear();
1577 for (
const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
1578 meshhelper.active_subdomain_elements_end(secondary_id)))
1580 for (
auto & n : elem->node_ref_range())
1581 unique_secondary_node_ids.insert(n.id());
1584 for (
auto secondary_node_id : unique_secondary_node_ids)
1586 Node & secondary_node =
_mesh.
nodeRef(secondary_node_id);
1597 for (
const auto & nec : constraints)
1599 if (nec->shouldApply())
1601 constraints_applied =
true;
1602 nec->computeResidual();
1604 if (nec->overwriteSecondaryResidual())
1607 residual_has_inserted_values =
true;
1613 if (nec->hasWritableCoupledVariables())
1616 has_writable_variables =
true;
1617 for (
auto * var : nec->getWritableCoupledVariables())
1619 if (var->isNodalDefined())
1632 if (constraints_applied)
1637 if (residual_has_inserted_values)
1648 if (has_writable_variables)
1671 for (
const auto & it : penetration_locators)
1681 const auto & constraints =
1683 for (
const auto i : index_range(secondary_nodes))
1685 const auto secondary_node_num = secondary_nodes[i];
1686 const Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
1690 for (
const auto & nfc : constraints)
1692 if (!nfc->isExplicitConstraint())
1699 if (nfc->secondaryBoundary() != secondary_boundary ||
1700 nfc->primaryBoundary() != primary_boundary)
1703 nfc->overwriteBoundaryVariables(soln, secondary_node);
1714 TIME_SECTION(
"residualSetup", 3);
1737#ifdef MOOSE_KOKKOS_ENABLED
1752 parallel_object_only();
1754 TIME_SECTION(
"computeResidualInternal", 3);
1760 std::vector<GeneralUserObject *> uos;
1766 for (
auto & uo : uos)
1767 uo->residualSetup();
1768 for (
auto & uo : uos)
1776 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
1779#ifdef MOOSE_KOKKOS_ENABLED
1787 TIME_SECTION(
"Kernels", 3 );
1798 using FVRange = StoredRange<MooseMesh::const_face_info_iterator, const FaceInfo *>;
1817 for (
unsigned int i = 0; i < n_threads;
1829 TIME_SECTION(
"ScalarKernels", 3 );
1837 else if (tags.size() == 1)
1838 scalar_kernel_warehouse =
1844 bool have_scalar_contributions =
false;
1846 for (
const auto & scalar_kernel : scalars)
1848 scalar_kernel->reinit();
1849 const std::vector<dof_id_type> & dof_indices = scalar_kernel->variable().dofIndices();
1850 const DofMap & dof_map = scalar_kernel->variable().dofMap();
1851 const dof_id_type first_dof = dof_map.first_dof();
1852 const dof_id_type end_dof = dof_map.end_dof();
1853 for (dof_id_type dof : dof_indices)
1855 if (dof >= first_dof && dof < end_dof)
1857 scalar_kernel->computeResidual();
1858 have_scalar_contributions =
true;
1863 if (have_scalar_contributions)
1874 TIME_SECTION(
"NodalKernels", 3 );
1880 if (range.begin() != range.end())
1887 for (
unsigned int i = 0; i < n_threads;
1906 TIME_SECTION(
"NodalKernelBCs", 3 );
1915 for (
unsigned int i = 0; i < n_threads;
1974 const std::set<TagID> & matrix_tags)
1976 TIME_SECTION(
"computeResidualAndJacobianInternal", 3);
1983 "residual_and_jacobian_together does not yet support ScalarKernels. Their "
1984 "contributions would be silently dropped. Please use "
1985 "residual_and_jacobian_together = false");
1989 "residual_and_jacobian_together does not yet support NodalKernels. Their "
1990 "contributions would be silently dropped. Please use "
1991 "residual_and_jacobian_together = false");
1996 "residual_and_jacobian_together does not yet support nodal constraints. Their "
1997 "contributions would be silently dropped. Please use "
1998 "residual_and_jacobian_together = false");
2009 std::vector<UserObject *> uos;
2015 for (
auto & uo : uos)
2016 uo->residualSetup();
2017 for (
auto & uo : uos)
2025 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
2028#ifdef MOOSE_KOKKOS_ENABLED
2042 TIME_SECTION(
"Kernels", 3 );
2049 using FVRange = StoredRange<MooseMesh::const_face_info_iterator, const FaceInfo *>;
2070 for (
unsigned int i = 0; i < n_threads;
2093 for (
const auto & residual_vector_tag : residual_vector_tags)
2103 const std::set<TagID> & tags)
2115#ifdef MOOSE_KOKKOS_ENABLED
2130 else if (tags.size() == 1)
2143 if (!bnd_nodes.
empty())
2145 TIME_SECTION(
"NodalBCs", 3 );
2147 for (
const auto & bnode : bnd_nodes)
2150 Node * node = bnode->_node;
2159 for (
const auto & nbc : bcs)
2160 if (nbc->shouldApply())
2161 nbc->computeResidual();
2180 ti->postJacobian(jacobian);
2196 else if (tags.size() == 1)
2217 std::map<std::string, std::set<unsigned int>> bc_involved_vars;
2219 for (
const auto & bid : all_boundary_ids)
2226 for (
const auto & bc : bcs)
2228 const std::vector<MooseVariableFEBase *> & coupled_moose_vars = bc->getCoupledMooseVars();
2232 std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2233 for (
const auto & coupled_var : coupled_moose_vars)
2235 var_set.insert(coupled_var->number());
2237 var_set.insert(bc->variable().number());
2245 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
2257 for (
const auto & bnode : bnd_nodes)
2260 Node * node = bnode->_node;
2268 for (
const auto & bc : bcs)
2271 std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2277 for (
const auto & it : coupling_entries)
2279 unsigned int ivar = it.first->number(), jvar = it.second->number();
2285 if ((bc->variable().number() == ivar) && var_set.count(jvar) && bc->shouldApply())
2286 bc->computeOffDiagJacobian(jvar);
2291 const auto & coupled_scalar_vars = bc->getCoupledMooseScalarVars();
2292 for (
const auto & jvariable : coupled_scalar_vars)
2295 bc->computeOffDiagJacobianScalar(jvariable->number());
2308 [[maybe_unused]]
const std::set<TagID> & vector_tags,
2309 [[maybe_unused]]
const std::set<TagID> & matrix_tags)
2311#ifdef MOOSE_KOKKOS_ENABLED
2324 if (!bnd_nodes.
empty())
2326 TIME_SECTION(
"NodalBCs", 3 );
2328 for (
const auto & bnode : bnd_nodes)
2331 Node * node = bnode->_node;
2340 for (
const auto & nbc : bcs)
2341 if (nbc->shouldApply())
2342 nbc->computeResidualAndJacobian();
2358 unsigned int s =
number();
2359 if (node.has_dofs(s))
2361 for (
unsigned int v = 0; v <
nVariables(); v++)
2362 for (
unsigned int c = 0; c < node.n_comp(s, v); c++)
2363 dofs.push_back(node.dof_number(s, v, c));
2370 std::unordered_map<dof_id_type, std::vector<dof_id_type>> & graph)
2374 for (
const auto & it : nearest_node_locators)
2376 std::vector<dof_id_type> & secondary_nodes = it.second->_secondary_nodes;
2378 for (
const auto & secondary_node : secondary_nodes)
2380 std::set<dof_id_type> unique_secondary_indices;
2381 std::set<dof_id_type> unique_primary_indices;
2383 auto node_to_elem_pair = node_to_elem_map.find(secondary_node);
2384 if (node_to_elem_pair != node_to_elem_map.end())
2386 const std::vector<dof_id_type> & elems = node_to_elem_pair->second;
2389 for (
const auto & cur_elem : elems)
2391 std::vector<dof_id_type> dof_indices;
2394 for (
const auto & dof : dof_indices)
2395 unique_secondary_indices.insert(dof);
2399 std::vector<dof_id_type> primary_nodes = it.second->_neighbor_nodes[secondary_node];
2401 for (
const auto & primary_node : primary_nodes)
2403 auto primary_node_to_elem_pair = node_to_elem_map.find(primary_node);
2404 mooseAssert(primary_node_to_elem_pair != node_to_elem_map.end(),
2405 "Missing entry in node to elem map");
2406 const std::vector<dof_id_type> & primary_node_elems = primary_node_to_elem_pair->second;
2409 for (
const auto & cur_elem : primary_node_elems)
2411 std::vector<dof_id_type> dof_indices;
2414 for (
const auto & dof : dof_indices)
2415 unique_primary_indices.insert(dof);
2419 for (
const auto & secondary_id : unique_secondary_indices)
2420 for (
const auto & primary_id : unique_primary_indices)
2422 graph[secondary_id].push_back(primary_id);
2423 graph[primary_id].push_back(secondary_id);
2430 for (
const auto & nc : ncs)
2432 std::vector<dof_id_type> primary_dofs;
2433 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
2434 for (
const auto & node_id : primary_node_ids)
2437 if (node && node->processor_id() == this->
processor_id())
2445 std::vector<dof_id_type> secondary_dofs;
2446 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
2447 for (
const auto & node_id : secondary_node_ids)
2450 if (node && node->processor_id() == this->
processor_id())
2458 for (
const auto & primary_id : primary_dofs)
2459 for (
const auto & secondary_id : secondary_dofs)
2461 graph[primary_id].push_back(secondary_id);
2462 graph[secondary_id].push_back(primary_id);
2467 for (
auto & it : graph)
2469 std::vector<dof_id_type> & row = it.second;
2470 std::sort(row.begin(), row.end());
2471 std::vector<dof_id_type>::iterator uit = std::unique(row.begin(), row.end());
2472 row.resize(uit - row.begin());
2486 std::unordered_map<dof_id_type, std::vector<dof_id_type>> graph;
2490 for (
const auto & it : graph)
2492 dof_id_type dof = it.first;
2493 const auto & row = it.second;
2495 for (
const auto & coupled_dof : row)
2496 jacobian.add(dof, coupled_dof, 0);
2510 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2511 MAT_NEW_NONZERO_ALLOCATION_ERR,
2514 LibmeshPetscCall(MatSetOption(
2515 cast_ref<PetscMatrix<Number> &>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE));
2517 std::vector<numeric_index_type> zero_rows;
2521 "If we're calling this method with displaced = true, then we better well have a "
2522 "displaced problem");
2527 bool constraints_applied;
2529 constraints_applied =
false;
2530 for (
const auto & it : penetration_locators)
2536 constraints_applied =
false;
2548 const auto & constraints =
2551 for (
const auto & secondary_node_num : secondary_nodes)
2553 Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
2561 reinitNodeFace(secondary_node, secondary_boundary, info, displaced);
2564 for (
const auto & nfc : constraints)
2566 if (nfc->isExplicitConstraint())
2572 if (nfc->secondaryBoundary() != secondary_boundary ||
2573 nfc->primaryBoundary() != primary_boundary)
2576 nfc->_jacobian = &jacobian_to_view;
2578 if (nfc->shouldApply())
2580 constraints_applied =
true;
2586 nfc->prepareShapes(nfc->variable().number());
2587 nfc->prepareNeighborShapes(nfc->variable().number());
2589 nfc->computeJacobian();
2591 if (nfc->overwriteSecondaryJacobian())
2594 zero_rows.push_back(nfc->variable().nodalDofIndex());
2597 std::vector<dof_id_type> secondary_dofs(1, nfc->variable().nodalDofIndex());
2603 Real scaling_factor =
2604 nfc->overwriteSecondaryJacobian() ? 1. : nfc->variable().scalingFactor();
2610 nfc->_connected_dof_indices,
2614 if (nfc->addCouplingEntriesToJacobian())
2621 nfc->primaryVariable().dofIndicesNeighbor(),
2627 nfc->primaryVariable().dofIndicesNeighbor(),
2628 nfc->_connected_dof_indices,
2629 nfc->primaryVariable().scalingFactor());
2636 const std::vector<MooseVariableFEBase *> coupled_vars = nfc->getCoupledMooseVars();
2637 for (
const auto & jvar : coupled_vars)
2645 if (nfc->variable().number() == jvar->number() ||
2647 nfc->variable().number(), jvar->number(), this->number()))
2655 nfc->prepareShapes(nfc->variable().number());
2656 nfc->prepareNeighborShapes(jvar->number());
2658 nfc->computeOffDiagJacobian(jvar->number());
2664 nfc->_connected_dof_indices,
2668 if (nfc->addCouplingEntriesToJacobian())
2675 jvar->dofIndicesNeighbor(),
2681 nfc->variable().dofIndicesNeighbor(),
2682 nfc->_connected_dof_indices,
2683 nfc->variable().scalingFactor());
2700 if (constraints_applied)
2702 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2703 MAT_KEEP_NONZERO_PATTERN,
2707 jacobian.zero_rows(zero_rows, 0.0);
2719 if (constraints_applied)
2721 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2722 MAT_KEEP_NONZERO_PATTERN,
2726 jacobian.zero_rows(zero_rows, 0.0);
2736 for (
const auto & it : element_pair_locators)
2743 const auto & element_constraints =
2747 const std::list<std::pair<const Elem *, const Elem *>> & elem_pairs =
2749 for (
const auto & pr : elem_pairs)
2751 const Elem * elem1 = pr.first;
2752 const Elem * elem2 = pr.second;
2760 for (
const auto & ec : element_constraints)
2772 ec->prepareShapes(ec->variable().number());
2773 ec->prepareNeighborShapes(ec->variable().number());
2776 ec->computeJacobian();
2786 std::set<dof_id_type> unique_secondary_node_ids;
2787 constraints_applied =
false;
2794 const auto & constraints =
2798 unique_secondary_node_ids.clear();
2800 for (
const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
2801 meshhelper.active_subdomain_elements_end(secondary_id)))
2803 for (
auto & n : elem->node_ref_range())
2804 unique_secondary_node_ids.insert(n.id());
2807 for (
auto secondary_node_id : unique_secondary_node_ids)
2809 const Node & secondary_node =
_mesh.
nodeRef(secondary_node_id);
2818 for (
const auto & nec : constraints)
2820 if (nec->shouldApply())
2822 constraints_applied =
true;
2829 nec->_jacobian = &jacobian_to_view;
2830 nec->prepareShapes(nec->variable().number());
2831 nec->prepareNeighborShapes(nec->variable().number());
2833 nec->computeJacobian();
2835 if (nec->overwriteSecondaryJacobian())
2838 zero_rows.push_back(nec->variable().nodalDofIndex());
2841 std::vector<dof_id_type> secondary_dofs(1, nec->variable().nodalDofIndex());
2847 nec->_connected_dof_indices,
2848 nec->variable().scalingFactor());
2853 nec->primaryVariable().dofIndicesNeighbor(),
2854 nec->_connected_dof_indices,
2855 nec->primaryVariable().scalingFactor());
2861 const std::vector<MooseVariableFEBase *> coupled_vars = nec->getCoupledMooseVars();
2862 for (
const auto & jvar : coupled_vars)
2870 if (nec->variable().number() == jvar->number() ||
2872 nec->variable().number(), jvar->number(), this->number()))
2880 nec->prepareShapes(nec->variable().number());
2881 nec->prepareNeighborShapes(jvar->number());
2883 nec->computeOffDiagJacobian(jvar->number());
2889 nec->_connected_dof_indices,
2890 nec->variable().scalingFactor());
2895 nec->variable().dofIndicesNeighbor(),
2896 nec->_connected_dof_indices,
2897 nec->variable().scalingFactor());
2912 if (constraints_applied)
2914 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2915 MAT_KEEP_NONZERO_PATTERN,
2919 jacobian.zero_rows(zero_rows, 0.0);
2933 else if (tags.size() == 1)
2947 bool have_scalar_contributions =
false;
2948 for (
const auto & kernel : scalars)
2950 if (!kernel->computesJacobian())
2954 const std::vector<dof_id_type> & dof_indices = kernel->variable().dofIndices();
2955 const DofMap & dof_map = kernel->variable().dofMap();
2956 const dof_id_type first_dof = dof_map.first_dof();
2957 const dof_id_type end_dof = dof_map.end_dof();
2958 for (dof_id_type dof : dof_indices)
2960 if (dof >= first_dof && dof < end_dof)
2962 kernel->computeJacobian();
2964 have_scalar_contributions =
true;
2970 if (have_scalar_contributions)
2999#ifdef MOOSE_KOKKOS_ENABLED
3014 for (
auto tag : tags)
3021 if (
auto petsc_matrix =
dynamic_cast<PetscMatrix<Number> *
>(&jacobian))
3023 LibmeshPetscCall(MatSetOption(petsc_matrix->mat(),
3024 MAT_KEEP_NONZERO_PATTERN,
3028 MatSetOption(petsc_matrix->mat(), MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
3030 LibmeshPetscCall(MatSetOption(
3031 cast_ref<PetscMatrix<Number> &>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE));
3039 TIME_SECTION(
"computeJacobianInternal", 3);
3052 std::vector<UserObject *> uos;
3058 for (
auto & uo : uos)
3059 uo->jacobianSetup();
3060 for (
auto & uo : uos)
3068 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
3071#ifdef MOOSE_KOKKOS_ENABLED
3097 for (
unsigned int i = 0; i < n_threads;
3102 using FVRange = StoredRange<MooseMesh::const_face_info_iterator, const FaceInfo *>;
3137 for (
unsigned int i = 0; i < n_threads;
3160 for (
unsigned int i = 0; i < n_threads;
3172 for (
unsigned int i = 0; i < n_threads;
3186 for (
unsigned int i = 0; i < n_threads; i++)
3197 for (
unsigned int i = 0; i < n_threads;
3207 static bool first =
true;
3232 std::unique_ptr<SparseMatrix<Number>> hash_copy;
3233 const SparseMatrix<Number> * view_jac_ptr;
3234 auto make_readable_jacobian = [&]()
3236#if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0)
3237 if (system_matrix.use_hash_table())
3239 hash_copy = cast_ref<PetscMatrix<Number> &>(system_matrix).copy_from_hash();
3240 view_jac_ptr = hash_copy.get();
3243 view_jac_ptr = &system_matrix;
3245 view_jac_ptr = &system_matrix;
3247 if (view_jac_ptr == &system_matrix)
3248 system_matrix.close();
3251 make_readable_jacobian();
3255 if (had_nodal_constraints)
3257 make_readable_jacobian();
3296 for (
auto & tag : tags)
3315 TIME_SECTION(
"computeJacobianTags", 5);
3337 for (
auto & tag : tags)
3345 const std::set<TagID> & tags)
3347 TIME_SECTION(
"computeJacobianBlocks", 3);
3350 for (
unsigned int i = 0; i <
blocks.size(); i++)
3352 SparseMatrix<Number> & jacobian =
blocks[i]->_jacobian;
3354 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
3355 MAT_KEEP_NONZERO_PATTERN,
3358 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
3359 MAT_NEW_NONZERO_ALLOCATION_ERR,
3365 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
3376 for (
unsigned int i = 0; i <
blocks.size(); i++)
3377 blocks[i]->_jacobian.close();
3379 for (
unsigned int i = 0; i <
blocks.size(); i++)
3382 SparseMatrix<Number> & jacobian =
blocks[i]->_jacobian;
3384 unsigned int ivar =
blocks[i]->_ivar;
3385 unsigned int jvar =
blocks[i]->_jvar;
3388 std::vector<numeric_index_type> zero_rows;
3392 for (
const auto & bnode : bnd_nodes)
3395 Node * node = bnode->_node;
3405 for (
const auto & bc : bcs)
3406 if (bc->variable().number() == ivar && bc->shouldApply())
3410 zero_rows.push_back(node->dof_number(precond_system.
number(), 0, 0));
3422 jacobian.zero_rows(zero_rows, 1.0);
3424 jacobian.zero_rows(zero_rows, 0.0);
3452#ifdef MOOSE_KOKKOS_ENABLED
3464 const NumericVector<Number> & update)
3468 bool has_active_dampers =
false;
3476 TIME_SECTION(
"computeDampers", 3,
"Computing Dampers");
3477 has_active_dampers =
true;
3482 damping = std::min(cid.
damping(), damping);
3491 TIME_SECTION(
"computeDamping::element", 3,
"Computing Element Damping");
3493 has_active_dampers =
true;
3498 damping = std::min(cndt.
damping(), damping);
3507 TIME_SECTION(
"computeDamping::general", 3,
"Computing General Damping");
3509 has_active_dampers =
true;
3511 for (
const auto & damper : gdampers)
3516 damper->checkMinDamping(gd_damping);
3522 damping = std::min(gd_damping, damping);
3534 catch (std::exception & e)
3537 const std::string & message = e.
what();
3538 if (message.find(
"Jacobian") == std::string::npos)
3544 if (has_active_dampers && damping < 1.0)
3545 _console <<
" Damping factor: " << damping << std::endl;
3552 const std::set<TagID> & matrix_tags,
3557 std::set<const Elem *> dirac_elements;
3561 TIME_SECTION(
"computeDirac", 3,
"Computing DiracKernels");
3567 for (
const auto & dkernel : dkernels)
3569 dkernel->clearPoints();
3570 dkernel->addPoints();
3578 DistElemRange range(dirac_elements.begin(), dirac_elements.end(), 1);
3587 for (
const auto tid : make_range(this->
numThreads()))
3591 for (
const auto tid : make_range(this->
numThreads()))
3596NumericVector<Number> &
3605NumericVector<Number> &
3637 std::vector<dof_id_type> & n_nz,
3638 std::vector<dof_id_type> & n_oz)
3644 std::unordered_map<dof_id_type, std::vector<dof_id_type>> graph;
3659 for (
const auto & git : graph)
3661 dof_id_type dof = git.first;
3662 dof_id_type local_dof = dof - first_dof_on_proc;
3664 if (dof < first_dof_on_proc || dof >= end_dof_on_proc)
3667 const auto & row = git.second;
3671 unsigned int original_row_length = sparsity_row.size();
3673 sparsity_row.insert(sparsity_row.end(), row.begin(), row.end());
3676 sparsity_row.begin(), sparsity_row.begin() + original_row_length, sparsity_row.end());
3679 for (
const auto & coupled_dof : row)
3681 if (coupled_dof < first_dof_on_proc || coupled_dof >= end_dof_on_proc)
3683 if (n_oz[local_dof] < n_dofs_not_on_proc)
3688 if (n_nz[local_dof] < n_dofs_on_proc)
3724 mooseError(
"More than one active Preconditioner detected");
3743 const std::set<MooseVariable *> & damped_vars)
3745 for (
const auto & var : damped_vars)
3751 const std::set<MooseVariable *> & damped_vars)
3753 for (
const auto & var : damped_vars)
3761 std::set<SubdomainID> input_subdomains;
3762 std::set<std::string> kernel_variables;
3764 bool global_kernels_exist =
false;
3774#ifdef MOOSE_KOKKOS_ENABLED
3781 std::vector<FVElementalKernel *> fv_elemental_kernels;
3784 .template condition<AttribSystem>(
"FVElementalKernel")
3787 for (
auto fv_kernel : fv_elemental_kernels)
3789 if (fv_kernel->blockRestricted())
3790 for (
auto block_id : fv_kernel->blockIDs())
3791 input_subdomains.insert(block_id);
3793 global_kernels_exist =
true;
3794 kernel_variables.insert(fv_kernel->variable().name());
3803 std::vector<FVFluxKernel *> fv_flux_kernels;
3806 .template condition<AttribSystem>(
"FVFluxKernel")
3809 for (
auto fv_kernel : fv_flux_kernels)
3811 if (fv_kernel->blockRestricted())
3812 for (
auto block_id : fv_kernel->blockIDs())
3813 input_subdomains.insert(block_id);
3815 global_kernels_exist =
true;
3816 kernel_variables.insert(fv_kernel->variable().name());
3819 std::vector<FVInterfaceKernel *> fv_interface_kernels;
3822 .template condition<AttribSystem>(
"FVInterfaceKernel")
3825 for (
auto fvik : fv_interface_kernels)
3827 kernel_variables.insert(scalar_fvik->lambdaVariable().name());
3829 std::vector<FVFluxBC *> fv_flux_bcs;
3832 .template condition<AttribSystem>(
"FVFluxBC")
3835 for (
auto fvbc : fv_flux_bcs)
3837 kernel_variables.insert(scalar_fvbc->lambdaVariable().name());
3842 const auto additional_variables_covered = ibc->additionalROVariables();
3843 kernel_variables.insert(additional_variables_covered.begin(),
3844 additional_variables_covered.end());
3848 if (!global_kernels_exist)
3851 std::set<SubdomainID> system_subdomains;
3857 if (variable_subdomains.empty())
3859 system_subdomains = mesh_subdomains;
3863 for (
const auto subdomain : variable_subdomains)
3864 if (mesh_subdomains.count(subdomain))
3865 system_subdomains.insert(subdomain);
3868 std::set<SubdomainID> difference;
3869 std::set_difference(system_subdomains.begin(),
3870 system_subdomains.end(),
3871 input_subdomains.begin(),
3872 input_subdomains.end(),
3873 std::inserter(difference, difference.end()));
3877 difference.erase(
id);
3879 difference.erase(
id);
3881 if (!difference.empty())
3883 std::vector<SubdomainID> difference_vec =
3884 std::vector<SubdomainID>(difference.begin(), difference.end());
3886 std::stringstream missing_block_names;
3887 std::copy(difference_names.begin(),
3888 difference_names.end(),
3889 std::ostream_iterator<std::string>(missing_block_names,
" "));
3890 std::stringstream missing_block_ids;
3891 std::copy(difference.begin(),
3893 std::ostream_iterator<unsigned int>(missing_block_ids,
" "));
3895 mooseError(
"Each subdomain must contain at least one Kernel.\nThe following block(s) lack an "
3897 missing_block_names.str(),
3899 missing_block_ids.str(),
3907 std::set<VariableName> difference;
3908 std::set_difference(variables.begin(),
3910 kernel_variables.begin(),
3911 kernel_variables.end(),
3912 std::inserter(difference, difference.end()));
3915 std::set<VariableName>
vars(difference);
3916 for (
auto & var_name :
vars)
3919 for (
const auto &
id : blks)
3921 difference.erase(var_name);
3924 if (!difference.empty())
3926 std::stringstream missing_kernel_vars;
3927 std::copy(difference.begin(),
3929 std::ostream_iterator<std::string>(missing_kernel_vars,
" "));
3930 mooseError(
"Each variable must be referenced by at least one active Kernel.\nThe following "
3931 "variable(s) lack an active kernel: " +
3932 missing_kernel_vars.str());
3944std::vector<std::string>
3947 std::vector<std::string> variable_names;
3949 if (time_kernels.hasActiveObjects())
3950 for (
const auto & kernel : time_kernels.getObjects())
3951 variable_names.push_back(kernel->variable().name());
3953 return variable_names;
3963 if (std::static_pointer_cast<MaterialPropertyInterface>(bc)->getMaterialPropertyCalled())
3970 if (std::static_pointer_cast<MaterialPropertyInterface>(ik)->getMaterialPropertyCalled())
3978 if (
auto mpi = std::dynamic_pointer_cast<MaterialPropertyInterface>(ct);
3979 mpi && mpi->getMaterialPropertyCalled())
3991 if (std::static_pointer_cast<MaterialPropertyInterface>(ik)->getMaterialPropertyCalled())
4003 if (std::static_pointer_cast<MaterialPropertyInterface>(dg)->getMaterialPropertyCalled())
4026 const std::set<TagID> & vector_tags,
4027 const std::set<TagID> & matrix_tags)
4029 parallel_object_only();
4034 map_pr.second(compute_type, vector_tags, matrix_tags);
4037 map_pr.second(compute_type, vector_tags, matrix_tags);
4039 catch (MetaPhysicL::LogicError &)
4042 "We caught a MetaPhysicL error in NonlinearSystemBase::mortarConstraints. This is very "
4043 "likely due to AD not having a sufficiently large derivative container size. Please run "
4044 "MOOSE configure with the '--with-derivative-size=<n>' option");
4062 for (
const auto var_number : make_range(
n_vars))
4067 std::set<unsigned int> var_numbers, var_numbers_covered, var_numbers_not_covered;
4068 for (
const auto var_number : make_range(
n_vars))
4069 var_numbers.insert(var_number);
4079 "', provided to the 'scaling_group_variables' parameter, does not exist in "
4080 "the nonlinear system.");
4086 if (!map_pair.second)
4087 mooseError(
"Variable ", var_name,
" is contained in multiple scaling grouplings");
4088 var_numbers_covered.insert(var.
number());
4091 std::set_difference(var_numbers.begin(),
4093 var_numbers_covered.begin(),
4094 var_numbers_covered.end(),
4095 std::inserter(var_numbers_not_covered, var_numbers_not_covered.begin()));
4100 for (
auto var_number : var_numbers_not_covered)
4105 const auto & number_to_var_map =
_vars[0].numberToVariableMap();
4111 libmesh_map_find(number_to_var_map, i)->
name()) !=
4124 _console <<
"\nPerforming automatic scaling calculation\n" << std::endl;
4126 TIME_SECTION(
"computeScaling", 3,
"Computing Automatic Scaling");
4129 std::vector<dof_id_type> dof_indices;
4137 auto & dof_map =
dofMap();
4143 const NumericVector<Number> & scaling_residual =
RHS();
4154 auto init_vector = NumericVector<Number>::build(this->
comm());
4155 init_vector->init(
system().n_dofs(),
system().n_local_dofs(),
false, PARALLEL);
4181 auto examine_dof_indices = [
this,
4185 &jac_inverse_scaling_factors,
4186 &resid_inverse_scaling_factors,
4187 &scaling_residual](
const auto & dof_indices,
const auto var_number)
4189 for (
auto dof_index : dof_indices)
4190 if (dof_map.local_index(dof_index))
4195 auto mat_value = (*_scaling_matrix)(dof_index, dof_index);
4197 factor = std::max(factor, std::abs(mat_value));
4201 auto vec_value = scaling_residual(dof_index);
4203 factor = std::max(factor, std::abs(vec_value));
4213 dof_map.dof_indices(elem, dof_indices, i);
4214 examine_dof_indices(dof_indices, i);
4220 dof_map.SCALAR_dof_indices(dof_indices, i);
4221 examine_dof_indices(dof_indices, i);
4229 if (jac_scaling && resid_scaling)
4230 for (MooseIndex(inverse_scaling_factors) i = 0; i < inverse_scaling_factors.size(); ++i)
4233 if (!resid_inverse_scaling_factors[i])
4235 if (!jac_inverse_scaling_factors[i])
4236 inverse_scaling_factors[i] = 1;
4238 inverse_scaling_factors[i] = jac_inverse_scaling_factors[i];
4240 else if (!jac_inverse_scaling_factors[i])
4242 inverse_scaling_factors[i] = resid_inverse_scaling_factors[i];
4244 inverse_scaling_factors[i] =
4248 else if (jac_scaling)
4249 inverse_scaling_factors = jac_inverse_scaling_factors;
4250 else if (resid_scaling)
4251 inverse_scaling_factors = resid_inverse_scaling_factors;
4253 mooseError(
"We shouldn't be calling this routine if we're not performing any scaling");
4256 for (
auto & scaling_factor : inverse_scaling_factors)
4257 if (scaling_factor == 0)
4261 std::vector<Real> flattened_inverse_scaling_factors(
system().
n_vars());
4262 for (
const auto i : index_range(flattened_inverse_scaling_factors))
4263 flattened_inverse_scaling_factors[i] = inverse_scaling_factors[
_var_to_group_var[i]];
4269 flattened_inverse_scaling_factors);
4290 if (!scaling_succeeded)
4303 LibmeshPetscCall(MatFDColoringDestroy(&
_fdcoloring));
4310 mooseError(
"No field split preconditioner is present for this system");
boundary_id_type BoundaryID
subdomain_id_type SubdomainID
StoredRange< std::set< const Elem * >::const_iterator, const Elem * > DistElemRange
void mooseDocumentedError(const std::string &repo_name, const unsigned int issue_num, Args &&... args)
Emit a documented error message with the given stringified, concatenated args and terminate the appli...
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
const ExecFlagType EXEC_PRE_KERNELS
std::array< Real, 2 > values
EXTERN_C_BEGIN PetscErrorCode DMCreate_Moose(DM)
std::shared_ptr< DisplacedProblem > displaced_problem
Key structure for APIs manipulating global vectors/matrices.
void addCachedJacobian(GlobalDataKey)
Adds the values that have been cached by calling cacheJacobian() and or cacheJacobianNeighbor() to th...
virtual libMesh::System & system() override
Get the reference to the libMesh system.
Base class for creating new types of boundary conditions.
Specialization for filling multiple "small" preconditioning matrices simulatenously.
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
const std::vector< std::shared_ptr< ElemElemConstraint > > & getActiveElemElemConstraints(InterfaceID interface_id, bool displaced) const
const std::vector< std::shared_ptr< MortarConstraintBase > > & getActiveMortarConstraints(const std::pair< BoundaryID, BoundaryID > &mortar_interface_key, bool displaced) const
const std::vector< std::shared_ptr< NodeFaceConstraint > > & getActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
bool hasActiveMortarConstraints(const std::pair< BoundaryID, BoundaryID > &mortar_interface_key, bool displaced) const
bool hasActiveNodeElemConstraints(SubdomainID secondary_id, SubdomainID primary_id, bool displaced) const
bool hasActiveNodalConstraints() const
Deterimine if active objects exist.
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 updateActive(THREAD_ID tid=0) override
Update the various active lists.
void addObject(std::shared_ptr< Constraint > object, THREAD_ID tid=0, bool recurse=true) override
Add Constraint object to the warehouse.
bool hasActiveElemElemConstraints(const InterfaceID interface_id, bool displaced) const
const std::vector< std::shared_ptr< NodeElemConstraintBase > > & getActiveNodeElemConstraints(SubdomainID secondary_id, SubdomainID primary_id, bool displaced) const
bool hasActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
const std::vector< std::shared_ptr< NodalConstraint > > & getActiveNodalConstraints() const
Access methods for active objects.
virtual void residualEnd(THREAD_ID tid=0) const
Base class for all Constraint types.
Base class for convergence criteria.
virtual void preLoop()
Method that gets called before each iteration loop.
Serves as a base class for DGKernel and ADDGKernel.
Base class for deriving dampers.
DiracKernelBase is the base class for all DiracKernel type classes.
This is the ElementPairInfo class.
This is the ElementPairLocator class.
const ElementPairList & getElemPairs() const
const ElementPairInfo & getElemPairInfo(std::pair< const Elem *, const Elem * > elem_pair) const
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void addJacobianScalar(const THREAD_ID tid=0)
virtual void clearDiracInfo() override
Gets called before Dirac Kernels are asked to add the points they are supposed to be evaluated in.
virtual void cacheResidual(const THREAD_ID tid) override
virtual void reinitNeighborPhys(const Elem *neighbor, unsigned int neighbor_side, const std::vector< Point > &physical_points, const THREAD_ID tid) override
virtual bool haveFV() const override
returns true if this problem includes/needs finite volume functionality.
void jacobianSetup() override
bool areCoupled(const unsigned int ivar, const unsigned int jvar, const unsigned int nl_sys_num) const
virtual void addResidualScalar(const THREAD_ID tid=0)
bool restoreOriginalNonzeroPattern() const
virtual void addCachedResidual(const THREAD_ID tid) override
AuxiliarySystem & getAuxiliarySystem()
virtual void reinitScalars(const THREAD_ID tid, bool reinit_for_derivative_reordering=false) override
fills the VariableValue arrays for scalar variables from the solution vector
virtual void cacheJacobianNeighbor(const THREAD_ID tid) override
virtual void addCachedJacobian(const THREAD_ID tid) override
virtual void reinitOffDiagScalars(const THREAD_ID tid) override
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class,...
virtual void cacheJacobian(const THREAD_ID tid) override
virtual void addJacobianOffDiagScalar(unsigned int ivar, const THREAD_ID tid=0)
void residualSetup() override
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, const THREAD_ID tid) override
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
bool getFailNextNonlinearConvergenceCheck() const
Whether it will skip further residual evaluations and fail the next nonlinear convergence check(s)
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
virtual void predictorCleanup(NumericVector< libMesh::Number > &ghosted_solution)
Perform cleanup tasks after application of predictor to solution vector.
virtual void getDiracElements(std::set< const Elem * > &elems) override
Fills "elems" with the elements that should be looped over for Dirac Kernels.
virtual GeometricSearchData & geomSearchData() override
bool identifyVariableGroupsInNL() const
Whether to identify variable groups in nonlinear systems.
void computingScalingJacobian(bool computing_scaling_jacobian)
Setter for whether we're computing the scaling jacobian.
bool hasDampers()
Whether or not this system has dampers.
virtual void prepareAssembly(const THREAD_ID tid) override
bool hasKokkosResidualObjects() const
void setCurrentNonlinearSystem(const unsigned int nl_sys_num)
const ConstBndNodeRange & getCurrentAlgebraicBndNodeRange()
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
const libMesh::ConstElemRange & getCurrentAlgebraicElementRange()
These are the element and nodes that contribute to the jacobian and residual for this local processor...
void reinitMaterialsNeighbor(SubdomainID blk_id, const THREAD_ID tid, bool swap_stateful=true, const std::deque< MaterialBase * > *reinit_mats=nullptr)
reinit materials on the neighboring element face
virtual void reinitNode(const Node *node, const THREAD_ID tid) override
Moose::CouplingType coupling() const
const std::unordered_map< std::pair< BoundaryID, BoundaryID >, MortarInterfaceConfig > & getMortarInterfaces(bool on_displaced) const
virtual void checkExceptionAndStopSolve(bool print_message=true)
Check to see if an exception has occurred on any processor and, if possible, force the solve to fail,...
NonlinearSystemBase & currentNonlinearSystem()
virtual MooseMesh & mesh() override
void setActiveMaterialProperties(const std::unordered_set< unsigned int > &mat_prop_ids, const THREAD_ID tid)
Record and set the material properties required by the current computing thread.
void setCurrentlyComputingResidual(bool currently_computing_residual) final
Set whether or not the problem is in the process of computing the residual.
virtual void updateGeomSearch(GeometricSearchData::GeometricSearchType type=GeometricSearchData::ALL) override
Update this object's geometric search data as well as the displaced problem's if it exists.
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num) override
std::vector< std::pair< MooseVariableFieldBase *, MooseVariableFieldBase * > > & couplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num)
bool useHashTableMatrixAssembly() const
bool _has_constraints
Whether or not this system has any Constraints.
bool errorOnJacobianNonzeroReallocation() const
Will return True if the user wants to get an error when a nonzero is reallocated in the Jacobian by P...
TheWarehouse & theWarehouse() const
const libMesh::ConstNodeRange & getCurrentAlgebraicNodeRange()
virtual void setResidual(NumericVector< libMesh::Number > &residual, const THREAD_ID tid) override
virtual void addCachedResidualDirectly(NumericVector< libMesh::Number > &residual, const THREAD_ID tid)
Allows for all the residual contributions that are currently cached to be added directly into the vec...
void computingScalingResidual(bool computing_scaling_residual)
Setter for whether we're computing the scaling residual.
void computingNonlinearResid(bool computing_nonlinear_residual) final
Set whether or not the problem is in the process of computing the nonlinear residual.
virtual void prepareAssemblyNeighbor(const THREAD_ID tid)
Begin a fresh neighbor accumulation phase by sizing and zeroing the neighbor blocks.
virtual void cacheResidualNeighbor(const THREAD_ID tid) override
virtual void setNeighborSubdomainID(const Elem *elem, unsigned int side, const THREAD_ID tid) override
bool ignoreZerosInJacobian() const
Will return true if zeros in the Jacobian are to be dropped from the sparsity pattern.
Base class for implementing constraints on boundaries for finite volume variables using scalar Lagran...
Base class for implementing constraints on finite volume variable elemental values using scalar Lagra...
const MooseVariableScalar & lambdaVariable() const
std::shared_ptr< MooseObject > create(const std::string &obj_name, const std::string &name, const InputParameters ¶meters, THREAD_ID tid=0, bool print_deprecated=true)
Base interface for field split preconditioner.
virtual void setupDM()=0
setup the data management data structure that manages the field split
Scope guard for starting and stopping Floating Point Exception Trapping.
std::map< std::pair< BoundaryID, BoundaryID >, NearestNodeLocator * > _nearest_node_locators
std::map< BoundaryID, std::shared_ptr< ElementPairLocator > > _element_pair_locators
std::map< std::pair< BoundaryID, BoundaryID >, PenetrationLocator * > _penetration_locators
Base kernel for hybridized finite element formulations.
InterfaceKernelBase is the base class for all InterfaceKernel type classes.
This is the common base class for the three main kernel types implemented in MOOSE,...
SolutionInvalidity & solutionInvalidity()
Get the SolutionInvalidity for this app.
const InputParameters & parameters() const
Get the parameters of the object.
const std::string & name() const
Get the name of the class.
Class for containing MooseEnum item information.
Provides a way for users to bail out of the current solve.
virtual const char * what() const
Get out the error message.
face_info_iterator ownedFaceInfoEnd()
virtual const Node & nodeRef(const dof_id_type i) const
virtual Elem * elemPtr(const dof_id_type i)
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
std::vector< SubdomainName > getSubdomainNames(const std::vector< SubdomainID > &subdomain_ids) const
Get the associated subdomainNames for the subdomain ids that are passed in.
const std::unordered_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.
face_info_iterator ownedFaceInfoBegin()
Iterators to owned faceInfo objects.
const std::set< SubdomainID > & interiorLowerDBlocks() 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.
const std::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
virtual const Node * queryNodePtr(const dof_id_type i) const
const std::set< SubdomainID > & boundaryLowerDBlocks() const
MooseObjectWarehouse< T > & getVectorTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given vector tag.
MooseObjectWarehouse< T > & getMatrixTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has one of the given matrix tags.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
MooseObjectWarehouse< T > & getVectorTagsObjectWarehouse(const std::set< TagID > &tags, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object at least has one of the given vector ta...
MooseObjectWarehouse< T > & getMatrixTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given matrix tag.
std::shared_ptr< T > getActiveObject(const std::string &name, THREAD_ID tid=0) const
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
virtual void updateActive(THREAD_ID tid=0)
Updates the active objects storage.
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true)
Adds an object to the storage structure.
bool hasActiveObjects(THREAD_ID tid=0) const
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
bool hasActiveBlockObjects(THREAD_ID tid=0) const
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
bool hasObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
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 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.
A storage container for MooseObjects that inherit from SetupInterface.
virtual void timestepSetup(THREAD_ID tid=0) const
virtual void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
virtual void residualSetup(THREAD_ID tid=0) const
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true) override
Adds an object to the storage structure.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
virtual void jacobianSetup(THREAD_ID tid=0) const
Base class for MOOSE preconditioners.
unsigned int number() const
Get variable number coming from libMesh.
This class provides an interface for common operations on field variables of both FE and FV types wit...
std::vector< dof_id_type > _secondary_nodes
Base class for creating new types of nodal kernels.
void computeDiracContributions(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags, Moose::ComputeType compute_type)
void addConstraint(const std::string &c_name, const std::string &name, InputParameters ¶meters)
Adds a Constraint.
MooseObjectWarehouse< ADDirichletBCBase > _ad_preset_nodal_bcs
MooseObjectTagWarehouse< ResidualObject > _kokkos_kernels
bool _debugging_residuals
true if debugging residuals
MoosePreconditioner const * getPreconditioner() const
bool preSolve()
Perform some steps to get ready for the solver.
bool _need_residual_ghosted
Whether or not a ghosted copy of the residual needs to be made.
MooseObjectWarehouse< NodalDamper > _nodal_dampers
Nodal Dampers for each thread.
std::size_t _num_scaling_groups
The number of scaling groups.
virtual void computeScalingJacobian()=0
Compute a "Jacobian" for automatic scaling purposes.
void computeKokkosResidualAndJacobian(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
virtual std::vector< std::string > timeKernelVariableNames() override
Returns the names of the variables that have time derivative kernels in the system.
Real referenceResidual() const
The reference residual used in relative convergence check.
MooseObjectWarehouse< ElementDamper > _element_dampers
Element Dampers for each thread.
NumericVector< Number > & getResidualNonTimeVector()
Return a numeric vector that is associated with the nontime tag.
FieldSplitPreconditionerBase & getFieldSplitPreconditioner()
MooseObjectTagWarehouse< ResidualObject > _kokkos_nodal_bcs
virtual void jacobianSetup() override
virtual void augmentSparsity(libMesh::SparsityPattern::Graph &sparsity, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz) override
Will modify the sparsity pattern to add logical geometric connections.
MatFDColoring _fdcoloring
Real _resid_vs_jac_scaling_param
The param that indicates the weighting of the residual vs the Jacobian in determining variable scalin...
void zeroVectorForResidual(const std::string &vector_name)
void onTimestepBegin()
Called at the beginning of the time step.
Convergence & convergence()
Retrieves the associated Convergence object.
std::set< TagID > _nl_vector_tags
Vector tags to temporarily store all tags associated with the current system.
std::vector< std::string > _ignore_variables_for_autoscaling
A container for variables that do not partipate in autoscaling.
virtual void subdomainSetup()
void reinitIncrementAtQpsForDampers(THREAD_ID tid, const std::set< MooseVariable * > &damped_vars)
Compute the incremental change in variables at QPs for dampers.
void computeKokkosResidual(const std::set< TagID > &tags)
Compute residual with Kokkos objects.
void postJacobian(const std::set< TagID > &tags)
Let the time integrators combine the time and non-time parts of the system Jacobian,...
void setKokkosInitialSolution()
void computeJacobian(libMesh::SparseMatrix< Number > &jacobian, const std::set< TagID > &tags)
Associate jacobian to systemMatrixTag, and then form a matrix for all the tags.
MooseObjectTagWarehouse< ResidualObject > _kokkos_integrated_bcs
NumericVector< Number > & residualVector(TagID tag)
Return a residual vector that is associated with the residual tag.
unsigned int _n_residual_evaluations
Total number of residual evaluations that have been performed.
MooseObjectTagWarehouse< ScalarKernelBase > _scalar_kernels
NumericVector< Number > * _increment_vec
increment vector
bool needInterfaceMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid) const
Indicated whether this system needs material properties on interfaces.
MooseObjectWarehouse< DirichletBCBase > _preset_nodal_bcs
void overwriteNodeFace(NumericVector< Number > &soln)
Called from explicit time stepping to overwrite boundary positions (explicit dynamics).
Real _pre_smo_residual
The pre-SMO residual, see setPreSMOResidual for a detailed explanation.
void updateActive(THREAD_ID tid)
Update active objects of Warehouses owned by NonlinearSystemBase.
NumericVector< Number > * _Re_time
residual vector for time contributions
virtual void setSolutionUDotDotOld(const NumericVector< Number > &u_dotdot_old)
bool computeScaling()
Method used to obtain scaling factors for variables.
std::set< TagID > _nl_matrix_tags
Matrix tags to temporarily store all tags associated with the current system.
void addSplit(const std::string &split_name, const std::string &name, InputParameters ¶meters)
Adds a split.
MooseObjectTagWarehouse< DiracKernelBase > _dirac_kernels
Dirac Kernel storage for each thread.
virtual void postAddResidualObject(ResidualObject &)
Called after any ResidualObject-derived objects are added to the system.
bool shouldEvaluatePreSMOResidual() const
We offer the option to check convergence against the pre-SMO residual.
virtual NumericVector< Number > & residualGhosted() override
virtual void preInit() override
This is called prior to the libMesh system has been init'd.
virtual void turnOffJacobian()
Turn off the Jacobian (must be called before equation system initialization)
bool _auto_scaling_initd
Whether we've initialized the automatic scaling data structures.
TagID timeVectorTag() const override
Ideally, we should not need this API.
void computeResidualTags(const std::set< TagID > &tags)
Form multiple tag-associated residual vectors for all the given tags.
virtual void setSolutionUDot(const NumericVector< Number > &udot)
Set transient term used by residual and Jacobian evaluation.
MooseObjectTagWarehouse< NodalKernelBase > _nodal_kernels
NodalKernels for each thread.
void addImplicitGeometricCouplingEntries(GeometricSearchData &geom_search_data)
Adds entries to the Jacobian in the correct positions for couplings coming from dofs being coupled th...
virtual void addNodalKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a NodalKernel.
MooseObjectWarehouse< ResidualObject > _kokkos_preset_nodal_bcs
void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters ¶meters)
Adds a boundary condition.
void computeScalarKernelsJacobians(const std::set< TagID > &tags)
MooseObjectTagWarehouse< NodalBCBase > _nodal_bcs
NumericVector< Number > & getResidualTimeVector()
Return a numeric vector that is associated with the time tag.
void getNodeDofs(dof_id_type node_id, std::vector< dof_id_type > &dofs)
std::vector< std::string > _vecs_to_zero_for_residual
vectors that will be zeroed before a residual computation
virtual void addHDGKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a hybridized discontinuous Galerkin (HDG) kernel.
bool _doing_dg
true if DG is active (optimization reasons)
void reinitNodeFace(const Node &secondary_node, const BoundaryID secondary_boundary, const PenetrationInfo &info, const bool displaced)
Reinitialize quantities such as variables, residuals, Jacobians, materials for node-face constraints.
void addDiracKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a Dirac kernel.
std::shared_ptr< Predictor > _predictor
If predictor is active, this is non-NULL.
std::shared_ptr< Split > getSplit(const std::string &name)
Retrieves a split by name.
void computeResidualTag(NumericVector< Number > &residual, TagID tag_id)
Computes residual for a given tag.
void setMatrixOptions(const std::set< TagID > &tags)
Set the PETSc options used for assembling the matrices of the given tags.
void findImplicitGeometricCouplingEntries(GeometricSearchData &geom_search_data, std::unordered_map< dof_id_type, std::vector< dof_id_type > > &graph)
Finds the implicit sparsity graph between geometrically related dofs.
bool _add_implicit_geometric_coupling_entries_to_jacobian
Whether or not to add implicit geometric couplings to the Jacobian for FDP.
virtual bool containsTimeKernel() override
If the system has a kernel that corresponds to a time derivative.
NumericVector< Number > * _residual_ghosted
ghosted form of the residual
void constraintJacobians(const SparseMatrix< Number > &jacobian_to_view, bool displaced)
Add jacobian contributions from Constraints.
void computeResidualAndJacobianInternal(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Compute residual and Jacobian from contributions not related to constraints, such as nodal boundary c...
Real preSMOResidual() const
The pre-SMO residual.
void setInitialResidual(Real r)
Record the initial residual (for later relative convergence check)
std::vector< SetupInterface * > getFVSetupObjects(THREAD_ID tid)
Retrieve every finite volume object belonging to this system on thread tid, as SetupInterfaces,...
MooseObjectTagWarehouse< KernelBase > _kernels
std::vector< bool > _variable_autoscaled
Container to hold flag if variable is to participate in autoscaling.
Real computeDamping(const NumericVector< Number > &solution, const NumericVector< Number > &update)
Compute damping.
bool _has_save_in
If there is any Kernel or IntegratedBC having save_in.
void computeNodalBCsResidual(NumericVector< Number > &residual)
Enforces nodal boundary conditions.
bool _has_diag_save_in
If there is any Kernel or IntegratedBC having diag_save_in.
MooseObjectTagWarehouse< IntegratedBCBase > _integrated_bcs
TagID systemMatrixTag() const override
Return the Matrix Tag ID for System.
virtual libMesh::NonlinearSolver< Number > * nonlinearSolver()=0
virtual NumericVector< Number > & RHS()=0
void reinitIncrementAtNodeForDampers(THREAD_ID tid, const std::set< MooseVariable * > &damped_vars)
Compute the incremental change in variables at nodes for dampers.
bool doingDG() const
Getter for _doing_dg.
virtual void setPreviousNewtonSolution(const NumericVector< Number > &soln)
TagID _Re_time_tag
Tag for time contribution residual.
bool _compute_scaling_once
Whether the scaling factors should only be computed once at the beginning of the simulation through a...
std::unique_ptr< NumericVector< Number > > _residual_copy
Copy of the residual vector, or nullptr if a copy is not needed.
TagID _Re_non_time_tag
Tag for non-time contribution residual.
ConvergenceName _convergence_name
Associated convergence object name.
void addDGKernel(std::string dg_kernel_name, const std::string &name, InputParameters ¶meters)
Adds a DG kernel.
void setupScalingData()
Setup group scaling containers.
void computeJacobianBlocks(std::vector< JacobianBlock * > &blocks)
Computes several Jacobian blocks simultaneously, summing their contributions into smaller preconditio...
void setPredictor(std::shared_ptr< Predictor > predictor)
void computeNodalBCsResidualAndJacobian(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Compute the residual and Jacobian together for nodal boundary conditions.
std::vector< unsigned int > _current_l_its
std::vector< std::vector< std::string > > _scaling_group_variables
A container of variable groupings that can be used in scaling calculations.
MooseObjectWarehouseBase< Split > _splits
Decomposition splits.
void setInitialSolution()
void enforceNodalConstraintsResidual(NumericVector< Number > &residual)
Enforce nodal constraints.
virtual void computeScalingResidual()=0
Compute a "residual" for automatic scaling purposes.
void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a scalar kernel.
void addImplicitGeometricCouplingEntriesToJacobian(bool add=true)
If called with true this will add entries into the jacobian to link together degrees of freedom that ...
virtual void initialSetup() override
Setup Functions.
void addInterfaceKernel(std::string interface_kernel_name, const std::string &name, InputParameters ¶meters)
Adds an interface kernel.
void addDamper(const std::string &damper_name, const std::string &name, InputParameters ¶meters)
Adds a damper.
bool _has_nodalbc_save_in
If there is a nodal BC having save_in.
std::unordered_map< unsigned int, unsigned int > _var_to_group_var
A map from variable index to group variable index and it's associated (inverse) scaling factor.
MooseObjectTagWarehouse< ResidualObject > _kokkos_nodal_kernels
bool _use_pre_smo_residual
Whether to use the pre-SMO initial residual in the relative convergence check.
void reinitMortarFunctors()
Update the mortar functors if the mesh has changed.
MooseObjectWarehouse< GeneralDamper > _general_dampers
General Dampers.
MooseObjectTagWarehouse< InterfaceKernelBase > _interface_kernels
virtual void timestepSetup() override
bool hasDiagSaveIn() const
Weather or not the nonlinear system has diagonal Jacobian save-ins.
bool _assemble_constraints_separately
Whether or not to assemble the residual and Jacobian after the application of each constraint.
std::unordered_map< std::pair< BoundaryID, BoundaryID >, ComputeMortarFunctor > _displaced_mortar_functors
Functors for computing displaced mortar constraints.
virtual NumericVector< Number > & residualCopy() override
void computeKokkosJacobian(const std::set< TagID > &tags)
Compute Jacobian with Kokkos objects.
bool needBoundaryMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid) const
Indicated whether this system needs material properties on boundaries.
void mortarConstraints(Moose::ComputeType compute_type, const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Do mortar constraint residual/jacobian computations.
TagID _Re_tag
Used for the residual vector from PETSc.
bool _computed_scaling
Flag used to indicate whether we have already computed the scaling Jacobian.
void setPreconditioner(std::shared_ptr< MoosePreconditioner > pc)
Sets a preconditioner.
virtual ~NonlinearSystemBase()
NonlinearSystemBase(FEProblemBase &problem, libMesh::System &sys, const std::string &name)
void computeNodalBCsJacobian(const std::set< TagID > &tags)
Compute the Jacobian for nodal boundary conditions.
void checkKernelCoverage(const std::set< SubdomainID > &mesh_subdomains) const
void computeResidual(NumericVector< Number > &residual, TagID tag_id)
Form a residual vector for a given tag.
std::unordered_map< std::pair< BoundaryID, BoundaryID >, ComputeMortarFunctor > _undisplaced_mortar_functors
Functors for computing undisplaced mortar constraints.
void computeJacobianTags(const std::set< TagID > &tags)
Computes multiple (tag associated) Jacobian matricese.
bool enforceNodalConstraintsJacobian(const SparseMatrix< Number > &jacobian)
Enforce nodal constraints in the Jacobian.
std::unique_ptr< libMesh::DiagonalMatrix< Number > > _scaling_matrix
A diagonal matrix used for computing scaling.
Real _initial_residual
The initial (i.e., 0th nonlinear iteration) residual, see setPreSMOResidual for a detailed explanatio...
virtual void residualSetup() override
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
bool _off_diagonals_in_auto_scaling
Whether to include off diagonals when determining automatic scaling factors.
virtual void customSetup(const ExecFlagType &exec_type) override
void constraintResiduals(NumericVector< Number > &residual, bool displaced)
Add residual contributions from Constraints.
virtual void setSolutionUDotOld(const NumericVector< Number > &u_dot_old)
virtual libMesh::System & system() override
Get the reference to the libMesh system.
void computeJacobianInternal(const std::set< TagID > &tags)
Form multiple matrices for all the tags.
void computeResidualInternal(const std::set< TagID > &tags)
Compute the residual for a given tag.
TagID _Ke_system_tag
Tag for system contribution Jacobian.
MooseObjectTagWarehouse< DGKernelBase > _dg_kernels
void setConstraintSecondaryValues(NumericVector< Number > &solution, bool displaced)
Sets the value of constrained variables in the solution vector.
bool needInternalNeighborSideMaterial(SubdomainID subdomain_id, THREAD_ID tid) const
Indicates whether this system needs material properties on internal sides.
void setupDM()
Setup the PETSc DM object (when appropriate)
void setupDampers()
Setup damping stuff (called before we actually start)
const bool & usePreSMOResidual() const
Whether we are using pre-SMO residual in relative convergence checks.
void computeKokkosNodalBCsResidual(const std::set< TagID > &tags)
Compute Kokkos nodal BCs.
FieldSplitPreconditionerBase * _fsp
The field split preconditioner if this sytem is using one.
virtual void setSolutionUDotDot(const NumericVector< Number > &udotdot)
Set transient term used by residual and Jacobian evaluation.
virtual void addKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a kernel.
bool hasSaveIn() const
Weather or not the nonlinear system has save-ins.
void computeResidualAndJacobianTags(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Form possibly multiple tag-associated vectors and matrices.
ConstraintWarehouse _constraints
Constraints storage object.
MooseObjectTagWarehouse< HDGKernel > _hybridized_kernels
bool _has_nodalbc_diag_save_in
If there is a nodal BC having diag_save_in.
void destroyColoring()
Destroy the coloring object if it exists.
std::shared_ptr< MoosePreconditioner > _preconditioner
Preconditioner.
TagID residualVectorTag() const override
unsigned int _current_nl_its
Real initialResidual() const
The initial residual.
Data structure used to hold penetration information.
BoundaryID _secondary_boundary
std::map< dof_id_type, PenetrationInfo * > & _penetration_info
Data structure of nodes and their associated penetration information.
BoundaryID _primary_boundary
NearestNodeLocator & _nearest_node
Interface for objects interacting with the PerfGraph.
Base class shared by AD and non-AD scalar kernels.
void accumulateIterationIntoTimeStepOccurences()
Pass the number of solution invalid occurrences from current iteration to cumulative counters.
void syncIteration()
Sync iteration counts to main processor Sum across all processors.
virtual void preInit() override
This is called prior to the libMesh system has been init'd.
virtual bool matrixFromColoring() const
Whether a system matrix is formed from coloring.
Base class for split-based preconditioners.
virtual TagName vectorTagName(const TagID tag) const
Retrieve the name associated with a TagID.
virtual void reinitElemPhys(const Elem *elem, const std::vector< Point > &phys_points_in_elem, const THREAD_ID tid)=0
std::vector< VectorTag > getVectorTags(const std::set< TagID > &tag_ids) const
virtual unsigned int numMatrixTags() const
The total number of tags.
bool defaultGhosting()
Whether or not the user has requested default ghosting ot be on.
virtual unsigned int numVectorTags(const Moose::VectorTagType type=Moose::VECTOR_TAG_ANY) const
The total number of tags, which can be limited to the tag type.
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num)=0
virtual TagID addVectorTag(const TagName &tag_name, const Moose::VectorTagType type=Moose::VECTOR_TAG_RESIDUAL)
Create a Tag.
virtual void reinitNeighborPhys(const Elem *neighbor, unsigned int neighbor_side, const std::vector< Point > &physical_points, const THREAD_ID tid)=0
virtual TagID addMatrixTag(TagName tag_name)
Create a Tag.
virtual std::map< TagName, TagID > & getMatrixTags()
Return all matrix tags in the system, where a tag is represented by a map from name to ID.
virtual GeometricSearchData & geomSearchData()=0
void zeroTaggedVectors(const std::set< TagID > &tags)
Zero all vectors for given tags.
NumericVector< Number > * _u_dot
solution vector for u^dot
virtual libMesh::SparseMatrix< Number > & getMatrix(TagID tag)
Get a raw SparseMatrix.
virtual void deactivateAllMatrixTags()
Make matrices inactive.
FEProblemBase & _fe_problem
the governing finite element/volume problem
const std::set< SubdomainID > & getSubdomainsForVar(unsigned int var_number) const
virtual void subdomainSetup()
std::vector< std::shared_ptr< TimeIntegrator > > _time_integrators
Time integrator.
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
NumericVector< Number > * _u_dotdot
solution vector for u^dotdot
virtual unsigned int nVariables() const
Get the number of variables in this system.
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
unsigned int number() const
Gets the number of this system.
virtual void activateAllMatrixTags()
Make all existing matrices active.
const std::vector< VariableName > & getVariableNames() const
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
virtual void customSetup(const ExecFlagType &exec_type)
NumericVector< Number > & solutionOld()
virtual void disassociateMatrixFromTag(libMesh::SparseMatrix< Number > &matrix, TagID tag)
Disassociate a matrix from a tag.
SubProblem & subproblem()
virtual void initialSetup()
Setup Functions.
virtual void timestepSetup()
virtual void associateVectorToTag(NumericVector< Number > &vec, TagID tag)
Associate a vector for a given tag.
virtual void jacobianSetup()
virtual void residualSetup()
virtual void disassociateVectorFromTag(NumericVector< Number > &vec, TagID tag)
Disassociate a given vector from a given tag.
void closeTaggedVectors(const std::set< TagID > &tags)
Close all vectors for given tags.
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a scalar variable with specified number.
virtual bool hasScalarVariable(const std::string &var_name) const
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
THREAD_ID numThreads() const
virtual bool hasVariable(const std::string &var_name) const
Query a system for a variable.
void closeTaggedMatrices(const std::set< TagID > &tags)
Close all matrices associated the tags.
SubProblem & _subproblem
The subproblem for whom this class holds variable data, etc; this can either be the governing finite ...
void applyScalingFactors(const std::vector< Real > &inverse_scaling_factors)
Applies scaling factors to the system's variables.
virtual void associateMatrixToTag(libMesh::SparseMatrix< Number > &matrix, TagID tag)
Associate a matrix to a tag.
NumericVector< Number > * _u_dotdot_old
old solution vector for u^dotdot
virtual const std::string & name() const
virtual bool hasMatrix(TagID tag) const
Check if the tagged matrix exists in the system.
const VariableWarehouse & variableWarehouse(THREAD_ID tid=0) const
virtual libMesh::DofMap & dofMap()
Gets writeable reference to the dof map.
NumericVector< Number > & solution()
NumericVector< Number > * _u_dot_old
old solution vector for u^dot
bool _automatic_scaling
Whether to automatically scale the variables.
NumericVector< Number > & addVector(const std::string &vector_name, const bool project, const libMesh::ParallelType type)
Adds a solution length vector to the system.
void update()
Update the system (doing libMesh magic)
void max(const T &r, T &o, Request &req) const
void min(const T &r, T &o, Request &req) const
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
std::vector< T * > & queryInto(std::vector< T * > &results, Args &&... args)
queryInto executes the query and stores the results in the given vector.
TheWarehouse is a container for MooseObjects that allows querying/filtering over various customizeabl...
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse.
void add(std::shared_ptr< MooseObject > obj)
add adds a new object to the warehouse and stores attributes/metadata about it for running queries/fi...
const std::vector< MooseVariableFieldBase * > & fieldVariables() const
Get the list of variables.
dof_id_type first_dof(const processor_id_type proc) const
dof_id_type end_dof(const processor_id_type proc) const
dof_id_type n_local_dofs(const unsigned int vn) const
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
void remove_algebraic_ghosting_functor(GhostingFunctor &evaluable_functor)
void ghost_constraints_needed()
void full_sparsity_pattern_needed()
dof_id_type n_dofs(const unsigned int vn) const
ParallelType type() const
virtual void localize(std::vector< T > &v_local) const=0
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
bool identify_variable_groups() const
dof_id_type n_dofs() const
const FEType & variable_type(const unsigned int i) const
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
std::unique_ptr< NumericVector< Number > > solution
void set_basic_system_only()
unsigned int n_vars() const
const DofMap & get_dof_map() const
unsigned int number() const
void appendFVSetupObjects(TheWarehouse &warehouse, const std::string &system_name, const unsigned int system_number, const THREAD_ID tid, std::vector< SetupInterface * > &results)
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
ComputeType
The type of nonlinear computation being performed.
@ ST_LINEAR
Solving a linear problem.
const TagName PREVIOUS_NL_SOLUTION_TAG
static void sort_row(const BidirectionalIterator begin, BidirectionalIterator middle, const BidirectionalIterator end)
std::vector< dof_id_type, Threads::scalable_allocator< dof_id_type > > Row
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())