libMesh::EquationSystems Class Reference

Manages multiples systems of equations. More...

#include <equation_systems.h>

Inheritance diagram for libMesh::EquationSystems:

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
}
 
enum  WriteFlags { WRITE_DATA = 1, WRITE_ADDITIONAL_DATA = 2, WRITE_PARALLEL_FILES = 4, WRITE_SERIAL_FILES = 8 }
 

Public Member Functions

 EquationSystems (MeshBase &mesh)
 
virtual ~EquationSystems ()
 
virtual void clear ()
 
virtual void init ()
 
virtual void reinit ()
 
virtual void enable_default_ghosting (bool enable)
 
void update ()
 
unsigned int n_systems () const
 
bool has_system (const std::string &name) const
 
template<typename T_sys >
const T_sys & get_system (const std::string &name) const
 
template<typename T_sys >
T_sys & get_system (const std::string &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 (const std::string &name) const
 
Systemget_system (const std::string &name)
 
const Systemget_system (const unsigned int num) const
 
Systemget_system (const unsigned int num)
 
virtual Systemadd_system (const std::string &system_type, const std::string &name)
 
template<typename T_sys >
T_sys & add_system (const std::string &name)
 
void delete_system (const std::string &name)
 
unsigned int n_vars () const
 
std::size_t n_dofs () const
 
std::size_t n_active_dofs () const
 
virtual void solve ()
 
virtual void adjoint_solve (const QoISet &qoi_indices=QoISet())
 
virtual void sensitivity_solve (const ParameterVector &parameters)
 
void build_variable_names (std::vector< std::string > &var_names, const FEType *type=nullptr, const std::set< std::string > *system_names=nullptr) const
 
void build_solution_vector (std::vector< Number > &soln, const std::string &system_name, const std::string &variable_name="all_vars") const
 
void build_solution_vector (std::vector< Number > &soln, const std::set< std::string > *system_names=nullptr) const
 
std::unique_ptr< NumericVector< Number > > build_parallel_solution_vector (const std::set< std::string > *system_names=nullptr) const
 
void get_vars_active_subdomains (const std::vector< std::string > &names, std::vector< std::set< subdomain_id_type >> &vars_active_subdomains) const
 
void get_solution (std::vector< Number > &soln, std::vector< std::string > &names) const
 
void build_elemental_solution_vector (std::vector< Number > &soln, std::vector< std::string > &names) const
 
std::unique_ptr< NumericVector< Number > > build_parallel_elemental_solution_vector (std::vector< std::string > &names) const
 
void build_discontinuous_solution_vector (std::vector< Number > &soln, const std::set< std::string > *system_names=nullptr) const
 
template<typename InValType >
void read (const std::string &name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
 
void read (const std::string &name, const XdrMODE mode, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
 
template<typename InValType >
void read (const std::string &name, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
 
void read (const std::string &name, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
 
void write (const std::string &name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const
 
void write (const std::string &name, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) 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
 
const MeshBaseget_mesh () const
 
MeshBaseget_mesh ()
 
void allgather ()
 
void enable_refine_in_reinit ()
 
void disable_refine_in_reinit ()
 
bool refine_in_reinit_flag ()
 
bool reinit_solutions ()
 
virtual void reinit_systems ()
 
const Parallel::Communicatorcomm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static std::string get_info ()
 
static void print_info (std::ostream &out=libMesh::out)
 
static unsigned int n_objects ()
 
static void enable_print_counter_info ()
 
static void disable_print_counter_info ()
 

Public Attributes

Parameters parameters
 

Protected Types

typedef std::map< std::string, System * >::iterator system_iterator
 
typedef std::map< std::string, System * >::const_iterator const_system_iterator
 
typedef std::map< std::string, std::pair< unsigned int, unsigned int > > Counts
 

Protected Member Functions

void increment_constructor_count (const std::string &name)
 
void increment_destructor_count (const std::string &name)
 

Protected Attributes

MeshBase_mesh
 
std::map< std::string, System * > _systems
 
bool _refine_in_reinit
 
bool _enable_default_ghosting
 
const Parallel::Communicator_communicator
 

Static Protected Attributes

static Counts _counts
 
static Threads::atomic< unsigned int > _n_objects
 
static Threads::spin_mutex _mutex
 
static bool _enable_print_counter = true
 

Private Member Functions

template<typename InValType >
void _read_impl (const std::string &name, const XdrMODE, const unsigned int read_flags, bool partition_agnostic=true)
 
void _add_system_to_nodes_and_elems ()
 
void _remove_default_ghosting (unsigned int sys_num)
 

Friends

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

Detailed Description

Manages multiples systems of equations.

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

Definition at line 74 of file equation_systems.h.

Member Typedef Documentation

◆ const_system_iterator

typedef std::map<std::string, System *>::const_iterator libMesh::EquationSystems::const_system_iterator
protected

Typedef for constant system iterators

Definition at line 566 of file equation_systems.h.

◆ 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 117 of file reference_counter.h.

◆ system_iterator

typedef std::map<std::string, System *>::iterator libMesh::EquationSystems::system_iterator
protected

Typedef for system iterators

Definition at line 561 of file equation_systems.h.

Member Enumeration Documentation

◆ ReadFlags

◆ WriteFlags

Constructor & Destructor Documentation

◆ EquationSystems()

libMesh::EquationSystems::EquationSystems ( MeshBase mesh)

Constructor.

Definition at line 55 of file equation_systems.C.

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

55  :
56  ParallelObject (m),
57  _mesh (m),
58  _refine_in_reinit(true),
60 {
61  // Set default parameters
62  this->parameters.set<Real> ("linear solver tolerance") = TOLERANCE * TOLERANCE;
63  this->parameters.set<unsigned int>("linear solver maximum iterations") = 5000;
64 }
ParallelObject(const Parallel::Communicator &comm_in)
static const Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
T & set(const std::string &)
Definition: parameters.h:464

◆ ~EquationSystems()

libMesh::EquationSystems::~EquationSystems ( )
virtual

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

Definition at line 68 of file equation_systems.C.

References clear().

69 {
70  this->clear ();
71 }

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 1341 of file equation_systems.C.

References _mesh, libMesh::MeshBase::element_ptr_range(), and libMesh::MeshBase::node_ptr_range().

Referenced by add_system().

1342 {
1343  // All the nodes
1344  for (auto & node : _mesh.node_ptr_range())
1345  node->add_system();
1346 
1347  // All the elements
1348  for (auto & elem : _mesh.element_ptr_range())
1349  elem->add_system();
1350 }
virtual SimpleRange< element_iterator > element_ptr_range()=0
virtual SimpleRange< node_iterator > node_ptr_range()=0

◆ _read_impl()

template<typename InValType >
template void libMesh::EquationSystems::_read_impl< Real > ( const std::string &  name,
const XdrMODE  ,
const unsigned int  read_flags,
bool  partition_agnostic = true 
)
private

Actual read implementation. This can be called repeatedly inside a try-catch block in an attempt to read broken files.

Parameters
nameName of the file to be read.
read_flagsSingle flag created by bitwise-OR'ing several flags together.
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.
Note
This renumbering is not compatible with meshes that have two nodes in exactly the same position!


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 143 of file equation_systems_io.C.

References _mesh, add_system(), libMesh::Parallel::Communicator::broadcast(), 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(), 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().

147 {
211  // Set booleans from the read_flags argument
212  const bool read_header = read_flags & EquationSystems::READ_HEADER;
213  const bool read_data = read_flags & EquationSystems::READ_DATA;
214  const bool read_additional_data = read_flags & EquationSystems::READ_ADDITIONAL_DATA;
215  const bool read_legacy_format = read_flags & EquationSystems::READ_LEGACY_FORMAT;
216  const bool try_read_ifems = read_flags & EquationSystems::TRY_READ_IFEMS;
217  const bool read_basic_only = read_flags & EquationSystems::READ_BASIC_ONLY;
218  bool read_parallel_files = false;
219 
220  std::vector<std::pair<std::string, System *>> xda_systems;
221 
222  // This will unzip a file with .bz2 as the extension, otherwise it
223  // simply returns the name if the file need not be unzipped.
224  Xdr io ((this->processor_id() == 0) ? name : "", mode);
225  libmesh_assert (io.reading());
226 
227  {
228  // 1.)
229  // Read the version header.
230  std::string version = "legacy";
231  if (!read_legacy_format)
232  {
233  if (this->processor_id() == 0) io.data(version);
234  this->comm().broadcast(version);
235 
236  // All processors have the version header, if it does not contain
237  // the libMesh_label string then it is a legacy file.
238  const std::string libMesh_label = "libMesh-";
239  std::string::size_type lm_pos = version.find(libMesh_label);
240  if (lm_pos==std::string::npos)
241  {
242  io.close();
243 
244  // Recursively call this read() function but with the
245  // EquationSystems::READ_LEGACY_FORMAT bit set.
246  this->read (name, mode, (read_flags | EquationSystems::READ_LEGACY_FORMAT), partition_agnostic);
247  return;
248  }
249 
250  // Figure out the libMesh version that created this file
251  std::istringstream iss(version.substr(lm_pos + libMesh_label.size()));
252  int ver_major = 0, ver_minor = 0, ver_patch = 0;
253  char dot;
254  iss >> ver_major >> dot >> ver_minor >> dot >> ver_patch;
255  io.set_version(LIBMESH_VERSION_ID(ver_major, ver_minor, ver_patch));
256 
257 
258  read_parallel_files = (version.rfind(" parallel") < version.size());
259 
260  // If requested that we try to read infinite element information,
261  // and the string " with infinite elements" is not in the version,
262  // then tack it on. This is for compatibility reading ifem
263  // files written prior to 11/10/2008 - BSK
264  if (try_read_ifems)
265  if (!(version.rfind(" with infinite elements") < version.size()))
266  version += " with infinite elements";
267 
268  }
269  else
270  libmesh_deprecated();
271 
272  START_LOG("read()","EquationSystems");
273 
274  // 2.)
275  // Read the number of equation systems
276  unsigned int n_sys=0;
277  if (this->processor_id() == 0) io.data (n_sys);
278  this->comm().broadcast(n_sys);
279 
280  for (unsigned int sys=0; sys<n_sys; sys++)
281  {
282  // 3.)
283  // Read the name of the sys-th equation system
284  std::string sys_name;
285  if (this->processor_id() == 0) io.data (sys_name);
286  this->comm().broadcast(sys_name);
287 
288  // 4.)
289  // Read the type of the sys-th equation system
290  std::string sys_type;
291  if (this->processor_id() == 0) io.data (sys_type);
292  this->comm().broadcast(sys_type);
293 
294  if (read_header)
295  this->add_system (sys_type, sys_name);
296 
297  // 5.) - 9.)
298  // Let System::read_header() do the job
299  System & new_system = this->get_system(sys_name);
300  new_system.read_header (io,
301  version,
302  read_header,
303  read_additional_data,
304  read_legacy_format);
305 
306  xda_systems.push_back(std::make_pair(sys_name, &new_system));
307 
308  // If we're only creating "basic" systems, we need to tell
309  // each system that before we call init() later.
310  if (read_basic_only)
311  new_system.set_basic_system_only();
312  }
313  }
314 
315 
316 
317  // Now we are ready to initialize the underlying data
318  // structures. This will initialize the vectors for
319  // storage, the dof_map, etc...
320  if (read_header)
321  this->init();
322 
323  // 10.) & 11.)
324  // Read and set the numeric vector values
325  if (read_data)
326  {
327  // the EquationSystems::read() method should look constant from the mesh
328  // perspective, but we need to assign a temporary numbering to the nodes
329  // and elements in the mesh, which requires that we abuse const_cast
330  if (!read_legacy_format && partition_agnostic)
331  {
332  MeshBase & mesh = const_cast<MeshBase &>(this->get_mesh());
334  }
335 
336  Xdr local_io (read_parallel_files ? local_file_name(this->processor_id(),name) : "", mode);
337 
338  for (auto & pr : xda_systems)
339  if (read_legacy_format)
340  {
341  libmesh_deprecated();
342 #ifdef LIBMESH_ENABLE_DEPRECATED
343  pr.second->read_legacy_data (io, read_additional_data);
344 #endif
345  }
346  else
347  if (read_parallel_files)
348  pr.second->read_parallel_data<InValType> (local_io, read_additional_data);
349  else
350  pr.second->read_serialized_data<InValType> (io, read_additional_data);
351 
352 
353  // Undo the temporary numbering.
354  if (!read_legacy_format && partition_agnostic)
356  }
357 
358  STOP_LOG("read()","EquationSystems");
359 
360  // Localize each system's data
361  this->update();
362 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
const T_sys & get_system(const std::string &name) const
MeshBase & mesh
const Parallel::Communicator & comm() const
virtual void fix_broken_node_and_element_numbering()=0
void read(const std::string &name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)
virtual System & add_system(const std::string &system_type, const std::string &name)
void globally_renumber_nodes_and_elements(MeshBase &)
Definition: mesh_tools.C:2424
const MeshBase & get_mesh() const
processor_id_type processor_id() const
void broadcast(T &data, const unsigned int root_id=0) const

◆ _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 1352 of file equation_systems.C.

References get_system().

Referenced by add_system().

1353 {
1354  this->get_system(sys_num).get_dof_map().remove_default_ghosting();
1355 }
const T_sys & get_system(const std::string &name) const

◆ add_system() [1/2]

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

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

Definition at line 355 of file equation_systems.C.

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

Referenced by _read_impl(), and libMesh::ErrorVector::plot_error().

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

◆ add_system() [2/2]

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

Add the system named name to the systems array.

Definition at line 647 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().

648 {
649  T_sys * ptr = nullptr;
650 
651  if (!_systems.count(name))
652  {
653  const unsigned int sys_num = this->n_systems();
654  ptr = new T_sys(*this, name, sys_num);
655 
656  _systems.insert (std::make_pair(name, ptr));
657 
659  this->_remove_default_ghosting(sys_num);
660 
661  // Tell all the \p DofObject entities to add a system.
663  }
664  else
665  {
666  // We now allow redundant add_system calls, to make it
667  // easier to load data from files for user-derived system
668  // subclasses
669  ptr = &(this->get_system<T_sys>(name));
670  }
671 
672  // Return a dynamically casted reference to the newly added System.
673  return *ptr;
674 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
unsigned int n_systems() const
void _remove_default_ghosting(unsigned int sys_num)
std::map< std::string, System * > _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 476 of file equation_systems.C.

References get_system(), and n_systems().

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

477 {
478  libmesh_assert (this->n_systems());
479 
480  for (unsigned int i=this->n_systems(); i != 0; --i)
481  this->get_system(i-1).adjoint_solve(qoi_indices);
482 }
unsigned int n_systems() const
const T_sys & get_system(const std::string &name) const

◆ allgather()

void libMesh::EquationSystems::allgather ( )

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

Definition at line 284 of file equation_systems.C.

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

285 {
286  // A serial mesh means nothing needs to be done
287  if (_mesh.is_serial())
288  return;
289 
290  const unsigned int n_sys = this->n_systems();
291 
292  libmesh_assert_not_equal_to (n_sys, 0);
293 
294  // Gather the mesh
295  _mesh.allgather();
296 
297  // Tell all the \p DofObject entities how many systems
298  // there are.
299  for (auto & node : _mesh.node_ptr_range())
300  node->set_n_systems(n_sys);
301 
302  for (auto & elem : _mesh.element_ptr_range())
303  elem->set_n_systems(n_sys);
304 
305  // And distribute each system's dofs
306  for (unsigned int i=0; i != this->n_systems(); ++i)
307  {
308  System & sys = this->get_system(i);
309  DofMap & dof_map = sys.get_dof_map();
310  dof_map.distribute_dofs(_mesh);
311 
312  // The user probably won't need constraint equations or the
313  // send_list after an allgather, but let's keep it in consistent
314  // shape just in case.
315  sys.reinit_constraints();
316  dof_map.prepare_send_list();
317  }
318 }
unsigned int n_systems() const
const T_sys & get_system(const std::string &name) const
virtual void allgather()
Definition: mesh_base.h:183
virtual bool is_serial() const
Definition: mesh_base.h:154
virtual SimpleRange< element_iterator > element_ptr_range()=0
virtual SimpleRange< node_iterator > node_ptr_range()=0

◆ build_discontinuous_solution_vector()

void libMesh::EquationSystems::build_discontinuous_solution_vector ( std::vector< Number > &  soln,
const std::set< std::string > *  system_names = nullptr 
) 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.

Definition at line 1055 of file equation_systems.C.

References _mesh, _systems, libMesh::MeshBase::active_element_ptr_range(), libMesh::Variable::active_on_subdomain(), libMesh::DofMap::dof_indices(), end, libMesh::System::get_dof_map(), libMesh::MeshBase::mesh_dimension(), n_systems(), libMesh::System::n_vars(), libMesh::FEInterface::nodal_soln(), libMesh::ParallelObject::processor_id(), libMesh::System::update_global_solution(), libMesh::System::variable(), and libMesh::System::variable_type().

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

1057 {
1058  LOG_SCOPE("build_discontinuous_solution_vector()", "EquationSystems");
1059 
1060  libmesh_assert (this->n_systems());
1061 
1062  const unsigned int dim = _mesh.mesh_dimension();
1063 
1064  // Get the number of variables (nv) by counting the number of variables
1065  // in each system listed in system_names
1066  unsigned int nv = 0;
1067 
1068  {
1069  const_system_iterator pos = _systems.begin();
1070  const const_system_iterator end = _systems.end();
1071 
1072  for (; pos != end; ++pos)
1073  {
1074  // Check current system is listed in system_names, and skip pos if not
1075  bool use_current_system = (system_names == nullptr);
1076  if (!use_current_system)
1077  use_current_system = system_names->count(pos->first);
1078  if (!use_current_system || pos->second->hide_output())
1079  continue;
1080 
1081  const System & system = *(pos->second);
1082  nv += system.n_vars();
1083  }
1084  }
1085 
1086  unsigned int tw=0;
1087 
1088  // get the total weight
1089  for (const auto & elem : _mesh.active_element_ptr_range())
1090  tw += elem->n_nodes();
1091 
1092  // Only if we are on processor zero, allocate the storage
1093  // to hold (number_of_nodes)*(number_of_variables) entries.
1094  if (_mesh.processor_id() == 0)
1095  soln.resize(tw*nv);
1096 
1097  std::vector<Number> sys_soln;
1098 
1099 
1100  unsigned int var_num=0;
1101 
1102  // For each system in this EquationSystems object,
1103  // update the global solution and if we are on processor 0,
1104  // loop over the elements and build the nodal solution
1105  // from the element solution. Then insert this nodal solution
1106  // into the vector passed to build_solution_vector.
1107  {
1108  const_system_iterator pos = _systems.begin();
1109  const const_system_iterator end = _systems.end();
1110 
1111  for (; pos != end; ++pos)
1112  {
1113  // Check current system is listed in system_names, and skip pos if not
1114  bool use_current_system = (system_names == nullptr);
1115  if (!use_current_system)
1116  use_current_system = system_names->count(pos->first);
1117  if (!use_current_system || pos->second->hide_output())
1118  continue;
1119 
1120  const System & system = *(pos->second);
1121  const unsigned int nv_sys = system.n_vars();
1122 
1123  system.update_global_solution (sys_soln, 0);
1124 
1125  if (_mesh.processor_id() == 0)
1126  {
1127  std::vector<Number> elem_soln; // The finite element solution
1128  std::vector<Number> nodal_soln; // The FE solution interpolated to the nodes
1129  std::vector<dof_id_type> dof_indices; // The DOF indices for the finite element
1130 
1131  for (unsigned int var=0; var<nv_sys; var++)
1132  {
1133  const FEType & fe_type = system.variable_type(var);
1134  const Variable & var_description = system.variable(var);
1135 
1136  unsigned int nn=0;
1137 
1138  for (auto & elem : _mesh.active_element_ptr_range())
1139  {
1140  if (var_description.active_on_subdomain(elem->subdomain_id()))
1141  {
1142  system.get_dof_map().dof_indices (elem, dof_indices, var);
1143 
1144  elem_soln.resize(dof_indices.size());
1145 
1146  for (std::size_t i=0; i<dof_indices.size(); i++)
1147  elem_soln[i] = sys_soln[dof_indices[i]];
1148 
1150  fe_type,
1151  elem,
1152  elem_soln,
1153  nodal_soln);
1154 
1155 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
1156  // infinite elements should be skipped...
1157  if (!elem->infinite())
1158 #endif
1159  {
1160  libmesh_assert_equal_to (nodal_soln.size(), elem->n_nodes());
1161 
1162  for (unsigned int n=0; n<elem->n_nodes(); n++)
1163  {
1164  soln[nv*(nn++) + (var + var_num)] +=
1165  nodal_soln[n];
1166  }
1167  }
1168  }
1169  else
1170  nn += elem->n_nodes();
1171  }
1172  }
1173  }
1174 
1175  var_num += nv_sys;
1176  }
1177  }
1178 }
unsigned int n_systems() const
IterBase * end
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
std::map< std::string, System * >::const_iterator const_system_iterator
unsigned int mesh_dimension() const
Definition: mesh_base.C:126
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)
Definition: fe_interface.C:550
processor_id_type processor_id() const
std::map< std::string, System * > _systems

◆ 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. 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 893 of file equation_systems.C.

References build_parallel_elemental_solution_vector().

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

895 {
896  // Call the parallel version of this function
897  std::unique_ptr<NumericVector<Number>> parallel_soln =
899 
900  // Localize into 'soln', provided that parallel_soln is not empty.
901  // Note: parallel_soln will be empty in the event that none of the
902  // input names were CONSTANT, MONOMIAL variables or there were
903  // simply no CONSTANT, MONOMIAL variables in the EquationSystems
904  // object.
905  soln.clear();
906  if (parallel_soln)
907  parallel_soln->localize_to_one(soln);
908 }
std::unique_ptr< NumericVector< Number > > build_parallel_elemental_solution_vector(std::vector< std::string > &names) const

◆ 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 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 variables exist on the system) or a std::unique_ptr to a var-major numeric vector of total length n_elem * n_vars 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 913 of file equation_systems.C.

References libMesh::ParallelObject::_communicator, _mesh, _systems, libMesh::MeshBase::active_local_element_ptr_range(), 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(), end, libMesh::System::get_dof_map(), libMesh::NumericVector< T >::init(), libMesh::MeshBase::max_elem_id(), libMesh::MONOMIAL, libMesh::MeshBase::n_elem(), libMesh::ParallelObject::n_processors(), n_systems(), libMesh::System::n_vars(), libMesh::PARALLEL, libMesh::ParallelObject::processor_id(), libMesh::NumericVector< T >::set(), libMesh::System::solution, libMesh::System::update(), libMesh::System::variable(), libMesh::System::variable_name(), and libMesh::System::variable_type().

Referenced by build_elemental_solution_vector(), and libMesh::Nemesis_IO::write_element_data().

914 {
915  // This function must be run on all processors at once
916  parallel_object_only();
917 
918  libmesh_assert (this->n_systems());
919 
920  const dof_id_type ne = _mesh.n_elem();
921 
922  libmesh_assert_equal_to (ne, _mesh.max_elem_id());
923 
924  // If the names vector has entries, we will only populate the soln vector
925  // with names included in that list. Note: The names vector may be
926  // reordered upon exiting this function
927  std::vector<std::string> filter_names = names;
928  bool is_filter_names = !filter_names.empty();
929 
930  names.clear();
931 
932  const FEType type(CONSTANT, MONOMIAL);
933 
934  dof_id_type nv = 0;
935 
936  // Find the total number of variables to output
937  std::vector<std::vector<unsigned>> do_output(_systems.size());
938  {
939  const_system_iterator pos = _systems.begin();
940  const const_system_iterator end = _systems.end();
941  unsigned sys_ctr = 0;
942 
943  for (; pos != end; ++pos, ++sys_ctr)
944  {
945  const System & system = *(pos->second);
946  const unsigned int nv_sys = system.n_vars();
947 
948  do_output[sys_ctr].resize(nv_sys);
949 
950  for (unsigned int var=0; var < nv_sys; ++var)
951  {
952  if (system.variable_type(var) != type ||
953  (is_filter_names && std::find(filter_names.begin(), filter_names.end(), system.variable_name(var)) == filter_names.end()))
954  continue;
955 
956  // Otherwise, this variable should be output
957  nv++;
958  do_output[sys_ctr][var] = 1;
959  }
960  }
961  }
962 
963  // If there are no variables to write out don't do anything...
964  if (!nv)
965  return std::unique_ptr<NumericVector<Number>>(nullptr);
966 
967  // We can handle the case where there are nullptrs in the Elem vector
968  // by just having extra zeros in the solution vector.
969  numeric_index_type parallel_soln_global_size = ne*nv;
970 
971  numeric_index_type div = parallel_soln_global_size / this->n_processors();
972  numeric_index_type mod = parallel_soln_global_size % this->n_processors();
973 
974  // Initialize all processors to the average size.
975  numeric_index_type parallel_soln_local_size = div;
976 
977  // The first "mod" processors get an extra entry.
978  if (this->processor_id() < mod)
979  parallel_soln_local_size = div+1;
980 
981  // Create a NumericVector to hold the parallel solution
982  std::unique_ptr<NumericVector<Number>> parallel_soln_ptr = NumericVector<Number>::build(_communicator);
983  NumericVector<Number> & parallel_soln = *parallel_soln_ptr;
984  parallel_soln.init(parallel_soln_global_size,
985  parallel_soln_local_size,
986  /*fast=*/false,
987  /*ParallelType=*/PARALLEL);
988 
989  dof_id_type var_num = 0;
990 
991  // For each system in this EquationSystems object,
992  // update the global solution and collect the
993  // CONSTANT MONOMIALs. The entries are in variable-major
994  // format.
995  const_system_iterator pos = _systems.begin();
996  const const_system_iterator end = _systems.end();
997  unsigned sys_ctr = 0;
998 
999  for (; pos != end; ++pos, ++sys_ctr)
1000  {
1001  const System & system = *(pos->second);
1002  const unsigned int nv_sys = system.n_vars();
1003 
1004  // Update the current_local_solution
1005  {
1006  System & non_const_sys = const_cast<System &>(system);
1007  // We used to simply call non_const_sys.solution->close()
1008  // here, but that is not allowed when the solution vector is
1009  // locked read-only, for example when printing the solution
1010  // during during the middle of a solve... So try to be a bit
1011  // more careful about calling close() unnecessarily.
1012  libmesh_assert(this->comm().verify(non_const_sys.solution->closed()));
1013  if (!non_const_sys.solution->closed())
1014  non_const_sys.solution->close();
1015  non_const_sys.update();
1016  }
1017 
1018  NumericVector<Number> & sys_soln(*system.current_local_solution);
1019 
1020  // The DOF indices for the finite element
1021  std::vector<dof_id_type> dof_indices;
1022 
1023  // Loop over the variable names and load them in order
1024  for (unsigned int var=0; var < nv_sys; ++var)
1025  {
1026  // Skip this variable if we are not outputting it.
1027  if (!do_output[sys_ctr][var])
1028  continue;
1029 
1030  names.push_back(system.variable_name(var));
1031 
1032  const Variable & variable = system.variable(var);
1033  const DofMap & dof_map = system.get_dof_map();
1034 
1035  for (const auto & elem : _mesh.active_local_element_ptr_range())
1036  if (variable.active_on_subdomain(elem->subdomain_id()))
1037  {
1038  dof_map.dof_indices (elem, dof_indices, var);
1039 
1040  libmesh_assert_equal_to (1, dof_indices.size());
1041 
1042  parallel_soln.set((ne*var_num)+elem->id(), sys_soln(dof_indices[0]));
1043  }
1044 
1045  var_num++;
1046  } // end loop on variables in this system
1047  } // end loop over systems
1048 
1049  parallel_soln.close();
1050  return std::unique_ptr<NumericVector<Number>>(parallel_soln_ptr.release());
1051 }
unsigned int n_systems() const
const Parallel::Communicator & comm() const
IterBase * end
const Parallel::Communicator & _communicator
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
std::map< std::string, System * >::const_iterator const_system_iterator
processor_id_type n_processors() const
dof_id_type numeric_index_type
Definition: id_types.h:92
virtual dof_id_type max_elem_id() const =0
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, const SolverPackage solver_package=libMesh::default_solver_package())
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const
uint8_t dof_id_type
Definition: id_types.h:64
std::map< std::string, System * > _systems

◆ build_parallel_solution_vector()

std::unique_ptr< NumericVector< Number > > libMesh::EquationSystems::build_parallel_solution_vector ( const std::set< std::string > *  system_names = nullptr) 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 600 of file equation_systems.C.

References libMesh::ParallelObject::_communicator, _mesh, _systems, std::abs(), libMesh::MeshBase::active_local_element_ptr_range(), libMesh::Variable::active_on_subdomain(), libMesh::NumericVector< T >::add(), libMesh::NumericVector< T >::build(), libMesh::NumericVector< T >::close(), libMesh::ParallelObject::comm(), libMesh::System::current_local_solution, libMesh::DofMap::dof_indices(), end, libMesh::FEInterface::field_type(), libMesh::NumericVector< T >::first_local_index(), libMesh::System::get_dof_map(), libMesh::NumericVector< T >::init(), libMesh::NumericVector< T >::last_local_index(), libMesh::MeshBase::local_nodes_begin(), libMesh::MeshBase::local_nodes_end(), libMesh::MeshBase::max_node_id(), libMesh::MeshBase::mesh_dimension(), libMesh::System::n_vars(), libMesh::FEInterface::n_vec_dim(), libMesh::FEInterface::nodal_soln(), libMesh::System::number(), libMesh::PARALLEL, libMesh::Parallel::Communicator::rank(), libMesh::NumericVector< T >::set(), libMesh::Parallel::Communicator::size(), libMesh::System::solution, libMesh::Parallel::Communicator::sum(), libMesh::TOLERANCE, libMesh::TYPE_VECTOR, libMesh::System::update(), libMesh::System::variable(), and libMesh::System::variable_type().

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

601 {
602  LOG_SCOPE("build_parallel_solution_vector()", "EquationSystems");
603 
604  // This function must be run on all processors at once
605  parallel_object_only();
606 
607  const unsigned int dim = _mesh.mesh_dimension();
608  const dof_id_type max_nn = _mesh.max_node_id();
609 
610  // allocate vector storage to hold
611  // (max_node_id)*(number_of_variables) entries.
612  //
613  // If node renumbering is disabled and adaptive coarsening has
614  // created gaps between node numbers, then this vector will be
615  // sparse.
616  //
617  // We have to differentiate between between scalar and vector
618  // variables. We intercept vector variables and treat each
619  // component as a scalar variable (consistently with build_solution_names).
620 
621  unsigned int nv = 0;
622 
623  //Could this be replaced by a/some convenience methods?[PB]
624  {
625  unsigned int n_scalar_vars = 0;
626  unsigned int n_vector_vars = 0;
627  const_system_iterator pos = _systems.begin();
628  const const_system_iterator end = _systems.end();
629 
630  for (; pos != end; ++pos)
631  {
632  // Check current system is listed in system_names, and skip pos if not
633  bool use_current_system = (system_names == nullptr);
634  if (!use_current_system)
635  use_current_system = system_names->count(pos->first);
636  if (!use_current_system || pos->second->hide_output())
637  continue;
638 
639  for (unsigned int vn=0; vn<pos->second->n_vars(); vn++)
640  {
641  if (FEInterface::field_type(pos->second->variable_type(vn)) == TYPE_VECTOR)
642  n_vector_vars++;
643  else
644  n_scalar_vars++;
645  }
646  }
647  // Here, we're assuming the number of vector components is the same
648  // as the mesh dimension. Will break for mixed dimension meshes.
649  nv = n_scalar_vars + dim*n_vector_vars;
650  }
651 
652  // Get the number of nodes to store locally.
653  dof_id_type n_local_nodes = cast_int<dof_id_type>
654  (std::distance(_mesh.local_nodes_begin(),
656 
657  // If node renumbering has been disabled, nodes may not be numbered
658  // contiguously, and the number of nodes might not match the
659  // max_node_id. In this case we just do our best.
660  dof_id_type n_total_nodes = n_local_nodes;
661  _mesh.comm().sum(n_total_nodes);
662 
663  const dof_id_type n_gaps = max_nn - n_total_nodes;
664  const dof_id_type gaps_per_processor = n_gaps / _mesh.comm().size();
665  const dof_id_type remainder_gaps = n_gaps % _mesh.comm().size();
666 
667  n_local_nodes = n_local_nodes + // Actual nodes
668  gaps_per_processor + // Our even share of gaps
669  (_mesh.comm().rank() < remainder_gaps); // Leftovers
670 
671  // Create a NumericVector to hold the parallel solution
672  std::unique_ptr<NumericVector<Number>> parallel_soln_ptr = NumericVector<Number>::build(_communicator);
673  NumericVector<Number> & parallel_soln = *parallel_soln_ptr;
674  parallel_soln.init(max_nn*nv, n_local_nodes*nv, false, PARALLEL);
675 
676  // Create a NumericVector to hold the "repeat_count" for each node - this is essentially
677  // the number of elements contributing to that node's value
678  std::unique_ptr<NumericVector<Number>> repeat_count_ptr = NumericVector<Number>::build(_communicator);
679  NumericVector<Number> & repeat_count = *repeat_count_ptr;
680  repeat_count.init(max_nn*nv, n_local_nodes*nv, false, PARALLEL);
681 
682  repeat_count.close();
683 
684  unsigned int var_num=0;
685 
686  // For each system in this EquationSystems object,
687  // update the global solution and if we are on processor 0,
688  // loop over the elements and build the nodal solution
689  // from the element solution. Then insert this nodal solution
690  // into the vector passed to build_solution_vector.
691  const_system_iterator pos = _systems.begin();
692  const const_system_iterator end = _systems.end();
693 
694  for (; pos != end; ++pos)
695  {
696  // Check current system is listed in system_names, and skip pos if not
697  bool use_current_system = (system_names == nullptr);
698  if (!use_current_system)
699  use_current_system = system_names->count(pos->first);
700  if (!use_current_system || pos->second->hide_output())
701  continue;
702 
703  const System & system = *(pos->second);
704  const unsigned int nv_sys = system.n_vars();
705  const unsigned int sys_num = system.number();
706 
707  //Could this be replaced by a/some convenience methods?[PB]
708  unsigned int n_scalar_vars = 0;
709  unsigned int n_vector_vars = 0;
710  for (unsigned int vn=0; vn<pos->second->n_vars(); vn++)
711  {
712  if (FEInterface::field_type(pos->second->variable_type(vn)) == TYPE_VECTOR)
713  n_vector_vars++;
714  else
715  n_scalar_vars++;
716  }
717 
718  // Here, we're assuming the number of vector components is the same
719  // as the mesh dimension. Will break for mixed dimension meshes.
720  unsigned int nv_sys_split = n_scalar_vars + dim*n_vector_vars;
721 
722  // Update the current_local_solution
723  {
724  System & non_const_sys = const_cast<System &>(system);
725  // We used to simply call non_const_sys.solution->close()
726  // here, but that is not allowed when the solution vector is
727  // locked read-only, for example when printing the solution
728  // during the middle of a solve... So try to be a bit
729  // more careful about calling close() unnecessarily.
730  libmesh_assert(this->comm().verify(non_const_sys.solution->closed()));
731  if (!non_const_sys.solution->closed())
732  non_const_sys.solution->close();
733  non_const_sys.update();
734  }
735 
736  NumericVector<Number> & sys_soln(*system.current_local_solution);
737 
738  std::vector<Number> elem_soln; // The finite element solution
739  std::vector<Number> nodal_soln; // The FE solution interpolated to the nodes
740  std::vector<dof_id_type> dof_indices; // The DOF indices for the finite element
741 
742  unsigned var_inc = 0;
743  for (unsigned int var=0; var<nv_sys; var++)
744  {
745  const FEType & fe_type = system.variable_type(var);
746  const Variable & var_description = system.variable(var);
747  const DofMap & dof_map = system.get_dof_map();
748 
749  unsigned int n_vec_dim = FEInterface::n_vec_dim( pos->second->get_mesh(), fe_type );
750 
751  for (const auto & elem : _mesh.active_local_element_ptr_range())
752  {
753  if (var_description.active_on_subdomain(elem->subdomain_id()))
754  {
755  dof_map.dof_indices (elem, dof_indices, var);
756 
757  elem_soln.resize(dof_indices.size());
758 
759  for (std::size_t i=0; i<dof_indices.size(); i++)
760  elem_soln[i] = sys_soln(dof_indices[i]);
761 
763  fe_type,
764  elem,
765  elem_soln,
766  nodal_soln);
767 
768 #ifdef LIBMESH_ENABLE_INFINITE_ELEMENTS
769  // infinite elements should be skipped...
770  if (!elem->infinite())
771 #endif
772  {
773  libmesh_assert_equal_to (nodal_soln.size(), n_vec_dim*elem->n_nodes());
774 
775  for (unsigned int n=0; n<elem->n_nodes(); n++)
776  {
777  for (unsigned int d=0; d < n_vec_dim; d++)
778  {
779  // For vector-valued elements, all components are in nodal_soln. For each
780  // node, the components are stored in order, i.e. node_0 -> s0_x, s0_y, s0_z
781  parallel_soln.add(nv*(elem->node_id(n)) + (var_inc+d + var_num), nodal_soln[n_vec_dim*n+d]);
782 
783  // Increment the repeat count for this position
784  repeat_count.add(nv*(elem->node_id(n)) + (var_inc+d + var_num), 1);
785  }
786  }
787  }
788  }
789  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:
790  for (unsigned int n=0; n<elem->n_nodes(); n++)
791  // Only do this if this variable has NO DoFs at this node... it might have some from an adjoining element...
792  if (!elem->node_ptr(n)->n_dofs(sys_num, var))
793  for (unsigned int d=0; d < n_vec_dim; d++)
794  repeat_count.add(nv*(elem->node_id(n)) + (var+d + var_num), 1);
795 
796  } // end loop over elements
797  var_inc += n_vec_dim;
798  } // end loop on variables in this system
799 
800  var_num += nv_sys_split;
801  } // end loop over systems
802 
803  // Sum the nodal solution values and repeat counts.
804  parallel_soln.close();
805  repeat_count.close();
806 
807  // If there were gaps in the node numbering, there will be
808  // corresponding zeros in the parallel_soln and repeat_count
809  // vectors. We need to set those repeat_count entries to 1
810  // in order to avoid dividing by zero.
811  if (n_gaps)
812  {
813  for (numeric_index_type i=repeat_count.first_local_index();
814  i<repeat_count.last_local_index(); ++i)
815  {
816  // repeat_count entries are integral values but let's avoid a
817  // direct floating point comparison with 0 just in case some
818  // roundoff noise crept in during vector assembly?
819  if (std::abs(repeat_count(i)) < TOLERANCE)
820  repeat_count.set(i, 1.);
821  }
822 
823  // Make sure the repeat_count vector is up-to-date on all
824  // processors.
825  repeat_count.close();
826  }
827 
828  // Divide to get the average value at the nodes
829  parallel_soln /= repeat_count;
830 
831  return std::unique_ptr<NumericVector<Number>>(parallel_soln_ptr.release());
832 }
double abs(double a)
processor_id_type size() const
Definition: communicator.h:175
static FEFieldType field_type(const FEType &fe_type)
const Parallel::Communicator & comm() const
static const Real TOLERANCE
IterBase * end
const Parallel::Communicator & _communicator
virtual SimpleRange< element_iterator > active_local_element_ptr_range()=0
std::map< std::string, System * >::const_iterator const_system_iterator
dof_id_type numeric_index_type
Definition: id_types.h:92
processor_id_type rank() const
Definition: communicator.h:173
virtual node_iterator local_nodes_end()=0
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())
virtual node_iterator local_nodes_begin()=0
unsigned int mesh_dimension() const
Definition: mesh_base.C:126
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)
Definition: fe_interface.C:550
virtual dof_id_type max_node_id() const =0
uint8_t dof_id_type
Definition: id_types.h:64
std::map< std::string, System * > _systems

◆ build_solution_vector() [1/2]

void libMesh::EquationSystems::build_solution_vector ( std::vector< Number > &  soln,
const std::string &  system_name,
const std::string &  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 588 of file equation_systems.C.

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

591 {
592  // TODO:[BSK] re-implement this from the method below
593  libmesh_not_implemented();
594 }

◆ build_solution_vector() [2/2]

void libMesh::EquationSystems::build_solution_vector ( std::vector< Number > &  soln,
const std::set< std::string > *  system_names = nullptr 
) 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.

Definition at line 836 of file equation_systems.C.

References build_parallel_solution_vector().

838 {
839  LOG_SCOPE("build_solution_vector()", "EquationSystems");
840 
841  // Call the parallel implementation
842  std::unique_ptr<NumericVector<Number>> parallel_soln =
843  this->build_parallel_solution_vector(system_names);
844 
845  // Localize the NumericVector into the provided std::vector.
846  parallel_soln->localize_to_one(soln);
847 }
std::unique_ptr< NumericVector< Number > > build_parallel_solution_vector(const std::set< std::string > *system_names=nullptr) const

◆ 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 486 of file equation_systems.C.

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

Referenced by 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(), and libMesh::MeshOutput< MeshBase >::write_equation_systems().

489 {
490  unsigned int var_num=0;
491 
492  const_system_iterator pos = _systems.begin();
493  const const_system_iterator end = _systems.end();
494 
495  // Need to size var_names by scalar variables plus all the
496  // vector components for all the vector variables
497  //Could this be replaced by a/some convenience methods?[PB]
498  {
499  unsigned int n_scalar_vars = 0;
500  unsigned int n_vector_vars = 0;
501 
502  for (; pos != end; ++pos)
503  {
504  // Check current system is listed in system_names, and skip pos if not
505  bool use_current_system = (system_names == nullptr);
506  if (!use_current_system)
507  use_current_system = system_names->count(pos->first);
508  if (!use_current_system || pos->second->hide_output())
509  continue;
510 
511  for (unsigned int vn=0; vn<pos->second->n_vars(); vn++)
512  {
513  if (FEInterface::field_type(pos->second->variable_type(vn)) == TYPE_VECTOR)
514  n_vector_vars++;
515  else
516  n_scalar_vars++;
517  }
518  }
519 
520  // Here, we're assuming the number of vector components is the same
521  // as the mesh dimension. Will break for mixed dimension meshes.
522  unsigned int dim = this->get_mesh().mesh_dimension();
523  unsigned int nv = n_scalar_vars + dim*n_vector_vars;
524 
525  // We'd better not have more than dim*his->n_vars() (all vector variables)
526  libmesh_assert_less_equal ( nv, dim*this->n_vars() );
527 
528  // Here, we're assuming the number of vector components is the same
529  // as the mesh dimension. Will break for mixed dimension meshes.
530 
531  var_names.resize( nv );
532  }
533 
534  // reset
535  pos = _systems.begin();
536 
537  for (; pos != end; ++pos)
538  {
539  // Check current system is listed in system_names, and skip pos if not
540  bool use_current_system = (system_names == nullptr);
541  if (!use_current_system)
542  use_current_system = system_names->count(pos->first);
543  if (!use_current_system || pos->second->hide_output())
544  continue;
545 
546  for (unsigned int vn=0; vn<pos->second->n_vars(); vn++)
547  {
548  std::string var_name = pos->second->variable_name(vn);
549  FEType fe_type = pos->second->variable_type(vn);
550 
551  unsigned int n_vec_dim = FEInterface::n_vec_dim( pos->second->get_mesh(), fe_type);
552 
553  // Filter on the type if requested
554  if (type == nullptr || (type && *type == fe_type))
555  {
556  if (FEInterface::field_type(fe_type) == TYPE_VECTOR)
557  {
558  switch(n_vec_dim)
559  {
560  case 0:
561  case 1:
562  var_names[var_num++] = var_name;
563  break;
564  case 2:
565  var_names[var_num++] = var_name+"_x";
566  var_names[var_num++] = var_name+"_y";
567  break;
568  case 3:
569  var_names[var_num++] = var_name+"_x";
570  var_names[var_num++] = var_name+"_y";
571  var_names[var_num++] = var_name+"_z";
572  break;
573  default:
574  libmesh_error_msg("Invalid dim in build_variable_names");
575  }
576  }
577  else
578  var_names[var_num++] = var_name;
579  }
580  }
581  }
582  // Now resize again in case we filtered any names
583  var_names.resize(var_num);
584 }
unsigned int n_vars() const
static FEFieldType field_type(const FEType &fe_type)
IterBase * end
std::map< std::string, System * >::const_iterator const_system_iterator
static unsigned int n_vec_dim(const MeshBase &mesh, const FEType &fe_type)
const MeshBase & get_mesh() const
unsigned int mesh_dimension() const
Definition: mesh_base.C:126
std::map< std::string, System * > _systems

◆ clear()

void libMesh::EquationSystems::clear ( )
virtual

Restores the data structure to a pristine state.

Definition at line 75 of file equation_systems.C.

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

Referenced by ~EquationSystems().

76 {
77  // Clear any additional parameters
78  parameters.clear ();
79 
80  // clear the systems. We must delete them
81  // since we newed them!
82  while (!_systems.empty())
83  {
84  system_iterator pos = _systems.begin();
85 
86  System * sys = pos->second;
87  delete sys;
88  sys = nullptr;
89 
90  _systems.erase (pos);
91  }
92 }
std::map< std::string, System * >::iterator system_iterator
virtual void clear()
Definition: parameters.h:317
std::map< std::string, System * > _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 89 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::BoundaryInfo::_find_id_maps(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_get_diagonal(), libMesh::SlepcEigenSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult(), libMesh::PetscLinearSolver< T >::_petsc_shell_matrix_mult_add(), _read_impl(), libMesh::MeshRefinement::_refine_elements(), libMesh::MeshRefinement::_smooth_flags(), libMesh::PetscDMWrapper::add_dofs_helper(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::ImplicitSystem::add_matrix(), libMesh::System::add_vector(), libMesh::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assemble_qoi(), libMesh::MeshCommunication::assign_global_indices(), libMesh::DofMap::attach_matrix(), 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_dims(), libMesh::System::calculate_norm(), libMesh::DofMap::check_dirichlet_bcid_consistency(), libMesh::PetscDMWrapper::check_section_n_dofs(), 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::Problem_Interface::computeF(), libMesh::Problem_Interface::computeJacobian(), libMesh::Problem_Interface::computePreconditioner(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::MeshTools::correct_node_proc_ids(), libMesh::MeshTools::create_bounding_box(), 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::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), DMlibMeshFunction(), DMlibMeshJacobian(), DMlibMeshSetSystem_libMesh(), DMVariableBounds_libMesh(), libMesh::MeshRefinement::eliminate_unrefined_patches(), libMesh::EpetraVector< T >::EpetraVector(), libMesh::WeightedPatchRecoveryErrorEstimator::estimate_error(), libMesh::PatchRecoveryErrorEstimator::estimate_error(), libMesh::JumpErrorEstimator::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_nelem_target(), libMesh::CondensedEigenSystem::get_eigenpair(), libMesh::DofMap::get_info(), libMesh::ImplicitSystem::get_linear_solver(), libMesh::LocationMap< T >::init(), libMesh::TimeSolver::init(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::EigenSystem::init_data(), libMesh::EigenSystem::init_matrices(), libMesh::OptimizationSystem::initialize_equality_constraints_storage(), libMesh::OptimizationSystem::initialize_inequality_constraints_storage(), 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_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_snes_fd_residual(), libMesh::libmesh_petsc_snes_jacobian(), libMesh::libmesh_petsc_snes_mffd_residual(), libMesh::libmesh_petsc_snes_postcheck(), 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::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_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::FEMSystem::mesh_position_set(), libMesh::DistributedMesh::n_active_elem(), libMesh::MeshTools::n_active_levels(), libMesh::BoundaryInfo::n_boundary_conds(), libMesh::BoundaryInfo::n_edge_conds(), libMesh::CondensedEigenSystem::n_global_non_condensed_dofs(), libMesh::MeshTools::n_levels(), libMesh::BoundaryInfo::n_nodeset_conds(), libMesh::MeshTools::n_p_levels(), libMesh::BoundaryInfo::n_shellface_conds(), 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::MeshTools::paranoid_n_levels(), libMesh::petsc_auto_fieldsplit(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), libMesh::MeshBase::prepare_for_use(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), 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::MeshBase::recalculate_n_partitions(), libMesh::MeshRefinement::refine_and_coarsen_elements(), libMesh::DistributedMesh::renumber_dof_objects(), libMesh::CheckpointIO::select_split_config(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::PetscDiffSolver::setup_petsc_data(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::split_mesh(), libMesh::MeshBase::subdomain_ids(), libMesh::BoundaryInfo::sync(), libMesh::MeshRefinement::test_level_one(), libMesh::MeshRefinement::test_unflagged(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::NameBasedIO::write(), libMesh::XdrIO::write(), 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().

90  { 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 1182 of file equation_systems.C.

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

1185 {
1186  // safety check, whether we handle at least the same number
1187  // of systems
1188  std::vector<bool> os_result;
1189 
1190  if (this->n_systems() != other_es.n_systems())
1191  {
1192  if (verbose)
1193  {
1194  libMesh::out << " Fatal difference. This system handles "
1195  << this->n_systems() << " systems," << std::endl
1196  << " while the other system handles "
1197  << other_es.n_systems()
1198  << " systems." << std::endl
1199  << " Aborting comparison." << std::endl;
1200  }
1201  return false;
1202  }
1203  else
1204  {
1205  // start comparing each system
1206  const_system_iterator pos = _systems.begin();
1207  const const_system_iterator end = _systems.end();
1208 
1209  for (; pos != end; ++pos)
1210  {
1211  const std::string & sys_name = pos->first;
1212  const System & system = *(pos->second);
1213 
1214  // get the other system
1215  const System & other_system = other_es.get_system (sys_name);
1216 
1217  os_result.push_back (system.compare (other_system, threshold, verbose));
1218 
1219  }
1220 
1221  }
1222 
1223 
1224  // sum up the results
1225  if (os_result.size()==0)
1226  return true;
1227  else
1228  {
1229  bool os_identical;
1230  unsigned int n = 0;
1231  do
1232  {
1233  os_identical = os_result[n];
1234  n++;
1235  }
1236  while (os_identical && n<os_result.size());
1237  return os_identical;
1238  }
1239 }
unsigned int n_systems() const
IterBase * end
std::map< std::string, System * >::const_iterator const_system_iterator
OStreamProxy out(std::cout)
std::map< std::string, System * > _systems

◆ delete_system()

void libMesh::EquationSystems::delete_system ( const std::string &  name)

Remove the system named name from the systems array.

Deprecated:
This function may not work as intended and has not been actively tested over the years. If you need the ability to delete a System from an EquationSystems object, it could probably be added.

Definition at line 441 of file equation_systems.C.

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

442 {
443  libmesh_deprecated();
444 
445  if (!_systems.count(name))
446  libmesh_error_msg("ERROR: no system named " << name);
447 
448  delete _systems[name];
449 
450  _systems.erase (name);
451 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
std::map< std::string, System * > _systems

◆ disable_print_counter_info()

void libMesh::ReferenceCounter::disable_print_counter_info ( )
staticinherited

Definition at line 106 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

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

107 {
108  _enable_print_counter = false;
109  return;
110 }

◆ 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 519 of file equation_systems.h.

References _refine_in_reinit.

519 { this->_refine_in_reinit = false; }

◆ 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 322 of file equation_systems.C.

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

323 {
324  _enable_default_ghosting = enable;
325  MeshBase &mesh = this->get_mesh();
326 
327  if (enable)
328  mesh.add_ghosting_functor(mesh.default_ghosting());
329  else
330  mesh.remove_ghosting_functor(mesh.default_ghosting());
331 
332  for (unsigned int i=0; i != this->n_systems(); ++i)
333  {
334  DofMap & dof_map = this->get_system(i).get_dof_map();
335  if (enable)
336  dof_map.add_default_ghosting();
337  else
338  dof_map.remove_default_ghosting();
339  }
340 }
unsigned int n_systems() const
const T_sys & get_system(const std::string &name) const
MeshBase & mesh
const MeshBase & get_mesh() const

◆ 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 100 of file reference_counter.C.

References libMesh::ReferenceCounter::_enable_print_counter.

101 {
102  _enable_print_counter = true;
103  return;
104 }

◆ 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 514 of file equation_systems.h.

References _refine_in_reinit.

514 { this->_refine_in_reinit = true; }

◆ 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 & pr : _counts)
59  {
60  const std::string name(pr.first);
61  const unsigned int creations = pr.second.first;
62  const unsigned int destructions = pr.second.second;
63 
64  oss << "| " << name << " reference count information:\n"
65  << "| Creations: " << creations << '\n'
66  << "| Destructions: " << destructions << '\n';
67  }
68 
69  oss << " ---------------------------------------------------------------------------- \n";
70 
71  return oss.str();
72 
73 #else
74 
75  return "";
76 
77 #endif
78 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42

◆ 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 1243 of file equation_systems.C.

References _systems, end, and n_systems().

Referenced by print_info().

1244 {
1245  std::ostringstream oss;
1246 
1247  oss << " EquationSystems\n"
1248  << " n_systems()=" << this->n_systems() << '\n';
1249 
1250  // Print the info for the individual systems
1251  const_system_iterator pos = _systems.begin();
1252  const const_system_iterator end = _systems.end();
1253 
1254  for (; pos != end; ++pos)
1255  oss << pos->second->get_info();
1256 
1257 
1258  // // Possibly print the parameters
1259  // if (!this->parameters.empty())
1260  // {
1261  // oss << " n_parameters()=" << this->n_parameters() << '\n';
1262  // oss << " Parameters:\n";
1263 
1264  // for (const auto & pr : _parameters)
1265  // oss << " "
1266  // << "\""
1267  // << pr.first
1268  // << "\""
1269  // << "="
1270  // << pr.second
1271  // << '\n';
1272  // }
1273 
1274  return oss.str();
1275 }
unsigned int n_systems() const
IterBase * end
std::map< std::string, System * >::const_iterator const_system_iterator
std::map< std::string, System * > _systems

◆ get_mesh() [1/2]

◆ get_mesh() [2/2]

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

Definition at line 630 of file equation_systems.h.

References _mesh.

631 {
632  return _mesh;
633 }

◆ get_solution()

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

Retrieve the solution data for CONSTANT MONOMIALs. If names is populated, only the variables corresponding to those names will be retrieved. This can be used to filter which variables are retrieved.

Deprecated:
Call the more appropriately-named build_elemental_solution_vector() instead.

Definition at line 883 of file equation_systems.C.

References build_elemental_solution_vector().

885 {
886  libmesh_deprecated();
887  this->build_elemental_solution_vector(soln, names);
888 }
void build_elemental_solution_vector(std::vector< Number > &soln, std::vector< std::string > &names) const

◆ get_system() [1/8]

template<typename T_sys >
const T_sys & libMesh::EquationSystems::get_system ( const std::string &  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 742 of file equation_systems.h.

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

Referenced by libMesh::ExactSolution::_compute_error(), libMesh::UniformRefinementEstimator::_estimate_error(), _read_impl(), _remove_default_ghosting(), libMesh::EnsightIO::add_scalar(), add_system(), libMesh::EnsightIO::add_vector(), adjoint_solve(), allgather(), libMesh::ExactSolution::attach_exact_deriv(), libMesh::ExactSolution::attach_exact_hessian(), libMesh::ExactSolution::attach_exact_value(), compare(), libMesh::ExactSolution::compute_error(), libMesh::GMVIO::copy_nodal_solution(), enable_default_ghosting(), libMesh::ExactSolution::error_norm(), libMesh::ExactErrorEstimator::estimate_error(), libMesh::ErrorEstimator::estimate_errors(), libMesh::ExactSolution::ExactSolution(), init(), reinit_solutions(), reinit_systems(), sensitivity_solve(), solve(), update(), libMesh::EnsightIO::write_scalar_ascii(), and libMesh::EnsightIO::write_vector_ascii().

743 {
744  const_system_iterator pos = _systems.find(name);
745 
746  // Check for errors
747  if (pos == _systems.end())
748  libmesh_error_msg("ERROR: no system named \"" << name << "\" found!");
749 
750  // Attempt dynamic cast
751  return *cast_ptr<T_sys *>(pos->second);
752 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
std::map< std::string, System * >::const_iterator const_system_iterator
std::map< std::string, System * > _systems

◆ get_system() [2/8]

template<typename T_sys >
T_sys & libMesh::EquationSystems::get_system ( const std::string &  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 761 of file equation_systems.h.

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

762 {
763  system_iterator pos = _systems.find(name);
764 
765  // Check for errors
766  if (pos == _systems.end())
767  libmesh_error_msg("ERROR: no system named " << name << " found!");
768 
769  // Attempt dynamic cast
770  return *cast_ptr<T_sys *>(pos->second);
771 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
std::map< std::string, System * >::iterator system_iterator
std::map< std::string, System * > _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 691 of file equation_systems.h.

References _systems, end, and n_systems().

692 {
693  libmesh_assert_less (num, this->n_systems());
694 
695 
696  const_system_iterator pos = _systems.begin();
697  const const_system_iterator end = _systems.end();
698 
699  for (; pos != end; ++pos)
700  if (pos->second->number() == num)
701  break;
702 
703  // Check for errors
704  if (pos == end)
705  libmesh_error_msg("ERROR: no system number " << num << " found!");
706 
707  // Attempt dynamic cast
708  return *cast_ptr<T_sys *>(pos->second);
709 }
unsigned int n_systems() const
IterBase * end
std::map< std::string, System * >::const_iterator const_system_iterator
std::map< std::string, System * > _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 716 of file equation_systems.h.

References _systems, end, and n_systems().

717 {
718  libmesh_assert_less (num, this->n_systems());
719 
720  const_system_iterator pos = _systems.begin();
721  const const_system_iterator end = _systems.end();
722 
723  for (; pos != end; ++pos)
724  if (pos->second->number() == num)
725  break;
726 
727  // Check for errors
728  if (pos == end)
729  libmesh_error_msg("ERROR: no system number " << num << " found!");
730 
731  // Attempt dynamic cast
732  return *cast_ptr<T_sys *>(pos->second);
733 }
unsigned int n_systems() const
IterBase * end
std::map< std::string, System * >::const_iterator const_system_iterator
std::map< std::string, System * > _systems

◆ get_system() [5/8]

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

Definition at line 780 of file equation_systems.h.

References libMesh::Quality::name().

781 {
782  return this->get_system<System>(name);
783 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42

◆ get_system() [6/8]

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

Definition at line 788 of file equation_systems.h.

References libMesh::Quality::name().

789 {
790  return this->get_system<System>(name);
791 }
std::string name(const ElemQuality 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 796 of file equation_systems.h.

797 {
798  return this->get_system<System>(num);
799 }

◆ 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 804 of file equation_systems.h.

805 {
806  return this->get_system<System>(num);
807 }

◆ 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 851 of file equation_systems.C.

References _systems, libMesh::Variable::active_subdomains(), and end.

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

853 {
854  unsigned int var_num=0;
855 
856  vars_active_subdomains.clear();
857  vars_active_subdomains.resize(names.size());
858 
859  const_system_iterator pos = _systems.begin();
860  const const_system_iterator end = _systems.end();
861 
862  for (; pos != end; ++pos)
863  {
864  for (unsigned int vn=0; vn<pos->second->n_vars(); vn++)
865  {
866  std::string var_name = pos->second->variable_name(vn);
867 
868  auto names_it = std::find(names.begin(), names.end(), var_name);
869  if(names_it != names.end())
870  {
871  const Variable & variable = pos->second->variable(vn);
872  const std::set<subdomain_id_type> & active_subdomains = variable.active_subdomains();
873  vars_active_subdomains[var_num++] = active_subdomains;
874  }
875  }
876  }
877 
878  libmesh_assert_equal_to(var_num, names.size());
879 }
IterBase * end
std::map< std::string, System * >::const_iterator const_system_iterator
std::map< std::string, System * > _systems

◆ has_system()

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

Definition at line 679 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(), and libMesh::ExactSolution::error_norm().

680 {
681  if (_systems.find(name) == _systems.end())
682  return false;
683  return true;
684 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
std::map< std::string, System * > _systems

◆ increment_constructor_count()

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

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

Definition at line 181 of file reference_counter.h.

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

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

182 {
183  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
184  std::pair<unsigned int, unsigned int> & p = _counts[name];
185 
186  p.first++;
187 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
spin_mutex spin_mtx
Definition: threads.C:29

◆ increment_destructor_count()

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

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

Definition at line 194 of file reference_counter.h.

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

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

195 {
196  Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
197  std::pair<unsigned int, unsigned int> & p = _counts[name];
198 
199  p.second++;
200 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
spin_mutex spin_mtx
Definition: threads.C:29

◆ init()

void libMesh::EquationSystems::init ( )
virtual

Initialize all the systems

Definition at line 96 of file equation_systems.C.

References _mesh, libMesh::MeshRefinement::clean_refinement_flags(), libMesh::MeshBase::element_ptr_range(), get_system(), n_systems(), and libMesh::MeshBase::node_ptr_range().

Referenced by _read_impl(), and libMesh::ErrorVector::plot_error().

97 {
98  const unsigned int n_sys = this->n_systems();
99 
100  libmesh_assert_not_equal_to (n_sys, 0);
101 
102  // Tell all the \p DofObject entities how many systems
103  // there are.
104  for (auto & node : _mesh.node_ptr_range())
105  node->set_n_systems(n_sys);
106 
107  for (auto & elem : _mesh.element_ptr_range())
108  elem->set_n_systems(n_sys);
109 
110  for (unsigned int i=0; i != this->n_systems(); ++i)
111  this->get_system(i).init();
112 
113 #ifdef LIBMESH_ENABLE_AMR
114  MeshRefinement mesh_refine(_mesh);
115  mesh_refine.clean_refinement_flags();
116 #endif
117 }
unsigned int n_systems() const
const T_sys & get_system(const std::string &name) const
virtual SimpleRange< element_iterator > element_ptr_range()=0
virtual SimpleRange< node_iterator > node_ptr_range()=0

◆ 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 1327 of file equation_systems.C.

References _systems, and end.

1328 {
1329  std::size_t tot=0;
1330 
1331  const_system_iterator pos = _systems.begin();
1332  const const_system_iterator end = _systems.end();
1333 
1334  for (; pos != end; ++pos)
1335  tot += pos->second->n_active_dofs();
1336 
1337  return tot;
1338 }
IterBase * end
std::map< std::string, System * >::const_iterator const_system_iterator
std::map< std::string, System * > _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 1311 of file equation_systems.C.

References _systems, and end.

1312 {
1313  std::size_t tot=0;
1314 
1315  const_system_iterator pos = _systems.begin();
1316  const const_system_iterator end = _systems.end();
1317 
1318  for (; pos != end; ++pos)
1319  tot += pos->second->n_dofs();
1320 
1321  return tot;
1322 }
IterBase * end
std::map< std::string, System * >::const_iterator const_system_iterator
std::map< std::string, System * > _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 83 of file reference_counter.h.

References libMesh::ReferenceCounter::_n_objects.

84  { return _n_objects; }
static Threads::atomic< unsigned int > _n_objects

◆ n_processors()

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

Definition at line 95 of file parallel_object.h.

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

Referenced by libMesh::BoundaryInfo::_find_id_maps(), libMesh::PetscDMWrapper::add_dofs_to_section(), libMesh::DistributedMesh::add_elem(), libMesh::DistributedMesh::add_node(), libMesh::LaplaceMeshSmoother::allgather_graph(), libMesh::FEMSystem::assembly(), libMesh::AztecLinearSolver< T >::AztecLinearSolver(), libMesh::BoundaryInfo::build_node_list_from_side_list(), build_parallel_elemental_solution_vector(), libMesh::DistributedMesh::clear(), libMesh::Nemesis_IO_Helper::compute_border_node_ids(), libMesh::Nemesis_IO_Helper::construct_nemesis_filename(), libMesh::UnstructuredMesh::create_pid_mesh(), libMesh::MeshTools::create_processor_bounding_box(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshBase::get_info(), libMesh::SystemSubsetBySubdomain::init(), libMesh::PetscDMWrapper::init_and_attach_petscdm(), libMesh::Nemesis_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::MeshBase::partition(), libMesh::PetscLinearSolver< T >::PetscLinearSolver(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), 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::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::DistributedMesh::update_parallel_id_counts(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), 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().

96  { return cast_int<processor_id_type>(_communicator.size()); }
processor_id_type size() const
Definition: communicator.h:175
const Parallel::Communicator & _communicator

◆ n_systems()

◆ n_vars()

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

Definition at line 1296 of file equation_systems.C.

References _systems, and end.

Referenced by build_variable_names().

1297 {
1298  unsigned int tot=0;
1299 
1300  const_system_iterator pos = _systems.begin();
1301  const const_system_iterator end = _systems.end();
1302 
1303  for (; pos != end; ++pos)
1304  tot += pos->second->n_vars();
1305 
1306  return tot;
1307 }
IterBase * end
std::map< std::string, System * >::const_iterator const_system_iterator
std::map< std::string, System * > _systems

◆ print_info() [1/2]

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

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

Definition at line 87 of file reference_counter.C.

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

88 {
90  out_stream << ReferenceCounter::get_info();
91 }
static std::string get_info()

◆ 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 1279 of file equation_systems.C.

References get_info().

Referenced by libMesh::operator<<().

1280 {
1281  os << this->get_info()
1282  << std::endl;
1283 }
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 101 of file parallel_object.h.

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

Referenced by libMesh::BoundaryInfo::_find_id_maps(), _read_impl(), 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::UnstructuredMesh::all_second_order(), libMesh::MeshTools::Modification::all_tri(), libMesh::FEMSystem::assembly(), build_discontinuous_solution_vector(), libMesh::Nemesis_IO_Helper::build_element_and_node_maps(), libMesh::InfElemBuilder::build_inf_elem(), libMesh::BoundaryInfo::build_node_list_from_side_list(), build_parallel_elemental_solution_vector(), libMesh::DistributedMesh::clear(), 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::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::MeshTools::correct_node_proc_ids(), libMesh::ExodusII_IO_Helper::create(), libMesh::DistributedMesh::delete_elem(), libMesh::DistributedMesh::delete_node(), libMesh::MeshCommunication::delete_remote_elements(), libMesh::DofMap::distribute_dofs(), libMesh::DofMap::distribute_local_dofs_node_major(), libMesh::DofMap::distribute_local_dofs_var_major(), libMesh::DistributedMesh::DistributedMesh(), libMesh::DofMap::end_dof(), libMesh::DofMap::end_old_dof(), libMesh::EnsightIO::EnsightIO(), libMesh::MeshFunction::find_element(), libMesh::MeshFunction::find_elements(), libMesh::UnstructuredMesh::find_neighbors(), libMesh::DofMap::first_dof(), libMesh::DofMap::first_old_dof(), 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::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::SystemSubsetBySubdomain::init(), 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::DofMap::last_dof(), 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(), libMesh::MeshRefinement::make_coarsening_compatible(), 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::SparsityPattern::Build::operator()(), libMesh::DistributedMesh::own_node(), libMesh::System::point_gradient(), libMesh::System::point_hessian(), libMesh::System::point_value(), 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(), libMesh::ExodusII_IO_Helper::read_elem_num_map(), libMesh::ExodusII_IO_Helper::read_global_values(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), libMesh::System::read_header(), libMesh::System::read_legacy_data(), libMesh::ExodusII_IO_Helper::read_node_num_map(), libMesh::System::read_parallel_data(), 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::DistributedMesh::renumber_dof_objects(), libMesh::CheckpointIO::select_split_config(), libMesh::DofMap::set_nonlocal_dof_objects(), libMesh::PetscDMWrapper::set_point_range_in_section(), libMesh::LaplaceMeshSmoother::smooth(), libMesh::MeshTools::total_weight(), libMesh::MeshRefinement::uniformly_coarsen(), libMesh::Parallel::Packing< T >::unpack(), libMesh::DistributedMesh::update_parallel_id_counts(), 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_elements(), 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::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::ExodusII_IO_Helper::write_nodal_values(), libMesh::Nemesis_IO_Helper::write_nodesets(), libMesh::ExodusII_IO_Helper::write_nodesets(), libMesh::System::write_parallel_data(), 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::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().

102  { return cast_int<processor_id_type>(_communicator.rank()); }
const Parallel::Communicator & _communicator
processor_id_type rank() const
Definition: communicator.h:173

◆ read() [1/4]

template<typename InValType >
void libMesh::EquationSystems::read ( const std::string &  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 90 of file equation_systems_io.C.

References _mesh, libMesh::MeshRefinement::clean_refinement_flags(), libMesh::Quality::name(), libMesh::out, and TRY_READ_IFEMS.

Referenced by _read_impl(), and read().

94 {
95  // If we have exceptions enabled we can be considerate and try
96  // to read old restart files which contain infinite element
97  // information but do not have the " with infinite elements"
98  // string in the version information.
99 
100  // First try the read the user requested
101  libmesh_try
102  {
103  this->_read_impl<InValType> (name, mode, read_flags, partition_agnostic);
104  }
105 
106  // If that fails, try it again but explicitly request we look for infinite element info
107  libmesh_catch (...)
108  {
109  libMesh::out << "\n*********************************************************************\n"
110  << "READING THE FILE \"" << name << "\" FAILED.\n"
111  << "It is possible this file contains infinite element information,\n"
112  << "but the version string does not contain \" with infinite elements\"\n"
113  << "Let's try this again, but looking for infinite element information...\n"
114  << "*********************************************************************\n"
115  << std::endl;
116 
117  libmesh_try
118  {
119  this->_read_impl<InValType> (name, mode, read_flags | EquationSystems::TRY_READ_IFEMS, partition_agnostic);
120  }
121 
122  // If all that failed, we are out of ideas here...
123  libmesh_catch (...)
124  {
125  libMesh::out << "\n*********************************************************************\n"
126  << "Well, at least we tried!\n"
127  << "Good Luck!!\n"
128  << "*********************************************************************\n"
129  << std::endl;
130  LIBMESH_THROW();
131  }
132  }
133 
134 #ifdef LIBMESH_ENABLE_AMR
135  MeshRefinement mesh_refine(_mesh);
136  mesh_refine.clean_refinement_flags();
137 #endif
138 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
OStreamProxy out(std::cout)

◆ read() [2/4]

template void libMesh::EquationSystems::read< Real > ( const std::string &  name,
const XdrMODE  mode,
const unsigned int  read_flags = (READ_HEADER|READ_DATA),
bool  partition_agnostic = true 
)
inline

Definition at line 417 of file equation_systems.h.

References libMesh::Quality::name().

421  { read<Number>(name, mode, read_flags, partition_agnostic); }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42

◆ read() [3/4]

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

Definition at line 72 of file equation_systems_io.C.

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

75 {
76  XdrMODE mode = READ;
77  if (name.find(".xdr") != std::string::npos)
78  mode = DECODE;
79  this->read(name, mode, read_flags, partition_agnostic);
80 
81 #ifdef LIBMESH_ENABLE_AMR
82  MeshRefinement mesh_refine(_mesh);
83  mesh_refine.clean_refinement_flags();
84 #endif
85 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
void read(const std::string &name, const XdrMODE, const unsigned int read_flags=(READ_HEADER|READ_DATA), bool partition_agnostic=true)

◆ read() [4/4]

template void libMesh::EquationSystems::read< Real > ( const std::string &  name,
const unsigned int  read_flags = (READ_HEADER|READ_DATA),
bool  partition_agnostic = true 
)
inline

Definition at line 428 of file equation_systems.h.

References libMesh::Quality::name().

431  { read<Number>(name, read_flags, partition_agnostic); }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42

◆ 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 524 of file equation_systems.h.

References _refine_in_reinit.

524 { return this->_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 121 of file equation_systems.C.

References reinit_solutions(), and reinit_systems().

Referenced by libMesh::UniformRefinementEstimator::_estimate_error(), and libMesh::AdjointRefinementEstimator::estimate_error().

122 {
123  const bool mesh_changed = this->reinit_solutions();
124 
125  // If the mesh has changed, systems will need to reinitialize their
126  // own data on the new mesh.
127  if (mesh_changed)
128  this->reinit_systems();
129 }

◆ 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 133 of file equation_systems.C.

References _mesh, _refine_in_reinit, libMesh::MeshRefinement::coarsen_elements(), libMesh::MeshBase::contract(), libMesh::DofMap::distribute_dofs(), libMesh::MeshBase::element_ptr_range(), libMesh::MeshRefinement::face_level_mismatch_limit(), libMesh::System::get_dof_map(), get_mesh(), get_system(), n_systems(), libMesh::MeshBase::node_ptr_range(), libMesh::MeshRefinement::overrefined_boundary_limit(), 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().

134 {
135  parallel_object_only();
136 
137  const unsigned int n_sys = this->n_systems();
138  libmesh_assert_not_equal_to (n_sys, 0);
139 
140  // We may have added new systems since our last
141  // EquationSystems::(re)init call
142  bool _added_new_systems = false;
143  for (unsigned int i=0; i != n_sys; ++i)
144  if (!this->get_system(i).is_initialized())
145  _added_new_systems = true;
146 
147  if (_added_new_systems)
148  {
149  // Our DofObjects will need space for the additional systems
150  for (auto & node : _mesh.node_ptr_range())
151  node->set_n_systems(n_sys);
152 
153  for (auto & elem : _mesh.element_ptr_range())
154  elem->set_n_systems(n_sys);
155 
156  // And any new systems will need initialization
157  for (unsigned int i=0; i != n_sys; ++i)
158  if (!this->get_system(i).is_initialized())
159  this->get_system(i).init();
160  }
161 
162 
163  // We used to assert that all nodes and elements *already* had
164  // n_systems() properly set; however this is false in the case where
165  // user code has manually added nodes and/or elements to an
166  // already-initialized system.
167 
168  // Make sure all the \p DofObject entities know how many systems
169  // there are.
170  {
171  // All the nodes
172  for (auto & node : _mesh.node_ptr_range())
173  node->set_n_systems(this->n_systems());
174 
175  // All the elements
176  for (auto & elem : _mesh.element_ptr_range())
177  elem->set_n_systems(this->n_systems());
178  }
179 
180  // Localize each system's vectors
181  for (unsigned int i=0; i != this->n_systems(); ++i)
182  this->get_system(i).re_update();
183 
184 #ifdef LIBMESH_ENABLE_AMR
185 
186  bool dof_constraints_created = false;
187  bool mesh_changed = false;
188 
189  // FIXME: For backwards compatibility, assume
190  // refine_and_coarsen_elements or refine_uniformly have already
191  // been called
192  {
193  for (unsigned int i=0; i != this->n_systems(); ++i)
194  {
195  System & sys = this->get_system(i);
196 
197  // Even if the system doesn't have any variables in it we want
198  // consistent behavior; e.g. distribute_dofs should have the
199  // opportunity to count up zero dofs on each processor.
200  //
201  // Who's been adding zero-var systems anyway, outside of my
202  // unit tests? - RHS
203  // if (!sys.n_vars())
204  // continue;
205 
206  sys.get_dof_map().distribute_dofs(_mesh);
207 
208  // Recreate any user or internal constraints
209  sys.reinit_constraints();
210 
211  sys.prolong_vectors();
212  }
213  mesh_changed = true;
214  dof_constraints_created = true;
215  }
216 
217  if (this->_refine_in_reinit)
218  {
219  // Don't override any user refinement settings
220  MeshRefinement mesh_refine(_mesh);
221  mesh_refine.face_level_mismatch_limit() = 0; // unlimited
222  mesh_refine.overrefined_boundary_limit() = -1; // unlimited
223  mesh_refine.underrefined_boundary_limit() = -1; // unlimited
224 
225  // Try to coarsen the mesh, then restrict each system's vectors
226  // if necessary
227  if (mesh_refine.coarsen_elements())
228  {
229  for (unsigned int i=0; i != this->n_systems(); ++i)
230  {
231  System & sys = this->get_system(i);
232  if (!dof_constraints_created)
233  {
234  sys.get_dof_map().distribute_dofs(_mesh);
235  sys.reinit_constraints();
236  }
237  sys.restrict_vectors();
238  }
239  mesh_changed = true;
240  dof_constraints_created = true;
241  }
242 
243  // Once vectors are all restricted, we can delete
244  // children of coarsened elements
245  if (mesh_changed)
246  this->get_mesh().contract();
247 
248  // Try to refine the mesh, then prolong each system's vectors
249  // if necessary
250  if (mesh_refine.refine_elements())
251  {
252  for (unsigned int i=0; i != this->n_systems(); ++i)
253  {
254  System & sys = this->get_system(i);
255  if (!dof_constraints_created)
256  {
257  sys.get_dof_map().distribute_dofs(_mesh);
258  sys.reinit_constraints();
259  }
260  sys.prolong_vectors();
261  }
262  mesh_changed = true;
263  // dof_constraints_created = true;
264  }
265  }
266 
267  return mesh_changed;
268 
269 #endif // #ifdef LIBMESH_ENABLE_AMR
270 
271  return false;
272 }
unsigned int n_systems() const
const T_sys & get_system(const std::string &name) const
virtual SimpleRange< element_iterator > element_ptr_range()=0
virtual SimpleRange< node_iterator > node_ptr_range()=0
virtual bool contract()=0
const MeshBase & get_mesh() const

◆ reinit_systems()

void libMesh::EquationSystems::reinit_systems ( )
virtual

Reinitialize all systems on the current mesh.

Definition at line 276 of file equation_systems.C.

References get_system(), and n_systems().

Referenced by reinit().

277 {
278  for (unsigned int i=0; i != this->n_systems(); ++i)
279  this->get_system(i).reinit();
280 }
unsigned int n_systems() const
const T_sys & get_system(const std::string &name) const

◆ 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 466 of file equation_systems.C.

References get_system(), and n_systems().

467 {
468  libmesh_assert (this->n_systems());
469 
470  for (unsigned int i=0; i != this->n_systems(); ++i)
471  this->get_system(i).sensitivity_solve(parameters_in);
472 }
unsigned int n_systems() const
const T_sys & get_system(const std::string &name) const

◆ 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 456 of file equation_systems.C.

References get_system(), and n_systems().

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

457 {
458  libmesh_assert (this->n_systems());
459 
460  for (unsigned int i=0; i != this->n_systems(); ++i)
461  this->get_system(i).solve();
462 }
unsigned int n_systems() const
const T_sys & get_system(const std::string &name) const

◆ update()

void libMesh::EquationSystems::update ( )

Updates local values for all the systems

Definition at line 344 of file equation_systems.C.

References get_system(), and n_systems().

Referenced by _read_impl().

345 {
346  LOG_SCOPE("update()", "EquationSystems");
347 
348  // Localize each system's vectors
349  for (unsigned int i=0; i != this->n_systems(); ++i)
350  this->get_system(i).update();
351 }
unsigned int n_systems() const
const T_sys & get_system(const std::string &name) const

◆ write() [1/2]

void libMesh::EquationSystems::write ( const std::string &  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!


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 378 of file equation_systems_io.C.

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

Referenced by libMesh::ErrorVector::plot_error(), write(), and libMesh::NameBasedIO::write_equation_systems().

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

◆ write() [2/2]

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

Definition at line 366 of file equation_systems_io.C.

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

369 {
370  XdrMODE mode = WRITE;
371  if (name.find(".xdr") != std::string::npos)
372  mode = ENCODE;
373  this->write(name, mode, write_flags, partition_agnostic);
374 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
void write(const std::string &name, const XdrMODE, const unsigned int write_flags=(WRITE_DATA), bool partition_agnostic=true) const

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 1287 of file equation_systems.C.

1289 {
1290  es.print_info(os);
1291  return os;
1292 }

Member Data Documentation

◆ _communicator

◆ _counts

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

◆ _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 578 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 141 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

◆ _mutex

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

Mutual exclusion object to enable thread-safe reference counting.

Definition at line 135 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 130 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 572 of file equation_systems.h.

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

◆ _systems

◆ parameters


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