libMesh
Classes | Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
libMesh::EnsightIO Class Reference

This class implements writing meshes and solutions in Ensight's Gold format. More...

#include <ensight_io.h>

Inheritance diagram for libMesh::EnsightIO:
[legend]

Classes

struct  Scalars
 
struct  SystemVars
 
struct  Vectors
 

Public Member Functions

 EnsightIO (const std::string &filename, const EquationSystems &eq)
 Constructor. More...
 
 ~EnsightIO ()=default
 Empty destructor. More...
 
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". More...
 
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. More...
 
void add_vector (const std::string &system, std::string_view vec_description, std::string u, std::string v, std::string w)
 Tell the EnsightIO interface that the variables (u, v, w) constitute a vector. More...
 
void write (Real time=0)
 Calls write_ascii() and write_case(). More...
 
virtual void write (const std::string &name) override
 Calls this->write(0);. More...
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object. More...
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided. More...
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 This method may be overridden by "parallel" output formats for writing nodal data. More...
 
virtual void write_nodal_data (const std::string &, const EquationSystems &, const std::set< std::string > *)
 This method should be overridden by "parallel" output formats for writing nodal data. More...
 
virtual void write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided. More...
 
unsigned intascii_precision ()
 Return/set the precision to use when writing ASCII files. More...
 

Protected Member Functions

const MeshBasemesh () const
 
virtual bool get_add_sides ()
 

Protected Attributes

const bool _is_parallel_format
 Flag specifying whether this format is parallel-capable. More...
 
const bool _serial_only_needed_on_proc_0
 Flag specifying whether this format can be written by only serializing the mesh to processor zero. More...
 

Private Member Functions

void write_ascii (Real time=0)
 
void write_scalar_ascii (std::string_view sys, std::string_view var)
 
void write_vector_ascii (std::string_view sys, const std::vector< std::string > &vec, std::string_view var_name)
 
void write_solution_ascii ()
 
void write_geometry_ascii ()
 
void write_case ()
 

Static Private Member Functions

static std::map< ElemType, std::string > build_element_map ()
 

Private Attributes

std::string _ensight_file_name
 
std::vector< Real_time_steps
 
std::map< std::string, SystemVars_system_vars_map
 
const EquationSystems_equation_systems
 

Static Private Attributes

static std::map< ElemType, std::string > _element_map = EnsightIO::build_element_map()
 

Detailed Description

This class implements writing meshes and solutions in Ensight's Gold format.

Author
Camata
Date
2009
Author
J. W. Peterson (refactoring and iostreams implementation)
Date
2016

Definition at line 47 of file ensight_io.h.

Constructor & Destructor Documentation

◆ EnsightIO()

libMesh::EnsightIO::EnsightIO ( const std::string &  filename,
const EquationSystems eq 
)

Constructor.

Definition at line 65 of file ensight_io.C.

References _ensight_file_name, _equation_systems, libMesh::ParallelObject::n_processors(), and libMesh::ParallelObject::processor_id().

66  :
67  MeshOutput<MeshBase> (eq.get_mesh()),
69 {
71  _ensight_file_name = filename;
72  else
73  {
74  std::ostringstream tmp_file;
75  tmp_file << filename << "_rank" << _equation_systems.processor_id();
76  _ensight_file_name = tmp_file.str();
77  }
78 }
std::string _ensight_file_name
Definition: ensight_io.h:144
template class LIBMESH_EXPORT MeshOutput< MeshBase >
Definition: mesh_output.C:180
processor_id_type n_processors() const
const EquationSystems & _equation_systems
Definition: ensight_io.h:151
processor_id_type processor_id() const

◆ ~EnsightIO()

libMesh::EnsightIO::~EnsightIO ( )
default

Empty destructor.

Member Function Documentation

◆ add_scalar()

void libMesh::EnsightIO::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".

Note
You must call add_scalar() or add_vector() (see below) at least once, otherwise only the Mesh will be written out.

Definition at line 122 of file ensight_io.C.

References _equation_systems, _system_vars_map, libMesh::EnsightIO::Scalars::description, libMesh::EquationSystems::get_system(), libMesh::EquationSystems::has_system(), and libMesh::libmesh_assert().

125 {
127  libmesh_assert(_equation_systems.get_system(system_name).has_variable(s));
128 
129  Scalars scl;
130  scl.description = scl_description;
131  scl.scalar_name = s;
132 
133  _system_vars_map[system_name].EnsightScalars.push_back(std::move(scl));
134 }
bool has_system(std::string_view name) const
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:148
const T_sys & get_system(std::string_view name) const
libmesh_assert(ctx)
const EquationSystems & _equation_systems
Definition: ensight_io.h:151

◆ add_vector() [1/2]

void libMesh::EnsightIO::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.

Note
u and v must have the same FEType, and be defined in the same system.

Definition at line 82 of file ensight_io.C.

References _equation_systems, _system_vars_map, libMesh::EnsightIO::Vectors::description, libMesh::EquationSystems::get_system(), libMesh::EquationSystems::has_system(), and libMesh::libmesh_assert().

86 {
88  libmesh_assert (_equation_systems.get_system(system_name).has_variable(u));
89  libmesh_assert (_equation_systems.get_system(system_name).has_variable(v));
90 
91  Vectors vec;
92  vec.description = vec_description;
93  vec.components.push_back(std::move(u));
94  vec.components.push_back(std::move(v));
95 
96  _system_vars_map[system_name].EnsightVectors.push_back(std::move(vec));
97 }
bool has_system(std::string_view name) const
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:148
const T_sys & get_system(std::string_view name) const
libmesh_assert(ctx)
const EquationSystems & _equation_systems
Definition: ensight_io.h:151

◆ add_vector() [2/2]

void libMesh::EnsightIO::add_vector ( const std::string &  system,
std::string_view  vec_description,
std::string  u,
std::string  v,
std::string  w 
)

Tell the EnsightIO interface that the variables (u, v, w) constitute a vector.

Note
Requires a 3D mesh, u, v, and w must have the same FEType, and must be defined in the same system.

Definition at line 101 of file ensight_io.C.

References _equation_systems, _system_vars_map, libMesh::EnsightIO::Vectors::description, libMesh::EquationSystems::get_system(), libMesh::EquationSystems::has_system(), and libMesh::libmesh_assert().

106 {
108  libmesh_assert(_equation_systems.get_system(system_name).has_variable(u));
109  libmesh_assert(_equation_systems.get_system(system_name).has_variable(v));
110  libmesh_assert(_equation_systems.get_system(system_name).has_variable(w));
111 
112  Vectors vec;
113  vec.description = 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));
117  _system_vars_map[system_name].EnsightVectors.push_back(std::move(vec));
118 }
bool has_system(std::string_view name) const
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:148
const T_sys & get_system(std::string_view name) const
libmesh_assert(ctx)
const EquationSystems & _equation_systems
Definition: ensight_io.h:151

◆ ascii_precision()

unsigned int & libMesh::MeshOutput< MeshBase >::ascii_precision ( )
inlineinherited

Return/set the precision to use when writing ASCII files.

By default we use numeric_limits<Real>::max_digits10, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Definition at line 269 of file mesh_output.h.

Referenced by libMesh::UNVIO::nodes_out(), libMesh::FroIO::write(), libMesh::MEDITIO::write_ascii(), libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().

270 {
271  return _ascii_precision;
272 }
unsigned int _ascii_precision
Precision to use when writing ASCII files.
Definition: mesh_output.h:207

◆ build_element_map()

std::map< ElemType, std::string > libMesh::EnsightIO::build_element_map ( )
staticprivate

Definition at line 45 of file ensight_io.C.

References libMesh::EDGE2, libMesh::EDGE3, libMesh::HEX20, libMesh::HEX8, libMesh::PYRAMID5, libMesh::QUAD4, libMesh::QUAD8, libMesh::TET10, libMesh::TET4, libMesh::TRI3, and libMesh::TRI6.

46 {
47  std::map<ElemType, std::string> ret;
48  ret[EDGE2] = "bar2";
49  ret[EDGE3] = "bar3";
50  ret[QUAD4] = "quad4";
51  ret[QUAD8] = "quad8";
52  // ret[QUAD9] = "quad9"; // not supported
53  ret[TRI3] = "tria3";
54  ret[TRI6] = "tria6";
55  ret[TET4] = "tetra4";
56  ret[TET10] = "tetra10";
57  ret[HEX8] = "hexa8";
58  ret[HEX20] = "hexa20";
59  // ret[HEX27] = "HEX27"; // not supported
60  ret[PYRAMID5] = "pyramid5";
61  return ret;
62 }

◆ get_add_sides()

virtual bool libMesh::MeshOutput< MeshBase >::get_add_sides ( )
inlineprotectedvirtualinherited
Returns
Whether or not added sides are expected to be output, to plot SIDE_DISCONTINUOUS data. Subclasses should override this if they are capable of plotting such data.

Reimplemented in libMesh::ExodusII_IO.

Definition at line 176 of file mesh_output.h.

176 { return false; }

◆ mesh()

const MeshBase & libMesh::MeshOutput< MeshBase >::mesh ( ) const
inlineprotectedinherited

◆ write() [1/2]

void libMesh::EnsightIO::write ( Real  time = 0)

Calls write_ascii() and write_case().

Writes case, mesh, and solution files named: name.case (contains a description of other files) name.geo000 (mesh) name_{varname}.scl000 (one file per scalar variable) name_{vecname}.vec000 (one file per vector variable)

Definition at line 152 of file ensight_io.C.

References write_ascii(), and write_case().

Referenced by write().

153 {
154  this->write_ascii(time);
155  this->write_case();
156 }
void write_ascii(Real time=0)
Definition: ensight_io.C:160

◆ write() [2/2]

void libMesh::EnsightIO::write ( const std::string &  name)
overridevirtual

Calls this->write(0);.

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 140 of file ensight_io.C.

References _ensight_file_name, libMesh::MeshOutput< MeshBase >::_is_parallel_format, libMesh::MeshOutput< MeshBase >::mesh(), libMesh::Quality::name(), and write().

141 {
142  // We may need to gather a DistributedMesh to output it, making that
143  // const qualifier in our constructor a dirty lie
144  MeshSerializer serialize(const_cast<MeshBase &>(this->mesh()), !_is_parallel_format);
145 
147  this->write();
148 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
const MeshBase & mesh() const
Definition: mesh_output.h:259
std::string _ensight_file_name
Definition: ensight_io.h:144
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition: mesh_output.h:184
void write(Real time=0)
Calls write_ascii() and write_case().
Definition: ensight_io.C:152

◆ write_ascii()

void libMesh::EnsightIO::write_ascii ( Real  time = 0)
private

Definition at line 160 of file ensight_io.C.

References _time_steps, write_geometry_ascii(), and write_solution_ascii().

Referenced by write().

161 {
162  _time_steps.push_back(time);
163 
164  this->write_geometry_ascii();
165  this->write_solution_ascii();
166 }
void write_solution_ascii()
Definition: ensight_io.C:318
void write_geometry_ascii()
Definition: ensight_io.C:170
std::vector< Real > _time_steps
Definition: ensight_io.h:145

◆ write_case()

void libMesh::EnsightIO::write_case ( )
private

Definition at line 272 of file ensight_io.C.

References _ensight_file_name, _system_vars_map, and _time_steps.

Referenced by write().

273 {
274  std::ostringstream case_file;
275  case_file << _ensight_file_name << ".case";
276 
277  // Open a stream for writing the case file.
278  std::ofstream case_stream(case_file.str().c_str());
279 
280  case_stream << "FORMAT\n";
281  case_stream << "type: ensight gold\n\n";
282  case_stream << "GEOMETRY\n";
283  case_stream << "model: 1 " << _ensight_file_name << ".geo" << "***\n";
284 
285  // Write Variable per node section
286  if (!_system_vars_map.empty())
287  case_stream << "\n\nVARIABLE\n";
288 
289  for (const auto & pr : _system_vars_map)
290  {
291  for (const auto & scalar : pr.second.EnsightScalars)
292  case_stream << "scalar per node: 1 "
293  << scalar.description << " "
294  << _ensight_file_name << "_" << scalar.scalar_name << ".scl***\n";
295 
296  for (const auto & vec : pr.second.EnsightVectors)
297  case_stream << "vector per node: 1 "
298  << vec.description << " "
299  << _ensight_file_name << "_" << vec.description << ".vec***\n";
300 
301  // Write time step section
302  if (_time_steps.size() != 0)
303  {
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";
310  for (const auto & time : _time_steps)
311  case_stream << std::setw(12) << std::setprecision(5) << std::scientific << time << "\n";
312  }
313  }
314 }
std::string _ensight_file_name
Definition: ensight_io.h:144
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:148
std::vector< Real > _time_steps
Definition: ensight_io.h:145

◆ write_discontinuous_equation_systems()

void libMesh::MeshOutput< MeshBase >::write_discontinuous_equation_systems ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

This method implements writing a mesh with discontinuous data to a specified file where the data is taken from the EquationSystems object.

Definition at line 89 of file mesh_output.C.

References libMesh::EquationSystems::build_discontinuous_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), libMesh::libmesh_assert(), and libMesh::out.

Referenced by libMesh::ExodusII_IO::write_timestep_discontinuous().

92 {
93  LOG_SCOPE("write_discontinuous_equation_systems()", "MeshOutput");
94 
95  // We may need to gather and/or renumber a DistributedMesh to output
96  // it, making that const qualifier in our constructor a dirty lie
97  MT & my_mesh = const_cast<MT &>(*_obj);
98 
99  // If we're asked to write data that's associated with a different
100  // mesh, output files full of garbage are the result.
101  libmesh_assert_equal_to(&es.get_mesh(), _obj);
102 
103  // A non-renumbered mesh may not have a contiguous numbering, and
104  // that needs to be fixed before we can build a solution vector.
105  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
106  my_mesh.max_node_id() != my_mesh.n_nodes())
107  {
108  // If we were allowed to renumber then we should have already
109  // been properly renumbered...
110  libmesh_assert(!my_mesh.allow_renumbering());
111 
112  libmesh_do_once(libMesh::out <<
113  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
114  << std::endl;);
115 
116  my_mesh.allow_renumbering(true);
117 
118  my_mesh.renumber_nodes_and_elements();
119 
120  // Not sure what good going back to false will do here, the
121  // renumbering horses have already left the barn...
122  my_mesh.allow_renumbering(false);
123  }
124 
125  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
126 
127  // Build the list of variable names that will be written.
128  std::vector<std::string> names;
129  es.build_variable_names (names, nullptr, system_names);
130 
131  if (!_is_parallel_format)
132  {
133  // Build the nodal solution values & get the variable
134  // names from the EquationSystems object
135  std::vector<Number> soln;
136  es.build_discontinuous_solution_vector (soln, system_names,
137  nullptr, false, /* defaults */
138  this->get_add_sides());
139 
140  this->write_nodal_data_discontinuous (fname, soln, names);
141  }
142  else // _is_parallel_format
143  {
144  libmesh_not_implemented();
145  }
146 }
virtual void write_nodal_data_discontinuous(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
This method implements writing a mesh with discontinuous data to a specified file where the nodal dat...
Definition: mesh_output.h:118
const MeshBase *const _obj
A pointer to a constant object.
Definition: mesh_output.h:202
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition: mesh_output.h:184
libmesh_assert(ctx)
OStreamProxy out
const bool _serial_only_needed_on_proc_0
Flag specifying whether this format can be written by only serializing the mesh to processor zero...
Definition: mesh_output.h:193

◆ write_equation_systems()

void libMesh::MeshOutput< MeshBase >::write_equation_systems ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names = nullptr 
)
virtualinherited

This method implements writing a mesh with data to a specified file where the data is taken from the EquationSystems object.

Reimplemented in libMesh::NameBasedIO.

Definition at line 31 of file mesh_output.C.

References libMesh::EquationSystems::build_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), libMesh::libmesh_assert(), and libMesh::out.

Referenced by libMesh::Nemesis_IO::write_timestep(), and libMesh::ExodusII_IO::write_timestep().

34 {
35  LOG_SCOPE("write_equation_systems()", "MeshOutput");
36 
37  // We may need to gather and/or renumber a DistributedMesh to output
38  // it, making that const qualifier in our constructor a dirty lie
39  MT & my_mesh = const_cast<MT &>(*_obj);
40 
41  // If we're asked to write data that's associated with a different
42  // mesh, output files full of garbage are the result.
43  libmesh_assert_equal_to(&es.get_mesh(), _obj);
44 
45  // A non-parallel format, non-renumbered mesh may not have a contiguous
46  // numbering, and that needs to be fixed before we can build a solution vector.
47  if (!_is_parallel_format &&
48  (my_mesh.max_elem_id() != my_mesh.n_elem() ||
49  my_mesh.max_node_id() != my_mesh.n_nodes()))
50  {
51  // If we were allowed to renumber then we should have already
52  // been properly renumbered...
53  libmesh_assert(!my_mesh.allow_renumbering());
54 
55  libmesh_do_once(libMesh::out <<
56  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
57  << std::endl;);
58 
59  my_mesh.allow_renumbering(true);
60 
61  my_mesh.renumber_nodes_and_elements();
62 
63  // Not sure what good going back to false will do here, the
64  // renumbering horses have already left the barn...
65  my_mesh.allow_renumbering(false);
66  }
67 
69  {
70  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
71 
72  // Build the list of variable names that will be written.
73  std::vector<std::string> names;
74  es.build_variable_names (names, nullptr, system_names);
75 
76  // Build the nodal solution values & get the variable
77  // names from the EquationSystems object
78  std::vector<Number> soln;
79  es.build_solution_vector (soln, system_names,
80  this->get_add_sides());
81 
82  this->write_nodal_data (fname, soln, names);
83  }
84  else // _is_parallel_format
85  this->write_nodal_data (fname, es, system_names);
86 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: mesh_output.h:109
const MeshBase *const _obj
A pointer to a constant object.
Definition: mesh_output.h:202
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition: mesh_output.h:184
libmesh_assert(ctx)
OStreamProxy out
const bool _serial_only_needed_on_proc_0
Flag specifying whether this format can be written by only serializing the mesh to processor zero...
Definition: mesh_output.h:193

◆ write_geometry_ascii()

void libMesh::EnsightIO::write_geometry_ascii ( )
private

Definition at line 170 of file ensight_io.C.

References _element_map, _ensight_file_name, _time_steps, libMesh::HEX27, libMesh::MeshTools::Generation::Private::idx(), libMesh::index_range(), libMesh::MeshOutput< MT >::mesh(), libMesh::Quality::name(), and libMesh::QUAD9.

Referenced by write_ascii().

171 {
172  std::ostringstream file;
173  file << _ensight_file_name
174  << ".geo"
175  << std::setw(3)
176  << std::setprecision(0)
177  << std::setfill('0')
178  << std::right
179  << _time_steps.size()-1;
180 
181  // Open a stream to write the mesh
182  std::ofstream mesh_stream(file.str().c_str());
183 
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";
192 
193  // mapping between nodal index and your coordinates
194  std::map<int, Point> mesh_nodes_map;
195 
196  // Map for grouping elements of the same type
197  std::map<ElemType, std::vector<const Elem *>> ensight_parts_map;
198 
199  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
200 
201  // Construct the various required maps
202  for (const auto & elem : the_mesh.active_local_element_ptr_range())
203  {
204  ensight_parts_map[elem->type()].push_back(elem);
205 
206  for (const Node & node : elem->node_ref_range())
207  mesh_nodes_map[node.id()] = node;
208  }
209 
210  // Write number of local points
211  mesh_stream << std::setw(10) << mesh_nodes_map.size() << "\n";
212 
213  // write x, y, and z node positions, build mapping between
214  // ensight and libmesh node numbers.
215  std::map <int, int> ensight_node_index;
216  for (unsigned direction=0; direction<3; ++direction)
217  {
218  int i = 1;
219  for (const auto & [idx, pt] : mesh_nodes_map)
220  {
221  mesh_stream << std::setw(12)
222  << std::setprecision(5)
223  << std::scientific
224  << pt(direction)
225  << "\n";
226  ensight_node_index[idx] = i++;
227  }
228  }
229 
230  // Write parts
231  for (const auto & [elem_type, elem_ref] : ensight_parts_map)
232  {
233  // Look up this ElemType in the map, error if not present.
234  std::string name = libmesh_map_find(_element_map, elem_type);
235 
236  // Write element type
237  mesh_stream << "\n" << name << "\n";
238 
239  // Write number of element
240  mesh_stream << std::setw(10) << elem_ref.size() << "\n";
241 
242  // Write element id
243  for (const auto & elem : elem_ref)
244  mesh_stream << std::setw(10) << elem->id() << "\n";
245 
246  // Write connectivity
247  for (auto i : index_range(elem_ref))
248  {
249  for (const auto & node : elem_ref[i]->node_ref_range())
250  {
251  // tests!
252  if (elem_type == QUAD9 && i==4)
253  continue;
254 
255  // tests!
256  if (elem_type == HEX27 &&
257  (i==4 || i ==10 || i == 12 ||
258  i == 13 || i ==14 || i == 16 || i == 22))
259  continue;
260 
261  mesh_stream << std::setw(10) << ensight_node_index[node.id()];
262  }
263  mesh_stream << "\n";
264  }
265  }
266 }
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
const MT & mesh() const
Definition: mesh_output.h:259
std::string _ensight_file_name
Definition: ensight_io.h:144
static std::map< ElemType, std::string > _element_map
Definition: ensight_io.h:154
std::vector< Real > _time_steps
Definition: ensight_io.h:145
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:111
unsigned int idx(const ElemType type, const unsigned int nx, const unsigned int i, const unsigned int j)
A useful inline function which replaces the macros used previously.

◆ write_nodal_data() [1/3]

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtualinherited

This method implements writing a mesh with nodal data to a specified file where the nodal data and variable names are provided.

Reimplemented in libMesh::ExodusII_IO, libMesh::Nemesis_IO, libMesh::GmshIO, libMesh::NameBasedIO, libMesh::VTKIO, libMesh::UCDIO, libMesh::GMVIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 109 of file mesh_output.h.

112  { libmesh_not_implemented(); }

◆ write_nodal_data() [2/3]

void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  fname,
const NumericVector< Number > &  parallel_soln,
const std::vector< std::string > &  names 
)
virtualinherited

This method may be overridden by "parallel" output formats for writing nodal data.

Instead of getting a localized copy of the nodal solution vector, it is passed a NumericVector of type=PARALLEL which is in node-major order i.e. (u0,v0,w0, u1,v1,w1, u2,v2,w2, u3,v3,w3, ...) and contains n_nodes*n_vars total entries. Then, it is up to the individual I/O class to extract the required solution values from this vector and write them in parallel.

If not implemented, localizes the parallel vector into a std::vector and calls the other version of this function.

Reimplemented in libMesh::Nemesis_IO.

Definition at line 149 of file mesh_output.C.

References libMesh::NumericVector< T >::localize().

152 {
153  // This is the fallback implementation for parallel I/O formats that
154  // do not yet implement proper writing in parallel, and instead rely
155  // on the full solution vector being available on all processors.
156  std::vector<Number> soln;
157  parallel_soln.localize(soln);
158  this->write_nodal_data(fname, soln, names);
159 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: mesh_output.h:109
virtual void localize(std::vector< T > &v_local) const =0
Creates a copy of the global vector in the local vector v_local.

◆ write_nodal_data() [3/3]

void libMesh::MeshOutput< MeshBase >::write_nodal_data ( const std::string &  fname,
const EquationSystems es,
const std::set< std::string > *  system_names 
)
virtualinherited

This method should be overridden by "parallel" output formats for writing nodal data.

Instead of getting a localized copy of the nodal solution vector, it directly uses EquationSystems current_local_solution vectors to look up nodal values.

If not implemented, reorders the solutions into a nodal-only NumericVector and calls the above version of this function.

Reimplemented in libMesh::Nemesis_IO.

Definition at line 162 of file mesh_output.C.

References libMesh::EquationSystems::build_parallel_solution_vector(), and libMesh::EquationSystems::build_variable_names().

165 {
166  std::vector<std::string> names;
167  es.build_variable_names (names, nullptr, system_names);
168 
169  std::unique_ptr<NumericVector<Number>> parallel_soln =
170  es.build_parallel_solution_vector(system_names);
171 
172  this->write_nodal_data (fname, *parallel_soln, names);
173 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
This method implements writing a mesh with nodal data to a specified file where the nodal data and va...
Definition: mesh_output.h:109

◆ write_nodal_data_discontinuous()

virtual void libMesh::MeshOutput< MeshBase >::write_nodal_data_discontinuous ( const std::string &  ,
const std::vector< Number > &  ,
const std::vector< std::string > &   
)
inlinevirtualinherited

This method implements writing a mesh with discontinuous data to a specified file where the nodal data and variables names are provided.

Reimplemented in libMesh::ExodusII_IO.

Definition at line 118 of file mesh_output.h.

121  { libmesh_not_implemented(); }

◆ write_scalar_ascii()

void libMesh::EnsightIO::write_scalar_ascii ( std::string_view  sys,
std::string_view  var 
)
private

Definition at line 334 of file ensight_io.C.

References _ensight_file_name, _equation_systems, _time_steps, libMesh::System::current_solution(), dim, libMesh::DofMap::dof_indices(), libMesh::System::get_dof_map(), libMesh::EquationSystems::get_system(), libMesh::index_range(), libMesh::libmesh_real(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::FEInterface::nodal_soln(), libMesh::System::variable_number(), and libMesh::System::variable_type().

Referenced by write_solution_ascii().

336 {
337  // Construct scalar variable filename
338  std::ostringstream scl_file;
339  scl_file << _ensight_file_name
340  << "_"
341  << var_name
342  << ".scl"
343  << std::setw(3)
344  << std::setprecision(0)
345  << std::setfill('0')
346  << std::right
347  << _time_steps.size()-1;
348 
349  // Open a stream and start writing scalar variable info.
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";
355 
356  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
357  const unsigned int dim = the_mesh.mesh_dimension();
358  const System & system = _equation_systems.get_system(sys);
359  const DofMap & dof_map = system.get_dof_map();
360  int var = system.variable_number(var_name);
361 
362  std::vector<dof_id_type> dof_indices_scl;
363 
364  // Map from node id -> solution value. We end up just writing this
365  // map out in order, not sure what would happen if there were holes
366  // in the numbering...
367  std::map<int, Real> local_soln;
368 
369  std::vector<Number> elem_soln;
370  std::vector<Number> nodal_soln;
371 
372  // Loop over active local elements, construct the nodal solution, and write it to file.
373  for (const auto & elem : the_mesh.active_local_element_ptr_range())
374  {
375  const FEType & fe_type = system.variable_type(var);
376 
377  dof_map.dof_indices (elem, dof_indices_scl, var);
378 
379  elem_soln.resize(dof_indices_scl.size());
380 
381  for (auto i : index_range(dof_indices_scl))
382  elem_soln[i] = system.current_solution(dof_indices_scl[i]);
383 
384  FEInterface::nodal_soln (dim, fe_type, elem, elem_soln, nodal_soln);
385 
386  libmesh_assert_equal_to (nodal_soln.size(), elem->n_nodes());
387 
388 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
389  libmesh_error_msg("Complex-valued Ensight output not yet supported");
390 #endif
391 
392  for (auto n : elem->node_index_range())
393  local_soln[elem->node_id(n)] = libmesh_real(nodal_soln[n]);
394  }
395 
396  for (const auto & pr : local_soln)
397  scl_stream << std::setw(12)
398  << std::setprecision(5)
399  << std::scientific
400  << pr.second
401  << "\n";
402 }
T libmesh_real(T a)
const MT & mesh() const
Definition: mesh_output.h:259
std::string _ensight_file_name
Definition: ensight_io.h:144
unsigned int dim
const T_sys & get_system(std::string_view name) const
const EquationSystems & _equation_systems
Definition: ensight_io.h:151
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, bool add_p_level=true)
Build the nodal soln from the element soln.
Definition: fe_interface.C:868
std::vector< Real > _time_steps
Definition: ensight_io.h:145
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:111

◆ write_solution_ascii()

void libMesh::EnsightIO::write_solution_ascii ( )
private

Definition at line 318 of file ensight_io.C.

References _system_vars_map, write_scalar_ascii(), and write_vector_ascii().

Referenced by write_ascii().

319 {
320  for (const auto & [sys_name, sys_vars] : _system_vars_map)
321  {
322  for (const auto & scalar : sys_vars.EnsightScalars)
323  this->write_scalar_ascii(sys_name,
324  scalar.scalar_name);
325 
326  for (const auto & vec : sys_vars.EnsightVectors)
327  this->write_vector_ascii(sys_name,
328  vec.components,
329  vec.description);
330  }
331 }
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:148
void write_scalar_ascii(std::string_view sys, std::string_view var)
Definition: ensight_io.C:334
void write_vector_ascii(std::string_view sys, const std::vector< std::string > &vec, std::string_view var_name)
Definition: ensight_io.C:405

◆ write_vector_ascii()

void libMesh::EnsightIO::write_vector_ascii ( std::string_view  sys,
const std::vector< std::string > &  vec,
std::string_view  var_name 
)
private

Definition at line 405 of file ensight_io.C.

References _ensight_file_name, _equation_systems, _time_steps, libMesh::System::current_solution(), dim, libMesh::DofMap::dof_indices(), libMesh::System::get_dof_map(), libMesh::EquationSystems::get_system(), libMesh::index_range(), libMesh::libmesh_real(), libMesh::MeshOutput< MT >::mesh(), libMesh::MeshBase::mesh_dimension(), libMesh::FEInterface::nodal_soln(), libMesh::System::variable_number(), and libMesh::System::variable_type().

Referenced by write_solution_ascii().

408 {
409  // Construct vector variable filename
410  std::ostringstream vec_file;
411  vec_file << _ensight_file_name
412  << "_"
413  << var_name
414  << ".vec"
415  << std::setw(3)
416  << std::setprecision(0)
417  << std::setfill('0')
418  << std::right
419  << _time_steps.size()-1;
420 
421  // Open a stream and start writing vector variable info.
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";
427 
428  // Get a constant reference to the mesh object.
429  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
430 
431  // The dimension that we are running
432  const unsigned int dim = the_mesh.mesh_dimension();
433 
434  const System & system = _equation_systems.get_system(sys);
435 
436  const DofMap & dof_map = system.get_dof_map();
437 
438  const unsigned int u_var = system.variable_number(vec[0]);
439  const unsigned int v_var = system.variable_number(vec[1]);
440  const unsigned int w_var = (dim==3) ? system.variable_number(vec[2]) : 0;
441 
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;
445 
446  // Map from node id -> solution value. We end up just writing this
447  // map out in order, not sure what would happen if there were holes
448  // in the numbering...
449  std::map<int,std::vector<Real>> local_soln;
450 
451  // Now we will loop over all the elements in the mesh.
452  for (const auto & elem : the_mesh.active_local_element_ptr_range())
453  {
454  const FEType & fe_type = system.variable_type(u_var);
455 
456  dof_map.dof_indices (elem, dof_indices_u, u_var);
457  dof_map.dof_indices (elem, dof_indices_v, v_var);
458  if (dim==3)
459  dof_map.dof_indices (elem, dof_indices_w, w_var);
460 
461  std::vector<Number> elem_soln_u;
462  std::vector<Number> elem_soln_v;
463  std::vector<Number> elem_soln_w;
464 
465  std::vector<Number> nodal_soln_u;
466  std::vector<Number> nodal_soln_v;
467  std::vector<Number> nodal_soln_w;
468 
469  elem_soln_u.resize(dof_indices_u.size());
470  elem_soln_v.resize(dof_indices_v.size());
471  if (dim == 3)
472  elem_soln_w.resize(dof_indices_w.size());
473 
474  for (auto i : index_range(dof_indices_u))
475  {
476  elem_soln_u[i] = system.current_solution(dof_indices_u[i]);
477  elem_soln_v[i] = system.current_solution(dof_indices_v[i]);
478  if (dim==3)
479  elem_soln_w[i] = system.current_solution(dof_indices_w[i]);
480  }
481 
482  FEInterface::nodal_soln (dim, fe_type, elem, elem_soln_u, nodal_soln_u);
483  FEInterface::nodal_soln (dim, fe_type, elem, elem_soln_v, nodal_soln_v);
484  if (dim == 3)
485  FEInterface::nodal_soln (dim, fe_type, elem, elem_soln_w, nodal_soln_w);
486 
487  libmesh_assert_equal_to (nodal_soln_u.size(), elem->n_nodes());
488  libmesh_assert_equal_to (nodal_soln_v.size(), elem->n_nodes());
489 
490 #ifdef LIBMESH_ENABLE_COMPLEX
491  libmesh_error_msg("Complex-valued Ensight output not yet supported");
492 #endif
493 
494  for (const auto & n : elem->node_index_range())
495  {
496  std::vector<Real> node_vec(3);
497  node_vec[0] = libmesh_real(nodal_soln_u[n]);
498  node_vec[1] = libmesh_real(nodal_soln_v[n]);
499  node_vec[2] = 0.0;
500  if (dim==3)
501  node_vec[2] = libmesh_real(nodal_soln_w[n]);
502  local_soln[elem->node_id(n)] = node_vec;
503  }
504  }
505 
506  for (unsigned dir=0; dir<3; ++dir)
507  {
508  for (const auto & pr : local_soln)
509  vec_stream << std::setw(12)
510  << std::scientific
511  << std::setprecision(5)
512  << pr.second[dir]
513  << "\n";
514  }
515 }
T libmesh_real(T a)
const MT & mesh() const
Definition: mesh_output.h:259
std::string _ensight_file_name
Definition: ensight_io.h:144
unsigned int dim
const T_sys & get_system(std::string_view name) const
const EquationSystems & _equation_systems
Definition: ensight_io.h:151
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, bool add_p_level=true)
Build the nodal soln from the element soln.
Definition: fe_interface.C:868
std::vector< Real > _time_steps
Definition: ensight_io.h:145
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:111

Member Data Documentation

◆ _element_map

std::map< ElemType, std::string > libMesh::EnsightIO::_element_map = EnsightIO::build_element_map()
staticprivate

Definition at line 154 of file ensight_io.h.

Referenced by write_geometry_ascii().

◆ _ensight_file_name

std::string libMesh::EnsightIO::_ensight_file_name
private

◆ _equation_systems

const EquationSystems& libMesh::EnsightIO::_equation_systems
private

◆ _is_parallel_format

const bool libMesh::MeshOutput< MeshBase >::_is_parallel_format
protectedinherited

Flag specifying whether this format is parallel-capable.

If this is false (default) I/O is only permitted when the mesh has been serialized.

Definition at line 184 of file mesh_output.h.

Referenced by libMesh::FroIO::write(), libMesh::PostscriptIO::write(), and write().

◆ _serial_only_needed_on_proc_0

const bool libMesh::MeshOutput< MeshBase >::_serial_only_needed_on_proc_0
protectedinherited

Flag specifying whether this format can be written by only serializing the mesh to processor zero.

If this is false (default) the mesh will be serialized to all processors

Definition at line 193 of file mesh_output.h.

◆ _system_vars_map

std::map<std::string, SystemVars> libMesh::EnsightIO::_system_vars_map
private

Definition at line 148 of file ensight_io.h.

Referenced by add_scalar(), add_vector(), write_case(), and write_solution_ascii().

◆ _time_steps

std::vector<Real> libMesh::EnsightIO::_time_steps
private

The documentation for this class was generated from the following files: