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

Site Contact