SundanceTriangleMeshReader.hpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 #ifndef SUNDANCE_TRIANGLEMESHREADER_H
00043 #define SUNDANCE_TRIANGLEMESHREADER_H
00044 
00045 #include "SundanceDefs.hpp"
00046 #include "SundanceMeshReaderBase.hpp"
00047 
00048 namespace Sundance
00049 {
00050   using namespace Teuchos;
00051   
00052   /**
00053    * TriangleMeshReader reads a mesh stored in Shewchuk's Triangle format.
00054    * This format is documented at 
00055    * <A HREF="http://www-2.cs.cmu.edu/~quake/triangle.html"> 
00056    * the Triangle homepage. 
00057    * </A>
00058    * This reader expects to find node information in <tt>.node</tt> files
00059    * and element information in <tt>.ele</tt> files. The <tt> filename </tt>
00060    * constructor argument is the stem of the filenames, and so that 
00061    * a reader constructed with filename <tt>joe</tt> will look for node and
00062    * element data in <tt>joe.node</tt> and <tt>joe.ele</tt> respectively.
00063    * Node and element
00064    * attributes are read if present, and can be accessed with the 
00065    * <tt>getAttributes()</tt> method of <tt>MeshSource.</tt>
00066    * 
00067    * <h4> Parallel extensions </h4>
00068    * We have extended the Triangle format to deal with distributed meshes.
00069    * A TriangleMeshReader is constructed with an MPIComm object, and if
00070    * that communicator has more than one processor the mesh is assumed
00071    * to be split into files, one for each processor. Data
00072    * on mesh "joe" for the <i>nnn</i>-th processor will be found in the files
00073    * <ul>
00074    * <li> <tt>joe.node.</tt><i>nnn</i>
00075    * <li> <tt>joe.ele.</tt><i>nnn</i>
00076    * <li> <tt>joe.par.</tt><i>nnn</i>
00077    * </ul>
00078    * The <tt>.node.</tt><i>nnn</i> and <tt>.ele.</tt><i>nnn</i> files contain the
00079    * node and element data for the part of the mesh seen 
00080    * by the <i>nnn</i>-th
00081    * processor. The node and element 
00082    * numberings given in those two files are <b>local</b> indexes.
00083    * The <tt>.par.</tt><i>nnn</i> contains node and element 
00084    * ownership information for the part of the mesh seen 
00085    * by the <i>nnn</i>-th
00086    * processor. 
00087    *
00088    * <br> 
00089    *
00090    * A <tt>.par</tt> file is formatted as follows:
00091    * <ul>
00092    * <li> First line: <tt> rank numProcs </tt>
00093    * <li> Second line: <tt> numPoints </tt>
00094    * <li> Next <i> nPoints </i> lines: <tt> ptLID ptGID ptOwnerRank </tt>
00095    * <li> Next line: <tt> numElems </tt>
00096    * <li> Next <i> nElems </i> lines: <tt> elemLID elemGID elemOwnerRank </tt>
00097    * </ul>
00098    * 
00099    */
00100   class TriangleMeshReader : public MeshReaderBase
00101   {
00102   public:
00103     /** */
00104     TriangleMeshReader(const std::string& filename, 
00105       const MeshType& meshType,
00106       int verbosity=0,
00107       const MPIComm& comm = MPIComm::world());
00108 
00109     /** Construct from a ParameterList */
00110     TriangleMeshReader(const ParameterList& params);
00111 
00112     /** virtual dtor */
00113     virtual ~TriangleMeshReader(){;}
00114 
00115 
00116     /** Create a mesh */
00117     virtual Mesh fillMesh() const ;
00118 
00119     /** Print a short descriptive std::string */
00120     virtual std::string description() const 
00121     {return "TriangleMeshReader[file=" + filename() + "]";}
00122       
00123 
00124     /** Return a ref count pointer to self */
00125     virtual RCP<MeshSourceBase> getRcp() {return rcp(this);}
00126 
00127   private:
00128     /** */
00129     void readParallelInfo(Array<int>& ptGID, Array<int>& ptOwner,
00130                           Array<int>& elemGID, Array<int>& elemOwner) const ;
00131 
00132     /** */
00133     Mesh readNodes(Array<int>& ptGID,
00134                    Array<int>& ptOwner) const ;
00135 
00136     /** */
00137     void readSides(Mesh& mesh) const ;
00138 
00139     /** */
00140     void readEdges(Mesh& mesh) const ;
00141 
00142     /** */
00143     void readElems(Mesh& mesh,
00144                    const Array<int>& nodeGID,
00145                    Array<int>& elemGID,
00146                    Array<int>& elemOwner) const ;
00147     
00148 
00149     /** */
00150     std::string nodeFilename_;
00151 
00152     /** */
00153     std::string elemFilename_;
00154 
00155     /** */
00156     std::string parFilename_;
00157 
00158     /** */
00159     std::string sideFilename_;
00160 
00161     /** */
00162     std::string edgeFilename_;
00163 
00164     /** */
00165     mutable int offset_;
00166   };
00167 }
00168 
00169 #endif

Site Contact