libMesh
ensight_io.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 #ifndef LIBMESH_ENSIGHT_IO_H
20 #define LIBMESH_ENSIGHT_IO_H
21 
22 // libMesh includes
23 #include "libmesh/libmesh.h"
24 #include "libmesh/mesh_base.h"
25 #include "libmesh/mesh_output.h"
26 
27 // C++ includes
28 #include <map>
29 #include <string>
30 #include <vector>
31 
32 namespace libMesh
33 {
34 
35 // Forward declarations
36 class EquationSystems;
37 enum ElemType : int;
38 
47 class EnsightIO : public MeshOutput<MeshBase>
48 {
49 public:
50 
54  EnsightIO (const std::string & filename,
55  const EquationSystems & eq);
56 
60  ~EnsightIO () = default;
61 
69  void add_scalar (const std::string & system,
70  std::string_view scalar_description,
71  std::string_view s);
72 
80  void add_vector (const std::string & system,
81  std::string_view vec_description,
82  std::string u,
83  std::string v);
84 
92  void add_vector (const std::string & system,
93  std::string_view vec_description,
94  std::string u,
95  std::string v,
96  std::string w);
105  void write (Real time = 0);
106 
110  virtual void write (const std::string & name) override;
111 
112 private:
113  // Represents the vectors that are used by the EnsightIO
114  struct Vectors
115  {
116  std::string description;
117  std::vector<std::string> components;
118  };
119 
120  // Represents the scalars
121  struct Scalars
122  {
123  std::string scalar_name;
124  std::string description;
125  };
126 
127  // Store the variables of system
128  struct SystemVars
129  {
130  std::vector<Vectors> EnsightVectors;
131  std::vector<Scalars> EnsightScalars;
132  };
133 
134  // private methods
135  // write solution in ascii format file
136  void write_ascii (Real time = 0);
137  void write_scalar_ascii (std::string_view sys, std::string_view var);
138  void write_vector_ascii (std::string_view sys, const std::vector<std::string> & vec, std::string_view var_name);
139  void write_solution_ascii ();
140  void write_geometry_ascii ();
141  void write_case();
142 
143  // private Attributes
144  std::string _ensight_file_name;
145  std::vector<Real> _time_steps;
146 
147  // mapping from system names to variable names+descriptions
148  std::map <std::string, SystemVars> _system_vars_map;
149 
150  // Reference to the EquationSystems we were constructed with
152 
153  // static mapping between libmesh ElemTypes and Ensight element strings.
154  static std::map<ElemType, std::string> _element_map;
155 
156  // Static function used to build the _element_map.
157  static std::map<ElemType, std::string> build_element_map();
158 };
159 
160 
161 } // namespace libMesh
162 
163 
164 #endif // LIBMESH_ENSIGHT_IO_H
std::string name(const ElemQuality q)
This function returns a string containing some name for q.
Definition: elem_quality.C:42
void write_solution_ascii()
Definition: ensight_io.C:318
ElemType
Defines an enum for geometric element types.
void write_geometry_ascii()
Definition: ensight_io.C:170
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.
Definition: ensight_io.C:82
std::string _ensight_file_name
Definition: ensight_io.h:144
This is the EquationSystems class.
EnsightIO(const std::string &filename, const EquationSystems &eq)
Constructor.
Definition: ensight_io.C:65
static std::map< ElemType, std::string > build_element_map()
Definition: ensight_io.C:45
std::vector< std::string > components
Definition: ensight_io.h:117
std::vector< Scalars > EnsightScalars
Definition: ensight_io.h:131
std::map< std::string, SystemVars > _system_vars_map
Definition: ensight_io.h:148
~EnsightIO()=default
Empty destructor.
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
The libMesh namespace provides an interface to certain functionality in the library.
static std::map< ElemType, std::string > _element_map
Definition: ensight_io.h:154
void write(Real time=0)
Calls write_ascii() and write_case().
Definition: ensight_io.C:152
const EquationSystems & _equation_systems
Definition: ensight_io.h:151
This class implements writing meshes and solutions in Ensight&#39;s Gold format.
Definition: ensight_io.h:47
void write_scalar_ascii(std::string_view sys, std::string_view var)
Definition: ensight_io.C:334
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"...
Definition: ensight_io.C:122
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void write_vector_ascii(std::string_view sys, const std::vector< std::string > &vec, std::string_view var_name)
Definition: ensight_io.C:405
std::vector< Real > _time_steps
Definition: ensight_io.h:145
void write_ascii(Real time=0)
Definition: ensight_io.C:160
void ErrorVector unsigned int
Definition: adjoints_ex3.C:360
std::vector< Vectors > EnsightVectors
Definition: ensight_io.h:130