libMesh
Loading...
Searching...
No Matches
equation_systems.C
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3
4// This library is free software; you can redistribute it and/or
5// modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation; either
7// version 2.1 of the License, or (at your option) any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12// Lesser General Public License for more details.
13
14// You should have received a copy of the GNU Lesser General Public
15// License along with this library; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
18
19// Local Includes
20#include "libmesh/default_coupling.h" // For downconversion
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"
42
43// System includes
44#include <functional> // std::plus
45#include <numeric> // std::iota
46#include <sstream>
47
48// Include the systems before this one to avoid
49// overlapping forward declarations.
50#include "libmesh/equation_systems.h"
51
52namespace libMesh
53{
54
57 _mesh (m),
58 _refine_in_reinit(true),
59 _enable_default_ghosting(true)
60{
61 // Set default parameters
62 this->parameters.set<Real> ("linear solver tolerance") = TOLERANCE * TOLERANCE;
63 this->parameters.set<unsigned int>("linear solver maximum iterations") = 5000;
64}
65
66
67
69
70
71
73{
74 // Clear any additional parameters
76
77 // Clear the systems.
78 _systems.clear();
79}
80
81
82
84{
85#ifndef NDEBUG
86 for (auto i : make_range(this->n_systems()))
87 libmesh_assert(!this->get_system(i).is_initialized());
88#endif
89
90 this->reinit_mesh();
91}
92
93
94
96{
97 const bool mesh_changed = this->reinit_solutions();
98
99 // If the mesh has changed, systems will need to reinitialize their
100 // own data on the new mesh.
101 if (mesh_changed)
102 this->reinit_systems();
103}
104
106{
107 const unsigned int n_sys = this->n_systems();
108
109 libmesh_assert_not_equal_to (n_sys, 0);
110
111 // Tell all the \p DofObject entities how many systems
112 // there are.
113 for (auto & node : _mesh.node_ptr_range())
114 node->set_n_systems(n_sys);
115
118 [n_sys](const ElemRange & range)
119 {
120 for (Elem * elem : range)
121 elem->set_n_systems(n_sys);
122 });
123
124 //for (auto i : make_range(this->n_systems()))
125 //this->get_system(i).init();
126
127#ifdef LIBMESH_ENABLE_AMR
128 MeshRefinement mesh_refine(_mesh);
129 mesh_refine.clean_refinement_flags();
130#endif
131
132 // Now loop over all the systems belonging to this ES
133 // and call reinit_mesh for each system
134 for (auto i : make_range(this->n_systems()))
135 this->get_system(i).reinit_mesh();
136
137}
138
140{
141 parallel_object_only();
142
143 const unsigned int n_sys = this->n_systems();
144 libmesh_assert_not_equal_to (n_sys, 0);
145
146 // And any new systems will need initialization
147 for (unsigned int i=0; i != n_sys; ++i)
148 if (!this->get_system(i).is_initialized())
149 this->get_system(i).init();
150
151 // We used to assert that all nodes and elements *already* had
152 // n_systems() properly set; however this is false in the case where
153 // user code has manually added nodes and/or elements to an
154 // already-initialized system.
155
156 // Make sure all the \p DofObject entities know how many systems
157 // there are.
158 {
159 // All the nodes
160 for (auto & node : _mesh.node_ptr_range())
161 node->set_n_systems(n_sys);
162
163 // All the elements
166 [n_sys](const ElemRange & range)
167 {
168 for (Elem * elem : range)
169 elem->set_n_systems(n_sys);
170 });
171 }
172
173 // Localize each system's vectors
174 for (unsigned int i=0; i != n_sys; ++i)
175 this->get_system(i).re_update();
176
177#ifdef LIBMESH_ENABLE_AMR
178
179 bool mesh_changed = false;
180
181 // FIXME: For backwards compatibility, assume
182 // refine_and_coarsen_elements or refine_uniformly have already
183 // been called
184 {
185 for (unsigned int i=0; i != n_sys; ++i)
186 {
187 System & sys = this->get_system(i);
188
189 // Even if the system doesn't have any variables in it we want
190 // consistent behavior; e.g. distribute_dofs should have the
191 // opportunity to count up zero dofs on each processor.
192 //
193 // Who's been adding zero-var systems anyway, outside of my
194 // unit tests? - RHS
195 // if (!sys.n_vars())
196 // continue;
197
199
200 // Recreate any user or internal constraints
201 sys.reinit_constraints();
202
203 // Even if there weren't any constraint changes,
204 // reinit_constraints() did prepare_send_list() for us.
205
206 sys.prolong_vectors();
207 }
208 mesh_changed = true;
209 }
210
211 if (this->_refine_in_reinit)
212 {
213 // Don't override any user refinement settings
214 MeshRefinement mesh_refine(_mesh);
215 mesh_refine.face_level_mismatch_limit() = 0; // unlimited
216 mesh_refine.overrefined_boundary_limit() = -1; // unlimited
217 mesh_refine.underrefined_boundary_limit() = -1; // unlimited
218
219 // Try to coarsen the mesh, then restrict each system's vectors
220 // if necessary
221 if (mesh_refine.coarsen_elements())
222 {
223 for (auto i : make_range(this->n_systems()))
224 {
225 System & sys = this->get_system(i);
227 sys.reinit_constraints();
228
229 // Even if there weren't any constraint changes,
230 // reinit_constraints() did prepare_send_list() for us.
231
232 sys.restrict_vectors();
233 }
234 mesh_changed = true;
235 }
236
237 // Once vectors are all restricted, we can delete
238 // children of coarsened elements
239 if (mesh_changed)
240 this->get_mesh().contract();
241
242 // Try to refine the mesh, then prolong each system's vectors
243 // if necessary
244 if (mesh_refine.refine_elements())
245 {
246 for (auto i : make_range(this->n_systems()))
247 {
248 System & sys = this->get_system(i);
250 sys.reinit_constraints();
251
252 // Even if there weren't any constraint changes,
253 // reinit_constraints() did prepare_send_list() for us.
254
255 sys.prolong_vectors();
256 }
257 mesh_changed = true;
258 }
259 }
260
261 return mesh_changed;
262
263#endif // #ifdef LIBMESH_ENABLE_AMR
264
265 return false;
266}
267
268
269
271{
272 for (auto i : make_range(this->n_systems()))
273 this->get_system(i).reinit();
274}
275
276
277
279{
280 // A serial mesh means nothing needs to be done
281 if (_mesh.is_serial())
282 return;
283
284 const unsigned int n_sys = this->n_systems();
285
286 libmesh_assert_not_equal_to (n_sys, 0);
287
288 // Gather the mesh
290
291 // Tell all the \p DofObject entities how many systems
292 // there are.
293 for (auto & node : _mesh.node_ptr_range())
294 node->set_n_systems(n_sys);
295
298 [n_sys](const ElemRange & range)
299 {
300 for (Elem * elem : range)
301 elem->set_n_systems(n_sys);
302 });
303
304 // And distribute each system's dofs
305 for (auto i : make_range(this->n_systems()))
306 {
307 System & sys = this->get_system(i);
308 DofMap & dof_map = sys.get_dof_map();
309 dof_map.distribute_dofs(_mesh);
310
311 // The user probably won't need constraint equations or the
312 // send_list after an allgather, but let's keep it in consistent
313 // shape just in case.
314 sys.reinit_constraints();
315
316 // Even if there weren't any constraint changes,
317 // reinit_constraints() did prepare_send_list() for us.
318 }
319}
320
321
322
324{
326 MeshBase &mesh = this->get_mesh();
327
328 if (enable)
329 mesh.add_ghosting_functor(mesh.default_ghosting());
330 else
331 mesh.remove_ghosting_functor(mesh.default_ghosting());
332
333 for (auto i : make_range(this->n_systems()))
334 {
335 DofMap & dof_map = this->get_system(i).get_dof_map();
336 if (enable)
337 dof_map.add_default_ghosting();
338 else
339 dof_map.remove_default_ghosting();
340 }
341}
342
343
344
346{
347 LOG_SCOPE("update()", "EquationSystems");
348
349 // Localize each system's vectors
350 for (auto i : make_range(this->n_systems()))
351 this->get_system(i).update();
352}
353
354
355
356System & EquationSystems::add_system (std::string_view sys_type,
357 std::string_view name)
358{
359 // If the user already built a system with this name, we'll
360 // trust them and we'll use it. That way they can pre-add
361 // non-standard derived system classes, and if their restart file
362 // has some non-standard sys_type we won't throw an error.
363 if (_systems.count(name))
364 {
365 return this->get_system(name);
366 }
367 // Build a basic System
368 else if (sys_type == "Basic")
369 this->add_system<System> (name);
370
371 // Build a Newmark system
372 else if (sys_type == "Newmark")
373 this->add_system<NewmarkSystem> (name);
374
375 // Build an Explicit system
376 else if ((sys_type == "Explicit"))
377 this->add_system<ExplicitSystem> (name);
378
379 // Build an Implicit system
380 else if ((sys_type == "Implicit") ||
381 (sys_type == "Steady" ))
382 this->add_system<ImplicitSystem> (name);
383
384 // build a transient implicit linear system
385 else if ((sys_type == "Transient") ||
386 (sys_type == "TransientImplicit") ||
387 (sys_type == "TransientLinearImplicit"))
388 this->add_system<TransientLinearImplicitSystem> (name);
389
390 // build a transient implicit nonlinear system
391 else if (sys_type == "TransientNonlinearImplicit")
392 this->add_system<TransientNonlinearImplicitSystem> (name);
393
394 // build a transient explicit system
395 else if (sys_type == "TransientExplicit")
396 this->add_system<TransientExplicitSystem> (name);
397
398 // build a linear implicit system
399 else if (sys_type == "LinearImplicit")
400 this->add_system<LinearImplicitSystem> (name);
401
402 // build a nonlinear implicit system
403 else if (sys_type == "NonlinearImplicit")
404 this->add_system<NonlinearImplicitSystem> (name);
405
406 // build a Reduced Basis Construction system
407 else if (sys_type == "RBConstruction")
408 this->add_system<RBConstruction> (name);
409
410 // build a transient Reduced Basis Construction system
411 else if (sys_type == "TransientRBConstruction")
412 this->add_system<TransientRBConstruction> (name);
413
414#ifdef LIBMESH_HAVE_SLEPC
415 // build an eigen system
416 else if (sys_type == "Eigen")
417 this->add_system<EigenSystem> (name);
418 else if (sys_type == "TransientEigenSystem")
419 this->add_system<TransientEigenSystem> (name);
420#endif
421
422#if defined(LIBMESH_USE_COMPLEX_NUMBERS)
423 // build a frequency system
424 else if (sys_type == "Frequency")
425 this->add_system<FrequencySystem> (name);
426#endif
427
428 else
429 libmesh_error_msg("ERROR: Unknown system type: " << sys_type);
430
431 // Return a reference to the new system
432 //return (*this)(name);
433 return this->get_system(name);
434}
435
436
437
439{
440 libmesh_assert (this->n_systems());
441
442 for (auto i : make_range(this->n_systems()))
443 this->get_system(i).solve();
444}
445
446
447
449{
450 libmesh_assert (this->n_systems());
451
452 for (auto i : make_range(this->n_systems()))
453 this->get_system(i).sensitivity_solve(parameters_in);
454}
455
456
457
458void EquationSystems::adjoint_solve (const QoISet & qoi_indices)
459{
460 libmesh_assert (this->n_systems());
461
462 for (unsigned int i=this->n_systems(); i != 0; --i)
463 this->get_system(i-1).adjoint_solve(qoi_indices);
464}
465
466
467
468void EquationSystems::build_variable_names (std::vector<std::string> & var_names,
469 const FEType * type,
470 const std::set<std::string> * system_names) const
471{
472 // start indexing at end of possibly non-empty vector of variable names to avoid overwriting them
473 unsigned int var_num = var_names.size();
474
475 // We'll want to double-check that we don't have any naming
476 // conflicts; this API causes problems down the line if so.
477 std::unordered_multiset<std::string> seen_names;
478
479 // Need to size var_names by scalar variables plus all the
480 // vector components for all the vector variables
481 //Could this be replaced by a/some convenience methods?[PB]
482 {
483 unsigned int n_scalar_vars = 0;
484 unsigned int n_vector_vars = 0;
485
486 for (const auto & [sys_name, sys_ptr] : _systems)
487 {
488 // Check current system is listed in system_names, and skip pos if not
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())
493 {
494 for (auto vn : make_range(sys_ptr->n_vars()))
495 seen_names.insert(sys_ptr->variable_name(vn));
496 continue;
497 }
498
499 for (auto vn : make_range(sys_ptr->n_vars()))
500 {
501 seen_names.insert(sys_ptr->variable_name(vn));
502 if (FEInterface::field_type(sys_ptr->variable_type(vn)) == TYPE_VECTOR)
503 n_vector_vars++;
504 else
505 n_scalar_vars++;
506 }
507 }
508
509 // Here, we're assuming the number of vector components is the same
510 // as the mesh spatial dimension.
511 unsigned int dim = this->get_mesh().spatial_dimension();
512 unsigned int nv = n_scalar_vars + dim*n_vector_vars;
513
514 // We'd better not have more than dim*this->n_vars() (all vector variables)
515 // Treat the NodeElem-only mesh case as dim=1
516 libmesh_assert_less_equal ( nv, (dim > 0 ? dim : 1)*this->n_vars() );
517
518 // 'nv' represents the max possible number of output variables, so allocate enough memory for
519 // all variables in the system to be populated here. When this is called more than once on a
520 // single 'var_names' vector, different filters should be used such that duplicates don't occur.
521 var_names.resize( nv );
522 }
523
524 for (const auto & [sys_name, sys_ptr] : _systems)
525 {
526 // Check current system is listed in system_names, and skip pos if not
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())
531 continue;
532
533 for (auto vn : make_range(sys_ptr->n_vars()))
534 {
535 const std::string & var_name = sys_ptr->variable_name(vn);
536 const FEType & fe_type = sys_ptr->variable_type(vn);
537
538 unsigned int n_vec_dim = FEInterface::n_vec_dim( sys_ptr->get_mesh(), fe_type);
539
540 // Filter on the type if requested
541 if (type == nullptr || (type && *type == fe_type))
542 {
543 if (FEInterface::field_type(fe_type) == TYPE_VECTOR)
544 {
545 switch(n_vec_dim)
546 {
547 case 0:
548 case 1:
549 var_names[var_num++] = var_name;
550 libmesh_error_msg_if(seen_names.count(var_name) > 1,
551 "Duplicate variable name "+var_name);
552 break;
553 case 2:
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");
560 break;
561 case 3:
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");
571 break;
572 default:
573 libmesh_error_msg("Invalid dim in build_variable_names");
574 }
575 }
576 else
577 var_names[var_num++] = var_name;
578 }
579 }
580 }
581 // Now resize again in case we filtered any names
582 var_names.resize(var_num);
583}
584
586 bool allow_high_order_discontinuous)
587{
588 return (type.order == CONSTANT || allow_high_order_discontinuous) &&
589 (type.family == MONOMIAL ||
590 type.family == MONOMIAL_VEC ||
591 type.family == XYZ);
592}
593
594
595
597 (std::vector<std::string> & var_names,
598 const std::set<std::string> * system_names,
599 bool allow_high_order_discontinuous) const
600{
601 const std::vector<std::string> name_filter = var_names;
602 const bool is_names_empty = name_filter.empty();
603 var_names.clear();
604
605 const std::vector<std::string> component_suffix = {"_x", "_y", "_z"};
606 const unsigned int dim = _mesh.spatial_dimension();
607 libmesh_error_msg_if(dim > 3, "Invalid dim in build_elemental_data_variable_names");
608
609 for (const auto & [sys_name, sys_ptr] : _systems)
610 {
611 const bool use_current_system = (system_names == nullptr) || system_names->count(sys_name);
612 if (!use_current_system || sys_ptr->hide_output())
613 continue;
614
615 for (auto var : make_range(sys_ptr->n_vars()))
616 {
617 const FEType & var_type = sys_ptr->variable_type(var);
618 if (!EquationSystems::is_elemental_data_fe_type(var_type, allow_high_order_discontinuous))
619 continue;
620
621 if (FEInterface::field_type(var_type) == TYPE_VECTOR)
622 {
623 for (auto comp : make_range(dim))
624 {
625 const std::string name =
626 sys_ptr->variable_name(var) + component_suffix[comp];
627
628 if (is_names_empty ||
629 std::find(name_filter.begin(), name_filter.end(), name) != name_filter.end())
630 var_names.push_back(name);
631 }
632 }
633 else
634 {
635 const std::string & name = sys_ptr->variable_name(var);
636
637 if (is_names_empty ||
638 std::find(name_filter.begin(), name_filter.end(), name) != name_filter.end())
639 var_names.push_back(name);
640 }
641 }
642 }
643
644 std::sort(var_names.begin(), var_names.end());
645}
646
647
648
649void EquationSystems::build_solution_vector (std::vector<Number> &,
650 std::string_view,
651 std::string_view) const
652{
653 // TODO:[BSK] re-implement this from the method below
654 libmesh_not_implemented();
655}
656
657
658
659
660std::unique_ptr<NumericVector<Number>>
661EquationSystems::build_parallel_solution_vector(const std::set<std::string> * system_names,
662 bool add_sides) const
663{
664 LOG_SCOPE("build_parallel_solution_vector()", "EquationSystems");
665
666 // This function must be run on all processors at once
667 parallel_object_only();
668
669 const unsigned int dim = _mesh.spatial_dimension();
670 const dof_id_type max_nn = _mesh.max_node_id();
671
672 // allocate vector storage to hold
673 // (max_node_id)*(number_of_variables) entries.
674 //
675 // If node renumbering is disabled and adaptive coarsening has
676 // created gaps between node numbers, then this vector will be
677 // sparse.
678 //
679 // We have to differentiate between between scalar and vector
680 // variables. We intercept vector variables and treat each
681 // component as a scalar variable (consistently with build_solution_names).
682
683 unsigned int nv = 0;
684
685 //Could this be replaced by a/some convenience methods?[PB]
686 {
687 unsigned int n_scalar_vars = 0;
688 unsigned int n_vector_vars = 0;
689 for (const auto & [sys_name, sys_ptr] : _systems)
690 {
691 // Check current system is listed in system_names, and skip pos if not
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())
696 continue;
697
698 for (auto vn : make_range(sys_ptr->n_vars()))
699 {
700 if (FEInterface::field_type(sys_ptr->variable_type(vn)) == TYPE_VECTOR)
701 n_vector_vars++;
702 else
703 n_scalar_vars++;
704 }
705 }
706 // Here, we're assuming the number of vector components is the same
707 // as the mesh spatial dimension.
708 nv = n_scalar_vars + dim*n_vector_vars;
709 }
710
711 // Get the number of nodes to store locally.
712 dof_id_type n_local_nodes = cast_int<dof_id_type>
713 (std::distance(_mesh.local_nodes_begin(),
714 _mesh.local_nodes_end()));
715
716 // If node renumbering has been disabled, nodes may not be numbered
717 // contiguously, and the number of nodes might not match the
718 // max_node_id. In this case we just do our best.
719 dof_id_type n_total_nodes = n_local_nodes;
720 _mesh.comm().sum(n_total_nodes);
721
722 const processor_id_type n_proc = _mesh.comm().size();
723 const processor_id_type my_pid = _mesh.comm().rank();
724 const dof_id_type n_gaps = max_nn - n_total_nodes;
725 const dof_id_type gaps_per_processor = n_gaps / n_proc;
726 const dof_id_type remainder_gaps = n_gaps % n_proc;
727
728 n_local_nodes = n_local_nodes + // Actual nodes
729 gaps_per_processor + // Our even share of gaps
730 (my_pid < remainder_gaps); // Leftovers
731
732 // If we've been asked to build added sides' data, we need space to
733 // add it. Keep track of how much space.
734 dof_id_type local_added_side_nodes = 0,
735 added_side_nodes = 0;
736
737 // others_added_side_nodes[p]: local_added_side_nodes on rank p
738 std::vector<dof_id_type> others_added_side_nodes;
739
740 // A map of (element_id, side, side_node) pairs to the corresponding
741 // added side node index.
742 std::map<std::tuple<dof_id_type, unsigned short, unsigned short>,
743 dof_id_type> discontinuous_node_indices;
744
745 // If we don't have any added side nodes, we'll have no offsets from
746 // them, and we won't care about which offsets apply to which node
747 // ids either.
748
749 // Number of true nodes on processors [0,p]
750 std::vector<dof_id_type> true_node_offsets;
751 // Number of added (fake) nodes on processors [0,p)
752 std::vector<dof_id_type> added_node_offsets;
753
754 auto node_id_to_vec_id =
755 [&true_node_offsets, &added_node_offsets]
756 (const dof_id_type node_id)
757 {
758 if (true_node_offsets.empty())
759 return node_id; // O(1) in the common !add_sides case
760
761 // Find the processor id that has node_id in the parallel vec
762 const auto lb = std::upper_bound(true_node_offsets.begin(),
763 true_node_offsets.end(), node_id);
764 libmesh_assert(lb != true_node_offsets.end());
765 const processor_id_type p = lb - true_node_offsets.begin();
766
767 return node_id + added_node_offsets[p];
768 };
769
770 if (add_sides)
771 {
772 true_node_offsets.resize(n_proc);
773 added_node_offsets.resize(n_proc);
774
775 // One loop to count everyone's new side nodes
776 for (const auto & elem : _mesh.active_element_ptr_range())
777 {
778 for (auto s : elem->side_index_range())
779 {
780 if (redundant_added_side(*elem,s))
781 continue;
782
783 const std::vector<unsigned int> side_nodes =
784 elem->nodes_on_side(s);
785
786 if (elem->processor_id() == this->processor_id())
787 local_added_side_nodes += side_nodes.size();
788 }
789 }
790
791 others_added_side_nodes.resize(n_proc);
792 _mesh.comm().allgather(local_added_side_nodes,
793 others_added_side_nodes);
794
795 added_side_nodes = std::accumulate(others_added_side_nodes.begin(),
796 others_added_side_nodes.end(), 0,
797 std::plus<>());
798
799 _mesh.comm().allgather(n_local_nodes, true_node_offsets);
800 for (auto p : make_range(n_proc-1))
801 true_node_offsets[p+1] += true_node_offsets[p];
802 libmesh_assert_equal_to(true_node_offsets[n_proc-1], _mesh.max_node_id());
803
804 // For nodes that exist in the mesh, we just need an offset to
805 // tell where to put their solutions.
806 added_node_offsets[0] = 0;
807 for (auto p : make_range(n_proc-1))
808 added_node_offsets[p+1] =
809 added_node_offsets[p] + others_added_side_nodes[p];
810
811 // For added side nodes, we need to fill a map. Start after all
812 // the true node for our pid plus all the side nodes for
813 // previous pids
814 dof_id_type node_counter = true_node_offsets[my_pid];
815 for (auto p : make_range(my_pid))
816 node_counter += others_added_side_nodes[p];
817
818 // One loop to figure out whose added side nodes get which index
819 for (const auto & elem : _mesh.active_local_element_ptr_range())
820 {
821 for (auto s : elem->side_index_range())
822 {
823 if (redundant_added_side(*elem,s))
824 continue;
825
826 const std::vector<unsigned int> side_nodes =
827 elem->nodes_on_side(s);
828
829 for (auto n : index_range(side_nodes))
830 discontinuous_node_indices
831 [std::make_tuple(elem->id(),s,n)] = node_counter++;
832 }
833 }
834 }
835
836 const dof_id_type
837 n_global_vals = (max_nn + added_side_nodes) * nv,
838 n_local_vals = (n_local_nodes + local_added_side_nodes) * nv;
839
840 // Create a NumericVector to hold the parallel solution
841 std::unique_ptr<NumericVector<Number>> parallel_soln_ptr = NumericVector<Number>::build(_communicator);
842 NumericVector<Number> & parallel_soln = *parallel_soln_ptr;
843 parallel_soln.init(n_global_vals, n_local_vals, false, PARALLEL);
844
845 // Create a NumericVector to hold the "repeat_count" for each node - this is essentially
846 // the number of elements contributing to that node's value
847 std::unique_ptr<NumericVector<Number>> repeat_count_ptr = NumericVector<Number>::build(_communicator);
848 NumericVector<Number> & repeat_count = *repeat_count_ptr;
849 repeat_count.init(n_global_vals, n_local_vals, false, PARALLEL);
850
851 repeat_count.close();
852
853 unsigned int var_num=0;
854
855 // For each system in this EquationSystems object,
856 // update the global solution and if we are on processor 0,
857 // loop over the elements and build the nodal solution
858 // from the element solution. Then insert this nodal solution
859 // into the vector passed to build_solution_vector.
860 for (const auto & [sys_name, sys_ptr] : _systems)
861 {
862 // Check current system is listed in system_names, and skip pos if not
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())
867 continue;
868
869 const System & system = *sys_ptr;
870 const unsigned int nv_sys = system.n_vars();
871 const unsigned int sys_num = system.number();
872
873 //Could this be replaced by a/some convenience methods?[PB]
874 unsigned int n_scalar_vars = 0;
875 unsigned int n_vector_vars = 0;
876 for (auto vn : make_range(sys_ptr->n_vars()))
877 {
878 if (FEInterface::field_type(sys_ptr->variable_type(vn)) == TYPE_VECTOR)
879 n_vector_vars++;
880 else
881 n_scalar_vars++;
882 }
883
884 // Here, we're assuming the number of vector components is the same
885 // as the mesh spatial dimension.
886 unsigned int nv_sys_split = n_scalar_vars + dim*n_vector_vars;
887
888 // Update the current_local_solution
889 {
890 System & non_const_sys = const_cast<System &>(system);
891 // We used to simply call non_const_sys.solution->close()
892 // here, but that is not allowed when the solution vector is
893 // locked read-only, for example when printing the solution
894 // during the middle of a solve... So try to be a bit
895 // more careful about calling close() unnecessarily.
896 libmesh_assert(this->comm().verify(non_const_sys.solution->closed()));
897 if (!non_const_sys.solution->closed())
898 non_const_sys.solution->close();
899 non_const_sys.update();
900 }
901
903
904 const DofMap & dof_map = system.get_dof_map();
905
906 std::vector<Number> elem_soln; // The finite element solution
907 std::vector<Number> nodal_soln; // The FE solution interpolated to the nodes
908 std::vector<dof_id_type> dof_indices; // The DOF indices for the finite element
909
910 unsigned var_inc = 0;
911 for (unsigned int var=0; var<nv_sys; var++)
912 {
913 const FEType & fe_type = system.variable_type(var);
914 const Variable & var_description = system.variable(var);
915 unsigned int n_vec_dim = FEInterface::n_vec_dim( sys_ptr->get_mesh(), fe_type );
916 const bool add_p_level = fe_type.p_refinement;
917
918 for (const auto & elem : _mesh.active_local_element_ptr_range())
919 {
920 if (var_description.active_on_subdomain(elem->subdomain_id()))
921 {
922 dof_map.dof_indices (elem, dof_indices, var);
923 sys_soln.get(dof_indices, elem_soln);
924
925 FEInterface::nodal_soln (elem->dim(),
926 fe_type,
927 elem,
928 elem_soln,
929 nodal_soln,
930 add_p_level,
931 n_vec_dim);
932
933 // infinite elements should be skipped...
934 if (!elem->infinite())
935 {
936 libmesh_assert_equal_to (nodal_soln.size(), n_vec_dim*elem->n_nodes());
937
938 for (auto n : elem->node_index_range())
939 {
940 const Node & node = elem->node_ref(n);
941
942 const dof_id_type node_idx =
943 nv * node_id_to_vec_id(node.id());
944
945 for (unsigned int d=0; d < n_vec_dim; d++)
946 {
947 // For vector-valued elements, all components are in nodal_soln. For each
948 // node, the components are stored in order, i.e. node_0 -> s0_x, s0_y, s0_z
949 parallel_soln.add(node_idx + (var_inc+d + var_num), nodal_soln[n_vec_dim*n+d]);
950
951 // Increment the repeat count for this position
952 repeat_count.add(node_idx + (var_inc+d + var_num), 1);
953 }
954 }
955
956 if (add_sides)
957 {
958 for (auto s : elem->side_index_range())
959 {
960 if (redundant_added_side(*elem,s))
961 continue;
962
963 // Compute the FE solution at all the
964 // side nodes
966 (fe_type, elem, s, elem_soln,
967 nodal_soln, add_p_level, n_vec_dim);
968
969#ifdef DEBUG
970 const std::vector<unsigned int> side_nodes =
971 elem->nodes_on_side(s);
972
973 libmesh_assert_equal_to
974 (nodal_soln.size(),
975 side_nodes.size());
976#endif
977
978 for (auto n : index_range(nodal_soln))
979 {
980 // Retrieve index into global solution vector.
981 std::size_t node_index =
982 nv * libmesh_map_find(discontinuous_node_indices,
983 std::make_tuple(elem->id(), s, n));
984
985 for (unsigned int d=0; d < n_vec_dim; d++)
986 {
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);
989 }
990 }
991 }
992 }
993 }
994 }
995 else // If this variable doesn't exist on this subdomain we have to still increment repeat_count so that we won't divide by 0 later:
996 for (auto n : elem->node_index_range())
997 {
998 const Node & node = elem->node_ref(n);
999 // Only do this if this variable has NO DoFs at
1000 // this node... it might have some from an
1001 // adjoining element...
1002 if (!node.n_dofs(sys_num, var))
1003 {
1004 const dof_id_type node_idx =
1005 nv * node_id_to_vec_id(node.id());
1006
1007 for (unsigned int d=0; d < n_vec_dim; d++)
1008 repeat_count.add(node_idx + (var_inc+d + var_num), 1);
1009 }
1010 }
1011
1012 } // end loop over elements
1013 var_inc += n_vec_dim;
1014 } // end loop on variables in this system
1015
1016 var_num += nv_sys_split;
1017 } // end loop over systems
1018
1019 // Sum the nodal solution values and repeat counts.
1020 parallel_soln.close();
1021 repeat_count.close();
1022
1023 // If there were gaps in the node numbering, there will be
1024 // corresponding zeros in the parallel_soln and repeat_count
1025 // vectors. We need to set those repeat_count entries to 1
1026 // in order to avoid dividing by zero.
1027 if (n_gaps)
1028 {
1029 for (numeric_index_type i=repeat_count.first_local_index();
1030 i<repeat_count.last_local_index(); ++i)
1031 {
1032 // repeat_count entries are integral values but let's avoid a
1033 // direct floating point comparison with 0 just in case some
1034 // roundoff noise crept in during vector assembly?
1035 if (std::abs(repeat_count(i)) < TOLERANCE)
1036 repeat_count.set(i, 1.);
1037 }
1038
1039 // Make sure the repeat_count vector is up-to-date on all
1040 // processors.
1041 repeat_count.close();
1042 }
1043
1044 // Divide to get the average value at the nodes
1045 parallel_soln /= repeat_count;
1046
1047 return parallel_soln_ptr;
1048}
1049
1050
1051
1052void EquationSystems::build_solution_vector (std::vector<Number> & soln,
1053 const std::set<std::string> * system_names,
1054 bool add_sides) const
1055{
1056 LOG_SCOPE("build_solution_vector()", "EquationSystems");
1057
1058 // Call the parallel implementation
1059 std::unique_ptr<NumericVector<Number>> parallel_soln =
1060 this->build_parallel_solution_vector(system_names, add_sides);
1061
1062 // Localize the NumericVector into the provided std::vector.
1063 parallel_soln->localize_to_one(soln);
1064}
1065
1066
1067
1068void EquationSystems::get_vars_active_subdomains(const std::vector<std::string> & names,
1069 std::vector<std::set<subdomain_id_type>> & vars_active_subdomains) const
1070{
1071 vars_active_subdomains.clear();
1072 vars_active_subdomains.resize(names.size());
1073
1074 for (const auto & pr : _systems)
1075 {
1076 const auto & sys_ptr = pr.second;
1077 for (auto vn : make_range(sys_ptr->n_vars()))
1078 {
1079 const std::string & var_name = sys_ptr->variable_name(vn);
1080
1081 auto names_it = std::find(names.begin(), names.end(), var_name);
1082 if(names_it != names.end())
1083 {
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;
1087 }
1088 }
1089 }
1090}
1091
1092
1093
1094void
1096 std::vector<std::string> & names,
1097 bool allow_high_order_discontinuous) const
1098{
1099 // Call the parallel version of this function
1100 std::unique_ptr<NumericVector<Number>> parallel_soln =
1101 this->build_parallel_elemental_solution_vector(names, allow_high_order_discontinuous);
1102
1103 // Localize into 'soln', provided that parallel_soln is not empty.
1104 // Note: parallel_soln will be empty in the event that none of the
1105 // input names were elemental data variables, or there were simply none of these in
1106 // the EquationSystems object.
1107 soln.clear();
1108 if (parallel_soln)
1109 parallel_soln->localize_to_one(soln);
1110}
1111
1112std::vector<std::pair<unsigned int, unsigned int>>
1114 (std::vector<std::string> & names, const FEType * type, const std::vector<FEType> * types) const
1115{
1116 // Resolve class of type input and assert that at least one of them is null
1117 libmesh_assert_msg(!type || !types,
1118 "Input 'type', 'types', or neither in find_variable_numbers, but not both.");
1119
1120 std::vector<FEType> type_filter;
1121 if (type)
1122 type_filter.push_back(*type);
1123 else if (types)
1124 type_filter = *types;
1125
1127 (names,
1128 [&type_filter](const FEType & var_type)
1129 {
1130 return type_filter.empty() ||
1131 std::find(type_filter.begin(), type_filter.end(), var_type) != type_filter.end();
1132 });
1133}
1134
1135
1136
1137std::vector<std::pair<unsigned int, unsigned int>>
1139 bool allow_high_order_discontinuous) const
1140{
1142 (names,
1143 [allow_high_order_discontinuous](const FEType & type)
1144 { return EquationSystems::is_elemental_data_fe_type(type, allow_high_order_discontinuous); });
1145}
1146
1147
1148
1149std::vector<std::pair<unsigned int, unsigned int>>
1151 (std::vector<std::string> & names,
1152 const std::function<bool(const FEType &)> & type_filter) const
1153{
1154 // This function must be run on all processors at once
1155 parallel_object_only();
1156
1157 libmesh_assert (this->n_systems());
1158
1159 // Store a copy of the valid variable names, if any. The names vector will be repopulated with any
1160 // valid names (or all if 'is_names_empty') in the system that passes through the type filter. If
1161 // the variable is a vector, its name will be decomposed into its separate components in
1162 // accordance with build_variable_names().
1163 std::vector<std::string> name_filter = names;
1164 bool is_names_empty = name_filter.empty();
1165 names.clear();
1166
1167 // initialize convenience variables
1168 FEType var_type;
1169 std::string name;
1170
1171 const std::vector<std::string> component_suffix = {"_x", "_y", "_z"};
1172 unsigned int dim = _mesh.spatial_dimension();
1173 libmesh_error_msg_if(dim > 3, "Invalid dim in find_variable_numbers");
1174
1175 // Now filter through the variables in each system and store the system index and their index
1176 // within that system. This way, we know where to find their data even after we sort them.
1177 std::vector<std::pair<unsigned int, unsigned int>> var_nums;
1178
1179 for (const auto & pr : _systems)
1180 {
1181 const System & system = *(pr.second);
1182
1183 for (auto var : make_range(system.n_vars()))
1184 {
1185 // apply the type filter
1186 var_type = system.variable_type(var);
1187 if (!type_filter(var_type))
1188 continue;
1189
1190 // apply the name filter (note that all variables pass if it is empty)
1191 if (FEInterface::field_type(var_type) == TYPE_VECTOR)
1192 {
1193 std::vector<std::string> component_names;
1194 for (unsigned int comp = 0; comp < dim; ++comp)
1195 {
1196 name = system.variable_name(var) + component_suffix[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);
1200 }
1201
1202 if (! component_names.empty())
1203 names.insert(names.end(), component_names.begin(), component_names.end());
1204 else
1205 continue;
1206 }
1207 else /*scalar-valued variable*/
1208 {
1209 name = system.variable_name(var);
1210 if (is_names_empty ||
1211 (std::find(name_filter.begin(), name_filter.end(), name) != name_filter.end()))
1212 names.push_back(name);
1213 else
1214 continue;
1215 }
1216
1217 // if the variable made it through both filters get its system indices
1218 var_nums.emplace_back(system.number(), var);
1219 }
1220 }
1221
1222 // Sort the var_nums vector pairs alphabetically based on the variable name
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);});
1229
1230 std::vector<std::pair<unsigned int, unsigned int>> var_nums_sorted(var_nums.size());
1231 for (auto i : index_range(var_nums_sorted))
1232 {
1233 var_nums_sorted[i].first = var_nums[sort_index[i]].first;
1234 var_nums_sorted[i].second = var_nums[sort_index[i]].second;
1235 }
1236
1237 // Also sort the names vector
1238 std::sort(names.begin(), names.end());
1239
1240 // Return the sorted vector pairs
1241 return var_nums_sorted;
1242}
1243
1244
1245std::unique_ptr<NumericVector<Number>>
1247 bool allow_high_order_discontinuous) const
1248{
1249 // Filter any names that aren't elemental variables and get the system indices for those that are.
1250 // Note that it's probably fine if the names vector is empty since we'll still filter out all
1251 // non-elemental-data variables. If there are none, then nothing is output here.
1252 std::vector<std::pair<unsigned int, unsigned int>> var_nums =
1253 this->find_elemental_data_variable_numbers(names, allow_high_order_discontinuous);
1254
1255 const std::size_t nv = names.size(); /*total number of vars including vector components*/
1256 const dof_id_type ne = _mesh.n_elem();
1257 libmesh_assert_equal_to (ne, _mesh.max_elem_id());
1258
1259 // If there are no variables to write out don't do anything...
1260 if (!nv)
1261 return std::unique_ptr<NumericVector<Number>>(nullptr);
1262
1263 // We can handle the case where there are nullptrs in the Elem vector
1264 // by just having extra zeros in the solution vector.
1265 numeric_index_type parallel_soln_global_size = ne*nv;
1266
1267 numeric_index_type div = parallel_soln_global_size / this->n_processors();
1268 numeric_index_type mod = parallel_soln_global_size % this->n_processors();
1269
1270 // Initialize all processors to the average size.
1271 numeric_index_type parallel_soln_local_size = div;
1272
1273 // The first "mod" processors get an extra entry.
1274 if (this->processor_id() < mod)
1275 parallel_soln_local_size = div+1;
1276
1277 // Create a NumericVector to hold the parallel solution
1278 std::unique_ptr<NumericVector<Number>> parallel_soln_ptr = NumericVector<Number>::build(_communicator);
1279 NumericVector<Number> & parallel_soln = *parallel_soln_ptr;
1280 parallel_soln.init(parallel_soln_global_size,
1281 parallel_soln_local_size,
1282 /*fast=*/false,
1283 /*ParallelType=*/PARALLEL);
1284
1285 unsigned int sys_ctr = 0;
1286 unsigned int var_ctr = 0;
1287 for (auto i : index_range(var_nums))
1288 {
1289 std::pair<unsigned int, unsigned int> var_num = var_nums[i];
1290 const System & system = this->get_system(var_num.first);
1291
1292 // Update the current_local_solution if necessary
1293 if (sys_ctr != var_num.first)
1294 {
1295 System & non_const_sys = const_cast<System &>(system);
1296 // We used to simply call non_const_sys.solution->close()
1297 // here, but that is not allowed when the solution vector is
1298 // locked read-only, for example when printing the solution
1299 // during during the middle of a solve... So try to be a bit
1300 // more careful about calling close() unnecessarily.
1301 libmesh_assert(this->comm().verify(non_const_sys.solution->closed()));
1302 if (!non_const_sys.solution->closed())
1303 non_const_sys.solution->close();
1304 non_const_sys.update();
1305 sys_ctr = var_num.first;
1306 }
1307
1309
1310 const unsigned int var = var_num.second;
1311
1312 const Variable & variable = system.variable(var);
1313 const DofMap & dof_map = system.get_dof_map();
1314
1315 // We need to check if the elemental data variable is a scalar or a vector and set the number of
1316 // components for the latter as per es.find_variable_numbers().
1317 // Even for the case where a variable is not active on any subdomain belonging to the
1318 // processor, we still need to know this number to update 'var_ctr'.
1319 const auto & var_type = system.variable_type(var);
1320 const FEFieldType field_type = FEInterface::field_type(var_type);
1321 const unsigned int n_comps =
1322 (field_type == TYPE_VECTOR) ?
1323 FEInterface::n_vec_dim(_mesh, var_type) : 1;
1324
1325 // Elemental data variables are normally CONSTANT order, in which case
1326 // there is exactly one DOF per component and we can just copy it
1327 // directly. When allow_high_order_discontinuous permits a
1328 // non-CONSTANT order variable through, a single DOF no longer
1329 // represents the element's value, so we instead compute a
1330 // quadrature-weighted average of the FE solution over the element.
1331 const bool need_quadrature_average =
1332 allow_high_order_discontinuous && var_type.order != CONSTANT;
1333
1334 // Loop over all elements in the mesh and index all components of the variable if it's active
1337 [&system, &dof_map, &variable, ne, var, var_ctr, n_comps, field_type,
1338 need_quadrature_average, &parallel_soln, &sys_soln](const ConstElemRange & range)
1339 {
1340 // The DOF indices for the finite element
1341 std::vector<dof_id_type> dof_indices;
1342
1343 // FE context for the quadrature-average path. It is built here,
1344 // inside the parallel_for lambda body, so that each range
1345 // invocation (which runs single-threaded) owns its own; sharing
1346 // FE objects across threads would race on reinit().
1347 std::unique_ptr<FEMContext> con;
1348 if (need_quadrature_average)
1349 {
1350 const std::vector<unsigned int> active_vars {var};
1351 con = std::make_unique<FEMContext>(system, &active_vars,
1352 /*allocate_local_matrices=*/false);
1353 }
1354
1355 // Quadrature-weighted average of the variable over elem. The
1356 // second argument only selects the value type: Number for
1357 // scalar variables, Gradient for vector-valued ones.
1358 auto element_average = [&con, &system, var](const Elem * elem, auto zero_value)
1359 {
1360 typedef decltype(zero_value) OutputType;
1361 typedef typename TensorTools::MakeReal<OutputType>::type OutputShape;
1362
1363 con->pre_fe_reinit(system, elem);
1364
1365 // Request what interior_value() needs before reinit
1366 FEGenericBase<OutputShape> * fe = nullptr;
1367 con->get_element_fe(var, fe);
1368 const std::vector<Real> & JxW = fe->get_JxW();
1369 fe->get_phi();
1370
1371 con->elem_fe_reinit();
1372
1373 OutputType avg = zero_value;
1374 Real vol = 0;
1375 for (auto qp : index_range(JxW))
1376 {
1377 OutputType u_h;
1378 con->interior_value(var, qp, u_h);
1379 avg += JxW[qp] * u_h;
1380 vol += JxW[qp];
1381 }
1382 avg /= vol;
1383 return avg;
1384 };
1385
1386 for (const Elem * elem : range)
1387 {
1388 if (variable.active_on_subdomain(elem->subdomain_id()))
1389 {
1390 if (need_quadrature_average)
1391 {
1392 if (field_type == TYPE_SCALAR)
1393 parallel_soln.set(ne * var_ctr + elem->id(), element_average(elem, Number()));
1394 else
1395 {
1396 const Gradient avg = element_average(elem, Gradient());
1397 for (unsigned int comp = 0; comp < n_comps; comp++)
1398 parallel_soln.set(ne * (var_ctr + comp) + elem->id(), avg(comp));
1399 }
1400 }
1401 else
1402 {
1403 dof_map.dof_indices(elem, dof_indices, var);
1404
1405 // The number of DOF components needs to be equal to the expected number so that we know
1406 // where to store data to correctly correspond to variable names.
1407 libmesh_assert_equal_to(dof_indices.size(), n_comps);
1408
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]));
1411 }
1412 }
1413 }
1414 });
1415
1416 var_ctr += n_comps;
1417 } // end loop over var_nums
1418
1419 // NOTE: number of output names might not be equal to the number passed to this function. Any that
1420 // aren't elemental data variables have been filtered out (see
1421 // EquationSystems::find_variable_numbers).
1422 //
1423 // But, if everything is accounted for properly, then names.size() == var_ctr
1424 libmesh_assert_equal_to(names.size(), var_ctr);
1425
1426 parallel_soln.close();
1427 return parallel_soln_ptr;
1428}
1429
1430
1431
1432void
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,
1437 bool vertices_only,
1438 bool add_sides) const
1439{
1440 LOG_SCOPE("build_discontinuous_solution_vector()", "EquationSystems");
1441
1442 libmesh_assert (this->n_systems());
1443
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)
1448 {
1449 std::vector<unsigned int> components;
1450
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);
1454
1455 if (FEInterface::field_type(fe_type) == TYPE_VECTOR)
1456 {
1457 libmesh_error_msg_if(n_vec_dim > component_suffix.size(),
1458 "Invalid dim in build_discontinuous_solution_vector");
1459
1460 const bool use_all_components =
1461 (var_names == nullptr) ||
1462 std::count(var_names->begin(), var_names->end(), var_name);
1463
1464 if (n_vec_dim <= 1)
1465 {
1466 if (use_all_components)
1467 components.push_back(0);
1468 }
1469 else
1470 for (auto comp : make_range(n_vec_dim))
1471 {
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);
1476 }
1477 }
1478 else if (var_names == nullptr ||
1479 std::count(var_names->begin(), var_names->end(), var_name))
1480 components.push_back(0);
1481
1482 return components;
1483 };
1484
1485 // Get the number of variables (nv) by counting the number of variables
1486 // in each system listed in system_names
1487 unsigned int nv = 0;
1488
1489 for (const auto & [sys_name, sys_ptr] : _systems)
1490 {
1491 // Check current system is listed in system_names, and skip pos if not
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())
1496 continue;
1497
1498 // Loop over all variables in this System and check whether we
1499 // are supposed to use each one.
1500 for (auto var_id : make_range(sys_ptr->n_vars()))
1501 nv += cast_int<unsigned int>(requested_components(*sys_ptr, var_id).size());
1502 }
1503
1504 // get the total "weight" - the number of nodal values to write for
1505 // each variable.
1506 unsigned int tw=0;
1507 for (const auto & elem : _mesh.active_element_ptr_range())
1508 {
1509 tw += vertices_only ? elem->n_vertices() : elem->n_nodes();
1510
1511 if (add_sides)
1512 {
1513 for (auto s : elem->side_index_range())
1514 {
1515 if (redundant_added_side(*elem,s))
1516 continue;
1517
1518 const std::vector<unsigned int> side_nodes =
1519 elem->nodes_on_side(s);
1520
1521 if (!vertices_only)
1522 tw += side_nodes.size();
1523 else
1524 for (auto n : index_range(side_nodes))
1525 if (elem->is_vertex(side_nodes[n]))
1526 ++tw;
1527 }
1528 }
1529 }
1530
1531 // Only if we are on processor zero, allocate the storage
1532 // to hold (number_of_nodes)*(number_of_variables) entries.
1533 if (_mesh.processor_id() == 0)
1534 soln.resize(tw*nv);
1535
1536 std::vector<Number> sys_soln;
1537
1538 // Keep track of the variable "offset". This is used for indexing
1539 // into the global solution vector.
1540 unsigned int var_offset = 0;
1541
1542 // For each system in this EquationSystems object,
1543 // update the global solution and if we are on processor 0,
1544 // loop over the elements and build the nodal solution
1545 // from the element solution. Then insert this nodal solution
1546 // into the vector passed to build_solution_vector.
1547 for (const auto & [sys_name, system] : _systems)
1548 {
1549 // Check current system is listed in system_names, and skip pos if not
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())
1554 continue;
1555
1556 const unsigned int nv_sys = system->n_vars();
1557 const auto & dof_map = system->get_dof_map();
1558
1559 system->update_global_solution (sys_soln, 0);
1560
1561 // Keep track of the number of vars actually written.
1562 unsigned int n_vars_written_current_system = 0;
1563
1564 if (_mesh.processor_id() == 0)
1565 {
1566 std::vector<Number> soln_coeffs; // The finite element solution coeffs
1567 std::vector<Number> nodal_soln; // The FE solution interpolated to the nodes
1568 std::vector<dof_id_type> dof_indices; // The DOF indices for the finite element
1569
1570 // For each variable, determine if we are supposed to
1571 // write it, then loop over the active elements, compute
1572 // the nodal_soln and store it to the "soln" vector. We
1573 // store zeros for subdomain-restricted variables on
1574 // elements where they are not active.
1575 for (auto var : make_range(nv_sys))
1576 {
1577 const std::vector<unsigned int> components_to_write =
1578 requested_components(*system, var);
1579
1580 // If we aren't supposed to write this var, go to the
1581 // next loop iteration.
1582 if (components_to_write.empty())
1583 continue;
1584
1585 const FEType & fe_type = system->variable_type(var);
1586 const Variable & var_description = system->variable(var);
1587 const bool add_p_level = fe_type.p_refinement;
1588 const unsigned int n_vec_dim = FEInterface::n_vec_dim(_mesh, fe_type);
1589
1590 unsigned int nn=0;
1591
1592 for (auto & elem : _mesh.active_element_ptr_range())
1593 {
1594 if (var_description.active_on_subdomain(elem->subdomain_id()))
1595 {
1596 dof_map.dof_indices (elem, dof_indices, var);
1597
1598 soln_coeffs.resize(dof_indices.size());
1599
1600 for (auto i : index_range(dof_indices))
1601 soln_coeffs[i] = sys_soln[dof_indices[i]];
1602
1603 // Compute the FE solution at all the nodes, but
1604 // only use the first n_vertices() entries if
1605 // vertices_only == true.
1606 FEInterface::nodal_soln (elem->dim(),
1607 fe_type,
1608 elem,
1609 soln_coeffs,
1610 nodal_soln,
1611 add_p_level,
1612 n_vec_dim);
1613
1614 // infinite elements should be skipped...
1615 if (!elem->infinite())
1616 {
1617 libmesh_assert_equal_to (nodal_soln.size(), elem->n_nodes()*n_vec_dim);
1618
1619 const unsigned int n_vals =
1620 vertices_only ? elem->n_vertices() : elem->n_nodes();
1621
1622 for (auto n : make_range(n_vals))
1623 {
1624 // Compute index into global solution vector.
1625 std::size_t index =
1626 nv * (nn++) + (n_vars_written_current_system + var_offset);
1627
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]];
1631 }
1632 }
1633 }
1634 else
1635 nn += vertices_only ? elem->n_vertices() : elem->n_nodes();
1636 } // end loop over active elements writing interiors
1637
1638 // Loop writing "fake" sides, if requested
1639 if (add_sides)
1640 {
1641 // We don't build discontinuous solution vectors in
1642 // parallel yet, but we'll do ordering of fake side
1643 // values as if we did, for consistency with the
1644 // parallel continuous ordering and for future
1645 // compatibility.
1646 std::vector<std::vector<const Elem *>>
1647 elems_by_pid(_mesh.n_processors());
1648
1649 for (const auto & elem : _mesh.active_element_ptr_range())
1650 elems_by_pid[elem->processor_id()].push_back(elem);
1651
1652 for (auto p : index_range(elems_by_pid))
1653 for (const Elem * elem : elems_by_pid[p])
1654 {
1655 if (var_description.active_on_subdomain(elem->subdomain_id()))
1656 {
1657 dof_map.dof_indices (elem, dof_indices, var);
1658
1659 soln_coeffs.resize(dof_indices.size());
1660
1661 for (auto i : index_range(dof_indices))
1662 soln_coeffs[i] = sys_soln[dof_indices[i]];
1663
1664 for (auto s : elem->side_index_range())
1665 {
1666 if (redundant_added_side(*elem,s))
1667 continue;
1668
1669 const std::vector<unsigned int> side_nodes =
1670 elem->nodes_on_side(s);
1671
1672 // Compute the FE solution at all the
1673 // side nodes, but only use those for
1674 // which is_vertex() == true if
1675 // vertices_only == true.
1676 FEInterface::side_nodal_soln
1677 (fe_type, elem, s, soln_coeffs,
1678 nodal_soln, add_p_level,
1679 n_vec_dim);
1680
1681 libmesh_assert_equal_to
1682 (nodal_soln.size(),
1683 side_nodes.size()*n_vec_dim);
1684
1685 // If we don't have a continuous FE
1686 // then we want to average between
1687 // sides, at least in the equal-level
1688 // case where it's easy. This is
1689 // analogous to our repeat_count
1690 // behavior elsewhere.
1691 const FEContinuity cont =
1692 FEInterface::get_continuity(fe_type);
1693 const Elem * const neigh = elem->neighbor_ptr(s);
1694
1695 if ((cont == DISCONTINUOUS || cont == H_CURL || cont == H_DIV) &&
1696 neigh &&
1697 neigh->level() == elem->level() &&
1698 var_description.active_on_subdomain(neigh->subdomain_id()))
1699 {
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());
1703
1704 for (auto i : index_range(neigh_indices))
1705 neigh_coeffs[i] = sys_soln[neigh_indices[i]];
1706
1707 const unsigned int s_neigh =
1708 neigh->which_neighbor_am_i(elem);
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,
1713 n_vec_dim);
1714
1715 const std::vector<unsigned int> neigh_nodes =
1716 neigh->nodes_on_side(s_neigh);
1717 for (auto n : index_range(side_nodes))
1718 for (auto neigh_n : index_range(neigh_nodes))
1719 if (neigh->node_ptr(neigh_nodes[neigh_n])
1720 == elem->node_ptr(side_nodes[n]))
1721 for (auto comp : make_range(n_vec_dim))
1722 {
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;
1727 }
1728 }
1729
1730 for (auto n : index_range(side_nodes))
1731 {
1732 if (vertices_only &&
1733 !elem->is_vertex(n))
1734 continue;
1735
1736 // Compute index into global solution vector.
1737 std::size_t index =
1738 nv * (nn++) + (n_vars_written_current_system + var_offset);
1739
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]];
1743 }
1744 }
1745 }
1746 else
1747 {
1748 nn += vertices_only ? elem->n_vertices() : elem->n_nodes();
1749
1750 for (auto s : elem->side_index_range())
1751 {
1752 if (redundant_added_side(*elem,s))
1753 continue;
1754
1755 const std::vector<unsigned int> side_nodes =
1756 elem->nodes_on_side(s);
1757
1758 for (auto n : index_range(side_nodes))
1759 {
1760 if (vertices_only &&
1761 !elem->is_vertex(n))
1762 continue;
1763 nn++;
1764 }
1765 }
1766 }
1767 } // end loop over active elements, writing "fake" sides
1768 }
1769 // If we made it here, we actually wrote a variable, so increment
1770 // the number of variables actually written for the current system.
1771 n_vars_written_current_system += cast_int<unsigned int>(components_to_write.size());
1772
1773 } // end loop over vars
1774 } // end if proc 0
1775
1776 // Update offset for next loop iteration.
1777 var_offset += n_vars_written_current_system;
1778 } // end loop over systems
1779}
1780
1781
1782
1783bool EquationSystems::redundant_added_side(const Elem & elem, unsigned int side)
1784{
1785 libmesh_assert(elem.active());
1786
1787 const Elem * neigh = elem.neighbor_ptr(side);
1788
1789 // Write boundary sides.
1790 if (!neigh)
1791 return false;
1792
1793 // Write ghost sides in Nemesis
1794 if (neigh == remote_elem)
1795 return false;
1796
1797 // Don't write a coarser side if a finer side exists
1798 if (!neigh->active())
1799 return true;
1800
1801 // Don't write a side redundantly from both of the
1802 // elements sharing it. We'll disambiguate with id().
1803 return (neigh->id() < elem.id());
1804}
1805
1806
1807
1808bool EquationSystems::compare (const EquationSystems & other_es,
1809 const Real threshold,
1810 const bool verbose) const
1811{
1812 // safety check, whether we handle at least the same number
1813 // of systems
1814 std::vector<bool> os_result;
1815
1816 if (this->n_systems() != other_es.n_systems())
1817 {
1818 if (verbose)
1819 {
1820 libMesh::out << " Fatal difference. This system handles "
1821 << this->n_systems() << " systems," << std::endl
1822 << " while the other system handles "
1823 << other_es.n_systems()
1824 << " systems." << std::endl
1825 << " Aborting comparison." << std::endl;
1826 }
1827 return false;
1828 }
1829 else
1830 {
1831 // start comparing each system
1832 for (const auto & [sys_name, sys_ptr] : _systems)
1833 {
1834 // get the other system
1835 const System & other_system = other_es.get_system (sys_name);
1836
1837 os_result.push_back (sys_ptr->compare (other_system, threshold, verbose));
1838
1839 }
1840
1841 }
1842
1843
1844 // sum up the results
1845 if (os_result.size()==0)
1846 return true;
1847 else
1848 {
1849 bool os_identical;
1850 unsigned int n = 0;
1851 do
1852 {
1853 os_identical = os_result[n];
1854 n++;
1855 }
1856 while (os_identical && n<os_result.size());
1857 return os_identical;
1858 }
1859}
1860
1861
1862
1863std::string EquationSystems::get_info () const
1864{
1865 std::ostringstream oss;
1866
1867 unsigned int n_hidden_sys = 0;
1868 for (auto & pr : _systems)
1869 n_hidden_sys += pr.second->hide_output();
1870
1871 oss << " EquationSystems\n"
1872 << " n_systems()=" << this->n_systems()
1873 << (n_hidden_sys ? " (hidden: " + std::to_string(n_hidden_sys) + ")" : "")
1874 << "\n";
1875
1876 // Print the info for the individual systems
1877 for (const auto & pr : _systems)
1878 if (!pr.second->hide_output())
1879 oss << pr.second->get_info();
1880
1881
1882 // // Possibly print the parameters
1883 // if (!this->parameters.empty())
1884 // {
1885 // oss << " n_parameters()=" << this->n_parameters() << '\n';
1886 // oss << " Parameters:\n";
1887
1888 // for (const auto & [key, val] : _parameters)
1889 // oss << " "
1890 // << "\""
1891 // << key
1892 // << "\""
1893 // << "="
1894 // << val
1895 // << '\n';
1896 // }
1897
1898 return oss.str();
1899}
1900
1901
1902
1903void EquationSystems::print_info (std::ostream & os) const
1904{
1905 os << this->get_info()
1906 << std::endl;
1907}
1908
1909
1910
1911std::ostream & operator << (std::ostream & os,
1912 const EquationSystems & es)
1913{
1914 es.print_info(os);
1915 return os;
1916}
1917
1918
1919
1920unsigned int EquationSystems::n_vars () const
1921{
1922 unsigned int tot=0;
1923
1924 for (const auto & pr : _systems)
1925 tot += pr.second->n_vars();
1926
1927 return tot;
1928}
1929
1930
1931
1932std::size_t EquationSystems::n_dofs () const
1933{
1934 std::size_t tot=0;
1935
1936 for (const auto & pr : _systems)
1937 tot += pr.second->n_dofs();
1938
1939 return tot;
1940}
1941
1942
1943
1944
1945std::size_t EquationSystems::n_active_dofs () const
1946{
1947 std::size_t tot=0;
1948
1949 for (const auto & pr : _systems)
1950 tot += pr.second->n_active_dofs();
1951
1952 return tot;
1953}
1954
1955
1956void EquationSystems::_add_system_to_nodes_and_elems()
1957{
1958 // All the nodes
1959 for (auto & node : _mesh.node_ptr_range())
1960 node->add_system();
1961
1962 // All the elements
1963 Threads::parallel_for
1964 (_mesh.element_stored_range(),
1965 [](const ElemRange & range)
1966 {
1967 for (Elem * elem : range)
1968 elem->add_system();
1969 });
1970}
1971
1972void EquationSystems::_remove_default_ghosting(unsigned int sys_num)
1973{
1974 this->get_system(sys_num).get_dof_map().remove_default_ghosting();
1975}
1976
1977} // namespace libMesh
unsigned int dim
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.
Definition dof_map.h:181
void remove_default_ghosting()
Remove any default ghosting functor(s).
Definition dof_map.C:1990
std::size_t distribute_dofs(MeshBase &)
Distribute dofs on the current mesh.
Definition dof_map.C:951
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
Definition dof_map.C:2203
void add_default_ghosting()
Add the default functor(s) for coupling and algebraic ghosting.
Definition dof_map.C:1998
unsigned int n_dofs(const unsigned int s, const unsigned int var=libMesh::invalid_uint) const
Definition dof_object.h:811
dof_id_type id() const
Definition dof_object.h:833
This is the base class from which all geometric element types are derived.
Definition elem.h:96
bool active() const
Definition elem.h:3079
unsigned int which_neighbor_am_i(const Elem *e) const
This function tells you which neighbor e is.
Definition elem.h:3057
virtual std::vector< unsigned int > nodes_on_side(const unsigned int) const =0
subdomain_id_type subdomain_id() const
Definition elem.h:2712
unsigned int level() const
Definition elem.h:3212
const Node * node_ptr(const unsigned int i) const
Definition elem.h:2637
const Elem * neighbor_ptr(unsigned int i) const
Definition elem.h:2736
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 &parameters)
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...
Definition fe_type.h:197
OrderWrapper order
The approximation order of the element (at 0 p-refinement level).
Definition fe_type.h:203
bool p_refinement
Whether or not the finite elements for this type increase their p refinement level on geometric eleme...
Definition fe_type.h:292
FEFamily family
The type of finite element.
Definition fe_type.h:228
This is the MeshBase class.
Definition mesh_base.h:81
virtual bool is_serial() const
Definition mesh_base.h:357
virtual bool contract()=0
Delete subactive (i.e.
virtual dof_id_type n_elem() const =0
unsigned int spatial_dimension() const
Definition mesh_base.h:2682
const ConstElemRange & active_local_element_stored_range() const
Definition mesh_base.C:1969
const ElemRange & element_stored_range()
Definition mesh_base.C:1954
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.
Definition mesh_base.h:386
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.
Definition node.h:55
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.
Definition parameters.h:349
T & set(const std::string &)
Definition parameters.h:494
Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a pa...
Definition qoi_set.h:46
The StoredRange class defines a contiguous, divisible set of objects.
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition system.h:100
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
Definition system.h:1667
const Variable & variable(unsigned int var) const
Return a constant reference to Variable var.
Definition system.C:2704
const FEType & variable_type(const unsigned int i) const
Definition system.C:2721
virtual void prolong_vectors()
Prolong vectors after the mesh has refined.
Definition system.C:432
virtual void restrict_vectors()
Restrict vectors after the mesh has coarsened.
Definition system.C:374
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Definition system.h:1655
const std::string & variable_name(const unsigned int i) const
Definition system.C:2679
virtual void update()
Update the local values to reflect the solution on neighboring processors.
Definition system.C:498
virtual void reinit_constraints()
Reinitializes the constraints for this system.
Definition system.C:483
unsigned int n_vars() const
Definition system.C:2674
const DofMap & get_dof_map() const
Definition system.h:2417
unsigned int number() const
Definition system.h:2393
This class defines the notion of a variable in the system.
Definition variable.h:51
const std::set< subdomain_id_type > & active_subdomains() const
Definition variable.h:181
bool active_on_subdomain(subdomain_id_type sid) const
Definition variable.h:167
This class defines a vector in LIBMESH_DIM dimensional Real or Complex space.
MeshBase & mesh
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...
Definition int_range.h:153
NumberVectorValue Gradient
libmesh_assert(ctx)
OStreamProxy out
dof_id_type numeric_index_type
Definition id_types.h:99
const RemoteElem * remote_elem
Definition remote_elem.C:57
static constexpr Real TOLERANCE
uint8_t dof_id_type
Definition id_types.h:67
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
uint8_t processor_id_type
Definition id_types.h:104
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...
Definition int_range.h:176