libMesh
mesh_output.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 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=libmesh_nullptr);
91 
96  virtual void write_nodal_data (const std::string &,
97  const std::vector<Number> &,
98  const std::vector<std::string> &)
99  { libmesh_not_implemented(); }
100 
114  virtual void write_nodal_data (const std::string &,
115  const NumericVector<Number> &,
116  const std::vector<std::string> &);
117 
125  unsigned int & ascii_precision ();
126 
127 protected:
128 
129 
133  const MT & mesh() const;
134 
135 
142 
151 
152 private:
153 
154 
159  const MT * const _obj;
160 
164  unsigned int _ascii_precision;
165 };
166 
167 
168 
169 
170 
171 
172 // ------------------------------------------------------------
173 // MeshOutput inline members
174 template <class MT>
175 inline
176 MeshOutput<MT>::MeshOutput (const bool is_parallel_format, const bool serial_only_needed_on_proc_0) :
177  _is_parallel_format(is_parallel_format),
178  _serial_only_needed_on_proc_0(serial_only_needed_on_proc_0),
180  _ascii_precision (std::numeric_limits<Real>::digits10 + 2)
181 {}
182 
183 
184 
185 template <class MT>
186 inline
187 MeshOutput<MT>::MeshOutput (const MT & obj, const bool is_parallel_format, const bool serial_only_needed_on_proc_0) :
188  _is_parallel_format(is_parallel_format),
189  _serial_only_needed_on_proc_0(serial_only_needed_on_proc_0),
190  _obj (&obj),
191  _ascii_precision (std::numeric_limits<Real>::digits10 + 2)
192 {
193  if (!_is_parallel_format && !this->mesh().is_serial())
194  {
195  if (this->mesh().processor_id() == 0)
196  {
197  libmesh_do_once(libMesh::out <<
198  "Warning: This MeshOutput subclass only supports meshes which have been serialized!"
199  << std::endl;);
200  }
201  }
202 }
203 
204 
205 
206 template <class MT>
207 inline
209 {
210 }
211 
212 
213 
214 template <class MT>
215 inline
216 const MT & MeshOutput<MT>::mesh () const
217 {
219  return *_obj;
220 }
221 
222 
223 
224 template <class MT>
225 inline
227 {
228  return _ascii_precision;
229 }
230 
231 
232 } // namespace libMesh
233 
234 
235 #endif // LIBMESH_MESH_OUTPUT_H
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:96
virtual ~MeshOutput()
Destructor.
Definition: mesh_output.h:208
This is the EquationSystems class.
const MT *const _obj
A pointer to a constant object.
Definition: mesh_output.h:159
const bool _is_parallel_format
Flag specifying whether this format is parallel-capable.
Definition: mesh_output.h:141
const class libmesh_nullptr_t libmesh_nullptr
unsigned int & ascii_precision()
Return/set the precision to use when writing ASCII files.
Definition: mesh_output.h:226
const MT & mesh() const
Definition: mesh_output.h:216
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:176
libmesh_assert(j)
unsigned int _ascii_precision
Precision to use when writing ASCII files.
Definition: mesh_output.h:164
virtual void write(const std::string &)=0
This method implements writing a mesh to a specified file.
virtual void write_equation_systems(const std::string &, const EquationSystems &, const std::set< std::string > *system_names=libmesh_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
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:150
processor_id_type processor_id()
Definition: libmesh_base.h:96