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 "gzstream.h" 54 std::map<ElemType, std::string> ret;
70 std::map<std::string, ElemType> ret;
84 if (file_name.rfind(
".gz") < file_name.size())
86 #ifdef LIBMESH_HAVE_GZSTREAM 87 igzstream in_stream (file_name.c_str());
90 libmesh_error_msg(
"ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
96 std::ifstream in_stream (file_name.c_str());
105 if (file_name.rfind(
".gz") < file_name.size())
107 #ifdef LIBMESH_HAVE_GZSTREAM 108 ogzstream out_stream (file_name.c_str());
111 libmesh_error_msg(
"ERROR: You must have the zlib.h header files and libraries to read and write compressed streams.");
117 std::ofstream out_stream (file_name.c_str());
142 unsigned int nNodes=0, nElem=0, dummy=0;
156 for (
unsigned int i=0; i<nNodes; i++)
160 std::array<Real, 3> xyz;
171 libmesh_assert_equal_to(xyz[1], 0);
176 libmesh_assert_equal_to(xyz[2], 0);
190 unsigned int material_id=0, node=0;
193 for (
unsigned int i=0; i<nElem; i++)
208 for (
auto n : elem->node_index_range())
224 elem->subdomain_id() = cast_int<subdomain_id_type>(material_id);
232 for (
unsigned char i=0; i!=4; ++i)
238 "Cannot open dimension " 240 <<
" mesh file when configured without " 257 "Error: Can't write boundary elements for meshes of dimension less than 3. " 279 out_stream <<
"# For a description of the UCD format see the AVS Developer's guide.\n" 298 for (
auto & node :
mesh.node_ptr_range())
302 out_stream << n++ <<
"\t";
303 node->write_unformatted(out_stream);
316 for (
const auto & elem :
mesh.element_ptr_range())
324 out_stream << e++ <<
" " << elem->subdomain_id() <<
" " << elem_string <<
"\t";
325 elem->write_connectivity(out_stream,
UCD);
332 const std::vector<Number> & soln,
333 const std::vector<std::string> & names)
343 std::ofstream out_stream(fname.c_str());
350 cast_int<unsigned int>(names.size()));
366 const std::vector<std::string> & names,
367 const std::vector<Number> & soln)
372 out_stream << names.size();
373 for (std::size_t i = 0, ns = names.size(); i < ns; i++)
379 out_stream << std::endl;
383 for (
const auto &
name : names)
386 out_stream <<
name <<
", dummy" << std::endl;
391 std::size_t nv = names.size();
397 for (std::size_t var = 0; var != nv; var++)
399 std::size_t
idx = nv*(n-1) + var;
401 out_stream <<
" " << soln[
idx];
403 out_stream << std::endl;
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
virtual void read(const std::string &) override
This method implements reading a mesh from a specified file in UCD format.
ElemType
Defines an enum for geometric element types.
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
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.
This class defines an abstract interface for Mesh output.
static std::map< ElemType, std::string > _writing_element_map
The libMesh namespace provides an interface to certain functionality in the library.
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.
This is the MeshBase class.
void read_implementation(std::istream &in_stream)
The actual implementation of the read function.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
static std::map< ElemType, std::string > build_writing_element_map()
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
void write_nodes(std::ostream &out, const MeshBase &mesh)
Write node information.
static std::map< std::string, ElemType > build_reading_element_map()
unsigned int mesh_dimension() const
void write_interior_elems(std::ostream &out, const MeshBase &mesh)
Write element information.
void write_implementation(std::ostream &out_stream)
The actual implementation of the write function.
static std::map< std::string, ElemType > _reading_element_map
virtual dof_id_type n_elem() const =0
virtual const Node * node_ptr(const dof_id_type i) const =0
processor_id_type processor_id() const
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 void write(const std::string &) override
This method implements writing a mesh to a specified file in UCD format.
A Point defines a location in LIBMESH_DIM dimensional Real space.
virtual dof_id_type n_nodes() const =0
void write_header(std::ostream &out, const MeshBase &mesh, dof_id_type n_elems, unsigned int n_vars)
Write UCD format header.