libMesh::EnsightIO Class Reference

#include <ensight_io.h>

Inheritance diagram for libMesh::EnsightIO:

Classes

struct  Scalars
 
struct  SystemVars
 
struct  Vectors
 

Public Member Functions

 EnsightIO (const std::string &filename, const EquationSystems &eq)
 
 ~EnsightIO ()
 
void add_scalar (const std::string &system, const std::string &scalar_description, const std::string &s)
 
void add_vector (const std::string &system, const std::string &vec_description, const std::string &u, const std::string &v)
 
void add_vector (const std::string &system, const std::string &vec_description, const std::string &u, const std::string &v, const std::string &w)
 
void write (Real time=0)
 
virtual void write (const std::string &name) override
 
virtual void write_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 
virtual void write_discontinuous_equation_systems (const std::string &, const EquationSystems &, const std::set< std::string > *system_names=nullptr)
 
virtual void write_nodal_data (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 
virtual void write_nodal_data (const std::string &, const NumericVector< Number > &, const std::vector< std::string > &)
 
virtual void write_nodal_data_discontinuous (const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
 
unsigned int & ascii_precision ()
 

Protected Member Functions

const MeshBasemesh () const
 

Protected Attributes

const bool _is_parallel_format
 
const bool _serial_only_needed_on_proc_0
 

Private Member Functions

void write_ascii (Real time=0)
 
void write_scalar_ascii (const std::string &sys, const std::string &var)
 
void write_vector_ascii (const std::string &sys, const std::vector< std::string > &vec, const std::string &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 55 of file ensight_io.h.

Constructor & Destructor Documentation

◆ EnsightIO()

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

Constructor.

Definition at line 64 of file ensight_io.C.

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

65  :
66  MeshOutput<MeshBase> (eq.get_mesh()),
68 {
70  _ensight_file_name = filename;
71  else
72  {
73  std::ostringstream tmp_file;
74  tmp_file << filename << "_rank" << _equation_systems.processor_id();
75  _ensight_file_name = tmp_file.str();
76  }
77 }
std::string _ensight_file_name
Definition: ensight_io.h:152
PetscBool eq
processor_id_type n_processors() const
const EquationSystems & _equation_systems
Definition: ensight_io.h:159
processor_id_type processor_id() const

◆ ~EnsightIO()

libMesh::EnsightIO::~EnsightIO ( )
inline

Empty destructor.

Definition at line 68 of file ensight_io.h.

68 {}

Member Function Documentation

◆ add_scalar()

void libMesh::EnsightIO::add_scalar ( const std::string &  system,
const std::string &  scalar_description,
const std::string &  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 121 of file ensight_io.C.

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

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

◆ add_vector() [1/2]

void libMesh::EnsightIO::add_vector ( const std::string &  system,
const std::string &  vec_description,
const std::string &  u,
const 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 81 of file ensight_io.C.

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

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

◆ add_vector() [2/2]

void libMesh::EnsightIO::add_vector ( const std::string &  system,
const std::string &  vec_description,
const std::string &  u,
const std::string &  v,
const 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 100 of file ensight_io.C.

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

105 {
106  libmesh_assert(_equation_systems.has_system(system_name));
107  libmesh_assert(_equation_systems.get_system(system_name).has_variable(u));
108  libmesh_assert(_equation_systems.get_system(system_name).has_variable(v));
109  libmesh_assert(_equation_systems.get_system(system_name).has_variable(w));
110 
111  Vectors vec;
112  vec.description = vec_name;
113  vec.components.push_back(u);
114  vec.components.push_back(v);
115  vec.components.push_back(w);
116  _system_vars_map[system_name].EnsightVectors.push_back(vec);
117 }
const T_sys & get_system(const std::string &name) const
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:156
const EquationSystems & _equation_systems
Definition: ensight_io.h:159
bool has_system(const std::string &name) const

◆ 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>::digits10 + 2, which should be enough to write out to ASCII and get the exact same Real back when reading in.

Definition at line 244 of file mesh_output.h.

Referenced by libMesh::TecplotIO::write_ascii(), libMesh::GMVIO::write_ascii_new_impl(), and libMesh::GMVIO::write_ascii_old_impl().

245 {
246  return _ascii_precision;
247 }

◆ build_element_map()

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

Definition at line 44 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.

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

◆ mesh()

◆ 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 151 of file ensight_io.C.

References write_ascii(), and write_case().

Referenced by write().

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

◆ write() [2/2]

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

Calls this->write(0);

Implements libMesh::MeshOutput< MeshBase >.

Definition at line 139 of file ensight_io.C.

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

140 {
141  // We may need to gather a DistributedMesh to output it, making that
142  // const qualifier in our constructor a dirty lie
143  MeshSerializer serialize(const_cast<MeshBase &>(this->mesh()), !_is_parallel_format);
144 
146  this->write();
147 }
std::string name(const ElemQuality q)
Definition: elem_quality.C:42
const MeshBase & mesh() const
Definition: mesh_output.h:234
std::string _ensight_file_name
Definition: ensight_io.h:152
void write(Real time=0)
Definition: ensight_io.C:151

◆ write_ascii()

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

Definition at line 159 of file ensight_io.C.

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

Referenced by write().

160 {
161  _time_steps.push_back(time);
162 
163  this->write_geometry_ascii();
164  this->write_solution_ascii();
165 }
void write_solution_ascii()
Definition: ensight_io.C:321
void write_geometry_ascii()
Definition: ensight_io.C:169
std::vector< Real > _time_steps
Definition: ensight_io.h:153

◆ write_case()

void libMesh::EnsightIO::write_case ( )
private

Definition at line 275 of file ensight_io.C.

References _ensight_file_name, _system_vars_map, and _time_steps.

Referenced by write().

276 {
277  std::ostringstream case_file;
278  case_file << _ensight_file_name << ".case";
279 
280  // Open a stream for writing the case file.
281  std::ofstream case_stream(case_file.str().c_str());
282 
283  case_stream << "FORMAT\n";
284  case_stream << "type: ensight gold\n\n";
285  case_stream << "GEOMETRY\n";
286  case_stream << "model: 1 " << _ensight_file_name << ".geo" << "***\n";
287 
288  // Write Variable per node section
289  if (!_system_vars_map.empty())
290  case_stream << "\n\nVARIABLE\n";
291 
292  for (const auto & pr : _system_vars_map)
293  {
294  for (const auto & scalar : pr.second.EnsightScalars)
295  case_stream << "scalar per node: 1 "
296  << scalar.description << " "
297  << _ensight_file_name << "_" << scalar.scalar_name << ".scl***\n";
298 
299  for (const auto & vec : pr.second.EnsightVectors)
300  case_stream << "vector per node: 1 "
301  << vec.description << " "
302  << _ensight_file_name << "_" << vec.description << ".vec***\n";
303 
304  // Write time step section
305  if (_time_steps.size() != 0)
306  {
307  case_stream << "\n\nTIME\n";
308  case_stream << "time set: 1\n";
309  case_stream << "number of steps: " << std::setw(10) << _time_steps.size() << "\n";
310  case_stream << "filename start number: " << std::setw(10) << 0 << "\n";
311  case_stream << "filename increment: " << std::setw(10) << 1 << "\n";
312  case_stream << "time values:\n";
313  for (const auto & time : _time_steps)
314  case_stream << std::setw(12) << std::setprecision(5) << std::scientific << time << "\n";
315  }
316  }
317 }
std::string _ensight_file_name
Definition: ensight_io.h:152
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:156
std::vector< Real > _time_steps
Definition: ensight_io.h:153

◆ 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 92 of file mesh_output.C.

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

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

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

◆ 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_parallel_solution_vector(), libMesh::EquationSystems::build_solution_vector(), libMesh::EquationSystems::build_variable_names(), libMesh::EquationSystems::get_mesh(), 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-renumbered mesh may not have a contiguous numbering, and
46  // that needs to be fixed before we can build a solution vector.
47  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
48  my_mesh.max_node_id() != my_mesh.n_nodes())
49  {
50  // If we were allowed to renumber then we should have already
51  // been properly renumbered...
52  libmesh_assert(!my_mesh.allow_renumbering());
53 
54  libmesh_do_once(libMesh::out <<
55  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
56  << std::endl;);
57 
58  my_mesh.allow_renumbering(true);
59 
60  my_mesh.renumber_nodes_and_elements();
61 
62  // Not sure what good going back to false will do here, the
63  // renumbering horses have already left the barn...
64  my_mesh.allow_renumbering(false);
65  }
66 
67  MeshSerializer serialize(const_cast<MT &>(*_obj), !_is_parallel_format, _serial_only_needed_on_proc_0);
68 
69  // Build the list of variable names that will be written.
70  std::vector<std::string> names;
71  es.build_variable_names (names, nullptr, system_names);
72 
74  {
75  // Build the nodal solution values & get the variable
76  // names from the EquationSystems object
77  std::vector<Number> soln;
78  es.build_solution_vector (soln, system_names);
79 
80  this->write_nodal_data (fname, soln, names);
81  }
82  else // _is_parallel_format
83  {
84  std::unique_ptr<NumericVector<Number>> parallel_soln =
85  es.build_parallel_solution_vector(system_names);
86 
87  this->write_nodal_data (fname, *parallel_soln, names);
88  }
89 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:105
const MeshBase *const _obj
Definition: mesh_output.h:177
OStreamProxy out(std::cout)

◆ write_geometry_ascii()

void libMesh::EnsightIO::write_geometry_ascii ( )
private

Definition at line 169 of file ensight_io.C.

References _element_map, _ensight_file_name, _time_steps, libMesh::MeshBase::active_local_element_ptr_range(), libMesh::HEX27, libMesh::index_range(), libMesh::MeshOutput< MT >::mesh(), and libMesh::QUAD9.

Referenced by write_ascii().

170 {
171  std::ostringstream file;
172  file << _ensight_file_name
173  << ".geo"
174  << std::setw(3)
175  << std::setprecision(0)
176  << std::setfill('0')
177  << std::right
178  << _time_steps.size()-1;
179 
180  // Open a stream to write the mesh
181  std::ofstream mesh_stream(file.str().c_str());
182 
183  mesh_stream << "EnSight Gold Geometry File Format\n";
184  mesh_stream << "Generated by \n";
185  mesh_stream << "node id off\n";
186  mesh_stream << "element id given\n";
187  mesh_stream << "part\n";
188  mesh_stream << std::setw(10) << 1 << "\n";
189  mesh_stream << "uns-elements\n";
190  mesh_stream << "coordinates\n";
191 
192  // mapping between nodal index and your coordinates
193  std::map<int, Point> mesh_nodes_map;
194 
195  // Map for grouping elements of the same type
196  std::map<ElemType, std::vector<const Elem *>> ensight_parts_map;
197 
198  const MeshBase & the_mesh = MeshOutput<MeshBase>::mesh();
199 
200  // Construct the various required maps
201  for (const auto & elem : the_mesh.active_local_element_ptr_range())
202  {
203  ensight_parts_map[elem->type()].push_back(elem);
204 
205  for (unsigned int i = 0; i < elem->n_nodes(); i++)
206  mesh_nodes_map[elem->node_id(i)] = elem->point(i);
207  }
208 
209  // Write number of local points
210  mesh_stream << std::setw(10) << mesh_nodes_map.size() << "\n";
211 
212  // write x, y, and z node positions, build mapping between
213  // ensight and libmesh node numbers.
214  std::map <int, int> ensight_node_index;
215  for (unsigned direction=0; direction<3; ++direction)
216  {
217  int i = 1;
218  for (const auto & pr : mesh_nodes_map)
219  {
220  mesh_stream << std::setw(12)
221  << std::setprecision(5)
222  << std::scientific
223  << pr.second(direction)
224  << "\n";
225  ensight_node_index[pr.first] = i++;
226  }
227  }
228 
229  // Write parts
230  for (const auto & pr : ensight_parts_map)
231  {
232  // Look up this ElemType in the map, error if not present.
233  auto name_it = _element_map.find(pr.first);
234  if (name_it == _element_map.end())
235  libmesh_error_msg("Error: Unsupported ElemType " << pr.first << " for EnsightIO.");
236 
237  // Write element type
238  mesh_stream << "\n" << name_it->second << "\n";
239 
240  const std::vector<const Elem *> & elem_ref = pr.second;
241 
242  // Write number of element
243  mesh_stream << std::setw(10) << elem_ref.size() << "\n";
244 
245  // Write element id
246  for (const auto & elem : elem_ref)
247  mesh_stream << std::setw(10) << elem->id() << "\n";
248 
249  // Write connectivity
250  for (auto i : index_range(elem_ref))
251  {
252  for (const auto & node : elem_ref[i]->node_ref_range())
253  {
254  // tests!
255  if (pr.first == QUAD9 && i==4)
256  continue;
257 
258  // tests!
259  if (pr.first == HEX27 &&
260  (i==4 || i ==10 || i == 12 ||
261  i == 13 || i ==14 || i == 16 || i == 22))
262  continue;
263 
264  mesh_stream << std::setw(10) << ensight_node_index[node.id()];
265  }
266  mesh_stream << "\n";
267  }
268  }
269 }
const MT & mesh() const
Definition: mesh_output.h:234
std::string _ensight_file_name
Definition: ensight_io.h:152
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Definition: int_range.h:104
static std::map< ElemType, std::string > _element_map
Definition: ensight_io.h:162
std::vector< Real > _time_steps
Definition: ensight_io.h:153

◆ write_nodal_data() [1/2]

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::UCDIO, libMesh::NameBasedIO, libMesh::GmshIO, libMesh::GMVIO, libMesh::VTKIO, libMesh::MEDITIO, libMesh::GnuPlotIO, and libMesh::TecplotIO.

Definition at line 105 of file mesh_output.h.

108  { libmesh_not_implemented(); }

◆ write_nodal_data() [2/2]

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 should 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 150 of file mesh_output.C.

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

153 {
154  // This is the fallback implementation for parallel I/O formats that
155  // do not yet implement proper writing in parallel, and instead rely
156  // on the full solution vector being available on all processors.
157  std::vector<Number> soln;
158  parallel_soln.localize(soln);
159  this->write_nodal_data(fname, soln, names);
160 }
virtual void write_nodal_data(const std::string &, const std::vector< Number > &, const std::vector< std::string > &)
Definition: mesh_output.h:105
virtual void localize(std::vector< T > &v_local) const =0

◆ 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 114 of file mesh_output.h.

117  { libmesh_not_implemented(); }

◆ write_scalar_ascii()

void libMesh::EnsightIO::write_scalar_ascii ( const std::string &  sys,
const std::string &  var 
)
private

Definition at line 337 of file ensight_io.C.

References _ensight_file_name, _equation_systems, _time_steps, libMesh::MeshBase::active_local_element_ptr_range(), libMesh::System::current_solution(), 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().

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

◆ write_solution_ascii()

void libMesh::EnsightIO::write_solution_ascii ( )
private

Definition at line 321 of file ensight_io.C.

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

Referenced by write_ascii().

322 {
323  for (const auto & pr : _system_vars_map)
324  {
325  for (const auto & scalar : pr.second.EnsightScalars)
326  this->write_scalar_ascii(pr.first,
327  scalar.scalar_name);
328 
329  for (const auto & vec : pr.second.EnsightVectors)
330  this->write_vector_ascii(pr.first,
331  vec.components,
332  vec.description);
333  }
334 }
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:156
void write_scalar_ascii(const std::string &sys, const std::string &var)
Definition: ensight_io.C:337
void write_vector_ascii(const std::string &sys, const std::vector< std::string > &vec, const std::string &var_name)
Definition: ensight_io.C:408

◆ write_vector_ascii()

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

Definition at line 408 of file ensight_io.C.

References _ensight_file_name, _equation_systems, _time_steps, libMesh::MeshBase::active_local_element_ptr_range(), libMesh::System::current_solution(), 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().

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

Member Data Documentation

◆ _element_map

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

Definition at line 162 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 159 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 168 of file mesh_output.h.

◆ _system_vars_map

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

Definition at line 156 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: