libMesh::UCDIO Class Reference

#include <ucd_io.h>

Inheritance diagram for libMesh::UCDIO:

Public Member Functions

 UCDIO (MeshBase &mesh)
 
 UCDIO (const MeshBase &mesh)
 
virtual void read (const std::string &) override
 
virtual void write (const std::string &) override
 
virtual void write_nodal_data (const std::string &fname, const std::vector< Number > &soln, const std::vector< std::string > &names) override
 
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 NumericVector< Number > &, const std::vector< std::string > &)
 
virtual void write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 
unsigned int & ascii_precision ()
 

Protected Member Functions

MeshBasemesh ()
 
void set_n_partitions (unsigned int n_parts)
 
void skip_comment_lines (std::istream &in, const char comment_start)
 
const MeshBasemesh () const
 

Protected Attributes

std::vector< bool > elems_of_dimension
 
const bool _is_parallel_format
 
const bool _serial_only_needed_on_proc_0
 

Private Member Functions

void read_implementation (std::istream &in_stream)
 
void write_implementation (std::ostream &out_stream)
 
void write_header (std::ostream &out, const MeshBase &mesh, dof_id_type n_elems, unsigned int n_vars)
 
void write_nodes (std::ostream &out, const MeshBase &mesh)
 
void write_interior_elems (std::ostream &out, const MeshBase &mesh)
 
void write_soln (std::ostream &out, const MeshBase &mesh, const std::vector< std::string > &names, const std::vector< Number > &soln)
 

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 52 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 62 of file ucd_io.h.

62  :
63  MeshInput<MeshBase> (mesh),
64  MeshOutput<MeshBase>(mesh)
65  {}

◆ 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 72 of file ucd_io.h.

72  :
73  MeshOutput<MeshBase> (mesh)
74  {}

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>::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.

Referenced by libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().

245 {
246  return _ascii_precision;
247 }

◆ 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 }

◆ mesh() [1/2]

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

Definition at line 169 of file mesh_input.h.

Referenced by libMesh::GMVIO::_read_one_cell(), libMesh::VTKIO::cells_to_vtk(), libMesh::TetGenIO::element_in(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::elements_out(), 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::Nemesis_IO::read(), libMesh::ExodusII_IO::read(), libMesh::GMVIO::read(), libMesh::XdrIO::read(), libMesh::CheckpointIO::read(), libMesh::VTKIO::read(), libMesh::CheckpointIO::read_bcs(), libMesh::CheckpointIO::read_connectivity(), libMesh::CheckpointIO::read_header(), libMesh::XdrIO::read_header(), read_implementation(), libMesh::UNVIO::read_implementation(), libMesh::GmshIO::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::OFFIO::read_stream(), libMesh::MatlabIO::read_stream(), libMesh::CheckpointIO::read_subdomain_names(), libMesh::TetGenIO::write(), libMesh::Nemesis_IO::write(), libMesh::ExodusII_IO::write(), libMesh::XdrIO::write(), libMesh::CheckpointIO::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(), write_header(), write_implementation(), write_interior_elems(), libMesh::GmshIO::write_mesh(), libMesh::VTKIO::write_nodal_data(), 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(), write_soln(), and libMesh::CheckpointIO::write_subdomain_names().

170 {
171  if (_obj == nullptr)
172  libmesh_error_msg("ERROR: _obj should not be nullptr!");
173  return *_obj;
174 }

◆ mesh() [2/2]

◆ 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)
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::Elem::dim(), libMesh::MeshInput< MeshBase >::elems_of_dimension, libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::MeshBase::n_nodes(), libMesh::Elem::n_nodes(), libMesh::MeshBase::node_ptr(), libMesh::DofObject::set_id(), libMesh::MeshBase::set_mesh_dimension(), libMesh::Elem::set_node(), libMesh::MeshInput< MeshBase >::skip_comment_lines(), and libMesh::Elem::subdomain_id().

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  Point xyz;
157 
158  for (unsigned int i=0; i<nNodes; i++)
159  {
160  libmesh_assert (in.good());
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  // Build the node
168  mesh.add_point (xyz, i);
169  }
170  }
171 
172  // Read the elements from the stream. Notice that the UCD node-numbering
173  // scheme is 1-based, and we just created a 0-based scheme above
174  // (which is of course what we want). So, when we read in the nodal
175  // connectivity for each element we need to take 1 off the value of
176  // each node so that we get the right thing.
177  {
178  unsigned int material_id=0, node=0;
179  std::string type;
180 
181  for (unsigned int i=0; i<nElem; i++)
182  {
183  libmesh_assert (in.good());
184 
185  // The cell type can be either tri, quad, tet, hex, or prism.
186  in >> dummy // Cell number, means nothing to us
187  >> material_id // We'll use this for the element subdomain id.
188  >> type; // string describing cell type
189 
190  // Convert the UCD type string to a libmesh ElementType
191  auto it = _reading_element_map.find(type);
192  if (it == _reading_element_map.end())
193  libmesh_error_msg("Unsupported element type = " << type);
194 
195  // Build the required type and release it into our custody.
196  Elem * elem = Elem::build(it->second).release();
197 
198  for (unsigned int n=0; n<elem->n_nodes(); n++)
199  {
200  libmesh_assert (in.good());
201 
202  in >> node; // read the current node
203  node -= 1; // UCD is 1-based, so subtract
204 
205  libmesh_assert_less (node, mesh.n_nodes());
206 
207  // assign the node
208  elem->set_node(n) = mesh.node_ptr(node);
209  }
210 
211  elems_of_dimension[elem->dim()] = true;
212 
213  // Set the element's subdomain ID based on the material_id.
214  elem->subdomain_id() = cast_int<subdomain_id_type>(material_id);
215 
216  // Add the element to the mesh
217  elem->set_id(i);
218  mesh.add_elem (elem);
219  }
220 
221  // Set the mesh dimension to the largest encountered for an element
222  for (unsigned char i=0; i!=4; ++i)
223  if (elems_of_dimension[i])
225 
226 #if LIBMESH_DIM < 3
227  if (mesh.mesh_dimension() > LIBMESH_DIM)
228  libmesh_error_msg("Cannot open dimension " \
229  << mesh.mesh_dimension() \
230  << " mesh file when configured without " \
231  << mesh.mesh_dimension() \
232  << "D support.");
233 #endif
234  }
235 }
const MeshBase & mesh() const
Definition: mesh_output.h:234
std::vector< bool > elems_of_dimension
Definition: mesh_input.h:97
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
void skip_comment_lines(std::istream &in, const char comment_start)
Definition: mesh_input.h:179
virtual Elem * add_elem(Elem *e)=0
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
Definition: elem.C:245
void set_mesh_dimension(unsigned char d)
Definition: mesh_base.h:213
unsigned int mesh_dimension() const
Definition: mesh_base.C:126
static std::map< std::string, ElemType > _reading_element_map
Definition: ucd_io.h:153
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 91 of file mesh_input.h.

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

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

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

◆ 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 179 of file mesh_input.h.

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

181 {
182  char c, line[256];
183 
184  while (in.get(c), c==comment_start)
185  in.getline (line, 255);
186 
187  // put back first character of
188  // first non-comment line
189  in.putback (c);
190 }

◆ 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)
Definition: ucd_io.C:239

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

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

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

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 MeshBase *const _obj
Definition: mesh_output.h:177
OStreamProxy out(std::cout)

◆ 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::NameBasedIO.

Definition at line 31 of file mesh_output.C.

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

Referenced by libMesh::Nemesis_IO::write_timestep(), and libMesh::ExodusII_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-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 MeshBase *const _obj
Definition: mesh_output.h:177
OStreamProxy out(std::cout)

◆ 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 262 of file ucd_io.C.

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

Referenced by write_implementation(), and write_nodal_data().

266 {
267  libmesh_assert (out_stream.good());
268  // TODO: We could print out the libmesh revision used to write this file here.
269  out_stream << "# For a description of the UCD format see the AVS Developer's guide.\n"
270  << "#\n";
271 
272  // Write the mesh info
273  out_stream << mesh.n_nodes() << " "
274  << n_elems << " "
275  << n_vars << " "
276  << " 0 0\n";
277 }
const unsigned int n_vars
Definition: tecplot_io.C:69
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 239 of file ucd_io.C.

References 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().

240 {
241  libmesh_assert (out_stream.good());
242 
243  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
244 
245  // UCD doesn't work any dimension except 3?
246  if (mesh.mesh_dimension() != 3)
247  libmesh_error_msg("Error: Can't write boundary elements for meshes of dimension less than 3. " \
248  << "Mesh dimension = " << mesh.mesh_dimension());
249 
250  // Write header
251  this->write_header(out_stream, mesh, mesh.n_elem(), 0);
252 
253  // Write the node coordinates
254  this->write_nodes(out_stream, mesh);
255 
256  // Write the elements
257  this->write_interior_elems(out_stream, mesh);
258 }
const MT & mesh() const
Definition: mesh_output.h:234
void write_nodes(std::ostream &out, const MeshBase &mesh)
Definition: ucd_io.C:281
unsigned int mesh_dimension() const
Definition: mesh_base.C:126
void write_interior_elems(std::ostream &out, const MeshBase &mesh)
Definition: ucd_io.C:299
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)
Definition: ucd_io.C:262

◆ write_interior_elems()

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

Write element information

Definition at line 299 of file ucd_io.C.

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

Referenced by write_implementation(), and write_nodal_data().

301 {
302  // 1-based element number for UCD
303  unsigned int e=1;
304 
305  // Write element information
306  for (const auto & elem : mesh.element_ptr_range())
307  {
308  libmesh_assert (out_stream.good());
309 
310  // Look up the corresponding UCD element type in the static map.
311  const ElemType etype = elem->type();
312  auto it = _writing_element_map.find(etype);
313  if (it == _writing_element_map.end())
314  libmesh_error_msg("Error: Unsupported ElemType " << etype << " for UCDIO.");
315 
316  // Write the element's subdomain ID as the UCD "material_id".
317  out_stream << e++ << " " << elem->subdomain_id() << " " << it->second << "\t";
318  elem->write_connectivity(out_stream, UCD);
319  }
320 }
static std::map< ElemType, std::string > _writing_element_map
Definition: ucd_io.h:149
virtual SimpleRange< element_iterator > element_ptr_range()=0

◆ write_nodal_data() [1/2]

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 324 of file ucd_io.C.

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

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

327 {
328  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
329 
330  const dof_id_type n_elem = mesh.n_elem();
331 
332  // Only processor 0 does the writing
333  if (mesh.processor_id())
334  return;
335 
336  std::ofstream out_stream(fname.c_str());
337 
338  // UCD doesn't work in 1D
339  libmesh_assert (mesh.mesh_dimension() != 1);
340 
341  // Write header
342  this->write_header(out_stream,mesh,n_elem,
343  cast_int<unsigned int>(names.size()));
344 
345  // Write the node coordinates
346  this->write_nodes(out_stream, mesh);
347 
348  // Write the elements
349  this->write_interior_elems(out_stream, mesh);
350 
351  // Write the solution
352  this->write_soln(out_stream, mesh, names, soln);
353 }
const MT & mesh() const
Definition: mesh_output.h:234
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
Definition: mesh_tools.C:702
void write_soln(std::ostream &out, const MeshBase &mesh, const std::vector< std::string > &names, const std::vector< Number > &soln)
Definition: ucd_io.C:357
void write_nodes(std::ostream &out, const MeshBase &mesh)
Definition: ucd_io.C:281
unsigned int mesh_dimension() const
Definition: mesh_base.C:126
void write_interior_elems(std::ostream &out, const MeshBase &mesh)
Definition: ucd_io.C:299
virtual dof_id_type n_elem() const =0
processor_id_type processor_id() const
uint8_t dof_id_type
Definition: id_types.h:64
void write_header(std::ostream &out, const MeshBase &mesh, dof_id_type n_elems, unsigned int n_vars)
Definition: ucd_io.C:262

◆ write_nodal_data() [2/2]

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 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.

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

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()

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

117  { libmesh_not_implemented(); }

◆ write_nodes()

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

Write node information

Definition at line 281 of file ucd_io.C.

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

Referenced by write_implementation(), and write_nodal_data().

283 {
284  // 1-based node number for UCD
285  unsigned int n=1;
286 
287  // Write the node coordinates
288  for (auto & node : mesh.node_ptr_range())
289  {
290  libmesh_assert (out_stream.good());
291 
292  out_stream << n++ << "\t";
293  node->write_unformatted(out_stream);
294  }
295 }
virtual SimpleRange< node_iterator > node_ptr_range()=0

◆ 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 357 of file ucd_io.C.

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

Referenced by write_nodal_data().

361 {
362  libmesh_assert (out_stream.good());
363 
364  // First write out how many variables and how many components per variable
365  out_stream << names.size();
366  for (std::size_t i = 0; i < names.size(); i++)
367  {
368  libmesh_assert (out_stream.good());
369  // Each named variable has only 1 component
370  out_stream << " 1";
371  }
372  out_stream << std::endl;
373 
374  // Now write out variable names and units. Since we don't store units
375  // We just write out dummy.
376  for (const auto & name : names)
377  {
378  libmesh_assert (out_stream.good());
379  out_stream << name << ", dummy" << std::endl;
380  }
381 
382  // Now, for each node, write out the solution variables.
383  // We use a 1-based node numbering for UCD.
384  std::size_t nv = names.size();
385  for (std::size_t n = 1; n <= mesh.n_nodes(); n++)
386  {
387  libmesh_assert (out_stream.good());
388  out_stream << n;
389 
390  for (std::size_t var = 0; var != nv; var++)
391  {
392  std::size_t idx = nv*(n-1) + var;
393 
394  out_stream << " " << soln[idx];
395  }
396  out_stream << std::endl;
397  }
398 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
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)

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 159 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 153 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 168 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 149 of file ucd_io.h.

Referenced by write_interior_elems().

◆ elems_of_dimension


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