$extrastylesheet
mesh_input.h
Go to the documentation of this file.
00001 // The libMesh Finite Element Library.
00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00003 
00004 // This library is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public
00006 // License as published by the Free Software Foundation; either
00007 // version 2.1 of the License, or (at your option) any later version.
00008 
00009 // This library is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 // Lesser General Public License for more details.
00013 
00014 // You should have received a copy of the GNU Lesser General Public
00015 // License along with this library; if not, write to the Free Software
00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017 
00018 
00019 
00020 #ifndef LIBMESH_MESH_INPUT_H
00021 #define LIBMESH_MESH_INPUT_H
00022 
00023 
00024 // Local includes
00025 #include "libmesh/libmesh_common.h"
00026 #include "libmesh/mesh_base.h"
00027 
00028 // C++ includes
00029 #include <cstddef>
00030 #include <istream>
00031 #include <string>
00032 #include <vector>
00033 
00034 namespace libMesh
00035 {
00036 
00037 
00038 
00048 // ------------------------------------------------------------
00049 // MeshInput class definition
00050 template <class MT>
00051 class MeshInput
00052 {
00053 protected:
00054 
00059   explicit
00060   MeshInput (bool is_parallel_format = false);
00061 
00066   explicit
00067   MeshInput (MT&, const bool is_parallel_format = false);
00068 
00069 public:
00070 
00074   virtual ~MeshInput ();
00075 
00079   virtual void read (const std::string&) = 0;
00080 
00081 
00082 protected:
00083 
00087   MT& mesh ();
00088 
00094   void set_n_partitions (unsigned int n_parts) { this->mesh().set_n_partitions() = n_parts; }
00095 
00100   std::vector<bool> elems_of_dimension;
00101 
00106   void skip_comment_lines (std::istream& in,
00107                            const char comment_start);
00108 
00109 
00110 private:
00111 
00112 
00117   MT* _obj;
00118 
00124   const bool _is_parallel_format;
00125 };
00126 
00127 
00128 
00129 // ------------------------------------------------------------
00130 // MeshInput inline members
00131 template <class MT>
00132 inline
00133 MeshInput<MT>::MeshInput (const bool is_parallel_format) :
00134   elems_of_dimension(),
00135   _obj (NULL),
00136   _is_parallel_format(is_parallel_format)
00137 {
00138 }
00139 
00140 
00141 
00142 template <class MT>
00143 inline
00144 MeshInput<MT>::MeshInput (MT& obj, const bool is_parallel_format) :
00145   elems_of_dimension(),
00146   _obj (&obj),
00147   _is_parallel_format(is_parallel_format)
00148 {
00149   if (!_is_parallel_format && !this->mesh().is_serial())
00150     {
00151       if (this->mesh().processor_id() == 0)
00152         {
00153           libmesh_do_once(libMesh::out <<
00154                           "Warning:  This MeshOutput subclass only supports meshes which have been serialized!"
00155                           << std::endl;);
00156         }
00157     }
00158 }
00159 
00160 
00161 
00162 template <class MT>
00163 inline
00164 MeshInput<MT>::~MeshInput ()
00165 {
00166 }
00167 
00168 
00169 
00170 template <class MT>
00171 inline
00172 MT& MeshInput<MT>::mesh ()
00173 {
00174   if (_obj == NULL)
00175     libmesh_error_msg("ERROR: _obj should not be NULL!");
00176   return *_obj;
00177 }
00178 
00179 
00180 
00181 template <class MT>
00182 void MeshInput<MT>::skip_comment_lines (std::istream &in,
00183                                         const char comment_start)
00184 {
00185   char c, line[256];
00186 
00187   while (in.get(c), c==comment_start)
00188     in.getline (line, 255);
00189 
00190   // put back first character of
00191   // first non-comment line
00192   in.putback (c);
00193 }
00194 
00195 
00196 } // namespace libMesh
00197 
00198 
00199 #endif // LIBMESH_MESH_INPUT_H