SundanceMeshSourceBase.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_MESHSOURCEBASE_H
00032 #define SUNDANCE_MESHSOURCEBASE_H
00033 
00034 
00035 #include "SundanceDefs.hpp"
00036 #include "SundanceMesh.hpp"
00037 #include "SundanceMeshType.hpp"
00038 #include "SundanceHandleable.hpp"
00039 #include "Teuchos_Describable.hpp"
00040 #include "SundancePrintable.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 Sundance::Handleable<MeshSourceBase>,
00080                        public Sundance::Printable,
00081                        public Teuchos::Describable,
00082                        public Noncopyable,
00083                        public ObjectWithClassVerbosity<MeshSourceBase>
00084 {
00085 public:
00086   /** Construct with a mesh type and MPI communicator */
00087   MeshSourceBase(const MeshType& meshType,
00088     const MPIComm& comm);
00089 
00090   /** Construct from a parameter list */
00091   MeshSourceBase(const ParameterList& params);
00092 
00093   /** virtual dtor */
00094   virtual ~MeshSourceBase(){;}
00095 
00096       
00097   /** Get a mesh from the source. If a mesh has already been created,
00098    * this method will return the cached mesh, otherwise it will 
00099    * build on with a call to fillMesh() */
00100   Mesh getMesh() const ;
00101 
00102   /** \name Extraction of attributes */
00103   //@{
00104   void getAttributes(RCP<Array<Array<double> > >& nodeAttributes,
00105     RCP<Array<Array<double> > >& elemAttributes) const ;
00106   //@}
00107 
00108   /** \name Printable interface */
00109   //@{
00110   /** Print to a stream */
00111   virtual void print(std::ostream& os) const {os << description();}
00112   //@}
00113 
00114   /** \name Describable interface */
00115   //@{
00116   /** Print to a stream */
00117   virtual std::string description() const 
00118     {return "MeshSourceBase[unknown subtype]";}
00119 
00120   /** access to the MPI communicator */
00121   const MPIComm& comm() const {return comm_;}
00122   //@}
00123       
00124 protected:
00125 
00126 
00127   /** Get processor rank */
00128   int myRank() const {return comm().getRank();}
00129   /** Get number of processors */
00130   int nProc() const {return comm().getNProc();}
00131 
00132   /** Fill a mesh object with data from the source. Subclass
00133    * implementors will need to provide a fillMesh() for their
00134    * subclass. Implementors should use the createMesh() method
00135    * for the allocation of the new mesh. */
00136   virtual Mesh fillMesh() const = 0 ;
00137 
00138   /** createMesh() physically allocates the mesh object */
00139   Mesh createMesh(int dim) const ;
00140 
00141   /** internal access to the node attributes */
00142   RCP<Array<Array<double> > >& nodeAttributes() const 
00143     {return nodeAttributes_;}
00144 
00145   /** internal access to the element attributes */
00146   RCP<Array<Array<double> > >& elemAttributes() const 
00147     {return elemAttributes_;}
00148 
00149 
00150 
00151 private:
00152 
00153   /** */
00154   mutable Mesh cachedMesh_;
00155 
00156   /** */
00157   mutable bool hasCachedMesh_;
00158 
00159   /** */
00160   MeshType meshType_;
00161 
00162   /** */
00163   MPIComm comm_;
00164 
00165   /** */
00166   mutable RCP<Array<Array<double> > > elemAttributes_;
00167 
00168   /** */
00169   mutable RCP<Array<Array<double> > > nodeAttributes_;
00170 
00171 };
00172 }
00173 
00174 
00175 #endif

Site Contact