libMesh::TetGenIO Class Reference

#include <tetgen_io.h>

Inheritance diagram for libMesh::TetGenIO:

Public Member Functions

 TetGenIO (MeshBase &mesh)
 
 TetGenIO (const MeshBase &mesh)
 
virtual void read (const std::string &) override
 
virtual void write (const std::string &) 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 std::vector< Number > &, const std::vector< std::string > &)
 
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 ()
 

Public Attributes

std::vector< std::vector< Real > > node_attributes
 
std::vector< std::vector< Real > > element_attributes
 

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_nodes_and_elem (std::istream &node_stream, std::istream &ele_stream)
 
void node_in (std::istream &node_stream)
 
void element_in (std::istream &ele_stream)
 

Private Attributes

std::map< dof_id_type, dof_id_type_assign_nodes
 
dof_id_type _num_nodes
 
dof_id_type _num_elements
 

Detailed Description

This class implements reading and writing meshes in the TetGen format. Format description: cf. TetGen home page.

Author
Benjamin S. Kirk
Date
2004

Definition at line 47 of file tetgen_io.h.

Constructor & Destructor Documentation

◆ TetGenIO() [1/2]

libMesh::TetGenIO::TetGenIO ( MeshBase mesh)
inlineexplicit

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

Definition at line 151 of file tetgen_io.h.

151  :
152  MeshInput<MeshBase> (mesh),
153  MeshOutput<MeshBase>(mesh)
154 {
155 }

◆ TetGenIO() [2/2]

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

Constructor. Takes a read-only reference to a mesh object. This is the constructor required to write a mesh.

Definition at line 160 of file tetgen_io.h.

160  :
161  MeshOutput<MeshBase>(mesh)
162 {
163 }

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 }

◆ element_in()

void libMesh::TetGenIO::element_in ( std::istream &  ele_stream)
private

Method reads elements and stores them in vector<Elem *> elements in the same order as they come in. Within TetGenMeshInterface, element labels are ignored.

Definition at line 170 of file tetgen_io.C.

References _assign_nodes, _num_elements, libMesh::MeshBase::add_elem(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshInput< MT >::mesh(), n_nodes, and libMesh::MeshBase::node_ptr().

Referenced by read_nodes_and_elem().

171 {
172  // Check input buffer
173  libmesh_assert (ele_stream.good());
174 
175  // Get a reference to the mesh
176  MeshBase & mesh = MeshInput<MeshBase>::mesh();
177 
178  // Read the elements from the ele_stream (*.ele file).
179  unsigned int element_lab=0, n_nodes=0, region_attribute=0;
180 
181  ele_stream >> _num_elements // Read the number of tetrahedrons from the stream.
182  >> n_nodes // Read the number of nodes per tetrahedron from the stream (defaults to 4).
183  >> region_attribute; // Read the number of attributes from stream.
184 
185  // According to the Tetgen docs for .ele files:
186  // http://wias-berlin.de/software/tetgen/1.5/doc/manual/manual006.html#ff_ele
187  // region_attribute can either 0 or 1, and specifies whether, for
188  // each tetrahedron, there is an extra integer specifying which
189  // region it belongs to. Normally, this id matches a value in a
190  // corresponding .poly or .smesh file, but here we simply use it to
191  // set the subdomain_id of the element in question.
192  if (region_attribute > 1)
193  libmesh_error_msg("Invalid region_attribute " << region_attribute << " specified in .ele file.");
194 
195  // Vector that assigns element nodes to their correct position.
196  // TetGen is normally 0-based
197  // (right now this is strictly not necessary since it is the identity map,
198  // but in the future TetGen could change their numbering scheme.)
199  static const unsigned int assign_elm_nodes[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
200 
201  for (dof_id_type i=0; i<_num_elements; i++)
202  {
203  libmesh_assert (ele_stream.good());
204 
205  // TetGen only supports Tet4 and Tet10 elements.
206  Elem * elem;
207 
208  if (n_nodes==4)
209  elem = new Tet4;
210 
211  else if (n_nodes==10)
212  elem = new Tet10;
213 
214  else
215  libmesh_error_msg("Elements with " << n_nodes << " nodes are not supported in the LibMesh tetgen module.");
216 
217  elem->set_id(i);
218 
219  mesh.add_elem (elem);
220 
221  libmesh_assert(elem);
222  libmesh_assert_equal_to (elem->n_nodes(), n_nodes);
223 
224  // The first number on the line is the tetrahedron number. We
225  // have previously ignored this, preferring to set our own ids,
226  // but this could be changed to respect the Tetgen numbering if
227  // desired.
228  ele_stream >> element_lab;
229 
230  // Read node labels
231  for (dof_id_type j=0; j<n_nodes; j++)
232  {
233  dof_id_type node_label;
234  ele_stream >> node_label;
235 
236  // Assign node to element
237  elem->set_node(assign_elm_nodes[j]) =
238  mesh.node_ptr(_assign_nodes[node_label]);
239  }
240 
241  // Read the region attribute (if present) and use it to set the subdomain id.
242  if (region_attribute)
243  {
244  unsigned int region;
245  ele_stream >> region;
246 
247  // Make sure that the id we read can be successfully cast to
248  // an integral value of type subdomain_id_type.
249  elem->subdomain_id() = cast_int<subdomain_id_type>(region);
250  }
251  }
252 }
dof_id_type _num_elements
Definition: tetgen_io.h:143
std::map< dof_id_type, dof_id_type > _assign_nodes
Definition: tetgen_io.h:133
const dof_id_type n_nodes
Definition: tecplot_io.C:68
virtual Elem * add_elem(Elem *e)=0
virtual const Node * node_ptr(const dof_id_type i) const =0
uint8_t dof_id_type
Definition: id_types.h:64

◆ 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(), element_in(), libMesh::UNVIO::elements_in(), libMesh::UNVIO::elements_out(), libMesh::UNVIO::groups_in(), 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(), libMesh::UCDIO::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(), 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(), libMesh::UCDIO::write_header(), libMesh::UCDIO::write_implementation(), libMesh::UCDIO::write_interior_elems(), 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::UCDIO::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::UCDIO::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]

◆ node_in()

void libMesh::TetGenIO::node_in ( std::istream &  node_stream)
private

Method reads nodes from node_stream and stores them in vector<Node *> nodes in the order they come in. The original node labels are being stored in the map _assign_nodes in order to assign the elements to the right nodes later.

Definition at line 112 of file tetgen_io.C.

References _assign_nodes, _num_nodes, libMesh::MeshBase::add_point(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), node_attributes, and libMesh::Real.

Referenced by read_nodes_and_elem().

113 {
114  // Check input buffer
115  libmesh_assert (node_stream.good());
116 
117  // Get a reference to the mesh
118  MeshBase & mesh = MeshInput<MeshBase>::mesh();
119 
120  unsigned int dimension=0, nAttributes=0, BoundaryMarkers=0;
121 
122  node_stream >> _num_nodes // Read the number of nodes from the stream
123  >> dimension // Read the dimension from the stream
124  >> nAttributes // Read the number of attributes from stream
125  >> BoundaryMarkers; // Read if or not boundary markers are included in *.node (0 or 1)
126 
127  // Read the nodal coordinates from the node_stream (*.node file).
128  unsigned int node_lab=0;
129  Point xyz;
130  Real dummy;
131 
132  // If present, make room for node attributes to be stored.
133  this->node_attributes.resize(nAttributes);
134  for (unsigned i=0; i<nAttributes; ++i)
135  this->node_attributes[i].resize(_num_nodes);
136 
137 
138  for (unsigned int i=0; i<_num_nodes; i++)
139  {
140  // Check input buffer
141  libmesh_assert (node_stream.good());
142 
143  node_stream >> node_lab // node number
144  >> xyz(0) // x-coordinate value
145  >> xyz(1) // y-coordinate value
146  >> xyz(2); // z-coordinate value
147 
148  // Read and store attributes from the stream.
149  for (unsigned int j=0; j<nAttributes; j++)
150  node_stream >> node_attributes[j][i];
151 
152  // Read (and discard) boundary marker if BoundaryMarker=1.
153  // TODO: should we store this somehow?
154  if (BoundaryMarkers == 1)
155  node_stream >> dummy;
156 
157  // Store the new position of the node under its label.
158  //_assign_nodes.insert (std::make_pair(node_lab,i));
159  _assign_nodes[node_lab] = i;
160 
161  // Add this point to the Mesh.
162  mesh.add_point(xyz, i);
163  }
164 }
std::map< dof_id_type, dof_id_type > _assign_nodes
Definition: tetgen_io.h:133
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
dof_id_type _num_nodes
Definition: tetgen_io.h:138
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
std::vector< std::vector< Real > > node_attributes
Definition: tetgen_io.h:82

◆ read()

void libMesh::TetGenIO::read ( const std::string &  name)
overridevirtual

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

Implements libMesh::MeshInput< MeshBase >.

Definition at line 33 of file tetgen_io.C.

References libMesh::MeshInput< MT >::mesh(), libMesh::Quality::name(), libMesh::out, read_nodes_and_elem(), and libMesh::MeshInput< MeshBase >::skip_comment_lines().

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

34 {
35  // This is a serial-only process for now;
36  // the Mesh should be read on processor 0 and
37  // broadcast later
38  libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().processor_id(), 0);
39 
40  std::string name_node, name_ele, dummy;
41 
42  // tetgen only works in 3D
43  MeshInput<MeshBase>::mesh().set_mesh_dimension(3);
44 
45 #if LIBMESH_DIM < 3
46  libmesh_error_msg("Cannot open dimension 3 mesh file when configured without 3D support.");
47 #endif
48 
49  // Check name for *.node or *.ele extension.
50  // Set std::istream for node_stream and ele_stream.
51  //
52  if (name.rfind(".node") < name.size())
53  {
54  name_node = name;
55  dummy = name;
56  std::size_t position = dummy.rfind(".node");
57  name_ele = dummy.replace(position, 5, ".ele");
58  }
59  else if (name.rfind(".ele") < name.size())
60  {
61  name_ele = name;
62  dummy = name;
63  std::size_t position = dummy.rfind(".ele");
64  name_node = dummy.replace(position, 4, ".node");
65  }
66  else
67  libmesh_error_msg("ERROR: Unrecognized file name: " << name);
68 
69 
70 
71  // Set the streams from which to read in
72  std::ifstream node_stream (name_node.c_str());
73  std::ifstream ele_stream (name_ele.c_str());
74 
75  if (!node_stream.good() || !ele_stream.good())
76  libmesh_error_msg("Error while opening either " \
77  << name_node \
78  << " or " \
79  << name_ele);
80 
81  libMesh::out<< "TetGenIO found the tetgen files to read " <<std::endl;
82 
83  // Skip the comment lines at the beginning
84  this->skip_comment_lines (node_stream, '#');
85  this->skip_comment_lines (ele_stream, '#');
86 
87  // Read the nodes and elements from the streams
88  this->read_nodes_and_elem (node_stream, ele_stream);
89  libMesh::out<< "TetGenIO read in nodes and elements " <<std::endl;
90 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
const MeshBase & mesh() const
Definition: mesh_output.h:234
void skip_comment_lines(std::istream &in, const char comment_start)
Definition: mesh_input.h:179
void read_nodes_and_elem(std::istream &node_stream, std::istream &ele_stream)
Definition: tetgen_io.C:94
OStreamProxy out(std::cout)

◆ read_nodes_and_elem()

void libMesh::TetGenIO::read_nodes_and_elem ( std::istream &  node_stream,
std::istream &  ele_stream 
)
private

Reads a mesh (nodes & elements) from the file provided through node_stream and ele_stream.

Definition at line 94 of file tetgen_io.C.

References _assign_nodes, _num_elements, _num_nodes, element_in(), and node_in().

Referenced by read().

96 {
97  _num_nodes = 0;
98  _num_elements = 0;
99 
100  // Read all the datasets.
101  this->node_in (node_stream);
102  this->element_in (ele_stream);
103 
104  // some more clean-up
105  _assign_nodes.clear();
106 }
dof_id_type _num_elements
Definition: tetgen_io.h:143
std::map< dof_id_type, dof_id_type > _assign_nodes
Definition: tetgen_io.h:133
dof_id_type _num_nodes
Definition: tetgen_io.h:138
void node_in(std::istream &node_stream)
Definition: tetgen_io.C:112
void element_in(std::istream &ele_stream)
Definition: tetgen_io.C:170

◆ 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 read(), and libMesh::UCDIO::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::TetGenIO::write ( const std::string &  fname)
overridevirtual

This method implements writing a mesh to a specified ".poly" file. ".poly" files defines so called Piecewise Linear Complex (PLC).

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 259 of file tetgen_io.C.

References libMesh::MeshBase::active_element_ptr_range(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::n_elem(), libMesh::MeshBase::n_nodes(), and libMesh::MeshBase::point().

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

260 {
261  // libmesh_assert three dimensions (should be extended later)
262  libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().mesh_dimension(), 3);
263 
264  if (!(fname.rfind(".poly") < fname.size()))
265  libmesh_error_msg("ERROR: Unrecognized file name: " << fname);
266 
267  // Open the output file stream
268  std::ofstream out_stream (fname.c_str());
269 
270  // Make sure it opened correctly
271  if (!out_stream.good())
272  libmesh_file_error(fname.c_str());
273 
274  // Get a reference to the mesh
275  const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
276 
277  // Begin interfacing with the .poly file
278  {
279  // header:
280  out_stream << "# poly file output generated by libmesh\n"
281  << mesh.n_nodes() << " 3 0 0\n";
282 
283  // write the nodes:
284  for (dof_id_type v=0; v<mesh.n_nodes(); v++)
285  out_stream << v << " "
286  << mesh.point(v)(0) << " "
287  << mesh.point(v)(1) << " "
288  << mesh.point(v)(2) << "\n";
289  }
290 
291  {
292  // write the connectivity:
293  out_stream << "# Facets:\n"
294  << mesh.n_elem() << " 0\n";
295 
296  for (const auto & elem : mesh.active_element_ptr_range())
297  out_stream << "1\n3 " // no. of facet polygons
298  // << elem->n_nodes() << " "
299  << elem->node_id(0) << " "
300  << elem->node_id(1) << " "
301  << elem->node_id(2) << "\n";
302  }
303 
304  // end of the file
305  out_stream << "0\n"; // no holes output!
306  out_stream << "\n\n# end of file\n";
307 }
const MeshBase & mesh() const
Definition: mesh_output.h:234
virtual SimpleRange< element_iterator > active_element_ptr_range()=0
virtual const Point & point(const dof_id_type i) const =0
virtual dof_id_type n_elem() const =0
virtual dof_id_type n_nodes() const =0
uint8_t dof_id_type
Definition: id_types.h:64

◆ 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_nodal_data() [1/2]

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

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]

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

Member Data Documentation

◆ _assign_nodes

std::map<dof_id_type,dof_id_type> libMesh::TetGenIO::_assign_nodes
private

stores new positions of nodes. Used when reading.

Definition at line 133 of file tetgen_io.h.

Referenced by element_in(), node_in(), and read_nodes_and_elem().

◆ _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().

◆ _num_elements

dof_id_type libMesh::TetGenIO::_num_elements
private

total number of elements. Primarily used when reading.

Definition at line 143 of file tetgen_io.h.

Referenced by element_in(), and read_nodes_and_elem().

◆ _num_nodes

dof_id_type libMesh::TetGenIO::_num_nodes
private

total number of nodes. Primarily used when reading.

Definition at line 138 of file tetgen_io.h.

Referenced by node_in(), and read_nodes_and_elem().

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

◆ element_attributes

std::vector<std::vector<Real> > libMesh::TetGenIO::element_attributes

Data structure to hold element attributes read in from file.

Note
This vector is no longer filled or used for anything. If region attributes are present in the .ele file, they are used to set the subdomain ids of the elements as they are created.
Deprecated:
This member, since it was originally a part of the public interface, remains for now, but will be removed some time in the near future.

Definition at line 95 of file tetgen_io.h.

◆ elems_of_dimension

◆ node_attributes

std::vector<std::vector<Real> > libMesh::TetGenIO::node_attributes

Data structure to hold node attributes read in from file. What you do with these is up to you!

Definition at line 82 of file tetgen_io.h.

Referenced by node_in().


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