SundanceMeshReaderBase.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                              Sundance
00005 //                 Copyright (2005) Sandia Corporation
00006 // 
00007 // Copyright (year first published) Sandia Corporation.  Under the terms 
00008 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government 
00009 // retains certain rights in this software.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 //  
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 //                                                                                 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA                                                                                
00025 // Questions? Contact Kevin Long (krlong@sandia.gov), 
00026 // Sandia National Laboratories, Livermore, California, USA
00027 // 
00028 // ************************************************************************
00029 /* @HEADER@ */
00030 
00031 #ifndef SUNDANCE_MESHREADERBASE_H
00032 #define SUNDANCE_MESHREADERBASE_H
00033 
00034 
00035 #include "SundanceDefs.hpp"
00036 #include "SundanceMeshSourceBase.hpp"
00037 #include "Teuchos_StrUtils.hpp"
00038 
00039 namespace Sundance
00040 {
00041 
00042 /**
00043  * MeshReaderBase is a base class for mesh sources that get a mesh
00044  * from a file. It provides several utilities for parsing lines
00045  * from mesh files. 
00046  */
00047 class MeshReaderBase : public MeshSourceBase
00048 {
00049 public:
00050   /** Construct with a filename */
00051   MeshReaderBase(const std::string& filename,
00052     const MeshType& meshType,
00053     int verbosity,
00054     const MPIComm& comm)
00055     : MeshSourceBase(meshType, verbosity, comm), filename_(filename)
00056     {}
00057 
00058   /** Construct from a parameter list */
00059   MeshReaderBase(const ParameterList& params);
00060 
00061   /** */
00062   virtual ~MeshReaderBase(){;}
00063 
00064 protected:
00065   /** access to the filename */
00066   const std::string& filename() const {return filename_;}
00067 
00068   /** convert a std::string to its integer value */
00069   int atoi(const std::string& x) const ;
00070 
00071   /** convert a std::string to its double value */
00072   double atof(const std::string& x) const ;
00073 
00074   /** Determine whether a line is empty */
00075   bool isEmptyLine(const std::string& x) const ;
00076 
00077   /** Open a file "fname" and check for success.
00078    * @param fname name of the file to be opened
00079    * @param description a description of the file, e.g., "node file",
00080    * to be included in any error messages generated.  
00081    **/
00082   RCP<std::ifstream> openFile(const std::string& fname, 
00083     const std::string& description) const ;
00084 
00085   /** 
00086    * Read the next non-empty, non-comment line from a stream
00087    * @param is the stream from which to get the line
00088    * @param line upon return, filled in with the line that was read
00089    * @param tokens array of space-separated tokens in the line
00090    * @param comment a character indicating that everything after it
00091    * is a comment
00092    */
00093   bool getNextLine(std::istream& is, std::string& line,
00094     Array<string>& tokens,
00095     char comment) const ;
00096 private:
00097   std::string filename_;
00098   mutable int nVertexVars_;
00099   mutable Array<double> vertexVars_;
00100 };
00101 }
00102 
00103 
00104 
00105 #endif

Site Contact