SundanceTriangleMeshReader.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_TRIANGLEMESHREADER_H
00032 #define SUNDANCE_TRIANGLEMESHREADER_H
00033 
00034 #include "SundanceDefs.hpp"
00035 #include "SundanceMeshReaderBase.hpp"
00036 
00037 namespace Sundance
00038 {
00039   using namespace Teuchos;
00040   
00041   /**
00042    * TriangleMeshReader reads a mesh stored in Shewchuk's Triangle format.
00043    * This format is documented at 
00044    * <A HREF="http://www-2.cs.cmu.edu/~quake/triangle.html"> 
00045    * the Triangle homepage. 
00046    * </A>
00047    * This reader expects to find node information in <tt>.node</tt> files
00048    * and element information in <tt>.ele</tt> files. The <tt> filename </tt>
00049    * constructor argument is the stem of the filenames, and so that 
00050    * a reader constructed with filename <tt>joe</tt> will look for node and
00051    * element data in <tt>joe.node</tt> and <tt>joe.ele</tt> respectively.
00052    * Node and element
00053    * attributes are read if present, and can be accessed with the 
00054    * <tt>getAttributes()</tt> method of <tt>MeshSource.</tt>
00055    * 
00056    * <h4> Parallel extensions </h4>
00057    * We have extended the Triangle format to deal with distributed meshes.
00058    * A TriangleMeshReader is constructed with an MPIComm object, and if
00059    * that communicator has more than one processor the mesh is assumed
00060    * to be split into files, one for each processor. Data
00061    * on mesh "joe" for the <i>nnn</i>-th processor will be found in the files
00062    * <ul>
00063    * <li> <tt>joe.node.</tt><i>nnn</i>
00064    * <li> <tt>joe.ele.</tt><i>nnn</i>
00065    * <li> <tt>joe.par.</tt><i>nnn</i>
00066    * </ul>
00067    * The <tt>.node.</tt><i>nnn</i> and <tt>.ele.</tt><i>nnn</i> files contain the
00068    * node and element data for the part of the mesh seen 
00069    * by the <i>nnn</i>-th
00070    * processor. The node and element 
00071    * numberings given in those two files are <b>local</b> indexes.
00072    * The <tt>.par.</tt><i>nnn</i> contains node and element 
00073    * ownership information for the part of the mesh seen 
00074    * by the <i>nnn</i>-th
00075    * processor. 
00076    *
00077    * <br> 
00078    *
00079    * A <tt>.par</tt> file is formatted as follows:
00080    * <ul>
00081    * <li> First line: <tt> rank numProcs </tt>
00082    * <li> Second line: <tt> numPoints </tt>
00083    * <li> Next <i> nPoints </i> lines: <tt> ptLID ptGID ptOwnerRank </tt>
00084    * <li> Next line: <tt> numElems </tt>
00085    * <li> Next <i> nElems </i> lines: <tt> elemLID elemGID elemOwnerRank </tt>
00086    * </ul>
00087    * 
00088    */
00089   class TriangleMeshReader : public MeshReaderBase
00090   {
00091   public:
00092     /** */
00093     TriangleMeshReader(const std::string& filename, 
00094                        const MeshType& meshType,
00095                        const MPIComm& comm = MPIComm::world());
00096 
00097     /** Construct from a ParameterList */
00098     TriangleMeshReader(const ParameterList& params);
00099 
00100     /** virtual dtor */
00101     virtual ~TriangleMeshReader(){;}
00102 
00103 
00104     /** Create a mesh */
00105     virtual Mesh fillMesh() const ;
00106 
00107     /** Print a short descriptive std::string */
00108     virtual std::string description() const 
00109     {return "TriangleMeshReader[file=" + filename() + "]";}
00110       
00111 
00112     /** Return a ref count pointer to self */
00113     virtual RCP<MeshSourceBase> getRcp() {return rcp(this);}
00114 
00115   private:
00116     /** */
00117     void readParallelInfo(Array<int>& ptGID, Array<int>& ptOwner,
00118                           Array<int>& elemGID, Array<int>& elemOwner) const ;
00119 
00120     /** */
00121     Mesh readNodes(Array<int>& ptGID,
00122                    Array<int>& ptOwner) const ;
00123 
00124     void readSides(Mesh& mesh) const ;
00125 
00126     /** */
00127     void readElems(Mesh& mesh,
00128                    const Array<int>& nodeGID,
00129                    Array<int>& elemGID,
00130                    Array<int>& elemOwner) const ;
00131     
00132 
00133     /** */
00134     std::string nodeFilename_;
00135 
00136     /** */
00137     std::string elemFilename_;
00138 
00139     /** */
00140     std::string parFilename_;
00141 
00142     /** */
00143     std::string sideFilename_;
00144 
00145     /** */
00146     mutable int offset_;
00147   };
00148 }
00149 
00150 #endif

Site Contact