21 #include "libmesh/dof_map.h" 22 #include "libmesh/ensight_io.h" 23 #include "libmesh/equation_systems.h" 24 #include "libmesh/fe_interface.h" 25 #include "libmesh/libmesh.h" 26 #include "libmesh/system.h" 27 #include "libmesh/elem.h" 28 #include "libmesh/enum_elem_type.h" 29 #include "libmesh/int_range.h" 30 #include "libmesh/utility.h" 47 std::map<ElemType, std::string> ret;
56 ret[
TET10] =
"tetra10";
58 ret[
HEX20] =
"hexa20";
74 std::ostringstream tmp_file;
83 std::string_view vec_description,
93 vec.components.push_back(std::move(u));
94 vec.components.push_back(std::move(v));
102 std::string_view vec_name,
114 vec.components.push_back(std::move(u));
115 vec.components.push_back(std::move(v));
116 vec.components.push_back(std::move(w));
123 std::string_view scl_description,
172 std::ostringstream file;
176 << std::setprecision(0)
182 std::ofstream mesh_stream(file.str().c_str());
184 mesh_stream <<
"EnSight Gold Geometry File Format\n";
185 mesh_stream <<
"Generated by \n";
186 mesh_stream <<
"node id off\n";
187 mesh_stream <<
"element id given\n";
188 mesh_stream <<
"part\n";
189 mesh_stream << std::setw(10) << 1 <<
"\n";
190 mesh_stream <<
"uns-elements\n";
191 mesh_stream <<
"coordinates\n";
194 std::map<int, Point> mesh_nodes_map;
197 std::map<ElemType, std::vector<const Elem *>> ensight_parts_map;
202 for (
const auto & elem : the_mesh.active_local_element_ptr_range())
204 ensight_parts_map[elem->type()].push_back(elem);
206 for (
const Node & node : elem->node_ref_range())
207 mesh_nodes_map[node.id()] = node;
211 mesh_stream << std::setw(10) << mesh_nodes_map.size() <<
"\n";
215 std::map <int, int> ensight_node_index;
216 for (
unsigned direction=0; direction<3; ++direction)
219 for (
const auto & [
idx, pt] : mesh_nodes_map)
221 mesh_stream << std::setw(12)
222 << std::setprecision(5)
226 ensight_node_index[
idx] = i++;
231 for (
const auto & [elem_type, elem_ref] : ensight_parts_map)
237 mesh_stream <<
"\n" <<
name <<
"\n";
240 mesh_stream << std::setw(10) << elem_ref.size() <<
"\n";
243 for (
const auto & elem : elem_ref)
244 mesh_stream << std::setw(10) << elem->id() <<
"\n";
249 for (
const auto & node : elem_ref[i]->node_ref_range())
252 if (elem_type ==
QUAD9 && i==4)
256 if (elem_type ==
HEX27 &&
257 (i==4 || i ==10 || i == 12 ||
258 i == 13 || i ==14 || i == 16 || i == 22))
261 mesh_stream << std::setw(10) << ensight_node_index[node.id()];
274 std::ostringstream case_file;
278 std::ofstream case_stream(case_file.str().c_str());
280 case_stream <<
"FORMAT\n";
281 case_stream <<
"type: ensight gold\n\n";
282 case_stream <<
"GEOMETRY\n";
287 case_stream <<
"\n\nVARIABLE\n";
291 for (
const auto & scalar : pr.second.EnsightScalars)
292 case_stream <<
"scalar per node: 1 " 293 << scalar.description <<
" " 296 for (
const auto & vec : pr.second.EnsightVectors)
297 case_stream <<
"vector per node: 1 " 298 << vec.description <<
" " 304 case_stream <<
"\n\nTIME\n";
305 case_stream <<
"time set: 1\n";
306 case_stream <<
"number of steps: " << std::setw(10) <<
_time_steps.size() <<
"\n";
307 case_stream <<
"filename start number: " << std::setw(10) << 0 <<
"\n";
308 case_stream <<
"filename increment: " << std::setw(10) << 1 <<
"\n";
309 case_stream <<
"time values:\n";
311 case_stream << std::setw(12) << std::setprecision(5) << std::scientific << time <<
"\n";
322 for (
const auto & scalar : sys_vars.EnsightScalars)
326 for (
const auto & vec : sys_vars.EnsightVectors)
335 std::string_view var_name)
338 std::ostringstream scl_file;
344 << std::setprecision(0)
350 std::ofstream scl_stream(scl_file.str().c_str());
351 scl_stream <<
"Per node scalar value\n";
352 scl_stream <<
"part\n";
353 scl_stream << std::setw(10) << 1 <<
"\n";
354 scl_stream <<
"coordinates\n";
362 std::vector<dof_id_type> dof_indices_scl;
367 std::map<int, Real> local_soln;
369 std::vector<Number> elem_soln;
370 std::vector<Number> nodal_soln;
373 for (
const auto & elem : the_mesh.active_local_element_ptr_range())
379 elem_soln.resize(dof_indices_scl.size());
386 libmesh_assert_equal_to (nodal_soln.size(), elem->n_nodes());
388 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 389 libmesh_error_msg(
"Complex-valued Ensight output not yet supported");
392 for (
auto n : elem->node_index_range())
393 local_soln[elem->node_id(n)] =
libmesh_real(nodal_soln[n]);
396 for (
const auto & pr : local_soln)
397 scl_stream << std::setw(12)
398 << std::setprecision(5)
406 const std::vector<std::string> & vec,
407 std::string_view var_name)
410 std::ostringstream vec_file;
416 << std::setprecision(0)
422 std::ofstream vec_stream(vec_file.str().c_str());
423 vec_stream <<
"Per vector per value\n";
424 vec_stream <<
"part\n";
425 vec_stream << std::setw(10) << 1 <<
"\n";
426 vec_stream <<
"coordinates\n";
442 std::vector<dof_id_type> dof_indices_u;
443 std::vector<dof_id_type> dof_indices_v;
444 std::vector<dof_id_type> dof_indices_w;
449 std::map<int,std::vector<Real>> local_soln;
452 for (
const auto & elem : the_mesh.active_local_element_ptr_range())
461 std::vector<Number> elem_soln_u;
462 std::vector<Number> elem_soln_v;
463 std::vector<Number> elem_soln_w;
465 std::vector<Number> nodal_soln_u;
466 std::vector<Number> nodal_soln_v;
467 std::vector<Number> nodal_soln_w;
469 elem_soln_u.resize(dof_indices_u.size());
470 elem_soln_v.resize(dof_indices_v.size());
472 elem_soln_w.resize(dof_indices_w.size());
487 libmesh_assert_equal_to (nodal_soln_u.size(), elem->n_nodes());
488 libmesh_assert_equal_to (nodal_soln_v.size(), elem->n_nodes());
490 #ifdef LIBMESH_ENABLE_COMPLEX 491 libmesh_error_msg(
"Complex-valued Ensight output not yet supported");
494 for (
const auto & n : elem->node_index_range())
496 std::vector<Real> node_vec(3);
502 local_soln[elem->node_id(n)] = node_vec;
506 for (
unsigned dir=0; dir<3; ++dir)
508 for (
const auto & pr : local_soln)
509 vec_stream << std::setw(12)
511 << std::setprecision(5)
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
class FEType hides (possibly multiple) FEFamily and approximation orders, thereby enabling specialize...
const MeshBase & mesh() const
void write_solution_ascii()
void write_geometry_ascii()
void add_vector(const std::string &system, std::string_view vec_description, std::string u, std::string v)
Tell the EnsightIO interface that the variables (u,v) constitute a vector.
std::string _ensight_file_name
This is the EquationSystems class.
A Node is like a Point, but with more information.
EnsightIO(const std::string &filename, const EquationSystems &eq)
Constructor.
static std::map< ElemType, std::string > build_element_map()
bool has_system(std::string_view name) const
void dof_indices(const Elem *const elem, std::vector< dof_id_type > &di) const
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
std::map< std::string, SystemVars > _system_vars_map
This class defines an abstract interface for Mesh output.
The libMesh namespace provides an interface to certain functionality in the library.
const T_sys & get_system(std::string_view name) const
This is the MeshBase class.
Number current_solution(const dof_id_type global_dof_number) const
unsigned int variable_number(std::string_view var) const
This class handles the numbering of degrees of freedom on a mesh.
processor_id_type n_processors() const
static std::map< ElemType, std::string > _element_map
Manages consistently variables, degrees of freedom, and coefficient vectors.
void write(Real time=0)
Calls write_ascii() and write_case().
const EquationSystems & _equation_systems
void write_scalar_ascii(std::string_view sys, std::string_view var)
void add_scalar(const std::string &system, std::string_view scalar_description, std::string_view s)
Tell the EnsightIO interface to output the finite element (not SCALAR) variable named "s"...
const FEType & variable_type(const unsigned int i) const
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Temporarily serialize a DistributedMesh for non-distributed-mesh capable code paths.
void write_vector_ascii(std::string_view sys, const std::vector< std::string > &vec, std::string_view var_name)
unsigned int mesh_dimension() const
std::vector< Real > _time_steps
processor_id_type processor_id() const
static void nodal_soln(const unsigned int dim, const FEType &fe_t, const Elem *elem, const std::vector< Number > &elem_soln, std::vector< Number > &nodal_soln, const bool add_p_level=true, const unsigned int vdim=1)
Build the nodal soln from the element soln.
const DofMap & get_dof_map() const
void write_ascii(Real time=0)
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...