Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

Mesh.h

Go to the documentation of this file.
00001 #ifndef MESH_H
00002 #define MESH_H
00003 
00004 #include "SundanceDefs.h"
00005 
00006 #include "TSFSmartPtr.h"
00007 #include "TSFArray.h"
00008 #include "Cell.h"
00009 #include "MeshData.h"
00010 
00011 
00012 
00013 namespace Sundance
00014 {
00015 
00016   using namespace TSF;
00017   using std::string;
00018 
00019   using std::ostream;
00020 
00021   class Point;
00022   class MeshTransformation;
00023   class CellFactory;
00024   class MeshWriter;
00025   class LogicalExpr;
00026 
00027   typedef bool (*CellConditional)(const Cell& cell);
00028 
00029   /** \ingroup UserLevelGeometry
00030    * Mesh represents an unstructured mesh.
00031    */
00032 
00033   class Mesh
00034     {
00035     public:
00036       /** \name Constructors */
00037       //@{
00038       /** Null constructor */
00039       Mesh();
00040       /** Start an empty mesh of a specified spatial dimension */
00041       Mesh(int spatialDim, const MPIComm& comm = MPIComm::world());
00042       /** Start an empty mesh of a specified spatial dimension, pretending
00043        * that it is the rank-th processor of an nproc-processor parallel
00044        * computer. */
00045       Mesh(int spatialDim, int rank, int nProc);
00046       //@}
00047 
00048       /** \name Informational methods */
00049       //@{
00050       /** Get dimension of the mesh */
00051       int spatialDim() const {return data_->spatialDim_;}
00052       /** Get number of cells of dimension dim */
00053       int numCells(int dim) const {return data_->cells_[dim].length();}
00054       /** Get number of point in the mesh */
00055       int numPoints() const {return data_->points_.length();}
00056       //@}
00057 
00058       /** \name getting individual cells and points */
00059       //@{
00060       /** look up a cell by its local index */
00061       const Cell& getCell(int dim, int index) const ;
00062       /** look up a cell by its global index */
00063       const Cell& getCellByGlobalIndex(int dim, int globalIndex) const ;
00064       /** */
00065       const Point& getPointByLocalIndex(int localIndex) const ;
00066       /** */
00067       const Point& getPointByGlobalIndex(int globalIndex) const ;
00068       //@}
00069 
00070       /** \name Cell labeling */
00071       //@{
00072       /** Label all cells of dimension=dim that satisfy a condition given
00073           by a user-defined function */
00074       void labelCells(int dim, const string& label, CellConditional conditional);
00075 
00076       /** Label all maximal cells on which the given logical expression is true */
00077       void labelMaximalCells(const string& label, const LogicalExpr& filter);
00078 
00079 
00080       /** Label all zero cells on which the given logical expression is true */
00081       void labelPoints(const string& label, const LogicalExpr& filter);
00082 
00083       /** Return a list of all labels in the mesh */
00084       const TSFArray<string>& labels() const {return data_->labels_;}
00085       //@}
00086 
00087       /** find the zero-cell closest to a specified point */
00088       Cell cellNearestToPoint(const Point& x) const ;
00089 
00090 
00091 
00092       /** \name Methods for creating a mesh */
00093       //@{
00094       /** add a point to the mesh. Give the coordinates of the point,
00095        * the ID of the processor that owns the point, a list of
00096        * other processors that include this point, and the global
00097        * index of the point */
00098       int addPoint(const Point& x,
00099                    int ownerProcID=0,
00100                    int globalIndex=-1);
00101       /**
00102        * Create a zero cell and add it to the mesh. Specify the
00103        * global index of the node associated with the zero cell,
00104        * the label, and the ID of the processor that owns the point
00105        */
00106       Cell createZeroCell(int globalNodeIndex, const string& label,
00107                           int ownerProcID=0);
00108       /**
00109        * Create a maximal cell
00110        */
00111       Cell createMaximalCell(const CellFactory& factory,
00112                              const string& label,
00113                              int ownerProcID=0,
00114                              int globalIndex=-1);
00115       /**
00116        * Create an intermediate cell and add it to the mesh.
00117        */
00118       Cell createIntermediateCell(int parentIndex, int cellDim,
00119                                   int myFacetID, int pid=0);
00120       //@}
00121 
00122 
00123       /** \name information about parallel environment */
00124       //@{
00125       /** return the local processor ID */
00126       int procID() const {return data_->procID_;}
00127       /** return the number of processors used to model the mesh */
00128       int numProcs() const {return data_->numProcs_;}
00129       /** get the communicator used y the */
00130       const MPIComm& comm() const {return data_->comm_;}
00131       //@}
00132 
00133       /** \name Mesh partioning */
00134       //@{
00135       /** Scatter a mesh into nProcs pieces, storing the n-th piece in a file
00136        * called filename.n.
00137        */
00138       void scatterMesh(int nProcs,
00139                        const string& filename,
00140                        const MeshWriter& writer) const ;
00141       Mesh getSubmesh(const MPIComm& comm = MPIComm::world()) const ;
00142       void getSubmesh(Mesh& subMesh, int myPid, int nProc,
00143                       const TSFArray<short>& assignments) const ;
00144 
00145       void findProcAssignments(int nProc, TSFArray<short>& procAssignments) const ;
00146       //@}
00147       /** \name Mesh transformations */
00148 
00149       //@{
00150       /** replace the mesh points with a new set of points */
00151       void replacePoints(const TSFArray<Point>& points);
00152 
00153       /** carry out an arbitrary transformation on the mesh */
00154       void transform(const MeshTransformation& trans);
00155 
00156       /** undo a mesh transformation */
00157       void undo(const MeshTransformation& trans);
00158 
00159       /** get the entire array of mesh points */
00160       const TSFArray<Point>& getPoints() const ;
00161       //@}
00162 
00163       /** \name Developer-only methods */
00164       //@{
00165       /** */
00166       int meshID() const {return data_->meshID_;}
00167 
00168       bool containsPoint(int globalIndex) const ;
00169       bool containsCell(int dim, int globalIndex) const ;
00170 
00171 
00172 
00173       void getBoundary(TSFArray<Cell>& bdryCells) const ;
00174       bool isBoundaryCell(int i) const {return data_->isBoundary_[i];}
00175 
00176       void getLabeledCells(const string& label, TSFArray<Cell>& cells) const ;
00177 
00178 
00179       int labelIndex(const string& label) const ;
00180       const string& label(int i) const ;
00181       int numLabels() const {return data_->labels_.length();}
00182 
00183       /** */
00184       int numFacets(int cellIndex, int dim) const ;
00185       /** */
00186       int numCofacets(int cellIndex, int dim) const ;
00187       /** */
00188       int facetIndex(int cellIndex, int dim, int facetNumber) const ;
00189       /** */
00190       int cofacetIndex(int cellIndex, int dim, int cofacetNumber) const ;
00191       /** */
00192       const Cell& getZeroCellByNodeIndex(int globalNodeIndex) const ;
00193       //    {return data_->cells_[0][data_->pointToZeroCellMap_[data_->pointIndexMap_.get(globalNodeIndex)]];}
00194       /** */
00195       int pointGlobalIndex(int pointLocalIndex) const
00196         {return data_->pointGlobalIndex_[pointLocalIndex];}
00197       /** */
00198       int pointOwnerProc(int pointLocalIndex) const
00199         {return data_->pointOwnerProcID_[pointLocalIndex];}
00200       /** */
00201       const TSFArray<int>& pointSharerProcIDs(int pointLocalIndex) const
00202         {return data_->pointSharerProcID_[pointLocalIndex];}
00203       /** */
00204       int lookupCellByNodes(int dim, const TSFArray<int>& nodes) const ;
00205 
00206       void printCells() const ;
00207 
00208       string toString() const {return "Mesh";}
00209 
00210       void diagnostics() const ;
00211       void assignGlobalIndices();
00212 
00213       static void traceCommunications() {traceComm_ = true;}
00214       static void traceCommunicationsOff() {traceComm_ = false;}
00215 
00216       friend class BoundaryCellSet;
00217       //@}
00218     private:
00219       //@{
00220       void computeGlobalOffsets(TSFArray<int>& offsets) const ;
00221       void shareIndexRequests(int d,
00222                               const TSFArray<TSFArray<int> >& indexRequestList,
00223                               const TSFArray<TSFArray<int> >& localIndexList,
00224                               TSFArray<TSFArray<int> >& globalIndices) const ;
00225       //@}
00226       TSFSmartPtr<MeshData> data_;
00227 
00228       static bool traceComm_;
00229     };
00230 
00231 
00232 }
00233 #endif
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 

Contact:
Kevin Long (krlong@ca.sandia.gov)


Documentation generated by