MeshKit  1.0
iMeshRefine2D.hpp
Go to the documentation of this file.
00001 #ifndef REFINE_H
00002 #define REFINE_H
00003 
00004 #include <assert.h>
00005 #include <math.h>
00006 #include <string.h>
00007 #include <algorithm>
00008 
00009 #include <iGeom.h>
00010 #include <iMesh.h>
00011 #include <iRel.h>
00012 
00013 #include <vector>
00014 #include <bitset>
00015 
00016 using namespace std;
00017 
00018 #include "meshkit/SimpleArray.h"
00019 #include "meshkit/basic_math.hpp"
00020 
00022 //   MeshRefine2D:
00023 //              LongestEdgeRefine2D: ConsistencyRefine2D
00024 //              ObtuseRefine2D: ConsistencyRefine2D
00025 //              GradeRefine2D: ConsistencyRefine2D
00026 //              Refine2D14:  ConsistencyRefine2D
00027 //              CentroidRefine2D
00028 //              DelaunayRefine2D
00029 //              Square3SubDivision
00031 //Class Refine, refines an existing triangulation. This class works for 2D cases
00032 //or the parametric domain of 3D surface triangulation. The user need to provide
00033 //which cells need to be refined. There could be many criteria for deviding the
00034 //cell, so this is not part of the class. 
00035 //
00036 //Input :   Connection :  Connectivity of the triangulation ( 1D array)
00037 //      :   ParamCoords:  parametric coordinates of the vertices.
00038 //      :   markFace   :  Faces which are marked for refinement.
00039 //
00040 //Output:   Connection :
00041 //          ParamCoords:
00042 //          
00043 //If the user is working with 3D triangulated surface, it is assumed that he 
00044 //has some representation ( example NURBS ) from which he can calculate the
00045 //physical Coordinates from the paramCoords. Again this is not the responsiblity
00046 //of the class.
00047 //
00048 //------------------------------------------------------------------------------
00049 //Number of Division     :   New Vertices           :  New Faces
00050 //------------------------------------------------------------------------------
00051 //    2                  :     1                    :  1
00052 //    3                  :     0                    :  2
00053 //    4                  :     3                    :  3
00054 //------------------------------------------------------------------------------
00055 // Default Number of Subdivisions is 2, which is conservative approach, but 
00056 // good at equalizing the aspect ratio with respect to neighbouring triangles.
00057 //
00058 // Programmer : Chaman Singh Verma
00059 // Place      : Argonne National Lab.
00060 //              Argonne, IL, USA
00061 //
00062 // 
00064 //
00071 enum RefinePolicy { CENTROID_PLACEMENT, CIRCUMCENTER_PLACEMENT, LONGEST_EDGE_BISECTION};
00072 
00073 enum RefineObjective {REFINE_AREA, REFINE_ASPECT_RATIO, REFINE_CURVATURE};
00074 
00076 
00078 class MeshRefine2D
00079 {
00080  public:
00081 
00082   MeshRefine2D() { 
00083      boundary_split_flag = 0; 
00084   }
00085   virtual ~MeshRefine2D() {}
00086 
00087   void setMesh(  iMesh_Instance &m ) {  mesh = m; }
00088   void setGeometry(  const iGeom_Instance &g ) { geom = g; }
00089 
00090   void setBoundarySplitFlag( bool f ) { boundary_split_flag = f; }
00091 
00092   vector<iBase_EntityHandle> getNewNodes() const { return insertedNodes; }
00093   vector<iBase_EntityHandle> getNewFaces() const { return insertedFaces; }
00094 
00095   size_t  getNumFacesRefined() const { return numfacesRefined; }
00096 
00097   virtual int execute() = 0;
00098 
00099   virtual int initialize();
00100 
00101  protected:
00102     int finalize();
00103 
00104     typedef iBase_EntityHandle EHandle;
00105     int   numIterations;
00106 
00107     iBase_TagHandle remove_tag, vertex_on_edge_tag, boundary_tag, globalID_tag;
00108 
00109     iBase_EntitySetHandle rootSet, currSet;
00110     vector<iBase_EntitySetHandle>  entitySets;
00111 
00112     iMesh_Instance mesh;
00113     iGeom_Instance geom;
00114 
00115     vector<EHandle>  hangingVertex; 
00116     vector<EHandle>  insertedNodes;
00117     vector<EHandle>  insertedFaces;
00118     
00119     bool    boundary_split_flag;                
00120     size_t  numfacesRefined;
00121 
00122     int setVertexOnEdge(EHandle v1, EHandle v2, EHandle &vmid);
00123     int getVertexOnEdge(EHandle v1, EHandle v2, EHandle &vmid) const;
00124 
00125     bool searchEdge( EHandle v1, EHandle v2, EHandle &edgehandle) const; 
00126     bool allow_edge_refinement( EHandle &edgehandle ) const;
00127 
00128     double  edge_length( EHandle v1, EHandle v2)  const;
00129     Point3D edge_centroid( EHandle v1, EHandle v2) const;
00130 
00131     double  face_aspect_ratio( EHandle v1 ) const;
00132     Point3D face_centroid( EHandle f) const;
00133 
00134     int getVertexCoords(EHandle vHandle, Point3D &p3d) const
00135     {
00136       int err;
00137       double x, y, z;
00138       iMesh_getVtxCoord(mesh, vHandle, &x, &y, &z, &err);
00139       p3d[0] = x;
00140       p3d[1] = y;
00141       p3d[2] = z;
00142       return err;
00143     }
00144 
00145     void setVertexCoords(EHandle f, const Point3D &p);
00146 
00147     EHandle create_new_edge( EHandle v1, EHandle v2 );
00148 
00149     int prune_mesh();
00150 
00151 };
00152 
00154 
00155 class Sqrt3Refine2D : public MeshRefine2D
00156 {
00157   public:
00158    int execute();
00159   private:
00160    int create_tags();
00161 };
00162 
00164 
00165 class CentroidRefine2D : public MeshRefine2D
00166 {
00167  public:
00168 
00169    int  initialize();
00170    int  execute();
00171 
00172  private:
00173   int atomicOp( const iBase_EntityHandle &f);
00174   int refine_tri( const iBase_EntityHandle &f);
00175   int refine_quad( const iBase_EntityHandle &f);
00176 };
00177 
00179 
00180 class ConsistencyRefine2D : public MeshRefine2D
00181 {
00182    public:
00183      ~ConsistencyRefine2D() {}
00184 
00185      int  initialize();
00186      int  execute();
00187 
00188    private:
00189      bitset<3>  edge0, edge1, edge2, bitvec;
00190      typedef iBase_EntityHandle EHandle;
00191 
00192      int create_tags();
00193 
00194      int  atomicOp( const EHandle &f);
00195      void  refineEdge0(const EHandle &f);
00196      void  refineEdge1(const EHandle &f);
00197      void  refineEdge2(const EHandle &f);
00198      void  subDivideQuad2Tri( const vector<EHandle>  &qnodes);
00199 
00200      void  checkFaceConsistency( const EHandle &f);
00201 
00202      void  makeConsistent();
00203      void  makeConsistent1( const EHandle &f );
00204      void  makeConsistent2( const EHandle &f );
00205      void  makeConsistent3( const EHandle &f );
00206 };
00207 
00208 
00210 
00211 class LongestEdgeRefine2D : public MeshRefine2D 
00212 {
00213  public:
00214   LongestEdgeRefine2D()
00215   { 
00216     cutOffAspectRatio = 0.50; 
00217   }
00218 
00219   ~LongestEdgeRefine2D() {}
00220 
00221   void setCutOffAspectRatio(double asp) { cutOffAspectRatio = asp;}
00222 
00223   int  initialize();
00224   int  execute();
00225 
00226  private:
00227   int create_tags();
00228   double cutOffAspectRatio;
00229   int  atomicOp( const iBase_EntityHandle &f);
00230 };
00231 
00233 
00234 class Refine2D14 : public MeshRefine2D 
00235 {
00236  public:
00237 
00238   ~Refine2D14() {}
00239 
00240   int  initialize();
00241   int  execute();
00242 
00243  private:
00244   int  atomicOp( const iBase_EntityHandle &f);
00245   int  refine_tri(const iBase_EntityHandle &f);
00246   int  refine_quad(const iBase_EntityHandle &f);
00247 };
00248 
00250 
00251 struct DelaunayRefinement2D : public MeshRefine2D
00252 {
00253   ~DelaunayRefinement2D() {}
00254 
00255   int  initialize();
00256   int  finalize();
00257   int  execute() {}
00258 };
00259 
00261 
00262 class ObtuseRefine2D : public MeshRefine2D
00263 {
00264   public:
00265    ObtuseRefine2D( ) { cutoffAngle = 90.0;}
00266 
00267    void setCutOffAngle( double a ) { cutoffAngle = std::max(90.0, a); }
00268 
00269    int  initialize();
00270    int  execute();
00271 
00272   private:
00273    double cutoffAngle;
00274    int   atomicOp(const iBase_EntityHandle &f);
00275 };
00276 
00278 
00279 class GradeRefine2D : public MeshRefine2D
00280 {
00281   public:
00282    int  initialize();
00283    int  finalize();
00284    int  execute();
00285 
00286   private:
00287      int atomicOp( const iBase_EntityHandle &v);
00288 };
00289 
00291 
00292 #endif
00293 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines