85 #include "libmesh/nonlinear_solver.h" 86 #include "libmesh/quadrature_gauss.h" 87 #include "libmesh/dense_vector.h" 88 #include "libmesh/boundary_info.h" 89 #include "libmesh/petsc_matrix.h" 90 #include "libmesh/petsc_vector.h" 91 #include "libmesh/petsc_nonlinear_solver.h" 92 #include "libmesh/numeric_vector.h" 93 #include "libmesh/mesh.h" 94 #include "libmesh/dense_subvector.h" 95 #include "libmesh/dense_submatrix.h" 96 #include "libmesh/dof_map.h" 97 #include "libmesh/sparse_matrix.h" 98 #include "libmesh/petsc_matrix.h" 99 #include "libmesh/default_coupling.h" 100 #include "libmesh/diagonal_matrix.h" 101 #include "libmesh/fe_interface.h" 102 #include "libmesh/petsc_solver_exception.h" 106 #include "petscsnes.h" 116 const std::string & name)
122 _residual_ghosted(NULL),
125 _Re_non_time_tag(-1),
127 _scalar_kernels(false),
129 _preset_nodal_bcs(false),
130 _ad_preset_nodal_bcs(false),
131 #ifdef MOOSE_KOKKOS_ENABLED
132 _kokkos_kernels(false),
133 _kokkos_integrated_bcs(false),
134 _kokkos_nodal_bcs(false),
135 _kokkos_preset_nodal_bcs(false),
136 _kokkos_nodal_kernels(false),
138 _general_dampers(false),
140 _increment_vec(NULL),
141 _use_finite_differenced_preconditioner(false),
142 _fdcoloring(nullptr),
144 _add_implicit_geometric_coupling_entries_to_jacobian(false),
145 _assemble_constraints_separately(false),
146 _need_residual_ghosted(false),
147 _debugging_residuals(false),
151 _n_residual_evaluations(0),
153 _computing_pre_smo_residual(false),
154 _pre_smo_residual(0),
155 _initial_residual(0),
156 _use_pre_smo_residual(false),
157 _print_all_var_norms(false),
159 _has_diag_save_in(false),
160 _has_nodalbc_save_in(false),
161 _has_nodalbc_diag_save_in(false),
162 _computed_scaling(false),
163 _compute_scaling_once(true),
164 _resid_vs_jac_scaling_param(0),
165 _off_diagonals_in_auto_scaling(false),
166 _auto_scaling_initd(false)
184 dof_map.set_implicit_neighbor_dofs(
false);
201 #ifdef MOOSE_KOKKOS_ENABLED 213 functor.second.setupMortarMaterials();
215 functor.second.setupMortarMaterials();
228 TIME_SECTION(
"nlInitialSetup", 2,
"Setting Up Nonlinear System");
233 TIME_SECTION(
"kernelsInitialSetup", 2,
"Setting Up Kernels/BCs/Constraints");
250 std::vector<FVElementalKernel *> fv_elemental_kernels;
253 .template condition<AttribSystem>(
"FVElementalKernel")
254 .
template condition<AttribThread>(tid)
257 for (
auto * fv_kernel : fv_elemental_kernels)
258 fv_kernel->initialSetup();
260 std::vector<FVFluxKernel *> fv_flux_kernels;
263 .template condition<AttribSystem>(
"FVFluxKernel")
264 .
template condition<AttribThread>(tid)
267 for (
auto * fv_kernel : fv_flux_kernels)
268 fv_kernel->initialSetup();
279 #ifdef MOOSE_KOKKOS_ENABLED 288 TIME_SECTION(
"mortarSetup", 2,
"Initializing Mortar Interfaces");
290 auto create_mortar_functors = [
this](
const bool displaced)
294 for (
const auto & [primary_secondary_boundary_pair, mortar_generation_ptr] :
300 auto & mortar_constraints =
307 auto & mortar_functors =
310 mortar_functors.emplace(primary_secondary_boundary_pair,
312 *mortar_generation_ptr,
320 create_mortar_functors(
false);
321 create_mortar_functors(
true);
355 std::vector<FVFluxBC *> bcs;
358 .template condition<AttribSystem>(
"FVFluxBC")
359 .
template condition<AttribThread>(tid)
362 std::vector<FVInterfaceKernel *> iks;
365 .template condition<AttribSystem>(
"FVInterfaceKernel")
366 .
template condition<AttribThread>(tid)
369 std::vector<FVFluxKernel *> kernels;
372 .template condition<AttribSystem>(
"FVFluxKernel")
373 .
template condition<AttribThread>(tid)
376 for (
auto * bc : bcs)
378 for (
auto * ik : iks)
380 for (
auto * kernel : kernels)
381 kernel->timestepSetup();
391 #ifdef MOOSE_KOKKOS_ENABLED 418 std::vector<FVFluxBC *> bcs;
421 .template condition<AttribSystem>(
"FVFluxBC")
422 .
template condition<AttribThread>(tid)
425 std::vector<FVInterfaceKernel *> iks;
428 .template condition<AttribSystem>(
"FVInterfaceKernel")
429 .
template condition<AttribThread>(tid)
432 std::vector<FVFluxKernel *> kernels;
435 .template condition<AttribSystem>(
"FVFluxKernel")
436 .
template condition<AttribThread>(tid)
439 for (
auto * bc : bcs)
440 bc->customSetup(exec_type);
441 for (
auto * ik : iks)
442 ik->customSetup(exec_type);
443 for (
auto * kernel : kernels)
444 kernel->customSetup(exec_type);
454 #ifdef MOOSE_KOKKOS_ENABLED 471 const std::string & name,
477 std::shared_ptr<KernelBase> kernel =
485 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
487 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
493 const std::string & name,
510 const std::string & name,
516 std::shared_ptr<NodalKernelBase> kernel =
524 if (parameters.
have_parameter<std::vector<AuxVariableName>>(
"save_in") &&
525 parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
527 if (parameters.
have_parameter<std::vector<AuxVariableName>>(
"save_in") &&
528 parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
534 const std::string & name,
537 std::shared_ptr<ScalarKernelBase> kernel =
547 const std::string & name,
554 std::shared_ptr<BoundaryCondition> bc =
559 const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
561 _vars[tid].addBoundaryVar(boundary_ids, bc_var);
570 if (nbc->checkNodalVar() && !nbc->variable().isNodal())
571 mooseError(
"Trying to use nodal boundary condition '",
573 "' on a non-nodal variable '",
574 nbc->variable().name(),
580 _vars[tid].addBoundaryVars(boundary_ids, nbc->getCoupledVars());
582 if (parameters.get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
584 if (parameters.get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
589 if (dbc && dbc->preset())
593 if (addbc && addbc->preset())
603 _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
605 if (parameters.get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
607 if (parameters.get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
619 const std::set<BoundaryID> & boundary_ids = bc->boundaryIDs();
620 _vars[tid].addBoundaryVar(boundary_ids, bc_var);
625 _vars[tid].addBoundaryVars(boundary_ids, ibc->getCoupledVars());
630 mooseError(
"Unknown BoundaryCondition type for object named ", bc->name());
635 const std::string & name,
643 if (constraint && constraint->addCouplingEntriesToJacobian())
649 const std::string & name,
654 std::shared_ptr<DiracKernelBase> kernel =
665 const std::string & name,
679 if (parameters.
get<std::vector<AuxVariableName>>(
"save_in").size() > 0)
681 if (parameters.
get<std::vector<AuxVariableName>>(
"diag_save_in").size() > 0)
687 const std::string & name,
692 std::shared_ptr<InterfaceKernelBase> interface_kernel =
696 const std::set<BoundaryID> & boundary_ids = interface_kernel->boundaryIDs();
698 _vars[tid].addBoundaryVar(boundary_ids, ik_var);
703 _vars[tid].addBoundaryVars(boundary_ids, interface_kernel->getCoupledVars());
709 const std::string & name,
737 const std::string & name,
746 std::shared_ptr<Split>
764 if (
_app.
parameters().
get<
bool>(
"use_legacy_initial_residual_evaluation_behavior"))
780 mooseError(
"pre-SMO residual is requested but not evaluated.");
832 parallel_object_only();
834 TIME_SECTION(
"nl::computeResidualTags", 5);
839 bool required_residual = tags.find(
residualVectorTag()) == tags.end() ? false :
true;
862 if (required_residual)
868 ti->postResidual(residual);
911 const std::set<TagID> & matrix_tags)
913 const bool required_residual =
923 if (required_residual)
929 ti->postResidual(residual);
967 TIME_SECTION(
"applyPredictor", 2,
"Applying Predictor");
973 _console <<
" Skipping predictor this step" << std::endl;
978 TIME_SECTION(
"initialBCs", 2,
"Applying BCs To Initial Condition");
981 for (
const auto & bnode : bnd_nodes)
984 Node * node = bnode->_node;
992 if (has_preset_nodal_bcs || has_ad_preset_nodal_bcs)
995 if (has_preset_nodal_bcs)
998 for (
const auto & preset_bc : preset_bcs)
999 preset_bc->computeValue(initial_solution);
1001 if (has_ad_preset_nodal_bcs)
1004 for (
const auto & preset_bc : preset_bcs_res)
1005 preset_bc->computeValue(initial_solution);
1011 #ifdef MOOSE_KOKKOS_ENABLED 1102 mooseError(
"The required residual vector is not available");
1114 for (
const auto & nc : ncs)
1116 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
1117 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
1119 if ((secondary_node_ids.size() > 0) && (primary_node_ids.size() > 0))
1123 nc->computeResidual(residual);
1142 for (
const auto & nc : ncs)
1144 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
1145 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
1147 if ((secondary_node_ids.size() > 0) && (primary_node_ids.size() > 0))
1151 nc->computeJacobian(jacobian_to_view);
1166 const bool displaced)
1171 const Elem * primary_elem =
info._elem;
1172 unsigned int primary_side =
info._side_num;
1173 std::vector<Point> points;
1174 points.push_back(
info._closest_point);
1195 const Elem *
const undisplaced_primary_elem =
1197 const Point undisplaced_primary_physical_point =
1198 [&points, displaced, primary_elem, undisplaced_primary_elem]()
1202 const Point reference_point =
1203 FEMap::inverse_map(primary_elem->dim(), primary_elem, points[0]);
1204 return FEMap::map(primary_elem->dim(), undisplaced_primary_elem, reference_point);
1213 undisplaced_primary_elem, primary_side, {undisplaced_primary_physical_point}, 0);
1230 "If we're calling this method with displaced = true, then we better well have a " 1231 "displaced problem");
1236 bool constraints_applied =
false;
1238 for (
const auto & it : penetration_locators)
1249 const auto & constraints =
1251 std::unordered_set<unsigned int> needed_mat_props;
1252 for (
const auto & constraint : constraints)
1254 const auto & mp_deps = constraint->getMatPropDependencies();
1255 needed_mat_props.insert(mp_deps.begin(), mp_deps.end());
1259 for (
unsigned int i = 0; i < secondary_nodes.size(); i++)
1261 dof_id_type secondary_node_num = secondary_nodes[i];
1272 for (
const auto & nfc : constraints)
1274 if (nfc->isExplicitConstraint())
1280 if (nfc->secondaryBoundary() != secondary_boundary ||
1281 nfc->primaryBoundary() != primary_boundary)
1284 if (nfc->shouldApply())
1286 constraints_applied =
true;
1287 nfc->computeSecondaryValue(
solution);
1290 if (nfc->hasWritableCoupledVariables())
1292 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
1293 for (
auto * var : nfc->getWritableCoupledVariables())
1295 if (var->isNodalDefined())
1307 std::set<dof_id_type> unique_secondary_node_ids;
1315 const auto & constraints =
1319 unique_secondary_node_ids.clear();
1321 for (
const auto & elem :
as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
1322 meshhelper.active_subdomain_elements_end(secondary_id)))
1324 for (
auto & n : elem->node_ref_range())
1325 unique_secondary_node_ids.insert(n.id());
1328 for (
auto secondary_node_id : unique_secondary_node_ids)
1342 for (
const auto & nec : constraints)
1344 if (nec->shouldApply())
1346 constraints_applied =
true;
1347 nec->computeSecondaryValue(
solution);
1359 if (constraints_applied)
1374 "If we're calling this method with displaced = true, then we better well have a " 1375 "displaced problem");
1380 bool constraints_applied;
1381 bool residual_has_inserted_values =
false;
1383 constraints_applied =
false;
1384 for (
const auto & it : penetration_locators)
1390 constraints_applied =
false;
1399 bool has_writable_variables(
false);
1403 const auto & constraints =
1406 for (
unsigned int i = 0; i < secondary_nodes.size(); i++)
1408 dof_id_type secondary_node_num = secondary_nodes[i];
1419 for (
const auto & nfc : constraints)
1425 if (nfc->secondaryBoundary() != secondary_boundary ||
1426 nfc->primaryBoundary() != primary_boundary)
1429 if (nfc->shouldApply())
1431 constraints_applied =
true;
1432 nfc->computeResidual();
1434 if (nfc->overwriteSecondaryResidual())
1440 const auto & secondary_var = nfc->variable();
1441 const auto & secondary_dofs = secondary_var.dofIndices();
1442 mooseAssert(secondary_dofs.size() == secondary_var.count(),
1443 "We are on a node so there should only be one dof per variable (for " 1444 "an ArrayVariable we should have a number of dofs equal to the " 1445 "number of components");
1451 std::vector<Number> values = {nfc->secondaryResidual()};
1452 residual.
insert(values, secondary_dofs);
1453 residual_has_inserted_values =
true;
1459 if (nfc->hasWritableCoupledVariables())
1461 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
1462 has_writable_variables =
true;
1463 for (
auto * var : nfc->getWritableCoupledVariables())
1465 if (var->isNodalDefined())
1476 if (has_writable_variables)
1494 if (constraints_applied)
1499 if (residual_has_inserted_values)
1502 residual_has_inserted_values =
false;
1516 if (constraints_applied)
1521 if (residual_has_inserted_values)
1535 for (
const auto & it : element_pair_locators)
1542 const auto & element_constraints =
1546 const std::list<std::pair<const Elem *, const Elem *>> & elem_pairs =
1548 for (
const auto & pr : elem_pairs)
1550 const Elem * elem1 = pr.first;
1551 const Elem * elem2 = pr.second;
1559 for (
const auto & ec : element_constraints)
1566 ec->prepareShapes(ec->variable().number());
1567 ec->prepareNeighborShapes(ec->variable().number());
1570 ec->computeResidual();
1580 std::set<dof_id_type> unique_secondary_node_ids;
1582 constraints_applied =
false;
1583 residual_has_inserted_values =
false;
1584 bool has_writable_variables =
false;
1591 const auto & constraints =
1595 unique_secondary_node_ids.clear();
1597 for (
const auto & elem :
as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
1598 meshhelper.active_subdomain_elements_end(secondary_id)))
1600 for (
auto & n : elem->node_ref_range())
1601 unique_secondary_node_ids.insert(n.id());
1604 for (
auto secondary_node_id : unique_secondary_node_ids)
1617 for (
const auto & nec : constraints)
1619 if (nec->shouldApply())
1621 constraints_applied =
true;
1622 nec->computeResidual();
1624 if (nec->overwriteSecondaryResidual())
1627 residual_has_inserted_values =
true;
1633 if (nec->hasWritableCoupledVariables())
1635 Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
1636 has_writable_variables =
true;
1637 for (
auto * var : nec->getWritableCoupledVariables())
1639 if (var->isNodalDefined())
1652 if (constraints_applied)
1657 if (residual_has_inserted_values)
1668 if (has_writable_variables)
1691 for (
const auto & it : penetration_locators)
1701 const auto & constraints =
1705 const auto secondary_node_num = secondary_nodes[i];
1710 for (
const auto & nfc : constraints)
1712 if (!nfc->isExplicitConstraint())
1719 if (nfc->secondaryBoundary() != secondary_boundary ||
1720 nfc->primaryBoundary() != primary_boundary)
1723 nfc->overwriteBoundaryVariables(soln, secondary_node);
1734 TIME_SECTION(
"residualSetup", 3);
1757 #ifdef MOOSE_KOKKOS_ENABLED 1772 parallel_object_only();
1774 TIME_SECTION(
"computeResidualInternal", 3);
1780 std::vector<UserObject *> uos;
1786 for (
auto & uo : uos)
1787 uo->residualSetup();
1788 for (
auto & uo : uos)
1799 #ifdef MOOSE_KOKKOS_ENABLED 1807 TIME_SECTION(
"Kernels", 3 );
1812 Threads::parallel_reduce(elem_range, cr);
1824 Threads::parallel_reduce(faces, fvr);
1833 Threads::parallel_reduce(faces, fvr);
1849 TIME_SECTION(
"ScalarKernels", 3 );
1857 else if (tags.size() == 1)
1858 scalar_kernel_warehouse =
1864 bool have_scalar_contributions =
false;
1866 for (
const auto & scalar_kernel : scalars)
1868 scalar_kernel->reinit();
1869 const std::vector<dof_id_type> & dof_indices = scalar_kernel->variable().dofIndices();
1875 if (dof >= first_dof && dof < end_dof)
1877 scalar_kernel->computeResidual();
1878 have_scalar_contributions =
true;
1883 if (have_scalar_contributions)
1894 TIME_SECTION(
"NodalKernels", 3 );
1904 Threads::parallel_reduce(range, cnk);
1926 TIME_SECTION(
"NodalKernelBCs", 3 );
1932 Threads::parallel_reduce(bnd_node_range, cnk);
1994 const std::set<TagID> & matrix_tags)
1996 TIME_SECTION(
"computeResidualAndJacobianInternal", 3);
2001 for (
auto tag : matrix_tags)
2010 LibmeshPetscCall(MatSetOption(petsc_matrix->mat(),
2011 MAT_KEEP_NONZERO_PATTERN,
2015 MatSetOption(petsc_matrix->mat(), MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
2018 MAT_IGNORE_ZERO_ENTRIES,
2027 std::vector<UserObject *> uos;
2033 for (
auto & uo : uos)
2034 uo->residualSetup();
2035 for (
auto & uo : uos)
2046 #ifdef MOOSE_KOKKOS_ENABLED 2054 TIME_SECTION(
"Kernels", 3 );
2059 Threads::parallel_reduce(elem_range, crj);
2067 Threads::parallel_reduce(faces, fvrj);
2076 Threads::parallel_reduce(faces, fvr);
2098 for (
const auto & residual_vector_tag : residual_vector_tags)
2108 const std::set<TagID> & tags)
2120 #ifdef MOOSE_KOKKOS_ENABLED 2135 else if (tags.size() == 1)
2148 if (!bnd_nodes.
empty())
2150 TIME_SECTION(
"NodalBCs", 3 );
2152 for (
const auto & bnode : bnd_nodes)
2155 Node * node = bnode->_node;
2164 for (
const auto & nbc : bcs)
2165 if (nbc->shouldApply())
2166 nbc->computeResidual();
2191 else if (tags.size() == 1)
2212 std::map<std::string, std::set<unsigned int>> bc_involved_vars;
2214 for (
const auto & bid : all_boundary_ids)
2221 for (
const auto & bc : bcs)
2223 const std::vector<MooseVariableFEBase *> & coupled_moose_vars = bc->getCoupledMooseVars();
2227 std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2228 for (
const auto & coupled_var : coupled_moose_vars)
2230 var_set.insert(coupled_var->number());
2232 var_set.insert(bc->variable().number());
2252 for (
const auto & bnode : bnd_nodes)
2255 Node * node = bnode->_node;
2263 for (
const auto & bc : bcs)
2266 std::set<unsigned int> & var_set = bc_involved_vars[bc->name()];
2272 for (
const auto & it : coupling_entries)
2274 unsigned int ivar = it.first->number(), jvar = it.second->number();
2280 if ((bc->variable().number() == ivar) && var_set.count(jvar) && bc->shouldApply())
2281 bc->computeOffDiagJacobian(jvar);
2284 const auto & coupled_scalar_vars = bc->getCoupledMooseScalarVars();
2285 for (
const auto & jvariable : coupled_scalar_vars)
2287 bc->computeOffDiagJacobianScalar(jvariable->number());
2300 [[maybe_unused]]
const std::set<TagID> & vector_tags,
2301 [[maybe_unused]]
const std::set<TagID> & matrix_tags)
2303 #ifdef MOOSE_KOKKOS_ENABLED 2316 if (!bnd_nodes.
empty())
2318 TIME_SECTION(
"NodalBCs", 3 );
2320 for (
const auto & bnode : bnd_nodes)
2323 Node * node = bnode->_node;
2332 for (
const auto & nbc : bcs)
2333 if (nbc->shouldApply())
2334 nbc->computeResidualAndJacobian();
2350 unsigned int s =
number();
2353 for (
unsigned int v = 0; v <
nVariables(); v++)
2354 for (
unsigned int c = 0; c < node.
n_comp(s, v); c++)
2362 std::unordered_map<
dof_id_type, std::vector<dof_id_type>> & graph)
2366 for (
const auto & it : nearest_node_locators)
2368 std::vector<dof_id_type> & secondary_nodes = it.second->_secondary_nodes;
2370 for (
const auto & secondary_node : secondary_nodes)
2372 std::set<dof_id_type> unique_secondary_indices;
2373 std::set<dof_id_type> unique_primary_indices;
2375 auto node_to_elem_pair = node_to_elem_map.find(secondary_node);
2376 if (node_to_elem_pair != node_to_elem_map.end())
2378 const std::vector<dof_id_type> & elems = node_to_elem_pair->second;
2381 for (
const auto & cur_elem : elems)
2383 std::vector<dof_id_type> dof_indices;
2386 for (
const auto & dof : dof_indices)
2387 unique_secondary_indices.insert(dof);
2391 std::vector<dof_id_type> primary_nodes = it.second->_neighbor_nodes[secondary_node];
2393 for (
const auto & primary_node : primary_nodes)
2395 auto primary_node_to_elem_pair = node_to_elem_map.find(primary_node);
2396 mooseAssert(primary_node_to_elem_pair != node_to_elem_map.end(),
2397 "Missing entry in node to elem map");
2398 const std::vector<dof_id_type> & primary_node_elems = primary_node_to_elem_pair->second;
2401 for (
const auto & cur_elem : primary_node_elems)
2403 std::vector<dof_id_type> dof_indices;
2406 for (
const auto & dof : dof_indices)
2407 unique_primary_indices.insert(dof);
2411 for (
const auto & secondary_id : unique_secondary_indices)
2412 for (
const auto & primary_id : unique_primary_indices)
2414 graph[secondary_id].push_back(primary_id);
2415 graph[primary_id].push_back(secondary_id);
2422 for (
const auto & nc : ncs)
2424 std::vector<dof_id_type> primary_dofs;
2425 std::vector<dof_id_type> & primary_node_ids = nc->getPrimaryNodeId();
2426 for (
const auto & node_id : primary_node_ids)
2437 std::vector<dof_id_type> secondary_dofs;
2438 std::vector<dof_id_type> & secondary_node_ids = nc->getSecondaryNodeId();
2439 for (
const auto & node_id : secondary_node_ids)
2450 for (
const auto & primary_id : primary_dofs)
2451 for (
const auto & secondary_id : secondary_dofs)
2453 graph[primary_id].push_back(secondary_id);
2454 graph[secondary_id].push_back(primary_id);
2459 for (
auto & it : graph)
2461 std::vector<dof_id_type> & row = it.second;
2462 std::sort(row.begin(), row.end());
2463 std::vector<dof_id_type>::iterator uit = std::unique(row.begin(), row.end());
2464 row.resize(uit - row.begin());
2478 std::unordered_map<dof_id_type, std::vector<dof_id_type>> graph;
2482 for (
const auto & it : graph)
2485 const auto & row = it.second;
2487 for (
const auto & coupled_dof : row)
2488 jacobian.add(dof, coupled_dof, 0);
2503 MAT_NEW_NONZERO_ALLOCATION_ERR,
2506 LibmeshPetscCall(MatSetOption(
2507 static_cast<PetscMatrix<Number> &
>(jacobian).mat(), MAT_IGNORE_ZERO_ENTRIES, PETSC_TRUE));
2509 std::vector<numeric_index_type> zero_rows;
2513 "If we're calling this method with displaced = true, then we better well have a " 2514 "displaced problem");
2519 bool constraints_applied;
2521 constraints_applied =
false;
2522 for (
const auto & it : penetration_locators)
2528 constraints_applied =
false;
2540 const auto & constraints =
2543 for (
const auto & secondary_node_num : secondary_nodes)
2556 for (
const auto & nfc : constraints)
2558 if (nfc->isExplicitConstraint())
2564 if (nfc->secondaryBoundary() != secondary_boundary ||
2565 nfc->primaryBoundary() != primary_boundary)
2568 nfc->_jacobian = &jacobian_to_view;
2570 if (nfc->shouldApply())
2572 constraints_applied =
true;
2574 nfc->prepareShapes(nfc->variable().number());
2575 nfc->prepareNeighborShapes(nfc->variable().number());
2577 nfc->computeJacobian();
2579 if (nfc->overwriteSecondaryJacobian())
2582 zero_rows.push_back(nfc->variable().nodalDofIndex());
2585 std::vector<dof_id_type> secondary_dofs(1, nfc->variable().nodalDofIndex());
2591 Real scaling_factor =
2592 nfc->overwriteSecondaryJacobian() ? 1. : nfc->variable().scalingFactor();
2598 nfc->_connected_dof_indices,
2602 if (nfc->addCouplingEntriesToJacobian())
2609 nfc->primaryVariable().dofIndicesNeighbor(),
2615 nfc->primaryVariable().dofIndicesNeighbor(),
2616 nfc->_connected_dof_indices,
2617 nfc->primaryVariable().scalingFactor());
2624 const std::vector<MooseVariableFEBase *> coupled_vars = nfc->getCoupledMooseVars();
2625 for (
const auto & jvar : coupled_vars)
2633 if (nfc->variable().number() == jvar->number() ||
2635 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)
2689 MAT_KEEP_NONZERO_PATTERN,
2693 jacobian.zero_rows(zero_rows, 0.0);
2705 if (constraints_applied)
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)
2753 ec->prepareShapes(ec->variable().number());
2754 ec->prepareNeighborShapes(ec->variable().number());
2757 ec->computeJacobian();
2767 std::set<dof_id_type> unique_secondary_node_ids;
2768 constraints_applied =
false;
2775 const auto & constraints =
2779 unique_secondary_node_ids.clear();
2781 for (
const auto & elem :
as_range(meshhelper.active_subdomain_elements_begin(secondary_id),
2782 meshhelper.active_subdomain_elements_end(secondary_id)))
2784 for (
auto & n : elem->node_ref_range())
2785 unique_secondary_node_ids.insert(n.id());
2788 for (
auto secondary_node_id : unique_secondary_node_ids)
2802 for (
const auto & nec : constraints)
2804 if (nec->shouldApply())
2806 constraints_applied =
true;
2808 nec->_jacobian = &jacobian_to_view;
2809 nec->prepareShapes(nec->variable().number());
2810 nec->prepareNeighborShapes(nec->variable().number());
2812 nec->computeJacobian();
2814 if (nec->overwriteSecondaryJacobian())
2817 zero_rows.push_back(nec->variable().nodalDofIndex());
2820 std::vector<dof_id_type> secondary_dofs(1, nec->variable().nodalDofIndex());
2826 nec->_connected_dof_indices,
2827 nec->variable().scalingFactor());
2832 nec->primaryVariable().dofIndicesNeighbor(),
2833 nec->_connected_dof_indices,
2834 nec->primaryVariable().scalingFactor());
2840 const std::vector<MooseVariableFEBase *> coupled_vars = nec->getCoupledMooseVars();
2841 for (
const auto & jvar : coupled_vars)
2849 if (nec->variable().number() == jvar->number() ||
2851 nec->variable().number(), jvar->number(), this->
number()))
2857 nec->prepareShapes(nec->variable().number());
2858 nec->prepareNeighborShapes(jvar->number());
2860 nec->computeOffDiagJacobian(jvar->number());
2866 nec->_connected_dof_indices,
2867 nec->variable().scalingFactor());
2872 nec->variable().dofIndicesNeighbor(),
2873 nec->_connected_dof_indices,
2874 nec->variable().scalingFactor());
2889 if (constraints_applied)
2892 MAT_KEEP_NONZERO_PATTERN,
2896 jacobian.zero_rows(zero_rows, 0.0);
2910 else if (tags.size() == 1)
2924 bool have_scalar_contributions =
false;
2925 for (
const auto & kernel : scalars)
2927 if (!kernel->computesJacobian())
2931 const std::vector<dof_id_type> & dof_indices = kernel->variable().dofIndices();
2937 if (dof >= first_dof && dof < end_dof)
2939 kernel->computeJacobian();
2941 have_scalar_contributions =
true;
2947 if (have_scalar_contributions)
2976 #ifdef MOOSE_KOKKOS_ENABLED 2991 TIME_SECTION(
"computeJacobianInternal", 3);
2998 for (
auto tag : tags)
3007 LibmeshPetscCall(MatSetOption(petsc_matrix->mat(),
3008 MAT_KEEP_NONZERO_PATTERN,
3012 MatSetOption(petsc_matrix->mat(), MAT_NEW_NONZERO_ALLOCATION_ERR, PETSC_FALSE));
3015 MAT_IGNORE_ZERO_ENTRIES,
3024 std::vector<UserObject *> uos;
3030 for (
auto & uo : uos)
3031 uo->jacobianSetup();
3032 for (
auto & uo : uos)
3043 #ifdef MOOSE_KOKKOS_ENABLED 3060 Threads::parallel_reduce(range, cnkjt);
3076 Threads::parallel_reduce(faces, fvj);
3085 Threads::parallel_reduce(faces, fvr);
3101 Threads::parallel_reduce(elem_range, cj);
3123 Threads::parallel_reduce(elem_range, cj);
3136 Threads::parallel_reduce(bnd_range, cnkjt);
3149 Threads::parallel_reduce(elem_range, cj);
3152 for (
unsigned int i = 0; i <
n_threads; i++)
3161 Threads::parallel_reduce(bnd_range, cnkjt);
3173 static bool first =
true;
3198 std::unique_ptr<SparseMatrix<Number>> hash_copy;
3200 auto make_readable_jacobian = [&]()
3202 #if PETSC_RELEASE_GREATER_EQUALS(3, 23, 0) 3203 if (system_matrix.use_hash_table())
3205 hash_copy = libMesh::cast_ref<PetscMatrix<Number> &>(system_matrix).copy_from_hash();
3206 view_jac_ptr = hash_copy.get();
3209 view_jac_ptr = &system_matrix;
3211 view_jac_ptr = &system_matrix;
3213 if (view_jac_ptr == &system_matrix)
3214 system_matrix.
close();
3217 make_readable_jacobian();
3221 if (had_nodal_constraints)
3223 make_readable_jacobian();
3259 for (
auto & tag : tags)
3278 TIME_SECTION(
"computeJacobianTags", 5);
3300 for (
auto & tag : tags)
3308 const std::set<TagID> & tags)
3310 TIME_SECTION(
"computeJacobianBlocks", 3);
3313 for (
unsigned int i = 0; i <
blocks.size(); i++)
3318 MAT_KEEP_NONZERO_PATTERN,
3322 MAT_NEW_NONZERO_ALLOCATION_ERR,
3335 Threads::parallel_reduce(elem_range, cjb);
3339 for (
unsigned int i = 0; i <
blocks.size(); i++)
3340 blocks[i]->_jacobian.close();
3342 for (
unsigned int i = 0; i <
blocks.size(); i++)
3347 unsigned int ivar =
blocks[i]->_ivar;
3348 unsigned int jvar =
blocks[i]->_jvar;
3351 std::vector<numeric_index_type> zero_rows;
3355 for (
const auto & bnode : bnd_nodes)
3358 Node * node = bnode->_node;
3368 for (
const auto & bc : bcs)
3369 if (bc->variable().number() == ivar && bc->shouldApply())
3415 #ifdef MOOSE_KOKKOS_ENABLED 3431 bool has_active_dampers =
false;
3439 TIME_SECTION(
"computeDampers", 3,
"Computing Dampers");
3440 has_active_dampers =
true;
3453 TIME_SECTION(
"computeDamping::element", 3,
"Computing Element Damping");
3455 has_active_dampers =
true;
3468 TIME_SECTION(
"computeDamping::general", 3,
"Computing General Damping");
3470 has_active_dampers =
true;
3472 for (
const auto & damper : gdampers)
3477 damper->checkMinDamping(gd_damping);
3483 damping =
std::min(gd_damping, damping);
3495 catch (std::exception & e)
3498 const std::string & message = e.what();
3499 if (message.find(
"Jacobian") == std::string::npos)
3505 if (has_active_dampers && damping < 1.0)
3506 _console <<
" Damping factor: " << damping << std::endl;
3516 std::set<const Elem *> dirac_elements;
3520 TIME_SECTION(
"computeDirac", 3,
"Computing DiracKernels");
3526 for (
const auto & dkernel : dkernels)
3528 dkernel->clearPoints();
3529 dkernel->addPoints();
3537 DistElemRange range(dirac_elements.begin(), dirac_elements.end(), 1);
3590 std::vector<dof_id_type> & n_nz,
3591 std::vector<dof_id_type> & n_oz)
3597 std::unordered_map<dof_id_type, std::vector<dof_id_type>> graph;
3612 for (
const auto & git : graph)
3617 if (dof < first_dof_on_proc || dof >= end_dof_on_proc)
3620 const auto & row = git.second;
3624 unsigned int original_row_length = sparsity_row.size();
3626 sparsity_row.insert(sparsity_row.end(), row.begin(), row.end());
3628 SparsityPattern::sort_row(
3629 sparsity_row.begin(), sparsity_row.begin() + original_row_length, sparsity_row.end());
3632 for (
const auto & coupled_dof : row)
3634 if (coupled_dof < first_dof_on_proc || coupled_dof >= end_dof_on_proc)
3636 if (n_oz[local_dof] < n_dofs_not_on_proc)
3641 if (n_nz[local_dof] < n_dofs_on_proc)
3677 mooseError(
"More than one active Preconditioner detected");
3696 const std::set<MooseVariable *> & damped_vars)
3698 for (
const auto & var : damped_vars)
3704 const std::set<MooseVariable *> & damped_vars)
3706 for (
const auto & var : damped_vars)
3714 std::set<SubdomainID> input_subdomains;
3715 std::set<std::string> kernel_variables;
3717 bool global_kernels_exist =
false;
3727 #ifdef MOOSE_KOKKOS_ENABLED 3734 std::vector<FVElementalKernel *> fv_elemental_kernels;
3737 .template condition<AttribSystem>(
"FVElementalKernel")
3738 .queryInto(fv_elemental_kernels);
3740 for (
auto fv_kernel : fv_elemental_kernels)
3742 if (fv_kernel->blockRestricted())
3743 for (
auto block_id : fv_kernel->blockIDs())
3744 input_subdomains.insert(block_id);
3746 global_kernels_exist =
true;
3747 kernel_variables.insert(fv_kernel->variable().name());
3750 if (dynamic_cast<FVScalarLagrangeMultiplierConstraint *>(fv_kernel))
3751 kernel_variables.insert(dynamic_cast<FVScalarLagrangeMultiplierConstraint *>(fv_kernel)
3756 std::vector<FVFluxKernel *> fv_flux_kernels;
3759 .template condition<AttribSystem>(
"FVFluxKernel")
3760 .queryInto(fv_flux_kernels);
3762 for (
auto fv_kernel : fv_flux_kernels)
3764 if (fv_kernel->blockRestricted())
3765 for (
auto block_id : fv_kernel->blockIDs())
3766 input_subdomains.insert(block_id);
3768 global_kernels_exist =
true;
3769 kernel_variables.insert(fv_kernel->variable().name());
3772 std::vector<FVInterfaceKernel *> fv_interface_kernels;
3775 .template condition<AttribSystem>(
"FVInterfaceKernel")
3776 .queryInto(fv_interface_kernels);
3778 for (
auto fvik : fv_interface_kernels)
3779 if (
auto scalar_fvik = dynamic_cast<FVScalarLagrangeMultiplierInterface *>(fvik))
3780 kernel_variables.insert(scalar_fvik->lambdaVariable().name());
3782 std::vector<FVFluxBC *> fv_flux_bcs;
3785 .template condition<AttribSystem>(
"FVFluxBC")
3786 .queryInto(fv_flux_bcs);
3788 for (
auto fvbc : fv_flux_bcs)
3789 if (
auto scalar_fvbc = dynamic_cast<FVBoundaryScalarLagrangeMultiplierConstraint *>(fvbc))
3790 kernel_variables.insert(scalar_fvbc->lambdaVariable().name());
3795 const auto additional_variables_covered = ibc->additionalROVariables();
3796 kernel_variables.insert(additional_variables_covered.begin(),
3797 additional_variables_covered.end());
3801 if (!global_kernels_exist)
3803 std::set<SubdomainID> difference;
3804 std::set_difference(mesh_subdomains.begin(),
3805 mesh_subdomains.end(),
3806 input_subdomains.begin(),
3807 input_subdomains.end(),
3808 std::inserter(difference, difference.end()));
3812 difference.erase(
id);
3814 difference.erase(
id);
3816 if (!difference.empty())
3818 std::vector<SubdomainID> difference_vec =
3819 std::vector<SubdomainID>(difference.begin(), difference.end());
3821 std::stringstream missing_block_names;
3822 std::copy(difference_names.begin(),
3823 difference_names.end(),
3824 std::ostream_iterator<std::string>(missing_block_names,
" "));
3825 std::stringstream missing_block_ids;
3826 std::copy(difference.begin(),
3828 std::ostream_iterator<unsigned int>(missing_block_ids,
" "));
3830 mooseError(
"Each subdomain must contain at least one Kernel.\nThe following block(s) lack an " 3832 missing_block_names.str(),
3834 missing_block_ids.str(),
3842 std::set<VariableName> difference;
3843 std::set_difference(variables.begin(),
3845 kernel_variables.begin(),
3846 kernel_variables.end(),
3847 std::inserter(difference, difference.end()));
3850 std::set<VariableName>
vars(difference);
3851 for (
auto & var_name :
vars)
3854 for (
const auto &
id : blks)
3856 difference.erase(var_name);
3859 if (!difference.empty())
3861 std::stringstream missing_kernel_vars;
3862 std::copy(difference.begin(),
3864 std::ostream_iterator<std::string>(missing_kernel_vars,
" "));
3865 mooseError(
"Each variable must be referenced by at least one active Kernel.\nThe following " 3866 "variable(s) lack an active kernel: " +
3867 missing_kernel_vars.str());
3879 std::vector<std::string>
3882 std::vector<std::string> variable_names;
3884 if (time_kernels.hasActiveObjects())
3885 for (
const auto & kernel : time_kernels.getObjects())
3886 variable_names.push_back(kernel->variable().name());
3888 return variable_names;
3898 if (std::static_pointer_cast<MaterialPropertyInterface>(bc)->getMaterialPropertyCalled())
3905 if (std::static_pointer_cast<MaterialPropertyInterface>(ik)->getMaterialPropertyCalled())
3913 if (
auto mpi = std::dynamic_pointer_cast<MaterialPropertyInterface>(ct);
3914 mpi && mpi->getMaterialPropertyCalled())
3926 if (std::static_pointer_cast<MaterialPropertyInterface>(ik)->getMaterialPropertyCalled())
3938 if (std::static_pointer_cast<MaterialPropertyInterface>(dg)->getMaterialPropertyCalled())
3961 const std::set<TagID> & vector_tags,
3962 const std::set<TagID> & matrix_tags)
3964 parallel_object_only();
3969 map_pr.second(compute_type, vector_tags, matrix_tags);
3972 map_pr.second(compute_type, vector_tags, matrix_tags);
3974 catch (MetaPhysicL::LogicError &)
3977 "We caught a MetaPhysicL error in NonlinearSystemBase::mortarConstraints. This is very " 3978 "likely due to AD not having a sufficiently large derivative container size. Please run " 3979 "MOOSE configure with the '--with-derivative-size=<n>' option");
4002 std::set<unsigned int> var_numbers, var_numbers_covered, var_numbers_not_covered;
4004 var_numbers.insert(var_number);
4014 "', provided to the 'scaling_group_variables' parameter, does not exist in " 4015 "the nonlinear system.");
4022 if (!map_pair.second)
4023 mooseError(
"Variable ", var_name,
" is contained in multiple scaling grouplings");
4024 var_numbers_covered.insert(var.
number());
4027 std::set_difference(var_numbers.begin(),
4029 var_numbers_covered.begin(),
4030 var_numbers_covered.end(),
4031 std::inserter(var_numbers_not_covered, var_numbers_not_covered.begin()));
4036 for (
auto var_number : var_numbers_not_covered)
4041 const auto & number_to_var_map =
_vars[0].numberToVariableMap();
4047 libmesh_map_find(number_to_var_map, i)->name()) !=
4060 _console <<
"\nPerforming automatic scaling calculation\n" << std::endl;
4062 TIME_SECTION(
"computeScaling", 3,
"Computing Automatic Scaling");
4069 std::vector<dof_id_type> dof_indices;
4077 auto & dof_map =
dofMap();
4121 auto examine_dof_indices = [
this,
4125 &jac_inverse_scaling_factors,
4126 &resid_inverse_scaling_factors,
4127 &scaling_residual](
const auto & dof_indices,
const auto var_number)
4129 for (
auto dof_index : dof_indices)
4130 if (dof_map.local_index(dof_index))
4135 auto mat_value = (*_scaling_matrix)(dof_index, dof_index);
4141 auto vec_value = scaling_residual(dof_index);
4153 dof_map.dof_indices(elem, dof_indices, i);
4154 examine_dof_indices(dof_indices, i);
4160 dof_map.SCALAR_dof_indices(dof_indices, i);
4161 examine_dof_indices(dof_indices, i);
4169 if (jac_scaling && resid_scaling)
4170 for (MooseIndex(inverse_scaling_factors) i = 0; i < inverse_scaling_factors.size(); ++i)
4173 if (!resid_inverse_scaling_factors[i])
4175 if (!jac_inverse_scaling_factors[i])
4176 inverse_scaling_factors[i] = 1;
4178 inverse_scaling_factors[i] = jac_inverse_scaling_factors[i];
4180 else if (!jac_inverse_scaling_factors[i])
4182 inverse_scaling_factors[i] = resid_inverse_scaling_factors[i];
4184 inverse_scaling_factors[i] =
4188 else if (jac_scaling)
4189 inverse_scaling_factors = jac_inverse_scaling_factors;
4190 else if (resid_scaling)
4191 inverse_scaling_factors = resid_inverse_scaling_factors;
4193 mooseError(
"We shouldn't be calling this routine if we're not performing any scaling");
4196 for (
auto & scaling_factor : inverse_scaling_factors)
4197 if (scaling_factor == 0)
4201 std::vector<Real> flattened_inverse_scaling_factors(
system().
n_vars());
4202 for (
const auto i :
index_range(flattened_inverse_scaling_factors))
4203 flattened_inverse_scaling_factors[i] = inverse_scaling_factors[
_var_to_group_var[i]];
4209 flattened_inverse_scaling_factors);
4222 auto & scaling_vector =
getVector(
"scaling_factors");
4225 const auto & dof_map =
dofMap();
4227 const auto & field_variables =
_vars[0].fieldVariables();
4228 const auto & scalar_variables =
_vars[0].scalars();
4230 std::vector<dof_id_type> dof_indices;
4232 for (
const Elem *
const elem :
4233 as_range(lm_mesh.active_local_elements_begin(), lm_mesh.active_local_elements_end()))
4234 for (
const auto *
const field_var : field_variables)
4236 const auto & factors = field_var->arrayScalingFactor();
4237 for (
const auto i :
make_range(field_var->count()))
4239 dof_map.dof_indices(elem, dof_indices, field_var->number() + i);
4240 for (
const auto dof : dof_indices)
4241 scaling_vector.set(dof, factors[i]);
4245 for (
const auto *
const scalar_var : scalar_variables)
4247 mooseAssert(scalar_var->count() == 1,
4248 "Scalar variables should always have only one component.");
4249 dof_map.SCALAR_dof_indices(dof_indices, scalar_var->number());
4250 for (
const auto dof : dof_indices)
4251 scaling_vector.set(dof, scalar_var->scalingFactor());
4255 scaling_vector.close();
4277 if (!scaling_succeeded)
4292 LibmeshPetscCall(MatFDColoringDestroy(&
_fdcoloring));
4299 mooseError(
"No field split preconditioner is present for this system");
std::string name(const ElemQuality q)
std::vector< std::shared_ptr< TimeIntegrator > > _time_integrators
Time integrator.
virtual void setSolutionUDotDotOld(const NumericVector< Number > &u_dotdot_old)
virtual void reinitNeighborPhys(const Elem *neighbor, unsigned int neighbor_side, const std::vector< Point > &physical_points, const THREAD_ID tid)=0
virtual void residualSetup(THREAD_ID tid=0) const
NumericVector< Number > & getResidualTimeVector()
Return a numeric vector that is associated with the time tag.
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.
MooseObjectTagWarehouse< NodalKernelBase > _nodal_kernels
NodalKernels for each thread.
NumericVector< Number > * _Re_time
residual vector for time contributions
void computeJacobianBlocks(std::vector< JacobianBlock *> &blocks)
Computes several Jacobian blocks simultaneously, summing their contributions into smaller preconditio...
virtual void insert(const T *v, const std::vector< numeric_index_type > &dof_indices)
MetaPhysicL::DualNumber< V, D, asd > abs(const MetaPhysicL::DualNumber< V, D, asd > &a)
TagID _Re_time_tag
Tag for time contribution residual.
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
std::map< std::pair< BoundaryID, BoundaryID >, PenetrationLocator * > _penetration_locators
dof_id_type end_dof(const processor_id_type proc) const
virtual void addKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a kernel.
virtual void setSolutionUDotDot(const NumericVector< Number > &udotdot)
Set transient term used by residual and Jacobian evaluation.
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
A kernel for hybridized finite element formulations.
MooseObjectTagWarehouse< ResidualObject > _kokkos_nodal_kernels
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
void reinitIncrementAtNodeForDampers(THREAD_ID tid, const std::set< MooseVariable *> &damped_vars)
Compute the incremental change in variables at nodes for dampers.
void overwriteNodeFace(NumericVector< Number > &soln)
Called from explicit time stepping to overwrite boundary positions (explicit dynamics).
Base class for deriving general dampers.
bool _use_pre_smo_residual
Whether to use the pre-SMO initial residual in the relative convergence check.
MoosePreconditioner const * getPreconditioner() const
virtual const char * what() const
Get out the error message.
std::vector< std::pair< MooseVariableFEBase *, MooseVariableFEBase * > > & couplingEntries(const THREAD_ID tid, const unsigned int nl_sys_num)
void findImplicitGeometricCouplingEntries(GeometricSearchData &geom_search_data, std::unordered_map< dof_id_type, std::vector< dof_id_type >> &graph)
Finds the implicit sparsity graph between geometrically related dofs.
void setupDampers()
Setup damping stuff (called before we actually start)
Real _initial_residual
The initial (i.e., 0th nonlinear iteration) residual, see setPreSMOResidual for a detailed explanatio...
std::vector< bool > _variable_autoscaled
Container to hold flag if variable is to participate in autoscaling.
void zeroVectorForResidual(const std::string &vector_name)
virtual void cacheResidualNeighbor(const THREAD_ID tid) override
bool identifyVariableGroupsInNL() const
Whether to identify variable groups in nonlinear systems.
void zeroTaggedVectors(const std::set< TagID > &tags)
Zero all vectors for given tags.
const std::set< SubdomainID > & interiorLowerDBlocks() const
Base class for split-based preconditioners.
bool hasActiveBlockObjects(THREAD_ID tid=0) const
std::shared_ptr< DisplacedProblem > displaced_problem
bool hasVector(const std::string &tag_name) const
Check if the named vector exists in the system.
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...
unsigned int n_comp(const unsigned int s, const unsigned int var) const
void applyScalingFactors(const std::vector< Real > &inverse_scaling_factors)
Applies scaling factors to the system's variables.
bool _debugging_residuals
true if debugging residuals
BoundaryID _secondary_boundary
NumericVector< Number > * _Re_non_time
residual vector for non-time contributions
const std::map< SubdomainID, std::vector< std::shared_ptr< T > > > & getActiveBlockObjects(THREAD_ID tid=0) const
MooseObjectTagWarehouse< ResidualObject > _kokkos_kernels
Real computeDamping(const NumericVector< Number > &solution, const NumericVector< Number > &update)
Compute damping.
virtual void reinitNode(const Node *node, const THREAD_ID tid) override
virtual void setPreviousNewtonSolution(const NumericVector< Number > &soln)
virtual void predictorCleanup(NumericVector< libMesh::Number > &ghosted_solution)
Perform cleanup tasks after application of predictor to solution vector.
bool _assemble_constraints_separately
Whether or not to assemble the residual and Jacobian after the application of each constraint...
virtual Elem * elemPtr(const dof_id_type i)
TagID systemMatrixTag() const override
Return the Matrix Tag ID for System.
NumericVector< Number > & solution()
bool hasObjects(THREAD_ID tid=0) const
Convenience functions for determining if objects exist.
MooseObjectTagWarehouse< DGKernelBase > _dg_kernels
virtual bool haveFV() const override
returns true if this problem includes/needs finite volume functionality.
face_info_iterator ownedFaceInfoBegin()
Iterators to owned faceInfo objects.
void reinitIncrementAtQpsForDampers(THREAD_ID tid, const std::set< MooseVariable *> &damped_vars)
Compute the incremental change in variables at QPs for dampers.
void computeResidualAndJacobianInternal(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Compute residual and Jacobian from contributions not related to constraints, such as nodal boundary c...
bool useHashTableMatrixAssembly() const
void addImplicitGeometricCouplingEntriesToJacobian(bool add=true)
If called with true this will add entries into the jacobian to link together degrees of freedom that ...
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
bool areCoupled(const unsigned int ivar, const unsigned int jvar, const unsigned int nl_sys_num) const
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
void accumulateIterationIntoTimeStepOccurences()
Pass the number of solution invalid occurrences from current iteration to cumulative counters...
unsigned int number() const
Get variable number coming from libMesh.
virtual void initialSetup() override
Setup Functions.
Data structure used to hold penetration information.
const std::vector< std::shared_ptr< NodalConstraint > > & getActiveNodalConstraints() const
Access methods for active objects.
NumericVector< Number > * _u_dot_old
old solution vector for u^dot
bool _has_nodalbc_diag_save_in
If there is a nodal BC having diag_save_in.
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
Base class for automatic differentiation Dirichlet BCs.
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...
virtual void getDiracElements(std::set< const Elem *> &elems) override
Fills "elems" with the elements that should be looped over for Dirac Kernels.
void setupDM()
Setup the PETSc DM object (when appropriate)
void setCurrentlyComputingResidual(bool currently_computing_residual) final
Set whether or not the problem is in the process of computing the residual.
void checkKernelCoverage(const std::set< SubdomainID > &mesh_subdomains) const
void addDGKernel(std::string dg_kernel_name, const std::string &name, InputParameters ¶meters)
Adds a DG kernel.
void computeJacobian(libMesh::SparseMatrix< Number > &jacobian, const std::set< TagID > &tags)
Associate jacobian to systemMatrixTag, and then form a matrix for all the tags.
const InputParameters & parameters() const
Get the parameters of the object.
virtual void reinitNeighborPhys(const Elem *neighbor, unsigned int neighbor_side, const std::vector< Point > &physical_points, const THREAD_ID tid) override
void computeKokkosResidualAndJacobian(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
virtual TagID addVectorTag(const TagName &tag_name, const Moose::VectorTagType type=Moose::VECTOR_TAG_RESIDUAL)
Create a Tag.
std::vector< T * > & queryInto(std::vector< T *> &results, Args &&... args)
queryInto executes the query and stores the results in the given vector.
void getNodeDofs(dof_id_type node_id, std::vector< dof_id_type > &dofs)
Base class for all Constraint types.
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.
void residualSetup() override
Base boundary condition of a Dirichlet type.
virtual void associateVectorToTag(NumericVector< Number > &vec, TagID tag)
Associate a vector for a given tag.
virtual void reinitNodes(const std::vector< dof_id_type > &nodes, const THREAD_ID tid) override
MooseObjectTagWarehouse< NodalBCBase > _nodal_bcs
virtual void addJacobianOffDiagScalar(unsigned int ivar, const THREAD_ID tid=0)
virtual void setException(const std::string &message)
Set an exception, which is stored at this point by toggling a member variable in this class...
const std::vector< std::shared_ptr< NodeFaceConstraint > > & getActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
virtual void customSetup(const ExecFlagType &exec_type, THREAD_ID tid=0) const
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...
virtual const Node * queryNodePtr(const dof_id_type i) const
const ElementPairInfo & getElemPairInfo(std::pair< const Elem *, const Elem *> elem_pair) const
MooseObjectWarehouseBase< Split > _splits
Decomposition splits.
NumericVector< Number > * _u_dotdot
solution vector for u^dotdot
bool hasActiveMortarConstraints(const std::pair< BoundaryID, BoundaryID > &mortar_interface_key, bool displaced) const
const Parallel::Communicator & comm() const
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Solving a linear problem.
bool _has_nodalbc_save_in
If there is a nodal BC having save_in.
bool hasActiveNodalConstraints() const
Deterimine if active objects exist.
virtual bool hasMatrix(TagID tag) const
Check if the tagged matrix exists in the system.
MooseObjectWarehouse< NodalDamper > _nodal_dampers
Nodal Dampers for each thread.
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::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
virtual libMesh::NonlinearSolver< Number > * nonlinearSolver()=0
dof_id_type n_dofs(const unsigned int vn) const
Real preSMOResidual() const
The pre-SMO residual.
std::unique_ptr< libMesh::DiagonalMatrix< Number > > _scaling_matrix
A diagonal matrix used for computing scaling.
virtual void setSolutionUDotOld(const NumericVector< Number > &u_dot_old)
virtual void associateMatrixToTag(libMesh::SparseMatrix< Number > &matrix, TagID tag)
Associate a matrix to a tag.
bool hasDiagSaveIn() const
Weather or not the nonlinear system has diagonal Jacobian save-ins.
This class provides an interface for common operations on field variables of both FE and FV types wit...
const Parallel::Communicator & _communicator
void updateActive(THREAD_ID tid=0) override
Update the various active lists.
Real initialResidual() const
The initial residual.
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
bool needInterfaceMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid) const
Indicated whether this system needs material properties on interfaces.
const libMesh::ConstElemRange & getCurrentAlgebraicElementRange()
These are the element and nodes that contribute to the jacobian and residual for this local processor...
MooseObjectWarehouse< ResidualObject > _kokkos_preset_nodal_bcs
std::size_t _num_scaling_groups
The number of scaling groups.
const libMesh::ConstNodeRange & getCurrentAlgebraicNodeRange()
void computingScalingJacobian(bool computing_scaling_jacobian)
Setter for whether we're computing the scaling jacobian.
dof_id_type n_local_dofs(const unsigned int vn) const
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
bool has_dofs(const unsigned int s=libMesh::invalid_uint) const
std::map< dof_id_type, PenetrationInfo * > & _penetration_info
Data structure of nodes and their associated penetration information.
bool hasActiveNodeElemConstraints(SubdomainID secondary_id, SubdomainID primary_id, bool displaced) const
Real _pre_smo_residual
The pre-SMO residual, see setPreSMOResidual for a detailed explanation.
bool hasDampers()
Whether or not this system has dampers.
const std::vector< std::shared_ptr< NodeElemConstraintBase > > & getActiveNodeElemConstraints(SubdomainID secondary_id, SubdomainID primary_id, bool displaced) const
bool _compute_scaling_once
Whether the scaling factors should only be computed once at the beginning of the simulation through a...
void computeResidualTags(const std::set< TagID > &tags)
Form multiple tag-associated residual vectors for all the given tags.
virtual void cacheJacobianNeighbor(const THREAD_ID tid) override
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool _has_save_in
If there is any Kernel or IntegratedBC having save_in.
virtual const Node & nodeRef(const dof_id_type i) const
TagID _Ke_system_tag
Tag for system contribution Jacobian.
virtual void setResidual(NumericVector< libMesh::Number > &residual, const THREAD_ID tid) override
dof_id_type n_dofs() const
virtual void disassociateMatrixFromTag(libMesh::SparseMatrix< Number > &matrix, TagID tag)
Disassociate a matrix from a tag.
Scope guard for starting and stopping Floating Point Exception Trapping.
auto max(const L &left, const R &right)
Serves as a base class for DGKernel and ADDGKernel.
const Variable & variable(const unsigned int c) const override
void constraintResiduals(NumericVector< Number > &residual, bool displaced)
Add residual contributions from Constraints.
Base class for MOOSE preconditioners.
NumericVector< Number > & addVector(const std::string &vector_name, const bool project, const libMesh::ParallelType type)
Adds a solution length vector to the system.
virtual GeometricSearchData & geomSearchData() override
std::unordered_map< std::pair< BoundaryID, BoundaryID >, ComputeMortarFunctor > _undisplaced_mortar_functors
Functors for computing undisplaced mortar constraints.
Specialization for filling multiple "small" preconditioning matrices simulatenously.
virtual bool matrixFromColoring() const
Whether a system matrix is formed from coloring.
void update()
Update the system (doing libMesh magic)
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num) override
void addScalarKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a scalar kernel.
void addBoundaryCondition(const std::string &bc_name, const std::string &name, InputParameters ¶meters)
Adds a boundary condition.
bool hasActiveNodeFaceConstraints(BoundaryID boundary_id, bool displaced) const
void computeResidual(NumericVector< Number > &residual, TagID tag_id)
Form a residual vector for a given tag.
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...
virtual unsigned int nVariables() const
Get the number of variables in this system.
EXTERN_C_BEGIN PetscErrorCode DMCreate_Moose(DM)
bool hasActiveBoundaryObjects(THREAD_ID tid=0) const
bool _need_residual_ghosted
Whether or not a ghosted copy of the residual needs to be made.
virtual void activateAllMatrixTags()
Make all existing matrices active.
virtual const std::string & name() const
virtual void jacobianSetup()
virtual bool containsTimeKernel() override
If the system has a kernel that corresponds to a time derivative.
void onTimestepBegin()
Called at the beginning of the time step.
const ConstBndNodeRange & getCurrentAlgebraicBndNodeRange()
std::vector< dof_id_type, Threads::scalable_allocator< dof_id_type > > Row
MooseObjectTagWarehouse< DiracKernelBase > _dirac_kernels
Dirac Kernel storage for each thread.
void closeTaggedMatrices(const std::set< TagID > &tags)
Close all matrices associated the tags.
TagID _Re_non_time_tag
Tag for non-time contribution residual.
std::set< TagID > _nl_matrix_tags
Matrix tags to temporarily store all tags associated with the current system.
void set_basic_system_only()
std::map< std::pair< BoundaryID, BoundaryID >, NearestNodeLocator * > _nearest_node_locators
void setPredictor(std::shared_ptr< Predictor > predictor)
Real _resid_vs_jac_scaling_param
The param that indicates the weighting of the residual vs the Jacobian in determining variable scalin...
bool _auto_scaling_initd
Whether we've initialized the automatic scaling data structures.
virtual void computeScalingResidual()=0
Compute a "residual" for automatic scaling purposes.
bool _doing_dg
true if DG is active (optimization reasons)
virtual libMesh::DofMap & dofMap()
Gets writeable reference to the dof map.
void syncIteration()
Sync iteration counts to main processor Sum across all processors.
virtual void deactivateAllMatrixTags()
Make matrices inactive.
void computeNodalBCsResidual(NumericVector< Number > &residual)
Enforces nodal boundary conditions.
unsigned int number() const
void computeResidualAndJacobianTags(const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Form possibly multiple tag-associated vectors and matrices.
bool needBoundaryMaterialOnSide(BoundaryID bnd_id, THREAD_ID tid) const
Indicated whether this system needs material properties on boundaries.
MooseObjectWarehouse< DirichletBCBase > _preset_nodal_bcs
std::unordered_map< unsigned int, unsigned int > _var_to_group_var
A map from variable index to group variable index and it's associated (inverse) scaling factor...
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...
std::vector< unsigned int > _current_l_its
virtual std::unique_ptr< Base > create()=0
void setCurrentNonlinearSystem(const unsigned int nl_sys_num)
std::shared_ptr< T > getActiveObject(const std::string &name, THREAD_ID tid=0) const
This is the common base class for the three main kernel types implemented in MOOSE, Kernel, VectorKernel and ArrayKernel.
std::vector< dof_id_type > _secondary_nodes
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
void min(const T &r, T &o, Request &req) const
void computeDiracContributions(const std::set< TagID > &tags, bool is_jacobian)
void updateActive(THREAD_ID tid)
Update active objects of Warehouses owned by NonlinearSystemBase.
TheWarehouse & theWarehouse() const
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
const ElementPairList & getElemPairs() const
FieldSplitPreconditionerBase & getFieldSplitPreconditioner()
std::unordered_map< std::pair< BoundaryID, BoundaryID >, ComputeMortarFunctor > _displaced_mortar_functors
Functors for computing displaced mortar constraints.
bool enforceNodalConstraintsJacobian(const SparseMatrix< Number > &jacobian)
Enforce nodal constraints in the Jacobian.
unsigned int _current_nl_its
const std::unordered_map< std::pair< BoundaryID, BoundaryID >, std::unique_ptr< AutomaticMortarGeneration > > & getMortarInterfaces(bool on_displaced) const
boundary_id_type BoundaryID
Real referenceResidual() const
The reference residual used in relative convergence check.
void addSplit(const std::string &split_name, const std::string &name, InputParameters ¶meters)
Adds a split.
bool _automatic_scaling
Whether to automatically scale the variables.
MatFDColoring _fdcoloring
void computeJacobianTags(const std::set< TagID > &tags)
Computes multiple (tag associated) Jacobian matricese.
SolutionInvalidity & solutionInvalidity()
Get the SolutionInvalidity for this app.
std::shared_ptr< MoosePreconditioner > _preconditioner
Preconditioner.
virtual void timestepSetup(THREAD_ID tid=0) const
NonlinearSystemBase & currentNonlinearSystem()
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
void computingScalingResidual(bool computing_scaling_residual)
Setter for whether we're computing the scaling residual.
virtual void setupDM()=0
setup the data management data structure that manages the field split
SubProblem & subproblem()
std::vector< std::string > _vecs_to_zero_for_residual
vectors that will be zeroed before a residual computation
virtual TagID addMatrixTag(TagName tag_name)
Create a Tag.
std::shared_ptr< Split > getSplit(const std::string &name)
Retrieves a split by name.
void setInitialSolution()
std::unique_ptr< NumericVector< Number > > solution
SubProblem & _subproblem
The subproblem for whom this class holds variable data, etc; this can either be the governing finite ...
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.
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 addHDGKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a hybridized discontinuous Galerkin (HDG) kernel.
virtual void zero_rows(std::vector< numeric_index_type > &rows, T diag_value=0.0)
MooseObjectTagWarehouse< KernelBase > _kernels
MooseObjectWarehouse< T > & getMatrixTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given matrix tag...
bool shouldEvaluatePreSMOResidual() const
We offer the option to check convergence against the pre-SMO residual.
std::vector< VectorTag > getVectorTags(const std::set< TagID > &tag_ids) const
Base class for deriving nodal dampers.
virtual void disassociateVectorFromTag(NumericVector< Number > &vec, TagID tag)
Disassociate a given vector from a given tag.
virtual void cacheResidual(const THREAD_ID tid) override
void mooseDeprecated(Args &&... args)
Emit a deprecated code/feature message with the given stringified, concatenated args.
virtual void computeScalingJacobian()=0
Compute a "Jacobian" for automatic scaling purposes.
bool errorOnJacobianNonzeroReallocation() const
Will return True if the user wants to get an error when a nonzero is reallocated in the Jacobian by P...
This is the ElementPairLocator class.
This is the ElementPairInfo class.
std::map< BoundaryID, std::shared_ptr< ElementPairLocator > > _element_pair_locators
Moose::CouplingType coupling() const
unsigned int number() const
Gets the number of this system.
void setupScalingData()
Setup group scaling containers.
virtual GeometricSearchData & geomSearchData()=0
const bool & usePreSMOResidual() const
Whether we are using pre-SMO residual in relative convergence checks.
MooseObjectTagWarehouse< HDGKernel > _hybridized_kernels
const std::set< SubdomainID > & boundaryLowerDBlocks() const
std::vector< SubdomainName > getSubdomainNames(const std::vector< SubdomainID > &subdomain_ids) const
Get the associated subdomainNames for the subdomain ids that are passed in.
AuxiliarySystem & getAuxiliarySystem()
virtual void initialSetup(THREAD_ID tid=0) const
Convenience methods for calling object setup methods.
virtual void updateGeomSearch(GeometricSearchData::GeometricSearchType type=GeometricSearchData::ALL) override
void closeTaggedVectors(const std::set< TagID > &tags)
Close all vectors for given tags.
Base class for deriving any boundary condition that works at nodes.
void computeResidualInternal(const std::set< TagID > &tags)
Compute the residual for a given tag.
virtual void prepareAssembly(const THREAD_ID tid) override
bool computeScaling()
Method used to obtain scaling factors for variables.
Interface for objects interacting with the PerfGraph.
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 bool hasVariable(const std::string &var_name) const
Query a system for a variable.
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid) override
virtual void clearDiracInfo() override
Gets called before Dirac Kernels are asked to add the points they are supposed to be evaluated in...
void destroyColoring()
Destroy the coloring object if it exists.
virtual void reinitNodesNeighbor(const std::vector< dof_id_type > &nodes, const THREAD_ID tid) override
bool identify_variable_groups() const
virtual void jacobianSetup(THREAD_ID tid=0) const
ConstraintWarehouse _constraints
Constraints storage object.
virtual void turnOffJacobian()
Turn off the Jacobian (must be called before equation system initialization)
void computeKokkosJacobian(const std::set< TagID > &tags)
Compute Jacobian with Kokkos objects.
TagID residualVectorTag() const override
const std::map< BoundaryID, std::vector< std::shared_ptr< T > > > & getActiveBoundaryObjects(THREAD_ID tid=0) const
void computingNonlinearResid(bool computing_nonlinear_residual) final
Set whether or not the problem is in the process of computing the nonlinear residual.
virtual void customSetup(const ExecFlagType &exec_type) override
ComputeType
The type of nonlinear computation being performed.
Base class for deriving element dampers.
Base interface for field split preconditioner.
bool _add_implicit_geometric_coupling_entries_to_jacobian
Whether or not to add implicit geometric couplings to the Jacobian for FDP.
const_iterator end() const
MooseObjectTagWarehouse< ResidualObject > _kokkos_integrated_bcs
void computeKokkosNodalBCsResidual(const std::set< TagID > &tags)
Compute Kokkos nodal BCs.
virtual void addNodalKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a NodalKernel.
virtual unsigned int numMatrixTags() const
The total number of tags.
Base class for creating new types of boundary conditions.
FEProblemBase & _fe_problem
the governing finite element/volume problem
virtual void reinitElemPhys(const Elem *elem, const std::vector< Point > &phys_points_in_elem, const THREAD_ID tid)=0
virtual MooseVariableScalar & getScalarVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a scalar variable with specified number.
ParallelType type() const
virtual NumericVector< Number > & RHS()=0
std::vector< VariableWarehouse > _vars
Variable warehouses (one for each thread)
Provides a way for users to bail out of the current solve.
unsigned int _n_residual_evaluations
Total number of residual evaluations that have been performed.
void addDiracKernel(const std::string &kernel_name, const std::string &name, InputParameters ¶meters)
Adds a Dirac kernel.
void computeJacobianInternal(const std::set< TagID > &tags)
Form multiple matrices for all the tags.
bool _has_diag_save_in
If there is any Kernel or IntegratedBC having diag_save_in.
Base class for creating new types of nodal kernels.
const FEType & variable_type(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual std::shared_ptr< const DisplacedProblem > getDisplacedProblem() const
std::unique_ptr< NumericVector< Number > > _residual_copy
Copy of the residual vector, or nullptr if a copy is not needed.
virtual void subdomainSetup()
bool hasSaveIn() const
Weather or not the nonlinear system has save-ins.
Generic class for solving transient nonlinear problems.
TagID timeVectorTag() const override
Ideally, we should not need this API.
Class for containing MooseEnum item information.
virtual std::vector< std::string > timeKernelVariableNames() override
Returns the names of the variables that have time derivative kernels in the system.
bool hasActiveObjects(THREAD_ID tid=0) const
NonlinearSystemBase(FEProblemBase &problem, libMesh::System &sys, const std::string &name)
void max(const T &r, T &o, Request &req) const
NumericVector< Number > * _u_dot
solution vector for u^dot
MooseObjectWarehouse< ElementDamper > _element_dampers
Element Dampers for each thread.
void addObject(std::shared_ptr< Constraint > object, THREAD_ID tid=0, bool recurse=true) override
Add Constraint object to the warehouse.
virtual void setSolutionUDot(const NumericVector< Number > &udot)
Set transient term used by residual and Jacobian evaluation.
virtual libMesh::SparseMatrix< Number > & getMatrix(TagID tag)
Get a raw SparseMatrix.
bool hasKokkosResidualObjects() const
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.
const std::vector< std::shared_ptr< MortarConstraintBase > > & getActiveMortarConstraints(const std::pair< BoundaryID, BoundaryID > &mortar_interface_key, bool displaced) const
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...
void computeScalarKernelsJacobians(const std::set< TagID > &tags)
void setInitialResidual(Real r)
Record the initial residual (for later relative convergence check)
Query query()
query creates and returns an initialized a query object for querying objects from the warehouse...
virtual Assembly & assembly(const THREAD_ID tid, const unsigned int sys_num)=0
const_iterator begin() const
bool needInternalNeighborSideMaterial(SubdomainID subdomain_id, THREAD_ID tid) const
Indicates whether this system needs material properties on internal sides.
void computeKokkosResidual(const std::set< TagID > &tags)
Compute residual with Kokkos objects.
Base class for deriving dampers.
bool getFailNextNonlinearConvergenceCheck() const
Whether it will skip further residual evaluations and fail the next nonlinear convergence check(s) ...
Base class shared by AD and non-AD scalar kernels.
void addDamper(const std::string &damper_name, const std::string &name, InputParameters ¶meters)
Adds a damper.
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
virtual void postAddResidualObject(ResidualObject &)
Called after any ResidualObject-derived objects are added to the system.
const std::vector< VariableName > & getVariableNames() const
virtual void preInit() override
This is called prior to the libMesh system has been init'd.
virtual void updateActive(THREAD_ID tid=0) override
Update the active status of Kernels.
virtual void timestepSetup() override
bool hasActiveElemElemConstraints(const InterfaceID interface_id, bool displaced) const
bool _off_diagonals_in_auto_scaling
Whether to include off diagonals when determining automatic scaling factors.
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.
void reinitNodeFace(const Node &secondary_node, const BoundaryID secondary_boundary, const PenetrationInfo &info, const bool displaced)
Reinitialize quantities such as variables, residuals, Jacobians, materials for node-face constraints...
Base class for deriving any boundary condition of a integrated type.
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
NumericVector< Number > * _residual_ghosted
ghosted form of the residual
void setCachedJacobian(GlobalDataKey)
Sets previously-cached Jacobian values via SparseMatrix::set() calls.
TagID _Re_tag
Used for the residual vector from PETSc.
virtual void customSetup(const ExecFlagType &exec_type)
MooseObjectWarehouse< T > & getVectorTagObjectWarehouse(TagID tag_id, THREAD_ID tid)
Retrieve a moose object warehouse in which every moose object has the given vector tag...
const std::set< SubdomainID > & getSubdomainsForVar(unsigned int var_number) const
virtual void addObject(std::shared_ptr< T > object, THREAD_ID tid=0, bool recurse=true)
Adds an object to the storage structure.
bool ignoreZerosInJacobian() const
Will return true if zeros in the Jacobian are to be dropped from the sparsity pattern.
void computeNodalBCsJacobian(const std::set< TagID > &tags)
Compute the Jacobian for nodal boundary conditions.
const ExecFlagType EXEC_PRE_KERNELS
void mortarConstraints(Moose::ComputeType compute_type, const std::set< TagID > &vector_tags, const std::set< TagID > &matrix_tags)
Do mortar constraint residual/jacobian computations.
NumericVector< Number > * _increment_vec
increment vector
InterfaceKernelBase is the base class for all InterfaceKernel type classes.
QueryCache & condition(Args &&... args)
Adds a new condition to the query.
bool doingDG() const
Getter for _doing_dg.
void computeResidualTag(NumericVector< Number > &residual, TagID tag_id)
Computes residual for a given tag.
void addConstraint(const std::string &c_name, const std::string &name, InputParameters ¶meters)
Adds a Constraint.
virtual TagName vectorTagName(const TagID tag) const
Retrieve the name associated with a TagID.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
bool hasKokkosObjects() const
bool restoreOriginalNonzeroPattern() const
face_info_iterator ownedFaceInfoEnd()
void constraintJacobians(const SparseMatrix< Number > &jacobian_to_view, bool displaced)
Add jacobian contributions from Constraints.
virtual libMesh::System & system() override
Get the reference to the libMesh system.
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
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. ...
bool preSolve()
Perform some steps to get ready for the solver.
void full_sparsity_pattern_needed()
bool _has_constraints
Whether or not this system has any Constraints.
dof_id_type first_dof(const processor_id_type proc) const
bool _computed_scaling
Flag used to indicate whether we have already computed the scaling Jacobian.
void remove_algebraic_ghosting_functor(GhostingFunctor &evaluable_functor)
MooseObjectTagWarehouse< InterfaceKernelBase > _interface_kernels
unsigned int n_vars() const
NumericVector< Number > & residualVector(TagID tag)
Return a residual vector that is associated with the residual tag.
NumericVector< Number > & solutionOld()
NumericVector< Number > & getResidualNonTimeVector()
Return a numeric vector that is associated with the nontime tag.
virtual bool hasScalarVariable(const std::string &var_name) const
const TagName PREVIOUS_NL_SOLUTION_TAG
processor_id_type processor_id() const
std::shared_ptr< Predictor > _predictor
If predictor is active, this is non-NULL.
void enforceNodalConstraintsResidual(NumericVector< Number > &residual)
Enforce nodal constraints.
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.
MooseObjectWarehouse< GeneralDamper > _general_dampers
General Dampers.
const std::vector< std::shared_ptr< ElemElemConstraint > > & getActiveElemElemConstraints(InterfaceID interface_id, bool displaced) const
virtual void initialSetup()
Setup Functions.
bool defaultGhosting()
Whether or not the user has requested default ghosting ot be on.
void addCachedJacobian(GlobalDataKey)
Adds the values that have been cached by calling cacheJacobian() and or cacheJacobianNeighbor() to th...
virtual void cacheJacobian(const THREAD_ID tid) override
auto min(const L &left, const R &right)
void jacobianSetup() override
void setKokkosInitialSolution()
virtual NumericVector< Number > & getVector(const std::string &name)
Get a raw NumericVector by name.
MooseObjectTagWarehouse< IntegratedBCBase > _integrated_bcs
const DofMap & get_dof_map() const
virtual void reinitNodeFace(const Node *node, BoundaryID bnd_id, const THREAD_ID tid) override
virtual void residualSetup()
virtual void reinitOffDiagScalars(const THREAD_ID tid) override
processor_id_type processor_id() 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 setNeighborSubdomainID(const Elem *elem, unsigned int side, const THREAD_ID tid) override
virtual void addResidualScalar(const THREAD_ID tid=0)
virtual void subdomainSetup(THREAD_ID tid=0) const
virtual void jacobianSetup() override
virtual void addCachedResidual(const THREAD_ID tid) override
std::vector< std::vector< std::string > > _scaling_group_variables
A container of variable groupings that can be used in scaling calculations.
void addInterfaceKernel(std::string interface_kernel_name, const std::string &name, InputParameters ¶meters)
Adds an interface kernel.
FieldSplitPreconditionerBase * _fsp
The field split preconditioner if this sytem is using one.
auto index_range(const T &sizable)
virtual NumericVector< Number > & residualCopy() override
void reinitMortarFunctors()
Update the mortar functors if the mesh has changed.
virtual NumericVector< Number > & residualGhosted() override
DiracKernelBase is the base class for all DiracKernel type classes.
virtual void updateActive(THREAD_ID tid=0)
Updates the active objects storage.
MooseObjectTagWarehouse< ResidualObject > _kokkos_nodal_bcs
void assembleScalingVector()
Assemble the numeric vector of scaling factors such that it can be used during assembly of the system...
BoundaryID _primary_boundary
NumericVector< Number > * _u_dotdot_old
old solution vector for u^dotdot
MooseObjectTagWarehouse< ScalarKernelBase > _scalar_kernels
virtual void residualEnd(THREAD_ID tid=0) const
void setConstraintSecondaryValues(NumericVector< Number > &solution, bool displaced)
Sets the value of constrained variables in the solution vector.
virtual void addJacobianScalar(const THREAD_ID tid=0)
NearestNodeLocator & _nearest_node
const std::map< dof_id_type, std::vector< dof_id_type > > & nodeToElemMap()
If not already created, creates a map from every node to all elements to which they are connected...
const std::set< SubdomainID > & meshSubdomains() const
Returns a read-only reference to the set of subdomains currently present in the Mesh.
virtual void addCachedJacobian(const THREAD_ID tid) override
virtual void timestepSetup()
virtual ~NonlinearSystemBase()
virtual void preInit() override
This is called prior to the libMesh system has been init'd.
virtual void residualSetup() override
void setPreconditioner(std::shared_ptr< MoosePreconditioner > pc)
Sets a preconditioner.
virtual void localize(std::vector< T > &v_local) const=0
MooseObjectWarehouse< ADDirichletBCBase > _ad_preset_nodal_bcs
virtual libMesh::System & system() override
Get the reference to the libMesh system.
Key structure for APIs manipulating global vectors/matrices.