mesh_input.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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_INPUT_H
21 #define LIBMESH_MESH_INPUT_H
22 
23 
24 // Local includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/mesh_base.h"
27 
28 // C++ includes
29 #include <cstddef>
30 #include <istream>
31 #include <string>
32 #include <vector>
33 
34 namespace libMesh
35 {
36 
37 
38 
47 template <class MT>
48 class MeshInput
49 {
50 protected:
51 
56  explicit
57  MeshInput (bool is_parallel_format = false);
58 
63  explicit
64  MeshInput (MT &, const bool is_parallel_format = false);
65 
66 public:
67 
71  virtual ~MeshInput ();
72 
76  virtual void read (const std::string &) = 0;
77 
78 
79 protected:
80 
84  MT & mesh ();
85 
91  void set_n_partitions (unsigned int n_parts) { this->mesh().set_n_partitions() = n_parts; }
92 
97  std::vector<bool> elems_of_dimension;
98 
103  void skip_comment_lines (std::istream & in,
104  const char comment_start);
105 
106 
107 private:
108 
109 
114  MT * _obj;
115 
122 };
123 
124 
125 
126 // ------------------------------------------------------------
127 // MeshInput inline members
128 template <class MT>
129 inline
130 MeshInput<MT>::MeshInput (const bool is_parallel_format) :
131  elems_of_dimension(),
132  _obj (nullptr),
133  _is_parallel_format(is_parallel_format)
134 {
135 }
136 
137 
138 
139 template <class MT>
140 inline
141 MeshInput<MT>::MeshInput (MT & obj, const bool is_parallel_format) :
142  elems_of_dimension(),
143  _obj (&obj),
144  _is_parallel_format(is_parallel_format)
145 {
146  if (!_is_parallel_format && !this->mesh().is_serial())
147  {
148  if (this->mesh().processor_id() == 0)
149  {
150  libmesh_do_once(libMesh::out <<
151  "Warning: This MeshOutput subclass only supports meshes which have been serialized!"
152  << std::endl;);
153  }
154  }
155 }
156 
157 
158 
159 template <class MT>
160 inline
162 {
163 }
164 
165 
166 
167 template <class MT>
168 inline
170 {
171  if (_obj == nullptr)
172  libmesh_error_msg("ERROR: _obj should not be nullptr!");
173  return *_obj;
174 }
175 
176 
177 
178 template <class MT>
179 void MeshInput<MT>::skip_comment_lines (std::istream & in,
180  const char comment_start)
181 {
182  char c, line[256];
183 
184  while (in.get(c), c==comment_start)
185  in.getline (line, 255);
186 
187  // put back first character of
188  // first non-comment line
189  in.putback (c);
190 }
191 
192 
193 } // namespace libMesh
194 
195 
196 #endif // LIBMESH_MESH_INPUT_H
const bool _is_parallel_format
Definition: mesh_input.h:121
std::vector< bool > elems_of_dimension
Definition: mesh_input.h:97
MeshBase & mesh
void skip_comment_lines(std::istream &in, const char comment_start)
Definition: mesh_input.h:179
virtual void read(const std::string &)=0
MeshInput(bool is_parallel_format=false)
Definition: mesh_input.h:130
void set_n_partitions(unsigned int n_parts)
Definition: mesh_input.h:91
virtual ~MeshInput()
Definition: mesh_input.h:161
OStreamProxy out(std::cout)