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

This class implements reading & writing meshes in the AVS's UCD format. More...

#include <ucd_io.h>

Inheritance diagram for libMesh::UCDIO:
[legend]

Public Member Functions

 UCDIO (MeshBase &mesh)
 Constructor. More...
 
 UCDIO (const MeshBase &mesh)
 Constructor. More...
 
virtual void read (const std::string &) override
 This method implements reading a mesh from a specified file in UCD format. More...
 
virtual void write (const std::string &) override
 This method implements writing a mesh to a specified file in UCD format. More...
 
virtual void write_nodal_data (const std::string &fname, const std::vector< Number > &soln, const std::vector< std::string > &names) override
 This method implements writing a mesh and solution to a specified file in UCD format. More...
 
bool is_parallel_format () const
 Returns true iff this mesh file format and input class are parallelized, so that all processors can read their share of the data at once. More...
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 This method may be overridden by "parallel" output formats for writing nodal data. More...
 
virtual void write_nodal_data (const std::string &, const EquationSystems &, const std::set< std::string > *)
 This method should be overridden by "parallel" output formats for writing nodal data. More...
 
virtual void write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided. More...
 
unsigned intascii_precision ()
 Return/set the precision to use when writing ASCII files. More...
 

Protected Member Functions

MeshBasemesh ()
 
void set_n_partitions (unsigned int n_parts)
 Sets the number of partitions in the mesh. More...
 
void skip_comment_lines (std::istream &in, const char comment_start)
 Reads input from in, skipping all the lines that start with the character comment_start. More...
 
const MeshBasemesh () const
 
virtual bool get_add_sides ()
 

Protected Attributes

std::vector< bool > elems_of_dimension
 A vector of bools describing what dimension elements have been encountered when reading a mesh. More...
 
const bool _is_parallel_format
 Flag specifying whether this format is parallel-capable. More...
 
const bool _serial_only_needed_on_proc_0
 Flag specifying whether this format can be written by only serializing the mesh to processor zero. More...
 

Private Member Functions

void read_implementation (std::istream &in_stream)
 The actual implementation of the read function. More...
 
void write_implementation (std::ostream &out_stream)
 The actual implementation of the write function. More...
 
void write_header (std::ostream &out, const MeshBase &mesh, dof_id_type n_elems, unsigned int n_vars)
 Write UCD format header. More...
 
void write_nodes (std::ostream &out, const MeshBase &mesh)
 Write node information. More...
 
void write_interior_elems (std::ostream &out, const MeshBase &mesh)
 Write element information. More...
 
void write_soln (std::ostream &out, const MeshBase &mesh, const std::vector< std::string > &names, const std::vector< Number > &soln)
 Writes all nodal solution variables. More...
 

Static Private Member Functions

static std::map< ElemType, std::string > build_writing_element_map ()
 
static std::map< std::string, ElemTypebuild_reading_element_map ()
 

Static Private Attributes

static std::map< ElemType, std::string > _writing_element_map = UCDIO::build_writing_element_map()
 
static std::map< std::string, ElemType_reading_element_map = UCDIO::build_reading_element_map()
 

Detailed Description

This class implements reading & writing meshes in the AVS's UCD format.

Author
Benjamin S. Kirk
Date
2004

Definition at line 44 of file ucd_io.h.

Constructor & Destructor Documentation

◆ UCDIO() [1/2]

libMesh::UCDIO::UCDIO ( MeshBase mesh)
inlineexplicit

Constructor.

Takes a writable reference to a mesh object. This is the constructor required to read a mesh.

Definition at line 54 of file ucd_io.h.

54  :
55  MeshInput<MeshBase> (mesh),
57  {}
template class LIBMESH_EXPORT MeshOutput< MeshBase >
Definition: mesh_output.C:180

◆ UCDIO() [2/2]

libMesh::UCDIO::UCDIO ( const MeshBase mesh)
inlineexplicit

Constructor.

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

Definition at line 64 of file ucd_io.h.

64  :
66  {}
template class LIBMESH_EXPORT MeshOutput< MeshBase >
Definition: mesh_output.C:180

Member Function Documentation

◆ ascii_precision()

unsigned int & libMesh::MeshOutput< MeshBase >::ascii_precision ( )
inlineinherited

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

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

Definition at line 269 of file mesh_output.h.

Referenced by libMesh::UNVIO::nodes_out(), libMesh::FroIO::write(), libMesh::STLIO::write(), libMesh::MEDITIO::write_ascii(), libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().

270 {
271  return _ascii_precision;
272 }
unsigned int _ascii_precision
Precision to use when writing ASCII files.
Definition: mesh_output.h:207

◆ build_reading_element_map()

std::map< std::string, ElemType > libMesh::UCDIO::build_reading_element_map ( )
staticprivate

Definition at line 68 of file ucd_io.C.

References libMesh::EDGE2, libMesh::HEX8, libMesh::PRISM6, libMesh::PYRAMID5, libMesh::QUAD4, libMesh::TET4, and libMesh::TRI3.

69 {
70  std::map<std::string, ElemType> ret;
71  ret["edge"] = EDGE2;
72  ret["tri"] = TRI3;
73  ret["quad"] = QUAD4;
74  ret["tet"] = TET4;
75  ret["hex"] = HEX8;
76  ret["prism"] = PRISM6;
77  ret["pyramid"] = PYRAMID5;
78  return ret;
79 }

◆ build_writing_element_map()

std::map< ElemType, std::string > libMesh::UCDIO::build_writing_element_map ( )
staticprivate

Definition at line 52 of file ucd_io.C.

References libMesh::EDGE2, libMesh::HEX8, libMesh::PRISM6, libMesh::PYRAMID5, libMesh::QUAD4, libMesh::TET4, and libMesh::TRI3.

53 {
54  std::map<ElemType, std::string> ret;
55  ret[EDGE2] = "edge";
56  ret[TRI3] = "tri";
57  ret[QUAD4] = "quad";
58  ret[TET4] = "tet";
59  ret[HEX8] = "hex";
60  ret[PRISM6] = "prism";
61  ret[PYRAMID5] = "pyramid";
62  return ret;
63 }

◆ get_add_sides()

virtual bool libMesh::MeshOutput< MeshBase >::get_add_sides ( )
inlineprotectedvirtualinherited
Returns
Whether or not added sides are expected to be output, to plot SIDE_DISCONTINUOUS data. Subclasses should override this if they are capable of plotting such data.

Reimplemented in libMesh::ExodusII_IO.

Definition at line 176 of file mesh_output.h.

176 { return false; }

◆ is_parallel_format()

bool libMesh::MeshInput< MeshBase >::is_parallel_format ( ) const
inlineinherited

Returns true iff this mesh file format and input class are parallelized, so that all processors can read their share of the data at once.

Definition at line 87 of file mesh_input.h.

References libMesh::MeshInput< MT >::_is_parallel_format.

87 { return this->_is_parallel_format; }
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition: mesh_input.h:130

◆ mesh() [1/2]

MeshBase & libMesh::MeshInput< MeshBase >::mesh ( )
inlineprotectedinherited
Returns
The object as a writable reference.

Definition at line 178 of file mesh_input.h.

Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::VTKIO::cells_to_vtk(), libMesh::ExodusII_IO::copy_elemental_solution(), libMesh::Nemesis_IO::copy_elemental_solution(), libMesh::ExodusII_IO::copy_nodal_solution(), libMesh::TetGenIO::element_in(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::elements_out(), libMesh::VTKIO::get_local_node_values(), libMesh::ExodusII_IO::get_sideset_data_indices(), libMesh::UNVIO::groups_in(), libMesh::TetGenIO::node_in(), libMesh::UNVIO::nodes_in(), libMesh::UNVIO::nodes_out(), libMesh::VTKIO::nodes_to_vtk(), libMesh::Nemesis_IO::prepare_to_write_nodal_data(), libMesh::GMVIO::read(), libMesh::STLIO::read(), libMesh::Nemesis_IO::read(), libMesh::XdrIO::read(), libMesh::ExodusII_IO::read(), libMesh::CheckpointIO::read(), libMesh::VTKIO::read(), libMesh::STLIO::read_ascii(), libMesh::CheckpointIO::read_bcs(), libMesh::STLIO::read_binary(), libMesh::CheckpointIO::read_connectivity(), libMesh::ExodusII_IO::read_header(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), read_implementation(), libMesh::UNVIO::read_implementation(), libMesh::GmshIO::read_mesh(), libMesh::DynaIO::read_mesh(), libMesh::CheckpointIO::read_nodes(), libMesh::CheckpointIO::read_nodesets(), libMesh::CheckpointIO::read_remote_elem(), libMesh::XdrIO::read_serialized_bcs_helper(), libMesh::XdrIO::read_serialized_connectivity(), libMesh::XdrIO::read_serialized_nodes(), libMesh::XdrIO::read_serialized_nodesets(), libMesh::XdrIO::read_serialized_subdomain_names(), libMesh::ExodusII_IO::read_sideset_data(), libMesh::OFFIO::read_stream(), libMesh::MatlabIO::read_stream(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::STLIO::write(), libMesh::TetGenIO::write(), libMesh::Nemesis_IO::write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::write(), libMesh::ExodusII_IO::write(), libMesh::GMVIO::write_ascii_new_impl(), libMesh::GMVIO::write_ascii_old_impl(), libMesh::GMVIO::write_binary(), libMesh::GMVIO::write_discontinuous_gmv(), libMesh::Nemesis_IO::write_element_data(), libMesh::ExodusII_IO::write_element_data(), libMesh::ExodusII_IO::write_elemsets(), write_header(), write_implementation(), write_interior_elems(), libMesh::GmshIO::write_mesh(), write_nodal_data(), libMesh::VTKIO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data(), libMesh::ExodusII_IO::write_nodal_data_common(), libMesh::ExodusII_IO::write_nodal_data_discontinuous(), write_nodes(), libMesh::CheckpointIO::write_nodesets(), libMesh::XdrIO::write_parallel(), libMesh::GmshIO::write_post(), 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::ExodusII_IO::write_sideset_data(), write_soln(), and libMesh::CheckpointIO::write_subdomain_names().

179 {
180  libmesh_error_msg_if(_obj == nullptr, "ERROR: _obj should not be nullptr!");
181  return *_obj;
182 }
MeshBase * _obj
A pointer to a non-const object object.
Definition: mesh_input.h:123

◆ mesh() [2/2]

const MeshBase & libMesh::MeshOutput< MeshBase >::mesh ( ) const
inlineprotectedinherited

◆ read()

void libMesh::UCDIO::read ( const std::string &  file_name)
overridevirtual

This method implements reading a mesh from a specified file in UCD format.

Implements libMesh::MeshInput< MeshBase >.

Definition at line 82 of file ucd_io.C.

References read_implementation().

Referenced by libMesh::NameBasedIO::read().

83 {
84  if (file_name.rfind(".gz") < file_name.size())
85  {
86 #ifdef LIBMESH_HAVE_GZSTREAM
87  igzstream in_stream (file_name.c_str());
88  this->read_implementation (in_stream);
89 #else
90  libmesh_error_msg("ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
91 #endif
92  }
93 
94  else
95  {
96  std::ifstream in_stream (file_name.c_str());
97  this->read_implementation (in_stream);
98  }
99 }
void read_implementation(std::istream &in_stream)
The actual implementation of the read function.
Definition: ucd_io.C:124

◆ read_implementation()

void libMesh::UCDIO::read_implementation ( std::istream &  in_stream)
private

The actual implementation of the read function.

The public read interface simply decides which type of stream to pass the implementation.

Definition at line 124 of file ucd_io.C.

References _reading_element_map, libMesh::MeshBase::add_elem(), libMesh::MeshBase::add_point(), libMesh::Elem::build(), libMesh::MeshInput< MeshBase >::elems_of_dimension, libMesh::libmesh_assert(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::MeshBase::n_nodes(), libMesh::MeshBase::node_ptr(), libMesh::MeshBase::set_mesh_dimension(), and libMesh::MeshInput< MeshBase >::skip_comment_lines().

Referenced by read().

125 {
126  // This is a serial-only process for now;
127  // the Mesh should be read on processor 0 and
128  // broadcast later
129  libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().processor_id(), 0);
130 
131  // Check input buffer
132  libmesh_assert (in.good());
133 
134  MeshBase & mesh = MeshInput<MeshBase>::mesh();
135 
136  // Keep track of what kinds of elements this file contains
137  elems_of_dimension.clear();
138  elems_of_dimension.resize(4, false);
139 
140  this->skip_comment_lines (in, '#');
141 
142  unsigned int nNodes=0, nElem=0, dummy=0;
143 
144  in >> nNodes // Read the number of nodes from the stream
145  >> nElem // Read the number of elements from the stream
146  >> dummy
147  >> dummy
148  >> dummy;
149 
150 
151  // Read the nodal coordinates. Note that UCD format always
152  // stores (x,y,z), and in 2D z=0. We don't need to store this,
153  // however. So, we read in x,y,z for each node and make a point
154  // in the proper way based on what dimension we're in
155  {
156  for (unsigned int i=0; i<nNodes; i++)
157  {
158  libmesh_assert (in.good());
159 
160  std::array<Real, 3> xyz;
161 
162  in >> dummy // Point number
163  >> xyz[0] // x-coordinate value
164  >> xyz[1] // y-coordinate value
165  >> xyz[2]; // z-coordinate value
166 
167  Point p(xyz[0]);
168 #if LIBMESH_DIM > 1
169  p(1) = xyz[1];
170 #else
171  libmesh_assert_equal_to(xyz[1], 0);
172 #endif
173 #if LIBMESH_DIM > 2
174  p(2) = xyz[2];
175 #else
176  libmesh_assert_equal_to(xyz[2], 0);
177 #endif
178 
179  // Build the node
180  mesh.add_point (p, i);
181  }
182  }
183 
184  // Read the elements from the stream. Notice that the UCD node-numbering
185  // scheme is 1-based, and we just created a 0-based scheme above
186  // (which is of course what we want). So, when we read in the nodal
187  // connectivity for each element we need to take 1 off the value of
188  // each node so that we get the right thing.
189  {
190  unsigned int material_id=0, node=0;
191  std::string type;
192 
193  for (unsigned int i=0; i<nElem; i++)
194  {
195  libmesh_assert (in.good());
196 
197  // The cell type can be either tri, quad, tet, hex, or prism.
198  in >> dummy // Cell number, means nothing to us
199  >> material_id // We'll use this for the element subdomain id.
200  >> type; // string describing cell type
201 
202  // Convert the UCD type string to a libmesh ElemType
203  ElemType et = libmesh_map_find(_reading_element_map, type);
204 
205  // Build the required type and release it into our custody.
206  auto elem = Elem::build(et);
207 
208  for (auto n : elem->node_index_range())
209  {
210  libmesh_assert (in.good());
211 
212  in >> node; // read the current node
213  node -= 1; // UCD is 1-based, so subtract
214 
215  libmesh_assert_less (node, mesh.n_nodes());
216 
217  // assign the node
218  elem->set_node(n, mesh.node_ptr(node));
219  }
220 
221  elems_of_dimension[elem->dim()] = true;
222 
223  // Set the element's subdomain ID based on the material_id.
224  elem->subdomain_id() = cast_int<subdomain_id_type>(material_id);
225 
226  // Add the element to the mesh
227  elem->set_id(i);
228  mesh.add_elem (std::move(elem));
229  }
230 
231  // Set the mesh dimension to the largest encountered for an element
232  for (unsigned char i=0; i!=4; ++i)
233  if (elems_of_dimension[i])
235 
236 #if LIBMESH_DIM < 3
237  libmesh_error_msg_if(mesh.mesh_dimension() > LIBMESH_DIM,
238  "Cannot open dimension "
239  << mesh.mesh_dimension()
240  << " mesh file when configured without "
241  << mesh.mesh_dimension()
242  << "D support.");
243 #endif
244  }
245 }
const MeshBase & mesh() const
Definition: mesh_output.h:259
ElemType
Defines an enum for geometric element types.
std::vector< bool > elems_of_dimension
A vector of bools describing what dimension elements have been encountered when reading a mesh...
Definition: mesh_input.h:107
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
void skip_comment_lines(std::istream &in, const char comment_start)
Reads input from in, skipping all the lines that start with the character comment_start.
Definition: mesh_input.h:187
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:444
libmesh_assert(ctx)
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
Definition: mesh_base.h:275
unsigned int mesh_dimension() const
Definition: mesh_base.C:372
static std::map< std::string, ElemType > _reading_element_map
Definition: ucd_io.h:145
virtual const Node * node_ptr(const dof_id_type i) const =0
virtual dof_id_type n_nodes() const =0

◆ set_n_partitions()

void libMesh::MeshInput< MeshBase >::set_n_partitions ( unsigned int  n_parts)
inlineprotectedinherited

Sets the number of partitions in the mesh.

Typically this gets done by the partitioner, but some parallel file formats begin "pre-partitioned".

Definition at line 101 of file mesh_input.h.

References libMesh::MeshInput< MT >::mesh().

Referenced by libMesh::Nemesis_IO::read(), and libMesh::XdrIO::read_header().

101 { this->mesh().set_n_partitions() = n_parts; }
unsigned int & set_n_partitions()
Definition: mesh_base.h:1865

◆ skip_comment_lines()

void libMesh::MeshInput< MeshBase >::skip_comment_lines ( std::istream &  in,
const char  comment_start 
)
protectedinherited

Reads input from in, skipping all the lines that start with the character comment_start.

Definition at line 187 of file mesh_input.h.

Referenced by libMesh::TetGenIO::read(), and read_implementation().

189 {
190  char c, line[256];
191 
192  while (in.get(c), c==comment_start)
193  in.getline (line, 255);
194 
195  // put back first character of
196  // first non-comment line
197  in.putback (c);
198 }

◆ write()

void libMesh::UCDIO::write ( const std::string &  file_name)
overridevirtual

This method implements writing a mesh to a specified file in UCD format.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 103 of file ucd_io.C.

References write_implementation().

Referenced by libMesh::NameBasedIO::write().

104 {
105  if (file_name.rfind(".gz") < file_name.size())
106  {
107 #ifdef LIBMESH_HAVE_GZSTREAM
108  ogzstream out_stream (file_name.c_str());
109  this->write_implementation (out_stream);
110 #else
111  libmesh_error_msg("ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
112 #endif
113  }
114 
115  else
116  {
117  std::ofstream out_stream (file_name.c_str());
118  this->write_implementation (out_stream);
119  }
120 }
void write_implementation(std::ostream &out_stream)
The actual implementation of the write function.
Definition: ucd_io.C:249

◆ write_discontinuous_equation_systems()

void libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

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 89 of file mesh_output.C.

References libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), libMesh::libmesh_assert(), and libMesh::out.

Referenced by libMesh::ExodusII_IO::write_timestep_discontinuous().

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

◆ write_equation_systems()

void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

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

Reimplemented in libMesh::ExodusII_IO, and libMesh::NameBasedIO.

Definition at line 31 of file mesh_output.C.

References libMesh::EquationSystems::build_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), libMesh::libmesh_assert(), and libMesh::out.

Referenced by libMesh::Nemesis_IO::write_timestep().

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-parallel format, non-renumbered mesh may not have a contiguous
46  // numbering, and that needs to be fixed before we can build a solution vector.
47  if (!_is_parallel_format &&
48  (my_mesh.max_elem_id() != my_mesh.n_elem() ||
49  my_mesh.max_node_id() != my_mesh.n_nodes()))
50  {
51  // If we were allowed to renumber then we should have already
52  // been properly renumbered...
53  libmesh_assert(!my_mesh.allow_renumbering());
54 
55  libmesh_do_once(libMesh::out <<
56  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
57  << std::endl;);
58 
59  my_mesh.allow_renumbering(true);
60 
61  my_mesh.renumber_nodes_and_elements();
62 
63  // Not sure what good going back to false will do here, the
64  // renumbering horses have already left the barn...
65  my_mesh.allow_renumbering(false);
66  }
67 
69  {
70  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
71 
72  // Build the list of variable names that will be written.
73  std::vector<std::string> names;
74  es.build_variable_names (names, nullptr, system_names);
75 
76  // Build the nodal solution values & get the variable
77  // names from the EquationSystems object
78  std::vector<Number> soln;
79  es.build_solution_vector (soln, system_names,
80  this->get_add_sides());
81 
82  this->write_nodal_data (fname, soln, names);
83  }
84  else // _is_parallel_format
85  this->write_nodal_data (fname, es, system_names);
86 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: mesh_output.h:109
const MeshBase *const _obj
A pointer to a constant object.
Definition: mesh_output.h:202
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition: mesh_output.h:184
libmesh_assert(ctx)
OStreamProxy out
const bool _serial_only_needed_on_proc_0
Flag specifying whether this format can be written by only serializing the mesh to processor zero...
Definition: mesh_output.h:193

◆ write_header()

void libMesh::UCDIO::write_header ( std::ostream &  out,
const MeshBase mesh,
dof_id_type  n_elems,
unsigned int  n_vars 
)
private

Write UCD format header.

Definition at line 272 of file ucd_io.C.

References libMesh::libmesh_assert(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshBase::n_nodes(), and n_vars.

Referenced by write_implementation(), and write_nodal_data().

276 {
277  libmesh_assert (out_stream.good());
278  // TODO: We could print out the libmesh revision used to write this file here.
279  out_stream << "# For a description of the UCD format see the AVS Developer's guide.\n"
280  << "#\n";
281 
282  // Write the mesh info
283  out_stream << mesh.n_nodes() << " "
284  << n_elems << " "
285  << n_vars << " "
286  << " 0 0\n";
287 }
unsigned int n_vars
libmesh_assert(ctx)
virtual dof_id_type n_nodes() const =0

◆ write_implementation()

void libMesh::UCDIO::write_implementation ( std::ostream &  out_stream)
private

The actual implementation of the write function.

The public write interface simply decides which type of stream to pass the implementation.

Definition at line 249 of file ucd_io.C.

References libMesh::libmesh_assert(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::MeshBase::n_elem(), write_header(), write_interior_elems(), and write_nodes().

Referenced by write().

250 {
251  libmesh_assert (out_stream.good());
252 
253  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
254 
255  // UCD doesn't work any dimension except 3?
256  libmesh_error_msg_if(mesh.mesh_dimension() != 3,
257  "Error: Can't write boundary elements for meshes of dimension less than 3. "
258  "Mesh dimension = " << mesh.mesh_dimension());
259 
260  // Write header
261  this->write_header(out_stream, mesh, mesh.n_elem(), 0);
262 
263  // Write the node coordinates
264  this->write_nodes(out_stream, mesh);
265 
266  // Write the elements
267  this->write_interior_elems(out_stream, mesh);
268 }
const MT & mesh() const
Definition: mesh_output.h:259
libmesh_assert(ctx)
void write_nodes(std::ostream &out, const MeshBase &mesh)
Write node information.
Definition: ucd_io.C:291
unsigned int mesh_dimension() const
Definition: mesh_base.C:372
void write_interior_elems(std::ostream &out, const MeshBase &mesh)
Write element information.
Definition: ucd_io.C:309
virtual dof_id_type n_elem() const =0
void write_header(std::ostream &out, const MeshBase &mesh, dof_id_type n_elems, unsigned int n_vars)
Write UCD format header.
Definition: ucd_io.C:272

◆ write_interior_elems()

void libMesh::UCDIO::write_interior_elems ( std::ostream &  out,
const MeshBase mesh 
)
private

Write element information.

Definition at line 309 of file ucd_io.C.

References _writing_element_map, libMesh::libmesh_assert(), libMesh::MeshInput< MeshBase >::mesh(), and libMesh::UCD.

Referenced by write_implementation(), and write_nodal_data().

311 {
312  // 1-based element number for UCD
313  unsigned int e=1;
314 
315  // Write element information
316  for (const auto & elem : mesh.element_ptr_range())
317  {
318  libmesh_assert (out_stream.good());
319 
320  // Look up the corresponding UCD element type in the static map.
321  std::string elem_string = libmesh_map_find(_writing_element_map, elem->type());
322 
323  // Write the element's subdomain ID as the UCD "material_id".
324  out_stream << e++ << " " << elem->subdomain_id() << " " << elem_string << "\t";
325  elem->write_connectivity(out_stream, UCD);
326  }
327 }
static std::map< ElemType, std::string > _writing_element_map
Definition: ucd_io.h:141
libmesh_assert(ctx)

◆ write_nodal_data() [1/3]

void libMesh::UCDIO::write_nodal_data ( const std::string &  fname,
const std::vector< Number > &  soln,
const std::vector< std::string > &  names 
)
overridevirtual

This method implements writing a mesh and solution to a specified file in UCD format.

This is internally called by MeshOutput::write_equation_systems

Reimplemented from libMesh::MeshOutput< MeshBase >.

Definition at line 331 of file ucd_io.C.

References libMesh::libmesh_assert(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::MeshTools::n_elem(), libMesh::MeshBase::n_elem(), libMesh::ParallelObject::processor_id(), write_header(), write_interior_elems(), write_nodes(), and write_soln().

Referenced by libMesh::NameBasedIO::write_nodal_data().

334 {
335  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
336 
337  const dof_id_type n_elem = mesh.n_elem();
338 
339  // Only processor 0 does the writing
340  if (mesh.processor_id())
341  return;
342 
343  std::ofstream out_stream(fname.c_str());
344 
345  // UCD doesn't work in 1D
347 
348  // Write header
349  this->write_header(out_stream,mesh,n_elem,
350  cast_int<unsigned int>(names.size()));
351 
352  // Write the node coordinates
353  this->write_nodes(out_stream, mesh);
354 
355  // Write the elements
356  this->write_interior_elems(out_stream, mesh);
357 
358  // Write the solution
359  this->write_soln(out_stream, mesh, names, soln);
360 }
const MT & mesh() const
Definition: mesh_output.h:259
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Count up the number of elements of a specific type (as defined by an iterator range).
Definition: mesh_tools.C:969
void write_soln(std::ostream &out, const MeshBase &mesh, const std::vector< std::string > &names, const std::vector< Number > &soln)
Writes all nodal solution variables.
Definition: ucd_io.C:364
libmesh_assert(ctx)
void write_nodes(std::ostream &out, const MeshBase &mesh)
Write node information.
Definition: ucd_io.C:291
unsigned int mesh_dimension() const
Definition: mesh_base.C:372
void write_interior_elems(std::ostream &out, const MeshBase &mesh)
Write element information.
Definition: ucd_io.C:309
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const
uint8_t dof_id_type
Definition: id_types.h:67
void write_header(std::ostream &out, const MeshBase &mesh, dof_id_type n_elems, unsigned int n_vars)
Write UCD format header.
Definition: ucd_io.C:272

◆ write_nodal_data() [2/3]

void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  fname,
const NumericVector< Number > &  parallel_soln,
const std::vector< std::string > &  names 
)
virtualinherited

This method may 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 149 of file mesh_output.C.

References libMesh::NumericVector< T >::localize().

152 {
153  // This is the fallback implementation for parallel I/O formats that
154  // do not yet implement proper writing in parallel, and instead rely
155  // on the full solution vector being available on all processors.
156  std::vector<Number> soln;
157  parallel_soln.localize(soln);
158  this->write_nodal_data(fname, soln, names);
159 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: mesh_output.h:109
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.

◆ write_nodal_data() [3/3]

void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names 
)
virtualinherited

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 directly uses EquationSystems current_local_solution vectors to look up nodal values.

If not implemented, reorders the solutions into a nodal-only NumericVector and calls the above version of this function.

Reimplemented in libMesh::Nemesis_IO.

Definition at line 162 of file mesh_output.C.

References libMesh::EquationSystems::build_parallel_solution_vector(), and libMesh::EquationSystems::build_variable_names().

165 {
166  std::vector<std::string> names;
167  es.build_variable_names (names, nullptr, system_names);
168 
169  std::unique_ptr<NumericVector<Number>> parallel_soln =
170  es.build_parallel_solution_vector(system_names);
171 
172  this->write_nodal_data (fname, *parallel_soln, names);
173 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: mesh_output.h:109

◆ write_nodal_data_discontinuous()

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data_discontinuous ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtualinherited

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 118 of file mesh_output.h.

121  { libmesh_not_implemented(); }

◆ write_nodes()

void libMesh::UCDIO::write_nodes ( std::ostream &  out,
const MeshBase mesh 
)
private

Write node information.

Definition at line 291 of file ucd_io.C.

References libMesh::libmesh_assert(), and libMesh::MeshInput< MeshBase >::mesh().

Referenced by write_implementation(), and write_nodal_data().

293 {
294  // 1-based node number for UCD
295  unsigned int n=1;
296 
297  // Write the node coordinates
298  for (auto & node : mesh.node_ptr_range())
299  {
300  libmesh_assert (out_stream.good());
301 
302  out_stream << n++ << "\t";
303  node->write_unformatted(out_stream);
304  }
305 }
libmesh_assert(ctx)

◆ write_soln()

void libMesh::UCDIO::write_soln ( std::ostream &  out,
const MeshBase mesh,
const std::vector< std::string > &  names,
const std::vector< Number > &  soln 
)
private

Writes all nodal solution variables.

Definition at line 364 of file ucd_io.C.

References libMesh::MeshTools::Generation::Private::idx(), libMesh::libmesh_assert(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshBase::n_nodes(), and libMesh::Quality::name().

Referenced by write_nodal_data().

368 {
369  libmesh_assert (out_stream.good());
370 
371  // First write out how many variables and how many components per variable
372  out_stream << names.size();
373  for (std::size_t i = 0, ns = names.size(); i < ns; i++)
374  {
375  libmesh_assert (out_stream.good());
376  // Each named variable has only 1 component
377  out_stream << " 1";
378  }
379  out_stream << std::endl;
380 
381  // Now write out variable names and units. Since we don't store units
382  // We just write out dummy.
383  for (const auto & name : names)
384  {
385  libmesh_assert (out_stream.good());
386  out_stream << name << ", dummy" << std::endl;
387  }
388 
389  // Now, for each node, write out the solution variables.
390  // We use a 1-based node numbering for UCD.
391  std::size_t nv = names.size();
392  for (auto n : IntRange<std::size_t>(1, mesh.n_nodes()))
393  {
394  libmesh_assert (out_stream.good());
395  out_stream << n;
396 
397  for (std::size_t var = 0; var != nv; var++)
398  {
399  std::size_t idx = nv*(n-1) + var;
400 
401  out_stream << " " << soln[idx];
402  }
403  out_stream << std::endl;
404  }
405 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
libmesh_assert(ctx)
virtual dof_id_type n_nodes() const =0
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
A useful inline function which replaces the macros used previously.

Member Data Documentation

◆ _is_parallel_format

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format
protectedinherited

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 184 of file mesh_output.h.

Referenced by libMesh::FroIO::write(), libMesh::PostscriptIO::write(), and libMesh::EnsightIO::write().

◆ _reading_element_map

std::map< std::string, ElemType > libMesh::UCDIO::_reading_element_map = UCDIO::build_reading_element_map()
staticprivate

Definition at line 145 of file ucd_io.h.

Referenced by read_implementation().

◆ _serial_only_needed_on_proc_0

const bool libMesh::MeshOutput< MeshBase >::_serial_only_needed_on_proc_0
protectedinherited

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 193 of file mesh_output.h.

◆ _writing_element_map

std::map< ElemType, std::string > libMesh::UCDIO::_writing_element_map = UCDIO::build_writing_element_map()
staticprivate

Definition at line 141 of file ucd_io.h.

Referenced by write_interior_elems().

◆ elems_of_dimension

std::vector<bool> libMesh::MeshInput< MeshBase >::elems_of_dimension
protectedinherited

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