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
249 functor.second.setupMortarMaterials();
251 functor.second.setupMortarMaterials();
261std::vector<SetupInterface *>
264 std::vector<SetupInterface *> fv_objects;
267 appendFVSetupObjects<FVElementalKernel>(
268 warehouse,
"FVElementalKernel",
number(), tid, fv_objects);
269 appendFVSetupObjects<FVFluxKernel>(warehouse,
"FVFluxKernel",
number(), tid, fv_objects);
270 appendFVSetupObjects<FVBoundaryCondition>(warehouse,
"FVDirichletBC",
number(), tid, fv_objects);
271 appendFVSetupObjects<FVBoundaryCondition>(warehouse,
"FVFluxBC",
number(), tid, fv_objects);
272 appendFVSetupObjects<FVInterfaceKernel>(
273 warehouse,
"FVInterfaceKernel",
number(), tid, fv_objects);
281 TIME_SECTION(
"nlInitialSetup", 2,
"Setting Up Nonlinear System");
286 TIME_SECTION(
"kernelsInitialSetup", 2,
"Setting Up Kernels/BCs/Constraints");
303 fv_object->initialSetup();
313#ifdef MOOSE_KOKKOS_ENABLED
322 TIME_SECTION(
"mortarSetup", 2,
"Initializing Mortar Interfaces");
324 auto create_mortar_functors = [
this](
const bool displaced)
328 for (
const auto & [primary_secondary_boundary_pair, interface_config] : mortar_interfaces)
333 auto & mortar_constraints =
339 auto & mortar_functors =
342 mortar_functors.emplace(primary_secondary_boundary_pair,
344 *interface_config.amg,
352 create_mortar_functors(
false);
353 create_mortar_functors(
true);
387 fv_object->timestepSetup();
396#ifdef MOOSE_KOKKOS_ENABLED
423 fv_object->customSetup(exec_type);
432#ifdef MOOSE_KOKKOS_ENABLED
449 const std::string & name,
455 std::shared_ptr<KernelBase> kernel =
463 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
465 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
471 const std::string & name,
488 const std::string & name,
494 std::shared_ptr<NodalKernelBase> kernel =
502 if (parameters.
have_parameter<std::vector<AuxVariableName>>(
"save_in") &&
503 parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
505 if (parameters.
have_parameter<std::vector<AuxVariableName>>(
"save_in") &&
506 parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
512 const std::string & name,
515 std::shared_ptr<ScalarKernelBase> kernel =
525 const std::string & name,
532 std::shared_ptr<BoundaryCondition> bc =
537 const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
539 _vars[tid].addBoundaryVar(boundary_ids, bc_var);
542 std::shared_ptr<NodalBCBase> nbc = std::dynamic_pointer_cast<NodalBCBase>(bc);
543 std::shared_ptr<IntegratedBCBase> ibc = std::dynamic_pointer_cast<IntegratedBCBase>(bc);
548 if (nbc->checkNodalVar() && !nbc->variable().isNodal())
549 mooseError(
"Trying to use nodal boundary condition '",
551 "' on a non-nodal variable '",
552 nbc->variable().name(),
558 _vars[tid].addBoundaryVars(boundary_ids, nbc->getCoupledVars());
560 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
562 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
566 std::shared_ptr<DirichletBCBase> dbc = std::dynamic_pointer_cast<DirichletBCBase>(bc);
567 if (dbc && dbc->preset())
570 std::shared_ptr<ADDirichletBCBase> addbc = std::dynamic_pointer_cast<ADDirichletBCBase>(bc);
571 if (addbc && addbc->preset())
581 _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
583 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
585 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
588 for (tid = 1; tid < this->
numThreads(); tid++)
597 const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
598 _vars[tid].addBoundaryVar(boundary_ids, bc_var);
600 ibc = std::static_pointer_cast<IntegratedBCBase>(bc);
603 _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
608 mooseError(
"Unknown BoundaryCondition type for object named ", bc->name());
613 const std::string & name,
621 if (constraint && constraint->addCouplingEntriesToJacobian())
627 const std::string & name,
632 std::shared_ptr<DiracKernelBase> kernel =
643 const std::string & name,
657 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
659 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
665 const std::string & name,
670 std::shared_ptr<InterfaceKernelBase> interface_kernel =
674 const std::set<BoundaryID> & boundary_ids = interface_kernel->boundaryIDs();
676 _vars[tid].addBoundaryVar(boundary_ids, ik_var);
681 _vars[tid].addBoundaryVars(boundary_ids, interface_kernel->getCoupledVars());
687 const std::string & name,
695 std::shared_ptr<ElementDamper> ed = std::dynamic_pointer_cast<ElementDamper>(damper);
696 std::shared_ptr<NodalDamper> nd = std::dynamic_pointer_cast<NodalDamper>(damper);
697 std::shared_ptr<GeneralDamper> gd = std::dynamic_pointer_cast<GeneralDamper>(damper);
715 const std::string & name,
724std::shared_ptr<Split>
742 if (
_app.
parameters().
get<
bool>(
"use_legacy_initial_residual_evaluation_behavior"))
758 mooseError(
"pre-SMO residual is requested but not evaluated.");
810 parallel_object_only();
812 TIME_SECTION(
"nl::computeResidualTags", 5);
817 bool required_residual = tags.find(
residualVectorTag()) == tags.end() ? false :
true;
829 NumericVector<Number> & vec =
getVector(numeric_vec);
840 if (required_residual)
846 ti->postResidual(residual);
889 const std::set<TagID> & matrix_tags)
891 const bool required_residual =
901 if (required_residual)
907 ti->postResidual(residual);
940 NumericVector<Number> & initial_solution(
solution());
945 TIME_SECTION(
"applyPredictor", 2,
"Applying Predictor");
951 _console <<
" Skipping predictor this step" << std::endl;
956 TIME_SECTION(
"initialBCs", 2,
"Applying BCs To Initial Condition");
959 for (
const auto & bnode : bnd_nodes)
962 Node * node = bnode->_node;
970 if (has_preset_nodal_bcs || has_ad_preset_nodal_bcs)
973 if (has_preset_nodal_bcs)
976 for (
const auto & preset_bc : preset_bcs)
977 preset_bc->computeValue(initial_solution);
979 if (has_ad_preset_nodal_bcs)
982 for (
const auto & preset_bc : preset_bcs_res)
983 preset_bc->computeValue(initial_solution);
989#ifdef MOOSE_KOKKOS_ENABLED
1021NumericVector<Number> &
1044NumericVector<Number> &
1067NumericVector<Number> &
1080 mooseError(
"The required residual vector is not available");
1092 for (
const auto & nc : ncs)
1094 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
1095 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
1097 if ((secondary_node_ids.size() > 0) && (primary_node_ids.size() > 0))
1099 nc->reinitConstraintNodes();
1100 nc->computeResidual(residual);
1119 for (
const auto & nc : ncs)
1121 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
1122 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
1124 if ((secondary_node_ids.size() > 0) && (primary_node_ids.size() > 0))
1126 nc->reinitConstraintNodes();
1127 nc->computeJacobian(jacobian_to_view);
1142 const bool displaced)
1147 const Elem * primary_elem = info._elem;
1148 unsigned int primary_side = info._side_num;
1149 std::vector<Point> points;
1150 points.push_back(info._closest_point);
1171 const Elem *
const undisplaced_primary_elem =
1172 displaced ?
_mesh.
elemPtr(primary_elem->id()) : primary_elem;
1173 const Point undisplaced_primary_physical_point =
1174 [&points, displaced, primary_elem, undisplaced_primary_elem]()
1178 const Point reference_point =
1179 FEMap::inverse_map(primary_elem->dim(), primary_elem, points[0]);
1180 return FEMap::map(primary_elem->dim(), undisplaced_primary_elem, reference_point);
1189 undisplaced_primary_elem, primary_side, {undisplaced_primary_physical_point}, 0);
1206 "If we're calling this method with displaced = true, then we better well have a "
1207 "displaced problem");
1212 bool constraints_applied =
false;
1214 for (
const auto & it : penetration_locators)
1225 const auto & constraints =
1227 std::unordered_set<unsigned int> needed_mat_props;
1228 for (
const auto & constraint : constraints)
1230 const auto & mp_deps = constraint->getMatPropDependencies();
1231 needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
1235 for (
unsigned int i = 0; i < secondary_nodes.size(); i++)
1237 dof_id_type secondary_node_num = secondary_nodes[i];
1238 Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
1246 reinitNodeFace(secondary_node, secondary_boundary, info, displaced);
1248 for (
const auto & nfc : constraints)
1250 if (nfc->isExplicitConstraint())
1256 if (nfc->secondaryBoundary() != secondary_boundary ||
1257 nfc->primaryBoundary() != primary_boundary)
1260 if (nfc->shouldApply())
1262 constraints_applied =
true;
1263 nfc->computeSecondaryValue(
solution);
1266 if (nfc->hasWritableCoupledVariables())
1269 for (
auto * var : nfc->getWritableCoupledVariables())
1271 if (var->isNodalDefined())
1283 std::set<dof_id_type> unique_secondary_node_ids;
1291 const auto & constraints =
1295 unique_secondary_node_ids.clear();
1297 for (
const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
1298 meshhelper.active_subdomain_elements_end(secondary_id)))
1300 for (
auto & n : elem->node_ref_range())
1301 unique_secondary_node_ids.insert(n.id());
1304 for (
auto secondary_node_id : unique_secondary_node_ids)
1306 Node & secondary_node =
_mesh.
nodeRef(secondary_node_id);
1318 for (
const auto & nec : constraints)
1320 if (nec->shouldApply())
1322 constraints_applied =
true;
1323 nec->computeSecondaryValue(
solution);
1335 if (constraints_applied)
1350 "If we're calling this method with displaced = true, then we better well have a "
1351 "displaced problem");
1356 bool constraints_applied;
1357 bool residual_has_inserted_values =
false;
1359 constraints_applied =
false;
1360 for (
const auto & it : penetration_locators)
1366 constraints_applied =
false;
1375 bool has_writable_variables(
false);
1379 const auto & constraints =
1382 for (
unsigned int i = 0; i < secondary_nodes.size(); i++)
1384 dof_id_type secondary_node_num = secondary_nodes[i];
1385 Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
1393 reinitNodeFace(secondary_node, secondary_boundary, info, displaced);
1395 for (
const auto & nfc : constraints)
1401 if (nfc->secondaryBoundary() != secondary_boundary ||
1402 nfc->primaryBoundary() != primary_boundary)
1405 if (nfc->shouldApply())
1407 constraints_applied =
true;
1408 nfc->computeResidual();
1410 if (nfc->overwriteSecondaryResidual())
1416 const auto & secondary_var = nfc->variable();
1417 const auto & secondary_dofs = secondary_var.dofIndices();
1418 mooseAssert(secondary_dofs.size() == secondary_var.count(),
1419 "We are on a node so there should only be one dof per variable (for "
1420 "an ArrayVariable we should have a number of dofs equal to the "
1421 "number of components");
1427 std::vector<Number>
values = {nfc->secondaryResidual()};
1428 residual.insert(
values, secondary_dofs);
1429 residual_has_inserted_values =
true;
1435 if (nfc->hasWritableCoupledVariables())
1438 has_writable_variables =
true;
1439 for (
auto * var : nfc->getWritableCoupledVariables())
1441 if (var->isNodalDefined())
1452 if (has_writable_variables)
1470 if (constraints_applied)
1475 if (residual_has_inserted_values)
1478 residual_has_inserted_values =
false;
1492 if (constraints_applied)
1497 if (residual_has_inserted_values)
1511 for (
const auto & it : element_pair_locators)
1518 const auto & element_constraints =
1522 const std::list<std::pair<const Elem *, const Elem *>> & elem_pairs =
1524 for (
const auto & pr : elem_pairs)
1526 const Elem * elem1 = pr.first;
1527 const Elem * elem2 = pr.second;
1535 for (
const auto & ec : element_constraints)
1542 ec->prepareShapes(ec->variable().number());
1543 ec->prepareNeighborShapes(ec->variable().number());
1546 ec->computeResidual();
1556 std::set<dof_id_type> unique_secondary_node_ids;
1558 constraints_applied =
false;
1559 residual_has_inserted_values =
false;
1560 bool has_writable_variables =
false;
1567 const auto & constraints =
1571 unique_secondary_node_ids.clear();
1573 for (
const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
1574 meshhelper.active_subdomain_elements_end(secondary_id)))
1576 for (
auto & n : elem->node_ref_range())
1577 unique_secondary_node_ids.insert(n.id());
1580 for (
auto secondary_node_id : unique_secondary_node_ids)
1582 Node & secondary_node =
_mesh.
nodeRef(secondary_node_id);
1593 for (
const auto & nec : constraints)
1595 if (nec->shouldApply())
1597 constraints_applied =
true;
1598 nec->computeResidual();
1600 if (nec->overwriteSecondaryResidual())
1603 residual_has_inserted_values =
true;
1609 if (nec->hasWritableCoupledVariables())
1612 has_writable_variables =
true;
1613 for (
auto * var : nec->getWritableCoupledVariables())
1615 if (var->isNodalDefined())
1628 if (constraints_applied)
1633 if (residual_has_inserted_values)
1644 if (has_writable_variables)
1667 for (
const auto & it : penetration_locators)
1677 const auto & constraints =
1679 for (
const auto i : index_range(secondary_nodes))
1681 const auto secondary_node_num = secondary_nodes[i];
1682 const Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
1686 for (
const auto & nfc : constraints)
1688 if (!nfc->isExplicitConstraint())
1695 if (nfc->secondaryBoundary() != secondary_boundary ||
1696 nfc->primaryBoundary() != primary_boundary)
1699 nfc->overwriteBoundaryVariables(soln, secondary_node);
1710 TIME_SECTION(
"residualSetup", 3);
1733#ifdef MOOSE_KOKKOS_ENABLED
1748 parallel_object_only();
1750 TIME_SECTION(
"computeResidualInternal", 3);
1756 std::vector<GeneralUserObject *> uos;
1762 for (
auto & uo : uos)
1763 uo->residualSetup();
1764 for (
auto & uo : uos)
1772 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
1775#ifdef MOOSE_KOKKOS_ENABLED
1783 TIME_SECTION(
"Kernels", 3 );
1794 using FVRange = StoredRange<MooseMesh::const_face_info_iterator, const FaceInfo *>;
1813 for (
unsigned int i = 0; i < n_threads;
1825 TIME_SECTION(
"ScalarKernels", 3 );
1833 else if (tags.size() == 1)
1834 scalar_kernel_warehouse =
1840 bool have_scalar_contributions =
false;
1842 for (
const auto & scalar_kernel : scalars)
1844 scalar_kernel->reinit();
1845 const std::vector<dof_id_type> & dof_indices = scalar_kernel->variable().dofIndices();
1846 const DofMap & dof_map = scalar_kernel->variable().dofMap();
1847 const dof_id_type first_dof = dof_map.first_dof();
1848 const dof_id_type end_dof = dof_map.end_dof();
1849 for (dof_id_type dof : dof_indices)
1851 if (dof >= first_dof && dof < end_dof)
1853 scalar_kernel->computeResidual();
1854 have_scalar_contributions =
true;
1859 if (have_scalar_contributions)
1870 TIME_SECTION(
"NodalKernels", 3 );
1876 if (range.begin() != range.end())
1883 for (
unsigned int i = 0; i < n_threads;
1902 TIME_SECTION(
"NodalKernelBCs", 3 );
1911 for (
unsigned int i = 0; i < n_threads;
1970 const std::set<TagID> & matrix_tags)
1972 TIME_SECTION(
"computeResidualAndJacobianInternal", 3);
1979 "residual_and_jacobian_together does not yet support ScalarKernels. Their "
1980 "contributions would be silently dropped. Please use "
1981 "residual_and_jacobian_together = false");
1985 "residual_and_jacobian_together does not yet support NodalKernels. Their "
1986 "contributions would be silently dropped. Please use "
1987 "residual_and_jacobian_together = false");
1992 "residual_and_jacobian_together does not yet support nodal constraints. Their "
1993 "contributions would be silently dropped. Please use "
1994 "residual_and_jacobian_together = false");
2005 std::vector<UserObject *> uos;
2011 for (
auto & uo : uos)
2012 uo->residualSetup();
2013 for (
auto & uo : uos)
2021 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
2024#ifdef MOOSE_KOKKOS_ENABLED
2038 TIME_SECTION(
"Kernels", 3 );
2045 using FVRange = StoredRange<MooseMesh::const_face_info_iterator, const FaceInfo *>;
2066 for (
unsigned int i = 0; i < n_threads;
2089 for (
const auto & residual_vector_tag : residual_vector_tags)
2099 const std::set<TagID> & tags)
2111#ifdef MOOSE_KOKKOS_ENABLED
2126 else if (tags.size() == 1)
2139 if (!bnd_nodes.
empty())
2141 TIME_SECTION(
"NodalBCs", 3 );
2143 for (
const auto & bnode : bnd_nodes)
2146 Node * node = bnode->_node;
2155 for (
const auto & nbc : bcs)
2156 if (nbc->shouldApply())
2157 nbc->computeResidual();
2182 else if (tags.size() == 1)
2203 std::map<std::string, std::set<unsigned int>> bc_involved_vars;
2205 for (
const auto & bid : all_boundary_ids)
2212 for (
const auto & bc : bcs)
2214 const std::vector<MooseVariableFEBase *> & coupled_moose_vars = bc->getCoupledMooseVars();
2218 std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2219 for (
const auto & coupled_var : coupled_moose_vars)
2221 var_set.insert(coupled_var->number());
2223 var_set.insert(bc->variable().number());
2231 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
2243 for (
const auto & bnode : bnd_nodes)
2246 Node * node = bnode->_node;
2254 for (
const auto & bc : bcs)
2257 std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2263 for (
const auto & it : coupling_entries)
2265 unsigned int ivar = it.first->number(), jvar = it.second->number();
2271 if ((bc->variable().number() == ivar) && var_set.count(jvar) && bc->shouldApply())
2272 bc->computeOffDiagJacobian(jvar);
2277 const auto & coupled_scalar_vars = bc->getCoupledMooseScalarVars();
2278 for (
const auto & jvariable : coupled_scalar_vars)
2281 bc->computeOffDiagJacobianScalar(jvariable->number());
2294 [[maybe_unused]]
const std::set<TagID> & vector_tags,
2295 [[maybe_unused]]
const std::set<TagID> & matrix_tags)
2297#ifdef MOOSE_KOKKOS_ENABLED
2310 if (!bnd_nodes.
empty())
2312 TIME_SECTION(
"NodalBCs", 3 );
2314 for (
const auto & bnode : bnd_nodes)
2317 Node * node = bnode->_node;
2326 for (
const auto & nbc : bcs)
2327 if (nbc->shouldApply())
2328 nbc->computeResidualAndJacobian();
2344 unsigned int s =
number();
2345 if (node.has_dofs(s))
2347 for (
unsigned int v = 0; v <
nVariables(); v++)
2348 for (
unsigned int c = 0; c < node.n_comp(s, v); c++)
2349 dofs.push_back(node.dof_number(s, v, c));
2356 std::unordered_map<dof_id_type, std::vector<dof_id_type>> & graph)
2360 for (
const auto & it : nearest_node_locators)
2362 std::vector<dof_id_type> & secondary_nodes = it.second->_secondary_nodes;
2364 for (
const auto & secondary_node : secondary_nodes)
2366 std::set<dof_id_type> unique_secondary_indices;
2367 std::set<dof_id_type> unique_primary_indices;
2369 auto node_to_elem_pair = node_to_elem_map.find(secondary_node);
2370 if (node_to_elem_pair != node_to_elem_map.end())
2372 const std::vector<dof_id_type> & elems = node_to_elem_pair->second;
2375 for (
const auto & cur_elem : elems)
2377 std::vector<dof_id_type> dof_indices;
2380 for (
const auto & dof : dof_indices)
2381 unique_secondary_indices.insert(dof);
2385 std::vector<dof_id_type> primary_nodes = it.second->_neighbor_nodes[secondary_node];
2387 for (
const auto & primary_node : primary_nodes)
2389 auto primary_node_to_elem_pair = node_to_elem_map.find(primary_node);
2390 mooseAssert(primary_node_to_elem_pair != node_to_elem_map.end(),
2391 "Missing entry in node to elem map");
2392 const std::vector<dof_id_type> & primary_node_elems = primary_node_to_elem_pair->second;
2395 for (
const auto & cur_elem : primary_node_elems)
2397 std::vector<dof_id_type> dof_indices;
2400 for (
const auto & dof : dof_indices)
2401 unique_primary_indices.insert(dof);
2405 for (
const auto & secondary_id : unique_secondary_indices)
2406 for (
const auto & primary_id : unique_primary_indices)
2408 graph[secondary_id].push_back(primary_id);
2409 graph[primary_id].push_back(secondary_id);
2416 for (
const auto & nc : ncs)
2418 std::vector<dof_id_type> primary_dofs;
2419 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
2420 for (
const auto & node_id : primary_node_ids)
2423 if (node && node->processor_id() == this->
processor_id())
2431 std::vector<dof_id_type> secondary_dofs;
2432 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
2433 for (
const auto & node_id : secondary_node_ids)
2436 if (node && node->processor_id() == this->
processor_id())
2444 for (
const auto & primary_id : primary_dofs)
2445 for (
const auto & secondary_id : secondary_dofs)
2447 graph[primary_id].push_back(secondary_id);
2448 graph[secondary_id].push_back(primary_id);
2453 for (
auto & it : graph)
2455 std::vector<dof_id_type> & row = it.second;
2456 std::sort(row.begin(), row.end());
2457 std::vector<dof_id_type>::iterator uit = std::unique(row.begin(), row.end());
2458 row.resize(uit - row.begin());
2472 std::unordered_map<dof_id_type, std::vector<dof_id_type>> graph;
2476 for (
const auto & it : graph)
2478 dof_id_type dof = it.first;
2479 const auto & row = it.second;
2481 for (
const auto & coupled_dof : row)
2482 jacobian.add(dof, coupled_dof, 0);
2496 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2497 MAT_NEW_NONZERO_ALLOCATION_ERR,
2500 LibmeshPetscCall(MatSetOption(
2501 cast_ref<PetscMatrix<Number> &>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE));
2503 std::vector<numeric_index_type> zero_rows;
2507 "If we're calling this method with displaced = true, then we better well have a "
2508 "displaced problem");
2513 bool constraints_applied;
2515 constraints_applied =
false;
2516 for (
const auto & it : penetration_locators)
2522 constraints_applied =
false;
2534 const auto & constraints =
2537 for (
const auto & secondary_node_num : secondary_nodes)
2539 Node & secondary_node =
_mesh.
nodeRef(secondary_node_num);
2547 reinitNodeFace(secondary_node, secondary_boundary, info, displaced);
2550 for (
const auto & nfc : constraints)
2552 if (nfc->isExplicitConstraint())
2558 if (nfc->secondaryBoundary() != secondary_boundary ||
2559 nfc->primaryBoundary() != primary_boundary)
2562 nfc->_jacobian = &jacobian_to_view;
2564 if (nfc->shouldApply())
2566 constraints_applied =
true;
2572 nfc->prepareShapes(nfc->variable().number());
2573 nfc->prepareNeighborShapes(nfc->variable().number());
2575 nfc->computeJacobian();
2577 if (nfc->overwriteSecondaryJacobian())
2580 zero_rows.push_back(nfc->variable().nodalDofIndex());
2583 std::vector<dof_id_type> secondary_dofs(1, nfc->variable().nodalDofIndex());
2589 Real scaling_factor =
2590 nfc->overwriteSecondaryJacobian() ? 1. : nfc->variable().scalingFactor();
2596 nfc->_connected_dof_indices,
2600 if (nfc->addCouplingEntriesToJacobian())
2607 nfc->primaryVariable().dofIndicesNeighbor(),
2613 nfc->primaryVariable().dofIndicesNeighbor(),
2614 nfc->_connected_dof_indices,
2615 nfc->primaryVariable().scalingFactor());
2622 const std::vector<MooseVariableFEBase *> coupled_vars = nfc->getCoupledMooseVars();
2623 for (
const auto & jvar : coupled_vars)
2631 if (nfc->variable().number() == jvar->number() ||
2633 nfc->variable().number(), jvar->number(), this->number()))
2641 nfc->prepareShapes(nfc->variable().number());
2642 nfc->prepareNeighborShapes(jvar->number());
2644 nfc->computeOffDiagJacobian(jvar->number());
2650 nfc->_connected_dof_indices,
2654 if (nfc->addCouplingEntriesToJacobian())
2661 jvar->dofIndicesNeighbor(),
2667 nfc->variable().dofIndicesNeighbor(),
2668 nfc->_connected_dof_indices,
2669 nfc->variable().scalingFactor());
2686 if (constraints_applied)
2688 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2689 MAT_KEEP_NONZERO_PATTERN,
2693 jacobian.zero_rows(zero_rows, 0.0);
2705 if (constraints_applied)
2707 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2708 MAT_KEEP_NONZERO_PATTERN,
2712 jacobian.zero_rows(zero_rows, 0.0);
2722 for (
const auto & it : element_pair_locators)
2729 const auto & element_constraints =
2733 const std::list<std::pair<const Elem *, const Elem *>> & elem_pairs =
2735 for (
const auto & pr : elem_pairs)
2737 const Elem * elem1 = pr.first;
2738 const Elem * elem2 = pr.second;
2746 for (
const auto & ec : element_constraints)
2758 ec->prepareShapes(ec->variable().number());
2759 ec->prepareNeighborShapes(ec->variable().number());
2762 ec->computeJacobian();
2772 std::set<dof_id_type> unique_secondary_node_ids;
2773 constraints_applied =
false;
2780 const auto & constraints =
2784 unique_secondary_node_ids.clear();
2786 for (
const auto & elem : as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
2787 meshhelper.active_subdomain_elements_end(secondary_id)))
2789 for (
auto & n : elem->node_ref_range())
2790 unique_secondary_node_ids.insert(n.id());
2793 for (
auto secondary_node_id : unique_secondary_node_ids)
2795 const Node & secondary_node =
_mesh.
nodeRef(secondary_node_id);
2804 for (
const auto & nec : constraints)
2806 if (nec->shouldApply())
2808 constraints_applied =
true;
2815 nec->_jacobian = &jacobian_to_view;
2816 nec->prepareShapes(nec->variable().number());
2817 nec->prepareNeighborShapes(nec->variable().number());
2819 nec->computeJacobian();
2821 if (nec->overwriteSecondaryJacobian())
2824 zero_rows.push_back(nec->variable().nodalDofIndex());
2827 std::vector<dof_id_type> secondary_dofs(1, nec->variable().nodalDofIndex());
2833 nec->_connected_dof_indices,
2834 nec->variable().scalingFactor());
2839 nec->primaryVariable().dofIndicesNeighbor(),
2840 nec->_connected_dof_indices,
2841 nec->primaryVariable().scalingFactor());
2847 const std::vector<MooseVariableFEBase *> coupled_vars = nec->getCoupledMooseVars();
2848 for (
const auto & jvar : coupled_vars)
2856 if (nec->variable().number() == jvar->number() ||
2858 nec->variable().number(), jvar->number(), this->number()))
2866 nec->prepareShapes(nec->variable().number());
2867 nec->prepareNeighborShapes(jvar->number());
2869 nec->computeOffDiagJacobian(jvar->number());
2875 nec->_connected_dof_indices,
2876 nec->variable().scalingFactor());
2881 nec->variable().dofIndicesNeighbor(),
2882 nec->_connected_dof_indices,
2883 nec->variable().scalingFactor());
2898 if (constraints_applied)
2900 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
2901 MAT_KEEP_NONZERO_PATTERN,
2905 jacobian.zero_rows(zero_rows, 0.0);
2919 else if (tags.size() == 1)
2933 bool have_scalar_contributions =
false;
2934 for (
const auto & kernel : scalars)
2936 if (!kernel->computesJacobian())
2940 const std::vector<dof_id_type> & dof_indices = kernel->variable().dofIndices();
2941 const DofMap & dof_map = kernel->variable().dofMap();
2942 const dof_id_type first_dof = dof_map.first_dof();
2943 const dof_id_type end_dof = dof_map.end_dof();
2944 for (dof_id_type dof : dof_indices)
2946 if (dof >= first_dof && dof < end_dof)
2948 kernel->computeJacobian();
2950 have_scalar_contributions =
true;
2956 if (have_scalar_contributions)
2985#ifdef MOOSE_KOKKOS_ENABLED
3000 for (
auto tag : tags)
3007 if (
auto petsc_matrix =
dynamic_cast<PetscMatrix<Number> *
>(&jacobian))
3009 LibmeshPetscCall(MatSetOption(petsc_matrix->mat(),
3010 MAT_KEEP_NONZERO_PATTERN,
3014 MatSetOption(petsc_matrix->mat(), MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
3016 LibmeshPetscCall(MatSetOption(
3017 cast_ref<PetscMatrix<Number> &>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE));
3025 TIME_SECTION(
"computeJacobianInternal", 3);
3038 std::vector<UserObject *> uos;
3044 for (
auto & uo : uos)
3045 uo->jacobianSetup();
3046 for (
auto & uo : uos)
3054 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
3057#ifdef MOOSE_KOKKOS_ENABLED
3083 for (
unsigned int i = 0; i < n_threads;
3088 using FVRange = StoredRange<MooseMesh::const_face_info_iterator, const FaceInfo *>;
3123 for (
unsigned int i = 0; i < n_threads;
3146 for (
unsigned int i = 0; i < n_threads;
3158 for (
unsigned int i = 0; i < n_threads;
3172 for (
unsigned int i = 0; i < n_threads; i++)
3183 for (
unsigned int i = 0; i < n_threads;
3193 static bool first =
true;
3218 std::unique_ptr<SparseMatrix<Number>> hash_copy;
3219 const SparseMatrix<Number> * view_jac_ptr;
3220 auto make_readable_jacobian = [&]()
3222#if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0)
3223 if (system_matrix.use_hash_table())
3225 hash_copy = cast_ref<PetscMatrix<Number> &>(system_matrix).copy_from_hash();
3226 view_jac_ptr = hash_copy.get();
3229 view_jac_ptr = &system_matrix;
3231 view_jac_ptr = &system_matrix;
3233 if (view_jac_ptr == &system_matrix)
3234 system_matrix.close();
3237 make_readable_jacobian();
3241 if (had_nodal_constraints)
3243 make_readable_jacobian();
3279 for (
auto & tag : tags)
3298 TIME_SECTION(
"computeJacobianTags", 5);
3320 for (
auto & tag : tags)
3328 const std::set<TagID> & tags)
3330 TIME_SECTION(
"computeJacobianBlocks", 3);
3333 for (
unsigned int i = 0; i <
blocks.size(); i++)
3335 SparseMatrix<Number> & jacobian =
blocks[i]->_jacobian;
3337 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
3338 MAT_KEEP_NONZERO_PATTERN,
3341 LibmeshPetscCall(MatSetOption(cast_ref<PetscMatrix<Number> &>(jacobian).mat(),
3342 MAT_NEW_NONZERO_ALLOCATION_ERR,
3348 for (
unsigned int tid = 0; tid < this->
numThreads(); tid++)
3359 for (
unsigned int i = 0; i <
blocks.size(); i++)
3360 blocks[i]->_jacobian.close();
3362 for (
unsigned int i = 0; i <
blocks.size(); i++)
3365 SparseMatrix<Number> & jacobian =
blocks[i]->_jacobian;
3367 unsigned int ivar =
blocks[i]->_ivar;
3368 unsigned int jvar =
blocks[i]->_jvar;
3371 std::vector<numeric_index_type> zero_rows;
3375 for (
const auto & bnode : bnd_nodes)
3378 Node * node = bnode->_node;
3388 for (
const auto & bc : bcs)
3389 if (bc->variable().number() == ivar && bc->shouldApply())
3393 zero_rows.push_back(node->dof_number(precond_system.
number(), 0, 0));
3405 jacobian.zero_rows(zero_rows, 1.0);
3407 jacobian.zero_rows(zero_rows, 0.0);
3435#ifdef MOOSE_KOKKOS_ENABLED
3447 const NumericVector<Number> & update)
3451 bool has_active_dampers =
false;
3459 TIME_SECTION(
"computeDampers", 3,
"Computing Dampers");
3460 has_active_dampers =
true;
3465 damping = std::min(cid.
damping(), damping);
3474 TIME_SECTION(
"computeDamping::element", 3,
"Computing Element Damping");
3476 has_active_dampers =
true;
3481 damping = std::min(cndt.
damping(), damping);
3490 TIME_SECTION(
"computeDamping::general", 3,
"Computing General Damping");
3492 has_active_dampers =
true;
3494 for (
const auto & damper : gdampers)
3499 damper->checkMinDamping(gd_damping);
3505 damping = std::min(gd_damping, damping);
3517 catch (std::exception & e)
3520 const std::string & message = e.
what();
3521 if (message.find(
"Jacobian") == std::string::npos)
3527 if (has_active_dampers && damping < 1.0)
3528 _console <<
" Damping factor: " << damping << std::endl;
3535 const std::set<TagID> & matrix_tags,
3540 std::set<const Elem *> dirac_elements;
3544 TIME_SECTION(
"computeDirac", 3,
"Computing DiracKernels");
3550 for (
const auto & dkernel : dkernels)
3552 dkernel->clearPoints();
3553 dkernel->addPoints();
3561 DistElemRange range(dirac_elements.begin(), dirac_elements.end(), 1);
3570 for (
const auto tid : make_range(this->
numThreads()))
3574 for (
const auto tid : make_range(this->
numThreads()))
3579NumericVector<Number> &
3588NumericVector<Number> &
3620 std::vector<dof_id_type> & n_nz,
3621 std::vector<dof_id_type> & n_oz)
3627 std::unordered_map<dof_id_type, std::vector<dof_id_type>> graph;
3642 for (
const auto & git : graph)
3644 dof_id_type dof = git.first;
3645 dof_id_type local_dof = dof - first_dof_on_proc;
3647 if (dof < first_dof_on_proc || dof >= end_dof_on_proc)
3650 const auto & row = git.second;
3654 unsigned int original_row_length = sparsity_row.size();
3656 sparsity_row.insert(sparsity_row.end(), row.begin(), row.end());
3659 sparsity_row.begin(), sparsity_row.begin() + original_row_length, sparsity_row.end());
3662 for (
const auto & coupled_dof : row)
3664 if (coupled_dof < first_dof_on_proc || coupled_dof >= end_dof_on_proc)
3666 if (n_oz[local_dof] < n_dofs_not_on_proc)
3671 if (n_nz[local_dof] < n_dofs_on_proc)
3707 mooseError(
"More than one active Preconditioner detected");
3726 const std::set<MooseVariable *> & damped_vars)
3728 for (
const auto & var : damped_vars)
3734 const std::set<MooseVariable *> & damped_vars)
3736 for (
const auto & var : damped_vars)
3744 std::set<SubdomainID> input_subdomains;
3745 std::set<std::string> kernel_variables;
3747 bool global_kernels_exist =
false;
3757#ifdef MOOSE_KOKKOS_ENABLED
3764 std::vector<FVElementalKernel *> fv_elemental_kernels;
3767 .template condition<AttribSystem>(
"FVElementalKernel")
3770 for (
auto fv_kernel : fv_elemental_kernels)
3772 if (fv_kernel->blockRestricted())
3773 for (
auto block_id : fv_kernel->blockIDs())
3774 input_subdomains.insert(block_id);
3776 global_kernels_exist =
true;
3777 kernel_variables.insert(fv_kernel->variable().name());
3786 std::vector<FVFluxKernel *> fv_flux_kernels;
3789 .template condition<AttribSystem>(
"FVFluxKernel")
3792 for (
auto fv_kernel : fv_flux_kernels)
3794 if (fv_kernel->blockRestricted())
3795 for (
auto block_id : fv_kernel->blockIDs())
3796 input_subdomains.insert(block_id);
3798 global_kernels_exist =
true;
3799 kernel_variables.insert(fv_kernel->variable().name());
3802 std::vector<FVInterfaceKernel *> fv_interface_kernels;
3805 .template condition<AttribSystem>(
"FVInterfaceKernel")
3808 for (
auto fvik : fv_interface_kernels)
3810 kernel_variables.insert(scalar_fvik->lambdaVariable().name());
3812 std::vector<FVFluxBC *> fv_flux_bcs;
3815 .template condition<AttribSystem>(
"FVFluxBC")
3818 for (
auto fvbc : fv_flux_bcs)
3820 kernel_variables.insert(scalar_fvbc->lambdaVariable().name());
3825 const auto additional_variables_covered = ibc->additionalROVariables();
3826 kernel_variables.insert(additional_variables_covered.begin(),
3827 additional_variables_covered.end());
3831 if (!global_kernels_exist)
3834 std::set<SubdomainID> system_subdomains;
3840 if (variable_subdomains.empty())
3842 system_subdomains = mesh_subdomains;
3846 for (
const auto subdomain : variable_subdomains)
3847 if (mesh_subdomains.count(subdomain))
3848 system_subdomains.insert(subdomain);
3851 std::set<SubdomainID> difference;
3852 std::set_difference(system_subdomains.begin(),
3853 system_subdomains.end(),
3854 input_subdomains.begin(),
3855 input_subdomains.end(),
3856 std::inserter(difference, difference.end()));
3860 difference.erase(
id);
3862 difference.erase(
id);
3864 if (!difference.empty())
3866 std::vector<SubdomainID> difference_vec =
3867 std::vector<SubdomainID>(difference.begin(), difference.end());
3869 std::stringstream missing_block_names;
3870 std::copy(difference_names.begin(),
3871 difference_names.end(),
3872 std::ostream_iterator<std::string>(missing_block_names,
" "));
3873 std::stringstream missing_block_ids;
3874 std::copy(difference.begin(),
3876 std::ostream_iterator<unsigned int>(missing_block_ids,
" "));
3878 mooseError(
"Each subdomain must contain at least one Kernel.\nThe following block(s) lack an "
3880 missing_block_names.str(),
3882 missing_block_ids.str(),
3890 std::set<VariableName> difference;
3891 std::set_difference(variables.begin(),
3893 kernel_variables.begin(),
3894 kernel_variables.end(),
3895 std::inserter(difference, difference.end()));
3898 std::set<VariableName>
vars(difference);
3899 for (
auto & var_name :
vars)
3902 for (
const auto &
id : blks)
3904 difference.erase(var_name);
3907 if (!difference.empty())
3909 std::stringstream missing_kernel_vars;
3910 std::copy(difference.begin(),
3912 std::ostream_iterator<std::string>(missing_kernel_vars,
" "));
3913 mooseError(
"Each variable must be referenced by at least one active Kernel.\nThe following "
3914 "variable(s) lack an active kernel: " +
3915 missing_kernel_vars.str());
3927std::vector<std::string>
3930 std::vector<std::string> variable_names;
3932 if (time_kernels.hasActiveObjects())
3933 for (
const auto & kernel : time_kernels.getObjects())
3934 variable_names.push_back(kernel->variable().name());
3936 return variable_names;
3946 if (std::static_pointer_cast<MaterialPropertyInterface>(bc)->getMaterialPropertyCalled())
3953 if (std::static_pointer_cast<MaterialPropertyInterface>(ik)->getMaterialPropertyCalled())
3961 if (
auto mpi = std::dynamic_pointer_cast<MaterialPropertyInterface>(ct);
3962 mpi && mpi->getMaterialPropertyCalled())
3974 if (std::static_pointer_cast<MaterialPropertyInterface>(ik)->getMaterialPropertyCalled())
3986 if (std::static_pointer_cast<MaterialPropertyInterface>(dg)->getMaterialPropertyCalled())
4009 const std::set<TagID> & vector_tags,
4010 const std::set<TagID> & matrix_tags)
4012 parallel_object_only();
4017 map_pr.second(compute_type, vector_tags, matrix_tags);
4020 map_pr.second(compute_type, vector_tags, matrix_tags);
4022 catch (MetaPhysicL::LogicError &)
4025 "We caught a MetaPhysicL error in NonlinearSystemBase::mortarConstraints. This is very "
4026 "likely due to AD not having a sufficiently large derivative container size. Please run "
4027 "MOOSE configure with the '--with-derivative-size=<n>' option");
4045 for (
const auto var_number : make_range(
n_vars))
4050 std::set<unsigned int> var_numbers, var_numbers_covered, var_numbers_not_covered;
4051 for (
const auto var_number : make_range(
n_vars))
4052 var_numbers.insert(var_number);
4062 "', provided to the 'scaling_group_variables' parameter, does not exist in "
4063 "the nonlinear system.");
4069 if (!map_pair.second)
4070 mooseError(
"Variable ", var_name,
" is contained in multiple scaling grouplings");
4071 var_numbers_covered.insert(var.
number());
4074 std::set_difference(var_numbers.begin(),
4076 var_numbers_covered.begin(),
4077 var_numbers_covered.end(),
4078 std::inserter(var_numbers_not_covered, var_numbers_not_covered.begin()));
4083 for (
auto var_number : var_numbers_not_covered)
4088 const auto & number_to_var_map =
_vars[0].numberToVariableMap();
4094 libmesh_map_find(number_to_var_map, i)->
name()) !=
4107 _console <<
"\nPerforming automatic scaling calculation\n" << std::endl;
4109 TIME_SECTION(
"computeScaling", 3,
"Computing Automatic Scaling");
4112 std::vector<dof_id_type> dof_indices;
4120 auto & dof_map =
dofMap();
4126 const NumericVector<Number> & scaling_residual =
RHS();
4137 auto init_vector = NumericVector<Number>::build(this->
comm());
4138 init_vector->init(
system().n_dofs(),
system().n_local_dofs(),
false, PARALLEL);
4164 auto examine_dof_indices = [
this,
4168 &jac_inverse_scaling_factors,
4169 &resid_inverse_scaling_factors,
4170 &scaling_residual](
const auto & dof_indices,
const auto var_number)
4172 for (
auto dof_index : dof_indices)
4173 if (dof_map.local_index(dof_index))
4178 auto mat_value = (*_scaling_matrix)(dof_index, dof_index);
4180 factor = std::max(factor, std::abs(mat_value));
4184 auto vec_value = scaling_residual(dof_index);
4186 factor = std::max(factor, std::abs(vec_value));
4196 dof_map.dof_indices(elem, dof_indices, i);
4197 examine_dof_indices(dof_indices, i);
4203 dof_map.SCALAR_dof_indices(dof_indices, i);
4204 examine_dof_indices(dof_indices, i);
4212 if (jac_scaling && resid_scaling)
4213 for (MooseIndex(inverse_scaling_factors) i = 0; i < inverse_scaling_factors.size(); ++i)
4216 if (!resid_inverse_scaling_factors[i])
4218 if (!jac_inverse_scaling_factors[i])
4219 inverse_scaling_factors[i] = 1;
4221 inverse_scaling_factors[i] = jac_inverse_scaling_factors[i];
4223 else if (!jac_inverse_scaling_factors[i])
4225 inverse_scaling_factors[i] = resid_inverse_scaling_factors[i];
4227 inverse_scaling_factors[i] =
4231 else if (jac_scaling)
4232 inverse_scaling_factors = jac_inverse_scaling_factors;
4233 else if (resid_scaling)
4234 inverse_scaling_factors = resid_inverse_scaling_factors;
4236 mooseError(
"We shouldn't be calling this routine if we're not performing any scaling");
4239 for (
auto & scaling_factor : inverse_scaling_factors)
4240 if (scaling_factor == 0)
4244 std::vector<Real> flattened_inverse_scaling_factors(
system().
n_vars());
4245 for (
const auto i : index_range(flattened_inverse_scaling_factors))
4246 flattened_inverse_scaling_factors[i] = inverse_scaling_factors[
_var_to_group_var[i]];
4252 flattened_inverse_scaling_factors);
4273 if (!scaling_succeeded)
4286 LibmeshPetscCall(MatFDColoringDestroy(&
_fdcoloring));
4293 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 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 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())