mesh_output.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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"
27 #include "libmesh/mesh_base.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 
42 
52 // ------------------------------------------------------------
53 // MeshOutput class definition
54 template <class MT>
56 {
57  protected:
58 
63  explicit
64  MeshOutput (const bool is_parallel_format = false);
65 
70  explicit
71  MeshOutput (const MT&, const bool is_parallel_format = false);
72 
73 
74  public:
75 
79  virtual ~MeshOutput ();
80 
84  virtual void write (const std::string&) = 0;
85 
90  virtual void write_equation_systems (const std::string&,
91  const EquationSystems&,
92  const std::set<std::string>* system_names=NULL);
93 
98  virtual void write_nodal_data (const std::string&,
99  const std::vector<Number>&,
100  const std::vector<std::string>&)
101  { libmesh_error(); }
102 
110  unsigned int & ascii_precision ();
111 
112  protected:
113 
114 
118  const MT& mesh() const;
119 
120 
127 
128 
129  private:
130 
131 
136  const MT* const _obj;
137 
141  unsigned int _ascii_precision;
142 
150  std::vector<Number>& soln,
151  std::vector<std::string>& names,
152  const std::set<std::string>* system_names=NULL);
153 };
154 
155 
156 
157 
158 
159 
160 // ------------------------------------------------------------
161 // MeshOutput inline members
162 template <class MT>
163 inline
164 MeshOutput<MT>::MeshOutput (const bool is_parallel_format) :
165  _is_parallel_format(is_parallel_format),
166  _obj(NULL),
167  _ascii_precision (std::numeric_limits<Real>::digits10 + 2)
168 {}
169 
170 
171 
172 template <class MT>
173 inline
174 MeshOutput<MT>::MeshOutput (const MT& obj, const bool is_parallel_format) :
175  _is_parallel_format(is_parallel_format),
176  _obj (&obj),
177  _ascii_precision (std::numeric_limits<Real>::digits10 + 2)
178 {
179  if (!_is_parallel_format && !this->mesh().is_serial())
180  {
181  if (this->mesh().processor_id() == 0)
182  {
183  libmesh_do_once(libMesh::out <<
184  "Warning: This MeshOutput subclass only supports meshes which have been serialized!"
185  << std::endl;);
186  }
187 // libmesh_error();
188  }
189 }
190 
191 
192 
193 template <class MT>
194 inline
196 {
197 }
198 
199 
200 
201 template <class MT>
202 inline
203 void MeshOutput<MT>::write_equation_systems (const std::string& fname,
204  const EquationSystems& es,
205  const std::set<std::string>* system_names)
206 {
207  START_LOG("write_equation_systems()", "MeshOutput");
208 
209  // We may need to gather and/or renumber a ParallelMesh to output
210  // it, making that const qualifier in our constructor a dirty lie
211  MT& my_mesh = const_cast<MT&>(*_obj);
212 
213  // A non-renumbered mesh may not have a contiguous numbering, and
214  // that needs to be fixed before we can build a solution vector.
215  if (my_mesh.max_elem_id() != my_mesh.n_elem() ||
216  my_mesh.max_node_id() != my_mesh.n_nodes())
217  {
218  // If we were allowed to renumber then we should have already
219  // been properly renumbered...
220  libmesh_assert(!my_mesh.allow_renumbering());
221 
222  libmesh_do_once(libMesh::out <<
223  "Warning: This MeshOutput subclass only supports meshes which are contiguously renumbered!"
224  << std::endl;);
225 
226  my_mesh.allow_renumbering(true);
227 
228  my_mesh.renumber_nodes_and_elements();
229 
230  // Not sure what good going back to false will do here, the
231  // renumbering horses have already left the barn...
232  my_mesh.allow_renumbering(false);
233  }
234 
235  MeshSerializer serialize(const_cast<MT&>(*_obj), !_is_parallel_format);
236 
237  // Build the nodal solution values & get the variable
238  // names from the EquationSystems object
239  std::vector<Number> soln;
240  std::vector<std::string> names;
241 
242  this->_build_variable_names_and_solution_vector(es, soln, names, system_names);
243  //es.build_variable_names (names);
244  //es.build_solution_vector (soln);
245 
246  this->write_nodal_data (fname, soln, names);
247 
248  STOP_LOG("write_equation_systems()", "MeshOutput");
249 }
250 
251 
252 
253 template <class MT>
254 inline
255 const MT& MeshOutput<MT>::mesh () const
256 {
257  libmesh_assert(_obj);
258  return *_obj;
259 }
260 
261 
262 
263 template <class MT>
264 inline
266 {
267  return _ascii_precision;
268 }
269 
270 
271 } // namespace libMesh
272 
273 
274 #endif // LIBMESH_MESH_OUTPUT_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo