libMesh
mesh_output.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 
82  virtual void write (const std::string &) = 0;
83 
88  virtual void write_equation_systems (const std::string &,
89  const EquationSystems &,
90  const std::set<std::string> * system_names=nullptr);
91 
97  virtual void write_discontinuous_equation_systems (const std::string &,
98  const EquationSystems &,
99  const std::set<std::string> * system_names=nullptr);
100 
105  virtual void write_nodal_data (const std::string &,
106  const std::vector<Number> &,
107  const std::vector<std::string> &)
108  { libmesh_not_implemented(); }
109 
114  virtual void write_nodal_data_discontinuous (const std::string &,
115  const std::vector<Number> &,
116  const std::vector<std::string> &)
117  { libmesh_not_implemented(); }
118 
132  virtual void write_nodal_data (const std::string &,
133  const NumericVector<Number> &,
134  const std::vector<std::string> &);
135 
145  virtual void write_nodal_data (const std::string &,
146  const EquationSystems &,
147  const std::set<std::string> *);
148 
156  unsigned int & ascii_precision ();
157 
158 protected:
159 
160 
164  const MT & mesh() const;
165 
166 
173 
182 
183 private:
184 
185 
190  const MT * const _obj;
191 
195  unsigned int _ascii_precision;
196 };
197 
198 
199 
200 
201 
202 
203 // ------------------------------------------------------------
204 // MeshOutput inline members
205 template <class MT>
206 inline
207 MeshOutput<MT>::MeshOutput (const bool is_parallel_format, const bool serial_only_needed_on_proc_0) :
208  _is_parallel_format(is_parallel_format),
209  _serial_only_needed_on_proc_0(serial_only_needed_on_proc_0),
210  _obj(nullptr),
211  _ascii_precision (std::numeric_limits<Real>::max_digits10)
212 {}
213 
214 
215 
216 template <class MT>
217 inline
218 MeshOutput<MT>::MeshOutput (const MT & obj, const bool is_parallel_format, const bool serial_only_needed_on_proc_0) :
219  _is_parallel_format(is_parallel_format),
220  _serial_only_needed_on_proc_0(serial_only_needed_on_proc_0),
221  _obj (&obj),
222  _ascii_precision (std::numeric_limits<Real>::max_digits10)
223 {
224  if (!_is_parallel_format && !this->mesh().is_serial())
225  {
226  if (this->mesh().processor_id() == 0)
227  {
228  libmesh_do_once(libMesh::out <<
229  "Warning: This MeshOutput subclass only supports meshes which have been serialized!"
230  << std::endl;);
231  }
232  }
233 }
234 
235 
236 
237 template <class MT>
238 inline
240 {
241 }
242 
243 
244 
245 template <class MT>
246 inline
247 const MT & MeshOutput<MT>::mesh () const
248 {
249  libmesh_assert(_obj);
250  return *_obj;
251 }
252 
253 
254 
255 template <class MT>
256 inline
258 {
259  return _ascii_precision;
260 }
261 
262 
263 } // namespace libMesh
264 
265 
266 #endif // LIBMESH_MESH_OUTPUT_H
libMesh::MeshOutput::MeshOutput
MeshOutput(const bool is_parallel_format=false, const bool serial_only_needed_on_proc_0=false)
Default constructor.
Definition: mesh_output.h:207
libMesh::MeshOutput::_serial_only_needed_on_proc_0
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:181
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
mesh
MeshBase & mesh
Definition: mesh_communication.C:1257
libMesh::NumericVector< Number >
libMesh::MeshOutput::ascii_precision
unsigned int & ascii_precision()
Return/set the precision to use when writing ASCII files.
Definition: mesh_output.h:257
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::MeshOutput::_is_parallel_format
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition: mesh_output.h:172
libMesh::EquationSystems
This is the EquationSystems class.
Definition: equation_systems.h:74
libMesh::MeshOutput::write_equation_systems
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
libMesh::MeshOutput::write
virtual void write(const std::string &)=0
This method implements writing a mesh to a specified file.
libMesh::MeshOutput
This class defines an abstract interface for Mesh output.
Definition: mesh_output.h:53
libMesh::MeshOutput::write_nodal_data
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:105
libMesh::MeshOutput::mesh
const MT & mesh() const
Definition: mesh_output.h:247
std
Definition: float128_shims.h:27
libMesh::MeshOutput::write_discontinuous_equation_systems
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:87
libMesh::MeshOutput::write_nodal_data_discontinuous
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:114
libMesh::MeshOutput::_obj
const MT *const _obj
A pointer to a constant object.
Definition: mesh_output.h:190
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::out
OStreamProxy out
libMesh::MeshOutput::~MeshOutput
virtual ~MeshOutput()
Destructor.
Definition: mesh_output.h:239
libMesh::MeshOutput::_ascii_precision
unsigned int _ascii_precision
Precision to use when writing ASCII files.
Definition: mesh_output.h:195