libMesh
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
libMesh::TetGenIO Class Reference

This class implements reading and writing meshes in the TetGen format. More...

#include <tetgen_io.h>

Inheritance diagram for libMesh::TetGenIO:
[legend]

Public Member Functions

 TetGenIO (MeshBase &mesh)
 Constructor.
 
 TetGenIO (const MeshBase &mesh)
 Constructor.
 
virtual void read (const std::string &) override
 This method implements reading a mesh from a specified file in TetGen format.
 
virtual void write (const std::string &) override
 This method implements writing a mesh to a specified ".poly" file.
 
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.
 
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.
 
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.
 
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 variable names are provided.
 
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.
 
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.
 
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.
 
unsigned intascii_precision ()
 Return/set the precision to use when writing ASCII files.
 

Public Attributes

std::vector< std::vector< Real > > node_attributes
 Data structure to hold node attributes read in from file.
 

Protected Member Functions

MeshBasemesh ()
 
void set_n_partitions (unsigned int n_parts)
 Sets the number of partitions in the mesh.
 
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.
 
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.
 
const bool _is_parallel_format
 Flag specifying whether this format is parallel-capable.
 
const bool _serial_only_needed_on_proc_0
 Flag specifying whether this format can be written by only serializing the mesh to processor zero.
 

Private Member Functions

void read_nodes_and_elem (std::istream &node_stream, std::istream &ele_stream)
 Reads a mesh (nodes & elements) from the file provided through node_stream and ele_stream.
 
void node_in (std::istream &node_stream)
 Method reads nodes from node_stream and stores them in vector<Node *> nodes in the order they come in.
 
void element_in (std::istream &ele_stream)
 Method reads elements and stores them in vector<Elem *> elements in the same order as they come in.
 

Private Attributes

std::map< dof_id_type, dof_id_type_assign_nodes
 stores new positions of nodes.
 
dof_id_type _num_nodes
 total number of nodes.
 
dof_id_type _num_elements
 total number of elements.
 
MeshBase_obj
 A pointer to a non-const object object.
 
const bool _is_parallel_format
 Flag specifying whether this format is parallel-capable.
 
unsigned int _ascii_precision
 Precision to use when writing ASCII files.
 

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 138 of file tetgen_io.h.

138 :
139 MeshInput<MeshBase> (mesh),
141{
142}
template class LIBMESH_EXPORT MeshOutput< MeshBase >

◆ 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 147 of file tetgen_io.h.

147 :
149{
150}

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

270{
271 return _ascii_precision;
272}
unsigned int _ascii_precision
Precision to use when writing ASCII files.

◆ 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 186 of file tetgen_io.C.

187{
188 // Check input buffer
189 libmesh_assert (ele_stream.good());
190
191 // Get a reference to the mesh
192 MeshBase & mesh = MeshInput<MeshBase>::mesh();
193
194 // Read the elements from the ele_stream (*.ele file).
195 unsigned int element_lab=0, n_nodes=0, region_attribute=0;
196
197 ele_stream >> _num_elements // Read the number of tetrahedrons from the stream.
198 >> n_nodes // Read the number of nodes per tetrahedron from the stream (defaults to 4).
199 >> region_attribute; // Read the number of attributes from stream.
200
201 // According to the Tetgen docs for .ele files:
202 // http://wias-berlin.de/software/tetgen/1.5/doc/manual/manual006.html#ff_ele
203 // region_attribute can either 0 or 1, and specifies whether, for
204 // each tetrahedron, there is an extra integer specifying which
205 // region it belongs to. Normally, this id matches a value in a
206 // corresponding .poly or .smesh file, but here we simply use it to
207 // set the subdomain_id of the element in question.
208 libmesh_error_msg_if(region_attribute > 1,
209 "Invalid region_attribute " << region_attribute << " specified in .ele file.");
210
211 // Vector that maps Tetgen node numbering to libMesh node numbering. Tet4s are
212 // numbered identically, but Tet10s are not.
213 static const unsigned int assign_elm_nodes[] = {0, 1, 2, 3, 9, 7, 4, 5, 8, 6};
214
215 for (dof_id_type i=0; i<_num_elements; i++)
216 {
217 libmesh_assert (ele_stream.good());
218
219 // TetGen only supports Tet4 and Tet10 elements.
220 Elem * elem = nullptr;
221
222 if (n_nodes==4)
224
225 else if (n_nodes==10)
227
228 else
229 libmesh_error_msg("Elements with " << n_nodes <<
230 " nodes are not supported in the LibMesh tetgen module.");
231
232 libmesh_assert(elem);
233 libmesh_assert_equal_to (elem->n_nodes(), n_nodes);
234
235 // The first number on the line is the tetrahedron number. We
236 // have previously ignored this, preferring to set our own ids,
237 // but this could be changed to respect the Tetgen numbering if
238 // desired.
239 ele_stream >> element_lab;
240
241 // Read node labels
242 for (dof_id_type j=0; j<n_nodes; j++)
243 {
244 dof_id_type node_label;
245 ele_stream >> node_label;
246
247 // Assign node to element
248 elem->set_node(assign_elm_nodes[j],
249 mesh.node_ptr(_assign_nodes[node_label]));
250 }
251
252 // Read the region attribute (if present) and use it to set the subdomain id.
253 if (region_attribute)
254 {
255 unsigned int region;
256 ele_stream >> region;
257
258 // Make sure that the id we read can be successfully cast to
259 // an integral value of type subdomain_id_type.
260 elem->subdomain_id() = restrict_int<subdomain_id_type>(region);
261 }
262 }
263}
static std::unique_ptr< Elem > build_with_id(const ElemType type, dof_id_type id)
Calls the build() method above with a nullptr parent, and additionally sets the newly-created Elem's ...
Definition elem.C:556
virtual const Node * node_ptr(const dof_id_type i) const =0
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
dof_id_type _num_elements
total number of elements.
Definition tetgen_io.h:130
std::map< dof_id_type, dof_id_type > _assign_nodes
stores new positions of nodes.
Definition tetgen_io.h:120
libmesh_assert(ctx)
uint8_t dof_id_type
Definition id_types.h:67
const dof_id_type n_nodes
Definition tecplot_io.C:67

References _assign_nodes, _num_elements, libMesh::MeshBase::add_elem(), libMesh::Elem::build_with_id(), libMesh::libmesh_assert(), libMesh::MeshInput< MT >::mesh(), libMesh::MeshInput< MeshBase >::mesh(), libMesh::Elem::n_nodes(), n_nodes, libMesh::MeshBase::node_ptr(), libMesh::Elem::set_node(), libMesh::Elem::subdomain_id(), libMesh::TET10, and libMesh::TET4.

Referenced by read_nodes_and_elem().

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

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

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
Returns
The object as a read-only reference.

Definition at line 168 of file mesh_output.h.

260{
261 libmesh_assert(_obj);
262 return *_obj;
263}
const MeshBase *const _obj
A pointer to a constant object.

◆ 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 115 of file tetgen_io.C.

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

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

Referenced by read_nodes_and_elem().

◆ 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 36 of file tetgen_io.C.

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

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

Referenced by libMesh::NameBasedIO::read(), and MeshInputTest::testTetgenIO().

◆ 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 97 of file tetgen_io.C.

99{
100 _num_nodes = 0;
101 _num_elements = 0;
102
103 // Read all the datasets.
104 this->node_in (node_stream);
105 this->element_in (ele_stream);
106
107 // some more clean-up
108 _assign_nodes.clear();
109}
void element_in(std::istream &ele_stream)
Method reads elements and stores them in vector<Elem *> elements in the same order as they come in.
Definition tetgen_io.C:186
void node_in(std::istream &node_stream)
Method reads nodes from node_stream and stores them in vector<Node *> nodes in the order they come in...
Definition tetgen_io.C:115

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

Referenced by read().

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

101{ this->mesh().set_n_partitions() = n_parts; }
MeshBase & mesh

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

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::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 270 of file tetgen_io.C.

271{
272 // libmesh_assert three dimensions (should be extended later)
273 libmesh_assert_equal_to (MeshOutput<MeshBase>::mesh().mesh_dimension(), 3);
274
275 libmesh_error_msg_if(!Utility::contains(fname, ".poly"),
276 "ERROR: Unrecognized file name: " << fname);
277
278 // Open the output file stream
279 std::ofstream out_stream (fname.c_str());
280
281 // Make sure it opened correctly
282 if (!out_stream.good())
283 libmesh_file_error(fname.c_str());
284
285 // Get a reference to the mesh
286 const MeshBase & mesh = MeshOutput<MeshBase>::mesh();
287
288 // Begin interfacing with the .poly file
289 {
290 // header:
291 out_stream << "# poly file output generated by libmesh\n"
292 << mesh.n_nodes() << " 3 0 0\n";
293
294 // write the nodes:
295 for (auto v : make_range(mesh.n_nodes()))
296 out_stream << v << " "
297 << mesh.point(v)(0) << " "
298 << mesh.point(v)(1) << " "
299 << mesh.point(v)(2) << "\n";
300 }
301
302 {
303 // write the connectivity:
304 out_stream << "# Facets:\n"
305 << mesh.n_elem() << " 0\n";
306
307 for (const auto & elem : mesh.active_element_ptr_range())
308 out_stream << "1\n3 " // no. of facet polygons
309 // << elem->n_nodes() << " "
310 << elem->node_id(0) << " "
311 << elem->node_id(1) << " "
312 << elem->node_id(2) << "\n";
313 }
314
315 // end of the file
316 out_stream << "0\n"; // no holes output!
317 out_stream << "\n\n# end of file\n";
318}
virtual dof_id_type n_elem() const =0
virtual dof_id_type n_nodes() const =0
const MT & mesh() const
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition int_range.h:176

References libMesh::Utility::contains(), libMesh::make_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().

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

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

◆ 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, and libMesh::ExodusII_IO.

Definition at line 92 of file mesh_output.C.

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
68 if (!_is_parallel_format)
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...

◆ write_nodal_data() [1/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 149 of file mesh_output.C.

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}

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

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

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::GmshIO, libMesh::GMVIO, libMesh::GnuPlotIO, libMesh::MEDITIO, libMesh::NameBasedIO, libMesh::TecplotIO, libMesh::VTKIO, libMesh::Nemesis_IO, and libMesh::UCDIO.

Definition at line 109 of file mesh_output.h.

112 { libmesh_not_implemented(); }

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

Member Data Documentation

◆ _ascii_precision

unsigned int libMesh::MeshOutput< MeshBase >::_ascii_precision
privateinherited

Precision to use when writing ASCII files.

Definition at line 207 of file mesh_output.h.

◆ _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 120 of file tetgen_io.h.

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

◆ _is_parallel_format [1/2]

const bool libMesh::MeshInput< MeshBase >::_is_parallel_format
privateinherited

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

◆ _is_parallel_format [2/2]

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.

◆ _num_elements

dof_id_type libMesh::TetGenIO::_num_elements
private

total number of elements.

Primarily used when reading.

Definition at line 130 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 125 of file tetgen_io.h.

Referenced by node_in(), and read_nodes_and_elem().

◆ _obj

MeshBase * libMesh::MeshInput< MeshBase >::_obj
privateinherited

A pointer to a non-const object object.

This allows us to read the object from file.

Definition at line 123 of file mesh_input.h.

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

◆ elems_of_dimension

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

A vector of bools describing what dimension elements have been encountered when reading a mesh.

Definition at line 107 of file mesh_input.h.

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