libMesh
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Friends | List of all members
libMesh::EquationSystems Class Reference

This is the EquationSystems class. More...

#include <equation_systems.h>

Inheritance diagram for libMesh::EquationSystems:
[legend]

Public Types

enum  ReadFlags {
  READ_HEADER = 1, READ_DATA = 2, READ_ADDITIONAL_DATA = 4, READ_LEGACY_FORMAT = 8,
  TRY_READ_IFEMS = 16, READ_BASIC_ONLY = 32
}
 Define enumeration to set properties in EquationSystems::read() More...
 
enum  WriteFlags { WRITE_DATA = 1, WRITE_ADDITIONAL_DATA = 2, WRITE_PARALLEL_FILES = 4, WRITE_SERIAL_FILES = 8 }
 Define enumeration to set properties in EquationSystems::write() More...
 

Public Member Functions

 EquationSystems (MeshBase &mesh)
 Constructor. More...
 
virtual ~EquationSystems ()
 Destructor. More...
 
virtual void clear ()
 Restores the data structure to a pristine state. More...
 
virtual void init ()
 Initialize all the systems. More...
 
virtual void reinit ()
 Handle any mesh changes and reinitialize all the systems on the updated mesh. More...
 
virtual void reinit_mesh ()
 Handle the association of a completely new mesh with the EquationSystem and all the Systems assigned to it. More...
 
virtual void enable_default_ghosting (bool enable)
 Enable or disable default ghosting functors on the Mesh and on all Systems. More...
 
void update ()
 Updates local values for all the systems. More...
 
unsigned int n_systems () const
 
bool has_system (std::string_view name) const
 
template<typename T_sys >
const T_sys & get_system (std::string_view name) const
 
template<typename T_sys >
T_sys & get_system (std::string_view name)
 
template<typename T_sys >
const T_sys & get_system (const unsigned int num) const
 
template<typename T_sys >
T_sys & get_system (const unsigned int num)
 
const Systemget_system (std::string_view name) const
 
Systemget_system (std::string_view name)
 
const Systemget_system (const unsigned int num) const
 
Systemget_system (const unsigned int num)
 
virtual Systemadd_system (std::string_view system_type, std::string_view name)
 Add the system of type system_type named name to the systems array. More...
 
template<typename T_sys >
T_sys & add_system (std::string_view name)
 Add the system named name to the systems array. More...
 
unsigned int n_vars () const
 
std::size_t n_dofs () const
 
std::size_t n_active_dofs () const
 
virtual void solve ()
 Call solve on all the individual equation systems. More...
 
virtual void adjoint_solve (const QoISet &qoi_indices=QoISet())
 Call adjoint_solve on all the individual equation systems. More...
 
virtual void sensitivity_solve (const ParameterVector &parameters)
 Call sensitivity_solve on all the individual equation systems. More...
 
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. More...
 
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. More...
 
void build_solution_vector (std::vector< Number > &soln, const std::set< std::string > *system_names=nullptr, bool add_sides=false) const
 Fill the input vector soln with solution values. More...
 
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. More...
 
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. More...
 
void get_solution (std::vector< Number > &soln, std::vector< std::string > &names) const
 Retrieve the solution data for CONSTANT MONOMIALs and/or components of CONSTANT MONOMIAL_VECs. More...
 
void build_elemental_solution_vector (std::vector< Number > &soln, std::vector< std::string > &names) const
 Retrieve the solution data for CONSTANT MONOMIALs and/or components of CONSTANT MONOMIAL_VECs. More...
 
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 entries in the input 'names' vector. More...
 
std::unique_ptr< NumericVector< Number > > build_parallel_elemental_solution_vector (std::vector< std::string > &names) const
 Builds a parallel vector of CONSTANT MONOMIAL and/or components of CONSTANT MONOMIAL_VEC solution values corresponding to the entries in the input 'names' vector. More...
 
void build_discontinuous_solution_vector (std::vector< Number > &soln, const std::set< std::string > *system_names=nullptr, const std::vector< std::string > *var_names=nullptr, bool vertices_only=false, bool add_sides=false) const
 Fill the input vector soln with solution values. More...
 
template<typename InValType = Number>
void read (std::string_view name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
 Read & initialize the systems from disk using the XDR data format. More...
 
template<typename InValType = Number>
void read (std::string_view name, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
 
template<typename InValType = Number>
void read (Xdr &io, std::function< std::unique_ptr< Xdr >()> &local_io_functor, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
 
void write (std::string_view name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
 Write the systems to disk using the XDR data format. More...
 
void write (std::string_view name, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
 
void write (std::ostream name, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
 
void write (Xdr &io, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true, Xdr *const local_io=nullptr) const
 
virtual bool compare (const EquationSystems &other_es, const Real threshold, const bool verbose) const
 
virtual std::string get_info () const
 
void print_info (std::ostream &os=libMesh::out) const
 Prints information about the equation systems, by default to libMesh::out. More...
 
const MeshBaseget_mesh () const
 
MeshBaseget_mesh ()
 
void allgather ()
 Serializes a distributed mesh and its associated degree of freedom numbering for all systems. More...
 
void enable_refine_in_reinit ()
 Calls to reinit() will also do two-step coarsen-then-refine. More...
 
void disable_refine_in_reinit ()
 Calls to reinit() will not try to coarsen or refine the mesh. More...
 
bool refine_in_reinit_flag ()
 
bool reinit_solutions ()
 Handle any mesh changes and project any solutions onto the updated mesh. More...
 
virtual void reinit_systems ()
 Reinitialize all systems on the current mesh. More...
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static bool redundant_added_side (const Elem &elem, unsigned int side)
 
static std::string get_info ()
 Gets a string containing the reference information. More...
 
static void print_info (std::ostream &out_stream=libMesh::out)
 Prints the reference information, by default to libMesh::out. More...
 
static unsigned int n_objects ()
 Prints the number of outstanding (created, but not yet destroyed) objects. More...
 
static void enable_print_counter_info ()
 Methods to enable/disable the reference counter output from print_info() More...
 
static void disable_print_counter_info ()
 

Public Attributes

Parameters parameters
 Data structure holding arbitrary parameters. More...
 

Protected Types

typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 Data structure to log the information. More...
 

Protected Member Functions

void increment_constructor_count (const std::string &name) noexcept
 Increments the construction counter. More...
 
void increment_destructor_count (const std::string &name) noexcept
 Increments the destruction counter. More...
 

Protected Attributes

MeshBase_mesh
 The mesh data structure. More...
 
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
 Data structure holding the systems. More...
 
bool _refine_in_reinit
 Flag for whether to call coarsen/refine in reinit(). More...
 
bool _enable_default_ghosting
 Flag for whether to enable default ghosting on newly added Systems. More...
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 Actually holds the data. More...
 
static Threads::atomic< unsigned int_n_objects
 The number of objects. More...
 
static Threads::spin_mutex _mutex
 Mutual exclusion object to enable thread-safe reference counting. More...
 
static bool _enable_print_counter = true
 Flag to control whether reference count information is printed when print_info is called. More...
 

Private Member Functions

void _add_system_to_nodes_and_elems ()
 This function is used in the implementation of add_system, it loops over the nodes and elements of the Mesh, adding the system to each one. More...
 
void _remove_default_ghosting (unsigned int sys_num)
 This just calls DofMap::remove_default_ghosting() but using a shim lets us forward-declare DofMap. More...
 

Friends

std::ostream & operator<< (std::ostream &os, const EquationSystems &es)
 Same as above, but allows you to also use stream syntax. More...
 

Detailed Description

This is the EquationSystems class.

It is in charge of handling all the various equation systems defined for a MeshBase. It may have multiple systems, which may be active or inactive, so that at different solution stages only a sub-set may be solved for. Also, through the templated access, different types of systems may be handled. Also other features, like flags, parameters, I/O etc are provided.

Author
Benjamin S. Kirk
Date
2002-2007 Manages multiples systems of equations.

Definition at line 68 of file equation_systems.h.

Member Typedef Documentation

◆ Counts

typedef std::map<std::string, std::pair<unsigned int, unsigned int> > libMesh::ReferenceCounter::Counts
protectedinherited

Data structure to log the information.

The log is identified by the class name.

Definition at line 119 of file reference_counter.h.

Member Enumeration Documentation

◆ ReadFlags

Define enumeration to set properties in EquationSystems::read()

Enumerator
READ_HEADER 
READ_DATA 
READ_ADDITIONAL_DATA 
READ_LEGACY_FORMAT 
TRY_READ_IFEMS 
READ_BASIC_ONLY 

Definition at line 77 of file equation_systems.h.

◆ WriteFlags

Define enumeration to set properties in EquationSystems::write()

Enumerator
WRITE_DATA 
WRITE_ADDITIONAL_DATA 
WRITE_PARALLEL_FILES 
WRITE_SERIAL_FILES 

Definition at line 87 of file equation_systems.h.

Constructor & Destructor Documentation

◆ EquationSystems()

libMesh::EquationSystems::EquationSystems ( MeshBase mesh)

Constructor.

Definition at line 52 of file equation_systems.C.

References parameters, libMesh::Real, libMesh::Parameters::set(), and libMesh::TOLERANCE.

52  :
53  ParallelObject (m),
54  _mesh (m),
55  _refine_in_reinit(true),
57 {
58  // Set default parameters
59  this->parameters.set<Real> ("linear solver tolerance") = TOLERANCE * TOLERANCE;
60  this->parameters.set<unsigned int>("linear solver maximum iterations") = 5000;
61 }
ParallelObject(const Parallel::Communicator &comm_in)
Constructor.
bool _enable_default_ghosting
Flag for whether to enable default ghosting on newly added Systems.
static constexpr Real TOLERANCE
MeshBase & _mesh
The mesh data structure.
bool _refine_in_reinit
Flag for whether to call coarsen/refine in reinit().
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
T & set(const std::string &)
Definition: parameters.h:469
Parameters parameters
Data structure holding arbitrary parameters.

◆ ~EquationSystems()

libMesh::EquationSystems::~EquationSystems ( )
virtualdefault

Destructor.

Should be virtual, since the user may want to derive subclasses of EquationSystems.

Member Function Documentation

◆ _add_system_to_nodes_and_elems()

void libMesh::EquationSystems::_add_system_to_nodes_and_elems ( )
private

This function is used in the implementation of add_system, it loops over the nodes and elements of the Mesh, adding the system to each one.

The main reason to separate this part is to avoid coupling this header file to mesh.h, and elem.h.

Definition at line 1741 of file equation_systems.C.

References _mesh.

Referenced by add_system().

1742 {
1743  // All the nodes
1744  for (auto & node : _mesh.node_ptr_range())
1745  node->add_system();
1746 
1747  // All the elements
1748  for (auto & elem : _mesh.element_ptr_range())
1749  elem->add_system();
1750 }
MeshBase & _mesh
The mesh data structure.

◆ _remove_default_ghosting()

void libMesh::EquationSystems::_remove_default_ghosting ( unsigned int  sys_num)
private

This just calls DofMap::remove_default_ghosting() but using a shim lets us forward-declare DofMap.

Definition at line 1752 of file equation_systems.C.

References get_system().

Referenced by add_system().

1753 {
1754  this->get_system(sys_num).get_dof_map().remove_default_ghosting();
1755 }
const T_sys & get_system(std::string_view name) const

◆ add_system() [1/2]

System & libMesh::EquationSystems::add_system ( std::string_view  system_type,
std::string_view  name 
)
virtual

Add the system of type system_type named name to the systems array.

Definition at line 342 of file equation_systems.C.

References _systems, get_system(), and libMesh::Quality::name().

Referenced by assemble_and_solve(), build_system(), main(), libMesh::ErrorVector::plot_error(), read(), TimeSolverTestImplementation< NewmarkSolver >::run_test_with_exact_soln(), setup(), WriteVecAndScalar::setupTests(), SystemsTest::simpleSetup(), MultiEvaluablePredTest::test(), SystemsTest::test100KVariables(), ConstraintOperatorTest::test1DCoarseningNewNodes(), ConstraintOperatorTest::test1DCoarseningOperator(), SystemsTest::test2DProjectVectorFE(), SystemsTest::test3DProjectVectorFE(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), MeshFunctionTest::test_subdomain_id_sets(), EquationSystemsTest::testAddSystem(), SystemsTest::testAssemblyWithDgFemContext(), DofMapTest::testBadElemFECombo(), EquationSystemsTest::testBadVarNames(), SystemsTest::testBlockRestrictedVarNDofs(), SystemsTest::testBoundaryProjectCube(), DofMapTest::testConstraintLoopDetection(), MeshInputTest::testCopyElementSolutionImpl(), MeshInputTest::testCopyElementVectorImpl(), MeshInputTest::testCopyNodalSolutionImpl(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), EquationSystemsTest::testDisableDefaultGhosting(), SystemsTest::testDofCouplingWithVarGroups(), MixedDimensionMeshTest::testDofOrdering(), MixedDimensionRefinedMeshTest::testDofOrdering(), MixedDimensionNonUniformRefinement::testDofOrdering(), MixedDimensionNonUniformRefinementTriangle::testDofOrdering(), MixedDimensionNonUniformRefinement3D::testDofOrdering(), DofMapTest::testDofOwner(), MeshInputTest::testDynaReadPatch(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), EquationSystemsTest::testInit(), MeshAssignTest::testMeshMoveAssign(), PeriodicBCTest::testPeriodicBC(), EquationSystemsTest::testPostInitAddElem(), EquationSystemsTest::testPostInitAddRealSystem(), EquationSystemsTest::testPostInitAddSystem(), SystemsTest::testProjectCube(), SystemsTest::testProjectCubeWithMeshFunction(), MeshInputTest::testProjectionRegression(), SystemsTest::testProjectLine(), SystemsTest::testProjectMatrix1D(), SystemsTest::testProjectMatrix2D(), SystemsTest::testProjectMatrix3D(), SystemsTest::testProjectSquare(), InfFERadialTest::testRefinement(), EquationSystemsTest::testRefineThenReinitPreserveFlags(), EquationSystemsTest::testReinitWithNodeElem(), EquationSystemsTest::testRepartitionThenReinit(), EquationSystemsTest::testSelectivePRefine(), MeshInputTest::testSingleElementImpl(), WriteVecAndScalar::testWriteExodus(), and WriteVecAndScalar::testWriteNemesis().

344 {
345  // If the user already built a system with this name, we'll
346  // trust them and we'll use it. That way they can pre-add
347  // non-standard derived system classes, and if their restart file
348  // has some non-standard sys_type we won't throw an error.
349  if (_systems.count(name))
350  {
351  return this->get_system(name);
352  }
353  // Build a basic System
354  else if (sys_type == "Basic")
355  this->add_system<System> (name);
356 
357  // Build a Newmark system
358  else if (sys_type == "Newmark")
359  this->add_system<NewmarkSystem> (name);
360 
361  // Build an Explicit system
362  else if ((sys_type == "Explicit"))
363  this->add_system<ExplicitSystem> (name);
364 
365  // Build an Implicit system
366  else if ((sys_type == "Implicit") ||
367  (sys_type == "Steady" ))
368  this->add_system<ImplicitSystem> (name);
369 
370  // build a transient implicit linear system
371  else if ((sys_type == "Transient") ||
372  (sys_type == "TransientImplicit") ||
373  (sys_type == "TransientLinearImplicit"))
374  this->add_system<TransientLinearImplicitSystem> (name);
375 
376  // build a transient implicit nonlinear system
377  else if (sys_type == "TransientNonlinearImplicit")
378  this->add_system<TransientNonlinearImplicitSystem> (name);
379 
380  // build a transient explicit system
381  else if (sys_type == "TransientExplicit")
382  this->add_system<TransientExplicitSystem> (name);
383 
384  // build a linear implicit system
385  else if (sys_type == "LinearImplicit")
386  this->add_system<LinearImplicitSystem> (name);
387 
388  // build a nonlinear implicit system
389  else if (sys_type == "NonlinearImplicit")
390  this->add_system<NonlinearImplicitSystem> (name);
391 
392  // build a Reduced Basis Construction system
393  else if (sys_type == "RBConstruction")
394  this->add_system<RBConstruction> (name);
395 
396  // build a transient Reduced Basis Construction system
397  else if (sys_type == "TransientRBConstruction")
398  this->add_system<TransientRBConstruction> (name);
399 
400 #ifdef LIBMESH_HAVE_SLEPC
401  // build an eigen system
402  else if (sys_type == "Eigen")
403  this->add_system<EigenSystem> (name);
404  else if (sys_type == "TransientEigenSystem")
405  this->add_system<TransientEigenSystem> (name);
406 #endif
407 
408 #if defined(LIBMESH_USE_COMPLEX_NUMBERS)
409  // build a frequency system
410  else if (sys_type == "Frequency")
411  this->add_system<FrequencySystem> (name);
412 #endif
413 
414  else
415  libmesh_error_msg("ERROR: Unknown system type: " << sys_type);
416 
417  // Return a reference to the new system
418  //return (*this)(name);
419  return this->get_system(name);
420 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
const T_sys & get_system(std::string_view name) const
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ add_system() [2/2]

template<typename T_sys >
T_sys & libMesh::EquationSystems::add_system ( std::string_view  name)
inline

Add the system named name to the systems array.

Definition at line 669 of file equation_systems.h.

References _add_system_to_nodes_and_elems(), _enable_default_ghosting, _remove_default_ghosting(), _systems, n_systems(), and libMesh::Quality::name().

670 {
671  if (!_systems.count(name))
672  {
673  const unsigned int sys_num = this->n_systems();
674 
675  auto result = _systems.emplace
676  (name, std::make_unique<T_sys>(*this, std::string(name),
677  sys_num));
678 
680  this->_remove_default_ghosting(sys_num);
681 
682  // Tell all the \p DofObject entities to add a system.
684 
685  // Return reference to newly added item
686  auto it = result.first;
687  auto & sys_ptr = it->second;
688  return cast_ref<T_sys &>(*sys_ptr);
689  }
690  else
691  {
692  // We now allow redundant add_system calls, to make it
693  // easier to load data from files for user-derived system
694  // subclasses
695  return this->get_system<T_sys>(name);
696  }
697 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
unsigned int n_systems() const
bool _enable_default_ghosting
Flag for whether to enable default ghosting on newly added Systems.
void _remove_default_ghosting(unsigned int sys_num)
This just calls DofMap::remove_default_ghosting() but using a shim lets us forward-declare DofMap...
void _add_system_to_nodes_and_elems()
This function is used in the implementation of add_system, it loops over the nodes and elements of th...
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ adjoint_solve()

void libMesh::EquationSystems::adjoint_solve ( const QoISet qoi_indices = QoISet())
virtual

Call adjoint_solve on all the individual equation systems.

By default this function solves each system's adjoint once, in the reverse order from that in which they were added. For more sophisticated decoupled problems the user may with to override this behavior in a derived class.

Definition at line 444 of file equation_systems.C.

References get_system(), libMesh::libmesh_assert(), and n_systems().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error().

445 {
446  libmesh_assert (this->n_systems());
447 
448  for (unsigned int i=this->n_systems(); i != 0; --i)
449  this->get_system(i-1).adjoint_solve(qoi_indices);
450 }
unsigned int n_systems() const
const T_sys & get_system(std::string_view name) const
libmesh_assert(ctx)

◆ allgather()

void libMesh::EquationSystems::allgather ( )

Serializes a distributed mesh and its associated degree of freedom numbering for all systems.

Definition at line 271 of file equation_systems.C.

References _mesh, libMesh::MeshBase::allgather(), libMesh::DofMap::distribute_dofs(), libMesh::System::get_dof_map(), get_system(), libMesh::MeshBase::is_serial(), libMesh::make_range(), n_systems(), libMesh::DofMap::prepare_send_list(), and libMesh::System::reinit_constraints().

272 {
273  // A serial mesh means nothing needs to be done
274  if (_mesh.is_serial())
275  return;
276 
277  const unsigned int n_sys = this->n_systems();
278 
279  libmesh_assert_not_equal_to (n_sys, 0);
280 
281  // Gather the mesh
282  _mesh.allgather();
283 
284  // Tell all the \p DofObject entities how many systems
285  // there are.
286  for (auto & node : _mesh.node_ptr_range())
287  node->set_n_systems(n_sys);
288 
289  for (auto & elem : _mesh.element_ptr_range())
290  elem->set_n_systems(n_sys);
291 
292  // And distribute each system's dofs
293  for (auto i : make_range(this->n_systems()))
294  {
295  System & sys = this->get_system(i);
296  DofMap & dof_map = sys.get_dof_map();
297  dof_map.distribute_dofs(_mesh);
298 
299  // The user probably won't need constraint equations or the
300  // send_list after an allgather, but let's keep it in consistent
301  // shape just in case.
302  sys.reinit_constraints();
303  dof_map.prepare_send_list();
304  }
305 }
unsigned int n_systems() const
virtual void allgather()
Gathers all elements and nodes of the mesh onto every processor.
Definition: mesh_base.h:234
const T_sys & get_system(std::string_view name) const
MeshBase & _mesh
The mesh data structure.
virtual bool is_serial() const
Definition: mesh_base.h:205
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:134

◆ build_discontinuous_solution_vector()

void libMesh::EquationSystems::build_discontinuous_solution_vector ( std::vector< Number > &  soln,
const std::set< std::string > *  system_names = nullptr,
const std::vector< std::string > *  var_names = nullptr,
bool  vertices_only = false,
bool  add_sides = false 
) const

Fill the input vector soln with solution values.

The entries will be in variable-major format (corresponding to the names from build_variable_names()).

If systems_names!=nullptr, only include data from the specified systems.

If vertices_only == true, then for higher-order elements only the solution at the vertices is computed. This can be useful when plotting discontinuous solutions on higher-order elements and only a lower-order representation is required.

If add_sides == true, append data for plotting on "side elements" too.

Definition at line 1263 of file equation_systems.C.

References libMesh::Variable::active_on_subdomain(), libMesh::DISCONTINUOUS, libMesh::FEInterface::get_continuity(), libMesh::H_CURL, libMesh::index_range(), libMesh::Elem::level(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::Elem::neighbor_ptr(), libMesh::FEInterface::nodal_soln(), libMesh::Elem::node_ptr(), libMesh::Elem::nodes_on_side(), libMesh::FEInterface::side_nodal_soln(), libMesh::Elem::subdomain_id(), and libMesh::Elem::which_neighbor_am_i().

Referenced by libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems(), libMesh::ExodusII_IO::write_discontinuous_exodusII(), libMesh::GMVIO::write_discontinuous_gmv(), and libMesh::ExodusII_IO::write_element_data_from_discontinuous_nodal_data().

1268 {
1269  LOG_SCOPE("build_discontinuous_solution_vector()", "EquationSystems");
1270 
1271  libmesh_assert (this->n_systems());
1272 
1273  // Get the number of variables (nv) by counting the number of variables
1274  // in each system listed in system_names
1275  unsigned int nv = 0;
1276 
1277  for (const auto & [sys_name, sys_ptr] : _systems)
1278  {
1279  // Check current system is listed in system_names, and skip pos if not
1280  bool use_current_system = (system_names == nullptr);
1281  if (!use_current_system)
1282  use_current_system = system_names->count(sys_name);
1283  if (!use_current_system || sys_ptr->hide_output())
1284  continue;
1285 
1286  // Loop over all variables in this System and check whether we
1287  // are supposed to use each one.
1288  for (auto var_id : make_range(sys_ptr->n_vars()))
1289  {
1290  bool use_current_var = (var_names == nullptr);
1291  if (!use_current_var)
1292  use_current_var = std::count(var_names->begin(),
1293  var_names->end(),
1294  sys_ptr->variable_name(var_id));
1295 
1296  // Only increment the total number of vars if we are
1297  // supposed to use this one.
1298  if (use_current_var)
1299  nv++;
1300  }
1301  }
1302 
1303  // get the total "weight" - the number of nodal values to write for
1304  // each variable.
1305  unsigned int tw=0;
1306  for (const auto & elem : _mesh.active_element_ptr_range())
1307  {
1308  tw += vertices_only ? elem->n_vertices() : elem->n_nodes();
1309 
1310  if (add_sides)
1311  {
1312  for (auto s : elem->side_index_range())
1313  {
1314  if (redundant_added_side(*elem,s))
1315  continue;
1316 
1317  const std::vector<unsigned int> side_nodes =
1318  elem->nodes_on_side(s);
1319 
1320  if (!vertices_only)
1321  tw += side_nodes.size();
1322  else
1323  for (auto n : index_range(side_nodes))
1324  if (elem->is_vertex(side_nodes[n]))
1325  ++tw;
1326  }
1327  }
1328  }
1329 
1330  // Only if we are on processor zero, allocate the storage
1331  // to hold (number_of_nodes)*(number_of_variables) entries.
1332  if (_mesh.processor_id() == 0)
1333  soln.resize(tw*nv);
1334 
1335  std::vector<Number> sys_soln;
1336 
1337  // Keep track of the variable "offset". This is used for indexing
1338  // into the global solution vector.
1339  unsigned int var_offset = 0;
1340 
1341  // For each system in this EquationSystems object,
1342  // update the global solution and if we are on processor 0,
1343  // loop over the elements and build the nodal solution
1344  // from the element solution. Then insert this nodal solution
1345  // into the vector passed to build_solution_vector.
1346  for (const auto & [sys_name, system] : _systems)
1347  {
1348  // Check current system is listed in system_names, and skip pos if not
1349  bool use_current_system = (system_names == nullptr);
1350  if (!use_current_system)
1351  use_current_system = system_names->count(sys_name);
1352  if (!use_current_system || system->hide_output())
1353  continue;
1354 
1355  const unsigned int nv_sys = system->n_vars();
1356  const auto & dof_map = system->get_dof_map();
1357 
1358  system->update_global_solution (sys_soln, 0);
1359 
1360  // Keep track of the number of vars actually written.
1361  unsigned int n_vars_written_current_system = 0;
1362 
1363  if (_mesh.processor_id() == 0)
1364  {
1365  std::vector<Number> soln_coeffs; // The finite element solution coeffs
1366  std::vector<Number> nodal_soln; // The FE solution interpolated to the nodes
1367  std::vector<dof_id_type> dof_indices; // The DOF indices for the finite element
1368 
1369  // For each variable, determine if we are supposed to
1370  // write it, then loop over the active elements, compute
1371  // the nodal_soln and store it to the "soln" vector. We
1372  // store zeros for subdomain-restricted variables on
1373  // elements where they are not active.
1374  for (unsigned int var=0; var<nv_sys; var++)
1375  {
1376  bool use_current_var = (var_names == nullptr);
1377  if (!use_current_var)
1378  use_current_var = std::count(var_names->begin(),
1379  var_names->end(),
1380  system->variable_name(var));
1381 
1382  // If we aren't supposed to write this var, go to the
1383  // next loop iteration.
1384  if (!use_current_var)
1385  continue;
1386 
1387  const FEType & fe_type = system->variable_type(var);
1388  const Variable & var_description = system->variable(var);
1389  const auto vg = dof_map.var_group_from_var_number(var);
1390  const bool add_p_level = dof_map.should_p_refine(vg);
1391 
1392  unsigned int nn=0;
1393 
1394  for (auto & elem : _mesh.active_element_ptr_range())
1395  {
1396  if (var_description.active_on_subdomain(elem->subdomain_id()))
1397  {
1398  system->get_dof_map().dof_indices (elem, dof_indices, var);
1399 
1400  soln_coeffs.resize(dof_indices.size());
1401 
1402  for (auto i : index_range(dof_indices))
1403  soln_coeffs[i] = sys_soln[dof_indices[i]];
1404 
1405  // Compute the FE solution at all the nodes, but
1406  // only use the first n_vertices() entries if
1407  // vertices_only == true.
1408  FEInterface::nodal_soln (elem->dim(),
1409  fe_type,
1410  elem,
1411  soln_coeffs,
1412  nodal_soln,
1413  add_p_level);
1414 
1415  // infinite elements should be skipped...
1416  if (!elem->infinite())
1417  {
1418  libmesh_assert_equal_to (nodal_soln.size(), elem->n_nodes());
1419 
1420  const unsigned int n_vals =
1421  vertices_only ? elem->n_vertices() : elem->n_nodes();
1422 
1423  for (unsigned int n=0; n<n_vals; n++)
1424  {
1425  // Compute index into global solution vector.
1426  std::size_t index =
1427  nv * (nn++) + (n_vars_written_current_system + var_offset);
1428 
1429  soln[index] += nodal_soln[n];
1430  }
1431  }
1432  }
1433  else
1434  nn += vertices_only ? elem->n_vertices() : elem->n_nodes();
1435  } // end loop over active elements writing interiors
1436 
1437  // Loop writing "fake" sides, if requested
1438  if (add_sides)
1439  {
1440  // We don't build discontinuous solution vectors in
1441  // parallel yet, but we'll do ordering of fake side
1442  // values as if we did, for consistency with the
1443  // parallel continuous ordering and for future
1444  // compatibility.
1445  std::vector<std::vector<const Elem *>>
1446  elems_by_pid(_mesh.n_processors());
1447 
1448  for (const auto & elem : _mesh.active_element_ptr_range())
1449  elems_by_pid[elem->processor_id()].push_back(elem);
1450 
1451  for (auto p : index_range(elems_by_pid))
1452  for (const Elem * elem : elems_by_pid[p])
1453  {
1454  if (var_description.active_on_subdomain(elem->subdomain_id()))
1455  {
1456  system->get_dof_map().dof_indices (elem, dof_indices, var);
1457 
1458  soln_coeffs.resize(dof_indices.size());
1459 
1460  for (auto i : index_range(dof_indices))
1461  soln_coeffs[i] = sys_soln[dof_indices[i]];
1462 
1463  for (auto s : elem->side_index_range())
1464  {
1465  if (redundant_added_side(*elem,s))
1466  continue;
1467 
1468  const std::vector<unsigned int> side_nodes =
1469  elem->nodes_on_side(s);
1470 
1471  // Compute the FE solution at all the
1472  // side nodes, but only use those for
1473  // which is_vertex() == true if
1474  // vertices_only == true.
1476  (fe_type, elem, s, soln_coeffs,
1477  nodal_soln, add_p_level);
1478 
1479  libmesh_assert_equal_to
1480  (nodal_soln.size(),
1481  side_nodes.size());
1482 
1483  // If we don't have a continuous FE
1484  // then we want to average between
1485  // sides, at least in the equal-level
1486  // case where it's easy. This is
1487  // analogous to our repeat_count
1488  // behavior elsewhere.
1489  const FEContinuity cont =
1490  FEInterface::get_continuity(fe_type);
1491  const Elem * const neigh = elem->neighbor_ptr(s);
1492 
1493  if ((cont == DISCONTINUOUS || cont == H_CURL) &&
1494  neigh &&
1495  neigh->level() == elem->level() &&
1496  var_description.active_on_subdomain(neigh->subdomain_id()))
1497  {
1498  std::vector<dof_id_type> neigh_indices;
1499  system->get_dof_map().dof_indices (neigh, neigh_indices, var);
1500  std::vector<Number> neigh_coeffs(neigh_indices.size());
1501 
1502  for (auto i : index_range(neigh_indices))
1503  neigh_coeffs[i] = sys_soln[neigh_indices[i]];
1504 
1505  const unsigned int s_neigh =
1506  neigh->which_neighbor_am_i(elem);
1507  std::vector<Number> neigh_soln;
1509  (fe_type, neigh, s_neigh,
1510  neigh_coeffs, neigh_soln, add_p_level);
1511 
1512  const std::vector<unsigned int> neigh_nodes =
1513  neigh->nodes_on_side(s_neigh);
1514  for (auto n : index_range(side_nodes))
1515  for (auto neigh_n : index_range(neigh_nodes))
1516  if (neigh->node_ptr(neigh_nodes[neigh_n])
1517  == elem->node_ptr(side_nodes[n]))
1518  {
1519  nodal_soln[n] += neigh_soln[neigh_n];
1520  nodal_soln[n] /= 2;
1521  }
1522  }
1523 
1524  for (auto n : index_range(side_nodes))
1525  {
1526  if (vertices_only &&
1527  !elem->is_vertex(n))
1528  continue;
1529 
1530  // Compute index into global solution vector.
1531  std::size_t index =
1532  nv * (nn++) + (n_vars_written_current_system + var_offset);
1533 
1534  soln[index] += nodal_soln[n];
1535  }
1536  }
1537  }
1538  else
1539  {
1540  nn += vertices_only ? elem->n_vertices() : elem->n_nodes();
1541 
1542  for (auto s : elem->side_index_range())
1543  {
1544  if (redundant_added_side(*elem,s))
1545  continue;
1546 
1547  const std::vector<unsigned int> side_nodes =
1548  elem->nodes_on_side(s);
1549 
1550  for (auto n : index_range(side_nodes))
1551  {
1552  if (vertices_only &&
1553  !elem->is_vertex(n))
1554  continue;
1555  nn++;
1556  }
1557  }
1558  }
1559  } // end loop over active elements, writing "fake" sides
1560  }
1561  // If we made it here, we actually wrote a variable, so increment
1562  // the number of variables actually written for the current system.
1563  n_vars_written_current_system++;
1564 
1565  } // end loop over vars
1566  } // end if proc 0
1567 
1568  // Update offset for next loop iteration.
1569  var_offset += n_vars_written_current_system;
1570  } // end loop over systems
1571 }
unsigned int n_systems() const
MeshBase & _mesh
The mesh data structure.
processor_id_type n_processors() const
libmesh_assert(ctx)
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, bool add_p_level=true)
Build the nodal soln from the element soln.
Definition: fe_interface.C:868
static FEContinuity get_continuity(const FEType &fe_type)
Returns the input FEType&#39;s FEContinuity based on the underlying FEFamily and potentially the Order...
FEContinuity
defines an enum for finite element types to libmesh_assert a certain level (or type? Hcurl?) of continuity.
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:134
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, bool add_p_level=true)
Build the nodal soln on one side from the (full) element soln.
Definition: fe_interface.C:892
processor_id_type processor_id() const
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:111
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.
static bool redundant_added_side(const Elem &elem, unsigned int side)

◆ build_elemental_solution_vector()

void libMesh::EquationSystems::build_elemental_solution_vector ( std::vector< Number > &  soln,
std::vector< std::string > &  names 
) const

Retrieve the solution data for CONSTANT MONOMIALs and/or components of CONSTANT MONOMIAL_VECs.

If 'names' is populated, only the variables corresponding to those names will be retrieved. This can be used to filter which variables are retrieved.

This is the more appropriately-named replacement for the get_solution() function defined above.

Definition at line 1028 of file equation_systems.C.

References build_parallel_elemental_solution_vector().

Referenced by get_solution(), and libMesh::ExodusII_IO::write_element_data().

1030 {
1031  // Call the parallel version of this function
1032  std::unique_ptr<NumericVector<Number>> parallel_soln =
1034 
1035  // Localize into 'soln', provided that parallel_soln is not empty.
1036  // Note: parallel_soln will be empty in the event that none of the
1037  // input names were CONSTANT, MONOMIAL nor components of CONSTANT,
1038  // MONOMIAL_VEC variables, or there were simply none of these in
1039  // the EquationSystems object.
1040  soln.clear();
1041  if (parallel_soln)
1042  parallel_soln->localize_to_one(soln);
1043 }
std::unique_ptr< NumericVector< Number > > build_parallel_elemental_solution_vector(std::vector< std::string > &names) const
Builds a parallel vector of CONSTANT MONOMIAL and/or components of CONSTANT MONOMIAL_VEC solution val...

◆ build_parallel_elemental_solution_vector()

std::unique_ptr< NumericVector< Number > > libMesh::EquationSystems::build_parallel_elemental_solution_vector ( std::vector< std::string > &  names) const

Builds a parallel vector of CONSTANT MONOMIAL and/or components of CONSTANT MONOMIAL_VEC solution values corresponding to the entries in the input 'names' vector.

This vector is approximately uniformly distributed across all of the available processors.

The related function build_elemental_solution_vector() is implemented by calling this function and then calling localize_to_one() on the resulting vector.

Returns a nullptr if no CONSTANT, MONOMIAL/MONOMIAL_VEC variables exist in the 'names' vector (if it is empty, then it will return all variables in the system of this type if any) or a std::unique_ptr to a var-major numeric vector of total length n_elem * n_vars, where n_vars includes all components of vectors, ordered according to: [u0, u1, ... uN, v0, v1, ... vN, w0, w1, ... wN] for constant monomial variables (u, v, w) on a mesh with N elements.

Definition at line 1152 of file equation_systems.C.

References libMesh::ParallelObject::_communicator, _mesh, libMesh::Variable::active_on_subdomain(), libMesh::NumericVector< T >::build(), libMesh::NumericVector< T >::close(), libMesh::ParallelObject::comm(), libMesh::CONSTANT, libMesh::System::current_local_solution, libMesh::DofMap::dof_indices(), find_variable_numbers(), libMesh::System::get_dof_map(), get_system(), libMesh::index_range(), libMesh::NumericVector< T >::init(), libMesh::libmesh_assert(), libMesh::MeshBase::max_elem_id(), libMesh::MeshBase::mesh_dimension(), libMesh::MONOMIAL, libMesh::MONOMIAL_VEC, libMesh::MeshBase::n_elem(), libMesh::ParallelObject::n_processors(), libMesh::PARALLEL, libMesh::ParallelObject::processor_id(), libMesh::NumericVector< T >::set(), libMesh::System::solution, libMesh::System::update(), libMesh::System::variable(), and libMesh::System::variable_type().

Referenced by build_elemental_solution_vector().

1153 {
1154  // Filter any names that aren't elemental variables and get the system indices for those that are.
1155  // Note that it's probably fine if the names vector is empty since we'll still at least filter
1156  // out all non-monomials. If there are no monomials, then nothing is output here.
1157  std::vector<FEType> type = {FEType(CONSTANT, MONOMIAL), FEType(CONSTANT, MONOMIAL_VEC)};
1158  std::vector<std::pair<unsigned int, unsigned int>> var_nums =
1159  this->find_variable_numbers(names, /*type=*/nullptr, &type);
1160 
1161  const std::size_t nv = names.size(); /*total number of vars including vector components*/
1162  const dof_id_type ne = _mesh.n_elem();
1163  libmesh_assert_equal_to (ne, _mesh.max_elem_id());
1164 
1165  // If there are no variables to write out don't do anything...
1166  if (!nv)
1167  return std::unique_ptr<NumericVector<Number>>(nullptr);
1168 
1169  // We can handle the case where there are nullptrs in the Elem vector
1170  // by just having extra zeros in the solution vector.
1171  numeric_index_type parallel_soln_global_size = ne*nv;
1172 
1173  numeric_index_type div = parallel_soln_global_size / this->n_processors();
1174  numeric_index_type mod = parallel_soln_global_size % this->n_processors();
1175 
1176  // Initialize all processors to the average size.
1177  numeric_index_type parallel_soln_local_size = div;
1178 
1179  // The first "mod" processors get an extra entry.
1180  if (this->processor_id() < mod)
1181  parallel_soln_local_size = div+1;
1182 
1183  // Create a NumericVector to hold the parallel solution
1184  std::unique_ptr<NumericVector<Number>> parallel_soln_ptr = NumericVector<Number>::build(_communicator);
1185  NumericVector<Number> & parallel_soln = *parallel_soln_ptr;
1186  parallel_soln.init(parallel_soln_global_size,
1187  parallel_soln_local_size,
1188  /*fast=*/false,
1189  /*ParallelType=*/PARALLEL);
1190 
1191  unsigned int sys_ctr = 0;
1192  unsigned int var_ctr = 0;
1193  for (auto i : index_range(var_nums))
1194  {
1195  std::pair<unsigned int, unsigned int> var_num = var_nums[i];
1196  const System & system = this->get_system(var_num.first);
1197 
1198  // Update the current_local_solution if necessary
1199  if (sys_ctr != var_num.first)
1200  {
1201  System & non_const_sys = const_cast<System &>(system);
1202  // We used to simply call non_const_sys.solution->close()
1203  // here, but that is not allowed when the solution vector is
1204  // locked read-only, for example when printing the solution
1205  // during during the middle of a solve... So try to be a bit
1206  // more careful about calling close() unnecessarily.
1207  libmesh_assert(this->comm().verify(non_const_sys.solution->closed()));
1208  if (!non_const_sys.solution->closed())
1209  non_const_sys.solution->close();
1210  non_const_sys.update();
1211  sys_ctr = var_num.first;
1212  }
1213 
1214  NumericVector<Number> & sys_soln(*system.current_local_solution);
1215 
1216  // The DOF indices for the finite element
1217  std::vector<dof_id_type> dof_indices;
1218 
1219  const unsigned int var = var_num.second;
1220 
1221  const Variable & variable = system.variable(var);
1222  const DofMap & dof_map = system.get_dof_map();
1223 
1224  // We need to check if the constant monomial is a scalar or a vector and set the number of
1225  // components as the mesh dimension for the latter case as per 'find_variable_numbers()'.
1226  // Even for the case where a variable is not active on any subdomain belonging to the
1227  // processor, we still need to know this number to update 'var_ctr'.
1228  const unsigned int n_comps =
1229  (system.variable_type(var) == type[1]) ? _mesh.mesh_dimension() : 1;
1230 
1231  // Loop over all elements in the mesh and index all components of the variable if it's active
1232  for (const auto & elem : _mesh.active_local_element_ptr_range())
1233  if (variable.active_on_subdomain(elem->subdomain_id()))
1234  {
1235  dof_map.dof_indices(elem, dof_indices, var);
1236 
1237  // The number of DOF components needs to be equal to the expected number so that we know
1238  // where to store data to correctly correspond to variable names.
1239  libmesh_assert_equal_to(dof_indices.size(), n_comps);
1240 
1241  for (unsigned int comp = 0; comp < n_comps; comp++)
1242  parallel_soln.set(ne * (var_ctr + comp) + elem->id(), sys_soln(dof_indices[comp]));
1243  }
1244 
1245  var_ctr += n_comps;
1246  } // end loop over var_nums
1247 
1248  // NOTE: number of output names might not be equal to the number passed to this function. Any that
1249  // aren't CONSTANT MONOMIALS or components of CONSTANT MONOMIAL_VECS have been filtered out (see
1250  // EquationSystems::find_variable_numbers).
1251  //
1252  // But, if everything is accounted for properly, then names.size() == var_ctr
1253  libmesh_assert_equal_to(names.size(), var_ctr);
1254 
1255  parallel_soln.close();
1256  return parallel_soln_ptr;
1257 }
const Parallel::Communicator & comm() const
const Parallel::Communicator & _communicator
const T_sys & get_system(std::string_view name) const
MeshBase & _mesh
The mesh data structure.
processor_id_type n_processors() const
dof_id_type numeric_index_type
Definition: id_types.h:99
virtual dof_id_type max_elem_id() const =0
libmesh_assert(ctx)
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
unsigned int mesh_dimension() const
Definition: mesh_base.C:324
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 &#39;type&#39; or of &#39;types&#39; corresponding to the entr...
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const
template class LIBMESH_EXPORT NumericVector< Number >
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:111
uint8_t dof_id_type
Definition: id_types.h:67

◆ build_parallel_solution_vector()

std::unique_ptr< NumericVector< Number > > libMesh::EquationSystems::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.

Returns
A std::unique_ptr to a node-major NumericVector of total length n_nodes*n_vars that various I/O classes can then use to get the local values they need to write on each processor.

Definition at line 585 of file equation_systems.C.

References libMesh::ParallelObject::_communicator, _mesh, _systems, std::abs(), libMesh::Variable::active_on_subdomain(), libMesh::NumericVector< T >::add(), TIMPI::Communicator::allgather(), libMesh::NumericVector< T >::build(), libMesh::NumericVector< T >::close(), libMesh::ParallelObject::comm(), libMesh::System::current_local_solution, dim, distance(), libMesh::DofMap::dof_indices(), libMesh::FEInterface::field_type(), libMesh::NumericVector< T >::first_local_index(), libMesh::NumericVector< T >::get(), libMesh::System::get_dof_map(), libMesh::DofObject::id(), libMesh::index_range(), libMesh::NumericVector< T >::init(), libMesh::NumericVector< T >::last_local_index(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::MeshBase::max_node_id(), libMesh::MeshBase::mesh_dimension(), libMesh::DofObject::n_dofs(), libMesh::System::n_vars(), libMesh::FEInterface::n_vec_dim(), libMesh::FEInterface::nodal_soln(), libMesh::System::number(), libMesh::PARALLEL, libMesh::ParallelObject::processor_id(), TIMPI::Communicator::rank(), redundant_added_side(), libMesh::NumericVector< T >::set(), libMesh::DofMap::should_p_refine(), libMesh::FEInterface::side_nodal_soln(), TIMPI::Communicator::size(), libMesh::System::solution, TIMPI::Communicator::sum(), libMesh::TOLERANCE, libMesh::TYPE_VECTOR, libMesh::System::update(), libMesh::DofMap::var_group_from_var_number(), libMesh::System::variable(), and libMesh::System::variable_type().

Referenced by build_solution_vector(), and libMesh::MeshOutput< MeshBase >::write_nodal_data().

587 {
588  LOG_SCOPE("build_parallel_solution_vector()", "EquationSystems");
589 
590  // This function must be run on all processors at once
591  parallel_object_only();
592 
593  const unsigned int dim = _mesh.mesh_dimension();
594  const dof_id_type max_nn = _mesh.max_node_id();
595 
596  // allocate vector storage to hold
597  // (max_node_id)*(number_of_variables) entries.
598  //
599  // If node renumbering is disabled and adaptive coarsening has
600  // created gaps between node numbers, then this vector will be
601  // sparse.
602  //
603  // We have to differentiate between between scalar and vector
604  // variables. We intercept vector variables and treat each
605  // component as a scalar variable (consistently with build_solution_names).
606 
607  unsigned int nv = 0;
608 
609  //Could this be replaced by a/some convenience methods?[PB]
610  {
611  unsigned int n_scalar_vars = 0;
612  unsigned int n_vector_vars = 0;
613  for (const auto & [sys_name, sys_ptr] : _systems)
614  {
615  // Check current system is listed in system_names, and skip pos if not
616  bool use_current_system = (system_names == nullptr);
617  if (!use_current_system)
618  use_current_system = system_names->count(sys_name);
619  if (!use_current_system || sys_ptr->hide_output())
620  continue;
621 
622  for (auto vn : make_range(sys_ptr->n_vars()))
623  {
624  if (FEInterface::field_type(sys_ptr->variable_type(vn)) == TYPE_VECTOR)
625  n_vector_vars++;
626  else
627  n_scalar_vars++;
628  }
629  }
630  // Here, we're assuming the number of vector components is the same
631  // as the mesh dimension. Will break for mixed dimension meshes.
632  nv = n_scalar_vars + dim*n_vector_vars;
633  }
634 
635  // Get the number of nodes to store locally.
636  dof_id_type n_local_nodes = cast_int<dof_id_type>
637  (std::distance(_mesh.local_nodes_begin(),
638  _mesh.local_nodes_end()));
639 
640  // If node renumbering has been disabled, nodes may not be numbered
641  // contiguously, and the number of nodes might not match the
642  // max_node_id. In this case we just do our best.
643  dof_id_type n_total_nodes = n_local_nodes;
644  _mesh.comm().sum(n_total_nodes);
645 
646  const processor_id_type n_proc = _mesh.comm().size();
647  const processor_id_type my_pid = _mesh.comm().rank();
648  const dof_id_type n_gaps = max_nn - n_total_nodes;
649  const dof_id_type gaps_per_processor = n_gaps / n_proc;
650  const dof_id_type remainder_gaps = n_gaps % n_proc;
651 
652  n_local_nodes = n_local_nodes + // Actual nodes
653  gaps_per_processor + // Our even share of gaps
654  (my_pid < remainder_gaps); // Leftovers
655 
656  // If we've been asked to build added sides' data, we need space to
657  // add it. Keep track of how much space.
658  dof_id_type local_added_side_nodes = 0,
659  added_side_nodes = 0;
660 
661  // others_added_side_nodes[p]: local_added_side_nodes on rank p
662  std::vector<dof_id_type> others_added_side_nodes;
663 
664  // A map of (element_id, side, side_node) pairs to the corresponding
665  // added side node index.
666  std::map<std::tuple<dof_id_type, unsigned short, unsigned short>,
667  dof_id_type> discontinuous_node_indices;
668 
669  // If we don't have any added side nodes, we'll have no offsets from
670  // them, and we won't care about which offsets apply to which node
671  // ids either.
672 
673  // Number of true nodes on processors [0,p]
674  std::vector<dof_id_type> true_node_offsets;
675  // Number of added (fake) nodes on processors [0,p)
676  std::vector<dof_id_type> added_node_offsets;
677 
678  auto node_id_to_vec_id =
679  [&true_node_offsets, &added_node_offsets]
680  (const dof_id_type node_id)
681  {
682  if (true_node_offsets.empty())
683  return node_id; // O(1) in the common !add_sides case
684 
685  // Find the processor id that has node_id in the parallel vec
686  const auto lb = std::upper_bound(true_node_offsets.begin(),
687  true_node_offsets.end(), node_id);
688  libmesh_assert(lb != true_node_offsets.end());
689  const processor_id_type p = lb - true_node_offsets.begin();
690 
691  return node_id + added_node_offsets[p];
692  };
693 
694  if (add_sides)
695  {
696  true_node_offsets.resize(n_proc);
697  added_node_offsets.resize(n_proc);
698 
699  // One loop to count everyone's new side nodes
700  for (const auto & elem : _mesh.active_element_ptr_range())
701  {
702  for (auto s : elem->side_index_range())
703  {
704  if (redundant_added_side(*elem,s))
705  continue;
706 
707  const std::vector<unsigned int> side_nodes =
708  elem->nodes_on_side(s);
709 
710  if (elem->processor_id() == this->processor_id())
711  local_added_side_nodes += side_nodes.size();
712  }
713  }
714 
715  others_added_side_nodes.resize(n_proc);
716  _mesh.comm().allgather(local_added_side_nodes,
717  others_added_side_nodes);
718 
719  added_side_nodes = std::accumulate(others_added_side_nodes.begin(),
720  others_added_side_nodes.end(), 0,
721  std::plus<>());
722 
723  _mesh.comm().allgather(n_local_nodes, true_node_offsets);
724  for (auto p : make_range(n_proc-1))
725  true_node_offsets[p+1] += true_node_offsets[p];
726  libmesh_assert_equal_to(true_node_offsets[n_proc-1], _mesh.max_node_id());
727 
728  // For nodes that exist in the mesh, we just need an offset to
729  // tell where to put their solutions.
730  added_node_offsets[0] = 0;
731  for (auto p : make_range(n_proc-1))
732  added_node_offsets[p+1] =
733  added_node_offsets[p] + others_added_side_nodes[p];
734 
735  // For added side nodes, we need to fill a map. Start after all
736  // the true node for our pid plus all the side nodes for
737  // previous pids
738  dof_id_type node_counter = true_node_offsets[my_pid];
739  for (auto p : make_range(my_pid))
740  node_counter += others_added_side_nodes[p];
741 
742  // One loop to figure out whose added side nodes get which index
743  for (const auto & elem : _mesh.active_local_element_ptr_range())
744  {
745  for (auto s : elem->side_index_range())
746  {
747  if (redundant_added_side(*elem,s))
748  continue;
749 
750  const std::vector<unsigned int> side_nodes =
751  elem->nodes_on_side(s);
752 
753  for (auto n : index_range(side_nodes))
754  discontinuous_node_indices
755  [std::make_tuple(elem->id(),s,n)] = node_counter++;
756  }
757  }
758  }
759 
760  const dof_id_type
761  n_global_vals = (max_nn + added_side_nodes) * nv,
762  n_local_vals = (n_local_nodes + local_added_side_nodes) * nv;
763 
764  // Create a NumericVector to hold the parallel solution
765  std::unique_ptr<NumericVector<Number>> parallel_soln_ptr = NumericVector<Number>::build(_communicator);
766  NumericVector<Number> & parallel_soln = *parallel_soln_ptr;
767  parallel_soln.init(n_global_vals, n_local_vals, false, PARALLEL);
768 
769  // Create a NumericVector to hold the "repeat_count" for each node - this is essentially
770  // the number of elements contributing to that node's value
771  std::unique_ptr<NumericVector<Number>> repeat_count_ptr = NumericVector<Number>::build(_communicator);
772  NumericVector<Number> & repeat_count = *repeat_count_ptr;
773  repeat_count.init(n_global_vals, n_local_vals, false, PARALLEL);
774 
775  repeat_count.close();
776 
777  unsigned int var_num=0;
778 
779  // For each system in this EquationSystems object,
780  // update the global solution and if we are on processor 0,
781  // loop over the elements and build the nodal solution
782  // from the element solution. Then insert this nodal solution
783  // into the vector passed to build_solution_vector.
784  for (const auto & [sys_name, sys_ptr] : _systems)
785  {
786  // Check current system is listed in system_names, and skip pos if not
787  bool use_current_system = (system_names == nullptr);
788  if (!use_current_system)
789  use_current_system = system_names->count(sys_name);
790  if (!use_current_system || sys_ptr->hide_output())
791  continue;
792 
793  const System & system = *sys_ptr;
794  const unsigned int nv_sys = system.n_vars();
795  const unsigned int sys_num = system.number();
796 
797  //Could this be replaced by a/some convenience methods?[PB]
798  unsigned int n_scalar_vars = 0;
799  unsigned int n_vector_vars = 0;
800  for (auto vn : make_range(sys_ptr->n_vars()))
801  {
802  if (FEInterface::field_type(sys_ptr->variable_type(vn)) == TYPE_VECTOR)
803  n_vector_vars++;
804  else
805  n_scalar_vars++;
806  }
807 
808  // Here, we're assuming the number of vector components is the same
809  // as the mesh dimension. Will break for mixed dimension meshes.
810  unsigned int nv_sys_split = n_scalar_vars + dim*n_vector_vars;
811 
812  // Update the current_local_solution
813  {
814  System & non_const_sys = const_cast<System &>(system);
815  // We used to simply call non_const_sys.solution->close()
816  // here, but that is not allowed when the solution vector is
817  // locked read-only, for example when printing the solution
818  // during the middle of a solve... So try to be a bit
819  // more careful about calling close() unnecessarily.
820  libmesh_assert(this->comm().verify(non_const_sys.solution->closed()));
821  if (!non_const_sys.solution->closed())
822  non_const_sys.solution->close();
823  non_const_sys.update();
824  }
825 
826  NumericVector<Number> & sys_soln(*system.current_local_solution);
827 
828  const DofMap & dof_map = system.get_dof_map();
829 
830  std::vector<Number> elem_soln; // The finite element solution
831  std::vector<Number> nodal_soln; // The FE solution interpolated to the nodes
832  std::vector<dof_id_type> dof_indices; // The DOF indices for the finite element
833 
834  unsigned var_inc = 0;
835  for (unsigned int var=0; var<nv_sys; var++)
836  {
837  const FEType & fe_type = system.variable_type(var);
838  const Variable & var_description = system.variable(var);
839  unsigned int n_vec_dim = FEInterface::n_vec_dim( sys_ptr->get_mesh(), fe_type );
840  const auto vg = dof_map.var_group_from_var_number(var);
841  const bool add_p_level = dof_map.should_p_refine(vg);
842 
843  for (const auto & elem : _mesh.active_local_element_ptr_range())
844  {
845  if (var_description.active_on_subdomain(elem->subdomain_id()))
846  {
847  dof_map.dof_indices (elem, dof_indices, var);
848  sys_soln.get(dof_indices, elem_soln);
849 
850  FEInterface::nodal_soln (elem->dim(),
851  fe_type,
852  elem,
853  elem_soln,
854  nodal_soln,
855  add_p_level);
856 
857  // infinite elements should be skipped...
858  if (!elem->infinite())
859  {
860  libmesh_assert_equal_to (nodal_soln.size(), n_vec_dim*elem->n_nodes());
861 
862  for (auto n : elem->node_index_range())
863  {
864  const Node & node = elem->node_ref(n);
865 
866  const dof_id_type node_idx =
867  nv * node_id_to_vec_id(node.id());
868 
869  for (unsigned int d=0; d < n_vec_dim; d++)
870  {
871  // For vector-valued elements, all components are in nodal_soln. For each
872  // node, the components are stored in order, i.e. node_0 -> s0_x, s0_y, s0_z
873  parallel_soln.add(node_idx + (var_inc+d + var_num), nodal_soln[n_vec_dim*n+d]);
874 
875  // Increment the repeat count for this position
876  repeat_count.add(node_idx + (var_inc+d + var_num), 1);
877  }
878  }
879 
880  if (add_sides)
881  {
882  for (auto s : elem->side_index_range())
883  {
884  if (redundant_added_side(*elem,s))
885  continue;
886 
887  // Compute the FE solution at all the
888  // side nodes
890  (fe_type, elem, s, elem_soln,
891  nodal_soln, add_p_level);
892 
893 #ifdef DEBUG
894  const std::vector<unsigned int> side_nodes =
895  elem->nodes_on_side(s);
896 
897  libmesh_assert_equal_to
898  (nodal_soln.size(),
899  side_nodes.size());
900 #endif
901 
902  for (auto n : index_range(nodal_soln))
903  {
904  // Retrieve index into global solution vector.
905  std::size_t node_index =
906  nv * libmesh_map_find(discontinuous_node_indices,
907  std::make_tuple(elem->id(), s, n));
908 
909  for (unsigned int d=0; d < n_vec_dim; d++)
910  {
911  parallel_soln.add(node_index + (var_inc+d + var_num), nodal_soln[n_vec_dim*n+d]);
912  repeat_count.add(node_index + (var_inc+d + var_num), 1);
913  }
914  }
915  }
916  }
917  }
918  }
919  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:
920  for (auto n : elem->node_index_range())
921  {
922  const Node & node = elem->node_ref(n);
923  // Only do this if this variable has NO DoFs at
924  // this node... it might have some from an
925  // adjoining element...
926  if (!node.n_dofs(sys_num, var))
927  {
928  const dof_id_type node_idx =
929  nv * node_id_to_vec_id(node.id());
930 
931  for (unsigned int d=0; d < n_vec_dim; d++)
932  repeat_count.add(node_idx + (var_inc+d + var_num), 1);
933  }
934  }
935 
936  } // end loop over elements
937  var_inc += n_vec_dim;
938  } // end loop on variables in this system
939 
940  var_num += nv_sys_split;
941  } // end loop over systems
942 
943  // Sum the nodal solution values and repeat counts.
944  parallel_soln.close();
945  repeat_count.close();
946 
947  // If there were gaps in the node numbering, there will be
948  // corresponding zeros in the parallel_soln and repeat_count
949  // vectors. We need to set those repeat_count entries to 1
950  // in order to avoid dividing by zero.
951  if (n_gaps)
952  {
953  for (numeric_index_type i=repeat_count.first_local_index();
954  i<repeat_count.last_local_index(); ++i)
955  {
956  // repeat_count entries are integral values but let's avoid a
957  // direct floating point comparison with 0 just in case some
958  // roundoff noise crept in during vector assembly?
959  if (std::abs(repeat_count(i)) < TOLERANCE)
960  repeat_count.set(i, 1.);
961  }
962 
963  // Make sure the repeat_count vector is up-to-date on all
964  // processors.
965  repeat_count.close();
966  }
967 
968  // Divide to get the average value at the nodes
969  parallel_soln /= repeat_count;
970 
971  return parallel_soln_ptr;
972 }
void allgather(const T &send_data, std::vector< T, A > &recv_data) const
static constexpr Real TOLERANCE
unsigned int dim
void sum(T &r) const
static FEFieldType field_type(const FEType &fe_type)
processor_id_type rank() const
const Parallel::Communicator & comm() const
const Parallel::Communicator & _communicator
Real distance(const Point &p)
MeshBase & _mesh
The mesh data structure.
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
Definition: type_vector.h:57
processor_id_type size() const
uint8_t processor_id_type
dof_id_type numeric_index_type
Definition: id_types.h:99
libmesh_assert(ctx)
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, bool add_p_level=true)
Build the nodal soln from the element soln.
Definition: fe_interface.C:868
static unsigned int n_vec_dim(const MeshBase &mesh, const FEType &fe_type)
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a NumericVector on the processors in communicator comm using the linear solver package specifi...
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:134
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, bool add_p_level=true)
Build the nodal soln on one side from the (full) element soln.
Definition: fe_interface.C:892
unsigned int mesh_dimension() const
Definition: mesh_base.C:324
virtual dof_id_type max_node_id() const =0
processor_id_type processor_id() const
template class LIBMESH_EXPORT NumericVector< Number >
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:111
uint8_t dof_id_type
Definition: id_types.h:67
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.
static bool redundant_added_side(const Elem &elem, unsigned int side)

◆ build_solution_vector() [1/2]

void libMesh::EquationSystems::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.

Note
The input vector soln will only be assembled on processor 0, so this method is only applicable to outputting plot files from processor 0.

Definition at line 573 of file equation_systems.C.

Referenced by libMesh::MeshOutput< MeshBase >::write_equation_systems().

576 {
577  // TODO:[BSK] re-implement this from the method below
578  libmesh_not_implemented();
579 }

◆ build_solution_vector() [2/2]

void libMesh::EquationSystems::build_solution_vector ( std::vector< Number > &  soln,
const std::set< std::string > *  system_names = nullptr,
bool  add_sides = false 
) const

Fill the input vector soln with solution values.

The entries will be in variable-major format (corresponding to the names from build_variable_names()).

If systems_names!=nullptr, only include data from the specified systems.

If add_sides is true, append data for plotting on "side elements" too.

Definition at line 976 of file equation_systems.C.

References build_parallel_solution_vector().

979 {
980  LOG_SCOPE("build_solution_vector()", "EquationSystems");
981 
982  // Call the parallel implementation
983  std::unique_ptr<NumericVector<Number>> parallel_soln =
984  this->build_parallel_solution_vector(system_names, add_sides);
985 
986  // Localize the NumericVector into the provided std::vector.
987  parallel_soln->localize_to_one(soln);
988 }
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...

◆ build_variable_names()

void libMesh::EquationSystems::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.

If type is passed, only variables of the specified type will be populated. If systems_names!=nullptr, only include names from the specified systems.

Definition at line 454 of file equation_systems.C.

References _systems, dim, libMesh::FEInterface::field_type(), get_mesh(), libMesh::make_range(), libMesh::MeshBase::mesh_dimension(), n_vars(), libMesh::FEInterface::n_vec_dim(), and libMesh::TYPE_VECTOR.

Referenced by main(), EquationSystemsTest::testBadVarNames(), libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems(), libMesh::ExodusII_IO::write_discontinuous_exodusII(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::Nemesis_IO::write_element_data(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO::write_element_data_from_discontinuous_nodal_data(), libMesh::MeshOutput< MeshBase >::write_equation_systems(), libMesh::Nemesis_IO::write_nodal_data(), and libMesh::MeshOutput< MeshBase >::write_nodal_data().

457 {
458  // start indexing at end of possibly non-empty vector of variable names to avoid overwriting them
459  unsigned int var_num = var_names.size();
460 
461  // We'll want to double-check that we don't have any naming
462  // conflicts; this API causes problems down the line if so.
463  std::unordered_multiset<std::string> seen_names;
464 
465  // Need to size var_names by scalar variables plus all the
466  // vector components for all the vector variables
467  //Could this be replaced by a/some convenience methods?[PB]
468  {
469  unsigned int n_scalar_vars = 0;
470  unsigned int n_vector_vars = 0;
471 
472  for (const auto & [sys_name, sys_ptr] : _systems)
473  {
474  // Check current system is listed in system_names, and skip pos if not
475  bool use_current_system = (system_names == nullptr);
476  if (!use_current_system)
477  use_current_system = system_names->count(sys_name);
478  if (!use_current_system || sys_ptr->hide_output())
479  {
480  for (auto vn : make_range(sys_ptr->n_vars()))
481  seen_names.insert(sys_ptr->variable_name(vn));
482  continue;
483  }
484 
485  for (auto vn : make_range(sys_ptr->n_vars()))
486  {
487  seen_names.insert(sys_ptr->variable_name(vn));
488  if (FEInterface::field_type(sys_ptr->variable_type(vn)) == TYPE_VECTOR)
489  n_vector_vars++;
490  else
491  n_scalar_vars++;
492  }
493  }
494 
495  // Here, we're assuming the number of vector components is the same
496  // as the mesh dimension. Will break for mixed dimension meshes.
497  unsigned int dim = this->get_mesh().mesh_dimension();
498  unsigned int nv = n_scalar_vars + dim*n_vector_vars;
499 
500  // We'd better not have more than dim*his->n_vars() (all vector variables)
501  // Treat the NodeElem-only mesh case as dim=1
502  libmesh_assert_less_equal ( nv, (dim > 0 ? dim : 1)*this->n_vars() );
503 
504  // 'nv' represents the max possible number of output variables, so allocate enough memory for
505  // all variables in the system to be populated here. When this is called more than once on a
506  // single 'var_names' vector, different filters should be used such that duplicates don't occur.
507  var_names.resize( nv );
508  }
509 
510  for (const auto & [sys_name, sys_ptr] : _systems)
511  {
512  // Check current system is listed in system_names, and skip pos if not
513  bool use_current_system = (system_names == nullptr);
514  if (!use_current_system)
515  use_current_system = system_names->count(sys_name);
516  if (!use_current_system || sys_ptr->hide_output())
517  continue;
518 
519  for (auto vn : make_range(sys_ptr->n_vars()))
520  {
521  const std::string & var_name = sys_ptr->variable_name(vn);
522  const FEType & fe_type = sys_ptr->variable_type(vn);
523 
524  unsigned int n_vec_dim = FEInterface::n_vec_dim( sys_ptr->get_mesh(), fe_type);
525 
526  // Filter on the type if requested
527  if (type == nullptr || (type && *type == fe_type))
528  {
529  if (FEInterface::field_type(fe_type) == TYPE_VECTOR)
530  {
531  switch(n_vec_dim)
532  {
533  case 0:
534  case 1:
535  var_names[var_num++] = var_name;
536  libmesh_error_msg_if(seen_names.count(var_name) > 1,
537  "Duplicate variable name "+var_name);
538  break;
539  case 2:
540  var_names[var_num++] = var_name+"_x";
541  var_names[var_num++] = var_name+"_y";
542  libmesh_error_msg_if(seen_names.count(var_name+"_x"),
543  "Duplicate variable name "+var_name+"_x");
544  libmesh_error_msg_if(seen_names.count(var_name+"_y"),
545  "Duplicate variable name "+var_name+"_y");
546  break;
547  case 3:
548  var_names[var_num++] = var_name+"_x";
549  var_names[var_num++] = var_name+"_y";
550  var_names[var_num++] = var_name+"_z";
551  libmesh_error_msg_if(seen_names.count(var_name+"_x"),
552  "Duplicate variable name "+var_name+"_x");
553  libmesh_error_msg_if(seen_names.count(var_name+"_y"),
554  "Duplicate variable name "+var_name+"_y");
555  libmesh_error_msg_if(seen_names.count(var_name+"_z"),
556  "Duplicate variable name "+var_name+"_z");
557  break;
558  default:
559  libmesh_error_msg("Invalid dim in build_variable_names");
560  }
561  }
562  else
563  var_names[var_num++] = var_name;
564  }
565  }
566  }
567  // Now resize again in case we filtered any names
568  var_names.resize(var_num);
569 }
unsigned int n_vars() const
unsigned int dim
static FEFieldType field_type(const FEType &fe_type)
static unsigned int n_vec_dim(const MeshBase &mesh, const FEType &fe_type)
const MeshBase & get_mesh() const
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:134
unsigned int mesh_dimension() const
Definition: mesh_base.C:324
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ clear()

void libMesh::EquationSystems::clear ( )
virtual

Restores the data structure to a pristine state.

Definition at line 69 of file equation_systems.C.

References _systems, libMesh::Parameters::clear(), and parameters.

Referenced by main().

70 {
71  // Clear any additional parameters
72  parameters.clear ();
73 
74  // Clear the systems.
75  _systems.clear();
76 }
virtual void clear()
Clears internal data structures & frees any allocated memory.
Definition: parameters.h:324
Parameters parameters
Data structure holding arbitrary parameters.
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ comm()

const Parallel::Communicator& libMesh::ParallelObject::comm ( ) const
inlineinherited
Returns
A reference to the Parallel::Communicator object used by this mesh.

Definition at line 97 of file parallel_object.h.

References libMesh::ParallelObject::_communicator.

Referenced by libMesh::__libmesh_petsc_diff_solver_jacobian(), libMesh::__libmesh_petsc_diff_solver_monitor(), libMesh::__libmesh_petsc_diff_solver_residual(), libMesh::__libmesh_tao_equality_constraints(), libMesh::__libmesh_tao_equality_constraints_jacobian(), libMesh::__libmesh_tao_gradient(), libMesh::__libmesh_tao_hessian(), libMesh::__libmesh_tao_inequality_constraints(), libMesh::__libmesh_tao_inequality_constraints_jacobian(), libMesh::__libmesh_tao_objective(), libMesh::MeshRefinement::_coarsen_elements(), libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), libMesh::Partitioner::_find_global_index_by_pid_map(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::SlepcEigenSolver< libMesh::Number >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< Number >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< libMesh::Number >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< Number >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< Number >::_petsc_shell_matrix_mult_add(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), libMesh::DofMap::add_constraints_to_send_list(), add_cube_convex_hull_to_mesh(), libMesh::PetscDMWrapper::add_dofs_helper(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::TransientRBConstruction::add_IC_to_RB_space(), libMesh::EigenSystem::add_matrices(), libMesh::System::add_matrix(), libMesh::RBConstruction::add_scaled_matrix_and_vector(), libMesh::System::add_variable(), libMesh::System::add_variables(), libMesh::System::add_vector(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::DofMap::allgather_recursive_constraints(), libMesh::TransientRBConstruction::allocate_data_structures(), libMesh::RBConstruction::allocate_data_structures(), libMesh::TransientRBConstruction::assemble_affine_expansion(), libMesh::FEMSystem::assemble_qoi(), libMesh::Nemesis_IO::assert_symmetric_cmaps(), libMesh::MeshCommunication::assign_global_indices(), libMesh::Partitioner::assign_partitioning(), libMesh::MeshTools::Generation::build_extrusion(), libMesh::BoundaryInfo::build_node_list_from_side_list(), build_parallel_elemental_solution_vector(), build_parallel_solution_vector(), libMesh::PetscDMWrapper::build_section(), libMesh::PetscDMWrapper::build_sf(), libMesh::MeshBase::cache_elem_data(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::RBConstruction::compute_Fq_representor_innerprods(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::RBConstruction::compute_output_dual_innerprods(), libMesh::RBConstruction::compute_residual_dual_norm_slow(), libMesh::RBSCMConstruction::compute_SCM_bounds_on_training_set(), libMesh::DofMap::computed_sparsity_already(), libMesh::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ContinuationSystem::ContinuationSystem(), libMesh::MeshBase::copy_constraint_rows(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), libMesh::DofMap::create_dof_constraints(), libMesh::MeshTools::create_nodal_bounding_box(), libMesh::MeshRefinement::create_parent_error_vector(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::MeshTools::create_subdomain_bounding_box(), libMesh::PetscMatrix< libMesh::Number >::create_submatrix_nosort(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::RBEIMEvaluation::distribute_bfs(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::DTKSolutionTransfer::DTKSolutionTransfer(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_interiors(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_nodes(), libMesh::RBEIMConstruction::enrich_eim_approximation_on_sides(), libMesh::TransientRBConstruction::enrich_RB_space(), libMesh::EpetraVector< T >::EpetraVector(), AssembleOptimization::equality_constraints(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::AdjointRefinementEstimator::estimate_error(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::MeshRefinement::flag_elements_by_elem_fraction(), libMesh::MeshRefinement::flag_elements_by_error_fraction(), libMesh::MeshRefinement::flag_elements_by_error_tolerance(), libMesh::MeshRefinement::flag_elements_by_mean_stddev(), libMesh::MeshRefinement::flag_elements_by_nelem_target(), libMesh::RBEIMEvaluation::gather_bfs(), libMesh::DofMap::gather_constraints(), libMesh::MeshfreeInterpolation::gather_remote_data(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::RBEIMEvaluation::get_eim_basis_function_node_value(), libMesh::RBEIMEvaluation::get_eim_basis_function_side_value(), libMesh::RBEIMEvaluation::get_eim_basis_function_value(), libMesh::MeshBase::get_info(), libMesh::System::get_info(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::RBEIMConstruction::get_max_abs_value(), libMesh::RBEIMConstruction::get_node_max_abs_value(), libMesh::RBEIMEvaluation::get_parametrized_function_node_value(), libMesh::RBEIMEvaluation::get_parametrized_function_side_value(), libMesh::RBEIMEvaluation::get_parametrized_function_value(), libMesh::RBEIMConstruction::get_random_point(), AssembleOptimization::inequality_constraints(), AssembleOptimization::inequality_constraints_jacobian(), libMesh::LocationMap< T >::init(), libMesh::TimeSolver::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), libMesh::RBEIMConstruction::initialize_parametrized_functions_in_training_set(), libMesh::RBEIMConstruction::inner_product(), integrate_function(), libMesh::MeshTools::libmesh_assert_consistent_distributed(), libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_equal_connectivity(), libMesh::MeshTools::libmesh_assert_equal_points(), libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_flags(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_p_levels(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::MeshTools::libmesh_assert_valid_unique_ids(), libMesh::libmesh_petsc_linesearch_shellfunc(), libMesh::libmesh_petsc_preconditioner_apply(), libMesh::libmesh_petsc_recalculate_monitor(), libMesh::libmesh_petsc_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_interface(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_postcheck(), libMesh::libmesh_petsc_snes_precheck(), libMesh::libmesh_petsc_snes_residual(), libMesh::libmesh_petsc_snes_residual_helper(), libMesh::MeshRefinement::limit_level_mismatch_at_edge(), libMesh::MeshRefinement::limit_level_mismatch_at_node(), libMesh::MeshRefinement::limit_overrefined_boundary(), libMesh::MeshRefinement::limit_underrefined_boundary(), libMesh::LinearImplicitSystem::LinearImplicitSystem(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshCommunication::make_elems_parallel_consistent(), libMesh::MeshRefinement::make_flags_parallel_consistent(), libMesh::MeshCommunication::make_new_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_new_nodes_parallel_consistent(), libMesh::MeshCommunication::make_node_bcids_parallel_consistent(), libMesh::MeshCommunication::make_node_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_proc_ids_parallel_consistent(), libMesh::MeshCommunication::make_node_unique_ids_parallel_consistent(), libMesh::MeshCommunication::make_nodes_parallel_consistent(), libMesh::MeshCommunication::make_p_levels_parallel_consistent(), libMesh::MeshRefinement::make_refinement_compatible(), libMesh::TransientRBConstruction::mass_matrix_scaled_matvec(), libMesh::FEMSystem::mesh_position_set(), libMesh::TriangulatorInterface::MeshedHole::MeshedHole(), LinearElasticityWithContact::move_mesh(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::DofMap::n_constrained_dofs(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), MixedOrderTest::n_neighbor_links(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::SparsityPattern::Build::n_nonzeros(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::RBEIMEvaluation::node_distribute_bfs(), libMesh::RBEIMEvaluation::node_gather_bfs(), libMesh::RBEIMConstruction::node_inner_product(), libMesh::MeshBase::operator==(), libMesh::DistributedMesh::parallel_max_elem_id(), libMesh::DistributedMesh::parallel_max_node_id(), libMesh::ReplicatedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_max_unique_id(), libMesh::DistributedMesh::parallel_n_elem(), libMesh::DistributedMesh::parallel_n_nodes(), libMesh::SparsityPattern::Build::parallel_sync(), libMesh::BoundaryInfo::parallel_sync_node_ids(), libMesh::BoundaryInfo::parallel_sync_side_ids(), libMesh::MeshTools::paranoid_n_levels(), libMesh::Partitioner::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::DofMap::print_dof_constraints(), libMesh::DofMap::process_mesh_constraint_rows(), libMesh::Partitioner::processor_pairs_to_interface_nodes(), libMesh::InterMeshProjection::project_system_vectors(), FEMParameters::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), read(), libMesh::ExodusII_IO::read_header(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::RBEIMEvaluation::read_in_interior_basis_functions(), libMesh::RBEIMEvaluation::read_in_node_basis_functions(), libMesh::RBEIMEvaluation::read_in_side_basis_functions(), libMesh::RBEvaluation::read_in_vectors_from_multiple_files(), libMesh::System::read_legacy_data(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::Nemesis_IO_Helper::read_var_names_impl(), libMesh::MeshBase::recalculate_n_partitions(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::DistributedMesh::renumber_nodes_and_elements(), LinearElasticityWithContact::residual_and_jacobian(), OverlappingAlgebraicGhostingTest::run_ghosting_test(), OverlappingCouplingGhostingTest::run_sparsity_pattern_test(), scale_mesh_and_plot(), libMesh::DofMap::scatter_constraints(), libMesh::CheckpointIO::select_split_config(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::send_and_insert_dof_values(), libMesh::TransientRBConstruction::set_error_temporal_data(), libMesh::Partitioner::set_interface_node_processor_ids_BFS(), libMesh::Partitioner::set_interface_node_processor_ids_linear(), libMesh::Partitioner::set_interface_node_processor_ids_petscpartitioner(), libMesh::Partitioner::set_node_processor_ids(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::Partitioner::set_parent_processor_ids(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::PetscDiffSolver::setup_petsc_data(), libMesh::RBEIMEvaluation::side_distribute_bfs(), libMesh::RBEIMEvaluation::side_gather_bfs(), libMesh::RBEIMConstruction::side_inner_product(), libMesh::Partitioner::single_partition(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::split_mesh(), libMesh::RBEIMConstruction::store_eim_solutions_for_training_set(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), ConstraintOperatorTest::test1DCoarseningNewNodes(), ConstraintOperatorTest::test1DCoarseningOperator(), libMesh::MeshRefinement::test_level_one(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), libMesh::MeshRefinement::test_unflagged(), DofMapTest::testBadElemFECombo(), SystemsTest::testBlockRestrictedVarNDofs(), BoundaryInfoTest::testBoundaryOnChildrenErrors(), MeshInputTest::testExodusIGASidesets(), MeshTriangulationTest::testFoundCenters(), PointLocatorTest::testLocator(), BoundaryInfoTest::testMesh(), PointLocatorTest::testPlanar(), MeshTriangulationTest::testPoly2TriRefinementBase(), SystemsTest::testProjectCubeWithMeshFunction(), BoundaryInfoTest::testRenumber(), CheckpointIOTest::testSplitter(), MeshInputTest::testTetgenIO(), MeshTriangulationTest::testTriangulatorInterp(), MeshTriangulationTest::testTriangulatorMeshedHoles(), libMesh::MeshTools::total_weight(), libMesh::RBConstruction::train_reduced_basis_with_POD(), libMesh::MeshFunctionSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::Poly2TriTriangulator::triangulate(), libMesh::TransientRBConstruction::truth_assembly(), libMesh::RBConstruction::truth_assembly(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::TransientRBConstruction::update_RB_initial_condition_all_N(), libMesh::TransientRBConstruction::update_RB_system_matrices(), libMesh::RBConstruction::update_RB_system_matrices(), libMesh::TransientRBConstruction::update_residual_terms(), libMesh::RBConstruction::update_residual_terms(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::VTKIO::write_nodal_data(), libMesh::RBEIMEvaluation::write_out_interior_basis_functions(), libMesh::RBEIMEvaluation::write_out_node_basis_functions(), libMesh::RBEIMEvaluation::write_out_side_basis_functions(), libMesh::RBEvaluation::write_out_vectors(), libMesh::TransientRBConstruction::write_riesz_representors_to_files(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::RBDataSerialization::RBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::TransientRBEvaluationSerialization::write_to_file(), libMesh::RBDataSerialization::RBEIMEvaluationSerialization::write_to_file(), and libMesh::RBDataSerialization::RBSCMEvaluationSerialization::write_to_file().

98  { return _communicator; }
const Parallel::Communicator & _communicator

◆ compare()

bool libMesh::EquationSystems::compare ( const EquationSystems other_es,
const Real  threshold,
const bool  verbose 
) const
virtual
Returns
true when this equation system contains identical data, up to the given threshold. Delegates most of the comparisons to perform to the responsible systems

Definition at line 1600 of file equation_systems.C.

References _systems, get_system(), n_systems(), and libMesh::out.

Referenced by do_compare().

1603 {
1604  // safety check, whether we handle at least the same number
1605  // of systems
1606  std::vector<bool> os_result;
1607 
1608  if (this->n_systems() != other_es.n_systems())
1609  {
1610  if (verbose)
1611  {
1612  libMesh::out << " Fatal difference. This system handles "
1613  << this->n_systems() << " systems," << std::endl
1614  << " while the other system handles "
1615  << other_es.n_systems()
1616  << " systems." << std::endl
1617  << " Aborting comparison." << std::endl;
1618  }
1619  return false;
1620  }
1621  else
1622  {
1623  // start comparing each system
1624  for (const auto & [sys_name, sys_ptr] : _systems)
1625  {
1626  // get the other system
1627  const System & other_system = other_es.get_system (sys_name);
1628 
1629  os_result.push_back (sys_ptr->compare (other_system, threshold, verbose));
1630 
1631  }
1632 
1633  }
1634 
1635 
1636  // sum up the results
1637  if (os_result.size()==0)
1638  return true;
1639  else
1640  {
1641  bool os_identical;
1642  unsigned int n = 0;
1643  do
1644  {
1645  os_identical = os_result[n];
1646  n++;
1647  }
1648  while (os_identical && n<os_result.size());
1649  return os_identical;
1650  }
1651 }
unsigned int n_systems() const
OStreamProxy out
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = false;
103  return;
104 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ disable_refine_in_reinit()

void libMesh::EquationSystems::disable_refine_in_reinit ( )
inline

Calls to reinit() will not try to coarsen or refine the mesh.

Definition at line 572 of file equation_systems.h.

References _refine_in_reinit.

Referenced by EquationSystemsTest::testRefineThenReinitPreserveFlags(), and EquationSystemsTest::testSelectivePRefine().

572 { this->_refine_in_reinit = false; }
bool _refine_in_reinit
Flag for whether to call coarsen/refine in reinit().

◆ enable_default_ghosting()

void libMesh::EquationSystems::enable_default_ghosting ( bool  enable)
virtual

Enable or disable default ghosting functors on the Mesh and on all Systems.

Standard ghosting is enabled by default. If disabled, default ghosting will also be disabled on any later added systems.

Unless other equivalent ghosting functors have been added, removing the default coupling functor is only safe for explicit solves, and removing the default algebraic ghosting functor is only safe for codes where no evaluations on neighbor cells (e.g. no jump error estimators) are done.

Definition at line 309 of file equation_systems.C.

References _enable_default_ghosting, libMesh::DofMap::add_default_ghosting(), get_mesh(), get_system(), libMesh::make_range(), mesh, n_systems(), and libMesh::DofMap::remove_default_ghosting().

Referenced by EquationSystemsTest::testDisableDefaultGhosting().

310 {
311  _enable_default_ghosting = enable;
312  MeshBase &mesh = this->get_mesh();
313 
314  if (enable)
315  mesh.add_ghosting_functor(mesh.default_ghosting());
316  else
317  mesh.remove_ghosting_functor(mesh.default_ghosting());
318 
319  for (auto i : make_range(this->n_systems()))
320  {
321  DofMap & dof_map = this->get_system(i).get_dof_map();
322  if (enable)
323  dof_map.add_default_ghosting();
324  else
325  dof_map.remove_default_ghosting();
326  }
327 }
unsigned int n_systems() const
bool _enable_default_ghosting
Flag for whether to enable default ghosting on newly added Systems.
MeshBase & mesh
const T_sys & get_system(std::string_view name) const
const MeshBase & get_mesh() const
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:134

◆ enable_print_counter_info()

void libMesh::ReferenceCounter::enable_print_counter_info ( )
staticinherited

Methods to enable/disable the reference counter output from print_info()

Definition at line 94 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

95 {
96  _enable_print_counter = true;
97  return;
98 }
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ enable_refine_in_reinit()

void libMesh::EquationSystems::enable_refine_in_reinit ( )
inline

Calls to reinit() will also do two-step coarsen-then-refine.

Definition at line 567 of file equation_systems.h.

References _refine_in_reinit.

567 { this->_refine_in_reinit = true; }
bool _refine_in_reinit
Flag for whether to call coarsen/refine in reinit().

◆ find_variable_numbers()

std::vector< std::pair< unsigned int, unsigned int > > libMesh::EquationSystems::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 entries in the input 'names' vector.

If 'names' is empty, this returns all variables of the type. The names of vector variables are decomposed into individual ones suffixed with their cartesian component, but there will still be a single pair of system numbers for such vector variables. Thus, the size of the 'names' vector modified by this function may not be equal to that of the returned vector of pairs. Nevertheless, both should be sorted in accordance with ExodusII format, and so the developer just needs to know to separate dof_indices when accessing the system solution for vector variables.

This function is designed to work for either a single type or a vector of types, but not both. This is because it can't simply be called a second time with another type as it filters (deletes) the names of those on the first call that used a different type. Thus, the 'types' argument is for the case where variables of multiple types are allowed to pass through.

TODO: find a more generic way to handle this whole procedure.

Definition at line 1047 of file equation_systems.C.

References dim, libMesh::FEInterface::field_type(), libMesh::index_range(), libMesh::Utility::iota(), libMesh::libmesh_assert(), libMesh::make_range(), libMesh::System::n_vars(), libMesh::Quality::name(), libMesh::System::number(), libMesh::TYPE_VECTOR, libMesh::System::variable_name(), and libMesh::System::variable_type().

Referenced by build_parallel_elemental_solution_vector(), libMesh::Nemesis_IO::write_element_data(), and libMesh::Nemesis_IO::write_nodal_data().

1048 {
1049  // This function must be run on all processors at once
1050  parallel_object_only();
1051 
1052  libmesh_assert (this->n_systems());
1053 
1054  // Resolve class of type input and assert that at least one of them is null
1055  libmesh_assert_msg(!type || !types,
1056  "Input 'type', 'types', or neither in find_variable_numbers, but not both.");
1057 
1058  std::vector<FEType> type_filter;
1059  if (type)
1060  type_filter.push_back(*type);
1061  else if (types)
1062  type_filter = *types;
1063 
1064  // Store a copy of the valid variable names, if any. The names vector will be repopulated with any
1065  // valid names (or all if 'is_names_empty') in the system that passes through the type filter. If
1066  // the variable is a vector, its name will be decomposed into its separate components in
1067  // accordance with build_variable_names().
1068  std::vector<std::string> name_filter = names;
1069  bool is_names_empty = name_filter.empty();
1070  names.clear();
1071 
1072  // initialize convenience variables
1073  FEType var_type;
1074  std::string name;
1075 
1076  const std::vector<std::string> component_suffix = {"_x", "_y", "_z"};
1077  unsigned int dim = _mesh.mesh_dimension();
1078  libmesh_error_msg_if(dim > 3, "Invalid dim in find_variable_numbers");
1079 
1080  // Now filter through the variables in each system and store the system index and their index
1081  // within that system. This way, we know where to find their data even after we sort them.
1082  std::vector<std::pair<unsigned int, unsigned int>> var_nums;
1083 
1084  for (const auto & pr : _systems)
1085  {
1086  const System & system = *(pr.second);
1087 
1088  for (auto var : make_range(system.n_vars()))
1089  {
1090  // apply the type filter
1091  var_type = system.variable_type(var);
1092  if (type_filter.size() &&
1093  std::find(type_filter.begin(), type_filter.end(), var_type) == type_filter.end())
1094  continue;
1095 
1096  // apply the name filter (note that all variables pass if it is empty)
1097  if (FEInterface::field_type(var_type) == TYPE_VECTOR)
1098  {
1099  std::vector<std::string> component_names;
1100  for (unsigned int comp = 0; comp < dim; ++comp)
1101  {
1102  name = system.variable_name(var) + component_suffix[comp];
1103  if (is_names_empty ||
1104  (std::find(name_filter.begin(), name_filter.end(), name) != name_filter.end()))
1105  component_names.push_back(name);
1106  }
1107 
1108  if (! component_names.empty())
1109  names.insert(names.end(), component_names.begin(), component_names.end());
1110  else
1111  continue;
1112  }
1113  else /*scalar-valued variable*/
1114  {
1115  name = system.variable_name(var);
1116  if (is_names_empty ||
1117  (std::find(name_filter.begin(), name_filter.end(), name) != name_filter.end()))
1118  names.push_back(name);
1119  else
1120  continue;
1121  }
1122 
1123  // if the variable made it through both filters get its system indices
1124  var_nums.emplace_back(system.number(), var);
1125  }
1126  }
1127 
1128  // Sort the var_nums vector pairs alphabetically based on the variable name
1129  std::vector<unsigned int> sort_index(var_nums.size());
1130  std::iota(sort_index.begin(), sort_index.end(), 0);
1131  std::sort(sort_index.begin(), sort_index.end(),
1132  [&](const unsigned int & lhs, const unsigned int & rhs)
1133  {return this->get_system(var_nums[lhs].first).variable_name(var_nums[lhs].second) <
1134  this->get_system(var_nums[rhs].first).variable_name(var_nums[rhs].second);});
1135 
1136  std::vector<std::pair<unsigned int, unsigned int>> var_nums_sorted(var_nums.size());
1137  for (auto i : index_range(var_nums_sorted))
1138  {
1139  var_nums_sorted[i].first = var_nums[sort_index[i]].first;
1140  var_nums_sorted[i].second = var_nums[sort_index[i]].second;
1141  }
1142 
1143  // Also sort the names vector
1144  std::sort(names.begin(), names.end());
1145 
1146  // Return the sorted vector pairs
1147  return var_nums_sorted;
1148 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
unsigned int n_systems() const
unsigned int dim
static FEFieldType field_type(const FEType &fe_type)
const T_sys & get_system(std::string_view name) const
void iota(ForwardIter first, ForwardIter last, T value)
Utility::iota was created back when std::iota was just an SGI STL extension.
Definition: utility.h:229
MeshBase & _mesh
The mesh data structure.
libmesh_assert(ctx)
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:134
unsigned int mesh_dimension() const
Definition: mesh_base.C:324
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:111
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ get_info() [1/2]

std::string libMesh::ReferenceCounter::get_info ( )
staticinherited

Gets a string containing the reference information.

Definition at line 47 of file reference_counter.C.

References libMesh::ReferenceCounter::_counts, and libMesh::Quality::name().

Referenced by libMesh::ReferenceCounter::print_info().

48 {
49 #if defined(LIBMESH_ENABLE_REFERENCE_COUNTING) && defined(DEBUG)
50 
51  std::ostringstream oss;
52 
53  oss << '\n'
54  << " ---------------------------------------------------------------------------- \n"
55  << "| Reference count information |\n"
56  << " ---------------------------------------------------------------------------- \n";
57 
58  for (const auto & [name, cd] : _counts)
59  oss << "| " << name << " reference count information:\n"
60  << "| Creations: " << cd.first << '\n'
61  << "| Destructions: " << cd.second << '\n';
62 
63  oss << " ---------------------------------------------------------------------------- \n";
64 
65  return oss.str();
66 
67 #else
68 
69  return "";
70 
71 #endif
72 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
static Counts _counts
Actually holds the data.

◆ get_info() [2/2]

std::string libMesh::EquationSystems::get_info ( ) const
virtual
Returns
A string containing information about the systems, flags, and parameters.

Definition at line 1655 of file equation_systems.C.

References _systems, and n_systems().

Referenced by print_info().

1656 {
1657  std::ostringstream oss;
1658 
1659  oss << " EquationSystems\n"
1660  << " n_systems()=" << this->n_systems() << '\n';
1661 
1662  // Print the info for the individual systems
1663  for (const auto & pr : _systems)
1664  oss << pr.second->get_info();
1665 
1666 
1667  // // Possibly print the parameters
1668  // if (!this->parameters.empty())
1669  // {
1670  // oss << " n_parameters()=" << this->n_parameters() << '\n';
1671  // oss << " Parameters:\n";
1672 
1673  // for (const auto & [key, val] : _parameters)
1674  // oss << " "
1675  // << "\""
1676  // << key
1677  // << "\""
1678  // << "="
1679  // << val
1680  // << '\n';
1681  // }
1682 
1683  return oss.str();
1684 }
unsigned int n_systems() const
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ get_mesh() [1/2]

const MeshBase & libMesh::EquationSystems::get_mesh ( ) const
inline
Returns
A constant reference to the mesh

Definition at line 644 of file equation_systems.h.

References _mesh.

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), alternative_fe_assembly(), assemble(), LinearElasticity::assemble(), assemble_1D(), assemble_biharmonic(), assemble_cd(), assemble_divgrad(), assemble_elasticity(), assemble_ellipticdg(), assemble_func(), assemble_helmholtz(), assemble_laplace(), assemble_mass(), assemble_matrices(), assemble_matrix_and_rhs(), assemble_poisson(), assemble_SchroedingerEquation(), assemble_shell(), assemble_stokes(), assemble_wave(), assembly_with_dg_fem_context(), build_variable_names(), compute_stresses(), LinearElasticity::compute_stresses(), LargeDeformationElasticity::compute_stresses(), enable_default_ghosting(), libMesh::AdjointRefinementEstimator::estimate_error(), fe_assembly(), fill_dirichlet_bc(), libMesh::MeshFunction::init(), LaplaceYoung::jacobian(), LargeDeformationElasticity::jacobian(), periodic_bc_test_poisson(), read(), reinit_solutions(), LaplaceYoung::residual(), LargeDeformationElasticity::residual(), run_timestepping(), scale_mesh_and_plot(), libMesh::DirectSolutionTransfer::transfer(), libMesh::MeshfreeSolutionTransfer::transfer(), libMesh::DTKSolutionTransfer::transfer(), transform_mesh_and_plot(), write(), libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems(), libMesh::MeshOutput< MeshBase >::write_equation_systems(), libMesh::Nemesis_IO_Helper::write_nodal_solution(), write_output(), and write_output_solvedata().

645 {
646  return _mesh;
647 }
MeshBase & _mesh
The mesh data structure.

◆ get_mesh() [2/2]

MeshBase & libMesh::EquationSystems::get_mesh ( )
inline
Returns
A reference to the mesh

Definition at line 652 of file equation_systems.h.

References _mesh.

653 {
654  return _mesh;
655 }
MeshBase & _mesh
The mesh data structure.

◆ get_solution()

void libMesh::EquationSystems::get_solution ( std::vector< Number > &  soln,
std::vector< std::string > &  names 
) const

Retrieve the solution data for CONSTANT MONOMIALs and/or components of CONSTANT MONOMIAL_VECs.

If 'names' is populated, only the variables corresponding to those names will be retrieved. This can be used to filter which variables are retrieved.

Definition at line 1018 of file equation_systems.C.

References build_elemental_solution_vector().

1020 {
1021  libmesh_deprecated();
1022  this->build_elemental_solution_vector(soln, names);
1023 }
void build_elemental_solution_vector(std::vector< Number > &soln, std::vector< std::string > &names) const
Retrieve the solution data for CONSTANT MONOMIALs and/or components of CONSTANT MONOMIAL_VECs.

◆ get_system() [1/8]

template<typename T_sys >
const T_sys & libMesh::EquationSystems::get_system ( std::string_view  name) const
inline
Returns
A constant reference to the system named name. The template argument defines the return type. For example, const SteadySystem & sys = eq.get_system<SteadySystem> ("sys"); is an example of how the method might be used

Definition at line 755 of file equation_systems.h.

References _systems, and libMesh::Quality::name().

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), _remove_default_ghosting(), add_M_C_K_helmholtz(), libMesh::EnsightIO::add_scalar(), libMesh::RBSCMConstruction::add_scaled_symm_Aq(), add_system(), libMesh::EnsightIO::add_vector(), adjoint_solve(), allgather(), alternative_fe_assembly(), apply_initial(), assemble(), LinearElasticity::assemble(), assemble_1D(), assemble_biharmonic(), assemble_cd(), assemble_divgrad(), assemble_elasticity(), assemble_ellipticdg(), assemble_func(), assemble_helmholtz(), assemble_laplace(), assemble_mass(), assemble_matrices(), assemble_matrix_and_rhs(), assemble_poisson(), assemble_SchroedingerEquation(), assemble_shell(), assemble_stokes(), assemble_wave(), assembly_with_dg_fem_context(), libMesh::ExactSolution::attach_exact_deriv(), libMesh::ExactSolution::attach_exact_hessian(), libMesh::ExactSolution::attach_exact_value(), build_parallel_elemental_solution_vector(), compare(), libMesh::ExactSolution::compute_error(), compute_stresses(), LinearElasticityWithContact::compute_stresses(), LinearElasticity::compute_stresses(), LargeDeformationElasticity::compute_stresses(), libMesh::GMVIO::copy_nodal_solution(), SolidSystem::element_time_derivative(), enable_default_ghosting(), libMesh::ExactSolution::error_norm(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::ErrorEstimator::estimate_errors(), libMesh::ExactSolution::ExactSolution(), fe_assembly(), fill_dirichlet_bc(), libMesh::DTKAdapter::find_sys(), init(), init_cd(), SolidSystem::init_data(), init_sys(), initialize(), LaplaceYoung::jacobian(), LargeDeformationElasticity::jacobian(), line_print(), libMesh::RBSCMConstruction::load_matrix_B(), main(), libMesh::RBSCMConstruction::perform_SCM_greedy(), periodic_bc_test_poisson(), read(), reinit_mesh(), reinit_solutions(), reinit_systems(), LaplaceYoung::residual(), LargeDeformationElasticity::residual(), run_timestepping(), SolidSystem::save_initial_mesh(), sensitivity_solve(), SolidSystem::side_time_derivative(), solve(), MixedDimensionMeshTest::testDofOrdering(), MixedDimensionRefinedMeshTest::testDofOrdering(), MixedDimensionNonUniformRefinement::testDofOrdering(), MixedDimensionNonUniformRefinementTriangle::testDofOrdering(), MixedDimensionNonUniformRefinement3D::testDofOrdering(), SlitMeshRefinedSystemTest::testRestart(), update(), libMesh::Nemesis_IO_Helper::write_element_values(), libMesh::Nemesis_IO_Helper::write_nodal_solution(), libMesh::EnsightIO::write_scalar_ascii(), and libMesh::EnsightIO::write_vector_ascii().

756 {
757  auto pos = _systems.find(name);
758 
759  // Check for errors
760  libmesh_error_msg_if(pos == _systems.end(), "ERROR: no system named \"" << name << "\" found!");
761 
762  // Attempt dynamic cast
763  const auto & sys_ptr = pos->second;
764  return cast_ref<const T_sys &>(*sys_ptr);
765 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ get_system() [2/8]

template<typename T_sys >
T_sys & libMesh::EquationSystems::get_system ( std::string_view  name)
inline
Returns
A writable reference to the system named name. The template argument defines the return type. For example, const SteadySystem & sys = eq.get_system<SteadySystem> ("sys"); is an example of how the method might be used

Definition at line 774 of file equation_systems.h.

References _systems, and libMesh::Quality::name().

775 {
776  auto pos = _systems.find(name);
777 
778  // Check for errors
779  libmesh_error_msg_if(pos == _systems.end(), "ERROR: no system named " << name << " found!");
780 
781  // Attempt dynamic cast
782  auto & sys_ptr = pos->second;
783  return cast_ref<T_sys &>(*sys_ptr);
784 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ get_system() [3/8]

template<typename T_sys >
const T_sys & libMesh::EquationSystems::get_system ( const unsigned int  num) const
inline
Returns
A constant reference to system number num. The template argument defines the return type. For example, const SteadySystem & sys = eq.get_system<SteadySystem> (0); is an example of how the method might be used

Definition at line 714 of file equation_systems.h.

References _systems, and n_systems().

715 {
716  libmesh_assert_less (num, this->n_systems());
717 
718  for (auto & pr : _systems)
719  {
720  const auto & sys_ptr = pr.second;
721  if (sys_ptr->number() == num)
722  return cast_ref<const T_sys &>(*sys_ptr);
723  }
724  // Error if we made it here
725  libmesh_error_msg("ERROR: no system number " << num << " found!");
726 }
unsigned int n_systems() const
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ get_system() [4/8]

template<typename T_sys >
T_sys & libMesh::EquationSystems::get_system ( const unsigned int  num)
inline
Returns
A writable reference to the system number num. The template argument defines the return type. For example, const SteadySystem & sys = eq.get_system<SteadySystem> (0); is an example of how the method might be used

Definition at line 733 of file equation_systems.h.

References _systems, and n_systems().

734 {
735  libmesh_assert_less (num, this->n_systems());
736 
737  for (auto & pr : _systems)
738  {
739  auto & sys_ptr = pr.second;
740  if (sys_ptr->number() == num)
741  return cast_ref<T_sys &>(*sys_ptr);
742  }
743 
744  // Error if we made it here
745  libmesh_error_msg("ERROR: no system number " << num << " found!");
746 }
unsigned int n_systems() const
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ get_system() [5/8]

const System & libMesh::EquationSystems::get_system ( std::string_view  name) const
inline
Returns
A constant reference to the system named name.

Definition at line 793 of file equation_systems.h.

References libMesh::Quality::name().

794 {
795  return this->get_system<System>(name);
796 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42

◆ get_system() [6/8]

System & libMesh::EquationSystems::get_system ( std::string_view  name)
inline
Returns
A writable reference to the system named name.

Definition at line 801 of file equation_systems.h.

References libMesh::Quality::name().

802 {
803  return this->get_system<System>(name);
804 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42

◆ get_system() [7/8]

const System & libMesh::EquationSystems::get_system ( const unsigned int  num) const
inline
Returns
A constant reference to system number num.

Definition at line 809 of file equation_systems.h.

810 {
811  return this->get_system<System>(num);
812 }

◆ get_system() [8/8]

System & libMesh::EquationSystems::get_system ( const unsigned int  num)
inline
Returns
A writable reference to the system number num.

Definition at line 817 of file equation_systems.h.

818 {
819  return this->get_system<System>(num);
820 }

◆ get_vars_active_subdomains()

void libMesh::EquationSystems::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.

Definition at line 992 of file equation_systems.C.

References _systems, libMesh::Variable::active_subdomains(), distance(), and libMesh::make_range().

Referenced by libMesh::Nemesis_IO::write_element_data(), libMesh::ExodusII_IO::write_element_data(), and libMesh::ExodusII_IO::write_element_data_from_discontinuous_nodal_data().

994 {
995  vars_active_subdomains.clear();
996  vars_active_subdomains.resize(names.size());
997 
998  for (const auto & pr : _systems)
999  {
1000  const auto & sys_ptr = pr.second;
1001  for (auto vn : make_range(sys_ptr->n_vars()))
1002  {
1003  const std::string & var_name = sys_ptr->variable_name(vn);
1004 
1005  auto names_it = std::find(names.begin(), names.end(), var_name);
1006  if(names_it != names.end())
1007  {
1008  const Variable & variable = sys_ptr->variable(vn);
1009  const std::set<subdomain_id_type> & active_subdomains = variable.active_subdomains();
1010  vars_active_subdomains[std::distance(names.begin(), names_it)] = active_subdomains;
1011  }
1012  }
1013  }
1014 }
Real distance(const Point &p)
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:134
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ has_system()

bool libMesh::EquationSystems::has_system ( std::string_view  name) const
inline
Returns
true if the system named name exists within this EquationSystems object.

Definition at line 702 of file equation_systems.h.

References _systems, and libMesh::Quality::name().

Referenced by libMesh::EnsightIO::add_scalar(), libMesh::EnsightIO::add_vector(), libMesh::ExactSolution::compute_error(), libMesh::ExactSolution::error_norm(), and main().

703 {
704  if (_systems.find(name) == _systems.end())
705  return false;
706  return true;
707 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ increment_constructor_count()

void libMesh::ReferenceCounter::increment_constructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the construction counter.

Should be called in the constructor of any derived class that will be reference counted.

Definition at line 183 of file reference_counter.h.

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::ReferenceCountedObject().

184 {
185  libmesh_try
186  {
187  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
188  std::pair<unsigned int, unsigned int> & p = _counts[name];
189  p.first++;
190  }
191  libmesh_catch (...)
192  {
193  auto stream = libMesh::err.get();
194  stream->exceptions(stream->goodbit); // stream must not throw
195  libMesh::err << "Encountered unrecoverable error while calling "
196  << "ReferenceCounter::increment_constructor_count() "
197  << "for a(n) " << name << " object." << std::endl;
198  std::terminate();
199  }
200 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
OStreamProxy err
static Counts _counts
Actually holds the data.
streamT * get()
Rather than implement every ostream/ios/ios_base function, we&#39;ll be lazy and make esoteric uses go th...
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:30

◆ increment_destructor_count()

void libMesh::ReferenceCounter::increment_destructor_count ( const std::string &  name)
inlineprotectednoexceptinherited

Increments the destruction counter.

Should be called in the destructor of any derived class that will be reference counted.

Definition at line 207 of file reference_counter.h.

References libMesh::err, libMesh::BasicOStreamProxy< charT, traits >::get(), libMesh::Quality::name(), and libMesh::Threads::spin_mtx.

Referenced by libMesh::ReferenceCountedObject< RBParametrized >::~ReferenceCountedObject().

208 {
209  libmesh_try
210  {
211  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
212  std::pair<unsigned int, unsigned int> & p = _counts[name];
213  p.second++;
214  }
215  libmesh_catch (...)
216  {
217  auto stream = libMesh::err.get();
218  stream->exceptions(stream->goodbit); // stream must not throw
219  libMesh::err << "Encountered unrecoverable error while calling "
220  << "ReferenceCounter::increment_destructor_count() "
221  << "for a(n) " << name << " object." << std::endl;
222  std::terminate();
223  }
224 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
OStreamProxy err
static Counts _counts
Actually holds the data.
streamT * get()
Rather than implement every ostream/ios/ios_base function, we&#39;ll be lazy and make esoteric uses go th...
spin_mutex spin_mtx
A convenient spin mutex object which can be used for obtaining locks.
Definition: threads.C:30

◆ init()

void libMesh::EquationSystems::init ( )
virtual

Initialize all the systems.

Reimplemented in Biharmonic.

Definition at line 80 of file equation_systems.C.

References _mesh, libMesh::MeshRefinement::clean_refinement_flags(), get_system(), libMesh::make_range(), and n_systems().

Referenced by assemble_and_solve(), main(), libMesh::ErrorVector::plot_error(), read(), TimeSolverTestImplementation< NewmarkSolver >::run_test_with_exact_soln(), setup(), WriteVecAndScalar::setupTests(), MultiEvaluablePredTest::test(), SystemsTest::test100KVariables(), ConstraintOperatorTest::test1DCoarseningNewNodes(), ConstraintOperatorTest::test1DCoarseningOperator(), SystemsTest::test2DProjectVectorFE(), SystemsTest::test3DProjectVectorFE(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), MeshFunctionTest::test_subdomain_id_sets(), SystemsTest::testAssemblyWithDgFemContext(), DofMapTest::testBadElemFECombo(), EquationSystemsTest::testBadVarNames(), SystemsTest::testBlockRestrictedVarNDofs(), SystemsTest::testBoundaryProjectCube(), DofMapTest::testConstraintLoopDetection(), MeshInputTest::testCopyElementSolutionImpl(), MeshInputTest::testCopyElementVectorImpl(), MeshInputTest::testCopyNodalSolutionImpl(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), SystemsTest::testDofCouplingWithVarGroups(), MixedDimensionMeshTest::testDofOrdering(), MixedDimensionRefinedMeshTest::testDofOrdering(), MixedDimensionNonUniformRefinement::testDofOrdering(), MixedDimensionNonUniformRefinementTriangle::testDofOrdering(), MixedDimensionNonUniformRefinement3D::testDofOrdering(), DofMapTest::testDofOwner(), MeshInputTest::testDynaReadPatch(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), EquationSystemsTest::testInit(), MeshAssignTest::testMeshMoveAssign(), PeriodicBCTest::testPeriodicBC(), EquationSystemsTest::testPostInitAddElem(), EquationSystemsTest::testPostInitAddRealSystem(), EquationSystemsTest::testPostInitAddSystem(), SystemsTest::testPostInitAddVector(), SystemsTest::testPostInitAddVectorTypeChange(), SystemsTest::testProjectCube(), SystemsTest::testProjectCubeWithMeshFunction(), MeshInputTest::testProjectionRegression(), SystemsTest::testProjectLine(), SystemsTest::testProjectMatrix1D(), SystemsTest::testProjectMatrix2D(), SystemsTest::testProjectMatrix3D(), SystemsTest::testProjectSquare(), EquationSystemsTest::testRefineThenReinitPreserveFlags(), EquationSystemsTest::testReinitWithNodeElem(), EquationSystemsTest::testRepartitionThenReinit(), EquationSystemsTest::testSelectivePRefine(), MeshInputTest::testSingleElementImpl(), WriteVecAndScalar::testWriteExodus(), and WriteVecAndScalar::testWriteNemesis().

81 {
82  const unsigned int n_sys = this->n_systems();
83 
84  libmesh_assert_not_equal_to (n_sys, 0);
85 
86  // Tell all the \p DofObject entities how many systems
87  // there are.
88  for (auto & node : _mesh.node_ptr_range())
89  node->set_n_systems(n_sys);
90 
91  for (auto & elem : _mesh.element_ptr_range())
92  elem->set_n_systems(n_sys);
93 
94  for (auto i : make_range(this->n_systems()))
95  this->get_system(i).init();
96 
97 #ifdef LIBMESH_ENABLE_AMR
98  MeshRefinement mesh_refine(_mesh);
99  mesh_refine.clean_refinement_flags();
100 #endif
101 }
unsigned int n_systems() const
const T_sys & get_system(std::string_view name) const
MeshBase & _mesh
The mesh data structure.
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:134

◆ n_active_dofs()

std::size_t libMesh::EquationSystems::n_active_dofs ( ) const
Returns
The number of active degrees of freedom for the EquationSystems object.

Definition at line 1730 of file equation_systems.C.

References _systems.

Referenced by main(), and write_output_solvedata().

1731 {
1732  std::size_t tot=0;
1733 
1734  for (const auto & pr : _systems)
1735  tot += pr.second->n_active_dofs();
1736 
1737  return tot;
1738 }
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ n_dofs()

std::size_t libMesh::EquationSystems::n_dofs ( ) const
Returns
The total number of degrees of freedom in all systems.

Definition at line 1717 of file equation_systems.C.

References _systems.

Referenced by Biharmonic::JR::bounds(), and Biharmonic::JR::residual_and_jacobian().

1718 {
1719  std::size_t tot=0;
1720 
1721  for (const auto & pr : _systems)
1722  tot += pr.second->n_dofs();
1723 
1724  return tot;
1725 }
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ n_objects()

static unsigned int libMesh::ReferenceCounter::n_objects ( )
inlinestaticinherited

Prints the number of outstanding (created, but not yet destroyed) objects.

Definition at line 85 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

Referenced by libMesh::LibMeshInit::~LibMeshInit().

86  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects
The number of objects.

◆ n_processors()

processor_id_type libMesh::ParallelObject::n_processors ( ) const
inlineinherited
Returns
The number of processors in the group.

Definition at line 103 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, libMesh::libmesh_assert(), and TIMPI::Communicator::size().

Referenced by libMesh::Partitioner::_find_global_index_by_pid_map(), libMesh::BoundaryInfo::_find_id_maps(), libMesh::DofMap::add_constraints_to_send_list(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DistributedMesh::add_elem(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::System::add_vector(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::DofMap::allgather_recursive_constraints(), libMesh::FEMSystem::assembly(), libMesh::Nemesis_IO::assert_symmetric_cmaps(), libMesh::Partitioner::assign_partitioning(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), build_parallel_elemental_solution_vector(), libMesh::DistributedMesh::clear(), libMesh::DistributedMesh::clear_elems(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::Nemesis_IO::copy_scalar_solution(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_scalar_dofs(), libMesh::DistributedMesh::DistributedMesh(), libMesh::EnsightIO::EnsightIO(), libMesh::RBEIMEvaluation::gather_bfs(), libMesh::MeshBase::get_info(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::Nemesis_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::DistributedMesh::insert_elem(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_new_node_procids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_topology_consistent_procids< Node >(), libMesh::MeshTools::libmesh_assert_valid_boundary_ids(), libMesh::MeshTools::libmesh_assert_valid_dof_ids(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::MeshTools::libmesh_assert_valid_refinement_flags(), libMesh::DofMap::local_variable_indices(), libMesh::MeshRefinement::make_coarsening_compatible(), libMesh::MeshBase::n_active_elem_on_proc(), libMesh::MeshBase::n_elem_on_proc(), libMesh::MeshBase::n_nodes_on_proc(), libMesh::RBEIMEvaluation::node_gather_bfs(), libMesh::Partitioner::partition(), libMesh::MeshBase::partition(), libMesh::Partitioner::partition_unpartitioned_elements(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::DofMap::prepare_send_list(), libMesh::DofMap::print_dof_constraints(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::CheckpointIO::read(), libMesh::CheckpointIO::read_connectivity(), libMesh::XdrIO::read_header(), libMesh::CheckpointIO::read_nodes(), libMesh::System::read_parallel_data(), libMesh::System::read_SCALAR_dofs(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::System::read_serialized_vector(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::Partitioner::repartition(), OverlappingFunctorTest::run_partitioner_test(), libMesh::DofMap::scatter_constraints(), libMesh::DistributedMesh::set_next_unique_id(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), WriteVecAndScalar::setupTests(), libMesh::RBEIMEvaluation::side_gather_bfs(), DistributedMeshTest::testRemoteElemError(), CheckpointIOTest::testSplitter(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::VTKIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::System::write_parallel_data(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), and libMesh::XdrIO::write_serialized_nodesets().

104  {
105  processor_id_type returnval =
106  cast_int<processor_id_type>(_communicator.size());
107  libmesh_assert(returnval); // We never have an empty comm
108  return returnval;
109  }
const Parallel::Communicator & _communicator
processor_id_type size() const
uint8_t processor_id_type
libmesh_assert(ctx)

◆ n_systems()

unsigned int libMesh::EquationSystems::n_systems ( ) const
inline

◆ n_vars()

unsigned int libMesh::EquationSystems::n_vars ( ) const
Returns
The total number of variables in all systems.

Definition at line 1705 of file equation_systems.C.

References _systems.

Referenced by build_variable_names().

1706 {
1707  unsigned int tot=0;
1708 
1709  for (const auto & pr : _systems)
1710  tot += pr.second->n_vars();
1711 
1712  return tot;
1713 }
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

◆ print_info() [1/2]

void libMesh::ReferenceCounter::print_info ( std::ostream &  out_stream = libMesh::out)
staticinherited

Prints the reference information, by default to libMesh::out.

Definition at line 81 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter, and libMesh::ReferenceCounter::get_info().

Referenced by libMesh::LibMeshInit::~LibMeshInit().

82 {
84  out_stream << ReferenceCounter::get_info();
85 }
static std::string get_info()
Gets a string containing the reference information.
static bool _enable_print_counter
Flag to control whether reference count information is printed when print_info is called...

◆ print_info() [2/2]

void libMesh::EquationSystems::print_info ( std::ostream &  os = libMesh::out) const

Prints information about the equation systems, by default to libMesh::out.

Definition at line 1688 of file equation_systems.C.

References get_info().

Referenced by assemble_and_solve(), do_compare(), main(), and libMesh::operator<<().

1689 {
1690  os << this->get_info()
1691  << std::endl;
1692 }
virtual std::string get_info() const

◆ processor_id()

processor_id_type libMesh::ParallelObject::processor_id ( ) const
inlineinherited
Returns
The rank of this processor in the group.

Definition at line 114 of file parallel_object.h.

References libMesh::ParallelObject::_communicator, and TIMPI::Communicator::rank().

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DistributedMesh::add_elem(), libMesh::BoundaryInfo::add_elements(), libMesh::DofMap::add_neighbors_to_send_list(), libMesh::DistributedMesh::add_node(), libMesh::MeshTools::Modification::all_tri(), libMesh::DofMap::allgather_recursive_constraints(), libMesh::FEMSystem::assembly(), libMesh::Nemesis_IO::assert_symmetric_cmaps(), libMesh::Partitioner::assign_partitioning(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::Partitioner::build_graph(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), build_parallel_elemental_solution_vector(), build_parallel_solution_vector(), libMesh::DistributedMesh::clear(), libMesh::DistributedMesh::clear_elems(), libMesh::ExodusII_IO_Helper::close(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::compute_communication_map_parameters(), libMesh::Nemesis_IO_Helper::compute_internal_and_border_elems_and_internal_nodes(), libMesh::RBConstruction::compute_max_error_bound(), libMesh::Nemesis_IO_Helper::compute_node_communication_maps(), libMesh::Nemesis_IO_Helper::compute_num_global_elem_blocks(), libMesh::Nemesis_IO_Helper::compute_num_global_nodesets(), libMesh::Nemesis_IO_Helper::compute_num_global_sidesets(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::ExodusII_IO::copy_scalar_solution(), libMesh::Nemesis_IO::copy_scalar_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DofMap::distribute_scalar_dofs(), libMesh::DistributedMesh::DistributedMesh(), libMesh::DofMap::end_dof(), libMesh::DofMap::end_old_dof(), libMesh::EnsightIO::EnsightIO(), libMesh::GenericProjector< FFunctor, GFunctor, FValue, ProjectionAction >::SubFunctor::find_dofs_to_send(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::DofMap::first_dof(), libMesh::DofMap::first_old_dof(), libMesh::RBEIMEvaluation::gather_bfs(), libMesh::Nemesis_IO_Helper::get_cmap_params(), libMesh::Nemesis_IO_Helper::get_eb_info_global(), libMesh::Nemesis_IO_Helper::get_elem_cmap(), libMesh::Nemesis_IO_Helper::get_elem_map(), libMesh::MeshBase::get_info(), libMesh::DofMap::get_info(), libMesh::Nemesis_IO_Helper::get_init_global(), libMesh::Nemesis_IO_Helper::get_init_info(), libMesh::Nemesis_IO_Helper::get_loadbal_param(), libMesh::DofMap::get_local_constraints(), libMesh::Nemesis_IO_Helper::get_node_cmap(), libMesh::Nemesis_IO_Helper::get_node_map(), libMesh::Nemesis_IO_Helper::get_ns_param_global(), libMesh::Nemesis_IO_Helper::get_ss_param_global(), libMesh::SparsityPattern::Build::handle_vi_vj(), libMesh::LaplaceMeshSmoother::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), HeatSystem::init_data(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::initialize_element_variables(), libMesh::ExodusII_IO_Helper::initialize_global_variables(), libMesh::ExodusII_IO_Helper::initialize_nodal_variables(), libMesh::DistributedMesh::insert_elem(), libMesh::DofMap::is_evaluable(), libMesh::SparsityPattern::Build::join(), libMesh::TransientRBEvaluation::legacy_write_offline_data_to_files(), libMesh::RBSCMEvaluation::legacy_write_offline_data_to_files(), libMesh::RBEvaluation::legacy_write_offline_data_to_files(), libMesh::MeshTools::libmesh_assert_consistent_distributed(), libMesh::MeshTools::libmesh_assert_consistent_distributed_nodes(), libMesh::MeshTools::libmesh_assert_contiguous_dof_ids(), libMesh::MeshTools::libmesh_assert_parallel_consistent_procids< Elem >(), libMesh::MeshTools::libmesh_assert_valid_neighbors(), libMesh::DistributedMesh::libmesh_assert_valid_parallel_object_ids(), libMesh::DofMap::local_variable_indices(), main(), libMesh::MeshRefinement::make_coarsening_compatible(), AugmentSparsityOnInterface::mesh_reinit(), libMesh::TriangulatorInterface::MeshedHole::MeshedHole(), libMesh::MeshBase::n_active_local_elem(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::DofMap::n_local_dofs(), libMesh::System::n_local_dofs(), libMesh::MeshBase::n_local_elem(), libMesh::MeshBase::n_local_nodes(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::BoundaryInfo::n_shellface_conds(), libMesh::RBEIMEvaluation::node_gather_bfs(), libMesh::SparsityPattern::Build::operator()(), libMesh::DistributedMesh::own_node(), libMesh::BoundaryInfo::parallel_sync_node_ids(), libMesh::BoundaryInfo::parallel_sync_side_ids(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::DofMap::print_dof_constraints(), libMesh::DofMap::process_mesh_constraint_rows(), libMesh::Nemesis_IO_Helper::put_cmap_params(), libMesh::Nemesis_IO_Helper::put_elem_cmap(), libMesh::Nemesis_IO_Helper::put_elem_map(), libMesh::Nemesis_IO_Helper::put_loadbal_param(), libMesh::Nemesis_IO_Helper::put_node_cmap(), libMesh::Nemesis_IO_Helper::put_node_map(), libMesh::NameBasedIO::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read(), read(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::ExodusII_IO_Helper::read_global_values(), libMesh::ExodusII_IO::read_header(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::DynaIO::read_mesh(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::System::read_parallel_data(), libMesh::TransientRBConstruction::read_riesz_representors_from_files(), libMesh::RBConstruction::read_riesz_representors_from_files(), libMesh::System::read_SCALAR_dofs(), libMesh::XdrIO::read_serialized_bc_names(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::System::read_serialized_blocked_dof_objects(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::System::read_serialized_data(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::System::read_serialized_vector(), libMesh::System::read_serialized_vectors(), libMesh::Nemesis_IO_Helper::read_var_names_impl(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::DistributedMesh::renumber_nodes_and_elements(), libMesh::DofMap::scatter_constraints(), libMesh::CheckpointIO::select_split_config(), libMesh::DistributedMesh::set_next_unique_id(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::RBEIMEvaluation::side_gather_bfs(), ExodusTest< elem_type >::test_read_gold(), ExodusTest< elem_type >::test_write(), MeshInputTest::testAbaqusRead(), MeshInputTest::testCopyElementSolutionImpl(), MeshInputTest::testCopyElementVectorImpl(), MeshInputTest::testCopyNodalSolutionImpl(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), MeshInputTest::testDynaFileMappings(), MeshInputTest::testDynaNoSplines(), MeshInputTest::testDynaReadElem(), MeshInputTest::testDynaReadPatch(), MeshInputTest::testExodusFileMappings(), MeshInputTest::testExodusIGASidesets(), MeshInputTest::testExodusWriteElementDataFromDiscontinuousNodalData(), MeshInputTest::testLowOrderEdgeBlocks(), SystemsTest::testProjectMatrix1D(), SystemsTest::testProjectMatrix2D(), SystemsTest::testProjectMatrix3D(), BoundaryInfoTest::testShellFaceConstraints(), MeshInputTest::testSingleElementImpl(), WriteVecAndScalar::testSolution(), CheckpointIOTest::testSplitter(), MeshInputTest::testTetgenIO(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::DTKAdapter::update_variable_values(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), write(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO_Helper::write_element_values(), libMesh::ExodusII_IO_Helper::write_element_values_element_major(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO_Helper::write_elemset_data(), libMesh::ExodusII_IO_Helper::write_elemsets(), libMesh::ExodusII_IO::write_global_data(), libMesh::ExodusII_IO_Helper::write_global_values(), libMesh::System::write_header(), libMesh::ExodusII_IO::write_information_records(), libMesh::ExodusII_IO_Helper::write_information_records(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), libMesh::UCDIO::write_nodal_data(), libMesh::VTKIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::ExodusII_IO_Helper::write_nodeset_data(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::RBEIMEvaluation::write_out_interior_basis_functions(), libMesh::RBEIMEvaluation::write_out_node_basis_functions(), libMesh::RBEIMEvaluation::write_out_side_basis_functions(), write_output_solvedata(), libMesh::System::write_parallel_data(), libMesh::RBConstruction::write_riesz_representors_to_files(), libMesh::System::write_SCALAR_dofs(), libMesh::XdrIO::write_serialized_bc_names(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::System::write_serialized_blocked_dof_objects(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::System::write_serialized_data(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::System::write_serialized_vector(), libMesh::System::write_serialized_vectors(), libMesh::ExodusII_IO_Helper::write_sideset_data(), libMesh::Nemesis_IO_Helper::write_sidesets(), libMesh::ExodusII_IO_Helper::write_sidesets(), libMesh::ExodusII_IO::write_timestep(), libMesh::ExodusII_IO_Helper::write_timestep(), and libMesh::ExodusII_IO::write_timestep_discontinuous().

115  { return cast_int<processor_id_type>(_communicator.rank()); }
processor_id_type rank() const
const Parallel::Communicator & _communicator

◆ read() [1/3]

template<typename InValType >
void libMesh::EquationSystems::read ( std::string_view  name,
const XdrMODE  mode,
const unsigned int  read_flags = (READ_HEADER | READ_DATA),
bool  partition_agnostic = true 
)

Read & initialize the systems from disk using the XDR data format.

This format allows for machine-independent binary output.

Set which sections of the file to read by bitwise OR'ing the EquationSystems::ReadFlags enumeration together. For example, to read all sections of the file, set read_flags to: (READ_HEADER | READ_DATA | READ_ADDITIONAL_DATA)

Note
The equation system can be defined without initializing the data vectors to any solution values. This can be done by omitting READ_DATA in the read_flags parameter.

If XdrMODE is omitted, it will be inferred as READ for filenames containing .xda or as DECODE for filenames containing .xdr

Parameters
nameName of the file to be read.
read_flagsSingle flag created by bitwise-OR'ing several flags together.
modeControls whether reading is done in binary or ascii mode.
partition_agnosticIf true then the mesh and degrees of freedom will be temporarily renumbered in a partition agnostic way so that files written using "n" mpi processes can be re-read on "m" mpi processes. This renumbering is not compatible with meshes that have two nodes in exactly the same position!

Definition at line 89 of file equation_systems_io.C.

References libMesh::Quality::name(), and libMesh::ParallelObject::processor_id().

Referenced by main(), read(), libMesh::FileHistoryData::retrieve_adjoint_solution(), libMesh::FileHistoryData::retrieve_primal_solution(), and SlitMeshRefinedSystemTest::testRestart().

93 {
94  // This will unzip a file with .bz2 as the extension, otherwise it
95  // simply returns the name if the file need not be unzipped.
96  Xdr io ((this->processor_id() == 0) ? std::string(name) : "", mode);
97 
98  std::function<std::unique_ptr<Xdr>()> local_io_functor;
99  local_io_functor = [this,&name,&mode]() {
100  return std::make_unique<Xdr>(local_file_name(this->processor_id(), name), mode); };
101 
102  this->read(io, local_io_functor, read_flags, partition_agnostic);
103 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
void read(std::string_view name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
Read & initialize the systems from disk using the XDR data format.
processor_id_type processor_id() const

◆ read() [2/3]

template<typename InValType >
void libMesh::EquationSystems::read ( std::string_view  name,
const unsigned int  read_flags = (READ_HEADER | READ_DATA),
bool  partition_agnostic = true 
)

Definition at line 76 of file equation_systems_io.C.

References libMesh::DECODE, libMesh::Quality::name(), libMesh::READ, and read().

79 {
80  XdrMODE mode = READ;
81  if (name.find(".xdr") != std::string::npos)
82  mode = DECODE;
83  this->read(name, mode, read_flags, partition_agnostic);
84 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:35
void read(std::string_view name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
Read & initialize the systems from disk using the XDR data format.

◆ read() [3/3]

template<typename InValType >
void libMesh::EquationSystems::read ( Xdr io,
std::function< std::unique_ptr< Xdr >()> &  local_io_functor,
const unsigned int  read_flags = (READ_HEADER | READ_DATA),
bool  partition_agnostic = true 
)


This program implements the output of an EquationSystems object. This warrants some documentation. The output file essentially consists of 11 sections:

1.) A version header (for non-'legacy' formats, libMesh-0.7.0 and greater).
2.) The number of individual equation systems (unsigned int)

for each system

3.)  The name of the system (string)
4.)  The type of the system (string)

handled through System::read():

+-------------------------------------------------------------+
|  5.) The number of variables in the system (unsigned int)   |
|                                                             |
|   for each variable in the system                           |
|                                                             |
|    6.) The name of the variable (string)                    |
|                                                             |
|    7.) Combined in an FEType:                               |
|         - The approximation order(s) of the variable (Order |
|           Enum, cast to int/s)                              |
|         - The finite element family/ies of the variable     |
|           (FEFamily Enum, cast to int/s)                    |
|                                                             |
|   end variable loop                                         |
|                                                             |
| 8.) The number of additional vectors (unsigned int),        |
|                                                             |
|    for each additional vector in the equation system object |
|                                                             |
|    9.) the name of the additional vector  (string)          |
+-------------------------------------------------------------+

end system loop


for each system, handled through System::read_{serialized,parallel}_data():

+--------------------------------------------------------------+
| 10.) The global solution vector, re-ordered to be node-major |
|     (More on this later.)                                    |
|                                                              |
|    for each additional vector in the equation system object  |
|                                                              |
|    11.) The global additional vector, re-ordered to be       |
|         node-major (More on this later.)                     |
+--------------------------------------------------------------+

end system loop

Note that the actual IO is handled through the Xdr class (to be renamed later?) which provides a uniform interface to both the XDR (eXternal Data Representation) interface and standard ASCII output. Thus this one section of code will read XDR or ASCII files with no changes.

Definition at line 108 of file equation_systems_io.C.

References _mesh, add_system(), TIMPI::Communicator::broadcast(), libMesh::MeshRefinement::clean_refinement_flags(), libMesh::Xdr::close(), libMesh::ParallelObject::comm(), libMesh::Xdr::data(), libMesh::MeshBase::fix_broken_node_and_element_numbering(), get_mesh(), get_system(), libMesh::MeshTools::Private::globally_renumber_nodes_and_elements(), init(), libMesh::libmesh_assert(), mesh, libMesh::ParallelObject::processor_id(), read(), READ_ADDITIONAL_DATA, READ_BASIC_ONLY, READ_DATA, READ_HEADER, libMesh::System::read_header(), READ_LEGACY_FORMAT, libMesh::Xdr::reading(), libMesh::System::set_basic_system_only(), libMesh::Xdr::set_version(), TRY_READ_IFEMS, and update().

112 {
176  // Set booleans from the read_flags argument
177  const bool read_header = read_flags & EquationSystems::READ_HEADER;
178  const bool read_data = read_flags & EquationSystems::READ_DATA;
179  const bool read_additional_data = read_flags & EquationSystems::READ_ADDITIONAL_DATA;
180  const bool read_legacy_format = read_flags & EquationSystems::READ_LEGACY_FORMAT;
181  const bool try_read_ifems = read_flags & EquationSystems::TRY_READ_IFEMS;
182  const bool read_basic_only = read_flags & EquationSystems::READ_BASIC_ONLY;
183  bool read_parallel_files = false;
184 
185  std::vector<std::pair<std::string, System *>> xda_systems;
186 
187  libmesh_assert (io.reading());
188 
189  {
190  // 1.)
191  // Read the version header.
192  std::string version = "legacy";
193  if (!read_legacy_format)
194  {
195  if (this->processor_id() == 0) io.data(version);
196  this->comm().broadcast(version);
197 
198  // All processors have the version header, if it does not contain
199  // the libMesh_label string then it is a legacy file.
200  const std::string libMesh_label = "libMesh-";
201  std::string::size_type lm_pos = version.find(libMesh_label);
202  if (lm_pos==std::string::npos)
203  {
204  io.close();
205 
206  // Recursively call this read() function but with the
207  // EquationSystems::READ_LEGACY_FORMAT bit set.
208  this->read (io, local_io_functor, (read_flags | EquationSystems::READ_LEGACY_FORMAT), partition_agnostic);
209  return;
210  }
211 
212  // Figure out the libMesh version that created this file
213  std::istringstream iss(version.substr(lm_pos + libMesh_label.size()));
214  int ver_major = 0, ver_minor = 0, ver_patch = 0;
215  char dot;
216  iss >> ver_major >> dot >> ver_minor >> dot >> ver_patch;
217  io.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch));
218 
219 
220  read_parallel_files = (version.rfind(" parallel") < version.size());
221 
222  // If requested that we try to read infinite element information,
223  // and the string " with infinite elements" is not in the version,
224  // then tack it on. This is for compatibility reading ifem
225  // files written prior to 11/10/2008 - BSK
226  if (try_read_ifems)
227  if (!(version.rfind(" with infinite elements") < version.size()))
228  version += " with infinite elements";
229 
230  }
231  else
232  libmesh_deprecated();
233 
234  LOG_SCOPE("read()", "EquationSystems");
235 
236  // 2.)
237  // Read the number of equation systems
238  unsigned int n_sys=0;
239  if (this->processor_id() == 0) io.data (n_sys);
240  this->comm().broadcast(n_sys);
241 
242  for (unsigned int sys=0; sys<n_sys; sys++)
243  {
244  // 3.)
245  // Read the name of the sys-th equation system
246  std::string sys_name;
247  if (this->processor_id() == 0) io.data (sys_name);
248  this->comm().broadcast(sys_name);
249 
250  // 4.)
251  // Read the type of the sys-th equation system
252  std::string sys_type;
253  if (this->processor_id() == 0) io.data (sys_type);
254  this->comm().broadcast(sys_type);
255 
256  if (read_header)
257  this->add_system (sys_type, sys_name);
258 
259  // 5.) - 9.)
260  // Let System::read_header() do the job
261  System & new_system = this->get_system(sys_name);
262  new_system.read_header (io,
263  version,
264  read_header,
265  read_additional_data,
266  read_legacy_format);
267 
268  xda_systems.emplace_back(sys_name, &new_system);
269 
270  // If we're only creating "basic" systems, we need to tell
271  // each system that before we call init() later.
272  if (read_basic_only)
273  new_system.set_basic_system_only();
274  }
275  }
276 
277 
278 
279  // Now we are ready to initialize the underlying data
280  // structures. This will initialize the vectors for
281  // storage, the dof_map, etc...
282  if (read_header)
283  this->init();
284 
285  // 10.) & 11.)
286  // Read and set the numeric vector values
287  if (read_data)
288  {
289  std::unique_ptr<Xdr> local_io;
290 
291  // the EquationSystems::read() method should look constant from the mesh
292  // perspective, but we need to assign a temporary numbering to the nodes
293  // and elements in the mesh, which requires that we abuse const_cast
294  if (!read_legacy_format && partition_agnostic)
295  {
296  MeshBase & mesh = const_cast<MeshBase &>(this->get_mesh());
298  }
299 
300  for (auto & pr : xda_systems)
301  if (read_legacy_format)
302  {
303  libmesh_deprecated();
304 #ifdef LIBMESH_ENABLE_DEPRECATED
305  pr.second->read_legacy_data (io, read_additional_data);
306 #endif
307  }
308  else
309  if (read_parallel_files)
310  {
311  if (!local_io)
312  {
313  local_io = local_io_functor();
314  libmesh_assert(local_io->reading());
315  }
316  pr.second->read_parallel_data<InValType> (*local_io, read_additional_data);
317  }
318  else
319  pr.second->read_serialized_data<InValType> (io, read_additional_data);
320 
321 
322  // Undo the temporary numbering.
323  if (!read_legacy_format && partition_agnostic)
325  }
326 
327  // Localize each system's data
328  this->update();
329 
330  #ifdef LIBMESH_ENABLE_AMR
331  MeshRefinement mesh_refine(_mesh);
332  mesh_refine.clean_refinement_flags();
333  #endif
334 }
MeshBase & mesh
const Parallel::Communicator & comm() const
virtual void fix_broken_node_and_element_numbering()=0
There is no reason for a user to ever call this function.
const T_sys & get_system(std::string_view name) const
MeshBase & _mesh
The mesh data structure.
libmesh_assert(ctx)
void read(std::string_view name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
Read & initialize the systems from disk using the XDR data format.
void globally_renumber_nodes_and_elements(MeshBase &)
There is no reason for a user to ever call this function.
Definition: mesh_tools.C:2376
void broadcast(T &data, const unsigned int root_id=0, const bool identical_sizes=false) const
const MeshBase & get_mesh() const
virtual void init()
Initialize all the systems.
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.
processor_id_type processor_id() const
void update()
Updates local values for all the systems.

◆ redundant_added_side()

bool libMesh::EquationSystems::redundant_added_side ( const Elem elem,
unsigned int  side 
)
static

Definition at line 1575 of file equation_systems.C.

References libMesh::Elem::active(), libMesh::DofObject::id(), libMesh::libmesh_assert(), libMesh::Elem::neighbor_ptr(), and libMesh::remote_elem.

Referenced by build_parallel_solution_vector(), libMesh::ExodusII_IO_Helper::initialize(), libMesh::ExodusII_IO_Helper::write_elements(), libMesh::ExodusII_IO_Helper::write_nodal_coordinates(), and libMesh::ExodusII_IO::write_nodal_data().

1576 {
1577  libmesh_assert(elem.active());
1578 
1579  const Elem * neigh = elem.neighbor_ptr(side);
1580 
1581  // Write boundary sides.
1582  if (!neigh)
1583  return false;
1584 
1585  // Write ghost sides in Nemesis
1586  if (neigh == remote_elem)
1587  return false;
1588 
1589  // Don't write a coarser side if a finer side exists
1590  if (!neigh->active())
1591  return true;
1592 
1593  // Don't write a side redundantly from both of the
1594  // elements sharing it. We'll disambiguate with id().
1595  return (neigh->id() < elem.id());
1596 }
libmesh_assert(ctx)
const RemoteElem * remote_elem
Definition: remote_elem.C:54

◆ refine_in_reinit_flag()

bool libMesh::EquationSystems::refine_in_reinit_flag ( )
inline
Returns
Whether or not calls to reinit() will try to coarsen/refine the mesh

Definition at line 577 of file equation_systems.h.

References _refine_in_reinit.

577 { return this->_refine_in_reinit; }
bool _refine_in_reinit
Flag for whether to call coarsen/refine in reinit().

◆ reinit()

void libMesh::EquationSystems::reinit ( )
virtual

Handle any mesh changes and reinitialize all the systems on the updated mesh.

Definition at line 105 of file equation_systems.C.

References reinit_solutions(), and reinit_systems().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), assemble_and_solve(), libMesh::AdjointRefinementEstimator::estimate_error(), main(), run_timestepping(), SystemsTest::test2DProjectVectorFE(), SystemsTest::test3DProjectVectorFE(), EquationSystemsTest::testBadVarNames(), MeshAssignTest::testMeshMoveAssign(), EquationSystemsTest::testPostInitAddElem(), EquationSystemsTest::testPostInitAddRealSystem(), EquationSystemsTest::testPostInitAddSystem(), SystemsTest::testProjectCube(), SystemsTest::testProjectLine(), SystemsTest::testProjectSquare(), InfFERadialTest::testRefinement(), EquationSystemsTest::testRefineThenReinitPreserveFlags(), EquationSystemsTest::testReinitWithNodeElem(), EquationSystemsTest::testRepartitionThenReinit(), and EquationSystemsTest::testSelectivePRefine().

106 {
107  const bool mesh_changed = this->reinit_solutions();
108 
109  // If the mesh has changed, systems will need to reinitialize their
110  // own data on the new mesh.
111  if (mesh_changed)
112  this->reinit_systems();
113 }
bool reinit_solutions()
Handle any mesh changes and project any solutions onto the updated mesh.
virtual void reinit_systems()
Reinitialize all systems on the current mesh.

◆ reinit_mesh()

void libMesh::EquationSystems::reinit_mesh ( )
virtual

Handle the association of a completely new mesh with the EquationSystem and all the Systems assigned to it.

Definition at line 115 of file equation_systems.C.

References _mesh, libMesh::MeshRefinement::clean_refinement_flags(), get_system(), libMesh::make_range(), and n_systems().

Referenced by MeshAssignTest::testMeshMoveAssign().

116 {
117  const unsigned int n_sys = this->n_systems();
118 
119  libmesh_assert_not_equal_to (n_sys, 0);
120 
121  // Tell all the \p DofObject entities how many systems
122  // there are.
123  for (auto & node : _mesh.node_ptr_range())
124  node->set_n_systems(n_sys);
125 
126  for (auto & elem : _mesh.element_ptr_range())
127  elem->set_n_systems(n_sys);
128 
129  //for (auto i : make_range(this->n_systems()))
130  //this->get_system(i).init();
131 
132 #ifdef LIBMESH_ENABLE_AMR
133  MeshRefinement mesh_refine(_mesh);
134  mesh_refine.clean_refinement_flags();
135 #endif
136 
137  // Now loop over all the systems belonging to this ES
138  // and call reinit_mesh for each system
139  for (auto i : make_range(this->n_systems()))
140  this->get_system(i).reinit_mesh();
141 
142 }
unsigned int n_systems() const
const T_sys & get_system(std::string_view name) const
MeshBase & _mesh
The mesh data structure.
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:134

◆ reinit_solutions()

bool libMesh::EquationSystems::reinit_solutions ( )

Handle any mesh changes and project any solutions onto the updated mesh.

Returns
Whether or not the mesh may have changed.

Definition at line 144 of file equation_systems.C.

References _mesh, _refine_in_reinit, libMesh::MeshRefinement::coarsen_elements(), libMesh::MeshBase::contract(), libMesh::DofMap::distribute_dofs(), libMesh::MeshRefinement::face_level_mismatch_limit(), libMesh::System::get_dof_map(), get_mesh(), get_system(), libMesh::make_range(), n_systems(), libMesh::MeshRefinement::overrefined_boundary_limit(), libMesh::DofMap::prepare_send_list(), libMesh::System::prolong_vectors(), libMesh::MeshRefinement::refine_elements(), libMesh::System::reinit_constraints(), libMesh::System::restrict_vectors(), and libMesh::MeshRefinement::underrefined_boundary_limit().

Referenced by reinit().

145 {
146  parallel_object_only();
147 
148  const unsigned int n_sys = this->n_systems();
149  libmesh_assert_not_equal_to (n_sys, 0);
150 
151  // And any new systems will need initialization
152  for (unsigned int i=0; i != n_sys; ++i)
153  if (!this->get_system(i).is_initialized())
154  this->get_system(i).init();
155 
156  // We used to assert that all nodes and elements *already* had
157  // n_systems() properly set; however this is false in the case where
158  // user code has manually added nodes and/or elements to an
159  // already-initialized system.
160 
161  // Make sure all the \p DofObject entities know how many systems
162  // there are.
163  {
164  // All the nodes
165  for (auto & node : _mesh.node_ptr_range())
166  node->set_n_systems(n_sys);
167 
168  // All the elements
169  for (auto & elem : _mesh.element_ptr_range())
170  elem->set_n_systems(n_sys);
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 
198  sys.get_dof_map().distribute_dofs(_mesh);
199 
200  // Recreate any user or internal constraints
201  sys.reinit_constraints();
202 
203  sys.get_dof_map().prepare_send_list();
204 
205  sys.prolong_vectors();
206  }
207  mesh_changed = true;
208  }
209 
210  if (this->_refine_in_reinit)
211  {
212  // Don't override any user refinement settings
213  MeshRefinement mesh_refine(_mesh);
214  mesh_refine.face_level_mismatch_limit() = 0; // unlimited
215  mesh_refine.overrefined_boundary_limit() = -1; // unlimited
216  mesh_refine.underrefined_boundary_limit() = -1; // unlimited
217 
218  // Try to coarsen the mesh, then restrict each system's vectors
219  // if necessary
220  if (mesh_refine.coarsen_elements())
221  {
222  for (auto i : make_range(this->n_systems()))
223  {
224  System & sys = this->get_system(i);
225  sys.get_dof_map().distribute_dofs(_mesh);
226  sys.reinit_constraints();
227  sys.get_dof_map().prepare_send_list();
228  sys.restrict_vectors();
229  }
230  mesh_changed = true;
231  }
232 
233  // Once vectors are all restricted, we can delete
234  // children of coarsened elements
235  if (mesh_changed)
236  this->get_mesh().contract();
237 
238  // Try to refine the mesh, then prolong each system's vectors
239  // if necessary
240  if (mesh_refine.refine_elements())
241  {
242  for (auto i : make_range(this->n_systems()))
243  {
244  System & sys = this->get_system(i);
245  sys.get_dof_map().distribute_dofs(_mesh);
246  sys.reinit_constraints();
247  sys.get_dof_map().prepare_send_list();
248  sys.prolong_vectors();
249  }
250  mesh_changed = true;
251  }
252  }
253 
254  return mesh_changed;
255 
256 #endif // #ifdef LIBMESH_ENABLE_AMR
257 
258  return false;
259 }
unsigned int n_systems() const
const T_sys & get_system(std::string_view name) const
MeshBase & _mesh
The mesh data structure.
bool _refine_in_reinit
Flag for whether to call coarsen/refine in reinit().
virtual bool contract()=0
Delete subactive (i.e.
const MeshBase & get_mesh() const
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:134

◆ reinit_systems()

void libMesh::EquationSystems::reinit_systems ( )
virtual

Reinitialize all systems on the current mesh.

Definition at line 263 of file equation_systems.C.

References get_system(), libMesh::make_range(), and n_systems().

Referenced by reinit().

264 {
265  for (auto i : make_range(this->n_systems()))
266  this->get_system(i).reinit();
267 }
unsigned int n_systems() const
const T_sys & get_system(std::string_view name) const
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:134

◆ sensitivity_solve()

void libMesh::EquationSystems::sensitivity_solve ( const ParameterVector parameters)
virtual

Call sensitivity_solve on all the individual equation systems.

By default this function solves each sensitivity system once, in the order in which in which they were added. For more sophisticated decoupled problems the user may with to override this behavior in a derived class.

Definition at line 434 of file equation_systems.C.

References get_system(), libMesh::libmesh_assert(), libMesh::make_range(), and n_systems().

435 {
436  libmesh_assert (this->n_systems());
437 
438  for (auto i : make_range(this->n_systems()))
439  this->get_system(i).sensitivity_solve(parameters_in);
440 }
unsigned int n_systems() const
const T_sys & get_system(std::string_view name) const
libmesh_assert(ctx)
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:134

◆ solve()

void libMesh::EquationSystems::solve ( )
virtual

Call solve on all the individual equation systems.

By default this function solves each equation system once, in the order they were added. For more sophisticated decoupled problems the user may with to override this behavior in a derived class.

Definition at line 424 of file equation_systems.C.

References get_system(), libMesh::libmesh_assert(), libMesh::make_range(), and n_systems().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error().

425 {
426  libmesh_assert (this->n_systems());
427 
428  for (auto i : make_range(this->n_systems()))
429  this->get_system(i).solve();
430 }
unsigned int n_systems() const
const T_sys & get_system(std::string_view name) const
libmesh_assert(ctx)
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:134

◆ update()

void libMesh::EquationSystems::update ( )

Updates local values for all the systems.

Definition at line 331 of file equation_systems.C.

References get_system(), libMesh::make_range(), and n_systems().

Referenced by main(), and read().

332 {
333  LOG_SCOPE("update()", "EquationSystems");
334 
335  // Localize each system's vectors
336  for (auto i : make_range(this->n_systems()))
337  this->get_system(i).update();
338 }
unsigned int n_systems() const
const T_sys & get_system(std::string_view name) const
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:134

◆ write() [1/4]

void libMesh::EquationSystems::write ( std::string_view  name,
const XdrMODE  mode,
const unsigned int  write_flags = (WRITE_DATA),
bool  partition_agnostic = true 
) const

Write the systems to disk using the XDR data format.

This format allows for machine-independent binary output.

Set the writing properties using the EquationSystems::WriteFlags enumeration. Set which sections to write out by bitwise OR'ing the enumeration values. Write everything by setting write_flags to: (WRITE_DATA | WRITE_ADDITIONAL_DATA)

Note
The solution data can be omitted by calling this routine with WRITE_DATA omitted in the write_flags argument.

If XdrMODE is omitted, it will be inferred as WRITE for filenames containing .xda or as ENCODE for filenames containing .xdr

Parameters
nameName of the file to be read.
write_flagsSingle flag created by bitwise-OR'ing several flags together.
modeControls whether reading is done in binary or ascii mode.
partition_agnosticIf true then the mesh and degrees of freedom will be temporarily renumbered in a partition agnostic way so that files written using "n" mpi processes can be re-read on "m" mpi processes. This renumbering is not compatible with meshes that have two nodes in exactly the same position!

Definition at line 350 of file equation_systems_io.C.

References libMesh::Quality::name(), libMesh::ParallelObject::processor_id(), WRITE_DATA, and WRITE_PARALLEL_FILES.

Referenced by main(), libMesh::ErrorVector::plot_error(), libMesh::FileHistoryData::rewrite_stored_solution(), libMesh::FileHistoryData::store_adjoint_solution(), libMesh::FileHistoryData::store_initial_solution(), libMesh::FileHistoryData::store_primal_solution(), write(), libMesh::NameBasedIO::write_equation_systems(), and write_output().

354 {
355  Xdr io((this->processor_id()==0) ? std::string(name) : "", mode);
356 
357  std::unique_ptr<Xdr> local_io;
358  // open a parallel buffer if warranted
359  if (write_flags & EquationSystems::WRITE_PARALLEL_FILES && write_flags & EquationSystems::WRITE_DATA)
360  local_io = std::make_unique<Xdr>(local_file_name(this->processor_id(),name), mode);
361 
362  this->write(io, write_flags, partition_agnostic, local_io.get());
363 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
void write(std::string_view name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
Write the systems to disk using the XDR data format.
processor_id_type processor_id() const

◆ write() [2/4]

void libMesh::EquationSystems::write ( std::string_view  name,
const unsigned int  write_flags = (WRITE_DATA),
bool  partition_agnostic = true 
) const

Definition at line 338 of file equation_systems_io.C.

References libMesh::ENCODE, libMesh::Quality::name(), libMesh::WRITE, and write().

341 {
342  XdrMODE mode = WRITE;
343  if (name.find(".xdr") != std::string::npos)
344  mode = ENCODE;
345  this->write(name, mode, write_flags, partition_agnostic);
346 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
void write(std::string_view name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
Write the systems to disk using the XDR data format.
XdrMODE
Defines an enum for read/write mode in Xdr format.
Definition: enum_xdr_mode.h:35

◆ write() [3/4]

void libMesh::EquationSystems::write ( std::ostream  name,
const unsigned int  write_flags = (WRITE_DATA),
bool  partition_agnostic = true 
) const

◆ write() [4/4]

void libMesh::EquationSystems::write ( Xdr io,
const unsigned int  write_flags = (WRITE_DATA),
bool  partition_agnostic = true,
Xdr *const  local_io = nullptr 
) const


This program implements the output of an EquationSystems object. This warrants some documentation. The output file essentially consists of 11 sections:

1.) The version header.
2.) The number of individual equation systems (unsigned int)

for each system

3.)  The name of the system (string)
4.)  The type of the system (string)

handled through System::read():

+-------------------------------------------------------------+
|  5.) The number of variables in the system (unsigned int)   |
|                                                             |
|   for each variable in the system                           |
|                                                             |
|    6.) The name of the variable (string)                    |
|                                                             |
|    7.) Combined in an FEType:                               |
|         - The approximation order(s) of the variable (Order |
|           Enum, cast to int/s)                              |
|         - The finite element family/ies of the variable     |
|           (FEFamily Enum, cast to int/s)                    |
|                                                             |
|   end variable loop                                         |
|                                                             |
| 8.) The number of additional vectors (unsigned int),        |
|                                                             |
|    for each additional vector in the equation system object |
|                                                             |
|    9.) the name of the additional vector  (string)          |
+-------------------------------------------------------------+

end system loop


for each system, handled through System::write_{serialized,parallel}_data():

+--------------------------------------------------------------+
| 10.) The global solution vector, re-ordered to be node-major |
|     (More on this later.)                                    |
|                                                              |
|    for each additional vector in the equation system object  |
|                                                              |
|    11.) The global additional vector, re-ordered to be       |
|         node-major (More on this later.)                     |
+--------------------------------------------------------------+

end system loop

Note that the actual IO is handled through the Xdr class (to be renamed later?) which provides a uniform interface to both the XDR (eXternal Data Representation) interface and standard ASCII output. Thus this one section of code will write XDR or ASCII files with no changes.

Definition at line 367 of file equation_systems_io.C.

References _mesh, _systems, libMesh::Xdr::close(), libMesh::Xdr::data(), libMesh::get_io_compatibility_version(), get_mesh(), libMesh::MeshTools::Private::globally_renumber_nodes_and_elements(), libMesh::libmesh_assert(), mesh, libMesh::ParallelObject::processor_id(), libMesh::Xdr::set_version(), WRITE_ADDITIONAL_DATA, WRITE_DATA, WRITE_PARALLEL_FILES, and libMesh::Xdr::writing().

371 {
435  // the EquationSystems::write() method should look constant,
436  // but we need to assign a temporary numbering to the nodes
437  // and elements in the mesh, which requires that we abuse const_cast
438  if (partition_agnostic)
439  {
440  MeshBase & mesh = const_cast<MeshBase &>(this->get_mesh());
442  }
443 
444  // set booleans from write_flags argument
445  const bool write_data = write_flags & EquationSystems::WRITE_DATA;
446  const bool write_additional_data = write_flags & EquationSystems::WRITE_ADDITIONAL_DATA;
447 
448  // always write parallel files if we're instructed to write in
449  // parallel
450  const bool write_parallel_files =
452  // Even if we're on a distributed mesh, we may or may not have a
453  // consistent way of reconstructing the same mesh partitioning
454  // later, but we need the same mesh partitioning if we want to
455  // reread the parallel solution safely, so let's write a serial file
456  // unless specifically requested not to.
457  // ||
458  // // but also write parallel files if we haven't been instructed to
459  // // write in serial and we're on a distributed mesh
460  // (!(write_flags & EquationSystems::WRITE_SERIAL_FILES) &&
461  // !this->get_mesh().is_serial())
462  ;
463 
464  if (write_parallel_files && write_data)
465  libmesh_assert(local_io);
466 
467  {
468  libmesh_assert (io.writing());
469 
470  LOG_SCOPE("write()", "EquationSystems");
471 
472  const unsigned int proc_id = this->processor_id();
473 
474  unsigned int n_sys = 0;
475  for (auto & pr : _systems)
476  if (!pr.second->hide_output())
477  n_sys++;
478 
479  // set the version number in the Xdr object
480  io.set_version(LIBMESH_VERSION_ID(LIBMESH_MAJOR_VERSION,
481  LIBMESH_MINOR_VERSION,
482  LIBMESH_MICRO_VERSION));
483 
484  // Only write the header information
485  // if we are processor 0.
486  if (proc_id == 0)
487  {
488  std::string comment;
489 
490  // 1.)
491  // Write the version header
492  std::string version("libMesh-" + libMesh::get_io_compatibility_version());
493  if (write_parallel_files) version += " parallel";
494 
495 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
496  version += " with infinite elements";
497 #endif
498  io.data (version, "# File Format Identifier");
499 
500  // 2.)
501  // Write the number of equation systems
502  io.data (n_sys, "# No. of Equation Systems");
503 
504  for (auto & [sys_name, sys] : _systems)
505  {
506  // Ignore this system if it has been marked as hidden
507  if (sys->hide_output()) continue;
508 
509  // 3.)
510  // Write the name of the sys_num-th system
511  {
512  const unsigned int sys_num = sys->number();
513 
514  comment = "# Name, System No. ";
515  comment += std::to_string(sys_num);
516 
517  // Note: There is no Xdr::data overload taking a "const
518  // std::string &" so we need to make a copy.
519  std::string copy = sys_name;
520  io.data (copy, comment);
521  }
522 
523  // 4.)
524  // Write the type of system handled
525  {
526  const unsigned int sys_num = sys->number();
527  std::string sys_type = sys->system_type();
528 
529  comment = "# Type, System No. ";
530  comment += std::to_string(sys_num);
531 
532  io.data (sys_type, comment);
533  }
534 
535  // 5.) - 9.)
536  // Let System::write_header() do the job
537  sys->write_header (io, version, write_additional_data);
538  }
539  }
540 
541  // Start from the first system, again,
542  // to write vectors to disk, if wanted
543  if (write_data)
544  {
545  for (auto & pr : _systems)
546  {
547  // Ignore this system if it has been marked as hidden
548  if (pr.second->hide_output()) continue;
549 
550  // 10.) + 11.)
551  if (write_parallel_files)
552  pr.second->write_parallel_data (*local_io,write_additional_data);
553  else
554  pr.second->write_serialized_data (io,write_additional_data);
555  }
556 
557  if (local_io)
558  local_io->close();
559  }
560 
561  io.close();
562  }
563 
564  // the EquationSystems::write() method should look constant,
565  // but we need to undo the temporary numbering of the nodes
566  // and elements in the mesh, which requires that we abuse const_cast
567  if (partition_agnostic)
568  const_cast<MeshBase &>(_mesh).fix_broken_node_and_element_numbering();
569 }
MeshBase & mesh
MeshBase & _mesh
The mesh data structure.
std::string get_io_compatibility_version()
Specifier for I/O file compatibility features.
libmesh_assert(ctx)
void globally_renumber_nodes_and_elements(MeshBase &)
There is no reason for a user to ever call this function.
Definition: mesh_tools.C:2376
const MeshBase & get_mesh() const
processor_id_type processor_id() const
std::map< std::string, std::unique_ptr< System >, std::less<> > _systems
Data structure holding the systems.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  os,
const EquationSystems es 
)
friend

Same as above, but allows you to also use stream syntax.

Definition at line 1696 of file equation_systems.C.

1698 {
1699  es.print_info(os);
1700  return os;
1701 }

Member Data Documentation

◆ _communicator

const Parallel::Communicator& libMesh::ParallelObject::_communicator
protectedinherited

◆ _counts

ReferenceCounter::Counts libMesh::ReferenceCounter::_counts
staticprotectedinherited

Actually holds the data.

Definition at line 124 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::get_info().

◆ _enable_default_ghosting

bool libMesh::EquationSystems::_enable_default_ghosting
protected

Flag for whether to enable default ghosting on newly added Systems.

Default value: true

Definition at line 621 of file equation_systems.h.

Referenced by add_system(), and enable_default_ghosting().

◆ _enable_print_counter

bool libMesh::ReferenceCounter::_enable_print_counter = true
staticprotectedinherited

Flag to control whether reference count information is printed when print_info is called.

Definition at line 143 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::disable_print_counter_info(), libMesh::ReferenceCounter::enable_print_counter_info(), and libMesh::ReferenceCounter::print_info().

◆ _mesh

MeshBase& libMesh::EquationSystems::_mesh
protected

◆ _mutex

Threads::spin_mutex libMesh::ReferenceCounter::_mutex
staticprotectedinherited

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 137 of file reference_counter.h.

◆ _n_objects

Threads::atomic< unsigned int > libMesh::ReferenceCounter::_n_objects
staticprotectedinherited

The number of objects.

Print the reference count information when the number returns to 0.

Definition at line 132 of file reference_counter.h.

Referenced by libMesh::ReferenceCounter::n_objects(), libMesh::ReferenceCounter::ReferenceCounter(), and libMesh::ReferenceCounter::~ReferenceCounter().

◆ _refine_in_reinit

bool libMesh::EquationSystems::_refine_in_reinit
protected

Flag for whether to call coarsen/refine in reinit().

Default value: true

Definition at line 615 of file equation_systems.h.

Referenced by disable_refine_in_reinit(), enable_refine_in_reinit(), refine_in_reinit_flag(), and reinit_solutions().

◆ _systems

std::map<std::string, std::unique_ptr<System>, std::less<> > libMesh::EquationSystems::_systems
protected

◆ parameters

Parameters libMesh::EquationSystems::parameters

Data structure holding arbitrary parameters.

Definition at line 595 of file equation_systems.h.

Referenced by add_M_C_K_helmholtz(), assemble_biharmonic(), assemble_cd(), assemble_divgrad(), assemble_ellipticdg(), assemble_func(), assemble_helmholtz(), assemble_poisson(), assemble_SchroedingerEquation(), assemble_shell(), assemble_stokes(), assemble_wave(), libMesh::ExactSolution::attach_exact_deriv(), libMesh::ExactSolution::attach_exact_hessian(), libMesh::ExactSolution::attach_exact_value(), libMesh::NewmarkSystem::clear(), clear(), libMesh::FrequencySystem::clear_all(), compute_jacobian(), compute_residual(), LinearElasticityWithContact::compute_stresses(), LargeDeformationElasticity::compute_stresses(), EquationSystems(), fe_assembly(), fill_dirichlet_bc(), libMesh::ExactErrorEstimator::find_squared_element_error(), libMesh::ImplicitSystem::get_linear_solve_parameters(), libMesh::FEComputeData::init(), init_cd(), HeatSystem::init_data(), libMesh::FrequencySystem::init_data(), init_sys(), Biharmonic::JR::InitialDensityBall(), Biharmonic::JR::InitialDensityRod(), Biharmonic::JR::InitialDensityStrip(), Biharmonic::JR::initialize(), initialize(), LargeDeformationElasticity::jacobian(), line_print(), main(), libMesh::FrequencySystem::n_frequencies(), libMesh::NewmarkSystem::NewmarkSystem(), libMesh::NonlinearImplicitSystem::NonlinearImplicitSystem(), LargeDeformationElasticity::residual(), LinearElasticityWithContact::residual_and_jacobian(), run_timestepping(), libMesh::FrequencySystem::set_current_frequency(), libMesh::FrequencySystem::set_frequencies(), libMesh::FrequencySystem::set_frequencies_by_range(), libMesh::FrequencySystem::set_frequencies_by_steps(), libMesh::NewmarkSystem::set_newmark_parameters(), libMesh::NonlinearImplicitSystem::set_solver_parameters(), setup(), SolidSystem::side_time_derivative(), libMesh::EigenSystem::solve(), libMesh::CondensedEigenSystem::solve(), libMesh::FrequencySystem::solve(), libMesh::LinearImplicitSystem::solve(), libMesh::RBConstruction::solve_for_matrix_and_rhs(), MeshfunctionDFEM::test_mesh_function_dfem(), MeshfunctionDFEM::test_mesh_function_dfem_grad(), MeshFunctionTest::test_p_level(), MeshFunctionTest::test_subdomain_id_sets(), MeshInputTest::testCopyElementSolutionImpl(), MeshInputTest::testCopyNodalSolutionImpl(), DefaultCouplingTest::testCoupling(), PointNeighborCouplingTest::testCoupling(), SystemsTest::testProjectCube(), SystemsTest::testProjectCubeWithMeshFunction(), MeshInputTest::testProjectionRegression(), SystemsTest::testProjectLine(), SystemsTest::testProjectSquare(), EquationSystemsTest::testRepartitionThenReinit(), MeshInputTest::testSingleElementImpl(), and libMesh::WrappedFunction< Output >::WrappedFunction().


The documentation for this class was generated from the following files: