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
54 std::map<ElemType, std::string> ret;
70 std::map<std::string, ElemType> ret;
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());
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() = restrict_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;
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
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 const Node * node_ptr(const dof_id_type i) const =0
unsigned int mesh_dimension() const
virtual dof_id_type n_elem() const =0
virtual dof_id_type n_nodes() const =0
void set_mesh_dimension(unsigned char d)
Resets the logical dimension of the mesh.
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.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
This class defines an abstract interface for Mesh output.
processor_id_type processor_id() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
void write_implementation(std::ostream &out_stream)
The actual implementation of the write function.
static std::map< std::string, ElemType > _reading_element_map
static std::map< std::string, ElemType > build_reading_element_map()
virtual void write(const std::string &) override
This method implements writing a mesh to a specified file in UCD format.
static std::map< ElemType, std::string > build_writing_element_map()
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.
void write_nodes(std::ostream &out, const MeshBase &mesh)
Write node information.
void read_implementation(std::istream &in_stream)
The actual implementation of the read function.
void write_header(std::ostream &out, const MeshBase &mesh, dof_id_type n_elems, unsigned int n_vars)
Write UCD format header.
void write_interior_elems(std::ostream &out, const MeshBase &mesh)
Write element information.
static std::map< ElemType, std::string > _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 void read(const std::string &) override
This method implements reading a mesh from a specified file in UCD format.
bool contains(std::string_view superstring, std::string_view substring)
Look for a substring within a string.
The libMesh namespace provides an interface to certain functionality in the library.
ElemType
Defines an enum for geometric element types.