Go to the documentation of this file.
20 #include "libmesh/libmesh_config.h"
21 #include "libmesh/ucd_io.h"
22 #include "libmesh/mesh_base.h"
23 #include "libmesh/face_quad4.h"
24 #include "libmesh/face_tri3.h"
25 #include "libmesh/cell_tet4.h"
26 #include "libmesh/cell_hex8.h"
27 #include "libmesh/cell_prism6.h"
28 #include "libmesh/enum_io_package.h"
29 #include "libmesh/enum_elem_type.h"
30 #include "libmesh/int_range.h"
31 #include "libmesh/utility.h"
33 #ifdef LIBMESH_HAVE_GZSTREAM
34 # include "libmesh/ignore_warnings.h"
35 # include "gzstream.h"
36 # include "libmesh/restore_warnings.h"
56 std::map<ElemType, std::string> ret;
72 std::map<std::string, ElemType> ret;
86 if (file_name.rfind(
".gz") < file_name.size())
88 #ifdef LIBMESH_HAVE_GZSTREAM
89 igzstream in_stream (file_name.c_str());
92 libmesh_error_msg(
"ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
98 std::ifstream in_stream (file_name.c_str());
107 if (file_name.rfind(
".gz") < file_name.size())
109 #ifdef LIBMESH_HAVE_GZSTREAM
110 ogzstream out_stream (file_name.c_str());
113 libmesh_error_msg(
"ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
119 std::ofstream out_stream (file_name.c_str());
144 unsigned int nNodes=0, nElem=0, dummy=0;
158 for (
unsigned int i=0; i<nNodes; i++)
162 std::array<Real, 3> xyz;
173 libmesh_assert_equal_to(xyz[1], 0);
178 libmesh_assert_equal_to(xyz[2], 0);
192 unsigned int material_id=0, node=0;
195 for (
unsigned int i=0; i<nElem; i++)
226 elem->
subdomain_id() = cast_int<subdomain_id_type>(material_id);
234 for (
unsigned char i=0; i!=4; ++i)
240 libmesh_error_msg(
"Cannot open dimension " \
242 <<
" mesh file when configured without " \
259 libmesh_error_msg(
"Error: Can't write boundary elements for meshes of dimension less than 3. " \
281 out_stream <<
"# For a description of the UCD format see the AVS Developer's guide.\n"
304 out_stream << n++ <<
"\t";
305 node->write_unformatted(out_stream);
326 out_stream << e++ <<
" " << elem->subdomain_id() <<
" " << elem_string <<
"\t";
327 elem->write_connectivity(out_stream,
UCD);
334 const std::vector<Number> & soln,
335 const std::vector<std::string> & names)
345 std::ofstream out_stream(fname.c_str());
352 cast_int<unsigned int>(names.size()));
368 const std::vector<std::string> & names,
369 const std::vector<Number> & soln)
374 out_stream << names.size();
375 for (std::size_t i = 0, ns = names.size(); i < ns; i++)
381 out_stream << std::endl;
385 for (
const auto &
name : names)
388 out_stream <<
name <<
", dummy" << std::endl;
393 std::size_t nv = names.size();
399 for (std::size_t var = 0; var != nv; var++)
401 std::size_t
idx = nv*(n-1) + var;
403 out_stream <<
" " << soln[
idx];
405 out_stream << std::endl;
static std::map< ElemType, std::string > _writing_element_map
void write_implementation(std::ostream &out_stream)
The actual implementation of the write function.
virtual dof_id_type n_elem() const =0
void read_implementation(std::istream &in_stream)
The actual implementation of the read function.
The libMesh namespace provides an interface to certain functionality in the library.
virtual unsigned short dim() const =0
IntRange< unsigned short > node_index_range() const
virtual const Node * node_ptr(const dof_id_type i) const =0
unsigned int mesh_dimension() const
void write_soln(std::ostream &out, const MeshBase &mesh, const std::vector< std::string > &names, const std::vector< Number > &soln)
Writes all nodal solution variables.
virtual SimpleRange< element_iterator > element_ptr_range()=0
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
This is the MeshBase class.
virtual SimpleRange< node_iterator > node_ptr_range()=0
processor_id_type processor_id() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
static std::map< std::string, ElemType > build_reading_element_map()
static std::map< std::string, ElemType > _reading_element_map
virtual Node *& set_node(const unsigned int i)
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in UCD format.
virtual dof_id_type n_nodes() const =0
This class defines an abstract interface for Mesh output.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
void write_header(std::ostream &out, const MeshBase &mesh, dof_id_type n_elems, unsigned int n_vars)
Write UCD format header.
subdomain_id_type subdomain_id() const
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file in UCD format.
This is the base class from which all geometric element types are derived.
static std::map< ElemType, std::string > build_writing_element_map()
virtual void write_nodal_data(const std::string &fname, const std::vector< Number > &soln, const std::vector< std::string > &names) override
This method implements writing a mesh and solution to a specified file in UCD format.
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
void write_interior_elems(std::ostream &out, const MeshBase &mesh)
Write element information.
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
void write_nodes(std::ostream &out, const MeshBase &mesh)
Write node information.
ElemType
Defines an enum for geometric element types.