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_MESHSOURCEBASE_H 00032 #define SUNDANCE_MESHSOURCEBASE_H 00033 00034 00035 #include "SundanceDefs.hpp" 00036 #include "SundanceMesh.hpp" 00037 #include "SundanceMeshType.hpp" 00038 #include "PlayaHandleable.hpp" 00039 #include "Teuchos_Describable.hpp" 00040 #include "PlayaPrintable.hpp" 00041 #include "SundanceNoncopyable.hpp" 00042 #include "SundanceObjectWithVerbosity.hpp" 00043 #include "SundanceIncrementallyCreatableMesh.hpp" 00044 #include "Teuchos_ParameterList.hpp" 00045 00046 namespace Sundance 00047 { 00048 /** 00049 * MeshSourceBase provides the internal interface for mesh sources, i.e., 00050 * objects such as mesh generators and file readers that can produce 00051 * a mesh object. The action of a mesh source should be independent 00052 * of the internal mesh representation used. To allow user-level 00053 * specification of the type of internal mesh representation to be 00054 * used, a MeshSourceBase is constructed with a MeshType object 00055 * which acts as a factory to produce empty meshes. 00056 * 00057 * Mesh sources are constructed with a MPI communicator. If the 00058 * communicator has more than one processor, the mesh created will 00059 * be distributed. 00060 * 00061 * <h4> Writing your own MeshSourceBase subtype </h4> 00062 * 00063 * The only method you will need to override is 00064 * <ul> 00065 * <li> <tt>virtual Mesh fillMesh() const </tt> 00066 * </ul> 00067 * which is where you fill in a mesh object and return it. This method 00068 * should usually physically create the mesh with a call to createMesh(), 00069 * ensuring that the correct mesh representation type is created 00070 * using the MeshType factory with which the source was constructed. 00071 * 00072 * See the PartitionedLineMesher source code for a very simple 00073 * example of how to write a mesh source subtype. 00074 * 00075 * Optionally, you can override the description() method to 00076 * provide more informative descriptive output than the std::string 00077 * <tt>"MeshSourceBase[unknown subtype]".</tt> 00078 */ 00079 class MeshSourceBase : public Playa::Handleable<MeshSourceBase>, 00080 public Playa::Printable, 00081 public Teuchos::Describable, 00082 public Noncopyable, 00083 public Playa::ObjectWithVerbosity 00084 { 00085 public: 00086 /** Construct with a mesh type and MPI communicator */ 00087 MeshSourceBase(const MeshType& meshType, 00088 int verbosity, 00089 const MPIComm& comm); 00090 00091 /** Construct from a parameter list */ 00092 MeshSourceBase(const ParameterList& params); 00093 00094 /** virtual dtor */ 00095 virtual ~MeshSourceBase(){;} 00096 00097 00098 /** Get a mesh from the source. If a mesh has already been created, 00099 * this method will return the cached mesh, otherwise it will 00100 * build on with a call to fillMesh() */ 00101 Mesh getMesh() const ; 00102 00103 /** \name Extraction of attributes */ 00104 //@{ 00105 void getAttributes(RCP<Array<Array<double> > >& nodeAttributes, 00106 RCP<Array<Array<double> > >& elemAttributes) const ; 00107 //@} 00108 00109 /** \name Printable interface */ 00110 //@{ 00111 /** Print to a stream */ 00112 virtual void print(std::ostream& os) const {os << description();} 00113 //@} 00114 00115 /** \name Describable interface */ 00116 //@{ 00117 /** Print to a stream */ 00118 virtual std::string description() const 00119 {return "MeshSourceBase[unknown subtype]";} 00120 00121 /** access to the MPI communicator */ 00122 const MPIComm& comm() const {return comm_;} 00123 //@} 00124 00125 protected: 00126 00127 00128 /** Get processor rank */ 00129 int myRank() const {return comm().getRank();} 00130 /** Get number of processors */ 00131 int nProc() const {return comm().getNProc();} 00132 00133 /** Fill a mesh object with data from the source. Subclass 00134 * implementors will need to provide a fillMesh() for their 00135 * subclass. Implementors should use the createMesh() method 00136 * for the allocation of the new mesh. */ 00137 virtual Mesh fillMesh() const = 0 ; 00138 00139 /** createMesh() physically allocates the mesh object */ 00140 Mesh createMesh(int dim) const ; 00141 00142 /** internal access to the node attributes */ 00143 RCP<Array<Array<double> > >& nodeAttributes() const 00144 {return nodeAttributes_;} 00145 00146 /** internal access to the element attributes */ 00147 RCP<Array<Array<double> > >& elemAttributes() const 00148 {return elemAttributes_;} 00149 00150 00151 00152 private: 00153 00154 /** */ 00155 mutable Mesh cachedMesh_; 00156 00157 /** */ 00158 mutable bool hasCachedMesh_; 00159 00160 /** */ 00161 MeshType meshType_; 00162 00163 /** */ 00164 MPIComm comm_; 00165 00166 /** */ 00167 mutable RCP<Array<Array<double> > > elemAttributes_; 00168 00169 /** */ 00170 mutable RCP<Array<Array<double> > > nodeAttributes_; 00171 00172 }; 00173 } 00174 00175 00176 #endif