LCOV - code coverage report
Current view: top level - src/mesh - MooseMesh.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33390 (250e9c) with base 846a5c Lines: 1785 2096 85.2 %
Date: 2026-07-31 18:15:22 Functions: 189 237 79.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "MooseError.h"
      11             : #include "MooseMesh.h"
      12             : #include "Factory.h"
      13             : #include "CacheChangedListsThread.h"
      14             : #include "MooseUtils.h"
      15             : #include "MooseApp.h"
      16             : #include "RelationshipManager.h"
      17             : #include "PointListAdaptor.h"
      18             : #include "Executioner.h"
      19             : #include "NonlinearSystemBase.h"
      20             : #include "LinearSystem.h"
      21             : #include "AuxiliarySystem.h"
      22             : #include "Assembly.h"
      23             : #include "SubProblem.h"
      24             : #include "MooseVariableBase.h"
      25             : #include "MooseMeshUtils.h"
      26             : #include "MooseAppCoordTransform.h"
      27             : #include "FEProblemBase.h"
      28             : 
      29             : #include <utility>
      30             : 
      31             : // libMesh
      32             : #include "libmesh/bounding_box.h"
      33             : #include "libmesh/boundary_info.h"
      34             : #include "libmesh/mesh_tools.h"
      35             : #include "libmesh/parallel.h"
      36             : #include "libmesh/mesh_communication.h"
      37             : #include "libmesh/periodic_boundary_base.h"
      38             : #include "libmesh/fe_base.h"
      39             : #include "libmesh/fe_interface.h"
      40             : #include "libmesh/mesh_communication.h"
      41             : #include "libmesh/mesh_tools.h"
      42             : #include "libmesh/parallel.h"
      43             : #include "libmesh/parallel_elem.h"
      44             : #include "libmesh/parallel_node.h"
      45             : #include "libmesh/parallel_ghost_sync.h"
      46             : #include "libmesh/utility.h"
      47             : #include "libmesh/remote_elem.h"
      48             : #include "libmesh/linear_partitioner.h"
      49             : #include "libmesh/centroid_partitioner.h"
      50             : #include "libmesh/parmetis_partitioner.h"
      51             : #include "libmesh/hilbert_sfc_partitioner.h"
      52             : #include "libmesh/morton_sfc_partitioner.h"
      53             : #include "libmesh/edge_edge2.h"
      54             : #include "libmesh/mesh_refinement.h"
      55             : #include "libmesh/quadrature.h"
      56             : #include "libmesh/boundary_info.h"
      57             : #include "libmesh/periodic_boundaries.h"
      58             : #include "libmesh/quadrature_gauss.h"
      59             : #include "libmesh/point_locator_base.h"
      60             : #include "libmesh/default_coupling.h"
      61             : #include "libmesh/ghost_point_neighbors.h"
      62             : #include "libmesh/fe_type.h"
      63             : #include "libmesh/enum_to_string.h"
      64             : #include "libmesh/elem_side_builder.h"
      65             : 
      66             : using namespace libMesh;
      67             : 
      68             : // Make newer nanoflann API compatible with older nanoflann versions
      69             : #if NANOFLANN_VERSION < 0x150
      70             : namespace nanoflann
      71             : {
      72             : typedef SearchParams SearchParameters;
      73             : 
      74             : template <typename T, typename U>
      75             : using ResultItem = std::pair<T, U>;
      76             : }
      77             : #endif
      78             : 
      79             : const std::array<bool, 3> MooseMesh::periodic_dim_default{false, false, false};
      80             : 
      81             : InputParameters
      82      203681 : MooseMesh::validParams()
      83             : {
      84      203681 :   InputParameters params = MooseObject::validParams();
      85             : 
      86      814724 :   MooseEnum parallel_type("DEFAULT REPLICATED DISTRIBUTED", "DEFAULT");
      87      814724 :   params.addParam<MooseEnum>("parallel_type",
      88             :                              parallel_type,
      89             :                              "DEFAULT: Use libMesh::ReplicatedMesh unless --distributed-mesh is "
      90             :                              "specified on the command line "
      91             :                              "REPLICATED: Always use libMesh::ReplicatedMesh "
      92             :                              "DISTRIBUTED: Always use libMesh::DistributedMesh");
      93             : 
      94      611043 :   params.addParam<bool>(
      95             :       "allow_renumbering",
      96      407362 :       true,
      97             :       "If allow_renumbering=false, node and element numbers are kept fixed until deletion");
      98             : 
      99      611043 :   params.addParam<MooseEnum>(
     100             :       "partitioner",
     101      407362 :       partitioning(),
     102             :       "Specifies a mesh partitioner to use when splitting the mesh for a parallel computation.");
     103      814724 :   MooseEnum direction("x y z radial");
     104      814724 :   params.addParam<MooseEnum>("centroid_partitioner_direction",
     105             :                              direction,
     106             :                              "Specifies the sort direction if using the centroid partitioner. "
     107             :                              "Available options: x, y, z, radial");
     108             : 
     109      814724 :   MooseEnum patch_update_strategy("never always auto iteration", "never");
     110      814724 :   params.addParam<MooseEnum>(
     111             :       "patch_update_strategy",
     112             :       patch_update_strategy,
     113             :       "How often to update the geometric search 'patch'.  The default is to "
     114             :       "never update it (which is the most efficient but could be a problem "
     115             :       "with lots of relative motion). 'always' will update the patch for all "
     116             :       "secondary nodes at the beginning of every timestep which might be time "
     117             :       "consuming. 'auto' will attempt to determine at the start of which "
     118             :       "timesteps the patch for all secondary nodes needs to be updated automatically."
     119             :       "'iteration' updates the patch at every nonlinear iteration for a "
     120             :       "subset of secondary nodes for which penetration is not detected. If there "
     121             :       "can be substantial relative motion between the primary and secondary surfaces "
     122             :       "during the nonlinear iterations within a timestep, it is advisable to use "
     123             :       "'iteration' option to ensure accurate contact detection.");
     124             : 
     125             :   // Note: This parameter is named to match 'construct_side_list_from_node_list' in SetupMeshAction
     126      611043 :   params.addParam<bool>(
     127             :       "construct_node_list_from_side_list",
     128      407362 :       true,
     129             :       "Whether or not to generate nodesets from the sidesets (currently often required).");
     130      611043 :   params.addParam<bool>(
     131             :       "displace_node_list_by_side_list",
     132      407362 :       true,
     133             :       "Whether to renumber existing nodesets with ids matching sidesets that "
     134             :       "lack names matching sidesets, when constructing nodesets from sidesets via the default "
     135             :       "'construct_node_list_from_side_list' option, rather than to merge them with the sideset.");
     136      611043 :   params.addParam<unsigned int>(
     137      407362 :       "patch_size", 40, "The number of nodes to consider in the NearestNode neighborhood.");
     138      814724 :   params.addParam<unsigned int>("ghosting_patch_size",
     139             :                                 "The number of nearest neighbors considered "
     140             :                                 "for ghosting purposes when 'iteration' "
     141             :                                 "patch update strategy is used. Default is "
     142             :                                 "5 * patch_size.");
     143      611043 :   params.addParam<unsigned int>("max_leaf_size",
     144      407362 :                                 10,
     145             :                                 "The maximum number of points in each leaf of the KDTree used in "
     146             :                                 "the nearest neighbor search. As the leaf size becomes larger,"
     147             :                                 "KDTree construction becomes faster but the nearest neighbor search"
     148             :                                 "becomes slower.");
     149             : 
     150      611043 :   params.addParam<bool>("build_all_side_lowerd_mesh",
     151      407362 :                         false,
     152             :                         "True to build the lower-dimensional mesh for all sides.");
     153             : 
     154      611043 :   params.addParam<bool>("skip_refine_when_use_split",
     155      407362 :                         true,
     156             :                         "True to skip uniform refinements when using a pre-split mesh.");
     157             : 
     158      814724 :   params.addParam<std::vector<SubdomainID>>(
     159             :       "add_subdomain_ids",
     160             :       "The listed subdomain ids will be assumed valid for the mesh. This permits setting up "
     161             :       "subdomain restrictions for subdomains initially containing no elements, which can occur, "
     162             :       "for example, in additive manufacturing simulations which dynamically add and remove "
     163             :       "elements. Names for this subdomains may be provided using add_subdomain_names. In this case "
     164             :       "this list and add_subdomain_names must contain the same number of items.");
     165      814724 :   params.addParam<std::vector<SubdomainName>>(
     166             :       "add_subdomain_names",
     167             :       "The listed subdomain names will be assumed valid for the mesh. This permits setting up "
     168             :       "subdomain restrictions for subdomains initially containing no elements, which can occur, "
     169             :       "for example, in additive manufacturing simulations which dynamically add and remove "
     170             :       "elements. IDs for this subdomains may be provided using add_subdomain_ids. Otherwise IDs "
     171             :       "are automatically assigned. In case add_subdomain_ids is set too, both lists must contain "
     172             :       "the same number of items.");
     173             : 
     174      814724 :   params.addParam<std::vector<BoundaryID>>(
     175             :       "add_sideset_ids",
     176             :       "The listed sideset ids will be assumed valid for the mesh. This permits setting up boundary "
     177             :       "restrictions for sidesets initially containing no sides. Names for this sidesets may be "
     178             :       "provided using add_sideset_names. In this case this list and add_sideset_names must contain "
     179             :       "the same number of items.");
     180      814724 :   params.addParam<std::vector<BoundaryName>>(
     181             :       "add_sideset_names",
     182             :       "The listed sideset names will be assumed valid for the mesh. This permits setting up "
     183             :       "boundary restrictions for sidesets initially containing no sides. Ids for this sidesets may "
     184             :       "be provided using add_sideset_ids. In this case this list and add_sideset_ids must contain "
     185             :       "the same number of items.");
     186             : 
     187      814724 :   params.addParam<std::vector<BoundaryID>>(
     188             :       "add_nodeset_ids",
     189             :       "The listed nodeset ids will be assumed valid for the mesh. This permits setting up boundary "
     190             :       "restrictions for node initially containing no sides. Names for this nodesets may be "
     191             :       "provided using add_nodeset_names. In this case this list and add_nodeset_names must contain "
     192             :       "the same number of items.");
     193      611043 :   params.addParam<std::vector<BoundaryName>>(
     194             :       "add_nodeset_names",
     195             :       "The listed nodeset names will be assumed valid for the mesh. This permits setting up "
     196             :       "boundary restrictions for nodesets initially containing no sides. Ids for this nodesets may "
     197             :       "be provided using add_nodesets_ids. In this case this list and add_nodesets_ids must "
     198             :       "contain the same number of items.");
     199             : 
     200      203681 :   params += MooseAppCoordTransform::validParams();
     201             : 
     202             :   // This indicates that the derived mesh type accepts a MeshGenerator, and should be set to true in
     203             :   // derived types that do so.
     204      407362 :   params.addPrivateParam<bool>("_mesh_generator_mesh", false);
     205             : 
     206             :   // Whether or not the mesh is pre split
     207      611043 :   params.addPrivateParam<bool>("_is_split", false);
     208             : 
     209      407362 :   params.registerBase("MooseMesh");
     210             : 
     211             :   // groups
     212      814724 :   params.addParamNamesToGroup("patch_update_strategy patch_size max_leaf_size", "Geometric search");
     213      814724 :   params.addParamNamesToGroup("add_subdomain_ids add_subdomain_names add_sideset_ids "
     214             :                               "add_sideset_names add_nodeset_ids add_nodeset_names",
     215             :                               "Pre-declaration of future mesh sub-entities");
     216      814724 :   params.addParamNamesToGroup("construct_node_list_from_side_list build_all_side_lowerd_mesh "
     217             :                               "displace_node_list_by_side_list",
     218             :                               "Automatic definition of mesh element sides entities");
     219      611043 :   params.addParamNamesToGroup("partitioner centroid_partitioner_direction", "Partitioning");
     220             : 
     221      407362 :   return params;
     222      203681 : }
     223             : 
     224       66973 : MooseMesh::MooseMesh(const InputParameters & parameters)
     225             :   : MooseObject(parameters),
     226             :     Restartable(this, "Mesh"),
     227             :     PerfGraphInterface(this),
     228       66973 :     _parallel_type(getParam<MooseEnum>("parallel_type").getEnum<MooseMesh::ParallelType>()),
     229       66973 :     _use_distributed_mesh(false),
     230       66973 :     _distribution_overridden(false),
     231       66973 :     _parallel_type_overridden(false),
     232       66973 :     _mesh(nullptr),
     233      133946 :     _partitioner_name(getParam<MooseEnum>("partitioner")),
     234       66973 :     _partitioner_overridden(false),
     235       66973 :     _custom_partitioner_requested(false),
     236       66973 :     _uniform_refine_level(0),
     237      133946 :     _skip_refine_when_use_split(getParam<bool>("skip_refine_when_use_split")),
     238       66973 :     _skip_deletion_repartition_after_refine(false),
     239       66973 :     _is_nemesis(false),
     240      133946 :     _patch_size(getParam<unsigned int>("patch_size")),
     241      133946 :     _ghosting_patch_size(isParamValid("ghosting_patch_size")
     242      133946 :                              ? getParam<unsigned int>("ghosting_patch_size")
     243       66973 :                              : 5 * _patch_size),
     244      133946 :     _max_leaf_size(getParam<unsigned int>("max_leaf_size")),
     245       66973 :     _patch_update_strategy(
     246      133946 :         getParam<MooseEnum>("patch_update_strategy").getEnum<Moose::PatchUpdateType>()),
     247       66973 :     _regular_orthogonal_mesh(false),
     248      133946 :     _is_split(getParam<bool>("_is_split")),
     249       66973 :     _allow_recovery(true),
     250      133946 :     _construct_node_list_from_side_list(getParam<bool>("construct_node_list_from_side_list")),
     251      133946 :     _displace_node_list_by_side_list(getParam<bool>("displace_node_list_by_side_list")),
     252       66973 :     _need_delete(false),
     253       66973 :     _allow_remote_element_removal(true),
     254       66973 :     _need_ghost_ghosted_boundaries(true),
     255       66973 :     _is_displaced(false),
     256       66973 :     _coord_sys(
     257      133946 :         declareRestartableData<std::map<SubdomainID, Moose::CoordinateSystemType>>("coord_sys")),
     258      133946 :     _rz_coord_axis(getParam<MooseEnum>("rz_coord_axis")),
     259       66973 :     _coord_system_set(false),
     260      653067 :     _doing_p_refinement(false)
     261             : {
     262      200919 :   if (isParamValid("ghosting_patch_size") && (_patch_update_strategy != Moose::Iteration))
     263           0 :     mooseError("Ghosting patch size parameter has to be set in the mesh block "
     264             :                "only when 'iteration' patch update strategy is used.");
     265             : 
     266      200919 :   if (isParamValid("coord_block"))
     267             :   {
     268          72 :     if (isParamValid("block"))
     269           0 :       paramWarning("block",
     270             :                    "You set both 'Mesh/block' and 'Mesh/coord_block'. The value of "
     271             :                    "'Mesh/coord_block' will be used.");
     272             : 
     273          72 :     _provided_coord_blocks = getParam<std::vector<SubdomainName>>("coord_block");
     274             :   }
     275      200847 :   else if (isParamValid("block"))
     276         765 :     _provided_coord_blocks = getParam<std::vector<SubdomainName>>("block");
     277             : 
     278      200919 :   if (getParam<bool>("build_all_side_lowerd_mesh"))
     279             :     // Do not initially allow removal of remote elements
     280         223 :     allowRemoteElementRemoval(false);
     281             : 
     282       66973 :   determineUseDistributedMesh();
     283             : 
     284             : #ifdef MOOSE_KOKKOS_ENABLED
     285       50310 :   if (_app.isKokkosAvailable())
     286       50310 :     _kokkos_mesh = std::make_unique<Moose::Kokkos::Mesh>(*this);
     287             : #endif
     288       66973 : }
     289             : 
     290        2987 : MooseMesh::MooseMesh(const MooseMesh & other_mesh)
     291             :   : MooseObject(other_mesh._pars),
     292             :     Restartable(this, "Mesh"),
     293             :     PerfGraphInterface(this, "CopiedMesh"),
     294        2987 :     _built_from_other_mesh(true),
     295        2987 :     _parallel_type(other_mesh._parallel_type),
     296        2987 :     _use_distributed_mesh(other_mesh._use_distributed_mesh),
     297        2987 :     _distribution_overridden(other_mesh._distribution_overridden),
     298        2987 :     _parallel_type_overridden(other_mesh._parallel_type_overridden),
     299        2987 :     _mesh(other_mesh.getMesh().clone()),
     300        2987 :     _partitioner_name(other_mesh._partitioner_name),
     301        2987 :     _partitioner_overridden(other_mesh._partitioner_overridden),
     302        2987 :     _custom_partitioner_requested(other_mesh._custom_partitioner_requested),
     303        2987 :     _uniform_refine_level(other_mesh.uniformRefineLevel()),
     304        2987 :     _skip_refine_when_use_split(other_mesh._skip_refine_when_use_split),
     305        2987 :     _skip_deletion_repartition_after_refine(other_mesh._skip_deletion_repartition_after_refine),
     306        2987 :     _is_nemesis(other_mesh._is_nemesis),
     307        2987 :     _patch_size(other_mesh._patch_size),
     308        2987 :     _ghosting_patch_size(other_mesh._ghosting_patch_size),
     309        2987 :     _max_leaf_size(other_mesh._max_leaf_size),
     310        2987 :     _patch_update_strategy(other_mesh._patch_update_strategy),
     311        2987 :     _regular_orthogonal_mesh(false),
     312        2987 :     _is_split(other_mesh._is_split),
     313        2987 :     _lower_d_interior_blocks(other_mesh._lower_d_interior_blocks),
     314        2987 :     _lower_d_boundary_blocks(other_mesh._lower_d_boundary_blocks),
     315        2987 :     _allow_recovery(other_mesh._allow_recovery),
     316        2987 :     _construct_node_list_from_side_list(other_mesh._construct_node_list_from_side_list),
     317        2987 :     _displace_node_list_by_side_list(other_mesh._displace_node_list_by_side_list),
     318        2987 :     _need_delete(other_mesh._need_delete),
     319        2987 :     _allow_remote_element_removal(other_mesh._allow_remote_element_removal),
     320        2987 :     _need_ghost_ghosted_boundaries(other_mesh._need_ghost_ghosted_boundaries),
     321        2987 :     _coord_sys(other_mesh._coord_sys),
     322        2987 :     _rz_coord_axis(other_mesh._rz_coord_axis),
     323        2987 :     _subdomain_id_to_rz_coord_axis(other_mesh._subdomain_id_to_rz_coord_axis),
     324        2987 :     _coord_system_set(other_mesh._coord_system_set),
     325        2987 :     _provided_coord_blocks(other_mesh._provided_coord_blocks),
     326       29110 :     _doing_p_refinement(other_mesh._doing_p_refinement)
     327             : {
     328        2987 :   _bounds.resize(other_mesh._bounds.size());
     329        3296 :   for (std::size_t i = 0; i < _bounds.size(); ++i)
     330             :   {
     331         309 :     _bounds[i].resize(other_mesh._bounds[i].size());
     332         927 :     for (std::size_t j = 0; j < _bounds[i].size(); ++j)
     333         618 :       _bounds[i][j] = other_mesh._bounds[i][j];
     334             :   }
     335             : 
     336        2987 :   updateCoordTransform();
     337             : 
     338             : #ifdef MOOSE_KOKKOS_ENABLED
     339        2227 :   if (_app.isKokkosAvailable())
     340        2227 :     _kokkos_mesh = std::make_unique<Moose::Kokkos::Mesh>(*this);
     341             : #endif
     342        2987 : }
     343             : 
     344       66007 : MooseMesh::~MooseMesh()
     345             : {
     346       66007 :   freeBndNodes();
     347       66007 :   freeBndElems();
     348       66007 :   clearQuadratureNodes();
     349       66007 : }
     350             : 
     351             : void
     352      220964 : MooseMesh::freeBndNodes()
     353             : {
     354             :   // free memory
     355    12599855 :   for (auto & bnode : _bnd_nodes)
     356    12378891 :     delete bnode;
     357             : 
     358      820518 :   for (auto & it : _node_set_nodes)
     359      599554 :     it.second.clear();
     360             : 
     361      220964 :   _node_set_nodes.clear();
     362             : 
     363      820669 :   for (auto & it : _bnd_node_ids)
     364      599705 :     it.second.clear();
     365             : 
     366      220964 :   _bnd_node_ids.clear();
     367      220964 :   _bnd_node_range.reset();
     368      220964 : }
     369             : 
     370             : void
     371      220964 : MooseMesh::freeBndElems()
     372             : {
     373             :   // free memory
     374     9628304 :   for (auto & belem : _bnd_elems)
     375     9407340 :     delete belem;
     376             : 
     377      799803 :   for (auto & it : _bnd_elem_ids)
     378      578839 :     it.second.clear();
     379             : 
     380      220964 :   _bnd_elem_ids.clear();
     381      220964 :   _bnd_elem_range.reset();
     382      220964 : }
     383             : 
     384             : bool
     385      137173 : MooseMesh::prepare(const MeshBase * const mesh_to_clone)
     386             : {
     387      685865 :   TIME_SECTION("prepare", 2, "Preparing Mesh", true);
     388             : 
     389             :   parallel_object_only();
     390             : 
     391      137173 :   bool libmesh_mesh_prepared = false;
     392             : 
     393             :   mooseAssert(_mesh, "The MeshBase has not been constructed");
     394             : 
     395      137173 :   if (!dynamic_cast<DistributedMesh *>(&getMesh()) || _is_nemesis)
     396             :     // For whatever reason we do not want to allow renumbering here nor ever in the future?
     397      114237 :     getMesh().allow_renumbering(false);
     398             : 
     399      137173 :   if (mesh_to_clone)
     400             :   {
     401             :     mooseAssert(mesh_to_clone->is_prepared(),
     402             :                 "The mesh we wish to clone from must already be prepared");
     403         149 :     _mesh = mesh_to_clone->clone();
     404         149 :     _moose_mesh_prepared = false;
     405             :   }
     406      137024 :   else if (!_mesh->is_prepared())
     407             :   {
     408       18157 :     _mesh->complete_preparation();
     409       18157 :     _moose_mesh_prepared = false;
     410       18157 :     libmesh_mesh_prepared = true;
     411             :   }
     412             : 
     413      137173 :   if (_moose_mesh_prepared)
     414       68647 :     return libmesh_mesh_prepared;
     415             : 
     416             :   // Collect (local) subdomain IDs
     417       68526 :   _mesh_subdomains.clear();
     418    13333303 :   for (const auto & elem : getMesh().element_ptr_range())
     419    13333303 :     _mesh_subdomains.insert(elem->subdomain_id());
     420             : 
     421       68526 :   bool need_subdomain_name_map_sync = false;
     422             :   // add explicitly requested subdomains
     423      205846 :   if (isParamValid("add_subdomain_ids") && !isParamValid("add_subdomain_names"))
     424             :   {
     425             :     // only subdomain ids are explicitly given
     426          72 :     const auto & add_subdomain_id = getParam<std::vector<SubdomainID>>("add_subdomain_ids");
     427          36 :     _mesh_subdomains.insert(add_subdomain_id.begin(), add_subdomain_id.end());
     428             :   }
     429      205666 :   else if (isParamValid("add_subdomain_ids") && isParamValid("add_subdomain_names"))
     430             :   {
     431             :     const auto add_subdomain =
     432         392 :         getParam<SubdomainID, SubdomainName>("add_subdomain_ids", "add_subdomain_names");
     433         244 :     for (const auto & [sub_id, sub_name] : add_subdomain)
     434             :     {
     435             :       // add subdomain id
     436         146 :       _mesh_subdomains.insert(sub_id);
     437             :       // set name of the subdomain just added
     438         146 :       setSubdomainName(sub_id, sub_name);
     439             :     }
     440          98 :     need_subdomain_name_map_sync = true;
     441          98 :   }
     442      205176 :   else if (isParamValid("add_subdomain_names"))
     443             :   {
     444             :     // the user has defined add_subdomain_names, but not add_subdomain_ids
     445          24 :     const auto & add_subdomain_names = getParam<std::vector<SubdomainName>>("add_subdomain_names");
     446             : 
     447             :     // to define subdomain ids, we need the largest subdomain id defined yet.
     448          12 :     subdomain_id_type offset = 0;
     449          12 :     if (!_mesh_subdomains.empty())
     450          12 :       offset = *_mesh_subdomains.rbegin();
     451             : 
     452             :     // add all subdomains (and auto-assign ids)
     453          48 :     for (const SubdomainName & sub_name : add_subdomain_names)
     454             :     {
     455             :       // to avoid two subdomains with the same ID (notably on recover)
     456          36 :       if (getSubdomainID(sub_name) != libMesh::Elem::invalid_subdomain_id)
     457           3 :         continue;
     458          33 :       const auto sub_id = ++offset;
     459             :       // add subdomain id
     460          33 :       _mesh_subdomains.insert(sub_id);
     461             :       // set name of the subdomain just added
     462          33 :       setSubdomainName(sub_id, sub_name);
     463             :     }
     464          12 :     need_subdomain_name_map_sync = true;
     465             :   }
     466       68526 :   if (need_subdomain_name_map_sync)
     467         110 :     _mesh->sync_subdomain_name_map();
     468             : 
     469             :   // Make sure nodesets have been generated
     470       68526 :   buildNodeListFromSideList();
     471             : 
     472             :   // Collect (local) boundary IDs
     473       68526 :   const std::set<BoundaryID> & local_bids = getMesh().get_boundary_info().get_boundary_ids();
     474       68526 :   _mesh_boundary_ids.insert(local_bids.begin(), local_bids.end());
     475             : 
     476             :   const std::set<BoundaryID> & local_node_bids =
     477       68526 :       getMesh().get_boundary_info().get_node_boundary_ids();
     478       68526 :   _mesh_nodeset_ids.insert(local_node_bids.begin(), local_node_bids.end());
     479             : 
     480             :   const std::set<BoundaryID> & local_side_bids =
     481       68526 :       getMesh().get_boundary_info().get_side_boundary_ids();
     482       68526 :   _mesh_sideset_ids.insert(local_side_bids.begin(), local_side_bids.end());
     483             : 
     484             :   // Add explicitly requested sidesets/nodesets
     485             :   // This is done *after* the side boundaries (e.g. "right", ...) have been generated.
     486      137052 :   auto add_sets = [this](const bool sidesets, auto & set_ids)
     487             :   {
     488      137052 :     const std::string type = sidesets ? "sideset" : "nodeset";
     489      137052 :     const std::string id_param = "add_" + type + "_ids";
     490      137052 :     const std::string name_param = "add_" + type + "_names";
     491             : 
     492      137052 :     if (isParamValid(id_param))
     493             :     {
     494          54 :       const auto & add_ids = getParam<std::vector<BoundaryID>>(id_param);
     495          54 :       _mesh_boundary_ids.insert(add_ids.begin(), add_ids.end());
     496          54 :       set_ids.insert(add_ids.begin(), add_ids.end());
     497          54 :       if (isParamValid(name_param))
     498             :       {
     499          42 :         const auto & add_names = getParam<std::vector<BoundaryName>>(name_param);
     500             :         mooseAssert(add_names.size() == add_ids.size(),
     501             :                     "Id and name sets must be the same size when adding.");
     502         114 :         for (const auto i : index_range(add_ids))
     503          72 :           setBoundaryName(add_ids[i], add_names[i]);
     504             :       }
     505             :     }
     506      136998 :     else if (isParamValid(name_param))
     507             :     {
     508             :       // the user has defined names, but not ids
     509          12 :       const auto & add_names = getParam<std::vector<BoundaryName>>(name_param);
     510             : 
     511          12 :       auto & mesh_ids = sidesets ? _mesh_sideset_ids : _mesh_nodeset_ids;
     512             : 
     513             :       // to define ids, we need the largest id defined yet.
     514          12 :       boundary_id_type offset = 0;
     515          12 :       if (!mesh_ids.empty())
     516          12 :         offset = *mesh_ids.rbegin();
     517          12 :       if (!_mesh_boundary_ids.empty())
     518          12 :         offset = std::max(offset, *_mesh_boundary_ids.rbegin());
     519             : 
     520             :       // add all sidesets/nodesets (and auto-assign ids)
     521          24 :       for (const auto & name : add_names)
     522             :       {
     523             :         // to avoid two sets with the same ID (notably on recover)
     524          12 :         if (getBoundaryID(name) != Moose::INVALID_BOUNDARY_ID)
     525           1 :           continue;
     526          11 :         const auto id = ++offset;
     527             :         // add sideset id
     528          11 :         _mesh_boundary_ids.insert(id);
     529          11 :         set_ids.insert(id);
     530             :         // set name of the sideset just added
     531          11 :         setBoundaryName(id, name);
     532             :       }
     533             :     }
     534      137052 :   };
     535             : 
     536       68526 :   add_sets(true, _mesh_sideset_ids);
     537       68526 :   add_sets(false, _mesh_nodeset_ids);
     538             : 
     539             :   // Communicate subdomain and boundary IDs if this is a parallel mesh
     540       68526 :   if (!getMesh().is_serial())
     541             :   {
     542        8882 :     _communicator.set_union(_mesh_subdomains);
     543        8882 :     _communicator.set_union(_mesh_boundary_ids);
     544        8882 :     _communicator.set_union(_mesh_nodeset_ids);
     545        8882 :     _communicator.set_union(_mesh_sideset_ids);
     546             :   }
     547             : 
     548       68526 :   if (!_built_from_other_mesh)
     549             :   {
     550       65713 :     if (!_coord_system_set)
     551      196911 :       setCoordSystem(_provided_coord_blocks, getParam<MultiMooseEnum>("coord_type"));
     552         228 :     else if (_pars.isParamSetByUser("coord_type"))
     553           0 :       mooseError(
     554             :           "Trying to set coordinate system type information based on the user input file, but "
     555             :           "the coordinate system type information has already been set programmatically! "
     556             :           "Either remove your coordinate system type information from the input file, or contact "
     557             :           "your application developer");
     558             :   }
     559             : 
     560             :   // Set general axisymmetric axes if provided
     561      274155 :   if (isParamValid("rz_coord_blocks") && isParamValid("rz_coord_origins") &&
     562       68577 :       isParamValid("rz_coord_directions"))
     563             :   {
     564          34 :     const auto rz_coord_blocks = getParam<std::vector<SubdomainName>>("rz_coord_blocks");
     565          34 :     const auto rz_coord_origins = getParam<std::vector<Point>>("rz_coord_origins");
     566          34 :     const auto rz_coord_directions = getParam<std::vector<RealVectorValue>>("rz_coord_directions");
     567          34 :     if (rz_coord_origins.size() == rz_coord_blocks.size() &&
     568          17 :         rz_coord_directions.size() == rz_coord_blocks.size())
     569             :     {
     570          17 :       std::vector<std::pair<Point, RealVectorValue>> rz_coord_axes;
     571          58 :       for (unsigned int i = 0; i < rz_coord_origins.size(); ++i)
     572          41 :         rz_coord_axes.push_back(std::make_pair(rz_coord_origins[i], rz_coord_directions[i]));
     573             : 
     574          17 :       setGeneralAxisymmetricCoordAxes(rz_coord_blocks, rz_coord_axes);
     575             : 
     576          51 :       if (isParamSetByUser("rz_coord_axis"))
     577           0 :         mooseError("The parameter 'rz_coord_axis' may not be provided if 'rz_coord_blocks', "
     578             :                    "'rz_coord_origins', and 'rz_coord_directions' are provided.");
     579          17 :     }
     580             :     else
     581           0 :       mooseError("The parameters 'rz_coord_blocks', 'rz_coord_origins', and "
     582             :                  "'rz_coord_directions' must all have the same size.");
     583          17 :   }
     584      479563 :   else if (isParamValid("rz_coord_blocks") || isParamValid("rz_coord_origins") ||
     585      274036 :            isParamValid("rz_coord_directions"))
     586           0 :     mooseError("If any of the parameters 'rz_coord_blocks', 'rz_coord_origins', and "
     587             :                "'rz_coord_directions' are provided, then all must be provided.");
     588             : 
     589       68526 :   detectOrthogonalDimRanges();
     590             : 
     591       68526 :   update();
     592             : 
     593             :   // Check if there is subdomain name duplication for the same subdomain ID
     594       68526 :   checkDuplicateSubdomainNames();
     595             : 
     596       68523 :   _moose_mesh_prepared = true;
     597             : 
     598       68523 :   return libmesh_mesh_prepared;
     599      137170 : }
     600             : 
     601             : bool
     602      154957 : MooseMesh::possiblyRebuildNodeToElemMap()
     603             : {
     604             :   // *Rebuild* the node to element map. I emphasize rebuild because if it has not been built
     605             :   // previously we won't do anything
     606      154957 :   if (!_node_to_elem_map_built)
     607             :   {
     608             :     mooseAssert(_node_to_elem_map.empty(), "If it hasn't been built, it better well be empty");
     609      147158 :     return false;
     610             :   }
     611             : 
     612        7799 :   _node_to_elem_map.clear();
     613        7799 :   _node_to_elem_map_built = false;
     614        7799 :   internalNodeToElemMap();
     615        7799 :   return true;
     616             : }
     617             : 
     618             : void
     619      154957 : MooseMesh::update()
     620             : {
     621      774785 :   TIME_SECTION("update", 3, "Updating Mesh", true);
     622             : 
     623             :   // Rebuild the boundary conditions
     624      154957 :   buildNodeListFromSideList();
     625             : 
     626      154957 :   buildNodeList();
     627      154957 :   buildBndElemList();
     628      154957 :   cacheInfo();
     629      154957 :   buildElemIDInfo();
     630             : 
     631             :   // this will make moose mesh aware of p-refinement added by mesh generators including
     632             :   // a file mesh generator loading a restart checkpoint file
     633      154957 :   _max_p_level = 0;
     634      154957 :   _max_h_level = 0;
     635    27753158 :   for (const auto & elem : getMesh().active_local_element_ptr_range())
     636             :   {
     637    27598201 :     if (elem->p_level() > _max_p_level)
     638         658 :       _max_p_level = elem->p_level();
     639    27598201 :     if (elem->level() > _max_h_level)
     640       25854 :       _max_h_level = elem->level();
     641      154957 :   }
     642      154957 :   comm().max(_max_p_level);
     643      154957 :   comm().max(_max_h_level);
     644             : 
     645             :   // the flag might have been set by calling doingPRefinement(true)
     646      154957 :   _doing_p_refinement = _doing_p_refinement || (_max_p_level > 0);
     647             : 
     648      154957 :   computeMaxPerElemAndSide();
     649             : 
     650             : #ifdef MOOSE_KOKKOS_ENABLED
     651      128666 :   if (_app.getExecutioner() && _app.feProblem().initialized() &&
     652       12623 :       _app.feProblem().hasKokkosObjects())
     653           0 :     _kokkos_mesh->update();
     654             : #endif
     655             : 
     656      154957 :   _finite_volume_info_dirty = true;
     657             : 
     658      154957 :   possiblyRebuildNodeToElemMap();
     659      154957 : }
     660             : 
     661             : void
     662         205 : MooseMesh::buildLowerDMesh()
     663             : {
     664         205 :   auto & mesh = getMesh();
     665             : 
     666         205 :   if (!mesh.is_serial())
     667           0 :     mooseError(
     668             :         "Hybrid finite element method must use replicated mesh.\nCurrently lower-dimensional mesh "
     669             :         "does not support mesh re-partitioning and a debug assertion being hit related with "
     670             :         "neighbors of lower-dimensional element, with distributed mesh.");
     671             : 
     672             :   // Lower-D element build requires neighboring element information
     673         205 :   if (!mesh.is_prepared())
     674         194 :     mesh.find_neighbors();
     675             : 
     676             :   // maximum number of sides of all elements
     677         205 :   unsigned int max_n_sides = 0;
     678             : 
     679             :   // remove existing lower-d element first
     680         205 :   std::set<Elem *> deleteable_elems;
     681        4347 :   for (auto & elem : mesh.element_ptr_range())
     682        4142 :     if (_lower_d_interior_blocks.count(elem->subdomain_id()) ||
     683        2071 :         _lower_d_boundary_blocks.count(elem->subdomain_id()))
     684           0 :       deleteable_elems.insert(elem);
     685        2071 :     else if (elem->n_sides() > max_n_sides)
     686         410 :       max_n_sides = elem->n_sides();
     687             : 
     688         205 :   for (auto & elem : deleteable_elems)
     689           0 :     mesh.delete_elem(elem);
     690         205 :   for (const auto & id : _lower_d_interior_blocks)
     691           0 :     _mesh_subdomains.erase(id);
     692         205 :   for (const auto & id : _lower_d_boundary_blocks)
     693           0 :     _mesh_subdomains.erase(id);
     694         205 :   _lower_d_interior_blocks.clear();
     695         205 :   _lower_d_boundary_blocks.clear();
     696             : 
     697         205 :   mesh.comm().max(max_n_sides);
     698             : 
     699         205 :   deleteable_elems.clear();
     700             : 
     701             :   // get all side types
     702         205 :   std::set<int> interior_side_types;
     703         205 :   std::set<int> boundary_side_types;
     704        4347 :   for (const auto & elem : mesh.active_element_ptr_range())
     705       11173 :     for (const auto side : elem->side_index_range())
     706             :     {
     707        9102 :       Elem * neig = elem->neighbor_ptr(side);
     708        9102 :       std::unique_ptr<Elem> side_elem(elem->build_side_ptr(side));
     709        9102 :       if (neig)
     710        5956 :         interior_side_types.insert(side_elem->type());
     711             :       else
     712        3146 :         boundary_side_types.insert(side_elem->type());
     713        9307 :     }
     714         205 :   mesh.comm().set_union(interior_side_types);
     715         205 :   mesh.comm().set_union(boundary_side_types);
     716             : 
     717             :   // assign block ids for different side types
     718         205 :   std::map<ElemType, SubdomainID> interior_block_ids;
     719         205 :   std::map<ElemType, SubdomainID> boundary_block_ids;
     720             :   // we assume this id is not used by the mesh
     721         205 :   auto id = libMesh::Elem::invalid_subdomain_id - 2;
     722         424 :   for (const auto & tpid : interior_side_types)
     723             :   {
     724         219 :     const auto type = ElemType(tpid);
     725         219 :     mesh.subdomain_name(id) = "INTERNAL_SIDE_LOWERD_SUBDOMAIN_" + Utility::enum_to_string(type);
     726         219 :     interior_block_ids[type] = id;
     727         219 :     _lower_d_interior_blocks.insert(id);
     728         219 :     if (_mesh_subdomains.count(id) > 0)
     729           0 :       mooseError("Trying to add a mesh block with id ", id, " that has existed in the mesh");
     730         219 :     _mesh_subdomains.insert(id);
     731         219 :     --id;
     732             :   }
     733         424 :   for (const auto & tpid : boundary_side_types)
     734             :   {
     735         219 :     const auto type = ElemType(tpid);
     736         219 :     mesh.subdomain_name(id) = "BOUNDARY_SIDE_LOWERD_SUBDOMAIN_" + Utility::enum_to_string(type);
     737         219 :     boundary_block_ids[type] = id;
     738         219 :     _lower_d_boundary_blocks.insert(id);
     739         219 :     if (_mesh_subdomains.count(id) > 0)
     740           0 :       mooseError("Trying to add a mesh block with id ", id, " that has existed in the mesh");
     741         219 :     _mesh_subdomains.insert(id);
     742         219 :     --id;
     743             :   }
     744             : 
     745         205 :   dof_id_type max_elem_id = mesh.max_elem_id();
     746         205 :   unique_id_type max_unique_id = mesh.parallel_max_unique_id();
     747             : 
     748         205 :   std::vector<Elem *> side_elems;
     749         205 :   _higher_d_elem_side_to_lower_d_elem.clear();
     750        4347 :   for (const auto & elem : mesh.active_element_ptr_range())
     751             :   {
     752             :     // skip existing lower-d elements
     753        2071 :     if (elem->interior_parent())
     754           0 :       continue;
     755             : 
     756       11173 :     for (const auto side : elem->side_index_range())
     757             :     {
     758        9102 :       Elem * neig = elem->neighbor_ptr(side);
     759             : 
     760        9102 :       bool build_side = false;
     761        9102 :       if (!neig)
     762        3146 :         build_side = true;
     763             :       else
     764             :       {
     765             :         mooseAssert(!neig->is_remote(), "We error if the mesh is not serial");
     766        5956 :         if (!neig->active())
     767           0 :           build_side = true;
     768        5956 :         else if (neig->level() == elem->level() && elem->id() < neig->id())
     769        2978 :           build_side = true;
     770             :       }
     771             : 
     772        9102 :       if (build_side)
     773             :       {
     774        6124 :         std::unique_ptr<Elem> side_elem(elem->build_side_ptr(side));
     775             : 
     776             :         // The side will be added with the same processor id as the parent.
     777        6124 :         side_elem->processor_id() = elem->processor_id();
     778             : 
     779             :         // Add subdomain ID
     780        6124 :         if (neig)
     781        2978 :           side_elem->subdomain_id() = interior_block_ids.at(side_elem->type());
     782             :         else
     783        3146 :           side_elem->subdomain_id() = boundary_block_ids.at(side_elem->type());
     784             : 
     785             :         // set ids consistently across processors (these ids will be temporary)
     786        6124 :         side_elem->set_id(max_elem_id + elem->id() * max_n_sides + side);
     787        6124 :         side_elem->set_unique_id(max_unique_id + elem->id() * max_n_sides + side);
     788             : 
     789             :         // Also assign the side's interior parent, so it is always
     790             :         // easy to figure out the Elem we came from.
     791             :         // Note: the interior parent could be a ghost element.
     792        6124 :         side_elem->set_interior_parent(elem);
     793             : 
     794        6124 :         side_elems.push_back(side_elem.release());
     795             : 
     796             :         // add link between higher d element to lower d element
     797        6124 :         auto pair = std::make_pair(elem, side);
     798        6124 :         auto link = std::make_pair(pair, side_elems.back());
     799        6124 :         auto ilink = std::make_pair(side_elems.back(), side);
     800        6124 :         _lower_d_elem_to_higher_d_elem_side.insert(ilink);
     801        6124 :         _higher_d_elem_side_to_lower_d_elem.insert(link);
     802        6124 :       }
     803             :     }
     804         205 :   }
     805             : 
     806             :   // finally, add the lower-dimensional element to the mesh
     807             :   // Note: lower-d interior element will exist on a processor if its associated interior
     808             :   //       parent exists on a processor whether or not being a ghost. Lower-d elements will
     809             :   //       get its interior parent's processor id.
     810        6329 :   for (auto & elem : side_elems)
     811        6124 :     mesh.add_elem(elem);
     812             : 
     813             :   // we do all the stuff in prepare_for_use such as renumber_nodes_and_elements(),
     814             :   // update_parallel_id_counts(), cache_elem_dims(), etc. except partitioning here.
     815         205 :   const bool skip_partitioning_old = mesh.skip_partitioning();
     816         205 :   mesh.skip_partitioning(true);
     817             :   // Finding neighbors is ambiguous for lower-dimensional elements on interior faces
     818         205 :   mesh.allow_find_neighbors(false);
     819         205 :   mesh.prepare_for_use();
     820         205 :   mesh.skip_partitioning(skip_partitioning_old);
     821         205 : }
     822             : 
     823             : const Node &
     824           0 : MooseMesh::node(const dof_id_type i) const
     825             : {
     826           0 :   mooseDeprecated("MooseMesh::node() is deprecated, please use MooseMesh::nodeRef() instead");
     827           0 :   return nodeRef(i);
     828             : }
     829             : 
     830             : Node &
     831           0 : MooseMesh::node(const dof_id_type i)
     832             : {
     833           0 :   mooseDeprecated("MooseMesh::node() is deprecated, please use MooseMesh::nodeRef() instead");
     834           0 :   return nodeRef(i);
     835             : }
     836             : 
     837             : const Node &
     838    42688962 : MooseMesh::nodeRef(const dof_id_type i) const
     839             : {
     840    42688962 :   const auto node_ptr = queryNodePtr(i);
     841             :   mooseAssert(node_ptr, "Missing node");
     842    42688962 :   return *node_ptr;
     843             : }
     844             : 
     845             : Node &
     846    24016230 : MooseMesh::nodeRef(const dof_id_type i)
     847             : {
     848    24016230 :   return const_cast<Node &>(const_cast<const MooseMesh *>(this)->nodeRef(i));
     849             : }
     850             : 
     851             : const Node *
     852           0 : MooseMesh::nodePtr(const dof_id_type i) const
     853             : {
     854           0 :   return &nodeRef(i);
     855             : }
     856             : 
     857             : Node *
     858        2096 : MooseMesh::nodePtr(const dof_id_type i)
     859             : {
     860        2096 :   return &nodeRef(i);
     861             : }
     862             : 
     863             : const Node *
     864    42691706 : MooseMesh::queryNodePtr(const dof_id_type i) const
     865             : {
     866    42691706 :   if (i > getMesh().max_node_id())
     867             :   {
     868      196773 :     auto it = _quadrature_nodes.find(i);
     869      196773 :     if (it == _quadrature_nodes.end())
     870           0 :       return nullptr;
     871      196773 :     auto & node_ptr = it->second;
     872             :     mooseAssert(node_ptr, "Uninitialized quadrature node");
     873      196773 :     return node_ptr;
     874             :   }
     875             : 
     876    42494933 :   return getMesh().query_node_ptr(i);
     877             : }
     878             : 
     879             : Node *
     880        2744 : MooseMesh::queryNodePtr(const dof_id_type i)
     881             : {
     882        2744 :   return const_cast<Node *>(const_cast<const MooseMesh *>(this)->queryNodePtr(i));
     883             : }
     884             : 
     885             : void
     886       83796 : MooseMesh::meshChanged()
     887             : {
     888      418980 :   TIME_SECTION("meshChanged", 3, "Updating Because Mesh Changed");
     889             : 
     890       83796 :   update();
     891             : 
     892             :   // Delete all of the cached ranges
     893       83796 :   _active_node_range.reset();
     894       83796 :   _active_semilocal_node_range.reset();
     895       83796 :   _local_node_range.reset();
     896       83796 :   _bnd_node_range.reset();
     897       83796 :   _bnd_elem_range.reset();
     898             : 
     899             :   // Rebuild the ranges
     900       83796 :   getActiveLocalElementRange();
     901       83796 :   getActiveNodeRange();
     902       83796 :   getLocalNodeRange();
     903       83796 :   getBoundaryNodeRange();
     904       83796 :   getBoundaryElementRange();
     905             : 
     906             :   // Call the callback function onMeshChanged
     907       83796 :   onMeshChanged();
     908       83796 : }
     909             : 
     910             : void
     911       83796 : MooseMesh::onMeshChanged()
     912             : {
     913       83796 : }
     914             : 
     915             : void
     916         208 : MooseMesh::cacheChangedLists()
     917             : {
     918        1040 :   TIME_SECTION("cacheChangedLists", 5, "Caching Changed Lists");
     919             : 
     920         208 :   ConstElemRange elem_range(getMesh().local_elements_begin(), getMesh().local_elements_end(), 1);
     921         208 :   CacheChangedListsThread cclt(*this);
     922         208 :   Threads::parallel_reduce(elem_range, cclt);
     923             : 
     924         208 :   _coarsened_element_children.clear();
     925             : 
     926         416 :   _refined_elements = std::make_unique<ConstElemPointerRange>(cclt._refined_elements.begin(),
     927         416 :                                                               cclt._refined_elements.end());
     928         416 :   _coarsened_elements = std::make_unique<ConstElemPointerRange>(cclt._coarsened_elements.begin(),
     929         416 :                                                                 cclt._coarsened_elements.end());
     930         208 :   _coarsened_element_children = cclt._coarsened_element_children;
     931         208 : }
     932             : 
     933             : ConstElemPointerRange *
     934         208 : MooseMesh::refinedElementRange() const
     935             : {
     936         208 :   return _refined_elements.get();
     937             : }
     938             : 
     939             : ConstElemPointerRange *
     940         208 : MooseMesh::coarsenedElementRange() const
     941             : {
     942         208 :   return _coarsened_elements.get();
     943             : }
     944             : 
     945             : const std::vector<const Elem *> &
     946        2468 : MooseMesh::coarsenedElementChildren(const Elem * elem) const
     947             : {
     948        2468 :   auto elem_to_child_pair = _coarsened_element_children.find(elem);
     949             :   mooseAssert(elem_to_child_pair != _coarsened_element_children.end(), "Missing element in map");
     950        4936 :   return elem_to_child_pair->second;
     951             : }
     952             : 
     953             : void
     954       71641 : MooseMesh::updateActiveSemiLocalNodeRange(std::set<dof_id_type> & ghosted_elems)
     955             : {
     956      358205 :   TIME_SECTION("updateActiveSemiLocalNodeRange", 5, "Updating ActiveSemiLocalNode Range");
     957             : 
     958       71641 :   _semilocal_node_list.clear();
     959             : 
     960             :   // First add the nodes connected to local elems
     961       71641 :   const ConstElemRange * active_local_elems = getActiveLocalElementRange();
     962    13066191 :   for (const auto & elem : *active_local_elems)
     963             :   {
     964    82304557 :     for (unsigned int n = 0; n < elem->n_nodes(); ++n)
     965             :     {
     966             :       // Since elem is const here but we require a non-const Node * to
     967             :       // store in the _semilocal_node_list (otherwise things like
     968             :       // UpdateDisplacedMeshThread don't work), we are using a
     969             :       // const_cast. A more long-term fix would be to have
     970             :       // getActiveLocalElementRange return a non-const ElemRange.
     971    69310007 :       Node * node = const_cast<Node *>(elem->node_ptr(n));
     972             : 
     973    69310007 :       _semilocal_node_list.insert(node);
     974             :     }
     975             :   }
     976             : 
     977             :   // Now add the nodes connected to ghosted_elems
     978      116852 :   for (const auto & ghost_elem_id : ghosted_elems)
     979             :   {
     980       45211 :     Elem * elem = getMesh().elem_ptr(ghost_elem_id);
     981      250228 :     for (unsigned int n = 0; n < elem->n_nodes(); n++)
     982             :     {
     983      205017 :       Node * node = elem->node_ptr(n);
     984             : 
     985      205017 :       _semilocal_node_list.insert(node);
     986             :     }
     987             :   }
     988             : 
     989             :   // Now create the actual range
     990      143282 :   _active_semilocal_node_range = std::make_unique<SemiLocalNodeRange>(_semilocal_node_list.begin(),
     991      143282 :                                                                       _semilocal_node_list.end());
     992       71641 : }
     993             : 
     994             : bool
     995       26305 : MooseMesh::isSemiLocal(Node * const node) const
     996             : {
     997       26305 :   return _semilocal_node_list.find(node) != _semilocal_node_list.end();
     998             : }
     999             : 
    1000             : /**
    1001             :  * Helper class for sorting Boundary Nodes so that we always get the same
    1002             :  * order of application for boundary conditions.
    1003             :  */
    1004             : class BndNodeCompare
    1005             : {
    1006             : public:
    1007      154957 :   BndNodeCompare() {}
    1008             : 
    1009   121258006 :   bool operator()(const BndNode * const & lhs, const BndNode * const & rhs)
    1010             :   {
    1011   121258006 :     if (lhs->_bnd_id < rhs->_bnd_id)
    1012    22565546 :       return true;
    1013             : 
    1014    98692460 :     if (lhs->_bnd_id > rhs->_bnd_id)
    1015    10253667 :       return false;
    1016             : 
    1017    88438793 :     if (lhs->_node->id() < rhs->_node->id())
    1018    57157697 :       return true;
    1019             : 
    1020    31281096 :     if (lhs->_node->id() > rhs->_node->id())
    1021    31281096 :       return false;
    1022             : 
    1023           0 :     return false;
    1024             :   }
    1025             : };
    1026             : 
    1027             : void
    1028      154957 : MooseMesh::buildNodeList()
    1029             : {
    1030      774785 :   TIME_SECTION("buildNodeList", 5, "Building Node List");
    1031             : 
    1032      154957 :   freeBndNodes();
    1033             : 
    1034      154957 :   auto bc_tuples = getMesh().get_boundary_info().build_node_list();
    1035             : 
    1036      154957 :   int n = bc_tuples.size();
    1037      154957 :   _bnd_nodes.clear();
    1038      154957 :   _bnd_nodes.reserve(n);
    1039    12661381 :   for (const auto & t : bc_tuples)
    1040             :   {
    1041    12506424 :     auto node_id = std::get<0>(t);
    1042    12506424 :     auto bc_id = std::get<1>(t);
    1043             : 
    1044    12506424 :     _bnd_nodes.push_back(new BndNode(getMesh().node_ptr(node_id), bc_id));
    1045    12506424 :     _node_set_nodes[bc_id].push_back(node_id);
    1046    12506424 :     _bnd_node_ids[bc_id].insert(node_id);
    1047             :   }
    1048             : 
    1049      154957 :   _bnd_nodes.reserve(_bnd_nodes.size() + _extra_bnd_nodes.size());
    1050      155011 :   for (unsigned int i = 0; i < _extra_bnd_nodes.size(); i++)
    1051             :   {
    1052          54 :     BndNode * bnode = new BndNode(_extra_bnd_nodes[i]._node, _extra_bnd_nodes[i]._bnd_id);
    1053          54 :     _bnd_nodes.push_back(bnode);
    1054          54 :     _bnd_node_ids[std::get<1>(bc_tuples[i])].insert(_extra_bnd_nodes[i]._node->id());
    1055             :   }
    1056             : 
    1057             :   // This sort is here so that boundary conditions are always applied in the same order
    1058      154957 :   std::sort(_bnd_nodes.begin(), _bnd_nodes.end(), BndNodeCompare());
    1059      154957 : }
    1060             : 
    1061             : void
    1062      154957 : MooseMesh::computeMaxPerElemAndSide()
    1063             : {
    1064      154957 :   auto & mesh = getMesh();
    1065             : 
    1066      154957 :   _max_sides_per_elem = 0;
    1067      154957 :   _max_nodes_per_elem = 0;
    1068      154957 :   _max_nodes_per_side = 0;
    1069             : 
    1070    59545257 :   for (auto & elem : as_range(mesh.local_elements_begin(), mesh.local_elements_end()))
    1071             :   {
    1072    29695150 :     _max_sides_per_elem = std::max(_max_sides_per_elem, elem->n_sides());
    1073    29695150 :     _max_nodes_per_elem = std::max(_max_nodes_per_elem, elem->n_nodes());
    1074             : 
    1075   162442146 :     for (unsigned int side = 0; side < elem->n_sides(); ++side)
    1076   132746996 :       _max_nodes_per_side = std::max(_max_nodes_per_side, elem->side_ptr(side)->n_nodes());
    1077      154957 :   }
    1078             : 
    1079      154957 :   mesh.comm().max(_max_sides_per_elem);
    1080      154957 :   mesh.comm().max(_max_nodes_per_elem);
    1081      154957 :   mesh.comm().max(_max_nodes_per_side);
    1082      154957 : }
    1083             : 
    1084             : void
    1085      154957 : MooseMesh::buildElemIDInfo()
    1086             : {
    1087      154957 :   unsigned int n = getMesh().n_elem_integers() + 1;
    1088             : 
    1089      154957 :   _block_id_mapping.clear();
    1090      154957 :   _max_ids.clear();
    1091      154957 :   _min_ids.clear();
    1092      154957 :   _id_identical_flag.clear();
    1093             : 
    1094      154957 :   _block_id_mapping.resize(n);
    1095      154957 :   _max_ids.resize(n, std::numeric_limits<dof_id_type>::min());
    1096      154957 :   _min_ids.resize(n, std::numeric_limits<dof_id_type>::max());
    1097      309914 :   _id_identical_flag.resize(n, std::vector<bool>(n, true));
    1098    27753158 :   for (const auto & elem : getMesh().active_local_element_ptr_range())
    1099    59317793 :     for (unsigned int i = 0; i < n; ++i)
    1100             :     {
    1101    31719592 :       auto id = (i == n - 1 ? elem->subdomain_id() : elem->get_extra_integer(i));
    1102    31719592 :       _block_id_mapping[i][elem->subdomain_id()].insert(id);
    1103    31719592 :       if (id > _max_ids[i])
    1104      118545 :         _max_ids[i] = id;
    1105    31719592 :       if (id < _min_ids[i])
    1106      159768 :         _min_ids[i] = id;
    1107    76369894 :       for (unsigned int j = 0; j < n; ++j)
    1108             :       {
    1109    44650302 :         auto idj = (j == n - 1 ? elem->subdomain_id() : elem->get_extra_integer(j));
    1110    44650302 :         if (i != j && _id_identical_flag[i][j] && id != idj)
    1111        6742 :           _id_identical_flag[i][j] = false;
    1112             :       }
    1113      154957 :     }
    1114             : 
    1115      312351 :   for (unsigned int i = 0; i < n; ++i)
    1116             :   {
    1117      382969 :     for (auto & blk : meshSubdomains())
    1118      225575 :       comm().set_union(_block_id_mapping[i][blk]);
    1119      157394 :     comm().min(_id_identical_flag[i]);
    1120             :   }
    1121      154957 :   comm().max(_max_ids);
    1122      154957 :   comm().min(_min_ids);
    1123      154957 : }
    1124             : 
    1125             : std::unordered_map<dof_id_type, std::set<dof_id_type>>
    1126          11 : MooseMesh::getElemIDMapping(const std::string & from_id_name, const std::string & to_id_name) const
    1127             : {
    1128          11 :   auto & mesh_base = getMesh();
    1129             : 
    1130          11 :   if (!mesh_base.has_elem_integer(from_id_name))
    1131           0 :     mooseError("Mesh does not have the element integer name '", from_id_name, "'");
    1132          11 :   if (!mesh_base.has_elem_integer(to_id_name))
    1133           0 :     mooseError("Mesh does not have the element integer name '", to_id_name, "'");
    1134             : 
    1135          11 :   const auto id1 = mesh_base.get_elem_integer_index(from_id_name);
    1136          11 :   const auto id2 = mesh_base.get_elem_integer_index(to_id_name);
    1137             : 
    1138          11 :   std::unordered_map<dof_id_type, std::set<dof_id_type>> id_map;
    1139          33 :   for (const auto id : getAllElemIDs(id1))
    1140          33 :     id_map[id] = std::set<dof_id_type>();
    1141             : 
    1142         811 :   for (const auto & elem : mesh_base.active_local_element_ptr_range())
    1143         811 :     id_map[elem->get_extra_integer(id1)].insert(elem->get_extra_integer(id2));
    1144             : 
    1145          33 :   for (auto & [id, ids] : id_map)
    1146             :   {
    1147          22 :     libmesh_ignore(id); // avoid overzealous gcc 9.4 unused var warning
    1148          22 :     comm().set_union(ids);
    1149             :   }
    1150             : 
    1151          11 :   return id_map;
    1152           0 : }
    1153             : 
    1154             : std::set<dof_id_type>
    1155          50 : MooseMesh::getAllElemIDs(unsigned int elem_id_index) const
    1156             : {
    1157          50 :   std::set<dof_id_type> unique_ids;
    1158         139 :   for (auto & pair : _block_id_mapping[elem_id_index])
    1159         319 :     for (auto & id : pair.second)
    1160         230 :       unique_ids.insert(id);
    1161          50 :   return unique_ids;
    1162           0 : }
    1163             : 
    1164             : std::set<dof_id_type>
    1165         152 : MooseMesh::getElemIDsOnBlocks(unsigned int elem_id_index, const std::set<SubdomainID> & blks) const
    1166             : {
    1167         152 :   std::set<dof_id_type> unique_ids;
    1168         379 :   for (auto & blk : blks)
    1169             :   {
    1170         227 :     auto it = _block_id_mapping[elem_id_index].find(blk);
    1171         227 :     if (it == _block_id_mapping[elem_id_index].end())
    1172           0 :       mooseError("Block ", blk, " is not available on the mesh");
    1173             : 
    1174         532 :     for (auto & mid : it->second)
    1175         305 :       unique_ids.insert(mid);
    1176             :   }
    1177         152 :   return unique_ids;
    1178           0 : }
    1179             : 
    1180             : void
    1181      154957 : MooseMesh::buildBndElemList()
    1182             : {
    1183      774785 :   TIME_SECTION("buildBndElemList", 5, "Building Boundary Elements List");
    1184             : 
    1185      154957 :   freeBndElems();
    1186             : 
    1187      154957 :   auto bc_tuples = getMesh().get_boundary_info().build_active_side_list();
    1188             : 
    1189      154957 :   int n = bc_tuples.size();
    1190      154957 :   _bnd_elems.clear();
    1191      154957 :   _bnd_elems.reserve(n);
    1192     9676135 :   for (const auto & t : bc_tuples)
    1193             :   {
    1194     9521178 :     auto elem_id = std::get<0>(t);
    1195     9521178 :     auto side_id = std::get<1>(t);
    1196     9521178 :     auto bc_id = std::get<2>(t);
    1197             : 
    1198     9521178 :     _bnd_elems.push_back(new BndElement(getMesh().elem_ptr(elem_id), side_id, bc_id));
    1199     9521178 :     _bnd_elem_ids[bc_id].insert(elem_id);
    1200             :   }
    1201      154957 : }
    1202             : 
    1203             : std::unordered_map<dof_id_type, std::vector<dof_id_type>> &
    1204      997114 : MooseMesh::internalNodeToElemMap()
    1205             : {
    1206      997114 :   if (!_node_to_elem_map_built) // Guard the creation with a double checked lock
    1207             :   {
    1208       11867 :     Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
    1209             : 
    1210       11867 :     if (!_node_to_elem_map_built)
    1211             :     {
    1212             :       // This is allowing the timing to be run even with threads
    1213             :       // This is safe because all threads will be waiting on this section when it runs
    1214             :       // NOTE: Do not copy this construction to other places without thinking REALLY hard about it
    1215             :       // The PerfGraph is NOT threadsafe and will cause all kinds of havok if care isn't taken
    1216       11867 :       auto in_threads = Threads::in_threads;
    1217       11867 :       Threads::in_threads = false;
    1218       59335 :       TIME_SECTION("nodeToElemMap", 5, "Building Node To Elem Map");
    1219       11867 :       Threads::in_threads = in_threads;
    1220             : 
    1221             :       mooseAssert(_node_to_elem_map.empty(), "Expected empty map before building");
    1222     2984309 :       for (const auto & elem : getMesh().active_element_ptr_range())
    1223    18205478 :         for (unsigned int n = 0; n < elem->n_nodes(); n++)
    1224    15244903 :           _node_to_elem_map[elem->node_id(n)].push_back(elem->id());
    1225             : 
    1226       11867 :       _node_to_elem_map_built = true; // MUST be set at the end for double-checked locking to work!
    1227       11867 :     }
    1228       11867 :   }
    1229      997114 :   return _node_to_elem_map;
    1230             : }
    1231             : 
    1232             : const std::unordered_map<dof_id_type, std::vector<dof_id_type>> &
    1233      983958 : MooseMesh::nodeToElemMap()
    1234             : {
    1235      983958 :   return internalNodeToElemMap();
    1236             : }
    1237             : 
    1238             : const ConstElemRange *
    1239    10374146 : MooseMesh::getActiveLocalElementRange()
    1240             : {
    1241    10374146 :   return &getMesh().active_local_element_stored_range();
    1242             : }
    1243             : 
    1244             : NodeRange *
    1245       83860 : MooseMesh::getActiveNodeRange()
    1246             : {
    1247       83860 :   if (!_active_node_range)
    1248             :   {
    1249      251388 :     TIME_SECTION("getActiveNodeRange", 5);
    1250             : 
    1251             :     _active_node_range =
    1252       83796 :         std::make_unique<NodeRange>(getMesh().active_nodes_begin(), getMesh().active_nodes_end());
    1253       83796 :   }
    1254             : 
    1255       83860 :   return _active_node_range.get();
    1256             : }
    1257             : 
    1258             : SemiLocalNodeRange *
    1259           0 : MooseMesh::getActiveSemiLocalNodeRange() const
    1260             : {
    1261             :   mooseAssert(_active_semilocal_node_range,
    1262             :               "_active_semilocal_node_range has not been created yet!");
    1263             : 
    1264           0 :   return _active_semilocal_node_range.get();
    1265             : }
    1266             : 
    1267             : ConstNodeRange *
    1268      318211 : MooseMesh::getLocalNodeRange()
    1269             : {
    1270      318211 :   if (!_local_node_range)
    1271             :   {
    1272      251388 :     TIME_SECTION("getLocalNodeRange", 5);
    1273             : 
    1274      167592 :     _local_node_range = std::make_unique<ConstNodeRange>(getMesh().local_nodes_begin(),
    1275      251388 :                                                          getMesh().local_nodes_end());
    1276       83796 :   }
    1277             : 
    1278      318211 :   return _local_node_range.get();
    1279             : }
    1280             : 
    1281             : ConstBndNodeRange *
    1282     3672709 : MooseMesh::getBoundaryNodeRange()
    1283             : {
    1284     3672709 :   if (!_bnd_node_range)
    1285             :   {
    1286      251904 :     TIME_SECTION("getBoundaryNodeRange", 5);
    1287             : 
    1288       83968 :     _bnd_node_range = std::make_unique<ConstBndNodeRange>(bndNodesBegin(), bndNodesEnd());
    1289       83968 :   }
    1290             : 
    1291     3672709 :   return _bnd_node_range.get();
    1292             : }
    1293             : 
    1294             : ConstBndElemRange *
    1295      188705 : MooseMesh::getBoundaryElementRange()
    1296             : {
    1297      188705 :   if (!_bnd_elem_range)
    1298             :   {
    1299      251388 :     TIME_SECTION("getBoundaryElementRange", 5);
    1300             : 
    1301       83796 :     _bnd_elem_range = std::make_unique<ConstBndElemRange>(bndElemsBegin(), bndElemsEnd());
    1302       83796 :   }
    1303             : 
    1304      188705 :   return _bnd_elem_range.get();
    1305             : }
    1306             : 
    1307             : const std::unordered_map<boundary_id_type, std::unordered_set<dof_id_type>> &
    1308           0 : MooseMesh::getBoundariesToElems() const
    1309             : {
    1310           0 :   mooseDeprecated("MooseMesh::getBoundariesToElems is deprecated, "
    1311             :                   "use MooseMesh::getBoundariesToActiveSemiLocalElemIds");
    1312           0 :   return getBoundariesToActiveSemiLocalElemIds();
    1313             : }
    1314             : 
    1315             : const std::unordered_map<boundary_id_type, std::unordered_set<dof_id_type>> &
    1316          61 : MooseMesh::getBoundariesToActiveSemiLocalElemIds() const
    1317             : {
    1318          61 :   return _bnd_elem_ids;
    1319             : }
    1320             : 
    1321             : std::unordered_set<dof_id_type>
    1322        3501 : MooseMesh::getBoundaryActiveSemiLocalElemIds(BoundaryID bid) const
    1323             : {
    1324             :   // The boundary to element map is computed on every mesh update
    1325        3501 :   const auto it = _bnd_elem_ids.find(bid);
    1326        3501 :   if (it == _bnd_elem_ids.end())
    1327             :     // Boundary is not local to this domain, return an empty set
    1328         106 :     return std::unordered_set<dof_id_type>{};
    1329        3395 :   return it->second;
    1330             : }
    1331             : 
    1332             : std::unordered_set<dof_id_type>
    1333           0 : MooseMesh::getBoundaryActiveNeighborElemIds(BoundaryID bid) const
    1334             : {
    1335             :   // Vector of boundary elems is updated every mesh update
    1336           0 :   std::unordered_set<dof_id_type> neighbor_elems;
    1337           0 :   for (const auto & bnd_elem : _bnd_elems)
    1338             :   {
    1339           0 :     const auto & [elem_ptr, elem_side, elem_bid] = *bnd_elem;
    1340           0 :     if (elem_bid == bid)
    1341             :     {
    1342           0 :       const auto * neighbor = elem_ptr->neighbor_ptr(elem_side);
    1343             :       // Dont add fully remote elements, ghosted is fine
    1344           0 :       if (neighbor && neighbor != libMesh::remote_elem)
    1345             :       {
    1346             :         // handle mesh refinement, only return active elements near the boundary
    1347           0 :         if (neighbor->active())
    1348           0 :           neighbor_elems.insert(neighbor->id());
    1349             :         else
    1350             :         {
    1351           0 :           std::vector<const Elem *> family;
    1352           0 :           neighbor->active_family_tree_by_neighbor(family, elem_ptr);
    1353           0 :           for (const auto & child_neighbor : family)
    1354           0 :             neighbor_elems.insert(child_neighbor->id());
    1355           0 :         }
    1356             :       }
    1357             :     }
    1358             :   }
    1359             : 
    1360           0 :   return neighbor_elems;
    1361           0 : }
    1362             : 
    1363             : bool
    1364           0 : MooseMesh::isBoundaryFullyExternalToSubdomains(BoundaryID bid,
    1365             :                                                const std::set<SubdomainID> & blk_group) const
    1366             : {
    1367             :   mooseAssert(_bnd_elem_range, "Boundary element range is not initialized");
    1368             : 
    1369             :   // Loop over all side elements of the mesh, select those on the boundary
    1370           0 :   for (const auto & bnd_elem : *_bnd_elem_range)
    1371             :   {
    1372           0 :     const auto & [elem_ptr, elem_side, elem_bid] = *bnd_elem;
    1373           0 :     if (elem_bid == bid)
    1374             :     {
    1375             :       // If an element is internal to the group of subdomain, check the neighbor
    1376           0 :       if (blk_group.find(elem_ptr->subdomain_id()) != blk_group.end())
    1377             :       {
    1378           0 :         const auto * const neighbor = elem_ptr->neighbor_ptr(elem_side);
    1379             : 
    1380             :         // If we did not ghost the neighbor, we cannot decide
    1381           0 :         if (neighbor == libMesh::remote_elem)
    1382           0 :           mooseError("Insufficient level of geometrical ghosting to determine "
    1383             :                      "if a boundary is internal to the mesh");
    1384             :         // If the neighbor does not exist, then we are on the edge of the mesh
    1385           0 :         if (!neighbor)
    1386           0 :           continue;
    1387             :         // If the neighbor is also in the group of subdomain,
    1388             :         // then the boundary cuts the subdomains
    1389           0 :         if (blk_group.find(neighbor->subdomain_id()) != blk_group.end())
    1390           0 :           return false;
    1391             :       }
    1392             :     }
    1393             :   }
    1394           0 :   return true;
    1395             : }
    1396             : 
    1397             : void
    1398      154957 : MooseMesh::cacheInfo()
    1399             : {
    1400      464871 :   TIME_SECTION("cacheInfo", 3);
    1401             : 
    1402      154957 :   _sub_to_data.clear();
    1403      154957 :   _neighbor_subdomain_boundary_ids.clear();
    1404      154957 :   _block_node_list.clear();
    1405      154957 :   _higher_d_elem_side_to_lower_d_elem.clear();
    1406      154957 :   _lower_d_elem_to_higher_d_elem_side.clear();
    1407      154957 :   _lower_d_interior_blocks.clear();
    1408      154957 :   _lower_d_boundary_blocks.clear();
    1409             : 
    1410      154957 :   const auto & mesh = getMesh();
    1411             : 
    1412             :   // Cache higher and lowerD element information
    1413    38310556 :   for (const auto & elem : mesh.element_ptr_range())
    1414             :   {
    1415    38155599 :     const Elem * ip_elem = elem->interior_parent();
    1416             : 
    1417    38155599 :     if (ip_elem)
    1418             :     {
    1419      102485 :       unsigned int ip_side = ip_elem->which_side_am_i(elem);
    1420             : 
    1421             :       // For some grid sequencing tests: ip_side == libMesh::invalid_uint
    1422      102485 :       if (ip_side != libMesh::invalid_uint)
    1423             :       {
    1424      102325 :         auto pair = std::make_pair(ip_elem, ip_side);
    1425      102325 :         _higher_d_elem_side_to_lower_d_elem.insert(
    1426      102325 :             std::pair<std::pair<const Elem *, unsigned short int>, const Elem *>(pair, elem));
    1427      102325 :         _lower_d_elem_to_higher_d_elem_side.insert(
    1428      102325 :             std::pair<const Elem *, unsigned short int>(elem, ip_side));
    1429             : 
    1430      102325 :         auto id = elem->subdomain_id();
    1431      102325 :         if (ip_elem->neighbor_ptr(ip_side))
    1432             :         {
    1433        6680 :           if (mesh.subdomain_name(id).find("INTERNAL_SIDE_LOWERD_SUBDOMAIN_") != std::string::npos)
    1434        6580 :             _lower_d_interior_blocks.insert(id);
    1435             :         }
    1436             :         else
    1437             :         {
    1438       95645 :           if (mesh.subdomain_name(id).find("BOUNDARY_SIDE_LOWERD_SUBDOMAIN_") != std::string::npos)
    1439        6890 :             _lower_d_boundary_blocks.insert(id);
    1440             :         }
    1441             :       }
    1442             :     }
    1443             : 
    1444   243917838 :     for (unsigned int nd = 0; nd < elem->n_nodes(); ++nd)
    1445             :     {
    1446   205762239 :       const Node & node = *elem->node_ptr(nd);
    1447   205762239 :       _block_node_list[node.id()].insert(elem->subdomain_id());
    1448             :     }
    1449      154957 :   }
    1450      154957 :   _communicator.set_union(_lower_d_interior_blocks);
    1451      154957 :   _communicator.set_union(_lower_d_boundary_blocks);
    1452             : 
    1453             :   // Cache the boundaries next to each subdomain
    1454    27753158 :   for (const auto & elem : mesh.active_local_element_ptr_range())
    1455             :   {
    1456    27598201 :     SubdomainID subdomain_id = elem->subdomain_id();
    1457    27598201 :     auto & sub_data = _sub_to_data[subdomain_id];
    1458    27598201 :     const auto elem_boundary_ids = getBoundaryIDs(elem);
    1459   151896713 :     for (unsigned int side = 0; side < elem->n_sides(); side++)
    1460             :     {
    1461   124298512 :       const auto & boundary_ids = elem_boundary_ids[side];
    1462   124298512 :       sub_data.boundary_ids.insert(boundary_ids.begin(), boundary_ids.end());
    1463             : 
    1464   124298512 :       const Elem * neig = elem->neighbor_ptr(side);
    1465   124298512 :       if (neig)
    1466             :       {
    1467   117086363 :         _neighbor_subdomain_boundary_ids[neig->subdomain_id()].insert(boundary_ids.begin(),
    1468             :                                                                       boundary_ids.end());
    1469   117086363 :         SubdomainID neighbor_subdomain_id = neig->subdomain_id();
    1470   117086363 :         if (neighbor_subdomain_id != subdomain_id)
    1471     1819192 :           sub_data.neighbor_subs.insert(neighbor_subdomain_id);
    1472             :       }
    1473             :     }
    1474    27753158 :   }
    1475             : 
    1476      374312 :   for (const auto blk_id : _mesh_subdomains)
    1477             :   {
    1478      219355 :     auto & sub_data = _sub_to_data[blk_id];
    1479      219355 :     _communicator.set_union(sub_data.neighbor_subs);
    1480      219355 :     _communicator.set_union(sub_data.boundary_ids);
    1481      219355 :     _communicator.set_union(_neighbor_subdomain_boundary_ids[blk_id]);
    1482             :   }
    1483      154957 : }
    1484             : 
    1485             : const std::set<SubdomainID> &
    1486    95950994 : MooseMesh::getNodeBlockIds(const Node & node) const
    1487             : {
    1488    95950994 :   auto it = _block_node_list.find(node.id());
    1489             : 
    1490    95950994 :   if (it == _block_node_list.end())
    1491           0 :     mooseError("Unable to find node: ", node.id(), " in any block list.");
    1492             : 
    1493   191901988 :   return it->second;
    1494             : }
    1495             : 
    1496             : MooseMesh::face_info_iterator
    1497      164703 : MooseMesh::ownedFaceInfoBegin()
    1498             : {
    1499             :   return face_info_iterator(
    1500      164703 :       _face_info.begin(),
    1501      164703 :       _face_info.end(),
    1502      329406 :       libMesh::Predicates::pid<std::vector<const FaceInfo *>::iterator>(this->processor_id()));
    1503             : }
    1504             : 
    1505             : MooseMesh::face_info_iterator
    1506      164703 : MooseMesh::ownedFaceInfoEnd()
    1507             : {
    1508             :   return face_info_iterator(
    1509      164703 :       _face_info.end(),
    1510      164703 :       _face_info.end(),
    1511      329406 :       libMesh::Predicates::pid<std::vector<const FaceInfo *>::iterator>(this->processor_id()));
    1512             : }
    1513             : 
    1514             : MooseMesh::elem_info_iterator
    1515       84250 : MooseMesh::ownedElemInfoBegin()
    1516             : {
    1517       84250 :   return elem_info_iterator(_elem_info.begin(),
    1518       84250 :                             _elem_info.end(),
    1519      168500 :                             Predicates::NotNull<std::vector<const ElemInfo *>::iterator>());
    1520             : }
    1521             : 
    1522             : MooseMesh::elem_info_iterator
    1523       84250 : MooseMesh::ownedElemInfoEnd()
    1524             : {
    1525       84250 :   return elem_info_iterator(_elem_info.end(),
    1526       84250 :                             _elem_info.end(),
    1527      168500 :                             Predicates::NotNull<std::vector<const ElemInfo *>::iterator>());
    1528             : }
    1529             : 
    1530             : // default begin() accessor
    1531             : MooseMesh::bnd_node_iterator
    1532       86428 : MooseMesh::bndNodesBegin()
    1533             : {
    1534       86428 :   Predicates::NotNull<bnd_node_iterator_imp> p;
    1535      172856 :   return bnd_node_iterator(_bnd_nodes.begin(), _bnd_nodes.end(), p);
    1536       86428 : }
    1537             : 
    1538             : // default end() accessor
    1539             : MooseMesh::bnd_node_iterator
    1540       86428 : MooseMesh::bndNodesEnd()
    1541             : {
    1542       86428 :   Predicates::NotNull<bnd_node_iterator_imp> p;
    1543      172856 :   return bnd_node_iterator(_bnd_nodes.end(), _bnd_nodes.end(), p);
    1544       86428 : }
    1545             : 
    1546             : // default begin() accessor
    1547             : MooseMesh::bnd_elem_iterator
    1548       83950 : MooseMesh::bndElemsBegin()
    1549             : {
    1550       83950 :   Predicates::NotNull<bnd_elem_iterator_imp> p;
    1551      167900 :   return bnd_elem_iterator(_bnd_elems.begin(), _bnd_elems.end(), p);
    1552       83950 : }
    1553             : 
    1554             : // default end() accessor
    1555             : MooseMesh::bnd_elem_iterator
    1556       83950 : MooseMesh::bndElemsEnd()
    1557             : {
    1558       83950 :   Predicates::NotNull<bnd_elem_iterator_imp> p;
    1559      167900 :   return bnd_elem_iterator(_bnd_elems.end(), _bnd_elems.end(), p);
    1560       83950 : }
    1561             : 
    1562             : const Node *
    1563           0 : MooseMesh::addUniqueNode(const Point & p, Real tol)
    1564             : {
    1565             :   /**
    1566             :    * Looping through the mesh nodes each time we add a point is very slow.  To speed things
    1567             :    * up we keep a local data structure
    1568             :    */
    1569           0 :   if (getMesh().n_nodes() != _node_map.size())
    1570             :   {
    1571           0 :     _node_map.clear();
    1572           0 :     _node_map.reserve(getMesh().n_nodes());
    1573           0 :     for (const auto & node : getMesh().node_ptr_range())
    1574           0 :       _node_map.push_back(node);
    1575             :   }
    1576             : 
    1577           0 :   Node * node = nullptr;
    1578           0 :   for (unsigned int i = 0; i < _node_map.size(); ++i)
    1579             :   {
    1580           0 :     if (p.relative_fuzzy_equals(*_node_map[i], tol))
    1581             :     {
    1582           0 :       node = _node_map[i];
    1583           0 :       break;
    1584             :     }
    1585             :   }
    1586           0 :   if (node == nullptr)
    1587             :   {
    1588           0 :     node = getMesh().add_node(new Node(p));
    1589           0 :     _node_map.push_back(node);
    1590             :   }
    1591             : 
    1592             :   mooseAssert(node != nullptr, "Node is NULL");
    1593           0 :   return node;
    1594             : }
    1595             : 
    1596             : Node *
    1597        5357 : MooseMesh::addQuadratureNode(const Elem * elem,
    1598             :                              const unsigned short int side,
    1599             :                              const unsigned int qp,
    1600             :                              BoundaryID bid,
    1601             :                              const Point & point)
    1602             : {
    1603             :   Node * qnode;
    1604             : 
    1605        5357 :   if (_elem_to_side_to_qp_to_quadrature_nodes[elem->id()][side].find(qp) ==
    1606       10714 :       _elem_to_side_to_qp_to_quadrature_nodes[elem->id()][side].end())
    1607             :   {
    1608             :     // Create a new node id starting from the max node id and counting down.  This will be the least
    1609             :     // likely to collide with an existing node id.
    1610             :     // Note that we are using numeric_limits<unsigned>::max even
    1611             :     // though max_id is stored as a dof_id_type.  I tried this with
    1612             :     // numeric_limits<dof_id_type>::max and it broke several tests in
    1613             :     // MOOSE.  So, this is some kind of a magic number that we will
    1614             :     // just continue to use...
    1615        5357 :     dof_id_type max_id = std::numeric_limits<unsigned int>::max() - 100;
    1616        5357 :     dof_id_type new_id = max_id - _quadrature_nodes.size();
    1617             : 
    1618        5357 :     if (new_id <= getMesh().max_node_id())
    1619           0 :       mooseError("Quadrature node id collides with existing node id!");
    1620             : 
    1621        5357 :     qnode = new Node(point, new_id);
    1622             : 
    1623             :     // Keep track of this new node in two different ways for easy lookup
    1624        5357 :     _quadrature_nodes[new_id] = qnode;
    1625        5357 :     _elem_to_side_to_qp_to_quadrature_nodes[elem->id()][side][qp] = qnode;
    1626             : 
    1627        5357 :     if (elem->active())
    1628        5357 :       internalNodeToElemMap()[new_id].push_back(elem->id());
    1629             :   }
    1630             :   else
    1631           0 :     qnode = _elem_to_side_to_qp_to_quadrature_nodes[elem->id()][side][qp];
    1632             : 
    1633        5357 :   BndNode * bnode = new BndNode(qnode, bid);
    1634        5357 :   _bnd_nodes.push_back(bnode);
    1635        5357 :   _bnd_node_ids[bid].insert(qnode->id());
    1636             : 
    1637        5357 :   _extra_bnd_nodes.push_back(*bnode);
    1638             : 
    1639             :   // Do this so the range will be regenerated next time it is accessed
    1640        5357 :   _bnd_node_range.reset();
    1641             : 
    1642        5357 :   return qnode;
    1643             : }
    1644             : 
    1645             : Node *
    1646      137880 : MooseMesh::getQuadratureNode(const Elem * elem,
    1647             :                              const unsigned short int side,
    1648             :                              const unsigned int qp)
    1649             : {
    1650             :   mooseAssert(_elem_to_side_to_qp_to_quadrature_nodes.find(elem->id()) !=
    1651             :                   _elem_to_side_to_qp_to_quadrature_nodes.end(),
    1652             :               "Elem has no quadrature nodes!");
    1653             :   mooseAssert(_elem_to_side_to_qp_to_quadrature_nodes[elem->id()].find(side) !=
    1654             :                   _elem_to_side_to_qp_to_quadrature_nodes[elem->id()].end(),
    1655             :               "Side has no quadrature nodes!");
    1656             :   mooseAssert(_elem_to_side_to_qp_to_quadrature_nodes[elem->id()][side].find(qp) !=
    1657             :                   _elem_to_side_to_qp_to_quadrature_nodes[elem->id()][side].end(),
    1658             :               "qp not found on side!");
    1659             : 
    1660      137880 :   return _elem_to_side_to_qp_to_quadrature_nodes[elem->id()][side][qp];
    1661             : }
    1662             : 
    1663             : void
    1664       74189 : MooseMesh::clearQuadratureNodes()
    1665             : {
    1666             :   // Delete all the quadrature nodes
    1667       79534 :   for (auto & it : _quadrature_nodes)
    1668        5345 :     delete it.second;
    1669             : 
    1670       74189 :   _quadrature_nodes.clear();
    1671       74189 :   _elem_to_side_to_qp_to_quadrature_nodes.clear();
    1672       74189 :   _extra_bnd_nodes.clear();
    1673             : 
    1674             :   // NOTE: this does not clear them from the nodeToElem map
    1675       74189 : }
    1676             : 
    1677             : BoundaryID
    1678      543878 : MooseMesh::getBoundaryID(const BoundaryName & boundary_name) const
    1679             : {
    1680      543878 :   if (boundary_name == "ANY_BOUNDARY_ID")
    1681           0 :     mooseError("Please use getBoundaryIDs() when passing \"ANY_BOUNDARY_ID\"");
    1682             : 
    1683      543878 :   return MooseMeshUtils::getBoundaryID(boundary_name, getMesh());
    1684             : }
    1685             : 
    1686             : const Elem *
    1687  1577196185 : MooseMesh::getLowerDElem(const Elem * elem, unsigned short int side) const
    1688             : {
    1689  1577196185 :   auto it = _higher_d_elem_side_to_lower_d_elem.find(std::make_pair(elem, side));
    1690             : 
    1691  1577196185 :   if (it != _higher_d_elem_side_to_lower_d_elem.end())
    1692      280844 :     return it->second;
    1693             :   else
    1694  1576915341 :     return nullptr;
    1695             : }
    1696             : 
    1697             : unsigned int
    1698         260 : MooseMesh::getHigherDSide(const Elem * elem) const
    1699             : {
    1700         260 :   auto it = _lower_d_elem_to_higher_d_elem_side.find(elem);
    1701             : 
    1702         260 :   if (it != _lower_d_elem_to_higher_d_elem_side.end())
    1703         260 :     return it->second;
    1704             :   else
    1705           0 :     return libMesh::invalid_uint;
    1706             : }
    1707             : 
    1708             : std::vector<BoundaryID>
    1709      116921 : MooseMesh::getBoundaryIDs(const std::vector<BoundaryName> & boundary_name,
    1710             :                           bool generate_unknown) const
    1711             : {
    1712             :   return MooseMeshUtils::getBoundaryIDs(
    1713      116921 :       getMesh(), boundary_name, generate_unknown, _mesh_boundary_ids);
    1714             : }
    1715             : 
    1716             : SubdomainID
    1717      529217 : MooseMesh::getSubdomainID(const SubdomainName & subdomain_name) const
    1718             : {
    1719      529217 :   return MooseMeshUtils::getSubdomainID(subdomain_name, getMesh());
    1720             : }
    1721             : 
    1722             : std::vector<SubdomainID>
    1723      239989 : MooseMesh::getSubdomainIDs(const std::vector<SubdomainName> & subdomain_name) const
    1724             : {
    1725      239989 :   return MooseMeshUtils::getSubdomainIDs(getMesh(), subdomain_name);
    1726             : }
    1727             : 
    1728             : std::set<SubdomainID>
    1729           0 : MooseMesh::getSubdomainIDs(const std::set<SubdomainName> & subdomain_name) const
    1730             : {
    1731           0 :   return MooseMeshUtils::getSubdomainIDs(getMesh(), subdomain_name);
    1732             : }
    1733             : 
    1734             : void
    1735         253 : MooseMesh::setSubdomainName(SubdomainID subdomain_id, const SubdomainName & name)
    1736             : {
    1737             :   mooseAssert(name != "ANY_BLOCK_ID", "Cannot set subdomain name to 'ANY_BLOCK_ID'");
    1738         253 :   getMesh().subdomain_name(subdomain_id) = name;
    1739         253 : }
    1740             : 
    1741             : void
    1742           0 : MooseMesh::setSubdomainName(MeshBase & mesh, SubdomainID subdomain_id, const SubdomainName & name)
    1743             : {
    1744             :   mooseAssert(name != "ANY_BLOCK_ID", "Cannot set subdomain name to 'ANY_BLOCK_ID'");
    1745           0 :   mesh.subdomain_name(subdomain_id) = name;
    1746           0 : }
    1747             : 
    1748             : const std::string &
    1749     4311396 : MooseMesh::getSubdomainName(SubdomainID subdomain_id) const
    1750             : {
    1751     4311396 :   return getMesh().subdomain_name(subdomain_id);
    1752             : }
    1753             : 
    1754             : std::vector<SubdomainName>
    1755          71 : MooseMesh::getSubdomainNames(const std::vector<SubdomainID> & subdomain_ids) const
    1756             : {
    1757          71 :   std::vector<SubdomainName> names(subdomain_ids.size());
    1758             : 
    1759         142 :   for (unsigned int i = 0; i < subdomain_ids.size(); i++)
    1760          71 :     names[i] = getSubdomainName(subdomain_ids[i]);
    1761             : 
    1762          71 :   return names;
    1763           0 : }
    1764             : 
    1765             : void
    1766         110 : MooseMesh::setBoundaryName(BoundaryID boundary_id, BoundaryName name)
    1767             : {
    1768         110 :   BoundaryInfo & boundary_info = getMesh().get_boundary_info();
    1769             : 
    1770             :   // We need to figure out if this boundary is a sideset or nodeset
    1771         110 :   if (boundary_info.get_side_boundary_ids().count(boundary_id))
    1772          30 :     boundary_info.sideset_name(boundary_id) = name;
    1773             :   else
    1774          80 :     boundary_info.nodeset_name(boundary_id) = name;
    1775         110 : }
    1776             : 
    1777             : const std::string &
    1778     7597399 : MooseMesh::getBoundaryName(const BoundaryID boundary_id) const
    1779             : {
    1780     7597399 :   const BoundaryInfo & boundary_info = getMesh().get_boundary_info();
    1781             : 
    1782             :   // We need to figure out if this boundary is a sideset or nodeset
    1783     7597399 :   if (boundary_info.get_side_boundary_ids().count(boundary_id))
    1784     7477029 :     return boundary_info.get_sideset_name(boundary_id);
    1785             :   else
    1786      120370 :     return boundary_info.get_nodeset_name(boundary_id);
    1787             : }
    1788             : 
    1789             : std::string
    1790          27 : MooseMesh::getBoundaryString(BoundaryID boundary_id) const
    1791             : {
    1792          27 :   const auto name = getBoundaryName(boundary_id);
    1793          54 :   return name.size() ? name : std::to_string(boundary_id);
    1794          27 : }
    1795             : 
    1796             : // specialization for PointListAdaptor<MooseMesh::PeriodicNodeInfo>
    1797             : template <>
    1798             : inline const Point &
    1799      173430 : PointListAdaptor<MooseMesh::PeriodicNodeInfo>::getPoint(
    1800             :     const MooseMesh::PeriodicNodeInfo & item) const
    1801             : {
    1802      173430 :   return *(item.first);
    1803             : }
    1804             : 
    1805             : void
    1806          27 : MooseMesh::buildPeriodicNodeMap(std::multimap<dof_id_type, dof_id_type> & periodic_node_map,
    1807             :                                 unsigned int var_number,
    1808             :                                 libMesh::PeriodicBoundaries * pbs) const
    1809             : {
    1810          81 :   TIME_SECTION("buildPeriodicNodeMap", 5);
    1811             : 
    1812             :   // clear existing map
    1813          27 :   periodic_node_map.clear();
    1814             : 
    1815             :   // get periodic nodes
    1816          27 :   std::vector<PeriodicNodeInfo> periodic_nodes;
    1817        1575 :   for (const auto & t : getMesh().get_boundary_info().build_node_list())
    1818             :   {
    1819             :     // unfortunately libMesh does not give us a pointer, so we have to look it up ourselves
    1820        1548 :     auto node = _mesh->node_ptr(std::get<0>(t));
    1821             :     mooseAssert(node != nullptr,
    1822             :                 "libMesh::BoundaryInfo::build_node_list() returned an ID for a non-existing node");
    1823        1548 :     auto bc_id = std::get<1>(t);
    1824        1548 :     periodic_nodes.emplace_back(node, bc_id);
    1825          27 :   }
    1826             : 
    1827             :   // sort by boundary id
    1828          27 :   std::sort(periodic_nodes.begin(),
    1829             :             periodic_nodes.end(),
    1830        8658 :             [](const PeriodicNodeInfo & a, const PeriodicNodeInfo & b) -> bool
    1831        8658 :             { return a.second > b.second; });
    1832             : 
    1833             :   // build kd-tree
    1834             :   using KDTreeType = nanoflann::KDTreeSingleIndexAdaptor<
    1835             :       nanoflann::L2_Simple_Adaptor<Real, PointListAdaptor<PeriodicNodeInfo>, Real, std::size_t>,
    1836             :       PointListAdaptor<PeriodicNodeInfo>,
    1837             :       LIBMESH_DIM,
    1838             :       std::size_t>;
    1839          27 :   const unsigned int max_leaf_size = 20; // slightly affects runtime
    1840             :   auto point_list =
    1841          27 :       PointListAdaptor<PeriodicNodeInfo>(periodic_nodes.begin(), periodic_nodes.end());
    1842             :   auto kd_tree = std::make_unique<KDTreeType>(
    1843          27 :       LIBMESH_DIM, point_list, nanoflann::KDTreeSingleIndexAdaptorParams(max_leaf_size));
    1844             :   mooseAssert(kd_tree != nullptr, "KDTree was not properly initialized.");
    1845          27 :   kd_tree->buildIndex();
    1846             : 
    1847             :   // data structures for kd-tree search
    1848          27 :   nanoflann::SearchParameters search_params;
    1849          27 :   std::vector<nanoflann::ResultItem<std::size_t, Real>> ret_matches;
    1850             : 
    1851             :   // iterate over periodic nodes (boundary ids are in contiguous blocks)
    1852          27 :   libMesh::PeriodicBoundaryBase * periodic = nullptr;
    1853          27 :   BoundaryID current_bc_id = BoundaryInfo::invalid_id;
    1854        1575 :   for (auto & pair : periodic_nodes)
    1855             :   {
    1856             :     // entering a new block of boundary IDs
    1857        1548 :     if (pair.second != current_bc_id)
    1858             :     {
    1859         108 :       current_bc_id = pair.second;
    1860         108 :       periodic = pbs->boundary(current_bc_id);
    1861         108 :       if (periodic && !periodic->is_my_variable(var_number))
    1862           0 :         periodic = nullptr;
    1863             :     }
    1864             : 
    1865             :     // variable is not periodic at this node, skip
    1866        1548 :     if (!periodic)
    1867           0 :       continue;
    1868             : 
    1869             :     // clear result buffer
    1870        1548 :     ret_matches.clear();
    1871             : 
    1872             :     // id of the current node
    1873        1548 :     const auto id = pair.first->id();
    1874             : 
    1875             :     // position where we expect a periodic partner for the current node and boundary
    1876        1548 :     Point search_point = periodic->get_corresponding_pos(*pair.first);
    1877             : 
    1878             :     // search at the expected point
    1879        1548 :     kd_tree->radiusSearch(&(search_point)(0), libMesh::TOLERANCE, ret_matches, search_params);
    1880        4248 :     for (auto & match_pair : ret_matches)
    1881             :     {
    1882        2700 :       const auto & match = periodic_nodes[match_pair.first];
    1883             :       // add matched node if the boundary id is the corresponding id in the periodic pair
    1884        2700 :       if (match.second == periodic->pairedboundary)
    1885        1548 :         periodic_node_map.emplace(id, match.first->id());
    1886             :     }
    1887             :   }
    1888          27 : }
    1889             : 
    1890             : void
    1891           0 : MooseMesh::buildPeriodicNodeSets(std::map<BoundaryID, std::set<dof_id_type>> & periodic_node_sets,
    1892             :                                  unsigned int var_number,
    1893             :                                  libMesh::PeriodicBoundaries * pbs) const
    1894             : {
    1895           0 :   TIME_SECTION("buildPeriodicNodeSets", 5);
    1896             : 
    1897           0 :   periodic_node_sets.clear();
    1898             : 
    1899             :   // Loop over all the boundary nodes adding the periodic nodes to the appropriate set
    1900           0 :   for (const auto & t : getMesh().get_boundary_info().build_node_list())
    1901             :   {
    1902           0 :     auto node_id = std::get<0>(t);
    1903           0 :     auto bc_id = std::get<1>(t);
    1904             : 
    1905             :     // Is this current node on a known periodic boundary?
    1906           0 :     if (periodic_node_sets.find(bc_id) != periodic_node_sets.end())
    1907           0 :       periodic_node_sets[bc_id].insert(node_id);
    1908             :     else // This still might be a periodic node but we just haven't seen this boundary_id yet
    1909             :     {
    1910           0 :       const libMesh::PeriodicBoundaryBase * periodic = pbs->boundary(bc_id);
    1911           0 :       if (periodic && periodic->is_my_variable(var_number))
    1912           0 :         periodic_node_sets[bc_id].insert(node_id);
    1913             :     }
    1914           0 :   }
    1915           0 : }
    1916             : 
    1917             : bool
    1918       68628 : MooseMesh::detectOrthogonalDimRanges(Real tol)
    1919             : {
    1920      205884 :   TIME_SECTION("detectOrthogonalDimRanges", 5);
    1921             : 
    1922       68628 :   if (_regular_orthogonal_mesh)
    1923       34404 :     return true;
    1924             : 
    1925       34224 :   std::vector<Real> min(3, std::numeric_limits<Real>::max());
    1926       34224 :   std::vector<Real> max(3, std::numeric_limits<Real>::min());
    1927       34224 :   unsigned int dim = getMesh().mesh_dimension();
    1928             : 
    1929             :   // Find the bounding box of our mesh
    1930    10257575 :   for (const auto & node : getMesh().node_ptr_range())
    1931             :     // Check all coordinates, we don't know if this mesh might be lying in a higher dim even if the
    1932             :     // mesh dimension is lower.
    1933    40893404 :     for (const auto i : make_range(Moose::dim))
    1934             :     {
    1935    30670053 :       if ((*node)(i) < min[i])
    1936      209985 :         min[i] = (*node)(i);
    1937    30670053 :       if ((*node)(i) > max[i])
    1938      469169 :         max[i] = (*node)(i);
    1939       34224 :     }
    1940             : 
    1941       34224 :   this->comm().max(max);
    1942       34224 :   this->comm().min(min);
    1943             : 
    1944       34224 :   _extreme_nodes.resize(8); // 2^LIBMESH_DIM
    1945             :   // Now make sure that there are actual nodes at all of the extremes
    1946       34224 :   std::vector<bool> extreme_matches(8, false);
    1947       34224 :   std::vector<unsigned int> comp_map(3);
    1948    10257575 :   for (const auto & node : getMesh().node_ptr_range())
    1949             :   {
    1950             :     // See if the current node is located at one of the extremes
    1951    10223351 :     unsigned int coord_match = 0;
    1952             : 
    1953    40893404 :     for (const auto i : make_range(Moose::dim))
    1954             :     {
    1955    30670053 :       if (std::abs((*node)(i)-min[i]) < tol)
    1956             :       {
    1957     6349562 :         comp_map[i] = MIN;
    1958     6349562 :         ++coord_match;
    1959             :       }
    1960    24320491 :       else if (std::abs((*node)(i)-max[i]) < tol)
    1961             :       {
    1962     1393901 :         comp_map[i] = MAX;
    1963     1393901 :         ++coord_match;
    1964             :       }
    1965             :     }
    1966             : 
    1967    10223351 :     if (coord_match == LIBMESH_DIM) // Found a coordinate at one of the extremes
    1968             :     {
    1969      124509 :       _extreme_nodes[comp_map[X] * 4 + comp_map[Y] * 2 + comp_map[Z]] = node;
    1970      124509 :       extreme_matches[comp_map[X] * 4 + comp_map[Y] * 2 + comp_map[Z]] = true;
    1971             :     }
    1972       34224 :   }
    1973             : 
    1974             :   // See if we matched all of the extremes for the mesh dimension
    1975       34224 :   this->comm().max(extreme_matches);
    1976       34224 :   if (std::count(extreme_matches.begin(), extreme_matches.end(), true) == (1 << dim))
    1977       29833 :     _regular_orthogonal_mesh = true;
    1978             : 
    1979             :   // Set the bounds
    1980       34224 :   _bounds.resize(LIBMESH_DIM);
    1981      136896 :   for (const auto i : make_range(Moose::dim))
    1982             :   {
    1983      102672 :     _bounds[i].resize(2);
    1984      102672 :     _bounds[i][MIN] = min[i];
    1985      102672 :     _bounds[i][MAX] = max[i];
    1986             :   }
    1987             : 
    1988       34224 :   return _regular_orthogonal_mesh;
    1989       68628 : }
    1990             : 
    1991             : void
    1992         538 : MooseMesh::detectPairedSidesets()
    1993             : {
    1994        1614 :   TIME_SECTION("detectPairedSidesets", 5);
    1995             : 
    1996         538 :   _paired_boundary = std::vector<std::pair<BoundaryID, BoundaryID>>();
    1997             : 
    1998             :   // Loop over level-0 elements (since boundary condition information
    1999             :   // is only directly stored for them) and find sidesets with normals
    2000             :   // that point in the -x, +x, -y, +y, and -z, +z direction.  If there
    2001             :   // is a unique sideset id for each direction, then the paired
    2002             :   // sidesets consist of (-x,+x), (-y,+y), (-z,+z).  If there are
    2003             :   // multiple sideset ids for a given direction, then we can't pick a
    2004             :   // single pair for that direction.  In that case, we'll just return
    2005             :   // as was done in the original algorithm.
    2006             : 
    2007             :   // we need to test all element dimensions from dim down to 1
    2008         538 :   const unsigned int mesh_dim = getMesh().mesh_dimension();
    2009             : 
    2010             :   // Helper for iterating through unit dimensions (0=x, 1=y, 2=z)
    2011             :   static constexpr std::array<std::size_t, 3> unit_dims{0, 1, 2};
    2012             :   // Helper for mapping from unit dim -> name
    2013        1614 :   static const std::array<std::string, 3> unit_dim_names{"x", "y", "z"};
    2014             : 
    2015             :   // Boundary id sets for elements of different dimensions
    2016             :   // First index: side dimension; 0=1D, 1=2D, 2=3D
    2017             :   // Second index: unit dimension; 0=x, 1=y, 2=z
    2018             :   // Third index: false for minus, true for plus
    2019       16678 :   std::array<std::array<std::array<std::set<BoundaryID>, 2>, 3>, 3> ids{};
    2020             : 
    2021             :   // Build quadrature needed to evaluate side normals
    2022         538 :   std::array<std::unique_ptr<FEBase>, 3> fe_faces{};
    2023         538 :   std::array<std::unique_ptr<libMesh::QGauss>, 3> qfaces{};
    2024        1596 :   for (const auto side_dim : make_range(mesh_dim))
    2025             :   {
    2026             :     // Face is assumed to be flat, therefore normal is assumed to be
    2027             :     // constant over the face, therefore only compute it at 1 qp.
    2028        1058 :     qfaces[side_dim] = std::unique_ptr<libMesh::QGauss>(new libMesh::QGauss(side_dim, CONSTANT));
    2029             : 
    2030             :     // A first-order Lagrange FE for the face.
    2031        1058 :     fe_faces[side_dim] = FEBase::build(side_dim + 1, FEType(FIRST, libMesh::LAGRANGE));
    2032        1058 :     fe_faces[side_dim]->attach_quadrature_rule(qfaces[side_dim].get());
    2033        1058 :     fe_faces[side_dim]->get_normals();
    2034             :   }
    2035             : 
    2036             :   // Get boundary IDs for each dimension that are in the unit normal
    2037         538 :   const auto & boundary_info = getMesh().get_boundary_info();
    2038             :   // Temporary for evaluating boundary_ids
    2039         538 :   std::vector<boundary_id_type> face_ids;
    2040             :   // The side dimensions we've come across, so that we only report
    2041             :   // warnings for side dimensions that we have
    2042         538 :   std::set<unsigned int> side_dims;
    2043             :   // Normal dimensions that we found that were nonzero; lets us
    2044             :   // skip warnings for dimensions that we don't have
    2045         538 :   std::array<bool, 3> nonzero_dims = periodic_dim_default;
    2046      307171 :   for (auto & elem : as_range(getMesh().level_elements_begin(0), getMesh().level_elements_end(0)))
    2047             :   {
    2048             :     // If not on the boundary, nothing to do
    2049      306633 :     if (!elem->on_boundary())
    2050      259116 :       continue;
    2051             : 
    2052       47517 :     const auto side_dim = elem->dim() - 1;
    2053       47517 :     side_dims.insert(side_dim);
    2054             : 
    2055             :     // Check for unit normals on each boundary side
    2056      265346 :     for (const auto s : elem->side_index_range())
    2057      217829 :       if (!elem->neighbor_ptr(s))
    2058             :       {
    2059             :         // Reinit to get the normal
    2060       52932 :         fe_faces[side_dim]->reinit(elem, s);
    2061       52932 :         const auto & normal = fe_faces[side_dim]->get_normals()[0];
    2062             : 
    2063             :         // Get the boundary ID(s) for this side.  If there is more
    2064             :         // than 1 boundary id, then we already can't determine a
    2065             :         // unique pairing of sides in this direction, but we'll just
    2066             :         // keep going to keep the logic simple.
    2067       52932 :         boundary_info.boundary_ids(elem, s, face_ids);
    2068             : 
    2069       52932 :         bool found = false;
    2070      211728 :         for (const auto unit_dim : unit_dims)
    2071             :         {
    2072      158796 :           if (libMesh::absolute_fuzzy_equals(normal(unit_dim), 0.0))
    2073      103964 :             continue;
    2074       54832 :           nonzero_dims[unit_dim] = true;
    2075       54832 :           if (!found)
    2076       88072 :             for (const auto plus : {false, true})
    2077             :             {
    2078       84272 :               if (libMesh::absolute_fuzzy_equals(normal(unit_dim), plus ? 1.0 : -1.0))
    2079             :               {
    2080       51032 :                 ids[side_dim][unit_dim][plus].insert(face_ids.begin(), face_ids.end());
    2081       51032 :                 found = true;
    2082       51032 :                 break;
    2083             :               }
    2084             :             }
    2085             :         }
    2086             :       }
    2087         538 :   }
    2088             : 
    2089             :   // For a distributed mesh, boundaries may be distributed as well. We therefore collect information
    2090             :   // from everyone. If the mesh is already serial, then there is no need to do an allgather. Note
    2091             :   // that this is just going to gather information about what the periodic bc ids are. We are not
    2092             :   // gathering any remote elements or anything like that. It's just that the GhostPointNeighbors
    2093             :   // ghosting functor currently relies on the fact that every process agrees on whether we have
    2094             :   // periodic boundaries; every process that thinks there are periodic boundaries will call
    2095             :   // MeshBase::sub_point_locator which makes a parallel_object_only() assertion (right or wrong). So
    2096             :   // we all need to go there (or not go there)
    2097         538 :   if (_use_distributed_mesh && !_mesh->is_serial())
    2098             :   {
    2099             :     // Communicate id data by packing as [side dim, unit dim, plus (as a char), boundary id]
    2100         122 :     std::vector<std::tuple<unsigned int, unsigned int, unsigned char, boundary_id_type>> id_data;
    2101         244 :     for (const auto side_dim : side_dims)
    2102         488 :       for (const auto unit_dim : unit_dims)
    2103        1098 :         for (const auto plus : {false, true})
    2104        1192 :           for (const auto bd : ids[side_dim][unit_dim][plus])
    2105         460 :             id_data.emplace_back(side_dim, unit_dim, plus, bd);
    2106         122 :     _communicator.allgather(id_data, false);
    2107        1170 :     for (const auto & [side_dim, unit_dim, plus_char, bd] : id_data)
    2108        1048 :       ids[side_dim][unit_dim][bool(plus_char)].insert(bd);
    2109             : 
    2110             :     // Gather true-ness of nonzero_dims
    2111         488 :     for (auto & entry : nonzero_dims)
    2112         366 :       _communicator.max(entry);
    2113             : 
    2114             :     // Gather found side dimensions
    2115         122 :     _communicator.set_union(side_dims);
    2116         122 :   } // end if (_use_distributed_mesh && !_need_ghost_ghosted_boundaries)
    2117             : 
    2118             :   // Find pairings that have exactly one boundary on each side
    2119         538 :   std::ostringstream oss_found, oss_missing;
    2120        1076 :   for (const auto side_dim : side_dims)
    2121             :   {
    2122        2152 :     for (const auto unit_dim : unit_dims)
    2123        1614 :       if (nonzero_dims[unit_dim])
    2124             :       {
    2125        1061 :         const auto & unit_name = unit_dim_names[unit_dim];
    2126        1061 :         const auto & minus = ids[side_dim][unit_dim][false];
    2127        1061 :         const auto & plus = ids[side_dim][unit_dim][true];
    2128             : 
    2129        1061 :         if (minus.size() == 1 && plus.size() == 1)
    2130             :         {
    2131        1904 :           const auto get_boundary_name = [this](const auto id)
    2132             :           {
    2133        1904 :             const auto & name = getBoundaryName(id);
    2134        1904 :             return name.size() ? name : std::to_string(id);
    2135         952 :           };
    2136             : 
    2137         952 :           oss_found << "\n  " << side_dim + 1 << "D " << unit_name
    2138         952 :                     << "-direction: " << get_boundary_name(*minus.begin()) << " <-> "
    2139        1904 :                     << get_boundary_name(*plus.begin());
    2140         952 :           _paired_boundary->emplace_back(std::make_pair(*minus.begin(), *plus.begin()));
    2141             :         }
    2142             :         else
    2143         109 :           oss_missing << "\n  " << side_dim + 1 << "D -" << unit_name << "/+" << unit_name
    2144         109 :                       << ": Found " << minus.size() << " -" << unit_name << " boundaries and "
    2145         109 :                       << plus.size() << " +" << unit_name << " boundaries";
    2146             :       }
    2147             :   }
    2148             : 
    2149         538 :   std::ostringstream oss;
    2150         538 :   const auto found = oss_found.str();
    2151         538 :   const auto missing = oss_missing.str();
    2152         538 :   if (found.size())
    2153             :     oss << "The following paired boundaries were automatically detected for periodicity:\n"
    2154         504 :         << found << "\n";
    2155         538 :   if (missing.size())
    2156             :   {
    2157          75 :     if (found.size())
    2158          41 :       oss << "\n";
    2159             :     oss << "Paired boundaries were not automatically detected for the following:\n"
    2160             :         << missing
    2161             :         << "\n\nAutomatic detection requires that exactly one boundary is found in each unit "
    2162          75 :            "direction.\n";
    2163             :   }
    2164             : 
    2165         538 :   mooseInfoRepeated(oss.str());
    2166         538 : }
    2167             : 
    2168             : Real
    2169       72760 : MooseMesh::dimensionWidth(unsigned int component) const
    2170             : {
    2171       72760 :   return getMaxInDimension(component) - getMinInDimension(component);
    2172             : }
    2173             : 
    2174             : Real
    2175       33393 : MooseMesh::getMinInDimension(unsigned int component) const
    2176             : {
    2177             :   mooseAssert(_mesh, "The MeshBase has not been constructed");
    2178             :   mooseAssert(component < _bounds.size(), "Requested dimension out of bounds");
    2179             : 
    2180       33393 :   return _bounds[component][MIN];
    2181             : }
    2182             : 
    2183             : Real
    2184       33393 : MooseMesh::getMaxInDimension(unsigned int component) const
    2185             : {
    2186             :   mooseAssert(_mesh, "The MeshBase has not been constructed");
    2187             :   mooseAssert(component < _bounds.size(), "Requested dimension out of bounds");
    2188             : 
    2189       33393 :   return _bounds[component][MAX];
    2190             : }
    2191             : 
    2192             : void
    2193         873 : MooseMesh::addPeriodicVariable(const unsigned int sys_num,
    2194             :                                const unsigned int var_num,
    2195             :                                const BoundaryID primary,
    2196             :                                const BoundaryID secondary)
    2197             : {
    2198         873 :   if (!_regular_orthogonal_mesh)
    2199           0 :     return;
    2200             : 
    2201         873 :   const auto key = std::make_pair(sys_num, var_num);
    2202         873 :   auto & entry = _periodic_dim.try_emplace(key, periodic_dim_default).first->second;
    2203             : 
    2204         873 :   _half_range = Point(dimensionWidth(0) / 2.0, dimensionWidth(1) / 2.0, dimensionWidth(2) / 2.0);
    2205             : 
    2206         873 :   bool component_found = false;
    2207        2707 :   for (const auto component : make_range(dimension()))
    2208             :   {
    2209        1834 :     const std::pair<BoundaryID, BoundaryID> * boundary_ids = getPairedBoundaryMapping(component);
    2210             : 
    2211        1834 :     if (boundary_ids && ((boundary_ids->first == primary && boundary_ids->second == secondary) ||
    2212         976 :                          (boundary_ids->first == secondary && boundary_ids->second == primary)))
    2213             :     {
    2214         858 :       entry[component] = true;
    2215         858 :       component_found = true;
    2216             :     }
    2217             :   }
    2218             : 
    2219         873 :   if (!component_found)
    2220          30 :     mooseWarning("Could not find a match between boundary '",
    2221          15 :                  getBoundaryName(primary),
    2222             :                  "' and '",
    2223          15 :                  getBoundaryName(secondary),
    2224             :                  "' to set periodic boundary conditions for variable (index:",
    2225             :                  var_num,
    2226             :                  ") in either the X, Y or Z direction. The periodic dimension of the mesh for this "
    2227             :                  "variable will not be stored.");
    2228             : }
    2229             : 
    2230             : const std::array<bool, 3> &
    2231     5076485 : MooseMesh::queryPeriodicDimensions(const unsigned int sys_num, const unsigned int var_num) const
    2232             : {
    2233     5076485 :   const auto key = std::make_pair(sys_num, var_num);
    2234     5076485 :   if (const auto it = _periodic_dim.find(key); it != _periodic_dim.end())
    2235     4972801 :     return it->second;
    2236      103684 :   return periodic_dim_default;
    2237             : }
    2238             : 
    2239             : const std::array<bool, 3> &
    2240          27 : MooseMesh::queryPeriodicDimensions(const MooseVariableBase & var) const
    2241             : {
    2242          27 :   return queryPeriodicDimensions(var.sys().number(), var.number());
    2243             : }
    2244             : 
    2245             : bool
    2246           0 : MooseMesh::isTranslatedPeriodic(const unsigned int sys_num,
    2247             :                                 const unsigned int var_num,
    2248             :                                 const unsigned int component) const
    2249             : {
    2250             :   mooseAssert(component < dimension(), "Requested dimension out of bounds");
    2251           0 :   return queryPeriodicDimensions(sys_num, var_num)[component];
    2252             : }
    2253             : 
    2254             : bool
    2255           0 : MooseMesh::isTranslatedPeriodic(const MooseVariableBase & var, const unsigned int component) const
    2256             : {
    2257           0 :   return isTranslatedPeriodic(var.sys().number(), var.number(), component);
    2258             : }
    2259             : 
    2260             : bool
    2261           0 : MooseMesh::isTranslatedPeriodic(const unsigned int var_num, const unsigned int component) const
    2262             : {
    2263           0 :   mooseDoOnce(mooseDeprecated(
    2264             :       "MooseMesh::isTranslatedPeriodic(const unsigned int, const unsigned int) is deprecated. Use "
    2265             :       "the method that additionally takes the system number or the MooseVariableBase instead."));
    2266           0 :   return isTranslatedPeriodic(0, var_num, component);
    2267             : }
    2268             : 
    2269             : RealVectorValue
    2270     5076458 : MooseMesh::minPeriodicVector(const unsigned int sys_num,
    2271             :                              const unsigned int var_num,
    2272             :                              Point p,
    2273             :                              Point q) const
    2274             : {
    2275     5076458 :   const auto & periodic_dims = queryPeriodicDimensions(sys_num, var_num);
    2276             : 
    2277    15164330 :   for (const auto i : make_range(dimension()))
    2278             :   {
    2279             :     // check to see if we're closer in real or periodic space in x, y, and z
    2280    10087872 :     if (periodic_dims[i])
    2281             :     {
    2282             :       // Need to test order before differencing
    2283     9880504 :       if (p(i) > q(i))
    2284             :       {
    2285     6390944 :         if (p(i) - q(i) > _half_range(i))
    2286     2344164 :           p(i) -= _half_range(i) * 2;
    2287             :       }
    2288             :       else
    2289             :       {
    2290     3489560 :         if (q(i) - p(i) > _half_range(i))
    2291      927180 :           p(i) += _half_range(i) * 2;
    2292             :       }
    2293             :     }
    2294             :   }
    2295             : 
    2296     5076458 :   return q - p;
    2297             : }
    2298             : 
    2299             : RealVectorValue
    2300           0 : MooseMesh::minPeriodicVector(const MooseVariableBase & var, const Point & p, const Point & q) const
    2301             : {
    2302           0 :   return minPeriodicVector(var.sys().number(), var.number(), p, q);
    2303             : }
    2304             : 
    2305             : RealVectorValue
    2306           0 : MooseMesh::minPeriodicVector(const unsigned int var_num, const Point & p, const Point & q) const
    2307             : {
    2308           0 :   mooseDoOnce(mooseDeprecated("MooseMesh::minPeriodicVector(const unsigned int, const Point &, "
    2309             :                               "const Point &) is deprecated. Use the method that additionally "
    2310             :                               "takes the system number or the MooseVariableBase instead."));
    2311           0 :   return minPeriodicVector(0, var_num, p, q);
    2312             : }
    2313             : 
    2314             : Real
    2315     5076458 : MooseMesh::minPeriodicDistance(const unsigned int sys_num,
    2316             :                                const unsigned int var_num,
    2317             :                                const Point & p,
    2318             :                                const Point & q) const
    2319             : {
    2320     5076458 :   return minPeriodicVector(sys_num, var_num, p, q).norm();
    2321             : }
    2322             : 
    2323             : Real
    2324       25600 : MooseMesh::minPeriodicDistance(const MooseVariableBase & var,
    2325             :                                const Point & p,
    2326             :                                const Point & q) const
    2327             : {
    2328       25600 :   return minPeriodicDistance(var.sys().number(), var.number(), p, q);
    2329             : }
    2330             : 
    2331             : Real
    2332           0 : MooseMesh::minPeriodicDistance(const unsigned int var_num, const Point & p, const Point & q) const
    2333             : {
    2334           0 :   mooseDoOnce(mooseDeprecated("MooseMesh::minPeriodicDistance(const unsigned int, const Point &, "
    2335             :                               "const Point &) is deprecated. Use the method that additionally "
    2336             :                               "takes the system number or the MooseVariableBase instead."));
    2337           0 :   return minPeriodicDistance(0, var_num, p, q);
    2338             : }
    2339             : 
    2340             : const std::pair<BoundaryID, BoundaryID> *
    2341        2383 : MooseMesh::getPairedBoundaryMapping(unsigned int component) const
    2342             : {
    2343        2383 :   if (!_regular_orthogonal_mesh)
    2344           0 :     mooseError("Trying to retrieve automatic paired mapping for a mesh that is not regular and "
    2345             :                "orthogonal");
    2346             : 
    2347             :   mooseAssert(component < dimension(), "Requested dimension out of bounds");
    2348             : 
    2349        2383 :   if (!hasDetectedPairedSidesets())
    2350           0 :     mooseError("MooseMesh::getPairedBoundaryMapping(): Paired boundaries not built; must call "
    2351             :                "detectPairedSidesets() first");
    2352             : 
    2353        2383 :   if (component < _paired_boundary->size())
    2354        2380 :     return &(*_paired_boundary)[component];
    2355             :   else
    2356           3 :     return nullptr;
    2357             : }
    2358             : 
    2359             : void
    2360          33 : MooseMesh::buildHRefinementAndCoarseningMaps(Assembly * const assembly)
    2361             : {
    2362          33 :   std::map<ElemType, Elem *> canonical_elems;
    2363             : 
    2364             :   // First, loop over all elements and find a canonical element for each type
    2365             :   // Doing it this way guarantees that this is going to work in parallel
    2366       19937 :   for (const auto & elem : getMesh().element_ptr_range()) // TODO: Thread this
    2367             :   {
    2368        9952 :     ElemType type = elem->type();
    2369             : 
    2370        9952 :     if (canonical_elems.find(type) ==
    2371       19904 :         canonical_elems.end()) // If we haven't seen this type of elem before save it
    2372          42 :       canonical_elems[type] = elem;
    2373             :     else
    2374             :     {
    2375        9910 :       Elem * stored = canonical_elems[type];
    2376        9910 :       if (elem->id() < stored->id()) // Arbitrarily keep the one with a lower id
    2377           0 :         canonical_elems[type] = elem;
    2378             :     }
    2379          33 :   }
    2380             :   // Now build the maps using these templates
    2381             :   // Note: This MUST be done NOT threaded!
    2382          75 :   for (const auto & can_it : canonical_elems)
    2383             :   {
    2384          42 :     Elem * elem = can_it.second;
    2385             : 
    2386             :     // Need to do this just once to get the right qrules put in place
    2387          42 :     assembly->setCurrentSubdomainID(elem->subdomain_id());
    2388          42 :     assembly->reinit(elem);
    2389          42 :     assembly->reinit(elem, 0);
    2390          42 :     auto && qrule = assembly->writeableQRule();
    2391          42 :     auto && qrule_face = assembly->writeableQRuleFace();
    2392             : 
    2393             :     // Volume to volume projection for refinement
    2394          42 :     buildRefinementMap(*elem, *qrule, *qrule_face, -1, -1, -1);
    2395             : 
    2396             :     // Volume to volume projection for coarsening
    2397          42 :     buildCoarseningMap(*elem, *qrule, *qrule_face, -1);
    2398             : 
    2399             :     // Map the sides of children
    2400         216 :     for (unsigned int side = 0; side < elem->n_sides(); side++)
    2401             :     {
    2402             :       // Side to side for sides that match parent's sides
    2403         174 :       buildRefinementMap(*elem, *qrule, *qrule_face, side, -1, side);
    2404         174 :       buildCoarseningMap(*elem, *qrule, *qrule_face, side);
    2405             :     }
    2406             : 
    2407             :     // Child side to parent volume mapping for "internal" child sides
    2408         240 :     for (unsigned int child = 0; child < elem->n_children(); ++child)
    2409        1146 :       for (unsigned int side = 0; side < elem->n_sides();
    2410             :            ++side)                                // Assume children have the same number of sides!
    2411         948 :         if (!elem->is_child_on_side(child, side)) // Otherwise we already computed that map
    2412         474 :           buildRefinementMap(*elem, *qrule, *qrule_face, -1, child, side);
    2413             :   }
    2414          33 : }
    2415             : 
    2416             : void
    2417          90 : MooseMesh::buildPRefinementAndCoarseningMaps(Assembly * const assembly)
    2418             : {
    2419          90 :   _elem_type_to_p_refinement_map.clear();
    2420          90 :   _elem_type_to_p_refinement_side_map.clear();
    2421          90 :   _elem_type_to_p_coarsening_map.clear();
    2422          90 :   _elem_type_to_p_coarsening_side_map.clear();
    2423             : 
    2424          90 :   std::map<ElemType, std::pair<Elem *, unsigned int>> elems_and_max_p_level;
    2425             : 
    2426       32218 :   for (const auto & elem : getMesh().active_element_ptr_range())
    2427             :   {
    2428       32128 :     const auto type = elem->type();
    2429       32128 :     auto & [picked_elem, max_p_level] = elems_and_max_p_level[type];
    2430       32128 :     if (!picked_elem)
    2431          90 :       picked_elem = elem;
    2432       32128 :     max_p_level = std::max(max_p_level, elem->p_level());
    2433          90 :   }
    2434             : 
    2435             :   // The only requirement on the FEType is that it can be arbitrarily p-refined
    2436          90 :   const FEType p_refinable_fe_type(CONSTANT, libMesh::MONOMIAL);
    2437          90 :   std::vector<Point> volume_ref_points_coarse, volume_ref_points_fine, face_ref_points_coarse,
    2438          90 :       face_ref_points_fine;
    2439          90 :   std::vector<unsigned int> p_levels;
    2440             : 
    2441         180 :   for (auto & [elem_type, elem_p_level_pair] : elems_and_max_p_level)
    2442             :   {
    2443          90 :     auto & [moose_elem, max_p_level] = elem_p_level_pair;
    2444          90 :     const auto dim = moose_elem->dim();
    2445             :     // Need to do this just once to get the right qrules put in place
    2446          90 :     assembly->setCurrentSubdomainID(moose_elem->subdomain_id());
    2447          90 :     assembly->reinit(moose_elem);
    2448          90 :     assembly->reinit(moose_elem, 0);
    2449          90 :     auto & qrule = assembly->writeableQRule();
    2450          90 :     auto & qrule_face = assembly->writeableQRuleFace();
    2451             : 
    2452          90 :     libMesh::Parallel::Communicator self_comm{};
    2453          90 :     ReplicatedMesh mesh(self_comm);
    2454          90 :     mesh.set_mesh_dimension(dim);
    2455         630 :     for (const auto & nd : moose_elem->node_ref_range())
    2456         540 :       mesh.add_point(nd);
    2457             : 
    2458          90 :     Elem * const elem = mesh.add_elem(Elem::build(elem_type).release());
    2459         630 :     for (const auto i : elem->node_index_range())
    2460         540 :       elem->set_node(i, mesh.node_ptr(i));
    2461             : 
    2462          90 :     std::unique_ptr<FEBase> fe_face(FEBase::build(dim, p_refinable_fe_type));
    2463          90 :     fe_face->get_phi();
    2464          90 :     const auto & face_phys_points = fe_face->get_xyz();
    2465          90 :     fe_face->attach_quadrature_rule(qrule_face);
    2466             : 
    2467          90 :     qrule->init(*elem);
    2468          90 :     volume_ref_points_coarse = qrule->get_points();
    2469          90 :     fe_face->reinit(elem, (unsigned int)0);
    2470          90 :     libMesh::FEMap::inverse_map(dim, elem, face_phys_points, face_ref_points_coarse);
    2471             : 
    2472          90 :     p_levels.resize(max_p_level + 1);
    2473          90 :     std::iota(p_levels.begin(), p_levels.end(), 0);
    2474          90 :     libMesh::MeshRefinement mesh_refinement(mesh);
    2475             : 
    2476         306 :     for (const auto p_level : p_levels)
    2477             :     {
    2478         216 :       mesh_refinement.uniformly_p_refine(1);
    2479         216 :       qrule->init(*elem);
    2480         216 :       volume_ref_points_fine = qrule->get_points();
    2481         216 :       fe_face->reinit(elem, (unsigned int)0);
    2482         216 :       libMesh::FEMap::inverse_map(dim, elem, face_phys_points, face_ref_points_fine);
    2483             : 
    2484         216 :       const auto map_key = std::make_pair(elem_type, p_level);
    2485         216 :       auto & volume_refine_map = _elem_type_to_p_refinement_map[map_key];
    2486         216 :       auto & face_refine_map = _elem_type_to_p_refinement_side_map[map_key];
    2487         216 :       auto & volume_coarsen_map = _elem_type_to_p_coarsening_map[map_key];
    2488         216 :       auto & face_coarsen_map = _elem_type_to_p_coarsening_side_map[map_key];
    2489             : 
    2490         432 :       auto fill_maps = [this](const auto & coarse_ref_points,
    2491             :                               const auto & fine_ref_points,
    2492             :                               auto & coarsen_map,
    2493             :                               auto & refine_map)
    2494             :       {
    2495         432 :         mapPoints(fine_ref_points, coarse_ref_points, refine_map);
    2496         432 :         mapPoints(coarse_ref_points, fine_ref_points, coarsen_map);
    2497         648 :       };
    2498             : 
    2499         216 :       fill_maps(
    2500             :           volume_ref_points_coarse, volume_ref_points_fine, volume_coarsen_map, volume_refine_map);
    2501         216 :       fill_maps(face_ref_points_coarse, face_ref_points_fine, face_coarsen_map, face_refine_map);
    2502             : 
    2503             :       // With this level's maps filled our fine points now become our coarse points
    2504         216 :       volume_ref_points_fine.swap(volume_ref_points_coarse);
    2505         216 :       face_ref_points_fine.swap(face_ref_points_coarse);
    2506             :     }
    2507          90 :   }
    2508          90 : }
    2509             : 
    2510             : void
    2511          57 : MooseMesh::buildRefinementAndCoarseningMaps(Assembly * const assembly)
    2512             : {
    2513         285 :   TIME_SECTION("buildRefinementAndCoarseningMaps", 5, "Building Refinement And Coarsening Maps");
    2514          57 :   if (doingPRefinement())
    2515          24 :     buildPRefinementAndCoarseningMaps(assembly);
    2516             :   else
    2517          33 :     buildHRefinementAndCoarseningMaps(assembly);
    2518          57 : }
    2519             : 
    2520             : void
    2521         690 : MooseMesh::buildRefinementMap(const Elem & elem,
    2522             :                               QBase & qrule,
    2523             :                               QBase & qrule_face,
    2524             :                               int parent_side,
    2525             :                               int child,
    2526             :                               int child_side)
    2527             : {
    2528        3450 :   TIME_SECTION("buildRefinementMap", 5, "Building Refinement Map");
    2529             : 
    2530         690 :   if (child == -1) // Doing volume mapping or parent side mapping
    2531             :   {
    2532             :     mooseAssert(parent_side == child_side,
    2533             :                 "Parent side must match child_side if not passing a specific child!");
    2534             : 
    2535         216 :     std::pair<int, ElemType> the_pair(parent_side, elem.type());
    2536             : 
    2537         216 :     if (_elem_type_to_refinement_map.find(the_pair) != _elem_type_to_refinement_map.end())
    2538           0 :       mooseError("Already built a qp refinement map!");
    2539             : 
    2540         216 :     std::vector<std::pair<unsigned int, QpMap>> coarsen_map;
    2541         216 :     std::vector<std::vector<QpMap>> & refinement_map = _elem_type_to_refinement_map[the_pair];
    2542         216 :     findAdaptivityQpMaps(
    2543             :         &elem, qrule, qrule_face, refinement_map, coarsen_map, parent_side, child, child_side);
    2544         216 :   }
    2545             :   else // Need to map a child side to parent volume qps
    2546             :   {
    2547         474 :     std::pair<int, int> child_pair(child, child_side);
    2548             : 
    2549         474 :     if (_elem_type_to_child_side_refinement_map.find(elem.type()) !=
    2550        1380 :             _elem_type_to_child_side_refinement_map.end() &&
    2551         432 :         _elem_type_to_child_side_refinement_map[elem.type()].find(child_pair) !=
    2552         906 :             _elem_type_to_child_side_refinement_map[elem.type()].end())
    2553           0 :       mooseError("Already built a qp refinement map!");
    2554             : 
    2555         474 :     std::vector<std::pair<unsigned int, QpMap>> coarsen_map;
    2556             :     std::vector<std::vector<QpMap>> & refinement_map =
    2557         474 :         _elem_type_to_child_side_refinement_map[elem.type()][child_pair];
    2558         474 :     findAdaptivityQpMaps(
    2559             :         &elem, qrule, qrule_face, refinement_map, coarsen_map, parent_side, child, child_side);
    2560         474 :   }
    2561         690 : }
    2562             : 
    2563             : const std::vector<std::vector<QpMap>> &
    2564        3422 : MooseMesh::getRefinementMap(const Elem & elem, int parent_side, int child, int child_side)
    2565             : {
    2566        3422 :   if (child == -1) // Doing volume mapping or parent side mapping
    2567             :   {
    2568             :     mooseAssert(parent_side == child_side,
    2569             :                 "Parent side must match child_side if not passing a specific child!");
    2570             : 
    2571        3422 :     std::pair<int, ElemType> the_pair(parent_side, elem.type());
    2572             : 
    2573        3422 :     if (_elem_type_to_refinement_map.find(the_pair) == _elem_type_to_refinement_map.end())
    2574           0 :       mooseError("Could not find a suitable qp refinement map!");
    2575             : 
    2576        3422 :     return _elem_type_to_refinement_map[the_pair];
    2577             :   }
    2578             :   else // Need to map a child side to parent volume qps
    2579             :   {
    2580           0 :     std::pair<int, int> child_pair(child, child_side);
    2581             : 
    2582           0 :     if (_elem_type_to_child_side_refinement_map.find(elem.type()) ==
    2583           0 :             _elem_type_to_child_side_refinement_map.end() ||
    2584           0 :         _elem_type_to_child_side_refinement_map[elem.type()].find(child_pair) ==
    2585           0 :             _elem_type_to_child_side_refinement_map[elem.type()].end())
    2586           0 :       mooseError("Could not find a suitable qp refinement map!");
    2587             : 
    2588           0 :     return _elem_type_to_child_side_refinement_map[elem.type()][child_pair];
    2589             :   }
    2590             : 
    2591             :   /**
    2592             :    *  TODO: When running with parallel mesh + stateful adaptivty we will need to make sure that each
    2593             :    *  processor has a complete map.  This may require parallel communication.  This is likely to
    2594             :    * happen
    2595             :    *  when running on a mixed element mesh.
    2596             :    */
    2597             : }
    2598             : 
    2599             : void
    2600         216 : MooseMesh::buildCoarseningMap(const Elem & elem, QBase & qrule, QBase & qrule_face, int input_side)
    2601             : {
    2602        1080 :   TIME_SECTION("buildCoarseningMap", 5, "Building Coarsening Map");
    2603             : 
    2604         216 :   std::pair<int, ElemType> the_pair(input_side, elem.type());
    2605             : 
    2606         216 :   if (_elem_type_to_coarsening_map.find(the_pair) != _elem_type_to_coarsening_map.end())
    2607           0 :     mooseError("Already built a qp coarsening map!");
    2608             : 
    2609         216 :   std::vector<std::vector<QpMap>> refinement_map;
    2610             :   std::vector<std::pair<unsigned int, QpMap>> & coarsen_map =
    2611         216 :       _elem_type_to_coarsening_map[the_pair];
    2612             : 
    2613             :   // The -1 here is for a specific child.  We don't do that for coarsening maps
    2614             :   // Also note that we're always mapping the same side to the same side (which is guaranteed by
    2615             :   // libMesh).
    2616         216 :   findAdaptivityQpMaps(
    2617             :       &elem, qrule, qrule_face, refinement_map, coarsen_map, input_side, -1, input_side);
    2618             : 
    2619             :   /**
    2620             :    *  TODO: When running with parallel mesh + stateful adaptivty we will need to make sure that each
    2621             :    *  processor has a complete map.  This may require parallel communication.  This is likely to
    2622             :    * happen
    2623             :    *  when running on a mixed element mesh.
    2624             :    */
    2625         216 : }
    2626             : 
    2627             : const std::vector<std::pair<unsigned int, QpMap>> &
    2628        1288 : MooseMesh::getCoarseningMap(const Elem & elem, int input_side)
    2629             : {
    2630        1288 :   std::pair<int, ElemType> the_pair(input_side, elem.type());
    2631             : 
    2632        1288 :   if (_elem_type_to_coarsening_map.find(the_pair) == _elem_type_to_coarsening_map.end())
    2633           0 :     mooseError("Could not find a suitable qp refinement map!");
    2634             : 
    2635        2576 :   return _elem_type_to_coarsening_map[the_pair];
    2636             : }
    2637             : 
    2638             : void
    2639        7038 : MooseMesh::mapPoints(const std::vector<Point> & from,
    2640             :                      const std::vector<Point> & to,
    2641             :                      std::vector<QpMap> & qp_map)
    2642             : {
    2643        7038 :   unsigned int n_from = from.size();
    2644        7038 :   unsigned int n_to = to.size();
    2645             : 
    2646        7038 :   qp_map.resize(n_from);
    2647             : 
    2648       61340 :   for (unsigned int i = 0; i < n_from; ++i)
    2649             :   {
    2650       54302 :     const Point & from_point = from[i];
    2651             : 
    2652       54302 :     QpMap & current_map = qp_map[i];
    2653             : 
    2654     1247054 :     for (unsigned int j = 0; j < n_to; ++j)
    2655             :     {
    2656     1192752 :       const Point & to_point = to[j];
    2657     1192752 :       Real distance = (from_point - to_point).norm();
    2658             : 
    2659     1192752 :       if (distance < current_map._distance)
    2660             :       {
    2661      167558 :         current_map._distance = distance;
    2662      167558 :         current_map._from = i;
    2663      167558 :         current_map._to = j;
    2664             :       }
    2665             :     }
    2666             :   }
    2667        7038 : }
    2668             : 
    2669             : void
    2670         906 : MooseMesh::findAdaptivityQpMaps(const Elem * template_elem,
    2671             :                                 QBase & qrule,
    2672             :                                 QBase & qrule_face,
    2673             :                                 std::vector<std::vector<QpMap>> & refinement_map,
    2674             :                                 std::vector<std::pair<unsigned int, QpMap>> & coarsen_map,
    2675             :                                 int parent_side,
    2676             :                                 int child,
    2677             :                                 int child_side)
    2678             : {
    2679        2718 :   TIME_SECTION("findAdaptivityQpMaps", 5);
    2680             : 
    2681         906 :   ReplicatedMesh mesh(_communicator);
    2682         906 :   mesh.skip_partitioning(true);
    2683             : 
    2684         906 :   unsigned int dim = template_elem->dim();
    2685         906 :   mesh.set_mesh_dimension(dim);
    2686             : 
    2687        7092 :   for (unsigned int i = 0; i < template_elem->n_nodes(); ++i)
    2688        6186 :     mesh.add_point(template_elem->point(i));
    2689             : 
    2690         906 :   Elem * elem = mesh.add_elem(Elem::build(template_elem->type()).release());
    2691             : 
    2692        7092 :   for (unsigned int i = 0; i < template_elem->n_nodes(); ++i)
    2693        6186 :     elem->set_node(i, mesh.node_ptr(i));
    2694             : 
    2695         906 :   std::unique_ptr<FEBase> fe(FEBase::build(dim, FEType()));
    2696         906 :   fe->get_phi();
    2697         906 :   const std::vector<Point> & q_points_volume = fe->get_xyz();
    2698             : 
    2699         906 :   std::unique_ptr<FEBase> fe_face(FEBase::build(dim, FEType()));
    2700         906 :   fe_face->get_phi();
    2701         906 :   const std::vector<Point> & q_points_face = fe_face->get_xyz();
    2702             : 
    2703         906 :   fe->attach_quadrature_rule(&qrule);
    2704         906 :   fe_face->attach_quadrature_rule(&qrule_face);
    2705             : 
    2706             :   // The current q_points (locations in *physical* space)
    2707             :   const std::vector<Point> * q_points;
    2708             : 
    2709         906 :   if (parent_side != -1)
    2710             :   {
    2711         348 :     fe_face->reinit(elem, parent_side);
    2712         348 :     q_points = &q_points_face;
    2713             :   }
    2714             :   else
    2715             :   {
    2716         558 :     fe->reinit(elem);
    2717         558 :     q_points = &q_points_volume;
    2718             :   }
    2719             : 
    2720         906 :   std::vector<Point> parent_ref_points;
    2721             : 
    2722         906 :   libMesh::FEMap::inverse_map(elem->dim(), elem, *q_points, parent_ref_points);
    2723         906 :   libMesh::MeshRefinement mesh_refinement(mesh);
    2724         906 :   mesh_refinement.uniformly_refine(1);
    2725             : 
    2726             :   // A map from the child element index to the locations of all the child's quadrature points in
    2727             :   // *reference* space. Note that we use a map here instead of a vector because the caller can
    2728             :   // pass an explicit child index. We are not guaranteed to have a sequence from [0, n_children)
    2729         906 :   std::map<unsigned int, std::vector<Point>> child_to_ref_points;
    2730             : 
    2731         906 :   unsigned int n_children = elem->n_children();
    2732             : 
    2733         906 :   refinement_map.resize(n_children);
    2734             : 
    2735         906 :   std::vector<unsigned int> children;
    2736             : 
    2737         906 :   if (child != -1) // Passed in a child explicitly
    2738         474 :     children.push_back(child);
    2739             :   else
    2740             :   {
    2741         432 :     children.resize(n_children);
    2742        2724 :     for (unsigned int child = 0; child < n_children; ++child)
    2743        2292 :       children[child] = child;
    2744             :   }
    2745             : 
    2746        3672 :   for (unsigned int i = 0; i < children.size(); ++i)
    2747             :   {
    2748        2766 :     unsigned int child = children[i];
    2749             : 
    2750        2766 :     if ((parent_side != -1 && !elem->is_child_on_side(child, parent_side)))
    2751         948 :       continue;
    2752             : 
    2753        1818 :     const Elem * child_elem = elem->child_ptr(child);
    2754             : 
    2755        1818 :     if (child_side != -1)
    2756             :     {
    2757        1422 :       fe_face->reinit(child_elem, child_side);
    2758        1422 :       q_points = &q_points_face;
    2759             :     }
    2760             :     else
    2761             :     {
    2762         396 :       fe->reinit(child_elem);
    2763         396 :       q_points = &q_points_volume;
    2764             :     }
    2765             : 
    2766        1818 :     std::vector<Point> child_ref_points;
    2767             : 
    2768        1818 :     libMesh::FEMap::inverse_map(elem->dim(), elem, *q_points, child_ref_points);
    2769        1818 :     child_to_ref_points[child] = child_ref_points;
    2770             : 
    2771        1818 :     std::vector<QpMap> & qp_map = refinement_map[child];
    2772             : 
    2773             :     // Find the closest parent_qp to each child_qp
    2774        1818 :     mapPoints(child_ref_points, parent_ref_points, qp_map);
    2775        1818 :   }
    2776             : 
    2777         906 :   coarsen_map.resize(parent_ref_points.size());
    2778             : 
    2779             :   // For each parent qp find the closest child qp
    2780        6210 :   for (unsigned int child = 0; child < n_children; child++)
    2781             :   {
    2782        5304 :     if (parent_side != -1 && !elem->is_child_on_side(child, child_side))
    2783         948 :       continue;
    2784             : 
    2785        4356 :     std::vector<Point> & child_ref_points = child_to_ref_points[child];
    2786             : 
    2787        4356 :     std::vector<QpMap> qp_map;
    2788             : 
    2789             :     // Find all of the closest points from parent_qp to _THIS_ child's qp
    2790        4356 :     mapPoints(parent_ref_points, child_ref_points, qp_map);
    2791             : 
    2792             :     // Check those to see if they are closer than what we currently have for each point
    2793       32856 :     for (unsigned int parent_qp = 0; parent_qp < parent_ref_points.size(); ++parent_qp)
    2794             :     {
    2795       28500 :       std::pair<unsigned int, QpMap> & child_and_map = coarsen_map[parent_qp];
    2796       28500 :       unsigned int & closest_child = child_and_map.first;
    2797       28500 :       QpMap & closest_map = child_and_map.second;
    2798             : 
    2799       28500 :       QpMap & current_map = qp_map[parent_qp];
    2800             : 
    2801       28500 :       if (current_map._distance < closest_map._distance)
    2802             :       {
    2803        6300 :         closest_child = child;
    2804        6300 :         closest_map = current_map;
    2805             :       }
    2806             :     }
    2807        4356 :   }
    2808         906 : }
    2809             : 
    2810             : void
    2811           0 : MooseMesh::changeBoundaryId(const boundary_id_type old_id,
    2812             :                             const boundary_id_type new_id,
    2813             :                             bool delete_prev)
    2814             : {
    2815           0 :   TIME_SECTION("changeBoundaryId", 6);
    2816           0 :   changeBoundaryId(getMesh(), old_id, new_id, delete_prev);
    2817           0 : }
    2818             : 
    2819             : void
    2820           0 : MooseMesh::changeBoundaryId(MeshBase & mesh,
    2821             :                             const boundary_id_type old_id,
    2822             :                             const boundary_id_type new_id,
    2823             :                             bool delete_prev)
    2824             : {
    2825             :   // Get a reference to our BoundaryInfo object, we will use it several times below...
    2826           0 :   BoundaryInfo & boundary_info = mesh.get_boundary_info();
    2827             : 
    2828             :   // Container to catch ids passed back from BoundaryInfo
    2829           0 :   std::vector<boundary_id_type> old_ids;
    2830             : 
    2831             :   // Only level-0 elements store BCs.  Loop over them.
    2832           0 :   for (auto & elem : as_range(mesh.level_elements_begin(0), mesh.level_elements_end(0)))
    2833             :   {
    2834           0 :     unsigned int n_sides = elem->n_sides();
    2835           0 :     for (unsigned int s = 0; s != n_sides; ++s)
    2836             :     {
    2837           0 :       boundary_info.boundary_ids(elem, s, old_ids);
    2838           0 :       if (std::find(old_ids.begin(), old_ids.end(), old_id) != old_ids.end())
    2839             :       {
    2840           0 :         std::vector<boundary_id_type> new_ids(old_ids);
    2841           0 :         std::replace(new_ids.begin(), new_ids.end(), old_id, new_id);
    2842           0 :         if (delete_prev)
    2843             :         {
    2844           0 :           boundary_info.remove_side(elem, s);
    2845           0 :           boundary_info.add_side(elem, s, new_ids);
    2846             :         }
    2847             :         else
    2848           0 :           boundary_info.add_side(elem, s, new_ids);
    2849           0 :       }
    2850             :     }
    2851           0 :   }
    2852             : 
    2853             :   // Remove any remaining references to the old ID from the
    2854             :   // BoundaryInfo object.  This prevents things like empty sidesets
    2855             :   // from showing up when printing information, etc.
    2856           0 :   if (delete_prev)
    2857           0 :     boundary_info.remove_id(old_id);
    2858             : 
    2859             :   // The cached boundary id sets will need re-preparation
    2860           0 :   mesh.unset_has_boundary_id_sets();
    2861           0 : }
    2862             : 
    2863             : const RealVectorValue &
    2864           0 : MooseMesh::getNormalByBoundaryID(BoundaryID id) const
    2865             : {
    2866             :   mooseAssert(_boundary_to_normal_map.get() != nullptr, "Boundary To Normal Map not built!");
    2867             : 
    2868             :   // Note: Boundaries that are not in the map (existing boundaries) will default
    2869             :   // construct a new RealVectorValue - (x,y,z)=(0, 0, 0)
    2870           0 :   return (*_boundary_to_normal_map)[id];
    2871             : }
    2872             : 
    2873             : MooseMesh &
    2874           0 : MooseMesh::clone() const
    2875             : {
    2876           0 :   mooseError("MooseMesh::clone() is no longer supported, use MooseMesh::safeClone() instead.");
    2877             : }
    2878             : 
    2879             : void
    2880       73957 : MooseMesh::determineUseDistributedMesh()
    2881             : {
    2882       73957 :   switch (_parallel_type)
    2883             :   {
    2884       69095 :     case ParallelType::DEFAULT:
    2885             :       // The user did not specify 'parallel_type = XYZ' in the input file,
    2886             :       // so we allow the --distributed-mesh command line arg to possibly turn
    2887             :       // on DistributedMesh.  If the command line arg is not present, we pick ReplicatedMesh.
    2888       69095 :       if (_app.getDistributedMeshOnCommandLine())
    2889       10810 :         _use_distributed_mesh = true;
    2890       69095 :       break;
    2891        3515 :     case ParallelType::REPLICATED:
    2892        3515 :       if (_app.getDistributedMeshOnCommandLine() || _is_nemesis || _is_split)
    2893         741 :         _parallel_type_overridden = true;
    2894        3515 :       _use_distributed_mesh = false;
    2895        3515 :       break;
    2896        1347 :     case ParallelType::DISTRIBUTED:
    2897        1347 :       _use_distributed_mesh = true;
    2898        1347 :       break;
    2899             :   }
    2900             : 
    2901             :   // If the user specifies 'nemesis = true' in the Mesh block, or they are using --use-split,
    2902             :   // we must use DistributedMesh.
    2903       73957 :   if (_is_nemesis || _is_split)
    2904         562 :     _use_distributed_mesh = true;
    2905       73957 : }
    2906             : 
    2907             : std::unique_ptr<MeshBase>
    2908       69197 : MooseMesh::buildMeshBaseObject(unsigned int dim)
    2909             : {
    2910       69197 :   std::unique_ptr<MeshBase> mesh;
    2911       69197 :   if (_use_distributed_mesh)
    2912       10847 :     mesh = buildTypedMesh<DistributedMesh>(dim);
    2913             :   else
    2914       58350 :     mesh = buildTypedMesh<ReplicatedMesh>(dim);
    2915             : 
    2916       69197 :   return mesh;
    2917           0 : }
    2918             : 
    2919             : void
    2920       66123 : MooseMesh::setMeshBase(std::unique_ptr<MeshBase> mesh_base)
    2921             : {
    2922       66123 :   _mesh = std::move(mesh_base);
    2923       66123 :   _mesh->allow_remote_element_removal(_allow_remote_element_removal);
    2924       66123 : }
    2925             : 
    2926             : void
    2927       65635 : MooseMesh::init()
    2928             : {
    2929             :   /**
    2930             :    * If the mesh base hasn't been constructed by the time init is called, just do it here.
    2931             :    * This can happen if somebody builds a mesh outside of the normal Action system. Forcing
    2932             :    * developers to create, construct the MeshBase, and then init separately is a bit much for casual
    2933             :    * use but it gives us the ability to run MeshGenerators in-between.
    2934             :    */
    2935       65635 :   if (!_mesh)
    2936          10 :     _mesh = buildMeshBaseObject();
    2937             : 
    2938       65635 :   if (_app.isSplitMesh() && _use_distributed_mesh)
    2939           0 :     mooseError("You cannot use the mesh splitter capability with DistributedMesh!");
    2940             : 
    2941      196905 :   TIME_SECTION("init", 2);
    2942             : 
    2943       65635 :   if (_app.isRecovering() && _allow_recovery && _app.isUltimateMaster())
    2944             :   {
    2945             :     // Some partitioners are not idempotent.  Some recovery data
    2946             :     // files require partitioning to match mesh partitioning.  This
    2947             :     // means that, when recovering, we can't safely repartition.
    2948        3324 :     const bool skip_partitioning_later = getMesh().skip_partitioning();
    2949        3324 :     getMesh().skip_partitioning(true);
    2950        3324 :     const bool allow_renumbering_later = getMesh().allow_renumbering();
    2951        3324 :     getMesh().allow_renumbering(false);
    2952             : 
    2953             :     // For now, only read the recovery mesh on the Ultimate Master..
    2954             :     // sub-apps need to just build their mesh like normal
    2955             :     {
    2956        9972 :       TIME_SECTION("readRecoveredMesh", 2);
    2957        3324 :       getMesh().read(_app.getRestartRecoverFileBase() + MooseApp::checkpointSuffix());
    2958        3324 :     }
    2959             : 
    2960        3324 :     getMesh().allow_renumbering(allow_renumbering_later);
    2961        3324 :     getMesh().skip_partitioning(skip_partitioning_later);
    2962             :   }
    2963             :   else // Normally just build the mesh
    2964             :   {
    2965             :     // Don't allow partitioning during building
    2966       62311 :     if (_app.isSplitMesh())
    2967          89 :       getMesh().skip_partitioning(true);
    2968       62311 :     buildMesh();
    2969             : 
    2970      186915 :     if (getParam<bool>("build_all_side_lowerd_mesh"))
    2971         205 :       buildLowerDMesh();
    2972             :   }
    2973       65629 : }
    2974             : 
    2975             : unsigned int
    2976    91565110 : MooseMesh::dimension() const
    2977             : {
    2978    91565110 :   return getMesh().mesh_dimension();
    2979             : }
    2980             : 
    2981             : unsigned int
    2982       37754 : MooseMesh::effectiveSpatialDimension() const
    2983             : {
    2984       37754 :   const Real abs_zero = 1e-12;
    2985             : 
    2986             :   // See if the mesh is completely containd in the z and y planes to calculate effective spatial
    2987             :   // dim
    2988       69595 :   for (unsigned int dim = LIBMESH_DIM; dim >= 1; --dim)
    2989       69595 :     if (dimensionWidth(dim - 1) >= abs_zero)
    2990       37754 :       return dim;
    2991             : 
    2992             :   // If we get here, we have a 1D mesh on the x-axis.
    2993           0 :   return 1;
    2994             : }
    2995             : 
    2996             : unsigned int
    2997       89958 : MooseMesh::getBlocksMaxDimension(const std::vector<SubdomainName> & blocks) const
    2998             : {
    2999       89958 :   const auto & mesh = getMesh();
    3000             : 
    3001             :   // Take a shortcut if possible
    3002       89958 :   if (const auto & elem_dims = mesh.elem_dimensions(); mesh.is_prepared() && elem_dims.size() == 1)
    3003       78814 :     return *elem_dims.begin();
    3004             : 
    3005       11144 :   unsigned short dim = 0;
    3006       11144 :   const auto subdomain_ids = getSubdomainIDs(blocks);
    3007       11144 :   const std::set<SubdomainID> subdomain_ids_set(subdomain_ids.begin(), subdomain_ids.end());
    3008     2328536 :   for (const auto & elem : mesh.active_subdomain_set_elements_ptr_range(subdomain_ids_set))
    3009     2328536 :     dim = std::max(dim, elem->dim());
    3010             : 
    3011             :   // Get the maximumal globally
    3012       11144 :   _communicator.max(dim);
    3013       11144 :   return dim;
    3014       11144 : }
    3015             : 
    3016             : std::vector<BoundaryID>
    3017   106423470 : MooseMesh::getBoundaryIDs(const Elem * const elem, const unsigned short int side) const
    3018             : {
    3019   106423470 :   std::vector<BoundaryID> ids;
    3020   106423470 :   getMesh().get_boundary_info().boundary_ids(elem, side, ids);
    3021   106423470 :   return ids;
    3022           0 : }
    3023             : 
    3024             : std::vector<std::vector<BoundaryID>>
    3025   406957866 : MooseMesh::getBoundaryIDs(const Elem * const elem) const
    3026             : {
    3027   406957866 :   std::vector<std::vector<BoundaryID>> ids;
    3028   406957866 :   getMesh().get_boundary_info().side_boundary_ids(elem, ids);
    3029   406957866 :   return ids;
    3030           0 : }
    3031             : 
    3032             : const std::set<BoundaryID> &
    3033      506742 : MooseMesh::getBoundaryIDs() const
    3034             : {
    3035      506742 :   return getMesh().get_boundary_info().get_boundary_ids();
    3036             : }
    3037             : 
    3038             : void
    3039      223483 : MooseMesh::buildNodeListFromSideList()
    3040             : {
    3041      223483 :   auto & boundary_info = getMesh().get_boundary_info();
    3042             : 
    3043      223483 :   if (_construct_node_list_from_side_list)
    3044             :   {
    3045      223457 :     const std::set<boundary_id_type> & side_bcids = boundary_info.get_side_boundary_ids();
    3046             : 
    3047      223457 :     if (_displace_node_list_by_side_list)
    3048             :     {
    3049             :       // Don't want to use auto here - the rbegin trick relies on a
    3050             :       // sorted set and we want the compiler to scream if libMesh ever
    3051             :       // switches type
    3052      223457 :       const std::set<boundary_id_type> & node_bcids = boundary_info.get_node_boundary_ids();
    3053             : 
    3054             :       // If we've got a reasonable largest BC id, we can just use the
    3055             :       // subsequent unused ones
    3056      223457 :       boundary_id_type next_bcid = 0;
    3057      223457 :       if (!node_bcids.empty())
    3058      215055 :         next_bcid = std::max(next_bcid, cast_int<boundary_id_type>(*node_bcids.rbegin() + 1));
    3059      223457 :       if (!side_bcids.empty())
    3060      218520 :         next_bcid = std::max(next_bcid, cast_int<boundary_id_type>(*side_bcids.rbegin() + 1));
    3061             : 
    3062             :       // We need all processors to agree on the id to use, even when
    3063             :       // each only sees the bcids on their own portions of a
    3064             :       // distributed mesh.
    3065      223457 :       _communicator.max(next_bcid);
    3066             : 
    3067             :       // If we've got an unreasonably high largest BC id, we should
    3068             :       // probably just search for unused ones with moderate values, so we
    3069             :       // don't risk wrapping.
    3070      223457 :       if (next_bcid > 1000 || next_bcid <= 0)
    3071        3047 :         next_bcid = 1000;
    3072             : 
    3073             :       // If any side bcid is already a node bcid with a different name,
    3074             :       // that's a different boundary condition that we need to reassign
    3075             :       // rather than overwrite or merge to.
    3076     1077091 :       for (auto bcid : side_bcids)
    3077     1675166 :         if (node_bcids.count(bcid) &&
    3078      821532 :             (boundary_info.get_sideset_name(bcid) != boundary_info.get_nodeset_name(bcid)))
    3079             :         {
    3080        2002 :           boundary_info.renumber_node_id(bcid, next_bcid);
    3081             :           do
    3082             :           {
    3083        2012 :             ++next_bcid;
    3084        2012 :           } while (node_bcids.count(next_bcid) || side_bcids.count(next_bcid));
    3085             :         }
    3086             :     }
    3087             : 
    3088             :     // For any side bcid that has a name, make sure that our new node
    3089             :     // bcid is given the same name.  We need to iterate over the
    3090             :     // actual name map (which is global) here, not over side_bcids
    3091             :     // (which only includes local ids on a distributed mesh).
    3092     1064263 :     for (auto & [id, name] : boundary_info.get_sideset_name_map())
    3093      840806 :       boundary_info.nodeset_name(id) = name;
    3094             : 
    3095      223457 :     boundary_info.build_node_list_from_side_list();
    3096             :   }
    3097      223483 : }
    3098             : 
    3099             : std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>>
    3100         218 : MooseMesh::buildSideList()
    3101             : {
    3102         218 :   return getMesh().get_boundary_info().build_side_list();
    3103             : }
    3104             : 
    3105             : std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>>
    3106        4742 : MooseMesh::buildActiveSideList() const
    3107             : {
    3108        4742 :   return getMesh().get_boundary_info().build_active_side_list();
    3109             : }
    3110             : 
    3111             : unsigned int
    3112       23836 : MooseMesh::sideWithBoundaryID(const Elem * const elem, const BoundaryID boundary_id) const
    3113             : {
    3114       23836 :   return getMesh().get_boundary_info().side_with_boundary_id(elem, boundary_id);
    3115             : }
    3116             : 
    3117             : MeshBase::node_iterator
    3118        3240 : MooseMesh::localNodesBegin()
    3119             : {
    3120        3240 :   return getMesh().local_nodes_begin();
    3121             : }
    3122             : 
    3123             : MeshBase::node_iterator
    3124        3240 : MooseMesh::localNodesEnd()
    3125             : {
    3126        3240 :   return getMesh().local_nodes_end();
    3127             : }
    3128             : 
    3129             : MeshBase::const_node_iterator
    3130           0 : MooseMesh::localNodesBegin() const
    3131             : {
    3132           0 :   return getMesh().local_nodes_begin();
    3133             : }
    3134             : 
    3135             : MeshBase::const_node_iterator
    3136           0 : MooseMesh::localNodesEnd() const
    3137             : {
    3138           0 :   return getMesh().local_nodes_end();
    3139             : }
    3140             : 
    3141             : MeshBase::element_iterator
    3142      148198 : MooseMesh::activeLocalElementsBegin()
    3143             : {
    3144      148198 :   return getMesh().active_local_elements_begin();
    3145             : }
    3146             : 
    3147             : const MeshBase::element_iterator
    3148      148198 : MooseMesh::activeLocalElementsEnd()
    3149             : {
    3150      148198 :   return getMesh().active_local_elements_end();
    3151             : }
    3152             : 
    3153             : MeshBase::const_element_iterator
    3154           0 : MooseMesh::activeLocalElementsBegin() const
    3155             : {
    3156           0 :   return getMesh().active_local_elements_begin();
    3157             : }
    3158             : 
    3159             : const MeshBase::const_element_iterator
    3160           0 : MooseMesh::activeLocalElementsEnd() const
    3161             : {
    3162           0 :   return getMesh().active_local_elements_end();
    3163             : }
    3164             : 
    3165             : dof_id_type
    3166       55223 : MooseMesh::nNodes() const
    3167             : {
    3168       55223 :   return getMesh().n_nodes();
    3169             : }
    3170             : 
    3171             : dof_id_type
    3172        1562 : MooseMesh::nElem() const
    3173             : {
    3174        1562 :   return getMesh().n_elem();
    3175             : }
    3176             : 
    3177             : dof_id_type
    3178           0 : MooseMesh::maxNodeId() const
    3179             : {
    3180           0 :   return getMesh().max_node_id();
    3181             : }
    3182             : 
    3183             : dof_id_type
    3184           0 : MooseMesh::maxElemId() const
    3185             : {
    3186           0 :   return getMesh().max_elem_id();
    3187             : }
    3188             : 
    3189             : Elem *
    3190           0 : MooseMesh::elem(const dof_id_type i)
    3191             : {
    3192           0 :   mooseDeprecated("MooseMesh::elem() is deprecated, please use MooseMesh::elemPtr() instead");
    3193           0 :   return elemPtr(i);
    3194             : }
    3195             : 
    3196             : const Elem *
    3197           0 : MooseMesh::elem(const dof_id_type i) const
    3198             : {
    3199           0 :   mooseDeprecated("MooseMesh::elem() is deprecated, please use MooseMesh::elemPtr() instead");
    3200           0 :   return elemPtr(i);
    3201             : }
    3202             : 
    3203             : Elem *
    3204    15694169 : MooseMesh::elemPtr(const dof_id_type i)
    3205             : {
    3206    15694169 :   return getMesh().elem_ptr(i);
    3207             : }
    3208             : 
    3209             : const Elem *
    3210     1237286 : MooseMesh::elemPtr(const dof_id_type i) const
    3211             : {
    3212     1237286 :   return getMesh().elem_ptr(i);
    3213             : }
    3214             : 
    3215             : Elem *
    3216       21675 : MooseMesh::queryElemPtr(const dof_id_type i)
    3217             : {
    3218       21675 :   return getMesh().query_elem_ptr(i);
    3219             : }
    3220             : 
    3221             : const Elem *
    3222       36374 : MooseMesh::queryElemPtr(const dof_id_type i) const
    3223             : {
    3224       36374 :   return getMesh().query_elem_ptr(i);
    3225             : }
    3226             : 
    3227             : bool
    3228           0 : MooseMesh::prepared() const
    3229             : {
    3230           0 :   return _mesh->is_prepared() && _moose_mesh_prepared;
    3231             : }
    3232             : 
    3233             : void
    3234           0 : MooseMesh::prepared(bool state)
    3235             : {
    3236           0 :   if (state)
    3237           0 :     mooseError("We don't have any right to tell the libmesh mesh that it *is* prepared. Only a "
    3238             :                "call to prepare_for_use should tell us that");
    3239             : 
    3240             :   // Some people may call this even before we have a MeshBase object. This isn't dangerous really
    3241             :   // because when the MeshBase object is born, it knows it's in an unprepared state
    3242           0 :   if (_mesh)
    3243           0 :     _mesh->unset_is_prepared();
    3244             : 
    3245             :   // If the libMesh mesh isn't preparead, then our MooseMesh wrapper is also no longer prepared
    3246           0 :   _moose_mesh_prepared = false;
    3247             : 
    3248             :   /**
    3249             :    * If we are explicitly setting the mesh to not prepared, then we've likely modified the mesh
    3250             :    * and can no longer make assumptions about orthogonality. We really should recheck.
    3251             :    */
    3252           0 :   _regular_orthogonal_mesh = false;
    3253           0 : }
    3254             : 
    3255             : void
    3256           0 : MooseMesh::needsPrepareForUse()
    3257             : {
    3258           0 :   prepared(false);
    3259           0 : }
    3260             : 
    3261             : const std::set<SubdomainID> &
    3262     8046534 : MooseMesh::meshSubdomains() const
    3263             : {
    3264     8046534 :   return _mesh_subdomains;
    3265             : }
    3266             : 
    3267             : const std::set<BoundaryID> &
    3268       11912 : MooseMesh::meshBoundaryIds() const
    3269             : {
    3270       11912 :   return _mesh_boundary_ids;
    3271             : }
    3272             : 
    3273             : const std::set<BoundaryID> &
    3274       29602 : MooseMesh::meshSidesetIds() const
    3275             : {
    3276       29602 :   return _mesh_sideset_ids;
    3277             : }
    3278             : 
    3279             : const std::set<BoundaryID> &
    3280      149063 : MooseMesh::meshNodesetIds() const
    3281             : {
    3282      149063 :   return _mesh_nodeset_ids;
    3283             : }
    3284             : 
    3285             : void
    3286           0 : MooseMesh::setMeshBoundaryIDs(std::set<BoundaryID> boundary_IDs)
    3287             : {
    3288           0 :   _mesh_boundary_ids = boundary_IDs;
    3289           0 : }
    3290             : 
    3291             : void
    3292           0 : MooseMesh::setBoundaryToNormalMap(
    3293             :     std::unique_ptr<std::map<BoundaryID, RealVectorValue>> boundary_map)
    3294             : {
    3295           0 :   _boundary_to_normal_map = std::move(boundary_map);
    3296           0 : }
    3297             : 
    3298             : void
    3299           0 : MooseMesh::setBoundaryToNormalMap(std::map<BoundaryID, RealVectorValue> * boundary_map)
    3300             : {
    3301           0 :   mooseDeprecated("setBoundaryToNormalMap(std::map<BoundaryID, RealVectorValue> * boundary_map) is "
    3302             :                   "deprecated, use the unique_ptr version instead");
    3303           0 :   _boundary_to_normal_map.reset(boundary_map);
    3304           0 : }
    3305             : 
    3306             : unsigned int
    3307      125150 : MooseMesh::uniformRefineLevel() const
    3308             : {
    3309      125150 :   return _uniform_refine_level;
    3310             : }
    3311             : 
    3312             : void
    3313       67651 : MooseMesh::setUniformRefineLevel(unsigned int level, bool deletion)
    3314             : {
    3315       67651 :   _uniform_refine_level = level;
    3316       67651 :   _skip_deletion_repartition_after_refine = deletion;
    3317       67651 : }
    3318             : 
    3319             : void
    3320       56144 : MooseMesh::addGhostedBoundary(BoundaryID boundary_id)
    3321             : {
    3322       56144 :   _ghosted_boundaries.insert(boundary_id);
    3323       56144 : }
    3324             : 
    3325             : void
    3326           0 : MooseMesh::setGhostedBoundaryInflation(const std::vector<Real> & inflation)
    3327             : {
    3328           0 :   _ghosted_boundaries_inflation = inflation;
    3329           0 : }
    3330             : 
    3331             : const std::set<unsigned int> &
    3332           0 : MooseMesh::getGhostedBoundaries() const
    3333             : {
    3334           0 :   return _ghosted_boundaries;
    3335             : }
    3336             : 
    3337             : const std::vector<Real> &
    3338       11484 : MooseMesh::getGhostedBoundaryInflation() const
    3339             : {
    3340       11484 :   return _ghosted_boundaries_inflation;
    3341             : }
    3342             : 
    3343             : namespace // Anonymous namespace for helpers
    3344             : {
    3345             : // A class for templated methods that expect output iterator
    3346             : // arguments, which adds objects to the Mesh.
    3347             : // Although extra_ghost_elem_inserter can add any object, we
    3348             : // template it around object type so that type inference and
    3349             : // iterator_traits will work.
    3350             : // This object specifically is used to insert extra ghost elems into the mesh
    3351             : template <typename T>
    3352             : struct extra_ghost_elem_inserter
    3353             : {
    3354             :   using iterator_category = std::output_iterator_tag;
    3355             :   using value_type = T;
    3356             : 
    3357       44732 :   extra_ghost_elem_inserter(DistributedMesh & m) : mesh(m) {}
    3358             : 
    3359       19101 :   void operator=(const Elem * e) { mesh.add_extra_ghost_elem(const_cast<Elem *>(e)); }
    3360             : 
    3361       35698 :   void operator=(Node * n) { mesh.add_node(n); }
    3362             : 
    3363             :   void operator=(Point * p) { mesh.add_point(*p); }
    3364             : 
    3365             :   extra_ghost_elem_inserter & operator++() { return *this; }
    3366             : 
    3367       54799 :   extra_ghost_elem_inserter operator++(int) { return extra_ghost_elem_inserter(*this); }
    3368             : 
    3369             :   // We don't return a reference-to-T here because we don't want to
    3370             :   // construct one or have any of its methods called.  We just want
    3371             :   // to allow the returned object to be able to do mesh insertions
    3372             :   // with operator=().
    3373       54799 :   extra_ghost_elem_inserter & operator*() { return *this; }
    3374             : 
    3375             : private:
    3376             :   DistributedMesh & mesh;
    3377             : };
    3378             : 
    3379             : /**
    3380             :  * Specific weak ordering for Elem *'s to be used in a set.
    3381             :  * We use the id, but first sort by level.  This guarantees
    3382             :  * when traversing the set from beginning to end the lower
    3383             :  * level (parent) elements are encountered first.
    3384             :  *
    3385             :  * This was swiped from libMesh mesh_communication.C, and ought to be
    3386             :  * replaced with libMesh::CompareElemIdsByLevel just as soon as I refactor to
    3387             :  * create that - @roystgnr
    3388             :  */
    3389             : struct CompareElemsByLevel
    3390             : {
    3391      104881 :   bool operator()(const Elem * a, const Elem * b) const
    3392             :   {
    3393             :     libmesh_assert(a);
    3394             :     libmesh_assert(b);
    3395      104881 :     const unsigned int al = a->level(), bl = b->level();
    3396      104881 :     const dof_id_type aid = a->id(), bid = b->id();
    3397             : 
    3398      104881 :     return (al == bl) ? aid < bid : al < bl;
    3399             :   }
    3400             : };
    3401             : 
    3402             : } // anonymous namespace
    3403             : 
    3404             : void
    3405      138445 : MooseMesh::ghostGhostedBoundaries()
    3406             : {
    3407             :   // No need to do this if using a serial mesh
    3408             :   // We do not need to ghost boundary elements when _need_ghost_ghosted_boundaries
    3409             :   // is not true. _need_ghost_ghosted_boundaries can be set by a mesh generator
    3410             :   // where boundaries are already ghosted accordingly
    3411      138445 :   if (!_use_distributed_mesh || !_need_ghost_ghosted_boundaries)
    3412      116079 :     return;
    3413             : 
    3414       67098 :   TIME_SECTION("GhostGhostedBoundaries", 3);
    3415             : 
    3416             :   parallel_object_only();
    3417             : 
    3418       22366 :   DistributedMesh & mesh = dynamic_cast<DistributedMesh &>(getMesh());
    3419             : 
    3420             :   // We clear ghosted elements that were added by previous invocations of this
    3421             :   // method but leave ghosted elements that were added by other code, e.g.
    3422             :   // OversampleOutput, untouched
    3423       22366 :   mesh.clear_extra_ghost_elems(_ghost_elems_from_ghost_boundaries);
    3424       22366 :   _ghost_elems_from_ghost_boundaries.clear();
    3425             : 
    3426       22366 :   std::set<const Elem *, CompareElemsByLevel> boundary_elems_to_ghost;
    3427       22366 :   std::set<Node *> connected_nodes_to_ghost;
    3428             : 
    3429       22366 :   std::vector<const Elem *> family_tree;
    3430             : 
    3431      902893 :   for (const auto & t : mesh.get_boundary_info().build_side_list())
    3432             :   {
    3433      880527 :     auto elem_id = std::get<0>(t);
    3434      880527 :     auto bc_id = std::get<2>(t);
    3435             : 
    3436      880527 :     if (_ghosted_boundaries.find(bc_id) != _ghosted_boundaries.end())
    3437             :     {
    3438        5695 :       Elem * elem = mesh.elem_ptr(elem_id);
    3439             : 
    3440             : #ifdef LIBMESH_ENABLE_AMR
    3441        5695 :       elem->family_tree(family_tree);
    3442        5695 :       Elem * parent = elem->parent();
    3443        5695 :       while (parent)
    3444             :       {
    3445           0 :         family_tree.push_back(parent);
    3446           0 :         parent = parent->parent();
    3447             :       }
    3448             : #else
    3449             :       family_tree.clear();
    3450             :       family_tree.push_back(elem);
    3451             : #endif
    3452       15230 :       for (const auto & felem : family_tree)
    3453             :       {
    3454        9535 :         boundary_elems_to_ghost.insert(felem);
    3455             : 
    3456             :         // The entries of connected_nodes_to_ghost need to be
    3457             :         // non-constant, so that they will work in things like
    3458             :         // UpdateDisplacedMeshThread. The container returned by
    3459             :         // family_tree contains const Elems even when the Elem
    3460             :         // it is called on is non-const, so once that interface
    3461             :         // gets fixed we can remove this const_cast.
    3462       57258 :         for (unsigned int n = 0; n < felem->n_nodes(); ++n)
    3463       47723 :           connected_nodes_to_ghost.insert(const_cast<Node *>(felem->node_ptr(n)));
    3464             :       }
    3465             :     }
    3466       22366 :   }
    3467             : 
    3468             :   // We really do want to store this by value instead of by reference
    3469       22366 :   const auto prior_ghost_elems = mesh.extra_ghost_elems();
    3470             : 
    3471       22366 :   mesh.comm().allgather_packed_range(&mesh,
    3472             :                                      connected_nodes_to_ghost.begin(),
    3473             :                                      connected_nodes_to_ghost.end(),
    3474             :                                      extra_ghost_elem_inserter<Node>(mesh));
    3475             : 
    3476       22366 :   mesh.comm().allgather_packed_range(&mesh,
    3477             :                                      boundary_elems_to_ghost.begin(),
    3478             :                                      boundary_elems_to_ghost.end(),
    3479             :                                      extra_ghost_elem_inserter<Elem>(mesh));
    3480             : 
    3481       22366 :   const auto & current_ghost_elems = mesh.extra_ghost_elems();
    3482             : 
    3483       44732 :   std::set_difference(current_ghost_elems.begin(),
    3484             :                       current_ghost_elems.end(),
    3485             :                       prior_ghost_elems.begin(),
    3486             :                       prior_ghost_elems.end(),
    3487       22366 :                       std::inserter(_ghost_elems_from_ghost_boundaries,
    3488             :                                     _ghost_elems_from_ghost_boundaries.begin()));
    3489       22366 : }
    3490             : 
    3491             : unsigned int
    3492       11484 : MooseMesh::getPatchSize() const
    3493             : {
    3494       11484 :   return _patch_size;
    3495             : }
    3496             : 
    3497             : void
    3498           0 : MooseMesh::setPatchUpdateStrategy(Moose::PatchUpdateType patch_update_strategy)
    3499             : {
    3500           0 :   _patch_update_strategy = patch_update_strategy;
    3501           0 : }
    3502             : 
    3503             : const Moose::PatchUpdateType &
    3504       36409 : MooseMesh::getPatchUpdateStrategy() const
    3505             : {
    3506       36409 :   return _patch_update_strategy;
    3507             : }
    3508             : 
    3509             : BoundingBox
    3510      114404 : MooseMesh::getInflatedProcessorBoundingBox(Real inflation_multiplier) const
    3511             : {
    3512             :   // Grab a bounding box to speed things up.  Note that
    3513             :   // local_bounding_box is *not* equivalent to processor_bounding_box
    3514             :   // with processor_id() except in serial.
    3515      114404 :   BoundingBox bbox = MeshTools::create_local_bounding_box(getMesh());
    3516             : 
    3517             :   // Inflate the bbox just a bit to deal with roundoff
    3518             :   // Adding 1% of the diagonal size in each direction on each end
    3519      114404 :   Real inflation_amount = inflation_multiplier * (bbox.max() - bbox.min()).norm();
    3520      114404 :   Point inflation(inflation_amount, inflation_amount, inflation_amount);
    3521             : 
    3522      114404 :   bbox.first -= inflation;  // min
    3523      114404 :   bbox.second += inflation; // max
    3524             : 
    3525      228808 :   return bbox;
    3526             : }
    3527             : 
    3528      160115 : MooseMesh::operator libMesh::MeshBase &() { return getMesh(); }
    3529             : 
    3530        2990 : MooseMesh::operator const libMesh::MeshBase &() const { return getMesh(); }
    3531             : 
    3532             : const MeshBase *
    3533      439965 : MooseMesh::getMeshPtr() const
    3534             : {
    3535      439965 :   return _mesh.get();
    3536             : }
    3537             : 
    3538             : MeshBase &
    3539    59350858 : MooseMesh::getMesh()
    3540             : {
    3541             :   mooseAssert(_mesh, "Mesh hasn't been created");
    3542    59350858 :   return *_mesh;
    3543             : }
    3544             : 
    3545             : const MeshBase &
    3546   707596809 : MooseMesh::getMesh() const
    3547             : {
    3548             :   mooseAssert(_mesh, "Mesh hasn't been created");
    3549   707596809 :   return *_mesh;
    3550             : }
    3551             : 
    3552             : void
    3553           0 : MooseMesh::printInfo(std::ostream & os, const unsigned int verbosity /* = 0 */) const
    3554             : {
    3555           0 :   os << '\n';
    3556           0 :   getMesh().print_info(os, verbosity);
    3557           0 :   os << std::flush;
    3558           0 : }
    3559             : 
    3560             : const std::vector<dof_id_type> &
    3561         229 : MooseMesh::getNodeList(boundary_id_type nodeset_id) const
    3562             : {
    3563             :   std::map<boundary_id_type, std::vector<dof_id_type>>::const_iterator it =
    3564         229 :       _node_set_nodes.find(nodeset_id);
    3565             : 
    3566         229 :   if (it == _node_set_nodes.end())
    3567             :   {
    3568             :     // On a distributed mesh we might not know about a remote nodeset,
    3569             :     // so we'll return an empty vector and hope the nodeset exists
    3570             :     // elsewhere.
    3571           0 :     if (!getMesh().is_serial())
    3572             :     {
    3573           0 :       static const std::vector<dof_id_type> empty_vec;
    3574           0 :       return empty_vec;
    3575             :     }
    3576             :     // On a replicated mesh we should know about every nodeset and if
    3577             :     // we're asked for one that doesn't exist then it must be a bug.
    3578             :     else
    3579             :     {
    3580           0 :       mooseError("Unable to nodeset ID: ", nodeset_id, '.');
    3581             :     }
    3582             :   }
    3583             : 
    3584         229 :   return it->second;
    3585             : }
    3586             : 
    3587             : const std::set<BoundaryID> &
    3588     4681422 : MooseMesh::getSubdomainBoundaryIds(const SubdomainID subdomain_id) const
    3589             : {
    3590     4681422 :   const auto it = _sub_to_data.find(subdomain_id);
    3591             : 
    3592     4681422 :   if (it == _sub_to_data.end())
    3593           0 :     mooseError("Unable to find subdomain ID: ", subdomain_id, '.');
    3594             : 
    3595     9362844 :   return it->second.boundary_ids;
    3596             : }
    3597             : 
    3598             : std::set<BoundaryID>
    3599          22 : MooseMesh::getSubdomainInterfaceBoundaryIds(const SubdomainID subdomain_id) const
    3600             : {
    3601          22 :   const auto & bnd_ids = getSubdomainBoundaryIds(subdomain_id);
    3602          22 :   std::set<BoundaryID> boundary_ids(bnd_ids.begin(), bnd_ids.end());
    3603             :   std::unordered_map<SubdomainID, std::set<BoundaryID>>::const_iterator it =
    3604          22 :       _neighbor_subdomain_boundary_ids.find(subdomain_id);
    3605             : 
    3606          22 :   boundary_ids.insert(it->second.begin(), it->second.end());
    3607             : 
    3608          44 :   return boundary_ids;
    3609           0 : }
    3610             : 
    3611             : std::set<SubdomainID>
    3612         203 : MooseMesh::getBoundaryConnectedBlocks(const BoundaryID bid) const
    3613             : {
    3614         203 :   std::set<SubdomainID> subdomain_ids;
    3615         763 :   for (const auto & [sub_id, data] : _sub_to_data)
    3616         560 :     if (data.boundary_ids.find(bid) != data.boundary_ids.end())
    3617         203 :       subdomain_ids.insert(sub_id);
    3618             : 
    3619         203 :   return subdomain_ids;
    3620           0 : }
    3621             : 
    3622             : std::set<SubdomainID>
    3623         169 : MooseMesh::getBoundaryConnectedSecondaryBlocks(const BoundaryID bid) const
    3624             : {
    3625         169 :   std::set<SubdomainID> subdomain_ids;
    3626         507 :   for (const auto & it : _neighbor_subdomain_boundary_ids)
    3627         338 :     if (it.second.find(bid) != it.second.end())
    3628         169 :       subdomain_ids.insert(it.first);
    3629             : 
    3630         169 :   return subdomain_ids;
    3631           0 : }
    3632             : 
    3633             : std::set<SubdomainID>
    3634          11 : MooseMesh::getInterfaceConnectedBlocks(const BoundaryID bid) const
    3635             : {
    3636          11 :   std::set<SubdomainID> subdomain_ids = getBoundaryConnectedBlocks(bid);
    3637         110 :   for (const auto & it : _neighbor_subdomain_boundary_ids)
    3638          99 :     if (it.second.find(bid) != it.second.end())
    3639          44 :       subdomain_ids.insert(it.first);
    3640             : 
    3641          11 :   return subdomain_ids;
    3642           0 : }
    3643             : 
    3644             : const std::set<SubdomainID> &
    3645           0 : MooseMesh::getBlockConnectedBlocks(const SubdomainID subdomain_id) const
    3646             : {
    3647           0 :   const auto it = _sub_to_data.find(subdomain_id);
    3648             : 
    3649           0 :   if (it == _sub_to_data.end())
    3650           0 :     mooseError("Unable to find subdomain ID: ", subdomain_id, '.');
    3651             : 
    3652           0 :   return it->second.neighbor_subs;
    3653             : }
    3654             : 
    3655             : bool
    3656     1216264 : MooseMesh::isBoundaryNode(dof_id_type node_id) const
    3657             : {
    3658     1216264 :   bool found_node = false;
    3659     4992112 :   for (const auto & it : _bnd_node_ids)
    3660             :   {
    3661     4053776 :     if (it.second.find(node_id) != it.second.end())
    3662             :     {
    3663      277928 :       found_node = true;
    3664      277928 :       break;
    3665             :     }
    3666             :   }
    3667     1216264 :   return found_node;
    3668             : }
    3669             : 
    3670             : bool
    3671      995742 : MooseMesh::isBoundaryNode(dof_id_type node_id, BoundaryID bnd_id) const
    3672             : {
    3673      995742 :   bool found_node = false;
    3674      995742 :   std::map<boundary_id_type, std::set<dof_id_type>>::const_iterator it = _bnd_node_ids.find(bnd_id);
    3675      995742 :   if (it != _bnd_node_ids.end())
    3676      935442 :     if (it->second.find(node_id) != it->second.end())
    3677       11620 :       found_node = true;
    3678      995742 :   return found_node;
    3679             : }
    3680             : 
    3681             : bool
    3682           0 : MooseMesh::isBoundaryElem(dof_id_type elem_id) const
    3683             : {
    3684           0 :   bool found_elem = false;
    3685           0 :   for (const auto & it : _bnd_elem_ids)
    3686             :   {
    3687           0 :     if (it.second.find(elem_id) != it.second.end())
    3688             :     {
    3689           0 :       found_elem = true;
    3690           0 :       break;
    3691             :     }
    3692             :   }
    3693           0 :   return found_elem;
    3694             : }
    3695             : 
    3696             : bool
    3697      425114 : MooseMesh::isBoundaryElem(dof_id_type elem_id, BoundaryID bnd_id) const
    3698             : {
    3699      425114 :   bool found_elem = false;
    3700      425114 :   auto it = _bnd_elem_ids.find(bnd_id);
    3701      425114 :   if (it != _bnd_elem_ids.end())
    3702      393181 :     if (it->second.find(elem_id) != it->second.end())
    3703       22342 :       found_elem = true;
    3704      425114 :   return found_elem;
    3705             : }
    3706             : 
    3707             : void
    3708        1276 : MooseMesh::errorIfDistributedMesh(std::string name) const
    3709             : {
    3710        1276 :   if (_use_distributed_mesh)
    3711           0 :     mooseError("Cannot use ",
    3712             :                name,
    3713             :                " with DistributedMesh!\n",
    3714             :                "Consider specifying parallel_type = 'replicated' in your input file\n",
    3715             :                "to prevent it from being run with DistributedMesh.");
    3716        1276 : }
    3717             : 
    3718             : void
    3719       69922 : MooseMesh::setPartitionerHelper(MeshBase * const mesh)
    3720             : {
    3721       69922 :   if (_use_distributed_mesh && (_partitioner_name != "default" && _partitioner_name != "parmetis"))
    3722             :   {
    3723          16 :     _partitioner_name = "parmetis";
    3724          16 :     _partitioner_overridden = true;
    3725             :   }
    3726             : 
    3727       69922 :   setPartitioner(mesh ? *mesh : getMesh(), _partitioner_name, _use_distributed_mesh, _pars, *this);
    3728       69922 : }
    3729             : 
    3730             : void
    3731       69922 : MooseMesh::setPartitioner(MeshBase & mesh_base,
    3732             :                           MooseEnum & partitioner,
    3733             :                           bool use_distributed_mesh,
    3734             :                           const InputParameters & params,
    3735             :                           MooseObject & context_obj)
    3736             : {
    3737             :   // Set the partitioner based on partitioner name
    3738       69922 :   switch (partitioner)
    3739             :   {
    3740       64922 :     case -3: // default
    3741             :       // We'll use the default partitioner, but notify the user of which one is being used...
    3742       64922 :       if (use_distributed_mesh)
    3743       21304 :         partitioner = "parmetis";
    3744             :       else
    3745      108540 :         partitioner = "metis";
    3746       64922 :       break;
    3747             : 
    3748             :     // No need to explicitily create the metis or parmetis partitioners,
    3749             :     // They are the default for serial and parallel mesh respectively
    3750        4888 :     case -2: // metis
    3751             :     case -1: // parmetis
    3752        4888 :       break;
    3753             : 
    3754          60 :     case 0: // linear
    3755          60 :       mesh_base.partitioner().reset(new libMesh::LinearPartitioner);
    3756          60 :       break;
    3757          52 :     case 1: // centroid
    3758             :     {
    3759         104 :       if (!params.isParamValid("centroid_partitioner_direction"))
    3760           0 :         context_obj.paramError(
    3761             :             "centroid_partitioner_direction",
    3762             :             "If using the centroid partitioner you _must_ specify centroid_partitioner_direction!");
    3763             : 
    3764          52 :       MooseEnum direction = params.get<MooseEnum>("centroid_partitioner_direction");
    3765             : 
    3766          52 :       if (direction == "x")
    3767          32 :         mesh_base.partitioner().reset(
    3768          16 :             new libMesh::CentroidPartitioner(libMesh::CentroidPartitioner::X));
    3769          36 :       else if (direction == "y")
    3770          72 :         mesh_base.partitioner().reset(
    3771          36 :             new libMesh::CentroidPartitioner(libMesh::CentroidPartitioner::Y));
    3772           0 :       else if (direction == "z")
    3773           0 :         mesh_base.partitioner().reset(
    3774           0 :             new libMesh::CentroidPartitioner(libMesh::CentroidPartitioner::Z));
    3775           0 :       else if (direction == "radial")
    3776           0 :         mesh_base.partitioner().reset(
    3777           0 :             new libMesh::CentroidPartitioner(libMesh::CentroidPartitioner::RADIAL));
    3778          52 :       break;
    3779          52 :     }
    3780           0 :     case 2: // hilbert_sfc
    3781           0 :       mesh_base.partitioner().reset(new libMesh::HilbertSFCPartitioner);
    3782           0 :       break;
    3783           0 :     case 3: // morton_sfc
    3784           0 :       mesh_base.partitioner().reset(new libMesh::MortonSFCPartitioner);
    3785           0 :       break;
    3786             :   }
    3787       69922 : }
    3788             : 
    3789             : void
    3790        1497 : MooseMesh::setCustomPartitioner(Partitioner * partitioner)
    3791             : {
    3792        1497 :   _custom_partitioner = partitioner->clone();
    3793        1497 :   setIsCustomPartitionerRequested(true);
    3794        1497 :   if (_mesh)
    3795          12 :     _mesh->partitioner() = _custom_partitioner->clone();
    3796        1497 :   _partitioner_name = "custom";
    3797        1497 : }
    3798             : 
    3799             : bool
    3800           0 : MooseMesh::isCustomPartitionerRequested() const
    3801             : {
    3802           0 :   return _custom_partitioner_requested;
    3803             : }
    3804             : 
    3805             : bool
    3806      145939 : MooseMesh::hasSecondOrderElements()
    3807             : {
    3808      145939 :   bool mesh_has_second_order_elements = false;
    3809    46315657 :   for (auto it = activeLocalElementsBegin(), end = activeLocalElementsEnd(); it != end; ++it)
    3810    23101159 :     if ((*it)->default_order() == SECOND)
    3811             :     {
    3812       16300 :       mesh_has_second_order_elements = true;
    3813       16300 :       break;
    3814      145939 :     }
    3815             : 
    3816             :   // We checked our local elements, so take the max over all processors.
    3817      145939 :   comm().max(mesh_has_second_order_elements);
    3818      145939 :   return mesh_has_second_order_elements;
    3819             : }
    3820             : 
    3821             : void
    3822        3001 : MooseMesh::setIsCustomPartitionerRequested(bool cpr)
    3823             : {
    3824        3001 :   _custom_partitioner_requested = cpr;
    3825        3001 : }
    3826             : 
    3827             : std::unique_ptr<libMesh::PointLocatorBase>
    3828        7000 : MooseMesh::getPointLocator() const
    3829             : {
    3830        7000 :   return getMesh().sub_point_locator();
    3831             : }
    3832             : 
    3833             : void
    3834        4742 : MooseMesh::buildFiniteVolumeInfo() const
    3835             : {
    3836             :   mooseAssert(!Threads::in_threads,
    3837             :               "This routine has not been implemented for threads. Please query this routine before "
    3838             :               "a threaded region or contact a MOOSE developer to discuss.");
    3839        4742 :   _finite_volume_info_dirty = false;
    3840             : 
    3841             :   using Keytype = std::pair<const Elem *, unsigned short int>;
    3842             : 
    3843             :   // create a map from elem/side --> boundary ids
    3844             :   std::vector<std::tuple<dof_id_type, unsigned short int, boundary_id_type>> side_list =
    3845        4742 :       buildActiveSideList();
    3846        4742 :   std::map<Keytype, std::set<boundary_id_type>> side_map;
    3847      164212 :   for (auto & [elem_id, side, bc_id] : side_list)
    3848             :   {
    3849      159470 :     const Elem * elem = _mesh->elem_ptr(elem_id);
    3850      159470 :     Keytype key(elem, side);
    3851      159470 :     auto & bc_set = side_map[key];
    3852      159470 :     bc_set.insert(bc_id);
    3853             :   }
    3854             : 
    3855        4742 :   _face_info.clear();
    3856        4742 :   _all_face_info.clear();
    3857        4742 :   _elem_side_to_face_info.clear();
    3858             : 
    3859        4742 :   _elem_to_elem_info.clear();
    3860        4742 :   _elem_info.clear();
    3861             : 
    3862             :   // by performing the element ID comparison check in the below loop, we are ensuring that we never
    3863             :   // double count face contributions. If a face lies along a process boundary, the only process that
    3864             :   // will contribute to both sides of the face residuals/Jacobians will be the process that owns the
    3865             :   // element with the lower ID.
    3866        4742 :   auto begin = getMesh().active_elements_begin();
    3867        4742 :   auto end = getMesh().active_elements_end();
    3868             : 
    3869             :   // We prepare a map connecting the Elem* and the corresponding ElemInfo
    3870             :   // for the active elements.
    3871        4742 :   _elem_to_elem_info.reserve(nActiveLocalElem());
    3872        4742 :   unsigned int num_sides = 0;
    3873     1137318 :   for (const Elem * elem : as_range(begin, end))
    3874             :   {
    3875     1132576 :     _elem_to_elem_info.emplace(elem->id(), elem);
    3876     1132576 :     num_sides += elem->n_sides();
    3877        4742 :   }
    3878             : 
    3879             :   // Used to speed up FaceInfo creation:
    3880             :   // - element side builder that caches per type of element
    3881        4742 :   libMesh::ElemSideBuilder side_builder;
    3882             : 
    3883        4742 :   _all_face_info.reserve(num_sides / 2);
    3884        4742 :   dof_id_type face_index = 0;
    3885     2269894 :   for (const Elem * elem : as_range(begin, end))
    3886             :   {
    3887     5035168 :     for (unsigned int side = 0; side < elem->n_sides(); ++side)
    3888             :     {
    3889             :       // get the neighbor element
    3890     3902592 :       const Elem * neighbor = elem->neighbor_ptr(side);
    3891             : 
    3892             :       // Check if the FaceInfo shall belong to the element. If yes,
    3893             :       // create and initialize the FaceInfo. We need this to ensure that
    3894             :       // we do not duplicate FaceInfo-s.
    3895     3902592 :       if (Moose::FV::elemHasFaceInfo(*elem, neighbor))
    3896             :       {
    3897             :         mooseAssert(!neighbor || (neighbor->level() < elem->level() ? neighbor->active() : true),
    3898             :                     "If the neighbor is coarser than the element, we expect that the neighbor must "
    3899             :                     "be active.");
    3900             : 
    3901             :         // We construct the faceInfo using the elementinfo and side index
    3902             :         mooseAssert(elem->default_order() < 4, "Did not expect such high element orders in FV");
    3903     4057954 :         _all_face_info.emplace_back(
    3904     2028977 :             &_elem_to_elem_info[elem->id()], side, face_index++, side_builder);
    3905             : 
    3906     2028977 :         auto & fi = _all_face_info.back();
    3907             : 
    3908             :         // get all the sidesets that this face is contained in and cache them
    3909             :         // in the face info.
    3910     2028977 :         std::set<boundary_id_type> & boundary_ids = fi.boundaryIDs();
    3911     2028977 :         boundary_ids.clear();
    3912             : 
    3913             :         // We initialize the weights/other information in faceInfo. If the neighbor does not exist
    3914             :         // or is remote (so when we are on some sort of mesh boundary), we initialize the ghost
    3915             :         // cell and use it to compute the weights corresponding to the faceInfo.
    3916     2028977 :         if (!neighbor || neighbor == libMesh::remote_elem)
    3917      152539 :           fi.computeBoundaryCoefficients();
    3918             :         else
    3919     1876438 :           fi.computeInternalCoefficients(&_elem_to_elem_info[neighbor->id()]);
    3920             : 
    3921     2028977 :         auto lit = side_map.find(Keytype(&fi.elem(), fi.elemSideID()));
    3922     2028977 :         if (lit != side_map.end())
    3923      152633 :           boundary_ids.insert(lit->second.begin(), lit->second.end());
    3924             : 
    3925     2028977 :         if (fi.neighborPtr())
    3926             :         {
    3927     1876438 :           auto rit = side_map.find(Keytype(fi.neighborPtr(), fi.neighborSideID()));
    3928     1876438 :           if (rit != side_map.end())
    3929        4220 :             boundary_ids.insert(rit->second.begin(), rit->second.end());
    3930             :         }
    3931             :       }
    3932             :     }
    3933        4742 :   }
    3934             : 
    3935             :   // Build the local face info and elem_side to face info maps. We need to do this after
    3936             :   // _all_face_info is finished being constructed because emplace_back invalidates all iterators and
    3937             :   // references if ever the new size exceeds capacity
    3938        4742 :   _elem_side_to_face_info.reserve(_all_face_info.size());
    3939             :   // heuristic to avoid resizing too much
    3940        4742 :   _face_info.reserve(_all_face_info.size());
    3941     2033719 :   for (auto & fi : _all_face_info)
    3942             :   {
    3943     2028977 :     const Elem * const elem = &fi.elem();
    3944     2028977 :     const auto side = fi.elemSideID();
    3945             : 
    3946             : #ifndef NDEBUG
    3947             :     auto pair_it =
    3948             : #endif
    3949     2028977 :         _elem_side_to_face_info.emplace(std::make_pair(elem, side), &fi);
    3950             :     mooseAssert(pair_it.second, "We should be adding unique FaceInfo objects.");
    3951             : 
    3952             :     // We will add the faces on processor boundaries to the list of face infos on each
    3953             :     // associated processor.
    3954     2583648 :     if (fi.elem().processor_id() == this->processor_id() ||
    3955      554671 :         (fi.neighborPtr() && (fi.neighborPtr()->processor_id() == this->processor_id())))
    3956     1745141 :       _face_info.push_back(&fi);
    3957             :   }
    3958             : 
    3959        4742 :   _elem_info.reserve(nActiveLocalElem());
    3960     1137318 :   for (auto & ei : _elem_to_elem_info)
    3961     1132576 :     if (ei.second.elem()->processor_id() == this->processor_id())
    3962      978244 :       _elem_info.push_back(&ei.second);
    3963        4742 : }
    3964             : 
    3965             : const FaceInfo *
    3966   122662946 : MooseMesh::faceInfo(const Elem * elem, unsigned int side) const
    3967             : {
    3968   122662946 :   auto it = _elem_side_to_face_info.find(std::make_pair(elem, side));
    3969             : 
    3970   122662946 :   if (it == _elem_side_to_face_info.end())
    3971         792 :     return nullptr;
    3972             :   else
    3973             :   {
    3974             :     mooseAssert(it->second,
    3975             :                 "For some reason, the FaceInfo object is NULL! Try calling "
    3976             :                 "`buildFiniteVolumeInfo()` before using this accessor!");
    3977   122662154 :     return it->second;
    3978             :   }
    3979             : }
    3980             : 
    3981             : const ElemInfo &
    3982   108299889 : MooseMesh::elemInfo(const dof_id_type id) const
    3983             : {
    3984   108299889 :   return libmesh_map_find(_elem_to_elem_info, id);
    3985             : }
    3986             : 
    3987             : void
    3988        4722 : MooseMesh::computeFiniteVolumeCoords() const
    3989             : {
    3990        4722 :   if (_finite_volume_info_dirty)
    3991           0 :     mooseError("Trying to compute face- and elem-info coords when the information is dirty");
    3992             : 
    3993     2032979 :   for (auto & fi : _all_face_info)
    3994             :   {
    3995             :     // get elem & neighbor elements, and set subdomain ids
    3996     2028257 :     const SubdomainID elem_subdomain_id = fi.elemSubdomainID();
    3997     2028257 :     const SubdomainID neighbor_subdomain_id = fi.neighborSubdomainID();
    3998             : 
    3999     2028257 :     coordTransformFactor(
    4000     2028257 :         *this, elem_subdomain_id, fi.faceCentroid(), fi.faceCoord(), neighbor_subdomain_id);
    4001             :   }
    4002             : 
    4003     1137138 :   for (auto & ei : _elem_to_elem_info)
    4004     1132416 :     coordTransformFactor(
    4005     2264832 :         *this, ei.second.subdomain_id(), ei.second.centroid(), ei.second.coordFactor());
    4006        4722 : }
    4007             : 
    4008             : MooseEnum
    4009      203681 : MooseMesh::partitioning()
    4010             : {
    4011             :   MooseEnum partitioning(
    4012      611043 :       "default=-3 metis=-2 parmetis=-1 linear=0 centroid hilbert_sfc morton_sfc custom", "default");
    4013      203681 :   return partitioning;
    4014             : }
    4015             : 
    4016             : MooseEnum
    4017        3421 : MooseMesh::elemTypes()
    4018             : {
    4019             :   MooseEnum elemTypes(
    4020             :       "EDGE EDGE2 EDGE3 EDGE4 QUAD QUAD4 QUAD8 QUAD9 TRI3 TRI6 HEX HEX8 HEX20 HEX27 TET4 TET10 "
    4021       10263 :       "PRISM6 PRISM15 PRISM18 PYRAMID5 PYRAMID13 PYRAMID14");
    4022        3421 :   return elemTypes;
    4023             : }
    4024             : 
    4025             : void
    4026       35755 : MooseMesh::allowRemoteElementRemoval(const bool allow_remote_element_removal)
    4027             : {
    4028       35755 :   _allow_remote_element_removal = allow_remote_element_removal;
    4029       35755 :   if (_mesh)
    4030       16324 :     _mesh->allow_remote_element_removal(allow_remote_element_removal);
    4031             : 
    4032       35755 :   if (!allow_remote_element_removal)
    4033             :     // If we're not allowing remote element removal now, then we will need deletion later after
    4034             :     // late geoemetric ghosting functors have been added (late geometric ghosting functor addition
    4035             :     // happens when algebraic ghosting functors are added)
    4036       35755 :     _need_delete = true;
    4037       35755 : }
    4038             : 
    4039             : void
    4040       17623 : MooseMesh::deleteRemoteElements()
    4041             : {
    4042       17623 :   _allow_remote_element_removal = true;
    4043       17623 :   if (!_mesh)
    4044           0 :     mooseError("Cannot delete remote elements because we have not yet attached a MeshBase");
    4045             : 
    4046       17623 :   _mesh->allow_remote_element_removal(true);
    4047             : 
    4048       17623 :   _mesh->delete_remote_elements();
    4049       17623 : }
    4050             : 
    4051             : void
    4052        4718 : MooseMesh::cacheFaceInfoVariableOwnership() const
    4053             : {
    4054             :   mooseAssert(
    4055             :       !Threads::in_threads,
    4056             :       "Performing writes to faceInfo variable association maps. This must be done unthreaded!");
    4057             : 
    4058        4718 :   const unsigned int num_eqs = _app.feProblem().es().n_systems();
    4059             : 
    4060     4060395 :   auto face_lambda = [this](const SubdomainID elem_subdomain_id,
    4061             :                             const SubdomainID neighbor_subdomain_id,
    4062             :                             SystemBase & sys,
    4063             :                             std::vector<std::vector<FaceInfo::VarFaceNeighbors>> & face_type_vector)
    4064             :   {
    4065     4060395 :     face_type_vector[sys.number()].resize(sys.nVariables(), FaceInfo::VarFaceNeighbors::NEITHER);
    4066     4060395 :     const auto & variables = sys.getVariables(0);
    4067             : 
    4068     8732670 :     for (const auto & var : variables)
    4069             :     {
    4070     4672275 :       const unsigned int var_num = var->number();
    4071     4672275 :       const unsigned int sys_num = var->sys().number();
    4072     4672275 :       std::set<SubdomainID> var_subdomains = var->blockIDs();
    4073             :       /**
    4074             :        * The following paragraph of code assigns the VarFaceNeighbors
    4075             :        * 1. The face is an internal face of this variable if it is defined on
    4076             :        *    the elem and neighbor subdomains
    4077             :        * 2. The face is an invalid face of this variable if it is neither defined
    4078             :        *    on the elem nor the neighbor subdomains
    4079             :        * 3. If not 1. or 2. then this is a boundary for this variable and the else clause
    4080             :        *    applies
    4081             :        */
    4082     4672275 :       bool var_defined_elem = var_subdomains.find(elem_subdomain_id) != var_subdomains.end();
    4083             :       bool var_defined_neighbor =
    4084     4672275 :           var_subdomains.find(neighbor_subdomain_id) != var_subdomains.end();
    4085     4672275 :       if (var_defined_elem && var_defined_neighbor)
    4086     3885061 :         face_type_vector[sys_num][var_num] = FaceInfo::VarFaceNeighbors::BOTH;
    4087      787214 :       else if (!var_defined_elem && !var_defined_neighbor)
    4088      349377 :         face_type_vector[sys_num][var_num] = FaceInfo::VarFaceNeighbors::NEITHER;
    4089             :       else
    4090             :       {
    4091             :         // this is a boundary face for this variable, set elem or neighbor
    4092      437837 :         if (var_defined_elem)
    4093      432405 :           face_type_vector[sys_num][var_num] = FaceInfo::VarFaceNeighbors::ELEM;
    4094        5432 :         else if (var_defined_neighbor)
    4095        5432 :           face_type_vector[sys_num][var_num] = FaceInfo::VarFaceNeighbors::NEIGHBOR;
    4096             :         else
    4097           0 :           mooseError("Should never get here");
    4098             :       }
    4099     4672275 :     }
    4100     4060395 :   };
    4101             : 
    4102             :   // We loop through the faces and check if they are internal, boundary or external to
    4103             :   // the variables in the problem
    4104     2032927 :   for (FaceInfo & face : _all_face_info)
    4105             :   {
    4106     2028209 :     const SubdomainID elem_subdomain_id = face.elemSubdomainID();
    4107     2028209 :     const SubdomainID neighbor_subdomain_id = face.neighborSubdomainID();
    4108             : 
    4109     2028209 :     auto & face_type_vector = face.faceType();
    4110             : 
    4111     2028209 :     face_type_vector.clear();
    4112     2028209 :     face_type_vector.resize(num_eqs);
    4113             : 
    4114             :     // First, we check the variables in the solver systems (linear/nonlinear)
    4115     4060395 :     for (const auto i : make_range(_app.feProblem().numSolverSystems()))
    4116     2032186 :       face_lambda(elem_subdomain_id,
    4117             :                   neighbor_subdomain_id,
    4118     2032186 :                   _app.feProblem().getSolverSystem(i),
    4119             :                   face_type_vector);
    4120             : 
    4121             :     // Then we check the variables in the auxiliary system
    4122     2028209 :     face_lambda(elem_subdomain_id,
    4123             :                 neighbor_subdomain_id,
    4124     2028209 :                 _app.feProblem().getAuxiliarySystem(),
    4125             :                 face_type_vector);
    4126             :   }
    4127        4718 : }
    4128             : 
    4129             : void
    4130        4718 : MooseMesh::cacheFVElementalDoFs() const
    4131             : {
    4132             :   mooseAssert(!Threads::in_threads,
    4133             :               "Performing writes to elemInfo dof indices. This must be done unthreaded!");
    4134             : 
    4135     2267443 :   auto elem_lambda = [](const ElemInfo & elem_info,
    4136             :                         SystemBase & sys,
    4137             :                         std::vector<std::vector<dof_id_type>> & dof_vector)
    4138             :   {
    4139     2267443 :     if (sys.nFVVariables())
    4140             :     {
    4141     1199180 :       dof_vector[sys.number()].resize(sys.nVariables(), libMesh::DofObject::invalid_id);
    4142     1199180 :       const auto & variables = sys.getVariables(0);
    4143             : 
    4144     3685546 :       for (const auto & var : variables)
    4145     2486366 :         if (var->isFV())
    4146             :         {
    4147     1440695 :           const auto & var_subdomains = var->blockIDs();
    4148             : 
    4149             :           // We will only cache for FV variables and if they live on the current subdomain
    4150     1440695 :           if (var_subdomains.find(elem_info.subdomain_id()) != var_subdomains.end())
    4151             :           {
    4152     1333516 :             std::vector<dof_id_type> indices;
    4153     1333516 :             var->dofMap().dof_indices(elem_info.elem(), indices, var->number());
    4154             :             mooseAssert(indices.size() == 1, "We expect to have only one dof per element!");
    4155     1333516 :             dof_vector[sys.number()][var->number()] = indices[0];
    4156     1333516 :           }
    4157             :         }
    4158             :     }
    4159     2267443 :   };
    4160             : 
    4161        4718 :   const unsigned int num_eqs = _app.feProblem().es().n_systems();
    4162             : 
    4163             :   // We loop through the elements in the mesh and cache the dof indices
    4164             :   // for the corresponding variables.
    4165     1137118 :   for (auto & ei_pair : _elem_to_elem_info)
    4166             :   {
    4167     1132400 :     auto & elem_info = ei_pair.second;
    4168     1132400 :     auto & dof_vector = elem_info.dofIndices();
    4169             : 
    4170     1132400 :     dof_vector.clear();
    4171     1132400 :     dof_vector.resize(num_eqs);
    4172             : 
    4173             :     // First, we cache the dof indices for the variables in the solver systems (linear, nonlinear)
    4174     2267443 :     for (const auto i : make_range(_app.feProblem().numSolverSystems()))
    4175     1135043 :       elem_lambda(elem_info, _app.feProblem().getSolverSystem(i), dof_vector);
    4176             : 
    4177             :     // Then we cache the dof indices for the auxvariables
    4178     1132400 :     elem_lambda(elem_info, _app.feProblem().getAuxiliarySystem(), dof_vector);
    4179             :   }
    4180        4718 : }
    4181             : 
    4182             : void
    4183        4718 : MooseMesh::setupFiniteVolumeMeshData() const
    4184             : {
    4185        4718 :   buildFiniteVolumeInfo();
    4186        4718 :   computeFiniteVolumeCoords();
    4187        4718 :   cacheFaceInfoVariableOwnership();
    4188        4718 :   cacheFVElementalDoFs();
    4189        4718 : }
    4190             : 
    4191             : void
    4192       65641 : MooseMesh::setCoordSystem(const std::vector<SubdomainName> & blocks,
    4193             :                           const MultiMooseEnum & coord_sys)
    4194             : {
    4195      328205 :   TIME_SECTION("setCoordSystem", 5, "Setting Coordinate System");
    4196       65641 :   if (!_provided_coord_blocks.empty() && (_provided_coord_blocks != blocks))
    4197             :   {
    4198           0 :     const std::string param_name = isParamValid("coord_block") ? "coord_block" : "block";
    4199           0 :     mooseWarning("Supplied blocks in the 'setCoordSystem' method do not match the value of the "
    4200             :                  "'Mesh/",
    4201             :                  param_name,
    4202             :                  "' parameter. Did you provide different parameter values for 'Mesh/",
    4203             :                  param_name,
    4204             :                  "' and 'Problem/block'?. We will honor the parameter value from 'Mesh/",
    4205             :                  param_name,
    4206             :                  "'");
    4207             :     mooseAssert(_coord_system_set,
    4208             :                 "If we are arriving here due to a bad specification in the Problem block, then we "
    4209             :                 "should have already set our coordinate system subdomains from the Mesh block");
    4210           0 :     return;
    4211           0 :   }
    4212      198081 :   if (_pars.isParamSetByUser("coord_type") && getParam<MultiMooseEnum>("coord_type") != coord_sys)
    4213           0 :     mooseError("Supplied coordinate systems in the 'setCoordSystem' method do not match the value "
    4214             :                "of the 'Mesh/coord_type' parameter. Did you provide different parameter values for "
    4215             :                "'coord_type' to 'Mesh' and 'Problem'?");
    4216             : 
    4217             :   // If blocks contain ANY_BLOCK_ID, it should be the only block specified, and coord_sys should
    4218             :   // have one and only one entry. In that case, the same coordinate system will be set for all
    4219             :   // subdomains.
    4220       65641 :   if (blocks.size() == 1 && blocks[0] == "ANY_BLOCK_ID")
    4221             :   {
    4222           0 :     if (coord_sys.size() > 1)
    4223           0 :       mooseError("If you specify ANY_BLOCK_ID as the only block, you must also specify a single "
    4224             :                  "coordinate system for it.");
    4225           0 :     if (!_mesh->is_prepared())
    4226           0 :       mooseError(
    4227             :           "You cannot set the coordinate system for ANY_BLOCK_ID before the mesh is prepared. "
    4228             :           "Please call this method after the mesh is prepared.");
    4229           0 :     const auto coord_type = coord_sys.size() == 0
    4230           0 :                                 ? Moose::COORD_XYZ
    4231           0 :                                 : Moose::stringToEnum<Moose::CoordinateSystemType>(coord_sys[0]);
    4232           0 :     for (const auto sid : meshSubdomains())
    4233           0 :       _coord_sys[sid] = coord_type;
    4234           0 :     return;
    4235             :   }
    4236             : 
    4237             :   // If multiple blocks are specified, but one of them is ANY_BLOCK_ID, let's emit a helpful error
    4238       65641 :   if (std::find(blocks.begin(), blocks.end(), "ANY_BLOCK_ID") != blocks.end())
    4239           0 :     mooseError("You cannot specify ANY_BLOCK_ID together with other blocks in the "
    4240             :                "setCoordSystem() method. If you want to set the same coordinate system for all "
    4241             :                "blocks, use ANY_BLOCK_ID as the only block.");
    4242             : 
    4243       65641 :   auto subdomains = meshSubdomains();
    4244             :   // It's possible that a user has called this API before the mesh is prepared and consequently we
    4245             :   // don't yet have the subdomains in meshSubdomains()
    4246       66040 :   for (const auto & sub_name : blocks)
    4247             :   {
    4248         399 :     const auto sub_id = getSubdomainID(sub_name);
    4249         399 :     subdomains.insert(sub_id);
    4250             :   }
    4251             : 
    4252       65641 :   if (coord_sys.size() <= 1)
    4253             :   {
    4254             :     // We will specify the same coordinate system for all blocks
    4255       65617 :     const auto coord_type = coord_sys.size() == 0
    4256       65617 :                                 ? Moose::COORD_XYZ
    4257       65617 :                                 : Moose::stringToEnum<Moose::CoordinateSystemType>(coord_sys[0]);
    4258      157706 :     for (const auto sid : subdomains)
    4259       92089 :       _coord_sys[sid] = coord_type;
    4260             :   }
    4261             :   else
    4262             :   {
    4263          24 :     if (blocks.size() != coord_sys.size())
    4264           0 :       mooseError("Number of blocks and coordinate systems does not match.");
    4265             : 
    4266          96 :     for (const auto i : index_range(blocks))
    4267             :     {
    4268          72 :       SubdomainID sid = getSubdomainID(blocks[i]);
    4269             :       Moose::CoordinateSystemType coord_type =
    4270          72 :           Moose::stringToEnum<Moose::CoordinateSystemType>(coord_sys[i]);
    4271          72 :       _coord_sys[sid] = coord_type;
    4272             :     }
    4273             : 
    4274          96 :     for (const auto & sid : subdomains)
    4275          72 :       if (_coord_sys.find(sid) == _coord_sys.end())
    4276           0 :         mooseError("Subdomain '" + Moose::stringify(sid) +
    4277             :                    "' does not have a coordinate system specified.");
    4278             :   }
    4279             : 
    4280       65641 :   _coord_system_set = true;
    4281             : 
    4282       65641 :   updateCoordTransform();
    4283       65641 : }
    4284             : 
    4285             : Moose::CoordinateSystemType
    4286  2290261442 : MooseMesh::getCoordSystem(SubdomainID sid) const
    4287             : {
    4288  2290261442 :   auto it = _coord_sys.find(sid);
    4289  2290261442 :   if (it != _coord_sys.end())
    4290  4580522884 :     return (*it).second;
    4291             :   else
    4292           0 :     mooseError("Requested subdomain ", sid, " does not exist.");
    4293             : }
    4294             : 
    4295             : Moose::CoordinateSystemType
    4296       55126 : MooseMesh::getUniqueCoordSystem() const
    4297             : {
    4298       55126 :   const auto unique_system = _coord_sys.find(*meshSubdomains().begin())->second;
    4299             :   // Check that it is actually unique
    4300       55126 :   bool result = std::all_of(
    4301       55126 :       std::next(_coord_sys.begin()),
    4302       55126 :       _coord_sys.end(),
    4303        4346 :       [unique_system](
    4304             :           typename std::unordered_map<SubdomainID, Moose::CoordinateSystemType>::const_reference
    4305        4346 :               item) { return (item.second == unique_system); });
    4306       55126 :   if (!result)
    4307           0 :     mooseError("The unique coordinate system of the mesh was requested by the mesh contains "
    4308             :                "multiple blocks with different coordinate systems");
    4309             : 
    4310       55126 :   if (usingGeneralAxisymmetricCoordAxes())
    4311           0 :     mooseError("General axisymmetric coordinate axes are being used, and it is currently "
    4312             :                "conservatively assumed that in this case there is no unique coordinate system.");
    4313             : 
    4314       55126 :   return unique_system;
    4315             : }
    4316             : 
    4317             : const std::map<SubdomainID, Moose::CoordinateSystemType> &
    4318       68645 : MooseMesh::getCoordSystem() const
    4319             : {
    4320       68645 :   return _coord_sys;
    4321             : }
    4322             : 
    4323             : void
    4324           0 : MooseMesh::setAxisymmetricCoordAxis(const MooseEnum & rz_coord_axis)
    4325             : {
    4326           0 :   _rz_coord_axis = rz_coord_axis;
    4327             : 
    4328           0 :   updateCoordTransform();
    4329           0 : }
    4330             : 
    4331             : void
    4332          17 : MooseMesh::setGeneralAxisymmetricCoordAxes(
    4333             :     const std::vector<SubdomainName> & blocks,
    4334             :     const std::vector<std::pair<Point, RealVectorValue>> & axes)
    4335             : {
    4336             :   // Set the axes for the given blocks
    4337             :   mooseAssert(blocks.size() == axes.size(), "Blocks and axes vectors must be the same length.");
    4338          58 :   for (const auto i : index_range(blocks))
    4339             :   {
    4340          41 :     const auto subdomain_id = getSubdomainID(blocks[i]);
    4341          41 :     const auto it = _coord_sys.find(subdomain_id);
    4342          41 :     if (it == _coord_sys.end())
    4343           0 :       mooseError("The block '",
    4344           0 :                  blocks[i],
    4345             :                  "' has not set a coordinate system. Make sure to call setCoordSystem() before "
    4346             :                  "setGeneralAxisymmetricCoordAxes().");
    4347             :     else
    4348             :     {
    4349          41 :       if (it->second == Moose::COORD_RZ)
    4350             :       {
    4351          41 :         const auto direction = axes[i].second;
    4352          41 :         if (direction.is_zero())
    4353           0 :           mooseError("Only nonzero vectors may be supplied for RZ directions.");
    4354             : 
    4355          41 :         _subdomain_id_to_rz_coord_axis[subdomain_id] =
    4356          82 :             std::make_pair(axes[i].first, direction.unit());
    4357             :       }
    4358             :       else
    4359           0 :         mooseError("The block '",
    4360           0 :                    blocks[i],
    4361             :                    "' was provided in setGeneralAxisymmetricCoordAxes(), but the coordinate system "
    4362             :                    "for this block is not 'RZ'.");
    4363             :     }
    4364             :   }
    4365             : 
    4366             :   // Make sure there are no RZ blocks that still do not have axes
    4367          17 :   const auto all_subdomain_ids = meshSubdomains();
    4368          70 :   for (const auto subdomain_id : all_subdomain_ids)
    4369          94 :     if (getCoordSystem(subdomain_id) == Moose::COORD_RZ &&
    4370          41 :         !_subdomain_id_to_rz_coord_axis.count(subdomain_id))
    4371           0 :       mooseError("The block '",
    4372           0 :                  getSubdomainName(subdomain_id),
    4373             :                  "' was specified to use the 'RZ' coordinate system but was not given in "
    4374             :                  "setGeneralAxisymmetricCoordAxes().");
    4375             : 
    4376          17 :   updateCoordTransform();
    4377          17 : }
    4378             : 
    4379             : const std::pair<Point, RealVectorValue> &
    4380     1063075 : MooseMesh::getGeneralAxisymmetricCoordAxis(SubdomainID subdomain_id) const
    4381             : {
    4382     1063075 :   auto it = _subdomain_id_to_rz_coord_axis.find(subdomain_id);
    4383     1063075 :   if (it != _subdomain_id_to_rz_coord_axis.end())
    4384     2126150 :     return (*it).second;
    4385             :   else
    4386           0 :     mooseError("Requested subdomain ", subdomain_id, " does not exist.");
    4387             : }
    4388             : 
    4389             : bool
    4390    24319265 : MooseMesh::usingGeneralAxisymmetricCoordAxes() const
    4391             : {
    4392    24319265 :   return _subdomain_id_to_rz_coord_axis.size() > 0;
    4393             : }
    4394             : 
    4395             : void
    4396       68645 : MooseMesh::updateCoordTransform()
    4397             : {
    4398       68645 :   if (!_coord_transform)
    4399       68624 :     _coord_transform = std::make_unique<MooseAppCoordTransform>(*this);
    4400             :   else
    4401          21 :     _coord_transform->setCoordinateSystem(*this);
    4402       68645 : }
    4403             : 
    4404             : unsigned int
    4405    20684434 : MooseMesh::getAxisymmetricRadialCoord() const
    4406             : {
    4407    20684434 :   if (usingGeneralAxisymmetricCoordAxes())
    4408           0 :     mooseError("getAxisymmetricRadialCoord() should not be called if "
    4409             :                "setGeneralAxisymmetricCoordAxes() has been called.");
    4410             : 
    4411    20684434 :   if (_rz_coord_axis == 0)
    4412      133200 :     return 1; // if the rotation axis is x (0), then the radial direction is y (1)
    4413             :   else
    4414    20551234 :     return 0; // otherwise the radial direction is assumed to be x, i.e., the rotation axis is y
    4415             : }
    4416             : 
    4417             : void
    4418       61035 : MooseMesh::checkCoordinateSystems()
    4419             : {
    4420    27896803 :   for (const auto & elem : getMesh().element_ptr_range())
    4421             :   {
    4422    13917887 :     SubdomainID sid = elem->subdomain_id();
    4423    13917887 :     if (_coord_sys[sid] == Moose::COORD_RZ && elem->dim() == 3)
    4424           3 :       mooseError("An RZ coordinate system was requested for subdomain " + Moose::stringify(sid) +
    4425             :                  " which contains 3D elements.");
    4426    13917884 :     if (_coord_sys[sid] == Moose::COORD_RSPHERICAL && elem->dim() > 1)
    4427           0 :       mooseError("An RSPHERICAL coordinate system was requested for subdomain " +
    4428           0 :                  Moose::stringify(sid) + " which contains 2D or 3D elements.");
    4429       61032 :   }
    4430       61032 : }
    4431             : 
    4432             : void
    4433        2022 : MooseMesh::setCoordData(const MooseMesh & other_mesh)
    4434             : {
    4435        2022 :   _coord_sys = other_mesh._coord_sys;
    4436        2022 :   _rz_coord_axis = other_mesh._rz_coord_axis;
    4437        2022 :   _subdomain_id_to_rz_coord_axis = other_mesh._subdomain_id_to_rz_coord_axis;
    4438        2022 : }
    4439             : 
    4440             : const MooseUnits &
    4441           2 : MooseMesh::lengthUnit() const
    4442             : {
    4443             :   mooseAssert(_coord_transform, "This must be non-null");
    4444           2 :   return _coord_transform->lengthUnit();
    4445             : }
    4446             : 
    4447             : void
    4448       68526 : MooseMesh::checkDuplicateSubdomainNames()
    4449             : {
    4450       68526 :   std::map<SubdomainName, SubdomainID> subdomain;
    4451      164755 :   for (const auto & sbd_id : _mesh_subdomains)
    4452             :   {
    4453       96232 :     std::string sub_name = getSubdomainName(sbd_id);
    4454       96232 :     if (!sub_name.empty() && subdomain.count(sub_name) > 0)
    4455           6 :       mooseError("The subdomain name ",
    4456             :                  sub_name,
    4457             :                  " is used for both subdomain with ID=",
    4458           3 :                  subdomain[sub_name],
    4459             :                  " and ID=",
    4460             :                  sbd_id,
    4461             :                  ", Please rename one of them!");
    4462             :     else
    4463       96229 :       subdomain[sub_name] = sbd_id;
    4464       96229 :   }
    4465       68523 : }
    4466             : 
    4467             : const std::vector<QpMap> &
    4468         800 : MooseMesh::getPRefinementMapHelper(
    4469             :     const Elem & elem,
    4470             :     const std::map<std::pair<ElemType, unsigned int>, std::vector<QpMap>> & map) const
    4471             : {
    4472             :   // We are actually seeking the map stored with the p_level - 1 key, e.g. the refinement map that
    4473             :   // maps from the previous p_level to this element's p_level
    4474         800 :   return libmesh_map_find(map,
    4475             :                           std::make_pair(elem.type(), cast_int<unsigned int>(elem.p_level() - 1)));
    4476             : }
    4477             : 
    4478             : const std::vector<QpMap> &
    4479           0 : MooseMesh::getPCoarseningMapHelper(
    4480             :     const Elem & elem,
    4481             :     const std::map<std::pair<ElemType, unsigned int>, std::vector<QpMap>> & map) const
    4482             : {
    4483             :   mooseAssert(elem.active() && elem.p_refinement_flag() == Elem::JUST_COARSENED,
    4484             :               "These are the conditions that should be met for requesting a coarsening map");
    4485           0 :   return libmesh_map_find(map, std::make_pair(elem.type(), elem.p_level()));
    4486             : }
    4487             : 
    4488             : const std::vector<QpMap> &
    4489         800 : MooseMesh::getPRefinementMap(const Elem & elem) const
    4490             : {
    4491         800 :   return getPRefinementMapHelper(elem, _elem_type_to_p_refinement_map);
    4492             : }
    4493             : 
    4494             : const std::vector<QpMap> &
    4495           0 : MooseMesh::getPRefinementSideMap(const Elem & elem) const
    4496             : {
    4497           0 :   return getPRefinementMapHelper(elem, _elem_type_to_p_refinement_side_map);
    4498             : }
    4499             : 
    4500             : const std::vector<QpMap> &
    4501           0 : MooseMesh::getPCoarseningMap(const Elem & elem) const
    4502             : {
    4503           0 :   return getPCoarseningMapHelper(elem, _elem_type_to_p_coarsening_map);
    4504             : }
    4505             : 
    4506             : const std::vector<QpMap> &
    4507           0 : MooseMesh::getPCoarseningSideMap(const Elem & elem) const
    4508             : {
    4509           0 :   return getPCoarseningMapHelper(elem, _elem_type_to_p_coarsening_side_map);
    4510             : }
    4511             : 
    4512             : bool
    4513       26973 : MooseMesh::skipNoncriticalPartitioning() const
    4514             : {
    4515       26973 :   return _mesh->skip_noncritical_partitioning();
    4516             : }

Generated by: LCOV version 1.14