21#include "libmesh/dof_map.h"
24#include "libmesh/coupling_matrix.h"
25#include "libmesh/default_coupling.h"
26#include "libmesh/dense_matrix.h"
27#include "libmesh/dense_vector_base.h"
28#include "libmesh/dirichlet_boundaries.h"
29#include "libmesh/enum_to_string.h"
30#include "libmesh/fe_type.h"
31#include "libmesh/fe_base.h"
32#include "libmesh/ghosting_functor.h"
33#include "libmesh/int_range.h"
34#include "libmesh/mesh_base.h"
35#include "libmesh/mesh_tools.h"
36#include "libmesh/numeric_vector.h"
37#include "libmesh/periodic_boundary_base.h"
38#include "libmesh/periodic_boundaries.h"
39#include "libmesh/sparse_matrix.h"
40#include "libmesh/sparsity_pattern.h"
41#include "libmesh/threads.h"
42#include "libmesh/static_condensation_dof_map.h"
43#include "libmesh/system.h"
44#include "libmesh/parallel_fe_type.h"
55#include <unordered_map>
62std::unique_ptr<SparsityPattern::Build>
64 const bool calculate_constrained,
65 const bool use_condensed_system)
const
69 LOG_SCOPE(
"build_sparsity()",
"DofMap");
85 if (use_condensed_system)
99 auto sp = std::make_unique<SparsityPattern::Build>
103 implicit_neighbor_dofs,
105 calculate_constrained,
109 mesh.active_local_elements_end()), *sp);
113 libmesh_assert_equal_to (sp->get_sparsity_pattern().size(), this->n_local_dofs());
121 libMesh::out <<
"WARNING: You have specified both an extra sparsity function and object.\n"
122 <<
" Are you sure this is what you meant to do??"
141 _dof_coupling(nullptr),
142 _error_on_constraint_loop(false),
143 _constrained_sparsity_construction(false),
146 _variable_group_numbers(),
152 _augment_sparsity_pattern(nullptr),
153 _extra_sparsity_function(nullptr),
154 _extra_sparsity_context(nullptr),
155 _augment_send_list(nullptr),
156 _extra_send_list_function(nullptr),
157 _extra_send_list_context(nullptr),
160 _need_full_sparsity_pattern(false),
161 _need_ghost_constraints(false),
163#ifdef LIBMESH_ENABLE_AMR
164 , _first_old_scalar_df()
166#ifdef LIBMESH_ENABLE_CONSTRAINTS
168 , _stashed_dof_constraints()
169 , _primal_constraint_values()
170 , _adjoint_constraint_values()
172#ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
173 , _node_constraints()
175#ifdef LIBMESH_ENABLE_PERIODIC
178#ifdef LIBMESH_ENABLE_DIRICHLET
180 , _adjoint_dirichlet_boundaries()
182 , _implicit_neighbor_dofs_initialized(false),
183 _implicit_neighbor_dofs(false),
184 _verify_dirichlet_bc_consistency(true),
193#ifdef LIBMESH_ENABLE_PERIODIC
216#ifdef LIBMESH_ENABLE_PERIODIC
243 parallel_object_only();
262 (!
_sp->get_n_nz().empty() ||
263 !
_sp->get_n_oz().empty());
264 this->
comm().
max(computed_sparsity_already);
306 return mesh.node_ptr(i);
313 return mesh.elem_ptr(i);
318template <
typename iterator_type>
320 iterator_type objects_end,
322 dofobject_accessor objects)
325 parallel_object_only();
329 std::unordered_map<processor_id_type, dof_id_type> ghost_objects_from_proc;
331 iterator_type it = objects_begin;
333 for (; it != objects_end; ++it)
342 ghost_objects_from_proc[obj_procid]++;
347 std::map<processor_id_type, std::vector<dof_id_type>>
352 for (
auto [p, size] : ghost_objects_from_proc)
355 requested_ids[p].reserve(size);
358 for (it = objects_begin; it != objects_end; ++it)
367 if (ghost_objects_from_proc.count(p))
368 libmesh_assert_equal_to (requested_ids[p].size(), ghost_objects_from_proc[p]);
374 typedef std::vector<dof_id_type> datum;
376 auto gather_functor =
377 [
this, &
mesh, &objects]
379 const std::vector<dof_id_type> & ids,
380 std::vector<datum> & data)
387 const std::size_t query_size = ids.size();
389 data.resize(query_size);
390 for (
auto & d : data)
391 d.resize(2 * n_var_groups);
393 for (std::size_t i=0; i != query_size; ++i)
397 libmesh_assert_equal_to (requested->
processor_id(), this->processor_id());
398 libmesh_assert_equal_to (requested->
n_var_groups(sys_num), n_var_groups);
399 for (
unsigned int vg=0; vg != n_var_groups; ++vg)
401 unsigned int n_comp_g =
403 data[i][vg] = n_comp_g;
407 data[i][n_var_groups+vg] = my_first_dof;
412 auto action_functor =
413 [
this, &
mesh, &objects]
415 const std::vector<dof_id_type> & ids,
416 const std::vector<datum> & data)
427 libmesh_assert_equal_to (requested->
processor_id(), pid);
428 for (
unsigned int vg=0; vg != n_var_groups; ++vg)
430 unsigned int n_comp_g =
431 cast_int<unsigned int>(data[i][vg]);
435 dof_id_type my_first_dof = data[i][n_var_groups+vg];
438 (sys_num, vg, my_first_dof);
444 datum * ex =
nullptr;
446 (this->
comm(), requested_ids, gather_functor, action_functor, ex);
450 for (it = objects_begin; it != objects_end; ++it)
455 for (
unsigned int v=0; v != num_variables; ++v)
457 unsigned int n_comp =
471 const std::map<
const Node *, std::set<subdomain_id_type>> &
472 constraining_subdomains)
476 LOG_SCOPE(
"reinit()",
"DofMap");
479 const bool constraining_subdomains_empty =
480 constraining_subdomains.empty();
495 unsigned int standard_n_levels =
511 std::vector<unsigned int> n_vars_per_group; n_vars_per_group.reserve (n_var_groups);
513 for (
unsigned int vg=0; vg<n_var_groups; vg++)
514 n_vars_per_group.push_back (this->variable_group(vg).n_variables());
516#ifdef LIBMESH_ENABLE_AMR
521 for (
auto & node :
mesh.node_ptr_range())
523 node->clear_old_dof_object();
528 (
mesh.element_stored_range(),
531 for (Elem * elem : range)
533 elem->clear_old_dof_object();
534 libmesh_assert (!elem->get_old_dof_object());
542 for (
auto & elem :
mesh.element_ptr_range())
548 for (
Node & node : elem->node_ref_range())
549 if (node.get_old_dof_object() == nullptr)
550 if (node.has_dofs(sys_num))
551 node.set_old_dof_object();
555 if (elem->has_dofs(sys_num))
556 elem->set_old_dof_object();
568 for (
auto & node :
mesh.node_ptr_range())
569 node->set_n_vars_per_group(sys_num, n_vars_per_group);
574 [sys_num, n_vars_per_group](
const ElemRange & range)
576 for (Elem * elem : range)
577 elem->set_n_vars_per_group(sys_num, n_vars_per_group);
581 this->_n_SCALAR_dofs = 0;
585 for (
unsigned int vg=0; vg<n_var_groups; vg++)
587 const VariableGroup & vg_description = this->variable_group(vg);
589 const unsigned int n_var_in_group = vg_description.n_variables();
590 const FEType & base_fe_type = vg_description.type();
592 const bool add_p_level = base_fe_type.p_refinement;
596 if (base_fe_type.family ==
SCALAR)
598 this->_n_SCALAR_dofs += base_fe_type.order.get_order()*n_var_in_group;
603 const bool extra_hanging_dofs =
607 for (
auto & elem :
mesh.active_element_ptr_range())
615 const bool active_on_elem =
616 vg_description.active_on_subdomain(elem->subdomain_id());
620 if (!active_on_elem && constraining_subdomains_empty)
623 FEType fe_type = base_fe_type;
627 libmesh_error_msg_if(base_fe_type.order.get_order() >
629 "ERROR: Finite element "
631 <<
" on geometric element "
633 <<
"\nonly supports FEInterface::max_order = "
635 <<
", not fe_type.order = "
636 << base_fe_type.order);
638#ifdef LIBMESH_ENABLE_AMR
641 if (base_fe_type.order + add_p_level*elem->p_level() >
647 <<
" on geometric element "
649 <<
"could not be p refined past FEInterface::max_order = "
654 -
int(base_fe_type.order));
659 for (
auto n : elem->node_index_range())
661 Node & node = elem->node_ref(n);
666 bool active_on_node = active_on_elem;
668 if (
auto it = constraining_subdomains.find(&node);
669 it != constraining_subdomains.end())
670 for (
auto s : it->second)
671 if (vg_description.active_on_subdomain(s))
673 active_on_node =
true;
680 if (elem->is_vertex(n))
682 const unsigned int old_node_dofs =
683 node.n_comp_group(sys_num, vg);
685 const unsigned int vertex_dofs =
690 if (vertex_dofs > old_node_dofs)
692 node.set_n_comp_group(sys_num, vg,
697 node.set_vg_dof_base(sys_num, vg,
715 for (
auto & elem :
mesh.active_element_ptr_range())
723 const bool active_on_elem =
724 vg_description.active_on_subdomain(elem->subdomain_id());
728 if (!active_on_elem && constraining_subdomains_empty)
732 for (
auto n : elem->node_index_range())
734 Node & node = elem->node_ref(n);
739 bool active_on_node = active_on_elem;
741 if (
auto it = constraining_subdomains.find(&node);
742 it != constraining_subdomains.end())
743 for (
auto s : it->second)
744 if (vg_description.active_on_subdomain(s))
746 active_on_node =
true;
753 const unsigned int old_node_dofs =
754 node.n_comp_group(sys_num, vg);
756 const unsigned int vertex_dofs = old_node_dofs?
757 cast_int<unsigned int>(node.vg_dof_base (sys_num,vg)):0;
759 const unsigned int new_node_dofs =
763 if (elem->is_vertex(n))
765 libmesh_assert_greater_equal (old_node_dofs, vertex_dofs);
775 libmesh_assert_greater_equal (vertex_dofs, new_node_dofs);
784 node.set_n_comp_group(sys_num, vg,
789 node.set_vg_dof_base(sys_num, vg, 0);
795 else if (vertex_dofs == 0)
797 if (new_node_dofs > old_node_dofs)
799 node.set_n_comp_group(sys_num, vg,
802 node.set_vg_dof_base(sys_num, vg,
809 else if (extra_hanging_dofs)
811 if (new_node_dofs > old_node_dofs - vertex_dofs)
813 node.set_n_comp_group(sys_num, vg,
814 vertex_dofs + new_node_dofs);
816 node.set_vg_dof_base(sys_num, vg,
824 libmesh_assert_greater_equal (old_node_dofs, vertex_dofs);
825 if (new_node_dofs > old_node_dofs)
827 node.set_n_comp_group(sys_num, vg,
830 node.set_vg_dof_base (sys_num, vg,
837 const unsigned int dofs_per_elem =
840 elem->set_n_comp_group(sys_num, vg, dofs_per_elem);
852 this->invalidate_dofs(
mesh);
859 const unsigned int sys_num = this->sys_number();
862 for (
auto & node :
mesh.node_ptr_range())
863 node->invalidate_dofs(sys_num);
866 for (
auto & elem :
mesh.active_element_ptr_range())
867 elem->invalidate_dofs(sys_num);
883 _dof_coupling =
nullptr;
887 for (
const auto & gf : _coupling_functors)
890 _mesh.remove_ghosting_functor(*gf);
892 this->_coupling_functors.clear();
896 _default_coupling->set_dof_coupling(this->_dof_coupling);
897 _default_coupling->set_n_levels(this->use_coupled_neighbor_dofs(this->_mesh));
899 this->add_coupling_functor(*_default_coupling);
904 for (
const auto & gf : _algebraic_ghosting_functors)
907 _mesh.remove_ghosting_functor(*gf);
909 this->_algebraic_ghosting_functors.clear();
914 _default_evaluating->set_n_levels(1);
915 this->add_algebraic_ghosting_functor(*_default_evaluating);
918 this->_shared_functors.clear();
921 _variable_groups.clear();
923 _variable_group_numbers.clear();
924 _array_variables.clear();
925 _first_scalar_df.clear();
926 this->clear_send_list();
927 this->clear_sparsity();
928 _need_full_sparsity_pattern =
false;
929 _need_ghost_constraints =
false;
931#ifdef LIBMESH_ENABLE_AMR
933 _dof_constraints.clear();
934 _stashed_dof_constraints.clear();
935 _primal_constraint_values.clear();
936 _adjoint_constraint_values.clear();
938 _first_old_df.clear();
940 _first_old_scalar_df.clear();
954 parallel_object_only();
957 LOG_SCOPE(
"distribute_dofs()",
"DofMap");
967 libmesh_assert_less (proc_id, n_proc);
972 const std::map<const Node *, std::set<subdomain_id_type>>
973 constraining_subdomains =
974 this->calculate_constraining_subdomains();
978 constraining_subdomains);
990 this->clear_send_list();
994 this->distribute_local_dofs_node_major
995 (next_free_dof,
mesh, constraining_subdomains);
997 this->distribute_local_dofs_var_major
998 (next_free_dof,
mesh, constraining_subdomains);
1001 const auto n_dofs = this->compute_dof_info(next_free_dof);
1005 this->invalidate_dofs(
mesh);
1007 next_free_dof = _first_df[proc_id];
1010 if (node_major_dofs)
1011 this->distribute_local_dofs_node_major
1012 (next_free_dof,
mesh, constraining_subdomains);
1014 this->distribute_local_dofs_var_major
1015 (next_free_dof,
mesh, constraining_subdomains);
1017 libmesh_assert_equal_to (next_free_dof, _end_df[proc_id]);
1025 if (this->n_processors() > 1)
1027 this->set_nonlocal_dof_objects(
mesh.nodes_begin(),
1029 mesh, &DofMap::node_ptr);
1031 this->set_nonlocal_dof_objects(
mesh.elements_begin(),
1032 mesh.elements_end(),
1033 mesh, &DofMap::elem_ptr);
1039 sys_num = this->sys_number();
1043 MeshTools::libmesh_assert_valid_dof_ids(
mesh, sys_num);
1046 for (
auto & node :
mesh.node_ptr_range())
1055 libmesh_assert_greater_equal (dofid, this->first_dof(obj_proc_id));
1056 libmesh_assert_less (dofid, this->end_dof(obj_proc_id));
1060 for (
auto & elem :
mesh.element_ptr_range())
1069 libmesh_assert_greater_equal (dofid, this->first_dof(obj_proc_id));
1070 libmesh_assert_less (dofid, this->end_dof(obj_proc_id));
1077#ifdef LIBMESH_ENABLE_AMR
1078 _first_old_scalar_df = _first_scalar_df;
1080 _first_scalar_df.clear();
1081 _first_scalar_df.resize(this->n_variables(), DofObject::invalid_id);
1082 dof_id_type current_SCALAR_dof_index = n_dofs - n_SCALAR_dofs();
1088 for (
auto v :
make_range(this->n_variables()))
1089 if (this->variable(v).type().family ==
SCALAR)
1091 _first_scalar_df[v] = current_SCALAR_dof_index;
1092 current_SCALAR_dof_index += this->variable(v).type().order.get_order();
1096 for (
const auto & gf : _algebraic_ghosting_functors)
1099 gf->dofmap_reinit();
1102 for (
const auto & gf : _coupling_functors)
1105 gf->dofmap_reinit();
1111 this->add_neighbors_to_send_list(
mesh);
1122template <
typename T, std::enable_if_t<std::is_same_v<T, dof_
id_type> ||
1123 std::is_same_v<T, std::vector<dof_
id_type>>,
int>>
1124void DofMap::local_variable_indices(T & idx,
1126 unsigned int var_num)
const
1131 if constexpr (std::is_same_v<T, dof_id_type>)
1133 else if constexpr (std::is_same_v<T, std::vector<dof_id_type>>)
1140 const unsigned int sys_num = this->sys_number();
1144 if (this->variable_type(var_num).family !=
SCALAR)
1146 const Variable & var(this->variable(var_num));
1148 for (
auto & elem :
mesh.active_local_element_ptr_range())
1155 const unsigned int n_nodes = elem->n_nodes();
1158 for (
unsigned int n=0; n<
n_nodes; n++)
1160 const Node & node = elem->node_ref(n);
1165 const unsigned int n_comp = node.
n_comp(sys_num, var_num);
1166 for(
unsigned int i=0; i<n_comp; i++)
1171 if constexpr (std::is_same_v<T, dof_id_type>)
1173 if (idx == 0 || index > greatest)
1174 { idx++; greatest = index; }
1176 else if constexpr (std::is_same_v<T, std::vector<dof_id_type>>)
1178 if (idx.empty() || index > idx.back())
1179 idx.push_back(index);
1185 const unsigned int n_comp = elem->n_comp(sys_num, var_num);
1186 for (
unsigned int i=0; i<n_comp; i++)
1188 const dof_id_type index = elem->dof_number(sys_num,var_num,i);
1190 if constexpr (std::is_same_v<T, dof_id_type>)
1192 if (idx == 0 || index > greatest)
1193 { idx++; greatest = index; }
1195 else if constexpr (std::is_same_v<T, std::vector<dof_id_type>>)
1197 if (idx.empty() || index > idx.back())
1198 idx.push_back(index);
1212 for (
const auto & node :
mesh.local_node_ptr_range())
1216 const unsigned int n_comp = node->n_comp(sys_num, var_num);
1217 for (
unsigned int i=0; i<n_comp; i++)
1219 const dof_id_type index = node->dof_number(sys_num,var_num,i);
1221 if constexpr (std::is_same_v<T, dof_id_type>)
1223 if (idx == 0 || index > greatest)
1224 { idx++; greatest = index; }
1226 else if constexpr (std::is_same_v<T, std::vector<dof_id_type>>)
1228 if (idx.empty() || index > idx.back())
1229 idx.push_back(index);
1236 else if (this->processor_id() == (this->n_processors()-1))
1238 std::vector<dof_id_type> di_scalar;
1239 this->SCALAR_dof_indices(di_scalar,var_num);
1241 if constexpr (std::is_same_v<T, dof_id_type>)
1242 idx += std::distance(di_scalar.begin(), di_scalar.end());
1243 else if constexpr (std::is_same_v<T, std::vector<dof_id_type>>)
1244 idx.insert(idx.end(), di_scalar.begin(), di_scalar.end());
1248template void DofMap::local_variable_indices(
dof_id_type &,
1250 unsigned int)
const;
1252template void DofMap::local_variable_indices(std::vector<dof_id_type> &,
1254 unsigned int)
const;
1257std::map<const Node *, std::set<subdomain_id_type>>
1258DofMap::calculate_constraining_subdomains()
1260 std::map<const Node *, std::set<subdomain_id_type>> constraining_subdomains;
1261 const auto & constraint_rows = _mesh.get_constraint_rows();
1266 if (!constraint_rows.empty())
1267 for (
auto & elem : _mesh.active_element_ptr_range())
1271 for (
const Node & node : elem->node_ref_range())
1273 if (
auto it = constraint_rows.find(&node);
1274 it != constraint_rows.end())
1276 for (
const auto & [pr, val] : it->second)
1278 const Node * spline_node =
1279 pr.first->node_ptr(pr.second);
1281 constraining_subdomains[spline_node].insert(sbdid);
1287 return constraining_subdomains;
1291void DofMap::distribute_local_dofs_node_major
1294 const std::map<
const Node *, std::set<subdomain_id_type>> &
1295 constraining_subdomains)
1297 const unsigned int sys_num = this->sys_number();
1298 const unsigned int n_var_groups = this->n_variable_groups();
1301 const bool constraining_subdomains_empty =
1302 constraining_subdomains.empty();
1309 for (
auto & elem :
mesh.active_local_element_ptr_range())
1313 const unsigned int n_nodes = elem->n_nodes();
1318 for (
unsigned int n=0; n<
n_nodes; n++)
1320 Node & node = elem->node_ref(n);
1322 for (
unsigned vg=0; vg<n_var_groups; vg++)
1324 const VariableGroup & vg_description(this->variable_group(vg));
1329 bool active_on_node =
1333 if (!active_on_node && !constraining_subdomains_empty)
1334 if (
auto it = constraining_subdomains.find(&node);
1335 it != constraining_subdomains.end())
1336 for (
auto s : it->second)
1339 active_on_node =
true;
1350 DofObject::invalid_id))
1363 for (
unsigned vg=0; vg<n_var_groups; vg++)
1365 const VariableGroup & vg_description(this->variable_group(vg));
1369 if (elem->n_comp_group(sys_num,vg) > 0)
1371 libmesh_assert_equal_to (elem->vg_dof_base(sys_num,vg),
1372 DofObject::invalid_id);
1374 elem->set_vg_dof_base(sys_num,
1379 elem->n_comp_group(sys_num,vg));
1393 for (
auto & node :
mesh.local_node_ptr_range())
1394 for (
unsigned vg=0; vg<n_var_groups; vg++)
1396 const VariableGroup & vg_description(this->variable_group(vg));
1398 if (node->n_comp_group(sys_num,vg))
1399 if (node->vg_dof_base(sys_num,vg) == DofObject::invalid_id)
1401 node->set_vg_dof_base (sys_num,
1406 node->n_comp(sys_num,vg));
1410 this->distribute_scalar_dofs(next_free_dof);
1413 this->assert_no_nodes_missed(
mesh);
1419void DofMap::distribute_local_dofs_var_major
1422 const std::map<
const Node *, std::set<subdomain_id_type>> &
1423 constraining_subdomains)
1425 const unsigned int sys_num = this->sys_number();
1426 const unsigned int n_var_groups = this->n_variable_groups();
1429 const bool constraining_subdomains_empty =
1430 constraining_subdomains.empty();
1437 for (
unsigned vg=0; vg<n_var_groups; vg++)
1439 const VariableGroup & vg_description(this->variable_group(vg));
1441 const unsigned int n_vars_in_group = vg_description.
n_variables();
1447 for (
auto & elem :
mesh.active_local_element_ptr_range())
1453 const bool active_on_elem =
1458 if (!active_on_elem && constraining_subdomains_empty)
1461 const unsigned int n_nodes = elem->n_nodes();
1464 for (
unsigned int n=0; n<
n_nodes; n++)
1466 Node & node = elem->node_ref(n);
1468 bool active_on_node = active_on_elem;
1469 if (!active_on_node)
1470 if (
auto it = constraining_subdomains.find(&node);
1471 it != constraining_subdomains.end())
1472 for (
auto s : it->second)
1475 active_on_node =
true;
1479 if (!active_on_node)
1487 DofObject::invalid_id))
1491 next_free_dof += (n_vars_in_group*
1497 if (elem->n_comp_group(sys_num,vg) > 0)
1499 libmesh_assert_equal_to (elem->vg_dof_base(sys_num,vg),
1500 DofObject::invalid_id);
1502 elem->set_vg_dof_base(sys_num,
1506 next_free_dof += (n_vars_in_group*
1507 elem->n_comp_group(sys_num,vg));
1519 for (
auto & node :
mesh.local_node_ptr_range())
1520 if (node->n_comp_group(sys_num,vg))
1521 if (node->vg_dof_base(sys_num,vg) == DofObject::invalid_id)
1523 node->set_vg_dof_base (sys_num,
1527 next_free_dof += (n_vars_in_group*
1528 node->n_comp_group(sys_num,vg));
1532 this->distribute_scalar_dofs(next_free_dof);
1535 this->assert_no_nodes_missed(
mesh);
1543 this->_n_SCALAR_dofs = 0;
1544 for (
auto vg :
make_range(this->n_variable_groups()))
1546 const VariableGroup & vg_description(this->variable_group(vg));
1550 this->_n_SCALAR_dofs += (vg_description.
n_variables()*
1558 if (this->processor_id() == (this->n_processors()-1))
1559 next_free_dof += _n_SCALAR_dofs;
1567 MeshTools::libmesh_assert_valid_procids<Node>(
mesh);
1569 for (
auto & node :
mesh.local_node_ptr_range())
1571 unsigned int n_var_g = node->n_var_groups(this->sys_number());
1572 for (
unsigned int vg=0; vg != n_var_g; ++vg)
1574 unsigned int n_comp_g =
1575 node->n_comp_group(this->sys_number(), vg);
1577 node->vg_dof_base(this->sys_number(), vg) : 0;
1578 libmesh_assert_not_equal_to (my_first_dof, DofObject::invalid_id);
1595 for (
const auto & gf :
as_range(gf_begin, gf_end))
1600 (*gf)(elems_begin, elems_end, p, more_elements_to_ghost);
1605#if defined(LIBMESH_ENABLE_DEPRECATED) && defined(LIBMESH_ENABLE_AMR)
1606 std::vector<std::pair<const Elem*, const CouplingMatrix*>> children_to_couple;
1607 for (
auto it = more_elements_to_ghost.begin();
1608 it != more_elements_to_ghost.end();)
1610 const Elem * elem = it->first;
1613 libmesh_deprecated();
1614 std::vector<const Elem*> children_to_ghost;
1617 for (
const Elem * child : children_to_ghost)
1618 if (child->processor_id() != p)
1619 children_to_couple.emplace_back(child, it->second);
1621 it = more_elements_to_ghost.erase(it);
1626 more_elements_to_ghost.insert(children_to_couple.begin(),
1627 children_to_couple.end());
1630 for (
const auto & [elem, elem_cm] : more_elements_to_ghost)
1636 if (
const auto existing_it = elements_to_ghost.find(elem);
1637 existing_it == elements_to_ghost.end())
1638 elements_to_ghost.emplace(elem, elem_cm);
1641 if (existing_it->second)
1648 if (temporary_coupling_matrices.empty() ||
1649 !temporary_coupling_matrices.count(existing_it->second))
1655 auto result_pr = temporary_coupling_matrices.insert(std::make_unique<CouplingMatrix>(*existing_it->second));
1656 existing_it->second = result_pr.first->get();
1672 if (
const auto temp_it = temporary_coupling_matrices.find(existing_it->second);
1673 temp_it != temporary_coupling_matrices.end())
1674 temporary_coupling_matrices.erase(temp_it);
1676 existing_it->second =
nullptr;
1691 LOG_SCOPE(
"add_neighbors_to_send_list()",
"DofMap");
1694 if (this->n_processors() == 1)
1697 const unsigned int n_var = this->n_variables();
1700 =
mesh.active_local_elements_begin();
1702 =
mesh.active_local_elements_end();
1710 this->merge_ghost_functor_outputs(elements_to_send,
1711 temporary_coupling_matrices,
1712 this->algebraic_ghosting_functors_begin(),
1713 this->algebraic_ghosting_functors_end(),
1714 local_elem_it, local_elem_end,
mesh.processor_id());
1716 this->merge_ghost_functor_outputs(elements_to_send,
1717 temporary_coupling_matrices,
1718 this->coupling_functors_begin(),
1719 this->coupling_functors_end(),
1720 local_elem_it, local_elem_end,
mesh.processor_id());
1725 std::map<const CouplingMatrix *, std::vector<unsigned int>>
1726 column_variable_lists;
1728 for (
const auto & [partner, ghost_coupling] : elements_to_send)
1731 libmesh_assert_not_equal_to
1732 (partner->processor_id(), this->processor_id());
1739 libmesh_assert_equal_to (ghost_coupling->size(), n_var);
1742 std::map<const CouplingMatrix *, std::vector<unsigned int>>::const_iterator
1743 column_variable_list = column_variable_lists.find(ghost_coupling);
1746 if (column_variable_list == column_variable_lists.end())
1748 auto inserted_variable_list_pair =
1749 column_variable_lists.emplace(ghost_coupling, std::vector<unsigned int>());
1750 column_variable_list = inserted_variable_list_pair.first;
1752 std::vector<unsigned int> & new_variable_list =
1753 inserted_variable_list_pair.first->second;
1755 std::vector<unsigned char> has_variable(n_var,
false);
1757 for (
unsigned int vi = 0; vi != n_var; ++vi)
1761 for (
const auto & vj : ccr)
1762 has_variable[vj] =
true;
1764 for (
unsigned int vj = 0; vj != n_var; ++vj)
1766 if (has_variable[vj])
1767 new_variable_list.push_back(vj);
1771 const std::vector<unsigned int> & variable_list =
1772 column_variable_list->second;
1774 for (
const auto & vj : variable_list)
1776 std::vector<dof_id_type> di;
1777 this->dof_indices (partner, di, vj);
1781 if (d != DofObject::invalid_id &&
1782 !this->local_index(d))
1784 libmesh_assert_less(d, this->n_dofs());
1785 _send_list.push_back(d);
1791 std::vector<dof_id_type> di;
1792 this->dof_indices (partner, di);
1795 for (
const auto & dof : di)
1796 if (dof != DofObject::invalid_id &&
1797 !this->local_index(dof))
1799 libmesh_assert_less(dof, this->n_dofs());
1800 _send_list.push_back(dof);
1807 temporary_coupling_matrices.clear();
1817 for ( ; local_elem_it != local_elem_end; ++local_elem_it)
1819 const Elem * elem = *local_elem_it;
1821 std::vector<dof_id_type> di;
1822 this->dof_indices (elem, di);
1825 for (
const auto & dof : di)
1826 if (dof != DofObject::invalid_id &&
1827 !this->local_index(dof))
1829 libmesh_assert_less(dof, this->n_dofs());
1830 _send_list.push_back(dof);
1837void DofMap::prepare_send_list ()
1839 LOG_SCOPE(
"prepare_send_list()",
"DofMap");
1842 if (this->n_processors() == 1)
1846 if (_extra_send_list_function)
1848 if (_augment_send_list)
1851 libMesh::out <<
"WARNING: You have specified both an extra send list function and object.\n"
1852 <<
" Are you sure this is what you meant to do??"
1856 _extra_send_list_function(_send_list, _extra_send_list_context);
1859 if (_augment_send_list)
1860 _augment_send_list->augment_send_list (_send_list);
1865 std::sort(_send_list.begin(), _send_list.end());
1868 std::vector<dof_id_type>::iterator new_end =
1869 std::unique (_send_list.begin(), _send_list.end());
1873 std::vector<dof_id_type> (_send_list.begin(), new_end).swap (_send_list);
1876 libmesh_assert(_send_list.empty() || _send_list.back() < this->n_dofs());
1881 this->clear_send_list();
1882 this->add_neighbors_to_send_list(
mesh);
1884#ifdef LIBMESH_ENABLE_CONSTRAINTS
1888 this->process_constraints(
mesh);
1890 this->prepare_send_list();
1893void DofMap::set_implicit_neighbor_dofs(
bool implicit_neighbor_dofs)
1895 _implicit_neighbor_dofs_initialized =
true;
1896 _implicit_neighbor_dofs = implicit_neighbor_dofs;
1899void DofMap::set_verify_dirichlet_bc_consistency(
bool val)
1901 _verify_dirichlet_bc_consistency = val;
1905bool DofMap::use_coupled_neighbor_dofs(
const MeshBase & )
const
1909 bool implicit_neighbor_dofs =
1916 if (implicit_neighbor_dofs)
1932 if (_implicit_neighbor_dofs_initialized)
1934 implicit_neighbor_dofs = _implicit_neighbor_dofs;
1938 if (!implicit_neighbor_dofs)
1946 bool all_discontinuous_dofs =
true;
1950 if (FEInterface::get_continuity(this->variable_type(var)) !=
DISCONTINUOUS)
1951 all_discontinuous_dofs =
false;
1953 if (all_discontinuous_dofs)
1954 implicit_neighbor_dofs =
true;
1957 return implicit_neighbor_dofs;
1964 _sp = this->build_sparsity(
mesh, this->_constrained_sparsity_construction);
1969 for (
const auto & mat : _matrices)
1971 mat->attach_sparsity_pattern (*_sp);
1972 if (_need_full_sparsity_pattern)
1973 mat->update_sparsity_pattern (_sp->get_sparsity_pattern());
1977 if (!_need_full_sparsity_pattern)
1978 _sp->clear_full_sparsity();
1983void DofMap::clear_sparsity()
1990void DofMap::remove_default_ghosting()
1992 this->remove_coupling_functor(this->default_coupling());
1993 this->remove_algebraic_ghosting_functor(this->default_algebraic_ghosting());
1998void DofMap::add_default_ghosting()
2000 this->add_coupling_functor(this->default_coupling());
2001 this->add_algebraic_ghosting_functor(this->default_algebraic_ghosting());
2011#ifdef LIBMESH_ENABLE_DEPRECATED
2012 _coupling_functors.erase
2013 (std::remove(_coupling_functors.begin(),
2014 _coupling_functors.end(),
2016 _coupling_functors.end());
2021 _coupling_functors.end(),
2022 &coupling_functor) ==
2023 _coupling_functors.end());
2025 _coupling_functors.push_back(&coupling_functor);
2028 _mesh.add_ghosting_functor(coupling_functor);
2036 auto raw_it = std::find(_coupling_functors.begin(),
2037 _coupling_functors.end(), &coupling_functor);
2039#ifndef LIBMESH_ENABLE_DEPRECATED
2044 if (raw_it != _coupling_functors.end())
2046 _coupling_functors.erase(raw_it);
2050 _coupling_functors.end(),
2051 &coupling_functor) ==
2052 _coupling_functors.end());
2054 _mesh.remove_ghosting_functor(coupling_functor);
2056 if (
const auto it = _shared_functors.find(&coupling_functor);
2057 it != _shared_functors.end())
2058 _shared_functors.erase(it);
2068#ifdef LIBMESH_ENABLE_DEPRECATED
2069 _algebraic_ghosting_functors.erase
2070 (std::remove(_algebraic_ghosting_functors.begin(),
2071 _algebraic_ghosting_functors.end(),
2072 &evaluable_functor),
2073 _algebraic_ghosting_functors.end());
2078 _algebraic_ghosting_functors.end(),
2079 &evaluable_functor) ==
2080 _algebraic_ghosting_functors.end());
2082 _algebraic_ghosting_functors.push_back(&evaluable_functor);
2083 evaluable_functor.
set_mesh(&_mesh);
2085 _mesh.add_ghosting_functor(evaluable_functor);
2093 auto raw_it = std::find(_algebraic_ghosting_functors.begin(),
2094 _algebraic_ghosting_functors.end(),
2095 &evaluable_functor);
2097#ifndef LIBMESH_ENABLE_DEPRECATED
2102 if (raw_it != _algebraic_ghosting_functors.end())
2104 _algebraic_ghosting_functors.erase(raw_it);
2108 _algebraic_ghosting_functors.end(),
2109 &evaluable_functor) ==
2110 _algebraic_ghosting_functors.end());
2112 _mesh.remove_ghosting_functor(evaluable_functor);
2114 if (
const auto it = _shared_functors.find(&evaluable_functor);
2115 it != _shared_functors.end())
2116 _shared_functors.erase(it);
2122 const std::vector<dof_id_type> & dof_indices_in,
2125 const unsigned int n_original_dofs = dof_indices_in.size();
2127#ifdef LIBMESH_ENABLE_AMR
2130 libmesh_assert_equal_to (dof_indices_in.size(), Ue.
size());
2131 bool has_constrained_dofs =
false;
2133 for (
unsigned int il=0; il != n_original_dofs; ++il)
2137 if (this->is_constrained_dof (ig)) has_constrained_dofs =
true;
2139 libmesh_assert_less (ig, Ug.
size());
2147 if (has_constrained_dofs)
2150 std::vector<dof_id_type> constrained_dof_indices(dof_indices_in);
2155 this->build_constraint_matrix_and_vector (C, H, constrained_dof_indices);
2157 libmesh_assert_equal_to (dof_indices_in.size(), C.
m());
2158 libmesh_assert_equal_to (constrained_dof_indices.size(), C.
n());
2164 for (
unsigned int i=0; i != n_original_dofs; i++)
2168 const unsigned int n_constrained =
2169 cast_int<unsigned int>(constrained_dof_indices.size());
2170 for (
unsigned int j=0; j<n_constrained; j++)
2172 const dof_id_type jg = constrained_dof_indices[j];
2180 Ue.
el(i) += C(i,j)*Ug(jg);
2189 libmesh_assert_equal_to (n_original_dofs, Ue.
size());
2191 for (
unsigned int il=0; il<n_original_dofs; il++)
2203void DofMap::dof_indices (
const Elem *
const elem,
2204 std::vector<dof_id_type> & di)
const
2224 const unsigned int n_var_groups = this->n_variable_groups();
2228 std::size_t tot_size = 0;
2240 std::vector<const Node *> elem_nodes;
2241 MeshTools::Subdivision::find_one_ring(sd_elem, elem_nodes);
2244 for (
unsigned int vg=0; vg<n_var_groups; vg++)
2247 const unsigned int vars_in_group = var.
n_variables();
2252 for (
unsigned int vig=0; vig != vars_in_group; ++vig)
2257 std::vector<dof_id_type> di_new;
2258 this->SCALAR_dof_indices(di_new,var.
number(vig));
2259 di.insert( di.end(), di_new.begin(), di_new.end());
2263 for (
unsigned int vig=0; vig != vars_in_group; ++vig)
2265 _dof_indices(*elem, elem->
p_level(), di, vg, vig,
2267 cast_int<unsigned int>(elem_nodes.size()),
2282 for (
unsigned int vg=0; vg<n_var_groups; vg++)
2285 const unsigned int vars_in_group = var.
n_variables();
2291 for (
unsigned int vig=0; vig != vars_in_group; ++vig)
2296 std::vector<dof_id_type> di_new;
2297 this->SCALAR_dof_indices(di_new,var.
number(vig));
2298 di.insert( di.end(), di_new.begin(), di_new.end());
2302 for (
unsigned int vig=0; vig != vars_in_group; ++vig)
2304 _dof_indices(*elem, elem->
p_level(), di, vg, vig,
2314 libmesh_assert_equal_to (tot_size, di.size());
2319void DofMap::dof_indices (
const Elem *
const elem,
2320 std::vector<dof_id_type> & di,
2321 const unsigned int vn,
2329 std::vector<dof_id_type> & dof_indices,
2330 const std::vector<dof_id_type> & scalar_dof_indices) {
2331 dof_indices.insert(dof_indices.end(), scalar_dof_indices.begin(), scalar_dof_indices.end());
2336 std::vector<dof_id_type> & dof_indices,
2337 const dof_id_type dof) { dof_indices.push_back(dof); },
2341void DofMap::array_dof_indices(
const Elem *
const elem,
2342 std::vector<dof_id_type> & di,
2343 const unsigned int vn,
2346 auto dof_indices_functor = [elem, p_level,
this](std::vector<dof_id_type> & functor_di,
2347 const unsigned int functor_vn) {
2348 this->dof_indices(elem, functor_di, functor_vn, p_level);
2350 this->array_dof_indices(dof_indices_functor, di, vn);
2353void DofMap::array_dof_indices(
const Node *
const node,
2354 std::vector<dof_id_type> & di,
2355 const unsigned int vn)
const
2357 auto dof_indices_functor = [node,
this](std::vector<dof_id_type> & functor_di,
2358 const unsigned int functor_vn) {
2359 this->dof_indices(node, functor_di, functor_vn);
2361 this->array_dof_indices(dof_indices_functor, di, vn);
2364void DofMap::dof_indices (
const Node *
const node,
2365 std::vector<dof_id_type> & di)
const
2380 const unsigned int n_var_groups = this->n_variable_groups();
2381 const unsigned int sys_num = this->sys_number();
2384 for (
unsigned int vg=0; vg<n_var_groups; vg++)
2387 const unsigned int vars_in_group = var.
n_variables();
2391 for (
unsigned int vig=0; vig != vars_in_group; ++vig)
2393 std::vector<dof_id_type> di_new;
2394 this->SCALAR_dof_indices(di_new,var.
number(vig));
2395 di.insert( di.end(), di_new.begin(), di_new.end());
2401 for (
unsigned int vig=0; vig != vars_in_group; ++vig)
2403 for (
int i=0; i != n_comp; ++i)
2406 node->
dof_number(sys_num, vg, vig, i, n_comp);
2407 libmesh_assert_not_equal_to
2408 (d, DofObject::invalid_id);
2417void DofMap::dof_indices (
const Node *
const node,
2418 std::vector<dof_id_type> & di,
2419 const unsigned int vn)
const
2423 this->dof_indices(node, di);
2440 const unsigned int sys_num = this->sys_number();
2443 const unsigned int vg = this->_variable_group_numbers[vn];
2448 std::vector<dof_id_type> di_new;
2449 this->SCALAR_dof_indices(di_new,vn);
2450 di.insert( di.end(), di_new.begin(), di_new.end());
2454 const unsigned int vig = vn - var.
number();
2456 for (
int i=0; i != n_comp; ++i)
2459 node->
dof_number(sys_num, vg, vig, i, n_comp);
2460 libmesh_assert_not_equal_to
2461 (d, DofObject::invalid_id);
2468void DofMap::dof_indices (
const Elem & elem,
2470 std::vector<dof_id_type> & di,
2471 const unsigned int vn)
const
2473 this->_node_dof_indices(elem, n, elem.
node_ref(n), di, vn);
2478#ifdef LIBMESH_ENABLE_AMR
2480void DofMap::old_dof_indices (
const Elem & elem,
2482 std::vector<dof_id_type> & di,
2483 const unsigned int vn)
const
2486 this->_node_dof_indices(elem, n, old_obj, di, vn);
2493void DofMap::_node_dof_indices (
const Elem & elem,
2496 std::vector<dof_id_type> & di,
2497 const unsigned int vn)
const
2509 const unsigned int sys_num = this->sys_number();
2510 const auto [vg, vig] =
2512 const unsigned int n_comp = obj.
n_comp_group(sys_num,vg);
2516 const bool extra_hanging_dofs =
2517 FEInterface::extra_hanging_dofs(fe_type);
2525 const unsigned int nc =
2526 FEInterface::n_dofs_at_node(fe_type, &elem, n, add_p_level);
2532 if (extra_hanging_dofs && nc && !elem.
is_vertex(n))
2534 const int dof_offset = n_comp - nc;
2542 di.resize(di.size() + nc, DofObject::invalid_id);
2545 for (
unsigned int i = dof_offset; i != n_comp; ++i)
2549 libmesh_assert_not_equal_to (d, DofObject::invalid_id);
2560 const unsigned int good_nc =
2561 std::min(
static_cast<unsigned int>(n_comp), nc);
2562 for (
unsigned int i=0; i != good_nc; ++i)
2566 libmesh_assert_not_equal_to (d, DofObject::invalid_id);
2569 for (
unsigned int i=good_nc; i != nc; ++i)
2570 di.push_back(DofObject::invalid_id);
2575DofMap::_dof_indices(
const Elem & elem,
2577 std::vector<dof_id_type> & di,
2578 const unsigned int vg,
2579 const unsigned int vig,
2580 const Node *
const * nodes,
2582 const unsigned int v
2585 std::size_t & tot_size
2603 std::vector<dof_id_type> & functor_di,
2604 const dof_id_type dof) { functor_di.push_back(dof); });
2607void DofMap::SCALAR_dof_indices (std::vector<dof_id_type> & di,
2608 const unsigned int vn,
2609#ifdef LIBMESH_ENABLE_AMR
2623#ifdef LIBMESH_ENABLE_AMR
2626 libmesh_assert_greater_equal(n_old_dofs(), n_SCALAR_dofs());
2629 this->_first_old_scalar_df[vn] : this->_first_scalar_df[vn];
2634 libmesh_assert_not_equal_to(my_idx, DofObject::invalid_id);
2637 const int n_dofs_vn = this->variable(vn).type().order.get_order();
2639 di.resize(n_dofs_vn);
2640 for (
int i = 0; i != n_dofs_vn; ++i)
2649 if (!this->local_index(dof_index))
2653 if (!std::binary_search(_send_list.begin(), _send_list.end(), dof_index))
2662bool DofMap::all_semilocal_indices (
const std::vector<dof_id_type> & dof_indices_in)
const
2665 for (
const auto & di : dof_indices_in)
2666 if (!this->semilocal_index(di))
2674template <
typename DofObjectSub
class>
2675bool DofMap::is_evaluable(
const DofObjectSubclass & obj,
2676 unsigned int var_num)
const
2679 if (obj.processor_id() == this->processor_id())
2682 std::vector<dof_id_type> di;
2685 this->dof_indices(&obj, di);
2687 this->dof_indices(&obj, di, var_num);
2689 return this->all_semilocal_indices(di);
2694#ifdef LIBMESH_ENABLE_AMR
2696void DofMap::old_dof_indices (
const Elem *
const elem,
2697 std::vector<dof_id_type> & di,
2698 const unsigned int vn)
const
2708 const unsigned int sys_num = this->sys_number();
2709 const unsigned int n_var_groups = this->n_variable_groups();
2710#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
2711 const bool is_inf = elem->
infinite();
2725 std::vector<const Node *> elem_nodes;
2726 const Node *
const * nodes_ptr;
2732 MeshTools::Subdivision::find_one_ring(sd_elem, elem_nodes);
2733 nodes_ptr = elem_nodes.data();
2734 n_nodes = cast_int<unsigned int>(elem_nodes.size());
2744 for (
unsigned int vg=0; vg<n_var_groups; vg++)
2747 const unsigned int vars_in_group = var.
n_variables();
2749 for (
unsigned int vig=0; vig<vars_in_group; vig++)
2751 const unsigned int v = var.
number(vig);
2759 std::vector<dof_id_type> di_new;
2760 this->SCALAR_dof_indices(di_new,v,
true);
2761 di.insert( di.end(), di_new.begin(), di_new.end());
2774 int p_adjustment = 0;
2777 libmesh_assert_greater (elem->
p_level(), 0);
2784 p_adjustment *= add_p_level;
2787 int extra_order =
int(add_p_level*elem->
p_level()) + p_adjustment;
2789 const bool extra_hanging_dofs =
2790 FEInterface::extra_hanging_dofs(fe_type);
2792 const FEInterface::n_dofs_at_node_ptr ndan =
2793 FEInterface::n_dofs_at_node_function(fe_type, elem);
2796 for (
unsigned int n=0; n<
n_nodes; n++)
2798 const Node * node = nodes_ptr[n];
2805 const unsigned int nc =
2806#ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
2808 FEInterface::n_dofs_at_node(var.
type(), extra_order, elem, n) :
2810 ndan (type, var.
type().
order + extra_order, n);
2812 const int n_comp = old_dof_obj.
n_comp_group(sys_num,vg);
2818 if (extra_hanging_dofs && !elem->
is_vertex(n))
2820 const int dof_offset = n_comp - nc;
2828 Elem::JUST_COARSENED);
2829 di.resize(di.size() + nc, DofObject::invalid_id);
2832 for (
int i=n_comp-1; i>=dof_offset; i--)
2835 old_dof_obj.
dof_number(sys_num, vg, vig, i, n_comp);
2854 const unsigned int old_nc =
2855 std::min(
static_cast<unsigned int>(n_comp), nc);
2856 for (
unsigned int i=0; i != old_nc; ++i)
2859 old_dof_obj.
dof_number(sys_num, vg, vig, i, n_comp);
2861 libmesh_assert_not_equal_to (d, DofObject::invalid_id);
2865 for (
unsigned int i=old_nc; i != nc; ++i)
2866 di.push_back(DofObject::invalid_id);
2871 const unsigned int nc =
2872 FEInterface::n_dofs_per_elem(fe_type, extra_order, elem);
2878 const unsigned int n_comp =
2881 if (old_dof_obj.
n_systems() > sys_num &&
2885 for (
unsigned int i=0; i<nc; i++)
2888 old_dof_obj.
dof_number(sys_num, vg, vig, i, n_comp);
2903 di.resize(di.size() + nc, DofObject::invalid_id);
2915#ifdef LIBMESH_ENABLE_CONSTRAINTS
2917void DofMap::find_connected_dofs (std::vector<dof_id_type> & elem_dofs)
const
2919 typedef std::set<dof_id_type> RCSet;
2922 RCSet dof_set (elem_dofs.begin(), elem_dofs.end());
2931 for (
const auto & dof : elem_dofs)
2932 if (this->is_constrained_dof(dof))
2935 DofConstraints::const_iterator
2936 pos = _dof_constraints.find(dof);
2949 for (
const auto & pr : constraint_row)
2950 if (!dof_set.count (pr.first))
2952 dof_set.insert (pr.first);
2964 elem_dofs.insert (elem_dofs.end(),
2965 dof_set.begin(), dof_set.end());
2971 this->find_connected_dofs (elem_dofs);
2980void DofMap::print_info(std::ostream & os)
const
2982 os << this->get_info();
2987std::string DofMap::get_info()
const
2989 std::ostringstream os;
2994 const char * may_equal =
" <= ";
2998 for (
const auto & mat : _matrices)
2999 if (mat->need_full_sparsity_pattern())
3003 long double avg_n_nz = 0, avg_n_oz = 0;
3007 for (
const auto & val : _sp->get_n_nz())
3009 max_n_nz = std::max(max_n_nz, val);
3013 std::size_t n_nz_size = _sp->get_n_nz().size();
3015 this->comm().max(max_n_nz);
3016 this->comm().sum(avg_n_nz);
3017 this->comm().sum(n_nz_size);
3019 avg_n_nz /= std::max(n_nz_size,std::size_t(1));
3021 for (
const auto & val : _sp->get_n_oz())
3023 max_n_oz = std::max(max_n_oz, val);
3027 std::size_t n_oz_size = _sp->get_n_oz().size();
3029 this->comm().max(max_n_oz);
3030 this->comm().sum(avg_n_oz);
3031 this->comm().sum(n_oz_size);
3033 avg_n_oz /= std::max(n_oz_size,std::size_t(1));
3036 os <<
" DofMap Sparsity\n Average On-Processor Bandwidth"
3037 << may_equal << avg_n_nz <<
'\n';
3039 os <<
" Average Off-Processor Bandwidth"
3040 << may_equal << avg_n_oz <<
'\n';
3042 os <<
" Maximum On-Processor Bandwidth"
3043 << may_equal << max_n_nz <<
'\n';
3045 os <<
" Maximum Off-Processor Bandwidth"
3046 << may_equal << max_n_oz << std::endl;
3048#ifdef LIBMESH_ENABLE_CONSTRAINTS
3050 std::size_t n_constraints = 0, max_constraint_length = 0,
3052 long double avg_constraint_length = 0.;
3054 for (
const auto & [constrained_dof, row] : _dof_constraints)
3057 if (!this->local_index(constrained_dof))
3060 std::size_t rowsize = row.size();
3062 max_constraint_length = std::max(max_constraint_length,
3064 avg_constraint_length += rowsize;
3067 if (_primal_constraint_values.count(constrained_dof))
3071 this->comm().sum(n_constraints);
3072 this->comm().sum(n_rhss);
3073 this->comm().sum(avg_constraint_length);
3074 this->comm().max(max_constraint_length);
3076 os <<
" DofMap Constraints\n Number of DoF Constraints = "
3080 <<
" Number of Heterogenous Constraints= " << n_rhss;
3083 avg_constraint_length /= n_constraints;
3086 <<
" Average DoF Constraint Length= " << avg_constraint_length;
3089#ifdef LIBMESH_ENABLE_NODE_CONSTRAINTS
3090 std::size_t n_node_constraints = 0, max_node_constraint_length = 0,
3092 long double avg_node_constraint_length = 0.;
3094 for (
const auto & [node, pr] : _node_constraints)
3097 if (node->processor_id() != this->processor_id())
3101 std::size_t rowsize = row.size();
3103 max_node_constraint_length = std::max(max_node_constraint_length,
3105 avg_node_constraint_length += rowsize;
3106 n_node_constraints++;
3108 if (pr.second !=
Point(0))
3112 this->comm().sum(n_node_constraints);
3113 this->comm().sum(n_node_rhss);
3114 this->comm().sum(avg_node_constraint_length);
3115 this->comm().max(max_node_constraint_length);
3117 os <<
"\n Number of Node Constraints = " << n_node_constraints;
3120 <<
" Number of Heterogenous Node Constraints= " << n_node_rhss;
3121 if (n_node_constraints)
3123 avg_node_constraint_length /= n_node_constraints;
3124 os <<
"\n Maximum Node Constraint Length= " << max_node_constraint_length
3126 <<
" Average Node Constraint Length= " << avg_node_constraint_length;
3139 _sc = std::make_unique<StaticCondensationDofMap>(
mesh, sys, *
this);
3142void DofMap::reinit_static_condensation()
3148unsigned int DofMap::add_variable(
System & sys,
3149 std::string_view var,
3151 const std::set<subdomain_id_type> *
const active_subdomains)
3153 parallel_object_only();
3157 libmesh_assert(this->comm().verify((active_subdomains ==
nullptr)));
3159 if (active_subdomains)
3165 if (this->variable_name(v) == var)
3167 if (this->variable_type(v) == type)
3174 const Variable & existing_var = this->variable(v);
3178 bool check1 = (!active_subdomains || active_subdomains->empty()) &&
3184 (active_subdomains && (*active_subdomains == existing_var.
active_subdomains()));
3187 if (check1 || check2)
3188 return _variables[v].number();
3191 libmesh_error_msg(
"ERROR: incompatible variable "
3192 << var <<
" has already been added for this system!");
3197 if (this->n_variable_groups())
3205 bool should_be_in_vg = this->identify_variable_groups();
3210 const std::set<subdomain_id_type> *
const their_active_subdomains(
3214 if (vg.
type() != type)
3215 should_be_in_vg =
false;
3218 if (their_active_subdomains &&
3219 (!active_subdomains || (active_subdomains && active_subdomains->empty())))
3220 should_be_in_vg =
false;
3223 if (!their_active_subdomains && (active_subdomains && !active_subdomains->empty()))
3224 should_be_in_vg =
false;
3226 if (their_active_subdomains && active_subdomains)
3228 if (*their_active_subdomains != *active_subdomains)
3229 should_be_in_vg =
false;
3233 if (should_be_in_vg)
3235 const unsigned int vn = this->
n_vars();
3237 std::string varstr(var);
3239 _variable_numbers[varstr] = vn;
3240 vg.
append(std::move(varstr));
3242 const unsigned int vgn = _variable_groups.size() - 1;
3243 _variable_group_numbers.push_back(vgn);
3244 _var_to_vg.emplace(vn, vgn);
3251 return this->add_variables(
3252 sys, std::vector<std::string>(1, std::string(var)), type, active_subdomains);
3255unsigned int DofMap::add_variables(
System & sys,
3256 const std::vector<std::string> & vars,
3258 const std::set<subdomain_id_type> *
const active_subdomains)
3260 parallel_object_only();
3266 libmesh_assert(this->comm().verify((active_subdomains ==
nullptr)));
3268 if (active_subdomains)
3273 for (
auto ovar : vars)
3278 if (this->variable_name(v) == ovar)
3280 if (this->variable_type(v) == type)
3281 return _variables[v].number();
3283 libmesh_error_msg(
"ERROR: incompatible variable "
3284 << ovar <<
" has already been added for this system!");
3288 if (this->n_variable_groups())
3296 bool should_be_in_vg = this->identify_variable_groups();
3301 const std::set<subdomain_id_type> *
const their_active_subdomains(
3305 if (vg.
type() != type)
3306 should_be_in_vg =
false;
3309 if (their_active_subdomains &&
3310 (!active_subdomains || (active_subdomains && active_subdomains->empty())))
3311 should_be_in_vg =
false;
3314 if (!their_active_subdomains && (active_subdomains && !active_subdomains->empty()))
3315 should_be_in_vg =
false;
3317 if (their_active_subdomains && active_subdomains)
3319 if (*their_active_subdomains != *active_subdomains)
3320 should_be_in_vg =
false;
3324 if (should_be_in_vg)
3326 unsigned int vn = this->
n_vars();
3327 const unsigned int vgn = _variable_groups.size() - 1;
3329 for (
auto ovar : vars)
3336 _variable_numbers[ovar] = vn;
3337 _variable_group_numbers.push_back(vgn);
3338 _var_to_vg.emplace(vn, vgn);
3344 const unsigned int curr_n_vars = this->
n_vars();
3346 const unsigned int next_first_component = this->n_components(sys.
get_mesh());
3350 _variable_groups.push_back(
3351 (active_subdomains ==
nullptr)
3352 ?
VariableGroup(&sys, vars, curr_n_vars, next_first_component, type)
3353 :
VariableGroup(&sys, vars, curr_n_vars, next_first_component, type, *active_subdomains));
3356 const unsigned int vgn = _variable_groups.size() - 1;
3361 const unsigned int vn = curr_n_vars + v;
3362 _variables.push_back(vg(v));
3363 _variable_numbers[vars[v]] = vn;
3364 _variable_group_numbers.push_back(vgn);
3365 _var_to_vg.emplace(vn, vgn);
3368 libmesh_assert_equal_to((curr_n_vars + vars.size()), this->n_vars());
3376 return cast_int<unsigned int>(curr_n_vars + vars.size() - 1);
3379unsigned int DofMap::add_variable_array (
System & sys,
3380 const std::vector<std::string> & vars,
3382 const std::set<subdomain_id_type> *
const active_subdomains)
3384 const unsigned int count = cast_int<unsigned int>(vars.size());
3385 const unsigned int last_var = this->add_variables(sys, vars, type, active_subdomains);
3386 const unsigned int first_var = last_var + 1 - count;
3387 _array_variables.push_back({first_var, first_var + count});
3391void DofMap::get_all_variable_numbers(std::vector<unsigned int> & all_variable_numbers)
const
3393 all_variable_numbers.resize(
n_vars());
3395 unsigned int count = 0;
3396 for (
auto vn : _variable_numbers)
3397 all_variable_numbers[count++] = vn.second;
3400template LIBMESH_EXPORT
bool DofMap::is_evaluable<Elem>(
const Elem &,
unsigned int)
const;
3401template LIBMESH_EXPORT
bool DofMap::is_evaluable<Node>(
const Node &,
unsigned int)
const;
void ErrorVector unsigned int
void max(const T &r, T &o, Request &req) const
This proxy class acts like a container of indices from a single coupling row.
This class defines a coupling matrix.
This class implements the default algebraic coupling in libMesh: elements couple to themselves,...
Defines a dense matrix for use in Finite Element-type computations.
Defines an abstract dense vector base class for use in Finite Element-type computations.
virtual void zero()=0
Set every element in the vector to 0.
virtual T el(const unsigned int i) const =0
virtual unsigned int size() const =0
Defines a dense vector for use in Finite Element-type computations.
We're using a class instead of a typedef to allow forward declarations and future flexibility.
This base class provides a minimal set of interfaces for satisfying user requests for.
void reinit(MeshBase &mesh, const std::map< const Node *, std::set< subdomain_id_type > > &constraining_subdomains)
Reinitialize the underlying data structures conformal to the current mesh.
unsigned int n_variable_groups() const
bool use_coupled_neighbor_dofs(const MeshBase &mesh) const
Tells other library functions whether or not this problem includes coupling between dofs in neighbori...
virtual void clear() override
Free all new memory associated with the object, but restore its original state, with the mesh pointer...
void * _extra_sparsity_context
A pointer associated with the extra sparsity that can optionally be passed in.
std::vector< GhostingFunctor * >::const_iterator GhostingFunctorIterator
Iterator type for coupling and algebraic ghosting functor ranges.
bool is_attached(SparseMatrix< Number > &matrix)
Matrices should not be attached more than once.
std::unique_ptr< DefaultCoupling > _default_evaluating
The default algebraic GhostingFunctor, used to implement standard libMesh send_list construction.
void update_sparsity_pattern(SparseMatrix< Number > &matrix) const
Additional matrices may be be temporarily initialized by this DofMap.
bool computed_sparsity_already() const
Returns true iff a sparsity pattern has already been computed.
void set_error_on_cyclic_constraint(bool error_on_cyclic_constraint)
Specify whether or not we perform an extra (opt-mode enabled) check for constraint loops.
void(* _extra_sparsity_function)(SparsityPattern::Graph &, std::vector< dof_id_type > &n_nz, std::vector< dof_id_type > &n_oz, void *)
A function pointer to a function to call to add extra entries to the sparsity pattern.
void set_nonlocal_dof_objects(iterator_type objects_begin, iterator_type objects_end, MeshBase &mesh, dofobject_accessor objects)
Helper function for distributing dofs in parallel.
unsigned int sys_number() const
std::vector< GhostingFunctor * > _coupling_functors
The list of all GhostingFunctor objects to be used when coupling degrees of freedom in matrix sparsit...
SparsityPattern::AugmentSparsityPattern * _augment_sparsity_pattern
Function object to call to add extra entries to the sparsity pattern.
void add_algebraic_ghosting_functor(GhostingFunctor &evaluable_functor, bool to_mesh=true)
Adds a functor which can specify algebraic ghosting requirements for use with distributed vectors.
void attach_matrix(SparseMatrix< Number > &matrix)
Additional matrices may be attached to this DofMap.
std::vector< SparseMatrix< Number > * > _matrices
Additional matrices handled by this object.
std::unique_ptr< SparsityPattern::Build > _sp
The sparsity pattern of the global matrix.
CouplingMatrix * _dof_coupling
Degree of freedom coupling.
bool is_periodic_boundary(const boundary_id_type boundaryid) const
std::unique_ptr< PeriodicBoundaries > _periodic_boundaries
Data structure containing periodic boundaries.
std::unique_ptr< DefaultCoupling > _default_coupling
The default coupling GhostingFunctor, used to implement standard libMesh sparsity pattern constructio...
std::set< std::unique_ptr< CouplingMatrix >, Utility::CompareUnderlying > CouplingMatricesSet
bool has_static_condensation() const
Checks whether we have static condensation.
MeshBase & _mesh
The mesh that system uses.
DofObject * node_ptr(MeshBase &mesh, dof_id_type i) const
DofMap(const unsigned int sys_number, MeshBase &mesh)
Constructor.
DofObject * elem_ptr(MeshBase &mesh, dof_id_type i) const
void add_coupling_functor(GhostingFunctor &coupling_functor, bool to_mesh=true)
Adds a functor which can specify coupling requirements for creation of sparse matrices.
std::unique_ptr< SparsityPattern::Build > build_sparsity(const MeshBase &mesh, bool calculate_constrained=false, bool use_condensed_system=false) const
Builds a sparsity pattern for matrices using the current degree-of-freedom numbering and coupling.
bool _error_on_constraint_loop
This flag indicates whether or not we do an opt-mode check for the presence of constraint loops,...
void set_error_on_constraint_loop(bool error_on_constraint_loop)
std::unique_ptr< StaticCondensationDofMap > _sc
Static condensation class.
bool _need_full_sparsity_pattern
Default false; set to true if any attached matrix requires a full sparsity pattern.
The DofObject defines an abstract base class for objects that have degrees of freedom associated with...
dof_id_type vg_dof_base(const unsigned int s, const unsigned int vg) const
VariableGroup DoF indices are indexed as id = base + var_in_vg*ncomp + comp This method allows for di...
unsigned int n_systems() const
unsigned int n_comp(const unsigned int s, const unsigned int var) const
unsigned int n_comp_group(const unsigned int s, const unsigned int vg) const
void set_n_comp_group(const unsigned int s, const unsigned int vg, const unsigned int ncomp)
Sets the number of components for VariableGroup vg of system s associated with this DofObject.
dof_id_type dof_number(const unsigned int s, const unsigned int var, const unsigned int comp) const
std::pair< unsigned int, unsigned int > var_to_vg_and_offset(const unsigned int s, const unsigned int var) const
processor_id_type processor_id() const
unsigned int n_var_groups(const unsigned int s) const
static constexpr dof_id_type invalid_id
An invalid id to distinguish an uninitialized DofObject.
DofObject * get_old_dof_object()
Pointer accessor for previously public old_dof_object.
DofObject & get_old_dof_object_ref()
As above, but do not use in situations where the old_dof_object may be nullptr, since this function a...
void set_vg_dof_base(const unsigned int s, const unsigned int vg, const dof_id_type db)
VariableGroup DoF indices are indexed as id = base + var_in_vg*ncomp + comp This method allows for di...
static constexpr processor_id_type invalid_processor_id
An invalid processor_id to distinguish DoFs that have not been assigned to a processor.
unsigned int n_vars(const unsigned int s, const unsigned int vg) const
bool has_dofs(const unsigned int s=libMesh::invalid_uint) const
This is the base class from which all geometric element types are derived.
RefinementState refinement_flag() const
const Node & node_ref(const unsigned int i) const
virtual unsigned int n_nodes() const =0
subdomain_id_type subdomain_id() const
void active_family_tree(std::vector< const Elem * > &active_family, bool reset=true) const
Same as the family_tree() member, but only adds the active children.
const Node *const * get_nodes() const
virtual bool is_vertex(const unsigned int i) const =0
virtual ElemType type() const =0
unsigned int p_level() const
RefinementState p_refinement_flag() const
virtual bool infinite() const =0
static unsigned int n_dofs_at_node(const unsigned int dim, const FEType &fe_t, const ElemType t, const unsigned int n)
static unsigned int max_order(const FEType &fe_t, const ElemType &el_t)
static unsigned int n_dofs_per_elem(const unsigned int dim, const FEType &fe_t, const ElemType t)
static bool extra_hanging_dofs(const FEType &fe_t)
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
OrderWrapper order
The approximation order of the element (at 0 p-refinement level).
bool p_refinement
Whether or not the finite elements for this type increase their p refinement level on geometric eleme...
FEFamily family
The type of finite element.
This abstract base class defines the interface by which library code and user code can report associa...
virtual void set_mesh(const MeshBase *mesh)
It should be called after cloning a ghosting functor.
std::map< const Elem *, const CouplingMatrix *, CompareDofObjectsByPIDAndThenID > map_type
What elements do we care about and what variables do we care about on each element?
This is the MeshBase class.
const ElemRange & element_stored_range()
void remove_ghosting_functor(GhostingFunctor &ghosting_functor)
Removes a functor which was previously added to the set of ghosting functors.
A Node is like a Point, but with more information.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
virtual numeric_index_type last_local_index() const =0
virtual numeric_index_type size() const =0
virtual numeric_index_type first_local_index() const =0
int get_order() const
Explicitly request the order as an int.
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
We're using a class instead of a typedef to allow forward declarations and future flexibility.
A Point defines a location in LIBMESH_DIM dimensional Real space.
virtual void update_sparsity_pattern(const SparsityPattern::Graph &)
Updates the matrix sparsity pattern.
void attach_dof_map(const DofMap &dof_map)
Set a pointer to the DofMap to use.
virtual bool need_full_sparsity_pattern() const
void attach_sparsity_pattern(const SparsityPattern::Build &sp)
Set a pointer to a sparsity pattern to use.
A class holding degree of freedom information pertinent to static condensation.
The StoredRange class defines a contiguous, divisible set of objects.
Manages consistently variables, degrees of freedom, and coefficient vectors.
bool is_initialized() const
const MeshBase & get_mesh() const
The Tri3Subdivision element is a three-noded subdivision surface shell element used in mechanics calc...
This class defines a logically grouped set of variables in the system.
unsigned int n_variables() const
unsigned int number(unsigned int v) const
void append(std::string var_name)
Appends a variable to the group.
This class defines the notion of a variable in the system.
const std::set< subdomain_id_type > & active_subdomains() const
bool active_on_subdomain(subdomain_id_type sid) const
bool implicitly_active() const
const FEType & type() const
void pull_parallel_vector_data(const Communicator &comm, const MapToVectors &queries, GatherFunctor &gather_data, const ActionFunctor &act_on_data, const datum *example)
void parallel_reduce(const Range &range, Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided reduction operation in parallel on the specified range.
void parallel_for(const Range &range, const Body &body, unsigned int n_threads=libMesh::n_threads())
Execute the provided function object in parallel on the specified range.
std::string enum_to_string(const T e)
The libMesh namespace provides an interface to certain functionality in the library.
std::map< const Node *, Real, std::less< const Node * >, Threads::scalable_allocator< std::pair< const Node *const, Real > > > NodeConstraintRow
A row of the Node constraint mapping.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
ElemType
Defines an enum for geometric element types.
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
StoredRange< MeshBase::element_iterator, Elem * > ElemRange
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
std::map< dof_id_type, Real, std::less< dof_id_type >, Threads::scalable_allocator< std::pair< const dof_id_type, Real > > > DofConstraintRow
A row of the Dof constraint matrix.
bool on_command_line(std::string arg)
uint8_t processor_id_type
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
The definition of the const_element_iterator struct.
const dof_id_type n_nodes