libMesh
mesh_output.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 
20 #ifndef LIBMESH_MESH_OUTPUT_H
21 #define LIBMESH_MESH_OUTPUT_H
22 
23 
24 // Local includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/libmesh_logging.h"
27 #include "libmesh/mesh_base.h"
28 #include "libmesh/mesh_serializer.h"
29 
30 // C++ includes
31 #include <cstddef>
32 #include <limits>
33 #include <string>
34 #include <vector>
35 
36 namespace libMesh
37 {
38 
39 // Forward declares
40 class EquationSystems;
41 template <typename T> class NumericVector;
42 
43 
52 template <class MT>
54 {
55 protected:
56 
61  explicit
62  MeshOutput (const bool is_parallel_format = false, const bool serial_only_needed_on_proc_0 = false);
63 
68  explicit
69  MeshOutput (const MT &, const bool is_parallel_format = false, const bool serial_only_needed_on_proc_0 = false);
70 
71 
72 public:
73 
77  virtual ~MeshOutput ();
78 
86  virtual void write (const std::string &) = 0;
87 
92  virtual void write_equation_systems (const std::string &,
93  const EquationSystems &,
94  const std::set<std::string> * system_names=nullptr);
95 
101  virtual void write_discontinuous_equation_systems (const std::string &,
102  const EquationSystems &,
103  const std::set<std::string> * system_names=nullptr);
104 
109  virtual void write_nodal_data (const std::string &,
110  const std::vector<Number> &,
111  const std::vector<std::string> &)
112  { libmesh_not_implemented(); }
113 
118  virtual void write_nodal_data_discontinuous (const std::string &,
119  const std::vector<Number> &,
120  const std::vector<std::string> &)
121  { libmesh_not_implemented(); }
122 
136  virtual void write_nodal_data (const std::string &,
137  const NumericVector<Number> &,
138  const std::vector<std::string> &);
139 
149  virtual void write_nodal_data (const std::string &,
150  const EquationSystems &,
151  const std::set<std::string> *);
152 
160  unsigned int & ascii_precision ();
161 
162 protected:
163 
164 
168  const MT & mesh() const;
169 
170 
176  virtual bool get_add_sides() { return false; }
177 
178 
185 
194 
195 private:
196 
197 
202  const MT * const _obj;
203 
207  unsigned int _ascii_precision;
208 };
209 
210 
211 
212 
213 
214 
215 // ------------------------------------------------------------
216 // MeshOutput inline members
217 template <class MT>
218 inline
219 MeshOutput<MT>::MeshOutput (const bool is_parallel_format, const bool serial_only_needed_on_proc_0) :
220  _is_parallel_format(is_parallel_format),
221  _serial_only_needed_on_proc_0(serial_only_needed_on_proc_0),
222  _obj(nullptr),
223  _ascii_precision (std::numeric_limits<Real>::max_digits10)
224 {}
225 
226 
227 
228 template <class MT>
229 inline
230 MeshOutput<MT>::MeshOutput (const MT & obj, const bool is_parallel_format, const bool serial_only_needed_on_proc_0) :
231  _is_parallel_format(is_parallel_format),
232  _serial_only_needed_on_proc_0(serial_only_needed_on_proc_0),
233  _obj (&obj),
234  _ascii_precision (std::numeric_limits<Real>::max_digits10)
235 {
236  if (!_is_parallel_format && !this->mesh().is_serial())
237  {
238  if (this->mesh().processor_id() == 0)
239  {
240  libmesh_do_once(libMesh::out <<
241  "Warning: This MeshOutput subclass only supports meshes which have been serialized!"
242  << std::endl;);
243  }
244  }
245 }
246 
247 
248 
249 template <class MT>
250 inline
252 {
253 }
254 
255 
256 
257 template <class MT>
258 inline
259 const MT & MeshOutput<MT>::mesh () const
260 {
261  libmesh_assert(_obj);
262  return *_obj;
263 }
264 
265 
266 
267 template <class MT>
268 inline
270 {
271  return _ascii_precision;
272 }
273 
274 
275 } // namespace libMesh
276 
277 
278 #endif // LIBMESH_MESH_OUTPUT_H
const MT & mesh() const
Definition: mesh_output.h:259
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 ~MeshOutput()
Destructor.
Definition: mesh_output.h:251
This is the EquationSystems class.
virtual bool get_add_sides()
Definition: mesh_output.h:176
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
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 ...
Definition: mesh_output.C:31
const MT *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
MeshBase & mesh
unsigned int & ascii_precision()
Return/set the precision to use when writing ASCII files.
Definition: mesh_output.h:269
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.
MeshOutput(const bool is_parallel_format=false, const bool serial_only_needed_on_proc_0=false)
Default constructor.
Definition: mesh_output.h:219
unsigned int _ascii_precision
Precision to use when writing ASCII files.
Definition: mesh_output.h:207
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 t...
Definition: mesh_output.C:89
libmesh_assert(ctx)
virtual void write(const std::string &)=0
This method implements writing a mesh to a specified file.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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