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 _scalar_kernels(false),
156 _preset_nodal_bcs(false),
157 _ad_preset_nodal_bcs(false),
158#ifdef MOOSE_KOKKOS_ENABLED
159 _kokkos_kernels(false),
160 _kokkos_integrated_bcs(false),
161 _kokkos_nodal_bcs(false),
162 _kokkos_preset_nodal_bcs(false),
163 _kokkos_nodal_kernels(false),
165 _general_dampers(false),
167 _increment_vec(NULL),
168 _use_finite_differenced_preconditioner(false),
169 _fdcoloring(nullptr),
171 _add_implicit_geometric_coupling_entries_to_jacobian(false),
172 _assemble_constraints_separately(false),
173 _need_residual_ghosted(false),
174 _debugging_residuals(false),
178 _n_residual_evaluations(0),
180 _computing_pre_smo_residual(false),
181 _pre_smo_residual(0),
182 _initial_residual(0),
183 _use_pre_smo_residual(false),
184 _print_all_var_norms(false),
186 _has_diag_save_in(false),
187 _has_nodalbc_save_in(false),
188 _has_nodalbc_diag_save_in(false),
189 _computed_scaling(false),
190 _compute_scaling_once(true),
191 _resid_vs_jac_scaling_param(0),
192 _off_diagonals_in_auto_scaling(false),
193 _auto_scaling_initd(false)
211 dof_map.set_implicit_neighbor_dofs(
false);
228#ifdef MOOSE_KOKKOS_ENABLED
240 functor.second.setupMortarMaterials();
242 functor.second.setupMortarMaterials();
252std::vector<SetupInterface *>
255 std::vector<SetupInterface *> fv_objects;
258 appendFVSetupObjects<FVElementalKernel>(
259 warehouse,
"FVElementalKernel",
number(), tid, fv_objects);
260 appendFVSetupObjects<FVFluxKernel>(warehouse,
"FVFluxKernel",
number(), tid, fv_objects);
261 appendFVSetupObjects<FVBoundaryCondition>(warehouse,
"FVDirichletBC",
number(), tid, fv_objects);
262 appendFVSetupObjects<FVBoundaryCondition>(warehouse,
"FVFluxBC",
number(), tid, fv_objects);
263 appendFVSetupObjects<FVInterfaceKernel>(
264 warehouse,
"FVInterfaceKernel",
number(), tid, fv_objects);
272 TIME_SECTION(
"nlInitialSetup", 2,
"Setting Up Nonlinear System");
277 TIME_SECTION(
"kernelsInitialSetup", 2,
"Setting Up Kernels/BCs/Constraints");
294 fv_object->initialSetup();
304#ifdef MOOSE_KOKKOS_ENABLED
313 TIME_SECTION(
"mortarSetup", 2,
"Initializing Mortar Interfaces");
315 auto create_mortar_functors = [
this](
const bool displaced)
319 for (
const auto & [primary_secondary_boundary_pair, interface_config] : mortar_interfaces)
324 auto & mortar_constraints =
330 auto & mortar_functors =
333 mortar_functors.emplace(primary_secondary_boundary_pair,
335 *interface_config.amg,
343 create_mortar_functors(
false);
344 create_mortar_functors(
true);
378 fv_object->timestepSetup();
387#ifdef MOOSE_KOKKOS_ENABLED
414 fv_object->customSetup(exec_type);
423#ifdef MOOSE_KOKKOS_ENABLED
440 const std::string & name,
446 std::shared_ptr<KernelBase> kernel =
454 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
456 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
462 const std::string & name,
479 const std::string & name,
485 std::shared_ptr<NodalKernelBase> kernel =
493 if (parameters.
have_parameter<std::vector<AuxVariableName>>(
"save_in") &&
494 parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
496 if (parameters.
have_parameter<std::vector<AuxVariableName>>(
"save_in") &&
497 parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
503 const std::string & name,
506 std::shared_ptr<ScalarKernelBase> kernel =
516 const std::string & name,
523 std::shared_ptr<BoundaryCondition> bc =
528 const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
530 _vars[tid].addBoundaryVar(boundary_ids, bc_var);
533 std::shared_ptr<NodalBCBase> nbc = std::dynamic_pointer_cast<NodalBCBase>(bc);
534 std::shared_ptr<IntegratedBCBase> ibc = std::dynamic_pointer_cast<IntegratedBCBase>(bc);
539 if (nbc->checkNodalVar() && !nbc->variable().isNodal())
540 mooseError(
"Trying to use nodal boundary condition '",
542 "' on a non-nodal variable '",
543 nbc->variable().name(),
549 _vars[tid].addBoundaryVars(boundary_ids, nbc->getCoupledVars());
551 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
553 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
557 std::shared_ptr<DirichletBCBase> dbc = std::dynamic_pointer_cast<DirichletBCBase>(bc);
558 if (dbc && dbc->preset())
561 std::shared_ptr<ADDirichletBCBase> addbc = std::dynamic_pointer_cast<ADDirichletBCBase>(bc);
562 if (addbc && addbc->preset())
572 _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
574 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
576 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
588 const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
589 _vars[tid].addBoundaryVar(boundary_ids, bc_var);
591 ibc = std::static_pointer_cast<IntegratedBCBase>(bc);
594 _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
599 mooseError(
"Unknown BoundaryCondition type for object named ", bc->name());
604 const std::string & name,
612 if (constraint && constraint->addCouplingEntriesToJacobian())
618 const std::string & name,
623 std::shared_ptr<DiracKernelBase> kernel =
634 const std::string & name,
648 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
650 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
656 const std::string & name,
661 std::shared_ptr<InterfaceKernelBase> interface_kernel =
665 const std::set<BoundaryID> & boundary_ids = interface_kernel->boundaryIDs();
667 _vars[tid].addBoundaryVar(boundary_ids, ik_var);
672 _vars[tid].addBoundaryVars(boundary_ids, interface_kernel->getCoupledVars());
678 const std::string & name,
686 std::shared_ptr<ElementDamper> ed = std::dynamic_pointer_cast<ElementDamper>(damper);
687 std::shared_ptr<NodalDamper> nd = std::dynamic_pointer_cast<NodalDamper>(damper);
688 std::shared_ptr<GeneralDamper> gd = std::dynamic_pointer_cast<GeneralDamper>(damper);
706 const std::string & name,
715std::shared_ptr<Split>
733 if (
_app.
parameters().
get<
bool>(
"use_legacy_initial_residual_evaluation_behavior"))
749 mooseError(
"pre-SMO residual is requested but not evaluated.");
801 parallel_object_only();
803 TIME_SECTION(
"nl::computeResidualTags", 5);
808 bool required_residual = tags.find(
residualVectorTag()) == tags.end() ? false :
true;
820 NumericVector<Number> & vec =
getVector(numeric_vec);
831 if (required_residual)
837 ti->postResidual(residual);
880 const std::set<TagID> & matrix_tags)
882 const bool required_residual =
892 if (required_residual)
898 ti->postResidual(residual);
931 NumericVector<Number> & initial_solution(
solution());
936 TIME_SECTION(
"applyPredictor", 2,
"Applying Predictor");
942 _console <<
" Skipping predictor this step" << std::endl;
947 TIME_SECTION(
"initialBCs", 2,
"Applying BCs To Initial Condition");
950 for (
const auto & bnode : bnd_nodes)
953 Node * node = bnode->_node;
961 if (has_preset_nodal_bcs || has_ad_preset_nodal_bcs)
964 if (has_preset_nodal_bcs)
967 for (
const auto & preset_bc : preset_bcs)
968 preset_bc->computeValue(initial_solution);
970 if (has_ad_preset_nodal_bcs)
973 for (
const auto & preset_bc : preset_bcs_res)
974 preset_bc->computeValue(initial_solution);
980#ifdef MOOSE_KOKKOS_ENABLED
1012NumericVector<Number> &
1035NumericVector<Number> &
1058NumericVector<Number> &
1071 mooseError(
"The required residual vector is not available");
1083 for (
const auto & nc : ncs)
1085 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
1086 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
1088 if ((secondary_node_ids.size() > 0) && (primary_node_ids.size() > 0))
1090 nc->reinitConstraintNodes();
1091 nc->computeResidual(residual);
1110 for (
const auto & nc : ncs)
1112 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
1113 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
1115 if ((secondary_node_ids.size() > 0) && (primary_node_ids.size() > 0))
1117 nc->reinitConstraintNodes();
1118 nc->computeJacobian(jacobian_to_view);
1133 const bool displaced)
1138 const Elem * primary_elem = info._elem;
1139 unsigned int primary_side = info._side_num;
1140 std::vector<Point> points;
1141 points.push_back(info._closest_point);
1162 const Elem *
const undisplaced_primary_elem =
1163 displaced ?
_mesh.
elemPtr(primary_elem->id()) : primary_elem;
1164 const Point undisplaced_primary_physical_point =
1165 [&points, displaced, primary_elem, undisplaced_primary_elem]()
1169 const Point reference_point =
1170 FEMap::inverse_map(primary_elem->dim(), primary_elem, points[0]);
1171 return FEMap::map(primary_elem->dim(), undisplaced_primary_elem, reference_point);
1180 undisplaced_primary_elem, primary_side, {undisplaced_primary_physical_point}, 0);
1197 "If we're calling this method with displaced = true, then we better well have a "
1198 "displaced problem");
1203 bool constraints_applied =
false;
1205 for (
const auto & it : penetration_locators)
1216 const auto & constraints =
1218 std::unordered_set<unsigned int> needed_mat_props;
1219 for (
const auto & constraint : constraints)
1221 const auto & mp_deps = constraint->getMatPropDependencies();
1222 needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
1226 for (
unsigned int i = 0; i < secondary_nodes.size(); i++)
1228 dof_id_type secondary_node_num = secondary_nodes[i];
1229 Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
1237 reinitNodeFace(secondary_node, secondary_boundary, info, displaced);
1239 for (
const auto & nfc : constraints)
1241 if (nfc->isExplicitConstraint())
1247 if (nfc->secondaryBoundary() != secondary_boundary ||
1248 nfc->primaryBoundary() != primary_boundary)
1251 if (nfc->shouldApply())
1253 constraints_applied =
true;
1254 nfc->computeSecondaryValue(
solution);
1257 if (nfc->hasWritableCoupledVariables())
1260 for (
auto * var : nfc->getWritableCoupledVariables())
1262 if (var->isNodalDefined())
1274 std::set<dof_id_type> unique_secondary_node_ids;
1282 const auto & constraints =
1286 unique_secondary_node_ids.clear();
1288 for (
const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
1289 meshhelper.active_subdomain_elements_end(secondary_id)))
1291 for (
auto & n : elem->node_ref_range())
1292 unique_secondary_node_ids.insert(n.id());
1295 for (
auto secondary_node_id : unique_secondary_node_ids)
1297 Node & secondary_node =
_mesh.
nodeRef(secondary_node_id);
1309 for (
const auto & nec : constraints)
1311 if (nec->shouldApply())
1313 constraints_applied =
true;
1314 nec->computeSecondaryValue(
solution);
1326 if (constraints_applied)
1341 "If we're calling this method with displaced = true, then we better well have a "
1342 "displaced problem");
1347 bool constraints_applied;
1348 bool residual_has_inserted_values =
false;
1350 constraints_applied =
false;
1351 for (
const auto & it : penetration_locators)
1357 constraints_applied =
false;
1366 bool has_writable_variables(
false);
1370 const auto & constraints =
1373 for (
unsigned int i = 0; i < secondary_nodes.size(); i++)
1375 dof_id_type secondary_node_num = secondary_nodes[i];
1376 Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
1384 reinitNodeFace(secondary_node, secondary_boundary, info, displaced);
1386 for (
const auto & nfc : constraints)
1392 if (nfc->secondaryBoundary() != secondary_boundary ||
1393 nfc->primaryBoundary() != primary_boundary)
1396 if (nfc->shouldApply())
1398 constraints_applied =
true;
1399 nfc->computeResidual();
1401 if (nfc->overwriteSecondaryResidual())
1407 const auto & secondary_var = nfc->variable();
1408 const auto & secondary_dofs = secondary_var.dofIndices();
1409 mooseAssert(secondary_dofs.size() == secondary_var.count(),
1410 "We are on a node so there should only be one dof per variable (for "
1411 "an ArrayVariable we should have a number of dofs equal to the "
1412 "number of components");
1418 std::vector<Number>
values = {nfc->secondaryResidual()};
1419 residual.insert(
values, secondary_dofs);
1420 residual_has_inserted_values =
true;
1426 if (nfc->hasWritableCoupledVariables())
1429 has_writable_variables =
true;
1430 for (
auto * var : nfc->getWritableCoupledVariables())
1432 if (var->isNodalDefined())
1443 if (has_writable_variables)
1461 if (constraints_applied)
1466 if (residual_has_inserted_values)
1469 residual_has_inserted_values =
false;
1483 if (constraints_applied)
1488 if (residual_has_inserted_values)
1502 for (
const auto & it : element_pair_locators)
1509 const auto & element_constraints =
1513 const std::list<std::pair<const Elem *, const Elem *>> & elem_pairs =
1515 for (
const auto & pr : elem_pairs)
1517 const Elem * elem1 = pr.first;
1518 const Elem * elem2 = pr.second;
1526 for (
const auto & ec : element_constraints)
1533 ec->prepareShapes(ec->variable().number());
1534 ec->prepareNeighborShapes(ec->variable().number());
1537 ec->computeResidual();
1547 std::set<dof_id_type> unique_secondary_node_ids;
1549 constraints_applied =
false;
1550 residual_has_inserted_values =
false;
1551 bool has_writable_variables =
false;
1558 const auto & constraints =
1562 unique_secondary_node_ids.clear();
1564 for (
const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
1565 meshhelper.active_subdomain_elements_end(secondary_id)))
1567 for (
auto & n : elem->node_ref_range())
1568 unique_secondary_node_ids.insert(n.id());
1571 for (
auto secondary_node_id : unique_secondary_node_ids)
1573 Node & secondary_node =
_mesh.
nodeRef(secondary_node_id);
1584 for (
const auto & nec : constraints)
1586 if (nec->shouldApply())
1588 constraints_applied =
true;
1589 nec->computeResidual();
1591 if (nec->overwriteSecondaryResidual())
1594 residual_has_inserted_values =
true;
1600 if (nec->hasWritableCoupledVariables())
1603 has_writable_variables =
true;
1604 for (
auto * var : nec->getWritableCoupledVariables())
1606 if (var->isNodalDefined())
1619 if (constraints_applied)
1624 if (residual_has_inserted_values)
1635 if (has_writable_variables)
1658 for (
const auto & it : penetration_locators)
1668 const auto & constraints =
1670 for (
const auto i : index_range(secondary_nodes))
1672 const auto secondary_node_num = secondary_nodes[i];
1673 const Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
1677 for (
const auto & nfc : constraints)
1679 if (!nfc->isExplicitConstraint())
1686 if (nfc->secondaryBoundary() != secondary_boundary ||
1687 nfc->primaryBoundary() != primary_boundary)
1690 nfc->overwriteBoundaryVariables(soln, secondary_node);
1701 TIME_SECTION(
"residualSetup", 3);
1724#ifdef MOOSE_KOKKOS_ENABLED
1739 parallel_object_only();
1741 TIME_SECTION(
"computeResidualInternal", 3);
1747 std::vector<GeneralUserObject *> uos;
1753 for (
auto & uo : uos)
1754 uo->residualSetup();
1755 for (
auto & uo : uos)
1766#ifdef MOOSE_KOKKOS_ENABLED
1774 TIME_SECTION(
"Kernels", 3 );
1785 using FVRange = StoredRange<MooseMesh::const_face_info_iterator, const FaceInfo *>;
1804 for (
unsigned int i = 0; i < n_threads;
1816 TIME_SECTION(
"ScalarKernels", 3 );
1824 else if (tags.size() == 1)
1825 scalar_kernel_warehouse =
1831 bool have_scalar_contributions =
false;
1833 for (
const auto & scalar_kernel : scalars)
1835 scalar_kernel->reinit();
1836 const std::vector<dof_id_type> & dof_indices = scalar_kernel->variable().dofIndices();
1837 const DofMap & dof_map = scalar_kernel->variable().dofMap();
1838 const dof_id_type first_dof = dof_map.first_dof();
1839 const dof_id_type end_dof = dof_map.end_dof();
1840 for (dof_id_type dof : dof_indices)
1842 if (dof >= first_dof && dof < end_dof)
1844 scalar_kernel->computeResidual();
1845 have_scalar_contributions =
true;
1850 if (have_scalar_contributions)
1861 TIME_SECTION(
"NodalKernels", 3 );
1867 if (range.begin() != range.end())
1874 for (
unsigned int i = 0; i < n_threads;
1893 TIME_SECTION(
"NodalKernelBCs", 3 );
1902 for (
unsigned int i = 0; i < n_threads;
1961 const std::set<TagID> & matrix_tags)
1963 TIME_SECTION(
"computeResidualAndJacobianInternal", 3);
1970 "residual_and_jacobian_together does not yet support ScalarKernels. Their "
1971 "contributions would be silently dropped. Please use "
1972 "residual_and_jacobian_together = false");
1976 "residual_and_jacobian_together does not yet support NodalKernels. Their "
1977 "contributions would be silently dropped. Please use "
1978 "residual_and_jacobian_together = false");
1983 "residual_and_jacobian_together does not yet support nodal constraints. Their "
1984 "contributions would be silently dropped. Please use "
1985 "residual_and_jacobian_together = false");
1990 for (
auto tag : matrix_tags)
1997 if (
auto petsc_matrix =
dynamic_cast<PetscMatrix<Number> *
>(&jacobian))
1999 LibmeshPetscCall(MatSetOption(petsc_matrix->mat(),
2000 MAT_KEEP_NONZERO_PATTERN,
2004 MatSetOption(petsc_matrix->mat(), MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
2006 LibmeshPetscCall(MatSetOption(
2007 cast_ref<PetscMatrix<Number> &>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE));
2015 std::vector<UserObject *> uos;
2021 for (
auto & uo : uos)
2022 uo->residualSetup();
2023 for (
auto & uo : uos)
2034#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();
2186 else if (tags.size() == 1)
2207 std::map<std::string, std::set<unsigned int>> bc_involved_vars;
2209 for (
const auto & bid : all_boundary_ids)
2216 for (
const auto & bc : bcs)
2218 const std::vector<MooseVariableFEBase *> & coupled_moose_vars = bc->getCoupledMooseVars();
2222 std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2223 for (
const auto & coupled_var : coupled_moose_vars)
2225 var_set.insert(coupled_var->number());
2227 var_set.insert(bc->variable().number());
2247 for (
const auto & bnode : bnd_nodes)
2250 Node * node = bnode->_node;
2258 for (
const auto & bc : bcs)
2261 std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2267 for (
const auto & it : coupling_entries)
2269 unsigned int ivar = it.first->number(), jvar = it.second->number();
2275 if ((bc->variable().number() == ivar) && var_set.count(jvar) && bc->shouldApply())
2276 bc->computeOffDiagJacobian(jvar);
2279 const auto & coupled_scalar_vars = bc->getCoupledMooseScalarVars();
2280 for (
const auto & jvariable : coupled_scalar_vars)
2282 bc->computeOffDiagJacobianScalar(jvariable->number());
2295 [[maybe_unused]]
const std::set<TagID> & vector_tags,
2296 [[maybe_unused]]
const std::set<TagID> & matrix_tags)
2298#ifdef MOOSE_KOKKOS_ENABLED
2311 if (!bnd_nodes.
empty())
2313 TIME_SECTION(
"NodalBCs", 3 );
2315 for (
const auto & bnode : bnd_nodes)
2318 Node * node = bnode->_node;
2327 for (
const auto & nbc : bcs)
2328 if (nbc->shouldApply())
2329 nbc->computeResidualAndJacobian();
2345 unsigned int s =
number();
2346 if (node.has_dofs(s))
2348 for (
unsigned int v = 0; v <
nVariables(); v++)
2349 for (
unsigned int c = 0; c < node.n_comp(s, v); c++)
2350 dofs.push_back(node.dof_number(s, v, c));
2357 std::unordered_map<dof_id_type, std::vector<dof_id_type>> & graph)
2361 for (
const auto & it : nearest_node_locators)
2363 std::vector<dof_id_type> & secondary_nodes = it.second->_secondary_nodes;
2365 for (
const auto & secondary_node : secondary_nodes)
2367 std::set<dof_id_type> unique_secondary_indices;
2368 std::set<dof_id_type> unique_primary_indices;
2370 auto node_to_elem_pair = node_to_elem_map.find(secondary_node);
2371 if (node_to_elem_pair != node_to_elem_map.end())
2373 const std::vector<dof_id_type> & elems = node_to_elem_pair->second;
2376 for (
const auto & cur_elem : elems)
2378 std::vector<dof_id_type> dof_indices;
2381 for (
const auto & dof : dof_indices)
2382 unique_secondary_indices.insert(dof);
2386 std::vector<dof_id_type> primary_nodes = it.second->_neighbor_nodes[secondary_node];
2388 for (
const auto & primary_node : primary_nodes)
2390 auto primary_node_to_elem_pair = node_to_elem_map.find(primary_node);
2391 mooseAssert(primary_node_to_elem_pair != node_to_elem_map.end(),
2392 "Missing entry in node to elem map");
2393 const std::vector<dof_id_type> & primary_node_elems = primary_node_to_elem_pair->second;
2396 for (
const auto & cur_elem : primary_node_elems)
2398 std::vector<dof_id_type> dof_indices;
2401 for (
const auto & dof : dof_indices)
2402 unique_primary_indices.insert(dof);
2406 for (
const auto & secondary_id : unique_secondary_indices)
2407 for (
const auto & primary_id : unique_primary_indices)
2409 graph[secondary_id].push_back(primary_id);
2410 graph[primary_id].push_back(secondary_id);
2417 for (
const auto & nc : ncs)
2419 std::vector<dof_id_type> primary_dofs;
2420 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
2421 for (
const auto & node_id : primary_node_ids)
2424 if (node && node->processor_id() == this->
processor_id())
2432 std::vector<dof_id_type> secondary_dofs;
2433 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
2434 for (
const auto & node_id : secondary_node_ids)
2437 if (node && node->processor_id() == this->
processor_id())
2445 for (
const auto & primary_id : primary_dofs)
2446 for (
const auto & secondary_id : secondary_dofs)
2448 graph[primary_id].push_back(secondary_id);
2449 graph[secondary_id].push_back(primary_id);
2454 for (
auto & it : graph)
2456 std::vector<dof_id_type> & row = it.second;
2457 std::sort(row.begin(), row.end());
2458 std::vector<dof_id_type>::iterator uit = std::unique(row.begin(), row.end());
2459 row.resize(uit - row.begin());
2473 std::unordered_map<dof_id_type, std::vector<dof_id_type>> graph;
2477 for (
const auto & it : graph)
2479 dof_id_type dof = it.first;
2480 const auto & row = it.second;
2482 for (
const auto & coupled_dof : row)
2483 jacobian.add(dof, coupled_dof, 0);
2497 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2498 MAT_NEW_NONZERO_ALLOCATION_ERR,
2501 LibmeshPetscCall(MatSetOption(
2502 cast_ref<PetscMatrix<Number> &>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE));
2504 std::vector<numeric_index_type> zero_rows;
2508 "If we're calling this method with displaced = true, then we better well have a "
2509 "displaced problem");
2514 bool constraints_applied;
2516 constraints_applied =
false;
2517 for (
const auto & it : penetration_locators)
2523 constraints_applied =
false;
2535 const auto & constraints =
2538 for (
const auto & secondary_node_num : secondary_nodes)
2540 Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
2548 reinitNodeFace(secondary_node, secondary_boundary, info, displaced);
2551 for (
const auto & nfc : constraints)
2553 if (nfc->isExplicitConstraint())
2559 if (nfc->secondaryBoundary() != secondary_boundary ||
2560 nfc->primaryBoundary() != primary_boundary)
2563 nfc->_jacobian = &jacobian_to_view;
2565 if (nfc->shouldApply())
2567 constraints_applied =
true;
2573 nfc->prepareShapes(nfc->variable().number());
2574 nfc->prepareNeighborShapes(nfc->variable().number());
2576 nfc->computeJacobian();
2578 if (nfc->overwriteSecondaryJacobian())
2581 zero_rows.push_back(nfc->variable().nodalDofIndex());
2584 std::vector<dof_id_type> secondary_dofs(1, nfc->variable().nodalDofIndex());
2590 Real scaling_factor =
2591 nfc->overwriteSecondaryJacobian() ? 1. : nfc->variable().scalingFactor();
2597 nfc->_connected_dof_indices,
2601 if (nfc->addCouplingEntriesToJacobian())
2608 nfc->primaryVariable().dofIndicesNeighbor(),
2614 nfc->primaryVariable().dofIndicesNeighbor(),
2615 nfc->_connected_dof_indices,
2616 nfc->primaryVariable().scalingFactor());
2623 const std::vector<MooseVariableFEBase *> coupled_vars = nfc->getCoupledMooseVars();
2624 for (
const auto & jvar : coupled_vars)
2632 if (nfc->variable().number() == jvar->number() ||
2634 nfc->variable().number(), jvar->number(), this->number()))
2642 nfc->prepareShapes(nfc->variable().number());
2643 nfc->prepareNeighborShapes(jvar->number());
2645 nfc->computeOffDiagJacobian(jvar->number());
2651 nfc->_connected_dof_indices,
2655 if (nfc->addCouplingEntriesToJacobian())
2662 jvar->dofIndicesNeighbor(),
2668 nfc->variable().dofIndicesNeighbor(),
2669 nfc->_connected_dof_indices,
2670 nfc->variable().scalingFactor());
2687 if (constraints_applied)
2689 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2690 MAT_KEEP_NONZERO_PATTERN,
2694 jacobian.zero_rows(zero_rows, 0.0);
2706 if (constraints_applied)
2708 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2709 MAT_KEEP_NONZERO_PATTERN,
2713 jacobian.zero_rows(zero_rows, 0.0);
2723 for (
const auto & it : element_pair_locators)
2730 const auto & element_constraints =
2734 const std::list<std::pair<const Elem *, const Elem *>> & elem_pairs =
2736 for (
const auto & pr : elem_pairs)
2738 const Elem * elem1 = pr.first;
2739 const Elem * elem2 = pr.second;
2747 for (
const auto & ec : element_constraints)
2759 ec->prepareShapes(ec->variable().number());
2760 ec->prepareNeighborShapes(ec->variable().number());
2763 ec->computeJacobian();
2773 std::set<dof_id_type> unique_secondary_node_ids;
2774 constraints_applied =
false;
2781 const auto & constraints =
2785 unique_secondary_node_ids.clear();
2787 for (
const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
2788 meshhelper.active_subdomain_elements_end(secondary_id)))
2790 for (
auto & n : elem->node_ref_range())
2791 unique_secondary_node_ids.insert(n.id());
2794 for (
auto secondary_node_id : unique_secondary_node_ids)
2796 const Node & secondary_node =
_mesh.
nodeRef(secondary_node_id);
2805 for (
const auto & nec : constraints)
2807 if (nec->shouldApply())
2809 constraints_applied =
true;
2816 nec->_jacobian = &jacobian_to_view;
2817 nec->prepareShapes(nec->variable().number());
2818 nec->prepareNeighborShapes(nec->variable().number());
2820 nec->computeJacobian();
2822 if (nec->overwriteSecondaryJacobian())
2825 zero_rows.push_back(nec->variable().nodalDofIndex());
2828 std::vector<dof_id_type> secondary_dofs(1, nec->variable().nodalDofIndex());
2834 nec->_connected_dof_indices,
2835 nec->variable().scalingFactor());
2840 nec->primaryVariable().dofIndicesNeighbor(),
2841 nec->_connected_dof_indices,
2842 nec->primaryVariable().scalingFactor());
2848 const std::vector<MooseVariableFEBase *> coupled_vars = nec->getCoupledMooseVars();
2849 for (
const auto & jvar : coupled_vars)
2857 if (nec->variable().number() == jvar->number() ||
2859 nec->variable().number(), jvar->number(), this->number()))
2867 nec->prepareShapes(nec->variable().number());
2868 nec->prepareNeighborShapes(jvar->number());
2870 nec->computeOffDiagJacobian(jvar->number());
2876 nec->_connected_dof_indices,
2877 nec->variable().scalingFactor());
2882 nec->variable().dofIndicesNeighbor(),
2883 nec->_connected_dof_indices,
2884 nec->variable().scalingFactor());
2899 if (constraints_applied)
2901 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2902 MAT_KEEP_NONZERO_PATTERN,
2906 jacobian.zero_rows(zero_rows, 0.0);
2920 else if (tags.size() == 1)
2934 bool have_scalar_contributions =
false;
2935 for (
const auto & kernel : scalars)
2937 if (!kernel->computesJacobian())
2941 const std::vector<dof_id_type> & dof_indices = kernel->variable().dofIndices();
2942 const DofMap & dof_map = kernel->variable().dofMap();
2943 const dof_id_type first_dof = dof_map.first_dof();
2944 const dof_id_type end_dof = dof_map.end_dof();
2945 for (dof_id_type dof : dof_indices)
2947 if (dof >= first_dof && dof < end_dof)
2949 kernel->computeJacobian();
2951 have_scalar_contributions =
true;
2957 if (have_scalar_contributions)
2986#ifdef MOOSE_KOKKOS_ENABLED
3001 TIME_SECTION(
"computeJacobianInternal", 3);
3008 for (
auto tag : tags)
3015 if (
auto petsc_matrix =
dynamic_cast<PetscMatrix<Number> *
>(&jacobian))
3017 LibmeshPetscCall(MatSetOption(petsc_matrix->mat(),
3018 MAT_KEEP_NONZERO_PATTERN,
3022 MatSetOption(petsc_matrix->mat(), MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
3024 LibmeshPetscCall(MatSetOption(
3025 cast_ref<PetscMatrix<Number> &>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE));
3033 std::vector<UserObject *> uos;
3039 for (
auto & uo : uos)
3040 uo->jacobianSetup();
3041 for (
auto & uo : uos)
3052#ifdef MOOSE_KOKKOS_ENABLED
3072 for (
unsigned int i = 0; i < n_threads;
3077 using FVRange = StoredRange<MooseMesh::const_face_info_iterator, const FaceInfo *>;
3112 for (
unsigned int i = 0; i < n_threads;
3135 for (
unsigned int i = 0; i < n_threads;
3147 for (
unsigned int i = 0; i < n_threads;
3161 for (
unsigned int i = 0; i < n_threads; i++)
3172 for (
unsigned int i = 0; i < n_threads;
3182 static bool first =
true;
3207 std::unique_ptr<SparseMatrix<Number>> hash_copy;
3208 const SparseMatrix<Number> * view_jac_ptr;
3209 auto make_readable_jacobian = [&]()
3211#if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0)
3212 if (system_matrix.use_hash_table())
3214 hash_copy = cast_ref<PetscMatrix<Number> &>(system_matrix).copy_from_hash();
3215 view_jac_ptr = hash_copy.get();
3218 view_jac_ptr = &system_matrix;
3220 view_jac_ptr = &system_matrix;
3222 if (view_jac_ptr == &system_matrix)
3223 system_matrix.close();
3226 make_readable_jacobian();
3230 if (had_nodal_constraints)
3232 make_readable_jacobian();
3268 for (
auto & tag : tags)
3287 TIME_SECTION(
"computeJacobianTags", 5);
3309 for (
auto & tag : tags)
3317 const std::set<TagID> & tags)
3319 TIME_SECTION(
"computeJacobianBlocks", 3);
3322 for (
unsigned int i = 0; i <
blocks.size(); i++)
3324 SparseMatrix<Number> & jacobian =
blocks[i]->_jacobian;
3326 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
3327 MAT_KEEP_NONZERO_PATTERN,
3330 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
3331 MAT_NEW_NONZERO_ALLOCATION_ERR,
3348 for (
unsigned int i = 0; i <
blocks.size(); i++)
3349 blocks[i]->_jacobian.close();
3351 for (
unsigned int i = 0; i <
blocks.size(); i++)
3354 SparseMatrix<Number> & jacobian =
blocks[i]->_jacobian;
3356 unsigned int ivar =
blocks[i]->_ivar;
3357 unsigned int jvar =
blocks[i]->_jvar;
3360 std::vector<numeric_index_type> zero_rows;
3364 for (
const auto & bnode : bnd_nodes)
3367 Node * node = bnode->_node;
3377 for (
const auto & bc : bcs)
3378 if (bc->variable().number() == ivar && bc->shouldApply())
3382 zero_rows.push_back(node->dof_number(precond_system.
number(), 0, 0));
3394 jacobian.zero_rows(zero_rows, 1.0);
3396 jacobian.zero_rows(zero_rows, 0.0);
3424#ifdef MOOSE_KOKKOS_ENABLED
3436 const NumericVector<Number> & update)
3440 bool has_active_dampers =
false;
3448 TIME_SECTION(
"computeDampers", 3,
"Computing Dampers");
3449 has_active_dampers =
true;
3453 damping = std::min(cid.
damping(), damping);
3462 TIME_SECTION(
"computeDamping::element", 3,
"Computing Element Damping");
3464 has_active_dampers =
true;
3468 damping = std::min(cndt.
damping(), damping);
3477 TIME_SECTION(
"computeDamping::general", 3,
"Computing General Damping");
3479 has_active_dampers =
true;
3481 for (
const auto & damper : gdampers)
3486 damper->checkMinDamping(gd_damping);
3492 damping = std::min(gd_damping, damping);
3504 catch (std::exception & e)
3507 const std::string & message = e.
what();
3508 if (message.find(
"Jacobian") == std::string::npos)
3514 if (has_active_dampers && damping < 1.0)
3515 _console <<
" Damping factor: " << damping << std::endl;
3522 const std::set<TagID> & matrix_tags,
3527 std::set<const Elem *> dirac_elements;
3531 TIME_SECTION(
"computeDirac", 3,
"Computing DiracKernels");
3537 for (
const auto & dkernel : dkernels)
3539 dkernel->clearPoints();
3540 dkernel->addPoints();
3548 DistElemRange range(dirac_elements.begin(), dirac_elements.end(), 1);
3566NumericVector<Number> &
3575NumericVector<Number> &
3607 std::vector<dof_id_type> & n_nz,
3608 std::vector<dof_id_type> & n_oz)
3614 std::unordered_map<dof_id_type, std::vector<dof_id_type>> graph;
3629 for (
const auto & git : graph)
3631 dof_id_type dof = git.first;
3632 dof_id_type local_dof = dof - first_dof_on_proc;
3634 if (dof < first_dof_on_proc || dof >= end_dof_on_proc)
3637 const auto & row = git.second;
3641 unsigned int original_row_length = sparsity_row.size();
3643 sparsity_row.insert(sparsity_row.end(), row.begin(), row.end());
3646 sparsity_row.begin(), sparsity_row.begin() + original_row_length, sparsity_row.end());
3649 for (
const auto & coupled_dof : row)
3651 if (coupled_dof < first_dof_on_proc || coupled_dof >= end_dof_on_proc)
3653 if (n_oz[local_dof] < n_dofs_not_on_proc)
3658 if (n_nz[local_dof] < n_dofs_on_proc)
3694 mooseError(
"More than one active Preconditioner detected");
3713 const std::set<MooseVariable *> & damped_vars)
3715 for (
const auto & var : damped_vars)
3721 const std::set<MooseVariable *> & damped_vars)
3723 for (
const auto & var : damped_vars)
3731 std::set<SubdomainID> input_subdomains;
3732 std::set<std::string> kernel_variables;
3734 bool global_kernels_exist =
false;
3744#ifdef MOOSE_KOKKOS_ENABLED
3751 std::vector<FVElementalKernel *> fv_elemental_kernels;
3754 .template condition<AttribSystem>(
"FVElementalKernel")
3757 for (
auto fv_kernel : fv_elemental_kernels)
3759 if (fv_kernel->blockRestricted())
3760 for (
auto block_id : fv_kernel->blockIDs())
3761 input_subdomains.insert(block_id);
3763 global_kernels_exist =
true;
3764 kernel_variables.insert(fv_kernel->variable().name());
3773 std::vector<FVFluxKernel *> fv_flux_kernels;
3776 .template condition<AttribSystem>(
"FVFluxKernel")
3779 for (
auto fv_kernel : fv_flux_kernels)
3781 if (fv_kernel->blockRestricted())
3782 for (
auto block_id : fv_kernel->blockIDs())
3783 input_subdomains.insert(block_id);
3785 global_kernels_exist =
true;
3786 kernel_variables.insert(fv_kernel->variable().name());
3789 std::vector<FVInterfaceKernel *> fv_interface_kernels;
3792 .template condition<AttribSystem>(
"FVInterfaceKernel")
3795 for (
auto fvik : fv_interface_kernels)
3797 kernel_variables.insert(scalar_fvik->lambdaVariable().name());
3799 std::vector<FVFluxBC *> fv_flux_bcs;
3802 .template condition<AttribSystem>(
"FVFluxBC")
3805 for (
auto fvbc : fv_flux_bcs)
3807 kernel_variables.insert(scalar_fvbc->lambdaVariable().name());
3812 const auto additional_variables_covered = ibc->additionalROVariables();
3813 kernel_variables.insert(additional_variables_covered.begin(),
3814 additional_variables_covered.end());
3818 if (!global_kernels_exist)
3820 std::set<SubdomainID> difference;
3821 std::set_difference(mesh_subdomains.begin(),
3822 mesh_subdomains.end(),
3823 input_subdomains.begin(),
3824 input_subdomains.end(),
3825 std::inserter(difference, difference.end()));
3829 difference.erase(
id);
3831 difference.erase(
id);
3833 if (!difference.empty())
3835 std::vector<SubdomainID> difference_vec =
3836 std::vector<SubdomainID>(difference.begin(), difference.end());
3838 std::stringstream missing_block_names;
3839 std::copy(difference_names.begin(),
3840 difference_names.end(),
3841 std::ostream_iterator<std::string>(missing_block_names,
" "));
3842 std::stringstream missing_block_ids;
3843 std::copy(difference.begin(),
3845 std::ostream_iterator<unsigned int>(missing_block_ids,
" "));
3847 mooseError(
"Each subdomain must contain at least one Kernel.\nThe following block(s) lack an "
3849 missing_block_names.str(),
3851 missing_block_ids.str(),
3859 std::set<VariableName> difference;
3860 std::set_difference(variables.begin(),
3862 kernel_variables.begin(),
3863 kernel_variables.end(),
3864 std::inserter(difference, difference.end()));
3867 std::set<VariableName>
vars(difference);
3868 for (
auto & var_name :
vars)
3871 for (
const auto &
id : blks)
3873 difference.erase(var_name);
3876 if (!difference.empty())
3878 std::stringstream missing_kernel_vars;
3879 std::copy(difference.begin(),
3881 std::ostream_iterator<std::string>(missing_kernel_vars,
" "));
3882 mooseError(
"Each variable must be referenced by at least one active Kernel.\nThe following "
3883 "variable(s) lack an active kernel: " +
3884 missing_kernel_vars.str());
3896std::vector<std::string>
3899 std::vector<std::string> variable_names;
3901 if (time_kernels.hasActiveObjects())
3902 for (
const auto & kernel : time_kernels.getObjects())
3903 variable_names.push_back(kernel->variable().name());
3905 return variable_names;
3915 if (std::static_pointer_cast<MaterialPropertyInterface>(bc)->getMaterialPropertyCalled())
3922 if (std::static_pointer_cast<MaterialPropertyInterface>(ik)->getMaterialPropertyCalled())
3930 if (
auto mpi = std::dynamic_pointer_cast<MaterialPropertyInterface>(ct);
3931 mpi && mpi->getMaterialPropertyCalled())
3943 if (std::static_pointer_cast<MaterialPropertyInterface>(ik)->getMaterialPropertyCalled())
3955 if (std::static_pointer_cast<MaterialPropertyInterface>(dg)->getMaterialPropertyCalled())
3978 const std::set<TagID> & vector_tags,
3979 const std::set<TagID> & matrix_tags)
3981 parallel_object_only();
3986 map_pr.second(compute_type, vector_tags, matrix_tags);
3989 map_pr.second(compute_type, vector_tags, matrix_tags);
3991 catch (MetaPhysicL::LogicError &)
3994 "We caught a MetaPhysicL error in NonlinearSystemBase::mortarConstraints. This is very "
3995 "likely due to AD not having a sufficiently large derivative container size. Please run "
3996 "MOOSE configure with the '--with-derivative-size=<n>' option");
4014 for (
const auto var_number : make_range(
n_vars))
4019 std::set<unsigned int> var_numbers, var_numbers_covered, var_numbers_not_covered;
4020 for (
const auto var_number : make_range(
n_vars))
4021 var_numbers.insert(var_number);
4031 "', provided to the 'scaling_group_variables' parameter, does not exist in "
4032 "the nonlinear system.");
4038 if (!map_pair.second)
4039 mooseError(
"Variable ", var_name,
" is contained in multiple scaling grouplings");
4040 var_numbers_covered.insert(var.
number());
4043 std::set_difference(var_numbers.begin(),
4045 var_numbers_covered.begin(),
4046 var_numbers_covered.end(),
4047 std::inserter(var_numbers_not_covered, var_numbers_not_covered.begin()));
4052 for (
auto var_number : var_numbers_not_covered)
4057 const auto & number_to_var_map =
_vars[0].numberToVariableMap();
4063 libmesh_map_find(number_to_var_map, i)->
name()) !=
4076 _console <<
"\nPerforming automatic scaling calculation\n" << std::endl;
4078 TIME_SECTION(
"computeScaling", 3,
"Computing Automatic Scaling");
4085 std::vector<dof_id_type> dof_indices;
4093 auto & dof_map =
dofMap();
4099 const NumericVector<Number> & scaling_residual =
RHS();
4110 auto init_vector = NumericVector<Number>::build(this->
comm());
4111 init_vector->init(
system().n_dofs(),
system().n_local_dofs(),
false, PARALLEL);
4137 auto examine_dof_indices = [
this,
4141 &jac_inverse_scaling_factors,
4142 &resid_inverse_scaling_factors,
4143 &scaling_residual](
const auto & dof_indices,
const auto var_number)
4145 for (
auto dof_index : dof_indices)
4146 if (dof_map.local_index(dof_index))
4151 auto mat_value = (*_scaling_matrix)(dof_index, dof_index);
4153 factor = std::max(factor, std::abs(mat_value));
4157 auto vec_value = scaling_residual(dof_index);
4159 factor = std::max(factor, std::abs(vec_value));
4169 dof_map.dof_indices(elem, dof_indices, i);
4170 examine_dof_indices(dof_indices, i);
4176 dof_map.SCALAR_dof_indices(dof_indices, i);
4177 examine_dof_indices(dof_indices, i);
4185 if (jac_scaling && resid_scaling)
4186 for (MooseIndex(inverse_scaling_factors) i = 0; i < inverse_scaling_factors.size(); ++i)
4189 if (!resid_inverse_scaling_factors[i])
4191 if (!jac_inverse_scaling_factors[i])
4192 inverse_scaling_factors[i] = 1;
4194 inverse_scaling_factors[i] = jac_inverse_scaling_factors[i];
4196 else if (!jac_inverse_scaling_factors[i])
4198 inverse_scaling_factors[i] = resid_inverse_scaling_factors[i];
4200 inverse_scaling_factors[i] =
4204 else if (jac_scaling)
4205 inverse_scaling_factors = jac_inverse_scaling_factors;
4206 else if (resid_scaling)
4207 inverse_scaling_factors = resid_inverse_scaling_factors;
4209 mooseError(
"We shouldn't be calling this routine if we're not performing any scaling");
4212 for (
auto & scaling_factor : inverse_scaling_factors)
4213 if (scaling_factor == 0)
4217 std::vector<Real> flattened_inverse_scaling_factors(
system().
n_vars());
4218 for (
const auto i : index_range(flattened_inverse_scaling_factors))
4219 flattened_inverse_scaling_factors[i] = inverse_scaling_factors[
_var_to_group_var[i]];
4225 flattened_inverse_scaling_factors);
4238 auto & scaling_vector =
getVector(
"scaling_factors");
4241 const auto & dof_map =
dofMap();
4243 const auto & field_variables =
_vars[0].fieldVariables();
4244 const auto & scalar_variables =
_vars[0].scalars();
4246 std::vector<dof_id_type> dof_indices;
4248 for (
const Elem *
const elem :
4249 as_range(lm_mesh.active_local_elements_begin(), lm_mesh.active_local_elements_end()))
4250 for (
const auto *
const field_var : field_variables)
4252 const auto & factors = field_var->arrayScalingFactor();
4253 for (
const auto i : make_range(field_var->count()))
4255 dof_map.dof_indices(elem, dof_indices, field_var->number() + i);
4256 for (
const auto dof : dof_indices)
4257 scaling_vector.set(dof, factors[i]);
4261 for (
const auto *
const scalar_var : scalar_variables)
4263 mooseAssert(scalar_var->count() == 1,
4264 "Scalar variables should always have only one component.");
4265 dof_map.SCALAR_dof_indices(dof_indices, scalar_var->number());
4266 for (
const auto dof : dof_indices)
4267 scaling_vector.set(dof, scalar_var->scalingFactor());
4271 scaling_vector.close();
4293 if (!scaling_succeeded)
4310 LibmeshPetscCall(MatFDColoringDestroy(&
_fdcoloring));
4317 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 preSolve()
Method that gets called in each iteration before the solve.
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 setKokkosInitialSolution()
void assembleScalingVector()
Assemble the numeric vector of scaling factors such that it can be used during assembly of the system...
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 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)
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.
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...
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 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())