libMesh::MeshOutput< MT > Class Template Referenceabstract

#include <mesh_output.h>

Public Member Functions

virtual ~MeshOutput ()
 
virtual void write (const std::string &)=0
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 
virtual void write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 
virtual void write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 
unsigned int & ascii_precision ()
 

Protected Member Functions

 MeshOutput (const bool is_parallel_format=false, const bool serial_only_needed_on_proc_0=false)
 
 MeshOutput (const MT &, const bool is_parallel_format=false, const bool serial_only_needed_on_proc_0=false)
 
const MT & mesh () const
 

Protected Attributes

const bool _is_parallel_format
 
const bool _serial_only_needed_on_proc_0
 

Private Attributes

const MT *const _obj
 
unsigned int _ascii_precision
 

Detailed Description

template<class MT>
class libMesh::MeshOutput< MT >

This class defines an abstract interface for Mesh output. Specific classes derived from this class actually implement writing various mesh formats.

Author
Benjamin S. Kirk
Date
2004

Definition at line 53 of file mesh_output.h.

Constructor & Destructor Documentation

◆ MeshOutput() [1/2]

template<class MT >
libMesh::MeshOutput< MT >::MeshOutput ( const bool  is_parallel_format = false,
const bool  serial_only_needed_on_proc_0 = false 
)
inlineexplicitprotected

Default constructor. Will set the _obj to nullptr, effectively rendering this object useless.

Definition at line 194 of file mesh_output.h.

194  :
195  _is_parallel_format(is_parallel_format),
196  _serial_only_needed_on_proc_0(serial_only_needed_on_proc_0),
197  _obj(nullptr),
198  _ascii_precision (std::numeric_limits<Real>::digits10 + 2)
199 {}
const MT *const _obj
Definition: mesh_output.h:177
const bool _is_parallel_format
Definition: mesh_output.h:159
unsigned int _ascii_precision
Definition: mesh_output.h:182
const bool _serial_only_needed_on_proc_0
Definition: mesh_output.h:168

◆ MeshOutput() [2/2]

template<class MT>
libMesh::MeshOutput< MT >::MeshOutput ( const MT &  obj,
const bool  is_parallel_format = false,
const bool  serial_only_needed_on_proc_0 = false 
)
inlineexplicitprotected

Constructor. Takes a reference to a constant object. This constructor will only allow us to write the object.

Definition at line 205 of file mesh_output.h.

205  :
206  _is_parallel_format(is_parallel_format),
207  _serial_only_needed_on_proc_0(serial_only_needed_on_proc_0),
208  _obj (&obj),
209  _ascii_precision (std::numeric_limits<Real>::digits10 + 2)
210 {
211  if (!_is_parallel_format && !this->mesh().is_serial())
212  {
213  if (this->mesh().processor_id() == 0)
214  {
215  libmesh_do_once(libMesh::out <<
216  "Warning: This MeshOutput subclass only supports meshes which have been serialized!"
217  << std::endl;);
218  }
219  }
220 }
const MT & mesh() const
Definition: mesh_output.h:234
const MT *const _obj
Definition: mesh_output.h:177
const bool _is_parallel_format
Definition: mesh_output.h:159
unsigned int _ascii_precision
Definition: mesh_output.h:182
const bool _serial_only_needed_on_proc_0
Definition: mesh_output.h:168
OStreamProxy out(std::cout)

◆ ~MeshOutput()

template<class MT >
libMesh::MeshOutput< MT >::~MeshOutput ( )
inlinevirtual

Destructor.

Definition at line 226 of file mesh_output.h.

227 {
228 }

Member Function Documentation

◆ ascii_precision()

template<class MT >
unsigned int & libMesh::MeshOutput< MT >::ascii_precision ( )
inline

Return/set the precision to use when writing ASCII files.

By default we use numeric_limits<Real>::digits10 + 2, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Definition at line 244 of file mesh_output.h.

245 {
246  return _ascii_precision;
247 }
unsigned int _ascii_precision
Definition: mesh_output.h:182

◆ mesh()

template<class MT >
const MT & libMesh::MeshOutput< MT >::mesh ( ) const
inlineprotected
Returns
The object as a read-only reference.

Definition at line 234 of file mesh_output.h.

Referenced by libMesh::VTKIO::cells_to_vtk(), libMesh::TecplotIO::elem_dimension(), libMesh::UNVIO::elements_out(), libMesh::UNVIO::nodes_out(), libMesh::VTKIO::nodes_to_vtk(), libMesh::Nemesis_IO::prepare_to_write_nodal_data(), libMesh::FroIO::write(), libMesh::PostscriptIO::write(), libMesh::TetGenIO::write(), libMesh::Nemesis_IO::write(), libMesh::ExodusII_IO::write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::MEDITIO::write_ascii(), libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::TecplotIO::write_binary(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::Nemesis_IO::write_element_data(), libMesh::ExodusII_IO::write_element_data(), libMesh::EnsightIO::write_geometry_ascii(), libMesh::UCDIO::write_implementation(), libMesh::GmshIO::write_mesh(), libMesh::VTKIO::write_nodal_data(), libMesh::UCDIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), libMesh::CheckpointIO::write_nodesets(), libMesh::XdrIO::write_parallel(), libMesh::GmshIO::write_post(), libMesh::EnsightIO::write_scalar_ascii(), libMesh::XdrIO::write_serialized_bcs_helper(), libMesh::XdrIO::write_serialized_connectivity(), libMesh::XdrIO::write_serialized_nodes(), libMesh::XdrIO::write_serialized_nodesets(), libMesh::XdrIO::write_serialized_subdomain_names(), libMesh::GnuPlotIO::write_solution(), libMesh::CheckpointIO::write_subdomain_names(), and libMesh::EnsightIO::write_vector_ascii().

235 {
236  libmesh_assert(_obj);
237  return *_obj;
238 }
const MT *const _obj
Definition: mesh_output.h:177

◆ write()

◆ write_discontinuous_equation_systems()

template<class MT >
void libMesh::MeshOutput< MT >::write_discontinuous_equation_systems ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
virtual

This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object.

Definition at line 92 of file mesh_output.C.

95 {
96  LOG_SCOPE("write_discontinuous_equation_systems()", "MeshOutput");
97 
98  // We may need to gather and/or renumber a DistributedMesh to output
99  // it, making that const qualifier in our constructor a dirty lie
100  MT & my_mesh = const_cast<MT &>(*_obj);
101 
102  // If we're asked to write data that's associated with a different
103  // mesh, output files full of garbage are the result.
104  libmesh_assert_equal_to(&es.get_mesh(), _obj);
105 
106  // A non-renumbered mesh may not have a contiguous numbering, and
107  // that needs to be fixed before we can build a solution vector.
108  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
109  my_mesh.max_node_id() != my_mesh.n_nodes())
110  {
111  // If we were allowed to renumber then we should have already
112  // been properly renumbered...
113  libmesh_assert(!my_mesh.allow_renumbering());
114 
115  libmesh_do_once(libMesh::out <<
116  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
117  << std::endl;);
118 
119  my_mesh.allow_renumbering(true);
120 
121  my_mesh.renumber_nodes_and_elements();
122 
123  // Not sure what good going back to false will do here, the
124  // renumbering horses have already left the barn...
125  my_mesh.allow_renumbering(false);
126  }
127 
128  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
129 
130  // Build the list of variable names that will be written.
131  std::vector<std::string> names;
132  es.build_variable_names (names, nullptr, system_names);
133 
134  if (!_is_parallel_format)
135  {
136  // Build the nodal solution values & get the variable
137  // names from the EquationSystems object
138  std::vector<Number> soln;
139  es.build_discontinuous_solution_vector (soln, system_names);
140 
141  this->write_nodal_data_discontinuous (fname, soln, names);
142  }
143  else // _is_parallel_format
144  {
145  libmesh_not_implemented();
146  }
147 }
virtual void write_nodal_data_discontinuous(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:114
const MT *const _obj
Definition: mesh_output.h:177
const bool _is_parallel_format
Definition: mesh_output.h:159
const bool _serial_only_needed_on_proc_0
Definition: mesh_output.h:168
OStreamProxy out(std::cout)

◆ write_equation_systems()

template<class MT >
void libMesh::MeshOutput< MT >::write_equation_systems ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
virtual

This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.

Reimplemented in libMesh::NameBasedIO.

Definition at line 31 of file mesh_output.C.

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

34 {
35  LOG_SCOPE("write_equation_systems()", "MeshOutput");
36 
37  // We may need to gather and/or renumber a DistributedMesh to output
38  // it, making that const qualifier in our constructor a dirty lie
39  MT & my_mesh = const_cast<MT &>(*_obj);
40 
41  // If we're asked to write data that's associated with a different
42  // mesh, output files full of garbage are the result.
43  libmesh_assert_equal_to(&es.get_mesh(), _obj);
44 
45  // A non-renumbered mesh may not have a contiguous numbering, and
46  // that needs to be fixed before we can build a solution vector.
47  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
48  my_mesh.max_node_id() != my_mesh.n_nodes())
49  {
50  // If we were allowed to renumber then we should have already
51  // been properly renumbered...
52  libmesh_assert(!my_mesh.allow_renumbering());
53 
54  libmesh_do_once(libMesh::out <<
55  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
56  << std::endl;);
57 
58  my_mesh.allow_renumbering(true);
59 
60  my_mesh.renumber_nodes_and_elements();
61 
62  // Not sure what good going back to false will do here, the
63  // renumbering horses have already left the barn...
64  my_mesh.allow_renumbering(false);
65  }
66 
67  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
68 
69  // Build the list of variable names that will be written.
70  std::vector<std::string> names;
71  es.build_variable_names (names, nullptr, system_names);
72 
74  {
75  // Build the nodal solution values & get the variable
76  // names from the EquationSystems object
77  std::vector<Number> soln;
78  es.build_solution_vector (soln, system_names);
79 
80  this->write_nodal_data (fname, soln, names);
81  }
82  else // _is_parallel_format
83  {
84  std::unique_ptr<NumericVector<Number>> parallel_soln =
85  es.build_parallel_solution_vector(system_names);
86 
87  this->write_nodal_data (fname, *parallel_soln, names);
88  }
89 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:105
const MT *const _obj
Definition: mesh_output.h:177
const bool _is_parallel_format
Definition: mesh_output.h:159
const bool _serial_only_needed_on_proc_0
Definition: mesh_output.h:168
OStreamProxy out(std::cout)

◆ write_nodal_data() [1/2]

template<class MT>
virtual void libMesh::MeshOutput< MT >::write_nodal_data ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtual

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.

Reimplemented in libMesh::ExodusII_IO, libMesh::Nemesis_IO, libMesh::UCDIO, libMesh::NameBasedIO, libMesh::GmshIO, libMesh::GMVIO, libMesh::VTKIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 105 of file mesh_output.h.

108  { libmesh_not_implemented(); }

◆ write_nodal_data() [2/2]

template<class MT >
void libMesh::MeshOutput< MT >::write_nodal_data ( const std::string &  fname,
const NumericVector< Number > &  parallel_soln,
const std::vector< std::string > &  names 
)
virtual

This method should be overridden by "parallel" output formats for writing nodal data. Instead of getting a localized copy of the nodal solution vector, it is passed a NumericVector of type=PARALLEL which is in node-major order i.e. (u0,v0,w0, u1,v1,w1, u2,v2,w2, u3,v3,w3, ...) and contains n_nodes*n_vars total entries. Then, it is up to the individual I/O class to extract the required solution values from this vector and write them in parallel.

If not implemented, localizes the parallel vector into a std::vector and calls the other version of this function.

Reimplemented in libMesh::Nemesis_IO.

Definition at line 150 of file mesh_output.C.

153 {
154  // This is the fallback implementation for parallel I/O formats that
155  // do not yet implement proper writing in parallel, and instead rely
156  // on the full solution vector being available on all processors.
157  std::vector<Number> soln;
158  parallel_soln.localize(soln);
159  this->write_nodal_data(fname, soln, names);
160 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:105
virtual void localize(std::vector< T > &v_local) const =0

◆ write_nodal_data_discontinuous()

template<class MT>
virtual void libMesh::MeshOutput< MT >::write_nodal_data_discontinuous ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtual

This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided.

Reimplemented in libMesh::ExodusII_IO.

Definition at line 114 of file mesh_output.h.

117  { libmesh_not_implemented(); }

Member Data Documentation

◆ _ascii_precision

template<class MT>
unsigned int libMesh::MeshOutput< MT >::_ascii_precision
private

Precision to use when writing ASCII files.

Definition at line 182 of file mesh_output.h.

◆ _is_parallel_format

template<class MT>
const bool libMesh::MeshOutput< MT >::_is_parallel_format
protected

Flag specifying whether this format is parallel-capable. If this is false (default) I/O is only permitted when the mesh has been serialized.

Definition at line 159 of file mesh_output.h.

◆ _obj

template<class MT>
const MT* const libMesh::MeshOutput< MT >::_obj
private

A pointer to a constant object. This allows us to write the object to file.

Definition at line 177 of file mesh_output.h.

◆ _serial_only_needed_on_proc_0

template<class MT>
const bool libMesh::MeshOutput< MT >::_serial_only_needed_on_proc_0
protected

Flag specifying whether this format can be written by only serializing the mesh to processor zero

If this is false (default) the mesh will be serialized to all processors

Definition at line 168 of file mesh_output.h.


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