25 #include "libmesh/libmesh_config.h" 26 #include "libmesh/libmesh_logging.h" 27 #include "libmesh/mesh_base.h" 28 #include "libmesh/medit_io.h" 29 #include "libmesh/elem.h" 39 if (this->
mesh().processor_id() == 0)
47 const std::vector<Number> & soln,
48 const std::vector<std::string> & names)
50 LOG_SCOPE(
"write_nodal_data()",
"MEDITIO");
52 if (this->
mesh().processor_id() == 0)
60 const std::vector<Number> * vec,
61 const std::vector<std::string> * solution_names)
73 std::ofstream out_stream (fname.c_str());
76 if (!out_stream.good())
77 libmesh_file_error(fname.c_str());
85 out_stream <<
"MeshVersionFormatted 1\n";
86 out_stream <<
"Dimension 3\n";
87 out_stream <<
"# Mesh generated by libmesh\n\n";
90 out_stream <<
"# Set of mesh vertices\n";
91 out_stream <<
"Vertices\n";
92 out_stream << the_mesh.
n_nodes() <<
"\n";
95 out_stream << the_mesh.
point(v)(0) <<
" " << the_mesh.
point(v)(1) <<
" " << the_mesh.
point(v)(2) <<
" 0\n";
100 out_stream <<
"\n# Set of Polys\n\n";
107 for (
const auto & elem : the_mesh.active_element_ptr_range())
109 if (elem->type() ==
TRI3) n_tri3++;
110 if (elem->type() ==
QUAD4) n_quad4++;
111 if (elem->type() ==
QUAD9) n_quad4+=4;
112 if (elem->type() ==
TET4) n_tet4++;
116 out_stream <<
"Triangles\n";
117 out_stream << n_tri3 <<
"\n";
119 for (
const auto & elem : the_mesh.active_element_ptr_range())
120 if (elem->type() ==
TRI3)
121 out_stream << elem->node_id(0)+1 <<
" " 122 << elem->node_id(1)+1 <<
" " 123 << elem->node_id(2)+1 <<
" 0\n";
126 out_stream <<
"Quadrilaterals\n";
127 out_stream << n_quad4 <<
"\n";
129 for (
const auto & elem : the_mesh.active_element_ptr_range())
131 if (elem->type() ==
QUAD4)
133 out_stream << elem->node_id(0)+1 <<
" " 134 << elem->node_id(1)+1 <<
" " 135 << elem->node_id(2)+1 <<
" " 136 << elem->node_id(3)+1 <<
" 0\n";
138 else if (elem->type() ==
QUAD9)
140 out_stream << elem->node_id(0)+1 <<
" " 141 << elem->node_id(4)+1 <<
" " 142 << elem->node_id(8)+1 <<
" " 143 << elem->node_id(7)+1 <<
" 0\n";
144 out_stream << elem->node_id(7)+1 <<
" " 145 << elem->node_id(8)+1 <<
" " 146 << elem->node_id(6)+1 <<
" " 147 << elem->node_id(3)+1 <<
" 0\n";
148 out_stream << elem->node_id(4)+1 <<
" " 149 << elem->node_id(1)+1 <<
" " 150 << elem->node_id(5)+1 <<
" " 151 << elem->node_id(8)+1 <<
" 0\n";
152 out_stream << elem->node_id(8)+1 <<
" " 153 << elem->node_id(5)+1 <<
" " 154 << elem->node_id(2)+1 <<
" " 155 << elem->node_id(6)+1 <<
" 0\n";
160 out_stream <<
"Tetrahedra\n";
161 out_stream << n_tet4 <<
"\n";
163 for (
const auto & elem : the_mesh.active_element_ptr_range())
164 if (elem->type() ==
TET4)
166 out_stream << elem->node_id(0)+1 <<
" " 167 << elem->node_id(1)+1 <<
" " 168 << elem->node_id(2)+1 <<
" " 169 << elem->node_id(3)+1 <<
" 0\n";
173 out_stream <<
'\n' <<
"# end of file\n";
176 if ((solution_names !=
nullptr) &&
180 std::size_t
idx = fname.find_last_of(
".");
181 std::string bbname = fname.substr(0,
idx) +
".bb";
183 std::ofstream bbout (bbname.c_str());
187 libmesh_file_error(bbname.c_str());
190 const std::size_t
n_vars = solution_names->size();
191 bbout <<
"3 1 " << the_mesh.
n_nodes() <<
" 2\n";
const MeshBase & mesh() const
virtual void write(const std::string &) override
This method implements writing a mesh to a specified ".mesh" file.
unsigned int & ascii_precision()
Return/set the precision to use when writing ASCII files.
This class defines an abstract interface for Mesh output.
The libMesh namespace provides an interface to certain functionality in the library.
This is the MeshBase class.
bool & binary()
Flag indicating whether or not to write a binary file.
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...
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &) override
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
virtual const Point & point(const dof_id_type i) const =0
virtual dof_id_type n_nodes() const =0
void write_ascii(const std::string &, const std::vector< Number > *=nullptr, const std::vector< std::string > *=nullptr)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...