SundanceMesh.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_MESH_H
00043 #define SUNDANCE_MESH_H
00044 
00045 #include "SundanceDefs.hpp"
00046 #include "SundanceMeshBase.hpp"
00047 #include "SundanceMaximalCofacetBatch.hpp"
00048 #include "SundanceIncrementallyCreatableMesh.hpp"
00049 #include "SundanceIdentityReorderer.hpp"
00050 #include "SundanceCellReorderer.hpp"
00051 #include "PlayaHandle.hpp"
00052 
00053 namespace Sundance
00054 {
00055 using namespace Teuchos;
00056 
00057 
00058 /**
00059  * Mesh is the user-level object representing discrete geometry. 
00060  * The Mesh class is a handle to a MeshBase, which is an abstract interface
00061  * for meshes. 
00062  */
00063 class Mesh : public Playa::Handle<MeshBase>
00064 {
00065 public:
00066 
00067   /* */
00068   HANDLE_CTORS(Mesh, MeshBase);
00069 
00070   /** */
00071   int id() const {return ptr()->id();}
00072 
00073   /** \brief Get the ordering convention used by this mesh */
00074   const MeshEntityOrder& meshOrder() const {return ptr()->meshOrder();}
00075     
00076   /** 
00077    * Get the spatial dimension of the mesh
00078    */
00079   int spatialDim() const {return ptr()->spatialDim();}
00080 
00081   /** 
00082    * Get the number of cells having dimension dim
00083    */
00084   int numCells(int dim) const {return ptr()->numCells(dim);}
00085 
00086   /** 
00087    * Return the position of the i-th node
00088    */
00089   Point nodePosition(int i) const {return ptr()->nodePosition(i);}
00090 
00091   /** 
00092    * Return a view of the i-th node's position
00093    */
00094   const double* nodePositionView(int i) const {return ptr()->nodePositionView(i);}
00095 
00096   /** 
00097    * Return the centroid position of the cellLID-th cell of dimension
00098    * cellDim.
00099    */
00100   Point centroid(int cellDim, int cellLID) const 
00101     {return ptr()->centroid(cellDim, cellLID);}
00102 
00103 
00104   /** 
00105    * Get the outward normals for the batch of cells of dimension
00106    * spatialDim()-1. If any cell in the batch is not on the boundary,
00107    * an exception is thrown. 
00108    *
00109    * \param cellLIDs [in] LIDs for the cells whose normals are to be
00110    * computed. 
00111    * \param outwardNormals [out] Outward normal unit vectors for each
00112    * cell in the batch.
00113    */
00114   void outwardNormals(
00115     const Array<int>& cellLIDs,
00116     Array<Point>& outwardNormals
00117     ) const 
00118     {ptr()->outwardNormals(cellLIDs, outwardNormals);}
00119 
00120   /** 
00121    * Get tangent vectors for a batch of edges
00122    *
00123    * \param cellLIDs [in] LIDs for the cells whose tangents are to be
00124    * computed. 
00125    * \param tangentVectors [out] Unit tangents for each cell
00126    */
00127   void tangentsToEdges(
00128     const Array<int>& cellLIDs,
00129     Array<Point>& tangentVectors
00130     ) const 
00131     {ptr()->tangentsToEdges(cellLIDs, tangentVectors);}
00132       
00133       
00134       
00135 
00136   /** 
00137    * Compute the jacobians of a batch of cells, returning the 
00138    * result via reference argument
00139    *
00140    * @param cellDim dimension of the cells whose Jacobians are to
00141    * be computed
00142    * @param cellLID local indices of the cells for which Jacobians
00143    * are to be computed
00144    * @param jBatch reference to the resulting Jacobian batch
00145    */
00146   void getJacobians(int cellDim, const Array<int>& cellLID,
00147     CellJacobianBatch& jBatch) const 
00148     {ptr()->getJacobians(cellDim, cellLID, jBatch);}
00149 
00150   /** 
00151    * Compute the diameters of a batch of cells,
00152    * result via reference argument
00153    *
00154    * @param cellDim dimension of the cells whose diameters are to
00155    * be computed
00156    * @param cellLID local indices of the cells for which diameters
00157    * are to be computed
00158    * @param diameters reference to the array of cell diameters
00159    */
00160   virtual void getCellDiameters(int cellDim, const Array<int>& cellLID,
00161     Array<double>& diameters) const 
00162     {ptr()->getCellDiameters(cellDim, cellLID, diameters);}
00163 
00164 
00165   /**
00166    * Map reference quadrature points to physical points on the
00167    * given cells. 
00168    */
00169   void pushForward(int cellDim, const Array<int>& cellLID,
00170     const Array<Point>& refQuadPts,
00171     Array<Point>& physQuadPts) const 
00172     {ptr()->pushForward(cellDim, cellLID, refQuadPts, physQuadPts);}
00173 
00174       
00175 
00176   /** 
00177    * Return the rank of the processor that owns the given cell
00178    */
00179   int ownerProcID(int cellDim, int cellLID) const 
00180     {return ptr()->ownerProcID(cellDim, cellLID);}
00181     
00182 
00183   /** 
00184    * Return the number of facets of the given cell
00185    */
00186   int numFacets(int cellDim, int cellLID, 
00187     int facetDim) const 
00188     {return ptr()->numFacets(cellDim, cellLID, facetDim);}
00189 
00190   /** 
00191    * Return the local ID of a facet cell
00192    * @param cellDim dimension of the cell whose facets are being obtained
00193    * @param cellLID local index of the cell whose
00194    * facets are being obtained
00195    * @param facetDim dimension of the desired facet
00196    * @param facetIndex index into the list of the cell's facets
00197    */
00198   int facetLID(int cellDim, int cellLID,
00199     int facetDim, int facetIndex,
00200     int& facetOrientation) const 
00201     {return ptr()->facetLID(cellDim, cellLID, 
00202         facetDim, facetIndex,
00203         facetOrientation);}
00204 
00205   /**
00206    * Return by reference argument an
00207    *  array containing the LIDs of the facetDim-dimensional 
00208    * facets of the given cell
00209    */
00210   void getFacetArray(int cellDim, int cellLID, int facetDim, 
00211     Array<int>& facetLIDs,
00212     Array<int>& facetOrientations) const 
00213     {ptr()->getFacetArray(cellDim, cellLID, 
00214         facetDim, facetLIDs,
00215         facetOrientations);}
00216 
00217   /** 
00218    * Return a view of an element's zero-dimensional facets
00219    */
00220   const int* elemZeroFacetView(int cellLID) const 
00221     {return ptr()->elemZeroFacetView(cellLID);}
00222 
00223   /** 
00224    * Return by reference argument an array containing
00225    * the LIDs of the facetDim-dimensional facets of the
00226    * given batch of cells 
00227    */
00228   void getFacetLIDs(int cellDim, 
00229     const Array<int>& cellLID,
00230     int facetDim,
00231     Array<int>& facetLID,
00232     Array<int>& facetOrientations) const 
00233     {ptr()->getFacetLIDs(cellDim, cellLID, 
00234         facetDim, facetLID, facetOrientations);}
00235 
00236 
00237   /** 
00238    * Return the number of maximal cofacets of the given cell
00239    */
00240   int numMaxCofacets(int cellDim, int cellLID) const 
00241     {return ptr()->numMaxCofacets(cellDim, cellLID);}
00242 
00243   /** 
00244    * Return the local ID of a maximal cofacet of a cell
00245    * @param cellDim dimension of the cell whose cofacets are being obtained
00246    * @param cellLID local index of the cell whose
00247    * cofacets are being obtained
00248    * @param cofacetIndex [in] index of the maximal cell 
00249    * into the list of the cell's cofacets
00250    * @param facetIndex [out] index of the calling cell
00251    * into the list of the maximal cell's facets
00252    */
00253   int maxCofacetLID(int cellDim, int cellLID,
00254     int cofacetIndex,
00255     int& facetIndex) const 
00256     {return ptr()->maxCofacetLID(cellDim, cellLID, cofacetIndex, facetIndex);}
00257 
00258   /** 
00259    * Get the LIDs of the maximal cofacets for a batch of 
00260    * codimension-one cells. 
00261    *
00262    * \param cellLIDs [in] array of LIDs of the cells whose cofacets are 
00263    * being obtained
00264    * \param cofacets [out] the batch of cofacets
00265    */
00266   void getMaxCofacetLIDs(const Array<int>& cellLIDs,
00267     MaximalCofacetBatch& cofacets) const 
00268     {ptr()->getMaxCofacetLIDs(cellLIDs, cofacets);}
00269 
00270 
00271 
00272   /** 
00273    * Find the cofacets of the given cell
00274    * @param cellDim dimension of the cell whose cofacets are being obtained
00275    * @param cellLID local index of the cell whose
00276    * cofacets are being obtained
00277    * @param cofacetDim dimension of the cofacets to get
00278    * @param cofacetLIDs LIDs of the cofacet
00279    */
00280   void getCofacets(int cellDim, int cellLID,
00281     int cofacetDim, Array<int>& cofacetLIDs) const 
00282     {ptr()->getCofacets(cellDim, cellLID, cofacetDim, cofacetLIDs);}
00283 
00284   /** 
00285    * Find the local ID of a cell given its global index
00286    */
00287   int mapGIDToLID(int cellDim, int globalIndex) const 
00288     {return ptr()->mapGIDToLID(cellDim, globalIndex);}
00289 
00290   /** 
00291    * Determine whether a given cell GID exists on this processor
00292    */
00293   bool hasGID(int cellDim, int globalIndex) const 
00294     {return ptr()->hasGID(cellDim, globalIndex);}
00295 
00296     
00297 
00298   /** 
00299    * Find the global ID of a cell given its local index
00300    */
00301   int mapLIDToGID(int cellDim, int localIndex) const 
00302     {return ptr()->mapLIDToGID(cellDim, localIndex);}
00303 
00304   /**
00305    * Get the type of the given cell
00306    */
00307   CellType cellType(int cellDim) const 
00308     {return ptr()->cellType(cellDim);}
00309 
00310   /** Get the label of the given cell */
00311   int label(int cellDim, int cellLID) const 
00312     {return ptr()->label(cellDim, cellLID);}
00313 
00314   /** Get the labels for a batch of cells */
00315   void getLabels(int cellDim, const Array<int>& cellLID, Array<int>& labels) const 
00316     {ptr()->getLabels(cellDim, cellLID, labels);}
00317 
00318   /** Set the label for the given cell */
00319   void setLabel(int cellDim, int cellLID, int label)
00320     {ptr()->setLabel(cellDim, cellLID, label);}
00321 
00322   /** Get the list of all labels defined for cells of the given dimension */
00323   Set<int> getAllLabelsForDimension(int cellDim) const 
00324     {return ptr()->getAllLabelsForDimension(cellDim);}
00325 
00326   /** 
00327    * Return the number of labels associated with the given dimension.
00328    */
00329   virtual int numLabels(int cellDim) const 
00330     {return getAllLabelsForDimension(cellDim).size();}
00331 
00332   /** 
00333    * Get the cells associated with a specified label. The array 
00334    * cellLID will be filled with those cells of dimension cellDim
00335    * having the given label.
00336    */
00337   void getLIDsForLabel(int cellDim, int label, Array<int>& cellLIDs) const 
00338     {ptr()->getLIDsForLabel(cellDim, label, cellLIDs);}
00339 
00340   /** Get the MPI communicator over which the mesh is distributed */
00341   const MPIComm& comm() const {return ptr()->comm();}
00342 
00343   /** \name Mesh creation methods */
00344   //@{
00345   /** Allocate space for an estimated number of vertices */
00346   void estimateNumVertices(int nPts) 
00347     {creatableMesh()->estimateNumVertices(nPts);}
00348     
00349   /** Allocate space for an estimated number of elements */
00350   void estimateNumElements(int nElems) 
00351     {creatableMesh()->estimateNumElements(nElems);}
00352 
00353     
00354   /** Add a new vertex to the mesh */
00355   int addVertex(int globalIndex, const Point& x,
00356     int ownerProcID, int label)
00357     {return creatableMesh()->addVertex(globalIndex, x, ownerProcID, label);}
00358 
00359   /** Add a new vertex to the mesh */
00360   int addElement(int globalIndex, const Array<int>& vertLID,
00361     int ownerProcID, int label)
00362     {return creatableMesh()->addElement(globalIndex, vertLID, 
00363         ownerProcID, label);}
00364 
00365   /** */
00366   void freezeTopology() 
00367     {creatableMesh()->freezeTopology();}
00368 
00369     
00370   /** \name Reordering */
00371   //@{
00372   /** Set the reordering method to be used with this mesh */
00373   void setReorderer(const CellReorderer& reorderer) 
00374     {ptr()->setReorderer(reorderer);}
00375 
00376   /** Set the reordering method to be used with this mesh */
00377   const CellReordererImplemBase* reorderer() const 
00378     {return ptr()->reorderer();}
00379   //@}
00380     
00381   /** */
00382   static CellReorderer& defaultReorderer()
00383     {
00384       static CellReorderer rtn = new IdentityReorderer();
00385       return rtn;
00386     }
00387 
00388   /** Work out global numberings for the cells of dimension cellDim */
00389   void assignIntermediateCellGIDs(int cellDim) 
00390     {
00391       if (!hasIntermediateGIDs(cellDim))
00392         ptr()->assignIntermediateCellGIDs(cellDim);
00393     }
00394 
00395   /** */
00396   bool hasIntermediateGIDs(int cellDim) const 
00397     {
00398       return ptr()->hasIntermediateGIDs(cellDim);
00399     }
00400 
00401   /** */
00402   void dump(const std::string& filename) const ;
00403 
00404   /** Test the consistency of the mesh numbering scheme 
00405    * across processors. This is meant as a check on Sundance's internal
00406    * logic rather than as a check on the validity of a user's mesh. */
00407   bool checkConsistency(const std::string& filename) const ;
00408 
00409   /** Test the consistency of the mesh numbering scheme 
00410    * across processors. This is meant as a check on Sundance's internal
00411    * logic rather than as a check on the validity of a user's mesh. */
00412   bool checkConsistency(std::ostream& os) const ;
00413 
00414   /** \name Functions for Mesh with hanging nodes */
00415     //@{
00416     /** Function returns true if the mesh allows hanging nodes (by refinement), false otherwise */
00417     bool allowsHangingHodes() const { return ptr()->allowsHangingHodes(); }
00418 
00419     /** Function returns true if the specified element is a "hanging" element
00420      * false otherwise */
00421     bool isElementHangingNode(int cellDim , int cellLID) const
00422         { return ptr()->isElementHangingNode(cellDim , cellLID); }
00423 
00424    /** Returns the index in the parent maxdim Cell of the refinement tree
00425     * @param maxCellLID [in] the LID of the cell */
00426     int indexInParent(int maxCellLID) const
00427         { return ptr()->indexInParent(maxCellLID); }
00428 
00429    /** How many children has a refined element. <br>
00430     * This function provides information of either we have bi or trisection */
00431    int maxChildren() const { return ptr()->maxChildren();}
00432 
00433    /** Function returns the facets of the maxdim parent cell (needed for HN treatment) */
00434    void returnParentFacets( int childCellLID , int dimFacets ,
00435                                  Array<int> &facetsLIDs , int &parentCellLIDs ) const {
00436       ptr()->returnParentFacets( childCellLID , dimFacets , facetsLIDs , parentCellLIDs );
00437    }
00438   //@}
00439 
00440 
00441   /** \name Special Weights Storage for Adaptive Cell Integration */
00442    //@{
00443   /** returns the status of the special weights if they are valid <br>
00444     *  These weights are usually computed for one setting of the curve (Adaptive Cell Integration)*/
00445   bool IsSpecialWeightValid() const {return ptr()->IsSpecialWeightValid();}
00446 
00447   /** specifies if the special weights are valid <br>
00448    *  if this is false then usually the special weights have to be recomputed */
00449   void setSpecialWeightValid(bool val) const { ptr()->setSpecialWeightValid(val);}
00450 
00451   /** deletes all the special weights*/
00452   void flushSpecialWeights() const { ptr()->flushSpecialWeights(); }
00453 
00454   /** verifies if the specified cell with the given dimension has special weights */
00455   bool hasSpecialWeight(int dim, int cellLID) const {return ptr()->hasSpecialWeight( dim, cellLID); }
00456 
00457   /** Sets the special weights */
00458   void setSpecialWeight(int dim, int cellLID, Array<double>& w) const {ptr()->setSpecialWeight(dim, cellLID, w);}
00459 
00460   /** Returns the special weights */
00461   void getSpecialWeight(int dim, int cellLID, Array<double>& w) const {ptr()->getSpecialWeight(dim, cellLID, w);}
00462    //@}
00463 
00464 
00465 
00466   /** \name Store the intersection/quadrature points for the curve/surf integral <br>
00467    *  for a curve or surf integral we need some quadrature points along the curve in one curve <br>
00468    *  These */
00469     //@{
00470 
00471   /** */
00472   bool IsCurvePointsValid() const {return ptr()->IsCurvePointsValid();}
00473 
00474   /**  */
00475   void setCurvePointsValid(bool val)  const {ptr()->setCurvePointsValid(val); }
00476 
00477   /** deletes all the curve points */
00478   void flushCurvePoints() const { ptr()->flushCurvePoints(); }
00479 
00480   /** verifies if the specified maxCell has already precalculated quadrature point for one curve */
00481   bool hasCurvePoints(int maxCellLID , int curveID) const { return ptr()->hasCurvePoints( maxCellLID , curveID); }
00482 
00483   /** Sets the points, curve derivatives and curve normals for one maxCell needed for curve/surf integral*/
00484   void setCurvePoints(int maxCellLID, int curveID , Array<Point>& points , Array<Point>& derivs , Array<Point>& normals) const
00485     {ptr()->setCurvePoints( maxCellLID, curveID , points , derivs , normals); }
00486 
00487   /** Gets the points, curve derivatives and curve normals for one maxCell needed for curve/surf integral*/
00488   void getCurvePoints(int maxCellLID,  int curveID , Array<Point>& points , Array<Point>& derivs , Array<Point>& normals) const
00489     {ptr()->getCurvePoints( maxCellLID,  curveID ,  points , derivs , normals); }
00490 
00491   //@}
00492 
00493 private:
00494   /** */
00495   IncrementallyCreatableMesh* creatableMesh();
00496 
00497 
00498   /** */
00499   bool checkVertexConsistency(std::ostream& os) const ;
00500   /** */
00501   bool checkCellConsistency(std::ostream& os, int dim) const ;
00502 
00503   /** */
00504   bool checkRemoteEntity(std::ostream& os, int p, int dim, int gid, 
00505     int owner, bool mustExist, int& lid) const ;
00506 
00507   /** */
00508   bool testIdentity(std::ostream& os, int a, int b, const std::string& msg) const ;
00509 
00510   /** */
00511   bool testIdentity(std::ostream& os, 
00512     const Array<int>& a,
00513     const Array<int>& b, const std::string& msg) const ;
00514 };
00515 }
00516 
00517 #endif

Site Contact