20#include "libmesh/default_coupling.h"
21#include "libmesh/dof_map.h"
22#include "libmesh/eigen_system.h"
23#include "libmesh/elem.h"
24#include "libmesh/explicit_system.h"
25#include "libmesh/fe_base.h"
26#include "libmesh/fe_interface.h"
27#include "libmesh/fem_context.h"
28#include "libmesh/frequency_system.h"
29#include "libmesh/int_range.h"
30#include "libmesh/libmesh_logging.h"
31#include "libmesh/linear_implicit_system.h"
32#include "libmesh/mesh_base.h"
33#include "libmesh/mesh_refinement.h"
34#include "libmesh/newmark_system.h"
35#include "libmesh/nonlinear_implicit_system.h"
36#include "libmesh/parallel.h"
37#include "libmesh/rb_construction.h"
38#include "libmesh/remote_elem.h"
39#include "libmesh/tensor_tools.h"
40#include "libmesh/transient_rb_construction.h"
41#include "libmesh/transient_system.h"
50#include "libmesh/equation_systems.h"
58 _refine_in_reinit(true),
59 _enable_default_ghosting(true)
63 this->
parameters.
set<
unsigned int>(
"linear solver maximum iterations") = 5000;
107 const unsigned int n_sys = this->
n_systems();
109 libmesh_assert_not_equal_to (n_sys, 0);
113 for (
auto & node :
_mesh.node_ptr_range())
114 node->set_n_systems(n_sys);
120 for (Elem * elem : range)
121 elem->set_n_systems(n_sys);
127#ifdef LIBMESH_ENABLE_AMR
141 parallel_object_only();
143 const unsigned int n_sys = this->
n_systems();
144 libmesh_assert_not_equal_to (n_sys, 0);
147 for (
unsigned int i=0; i != n_sys; ++i)
160 for (
auto & node :
_mesh.node_ptr_range())
161 node->set_n_systems(n_sys);
168 for (Elem * elem : range)
169 elem->set_n_systems(n_sys);
174 for (
unsigned int i=0; i != n_sys; ++i)
177#ifdef LIBMESH_ENABLE_AMR
179 bool mesh_changed =
false;
185 for (
unsigned int i=0; i != n_sys; ++i)
284 const unsigned int n_sys = this->
n_systems();
286 libmesh_assert_not_equal_to (n_sys, 0);
293 for (
auto & node :
_mesh.node_ptr_range())
294 node->set_n_systems(n_sys);
300 for (Elem * elem : range)
301 elem->set_n_systems(n_sys);
329 mesh.add_ghosting_functor(
mesh.default_ghosting());
331 mesh.remove_ghosting_functor(
mesh.default_ghosting());
347 LOG_SCOPE(
"update()",
"EquationSystems");
357 std::string_view name)
368 else if (sys_type ==
"Basic")
369 this->add_system<System> (name);
372 else if (sys_type ==
"Newmark")
373 this->add_system<NewmarkSystem> (name);
376 else if ((sys_type ==
"Explicit"))
377 this->add_system<ExplicitSystem> (name);
380 else if ((sys_type ==
"Implicit") ||
381 (sys_type ==
"Steady" ))
382 this->add_system<ImplicitSystem> (name);
385 else if ((sys_type ==
"Transient") ||
386 (sys_type ==
"TransientImplicit") ||
387 (sys_type ==
"TransientLinearImplicit"))
388 this->add_system<TransientLinearImplicitSystem> (name);
391 else if (sys_type ==
"TransientNonlinearImplicit")
392 this->add_system<TransientNonlinearImplicitSystem> (name);
395 else if (sys_type ==
"TransientExplicit")
396 this->add_system<TransientExplicitSystem> (name);
399 else if (sys_type ==
"LinearImplicit")
400 this->add_system<LinearImplicitSystem> (name);
403 else if (sys_type ==
"NonlinearImplicit")
404 this->add_system<NonlinearImplicitSystem> (name);
407 else if (sys_type ==
"RBConstruction")
408 this->add_system<RBConstruction> (name);
411 else if (sys_type ==
"TransientRBConstruction")
412 this->add_system<TransientRBConstruction> (name);
414#ifdef LIBMESH_HAVE_SLEPC
416 else if (sys_type ==
"Eigen")
417 this->add_system<EigenSystem> (name);
418 else if (sys_type ==
"TransientEigenSystem")
419 this->add_system<TransientEigenSystem> (name);
422#if defined(LIBMESH_USE_COMPLEX_NUMBERS)
424 else if (sys_type ==
"Frequency")
425 this->add_system<FrequencySystem> (name);
429 libmesh_error_msg(
"ERROR: Unknown system type: " << sys_type);
453 this->
get_system(i).sensitivity_solve(parameters_in);
462 for (
unsigned int i=this->
n_systems(); i != 0; --i)
463 this->
get_system(i-1).adjoint_solve(qoi_indices);
470 const std::set<std::string> * system_names)
const
473 unsigned int var_num = var_names.size();
477 std::unordered_multiset<std::string> seen_names;
483 unsigned int n_scalar_vars = 0;
484 unsigned int n_vector_vars = 0;
486 for (
const auto & [sys_name, sys_ptr] :
_systems)
489 bool use_current_system = (system_names ==
nullptr);
490 if (!use_current_system)
491 use_current_system = system_names->count(sys_name);
492 if (!use_current_system || sys_ptr->hide_output())
495 seen_names.insert(sys_ptr->variable_name(vn));
501 seen_names.insert(sys_ptr->variable_name(vn));
512 unsigned int nv = n_scalar_vars +
dim*n_vector_vars;
516 libmesh_assert_less_equal ( nv, (
dim > 0 ?
dim : 1)*this->
n_vars() );
521 var_names.resize( nv );
524 for (
const auto & [sys_name, sys_ptr] :
_systems)
527 bool use_current_system = (system_names ==
nullptr);
528 if (!use_current_system)
529 use_current_system = system_names->count(sys_name);
530 if (!use_current_system || sys_ptr->hide_output())
535 const std::string & var_name = sys_ptr->variable_name(vn);
536 const FEType & fe_type = sys_ptr->variable_type(vn);
541 if (type ==
nullptr || (type && *type == fe_type))
549 var_names[var_num++] = var_name;
550 libmesh_error_msg_if(seen_names.count(var_name) > 1,
551 "Duplicate variable name "+var_name);
554 var_names[var_num++] = var_name+
"_x";
555 var_names[var_num++] = var_name+
"_y";
556 libmesh_error_msg_if(seen_names.count(var_name+
"_x"),
557 "Duplicate variable name "+var_name+
"_x");
558 libmesh_error_msg_if(seen_names.count(var_name+
"_y"),
559 "Duplicate variable name "+var_name+
"_y");
562 var_names[var_num++] = var_name+
"_x";
563 var_names[var_num++] = var_name+
"_y";
564 var_names[var_num++] = var_name+
"_z";
565 libmesh_error_msg_if(seen_names.count(var_name+
"_x"),
566 "Duplicate variable name "+var_name+
"_x");
567 libmesh_error_msg_if(seen_names.count(var_name+
"_y"),
568 "Duplicate variable name "+var_name+
"_y");
569 libmesh_error_msg_if(seen_names.count(var_name+
"_z"),
570 "Duplicate variable name "+var_name+
"_z");
573 libmesh_error_msg(
"Invalid dim in build_variable_names");
577 var_names[var_num++] = var_name;
582 var_names.resize(var_num);
586 bool allow_high_order_discontinuous)
588 return (type.
order ==
CONSTANT || allow_high_order_discontinuous) &&
597 (std::vector<std::string> & var_names,
598 const std::set<std::string> * system_names,
599 bool allow_high_order_discontinuous)
const
601 const std::vector<std::string> name_filter = var_names;
602 const bool is_names_empty = name_filter.empty();
605 const std::vector<std::string> component_suffix = {
"_x",
"_y",
"_z"};
607 libmesh_error_msg_if(
dim > 3,
"Invalid dim in build_elemental_data_variable_names");
609 for (
const auto & [sys_name, sys_ptr] :
_systems)
611 const bool use_current_system = (system_names ==
nullptr) || system_names->count(sys_name);
612 if (!use_current_system || sys_ptr->hide_output())
615 for (
auto var :
make_range(sys_ptr->n_vars()))
617 const FEType & var_type = sys_ptr->variable_type(var);
625 const std::string name =
626 sys_ptr->variable_name(var) + component_suffix[comp];
628 if (is_names_empty ||
629 std::find(name_filter.begin(), name_filter.end(), name) != name_filter.end())
630 var_names.push_back(name);
635 const std::string & name = sys_ptr->variable_name(var);
637 if (is_names_empty ||
638 std::find(name_filter.begin(), name_filter.end(), name) != name_filter.end())
639 var_names.push_back(name);
644 std::sort(var_names.begin(), var_names.end());
651 std::string_view)
const
654 libmesh_not_implemented();
660std::unique_ptr<NumericVector<Number>>
662 bool add_sides)
const
664 LOG_SCOPE(
"build_parallel_solution_vector()",
"EquationSystems");
667 parallel_object_only();
687 unsigned int n_scalar_vars = 0;
688 unsigned int n_vector_vars = 0;
689 for (
const auto & [sys_name, sys_ptr] :
_systems)
692 bool use_current_system = (system_names ==
nullptr);
693 if (!use_current_system)
694 use_current_system = system_names->count(sys_name);
695 if (!use_current_system || sys_ptr->hide_output())
708 nv = n_scalar_vars +
dim*n_vector_vars;
713 (std::distance(
_mesh.local_nodes_begin(),
714 _mesh.local_nodes_end()));
725 const dof_id_type gaps_per_processor = n_gaps / n_proc;
726 const dof_id_type remainder_gaps = n_gaps % n_proc;
728 n_local_nodes = n_local_nodes +
730 (my_pid < remainder_gaps);
735 added_side_nodes = 0;
738 std::vector<dof_id_type> others_added_side_nodes;
742 std::map<std::tuple<dof_id_type, unsigned short, unsigned short>,
750 std::vector<dof_id_type> true_node_offsets;
752 std::vector<dof_id_type> added_node_offsets;
754 auto node_id_to_vec_id =
755 [&true_node_offsets, &added_node_offsets]
758 if (true_node_offsets.empty())
762 const auto lb = std::upper_bound(true_node_offsets.begin(),
763 true_node_offsets.end(), node_id);
767 return node_id + added_node_offsets[p];
772 true_node_offsets.resize(n_proc);
773 added_node_offsets.resize(n_proc);
776 for (
const auto & elem :
_mesh.active_element_ptr_range())
778 for (
auto s : elem->side_index_range())
783 const std::vector<unsigned int> side_nodes =
784 elem->nodes_on_side(s);
787 local_added_side_nodes += side_nodes.size();
791 others_added_side_nodes.resize(n_proc);
793 others_added_side_nodes);
795 added_side_nodes = std::accumulate(others_added_side_nodes.begin(),
796 others_added_side_nodes.end(), 0,
801 true_node_offsets[p+1] += true_node_offsets[p];
806 added_node_offsets[0] = 0;
808 added_node_offsets[p+1] =
809 added_node_offsets[p] + others_added_side_nodes[p];
814 dof_id_type node_counter = true_node_offsets[my_pid];
816 node_counter += others_added_side_nodes[p];
819 for (
const auto & elem :
_mesh.active_local_element_ptr_range())
821 for (
auto s : elem->side_index_range())
826 const std::vector<unsigned int> side_nodes =
827 elem->nodes_on_side(s);
830 discontinuous_node_indices
831 [std::make_tuple(elem->id(),s,n)] = node_counter++;
837 n_global_vals = (max_nn + added_side_nodes) * nv,
838 n_local_vals = (n_local_nodes + local_added_side_nodes) * nv;
843 parallel_soln.
init(n_global_vals, n_local_vals,
false,
PARALLEL);
849 repeat_count.
init(n_global_vals, n_local_vals,
false,
PARALLEL);
851 repeat_count.
close();
853 unsigned int var_num=0;
860 for (
const auto & [sys_name, sys_ptr] :
_systems)
863 bool use_current_system = (system_names ==
nullptr);
864 if (!use_current_system)
865 use_current_system = system_names->count(sys_name);
866 if (!use_current_system || sys_ptr->hide_output())
869 const System & system = *sys_ptr;
870 const unsigned int nv_sys = system.
n_vars();
871 const unsigned int sys_num = system.
number();
874 unsigned int n_scalar_vars = 0;
875 unsigned int n_vector_vars = 0;
886 unsigned int nv_sys_split = n_scalar_vars +
dim*n_vector_vars;
897 if (!non_const_sys.
solution->closed())
906 std::vector<Number> elem_soln;
907 std::vector<Number> nodal_soln;
908 std::vector<dof_id_type> dof_indices;
910 unsigned var_inc = 0;
911 for (
unsigned int var=0; var<nv_sys; var++)
918 for (
const auto & elem :
_mesh.active_local_element_ptr_range())
923 sys_soln.
get(dof_indices, elem_soln);
934 if (!elem->infinite())
936 libmesh_assert_equal_to (nodal_soln.size(), n_vec_dim*elem->n_nodes());
938 for (
auto n : elem->node_index_range())
940 const Node & node = elem->node_ref(n);
943 nv * node_id_to_vec_id(node.
id());
945 for (
unsigned int d=0; d < n_vec_dim; d++)
949 parallel_soln.
add(node_idx + (var_inc+d + var_num), nodal_soln[n_vec_dim*n+d]);
952 repeat_count.
add(node_idx + (var_inc+d + var_num), 1);
958 for (
auto s : elem->side_index_range())
966 (fe_type, elem, s, elem_soln,
967 nodal_soln, add_p_level, n_vec_dim);
970 const std::vector<unsigned int> side_nodes =
971 elem->nodes_on_side(s);
973 libmesh_assert_equal_to
981 std::size_t node_index =
982 nv * libmesh_map_find(discontinuous_node_indices,
983 std::make_tuple(elem->id(), s, n));
985 for (
unsigned int d=0; d < n_vec_dim; d++)
987 parallel_soln.
add(node_index + (var_inc+d + var_num), nodal_soln[n_vec_dim*n+d]);
988 repeat_count.
add(node_index + (var_inc+d + var_num), 1);
996 for (
auto n : elem->node_index_range())
998 const Node & node = elem->node_ref(n);
1002 if (!node.
n_dofs(sys_num, var))
1005 nv * node_id_to_vec_id(node.
id());
1007 for (
unsigned int d=0; d < n_vec_dim; d++)
1008 repeat_count.
add(node_idx + (var_inc+d + var_num), 1);
1013 var_inc += n_vec_dim;
1016 var_num += nv_sys_split;
1020 parallel_soln.
close();
1021 repeat_count.
close();
1035 if (std::abs(repeat_count(i)) <
TOLERANCE)
1036 repeat_count.
set(i, 1.);
1041 repeat_count.
close();
1045 parallel_soln /= repeat_count;
1047 return parallel_soln_ptr;
1053 const std::set<std::string> * system_names,
1054 bool add_sides)
const
1056 LOG_SCOPE(
"build_solution_vector()",
"EquationSystems");
1059 std::unique_ptr<NumericVector<Number>> parallel_soln =
1063 parallel_soln->localize_to_one(soln);
1069 std::vector<std::set<subdomain_id_type>> & vars_active_subdomains)
const
1071 vars_active_subdomains.clear();
1072 vars_active_subdomains.resize(names.size());
1076 const auto & sys_ptr = pr.second;
1077 for (
auto vn :
make_range(sys_ptr->n_vars()))
1079 const std::string & var_name = sys_ptr->variable_name(vn);
1081 auto names_it = std::find(names.begin(), names.end(), var_name);
1082 if(names_it != names.end())
1084 const Variable & variable = sys_ptr->variable(vn);
1085 const std::set<subdomain_id_type> & active_subdomains = variable.
active_subdomains();
1086 vars_active_subdomains[std::distance(names.begin(), names_it)] = active_subdomains;
1096 std::vector<std::string> & names,
1097 bool allow_high_order_discontinuous)
const
1100 std::unique_ptr<NumericVector<Number>> parallel_soln =
1109 parallel_soln->localize_to_one(soln);
1112std::vector<std::pair<unsigned int, unsigned int>>
1114 (std::vector<std::string> & names,
const FEType * type,
const std::vector<FEType> * types)
const
1117 libmesh_assert_msg(!type || !types,
1118 "Input 'type', 'types', or neither in find_variable_numbers, but not both.");
1120 std::vector<FEType> type_filter;
1122 type_filter.push_back(*type);
1124 type_filter = *types;
1128 [&type_filter](
const FEType & var_type)
1130 return type_filter.empty() ||
1131 std::find(type_filter.begin(), type_filter.end(), var_type) != type_filter.end();
1137std::vector<std::pair<unsigned int, unsigned int>>
1139 bool allow_high_order_discontinuous)
const
1143 [allow_high_order_discontinuous](
const FEType & type)
1149std::vector<std::pair<unsigned int, unsigned int>>
1151 (std::vector<std::string> & names,
1152 const std::function<
bool(
const FEType &)> & type_filter)
const
1155 parallel_object_only();
1163 std::vector<std::string> name_filter = names;
1164 bool is_names_empty = name_filter.empty();
1171 const std::vector<std::string> component_suffix = {
"_x",
"_y",
"_z"};
1173 libmesh_error_msg_if(
dim > 3,
"Invalid dim in find_variable_numbers");
1177 std::vector<std::pair<unsigned int, unsigned int>> var_nums;
1181 const System & system = *(pr.second);
1187 if (!type_filter(var_type))
1193 std::vector<std::string> component_names;
1194 for (
unsigned int comp = 0; comp <
dim; ++comp)
1197 if (is_names_empty ||
1198 (std::find(name_filter.begin(), name_filter.end(), name) != name_filter.end()))
1199 component_names.push_back(name);
1202 if (! component_names.empty())
1203 names.insert(names.end(), component_names.begin(), component_names.end());
1210 if (is_names_empty ||
1211 (std::find(name_filter.begin(), name_filter.end(), name) != name_filter.end()))
1212 names.push_back(name);
1218 var_nums.emplace_back(system.
number(), var);
1223 std::vector<unsigned int> sort_index(var_nums.size());
1224 std::iota(sort_index.begin(), sort_index.end(), 0);
1225 std::sort(sort_index.begin(), sort_index.end(),
1226 [&](
const unsigned int & lhs,
const unsigned int & rhs)
1227 {return this->get_system(var_nums[lhs].first).variable_name(var_nums[lhs].second) <
1228 this->get_system(var_nums[rhs].first).variable_name(var_nums[rhs].second);});
1230 std::vector<std::pair<unsigned int, unsigned int>> var_nums_sorted(var_nums.size());
1233 var_nums_sorted[i].first = var_nums[sort_index[i]].first;
1234 var_nums_sorted[i].second = var_nums[sort_index[i]].second;
1238 std::sort(names.begin(), names.end());
1241 return var_nums_sorted;
1245std::unique_ptr<NumericVector<Number>>
1247 bool allow_high_order_discontinuous)
const
1252 std::vector<std::pair<unsigned int, unsigned int>> var_nums =
1255 const std::size_t nv = names.size();
1261 return std::unique_ptr<NumericVector<Number>>(
nullptr);
1275 parallel_soln_local_size = div+1;
1280 parallel_soln.
init(parallel_soln_global_size,
1281 parallel_soln_local_size,
1285 unsigned int sys_ctr = 0;
1286 unsigned int var_ctr = 0;
1289 std::pair<unsigned int, unsigned int> var_num = var_nums[i];
1293 if (sys_ctr != var_num.first)
1302 if (!non_const_sys.
solution->closed())
1305 sys_ctr = var_num.first;
1310 const unsigned int var = var_num.second;
1321 const unsigned int n_comps =
1331 const bool need_quadrature_average =
1332 allow_high_order_discontinuous && var_type.order !=
CONSTANT;
1337 [&system, &dof_map, &variable, ne, var, var_ctr, n_comps, field_type,
1338 need_quadrature_average, ¶llel_soln, &sys_soln](
const ConstElemRange & range)
1341 std::vector<dof_id_type> dof_indices;
1347 std::unique_ptr<FEMContext> con;
1348 if (need_quadrature_average)
1350 const std::vector<unsigned int> active_vars {var};
1351 con = std::make_unique<FEMContext>(system, &active_vars,
1358 auto element_average = [&con, &system, var](
const Elem * elem,
auto zero_value)
1360 typedef decltype(zero_value) OutputType;
1361 typedef typename TensorTools::MakeReal<OutputType>::type OutputShape;
1363 con->pre_fe_reinit(system, elem);
1366 FEGenericBase<OutputShape> * fe = nullptr;
1367 con->get_element_fe(var, fe);
1368 const std::vector<Real> & JxW = fe->get_JxW();
1371 con->elem_fe_reinit();
1373 OutputType avg = zero_value;
1375 for (auto qp : index_range(JxW))
1378 con->interior_value(var, qp, u_h);
1379 avg += JxW[qp] * u_h;
1386 for (
const Elem * elem : range)
1388 if (variable.active_on_subdomain(elem->subdomain_id()))
1390 if (need_quadrature_average)
1393 parallel_soln.
set(ne * var_ctr + elem->id(), element_average(elem,
Number()));
1397 for (
unsigned int comp = 0; comp < n_comps; comp++)
1398 parallel_soln.
set(ne * (var_ctr + comp) + elem->id(), avg(comp));
1403 dof_map.dof_indices(elem, dof_indices, var);
1407 libmesh_assert_equal_to(dof_indices.size(), n_comps);
1409 for (
unsigned int comp = 0; comp < n_comps; comp++)
1410 parallel_soln.
set(ne * (var_ctr + comp) + elem->id(), sys_soln(dof_indices[comp]));
1424 libmesh_assert_equal_to(names.size(), var_ctr);
1426 parallel_soln.close();
1427 return parallel_soln_ptr;
1433EquationSystems::build_discontinuous_solution_vector
1434(std::vector<Number> & soln,
1435 const std::set<std::string> * system_names,
1436 const std::vector<std::string> * var_names,
1438 bool add_sides)
const
1440 LOG_SCOPE(
"build_discontinuous_solution_vector()",
"EquationSystems");
1444 const std::vector<std::string> component_suffix = {
"_x",
"_y",
"_z"};
1445 const auto requested_components =
1446 [
this, var_names, &component_suffix](
const System & system,
1447 const unsigned int var)
1449 std::vector<unsigned int> components;
1451 const std::string & var_name = system.variable_name(var);
1452 const FEType & fe_type = system.variable_type(var);
1453 const unsigned int n_vec_dim = FEInterface::n_vec_dim(_mesh, fe_type);
1455 if (FEInterface::field_type(fe_type) ==
TYPE_VECTOR)
1457 libmesh_error_msg_if(n_vec_dim > component_suffix.size(),
1458 "Invalid dim in build_discontinuous_solution_vector");
1460 const bool use_all_components =
1461 (var_names ==
nullptr) ||
1462 std::count(var_names->begin(), var_names->end(), var_name);
1466 if (use_all_components)
1467 components.push_back(0);
1472 const std::string component_name = var_name + component_suffix[comp];
1473 if (use_all_components ||
1474 std::count(var_names->begin(), var_names->end(), component_name))
1475 components.push_back(comp);
1478 else if (var_names ==
nullptr ||
1479 std::count(var_names->begin(), var_names->end(), var_name))
1480 components.push_back(0);
1487 unsigned int nv = 0;
1489 for (
const auto & [sys_name, sys_ptr] : _systems)
1492 bool use_current_system = (system_names ==
nullptr);
1493 if (!use_current_system)
1494 use_current_system = system_names->count(sys_name);
1495 if (!use_current_system || sys_ptr->hide_output())
1500 for (
auto var_id :
make_range(sys_ptr->n_vars()))
1501 nv += cast_int<unsigned int>(requested_components(*sys_ptr, var_id).size());
1507 for (
const auto & elem : _mesh.active_element_ptr_range())
1509 tw += vertices_only ? elem->n_vertices() : elem->n_nodes();
1513 for (
auto s : elem->side_index_range())
1515 if (redundant_added_side(*elem,s))
1518 const std::vector<unsigned int> side_nodes =
1519 elem->nodes_on_side(s);
1522 tw += side_nodes.size();
1525 if (elem->is_vertex(side_nodes[n]))
1533 if (_mesh.processor_id() == 0)
1536 std::vector<Number> sys_soln;
1540 unsigned int var_offset = 0;
1547 for (
const auto & [sys_name, system] : _systems)
1550 bool use_current_system = (system_names ==
nullptr);
1551 if (!use_current_system)
1552 use_current_system = system_names->count(sys_name);
1553 if (!use_current_system || system->hide_output())
1556 const unsigned int nv_sys = system->n_vars();
1557 const auto & dof_map = system->get_dof_map();
1559 system->update_global_solution (sys_soln, 0);
1562 unsigned int n_vars_written_current_system = 0;
1564 if (_mesh.processor_id() == 0)
1566 std::vector<Number> soln_coeffs;
1567 std::vector<Number> nodal_soln;
1568 std::vector<dof_id_type> dof_indices;
1577 const std::vector<unsigned int> components_to_write =
1578 requested_components(*system, var);
1582 if (components_to_write.empty())
1585 const FEType & fe_type = system->variable_type(var);
1586 const Variable & var_description = system->variable(var);
1588 const unsigned int n_vec_dim = FEInterface::n_vec_dim(_mesh, fe_type);
1592 for (
auto & elem : _mesh.active_element_ptr_range())
1596 dof_map.dof_indices (elem, dof_indices, var);
1598 soln_coeffs.resize(dof_indices.size());
1601 soln_coeffs[i] = sys_soln[dof_indices[i]];
1606 FEInterface::nodal_soln (elem->dim(),
1615 if (!elem->infinite())
1617 libmesh_assert_equal_to (nodal_soln.size(), elem->n_nodes()*n_vec_dim);
1619 const unsigned int n_vals =
1620 vertices_only ? elem->n_vertices() : elem->n_nodes();
1626 nv * (nn++) + (n_vars_written_current_system + var_offset);
1628 for (
auto component_index :
index_range(components_to_write))
1629 soln[index + component_index] +=
1630 nodal_soln[n_vec_dim*n + components_to_write[component_index]];
1635 nn += vertices_only ? elem->n_vertices() : elem->n_nodes();
1646 std::vector<std::vector<const Elem *>>
1647 elems_by_pid(_mesh.n_processors());
1649 for (
const auto & elem : _mesh.active_element_ptr_range())
1650 elems_by_pid[elem->processor_id()].push_back(elem);
1653 for (
const Elem * elem : elems_by_pid[p])
1657 dof_map.dof_indices (elem, dof_indices, var);
1659 soln_coeffs.resize(dof_indices.size());
1662 soln_coeffs[i] = sys_soln[dof_indices[i]];
1664 for (
auto s : elem->side_index_range())
1666 if (redundant_added_side(*elem,s))
1669 const std::vector<unsigned int> side_nodes =
1670 elem->nodes_on_side(s);
1676 FEInterface::side_nodal_soln
1677 (fe_type, elem, s, soln_coeffs,
1678 nodal_soln, add_p_level,
1681 libmesh_assert_equal_to
1683 side_nodes.size()*n_vec_dim);
1692 FEInterface::get_continuity(fe_type);
1697 neigh->
level() == elem->level() &&
1700 std::vector<dof_id_type> neigh_indices;
1701 dof_map.dof_indices (neigh, neigh_indices, var);
1702 std::vector<Number> neigh_coeffs(neigh_indices.size());
1705 neigh_coeffs[i] = sys_soln[neigh_indices[i]];
1707 const unsigned int s_neigh =
1709 std::vector<Number> neigh_soln;
1710 FEInterface::side_nodal_soln
1711 (fe_type, neigh, s_neigh,
1712 neigh_coeffs, neigh_soln, add_p_level,
1715 const std::vector<unsigned int> neigh_nodes =
1719 if (neigh->
node_ptr(neigh_nodes[neigh_n])
1720 == elem->node_ptr(side_nodes[n]))
1723 const auto nodal_index = n_vec_dim*n + comp;
1724 nodal_soln[nodal_index] +=
1725 neigh_soln[n_vec_dim*neigh_n + comp];
1726 nodal_soln[nodal_index] /= 2;
1732 if (vertices_only &&
1733 !elem->is_vertex(n))
1738 nv * (nn++) + (n_vars_written_current_system + var_offset);
1740 for (
auto component_index :
index_range(components_to_write))
1741 soln[index + component_index] +=
1742 nodal_soln[n_vec_dim*n + components_to_write[component_index]];
1748 nn += vertices_only ? elem->n_vertices() : elem->n_nodes();
1750 for (
auto s : elem->side_index_range())
1752 if (redundant_added_side(*elem,s))
1755 const std::vector<unsigned int> side_nodes =
1756 elem->nodes_on_side(s);
1760 if (vertices_only &&
1761 !elem->is_vertex(n))
1771 n_vars_written_current_system += cast_int<unsigned int>(components_to_write.size());
1777 var_offset += n_vars_written_current_system;
1783bool EquationSystems::redundant_added_side(
const Elem & elem,
unsigned int side)
1803 return (neigh->
id() < elem.
id());
1809 const Real threshold,
1810 const bool verbose)
const
1814 std::vector<bool> os_result;
1816 if (this->n_systems() != other_es.
n_systems())
1820 libMesh::out <<
" Fatal difference. This system handles "
1821 << this->n_systems() <<
" systems," << std::endl
1822 <<
" while the other system handles "
1824 <<
" systems." << std::endl
1825 <<
" Aborting comparison." << std::endl;
1832 for (
const auto & [sys_name, sys_ptr] : _systems)
1837 os_result.push_back (sys_ptr->compare (other_system, threshold, verbose));
1845 if (os_result.size()==0)
1853 os_identical = os_result[n];
1856 while (os_identical && n<os_result.size());
1857 return os_identical;
1863std::string EquationSystems::get_info ()
const
1865 std::ostringstream oss;
1867 unsigned int n_hidden_sys = 0;
1868 for (
auto & pr : _systems)
1869 n_hidden_sys += pr.second->hide_output();
1871 oss <<
" EquationSystems\n"
1872 <<
" n_systems()=" << this->n_systems()
1873 << (n_hidden_sys ?
" (hidden: " + std::to_string(n_hidden_sys) +
")" :
"")
1877 for (
const auto & pr : _systems)
1878 if (!pr.second->hide_output())
1879 oss << pr.second->get_info();
1903void EquationSystems::print_info (std::ostream & os)
const
1905 os << this->get_info()
1911std::ostream & operator << (std::ostream & os,
1920unsigned int EquationSystems::n_vars ()
const
1924 for (
const auto & pr : _systems)
1925 tot += pr.second->n_vars();
1932std::size_t EquationSystems::n_dofs ()
const
1936 for (
const auto & pr : _systems)
1937 tot += pr.second->n_dofs();
1945std::size_t EquationSystems::n_active_dofs ()
const
1949 for (
const auto & pr : _systems)
1950 tot += pr.second->n_active_dofs();
1956void EquationSystems::_add_system_to_nodes_and_elems()
1959 for (
auto & node : _mesh.node_ptr_range())
1963 Threads::parallel_for
1964 (_mesh.element_stored_range(),
1967 for (Elem * elem : range)
1972void EquationSystems::_remove_default_ghosting(
unsigned int sys_num)
1974 this->get_system(sys_num).get_dof_map().remove_default_ghosting();
processor_id_type size() const
processor_id_type rank() const
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
This class handles the numbering of degrees of freedom on a mesh.
void remove_default_ghosting()
Remove any default ghosting functor(s).
std::size_t distribute_dofs(MeshBase &)
Distribute dofs on the current mesh.
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
void add_default_ghosting()
Add the default functor(s) for coupling and algebraic ghosting.
unsigned int n_dofs(const unsigned int s, const unsigned int var=libMesh::invalid_uint) const
This is the base class from which all geometric element types are derived.
unsigned int which_neighbor_am_i(const Elem *e) const
This function tells you which neighbor e is.
virtual std::vector< unsigned int > nodes_on_side(const unsigned int) const =0
subdomain_id_type subdomain_id() const
unsigned int level() const
const Node * node_ptr(const unsigned int i) const
const Elem * neighbor_ptr(unsigned int i) const
This is the EquationSystems class.
virtual void reinit()
Handle any mesh changes and reinitialize all the systems on the updated mesh.
std::vector< std::pair< unsigned int, unsigned int > > find_variable_numbers_by_predicate(std::vector< std::string > &names, const std::function< bool(const FEType &)> &type_filter) const
Implementation detail for find_variable_numbers() variants.
void build_elemental_data_variable_names(std::vector< std::string > &var_names, const std::set< std::string > *system_names=nullptr, bool allow_high_order_discontinuous=false) const
Filter var_names to names of variables that can be represented as elemental data.
EquationSystems(MeshBase &mesh)
Constructor.
void print_info(std::ostream &os=libMesh::out) const
Prints information about the equation systems, by default to libMesh::out.
std::unique_ptr< NumericVector< Number > > build_parallel_solution_vector(const std::set< std::string > *system_names=nullptr, bool add_sides=false) const
A version of build_solution_vector which is appropriate for "parallel" output formats like Nemesis.
virtual ~EquationSystems()
Destructor.
virtual void sensitivity_solve(const ParameterVector ¶meters)
Call sensitivity_solve on all the individual equation systems.
void update()
Updates local values for all the systems.
std::vector< std::pair< unsigned int, unsigned int > > find_variable_numbers(std::vector< std::string > &names, const FEType *type=nullptr, const std::vector< FEType > *types=nullptr) const
Finds system and variable numbers for any variables of 'type' or of 'types' corresponding to the entr...
void build_variable_names(std::vector< std::string > &var_names, const FEType *type=nullptr, const std::set< std::string > *system_names=nullptr) const
Fill the input vector var_names with the names of the variables for each system.
unsigned int n_systems() const
static bool redundant_added_side(const Elem &elem, unsigned int side)
unsigned int n_vars() const
void get_vars_active_subdomains(const std::vector< std::string > &names, std::vector< std::set< subdomain_id_type > > &vars_active_subdomains) const
Retrieve vars_active_subdomains, which indicates the active subdomains for each variable in names.
const MeshBase & get_mesh() const
Parameters parameters
Data structure holding arbitrary parameters.
std::vector< std::pair< unsigned int, unsigned int > > find_elemental_data_variable_numbers(std::vector< std::string > &names, bool allow_high_order_discontinuous=false) const
Finds system and variable numbers for variables that can be represented as elemental data.
void build_solution_vector(std::vector< Number > &soln, std::string_view system_name, std::string_view variable_name="all_vars") const
Fill the input vector soln with the solution values for the system named name.
bool _refine_in_reinit
Flag for whether to call coarsen/refine in reinit().
std::unique_ptr< NumericVector< Number > > build_parallel_elemental_solution_vector(std::vector< std::string > &names, bool allow_high_order_discontinuous=false) const
Builds a parallel vector of elemental data solution values corresponding to the entries in the input ...
MeshBase & _mesh
The mesh data structure.
bool reinit_solutions()
Handle any mesh changes and project any solutions onto the updated mesh.
virtual void init()
Initialize all the systems.
void build_elemental_solution_vector(std::vector< Number > &soln, std::vector< std::string > &names, bool allow_high_order_discontinuous=false) const
Retrieve the solution data for elemental data variables.
virtual System & add_system(std::string_view system_type, std::string_view name)
Add the system of type system_type named name to the systems array.
virtual void reinit_mesh()
Handle the association of a completely new mesh with the EquationSystem and all the Systems assigned ...
virtual void adjoint_solve(const QoISet &qoi_indices=QoISet())
Call adjoint_solve on all the individual equation systems.
virtual void reinit_systems()
Reinitialize all systems on the current mesh.
virtual void clear()
Restores the data structure to a pristine state.
const T_sys & get_system(std::string_view name) const
virtual void enable_default_ghosting(bool enable)
Enable or disable default ghosting functors on the Mesh and on all Systems.
static bool is_elemental_data_fe_type(const FEType &type, bool allow_high_order_discontinuous=false)
virtual void solve()
Call solve on all the individual equation systems.
bool _enable_default_ghosting
Flag for whether to enable default ghosting on newly added Systems.
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.
void allgather()
Serializes a distributed mesh and its associated degree of freedom numbering for all systems.
static unsigned int n_vec_dim(const MeshBase &mesh, const FEType &fe_type)
static FEFieldType field_type(const FEType &fe_type)
static void nodal_soln(const unsigned int dim, const FEType &fe_t, const Elem *elem, const std::vector< Number > &elem_soln, std::vector< Number > &nodal_soln, const bool add_p_level=true, const unsigned int vdim=1)
Build the nodal soln from the element soln.
static void side_nodal_soln(const FEType &fe_t, const Elem *elem, const unsigned int side, const std::vector< Number > &elem_soln, std::vector< Number > &nodal_soln, const bool add_p_level=true, const unsigned int vdim=1)
Build the nodal soln on one side from the (full) element soln.
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 is the MeshBase class.
virtual bool is_serial() const
virtual bool contract()=0
Delete subactive (i.e.
virtual dof_id_type n_elem() const =0
unsigned int spatial_dimension() const
const ConstElemRange & active_local_element_stored_range() const
const ElemRange & element_stored_range()
virtual dof_id_type max_node_id() const =0
virtual dof_id_type max_elem_id() const =0
virtual void allgather()
Gathers all elements and nodes of the mesh onto every processor.
Implements (adaptive) mesh refinement algorithms for a MeshBase.
bool coarsen_elements()
Only coarsens the user-requested elements.
void clean_refinement_flags()
Sets the refinement flag to Elem::DO_NOTHING for each element in the mesh.
unsigned char & face_level_mismatch_limit()
If face_level_mismatch_limit is set to a nonzero value, then refinement and coarsening will produce m...
signed char & underrefined_boundary_limit()
If underrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will pro...
bool refine_elements()
Only refines the user-requested elements.
signed char & overrefined_boundary_limit()
If overrefined_boundary_limit is set to a nonnegative value, then refinement and coarsening will prod...
A Node is like a Point, but with more information.
Provides a uniform interface to vector storage schemes for different linear algebra libraries.
virtual void set(const numeric_index_type i, const T value)=0
Sets v(i) = value.
virtual void get(const std::vector< numeric_index_type > &index, T *values) const
Access multiple components at once.
virtual numeric_index_type last_local_index() const =0
virtual void close()=0
Calls the NumericVector's internal assembly routines, ensuring that the values are consistent across ...
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
virtual void init(const numeric_index_type n, const numeric_index_type n_local, const bool fast=false, const ParallelType ptype=AUTOMATIC)=0
Change the dimension of the vector to n.
virtual void add(const numeric_index_type i, const T value)=0
Adds value to the vector entry specified by i.
virtual numeric_index_type first_local_index() const =0
An object whose state is distributed along a set of processors.
const Parallel::Communicator & _communicator
processor_id_type processor_id() const
const Parallel::Communicator & comm() const
processor_id_type n_processors() const
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
virtual void clear()
Clears internal data structures & frees any allocated memory.
T & set(const std::string &)
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
The StoredRange class defines a contiguous, divisible set of objects.
Manages consistently variables, degrees of freedom, and coefficient vectors.
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
const FEType & variable_type(const unsigned int i) const
virtual void prolong_vectors()
Prolong vectors after the mesh has refined.
virtual void restrict_vectors()
Restrict vectors after the mesh has coarsened.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
const std::string & variable_name(const unsigned int i) const
virtual void update()
Update the local values to reflect the solution on neighboring processors.
virtual void reinit_constraints()
Reinitializes the constraints for this system.
unsigned int n_vars() const
const DofMap & get_dof_map() const
unsigned int number() const
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
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
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.
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
NumberVectorValue Gradient
dof_id_type numeric_index_type
const RemoteElem * remote_elem
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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...