MeshKit  1.0
EBMesher.hpp
Go to the documentation of this file.
00001 #ifndef MESHKIT_EB_MESHER_HPP
00002 #define MESHKIT_EB_MESHER_HPP
00003 
00004 #include <vector>
00005 #include <map>
00006 #include <sys/resource.h>
00007 
00008 #include "meshkit/Types.hpp"
00009 #include "meshkit/Error.hpp"
00010 #include "meshkit/MeshScheme.hpp"
00011 #include "meshkit/ModelEnt.hpp"
00012 #include "meshkit/iMesh.hpp"
00013 
00014 #ifdef HAVE_MOAB
00015 #include "moab/Interface.hpp"
00016 #include "moab/GeomTopoTool.hpp"
00017 #include "MBOrientedBoxTreeTool.hpp"
00018 #endif
00019 
00021 enum EdgeStatus {
00022   INSIDE,
00023   OUTSIDE,
00024   BOUNDARY
00025 };
00026 
00028 struct CutFraction {
00029   std::vector<double> fraction[3];
00030 
00031   CutFraction() {};
00032 
00033   CutFraction(int dir, const std::vector<double>& val) {
00034     add(dir, val);
00035   };
00036   
00037   void add(int dir, const std::vector<double>& val) {
00038     for (unsigned int i = 0; i < val.size(); i++) {
00039       fraction[dir].push_back(val[i]);
00040     }
00041   }
00042 };
00043 
00046 struct CutCellSurfEdgeKey {
00047   int i, j, k, l;
00048 
00049   CutCellSurfEdgeKey() {
00050     i = j = k = l = 0;
00051   };
00052 
00053   CutCellSurfEdgeKey(int ii, int jj, int kk, int ll) {
00054     i = ii;
00055     j = jj;
00056     k = kk;
00057     l = ll;
00058   };
00059 };
00060 
00062 struct IntersectDist {
00063   double distance;
00064   int index;
00065 
00066   IntersectDist() {};
00067 
00068   IntersectDist(double d, int i) {
00069     distance = d;
00070     index = i;
00071   };
00072 };
00073 
00075 struct VolFrac {
00076   double vol;
00077   bool closed;
00078   double ePnt[6];
00079 
00080   VolFrac() {};
00081 
00082   VolFrac(double f, int c) {
00083     vol = f;
00084     closed = c;
00085   };
00086 };
00087 
00088 struct LessThan
00089 {
00090   bool operator() (const CutCellSurfEdgeKey key1, const CutCellSurfEdgeKey key2) const
00091   {
00092     if (key1.i < key2.i) return true;
00093     else if (key1.i > key2.i) return false;
00094     else {
00095       if (key1.j < key2.j) return true;
00096       else if (key1.j > key2.j) return false;
00097       else {
00098         if (key1.k < key2.k) return true;
00099         else if (key1.k > key2.k) return false;
00100         else {
00101           if (key1.l < key2.l) return true;
00102           else return false;
00103         }
00104       }
00105     }
00106   };
00107 };
00108 
00109 namespace MeshKit {
00110 
00111 class MKCore;
00112     
00113 
00122 class EBMesher : public MeshScheme
00123 {
00124 public:
00125 
00127   EBMesher(MKCore *mkcore, const MEntVector &me_vec,
00128            double size = -1., bool use_geom = true,
00129            int add_layer = 3);
00130   
00132   virtual ~EBMesher();
00133   
00135   static const char* name() 
00136     { return "EBMesher"; }
00137 
00142   static bool can_mesh(iBase_EntityType dim)
00143     { return iBase_REGION == dim; }
00144    
00151   static bool can_mesh(ModelEnt *me);
00152   
00156   static const moab::EntityType* output_types();
00157   
00161   virtual const moab::EntityType* mesh_types_arr() const
00162   { return output_types(); }
00163   
00164   
00165   virtual bool add_modelent(ModelEnt *model_ent);
00166   
00172   int set_division(double* min, double* max);
00173   
00176   virtual void setup_this();
00177   
00180   virtual void execute_this();
00181   
00190   void get_grid_and_edges_techX(double* boxMin, double* boxMax, int* nDiv,
00191                                 std::map< CutCellSurfEdgeKey, std::vector<double>, LessThan >& rmdCutCellSurfEdge,
00192                                 std::vector<int>& rvnInsideCell, bool isCornerExterior = true);
00193   
00203   bool get_grid_and_edges(double* boxMin, double* boxMax, int* nDiv,
00204                           std::map< CutCellSurfEdgeKey, std::vector<double>, LessThan >& rmdCutCellEdge,
00205                           std::vector<int>& rvnInsideCell, bool isCornerExterior = true);
00206   
00211   bool get_volume_fraction(int vol_frac_div);
00212   
00217   void export_mesh(const char* file_name, bool separate = false);
00218 
00222   void set_num_interval(int* n_interval);
00223 
00227   void increase_box(double box_increase);
00228 
00232   void use_whole_geom(int use);
00233 
00237   void use_mesh_geometry(bool use);
00238 
00241   void set_obb_tree_box_dimension();
00242   
00243 protected:
00244   
00245 private:
00246 
00248   EBMesher(const EBMesher &);
00249   
00250   MeshOp* get_scd_mesher();
00251 
00253   EBMesher &operator=(const EBMesher &);
00254 
00255   iBase_TagHandle m_elemStatusTag, m_edgeCutFracLengthTag,
00256     m_edgeCutFracTag, m_volFracLengthTag, m_volFracHandleTag, m_volFracTag, m_bbTag;
00257   iMesh_Instance m_mesh;
00258   iBase_EntitySetHandle m_hRootSet;
00259   std::vector<IntersectDist> m_vIntersection;
00260   int m_nTri, m_nHex, m_iInter, m_nFraction, m_iStartHex, m_nMove, m_nAddLayer,
00261     m_nIteration, m_iOverlap, m_iElem, m_nNode[3], m_nDiv[3],
00262     m_iFirstP, m_iSecondP;
00263   double m_dFirstP, m_dSecondP, m_curPnt, m_prevPnt, m_boxIncrease,
00264     m_dIntervalSize[3], m_origin_coords[3], m_dInputSize,
00265     m_min[3], m_max[3];
00266   EdgeStatus m_nStatus;
00267   bool m_bMovedOnce, m_bUseGeom, m_bUseWholeGeom, m_bUseMeshGeom;
00268   std::vector<iBase_EntityHandle> m_vhVertex;
00269   std::vector<int> m_vnHexStatus;
00270   std::map<int, CutFraction> m_mdCutFraction;
00271   std::vector<EdgeStatus> m_vnEdgeStatus[3];
00272   
00278   EdgeStatus get_edge_status(const double dZ, int& iSkip);
00279 
00287   bool set_neighbor_hex_status(int dir, int i, int j, int k);
00288 
00295   bool set_hex_status(int index, EdgeStatus value, int dir);
00296 
00301   bool set_edge_status(int dir);
00302 
00306   void set_tag_info();
00307 
00315   void write_mesh(const char* file_name, int type,
00316                   iBase_EntityHandle* handles, int& n_elem);
00317 
00323   double get_edge_fraction(int idHex, int dir);
00324 
00332   double get_uncut_edge_fraction(int i, int j, int k, int dir);
00333 
00338   bool is_shared_overlapped_surf(int index);
00339 
00346   bool move_intersections(int n_dir, int n_inter, double start_pnt[3]);
00347 
00352   bool get_inside_hex(std::vector<int>& rvnInsideCell);
00353 
00359   bool is_ray_move_and_set_overlap_surf(bool& bMoveOnce);
00360 
00361   void remove_intersection_duplicates();
00362 
00363   // test function 1 for debugging
00364   bool export_fraction_edges(std::map< CutCellSurfEdgeKey, std::vector<double>, LessThan >& rmdCutCellSurfEdge);
00365 
00366   // test functions 2 for debugging
00367   bool export_fraction_points(std::map< CutCellSurfEdgeKey, std::vector<double>, LessThan >& mdCutCellEdge);
00368 
00369   // test functions 3 for debugging
00370   bool make_edge(double ePnt[6], std::vector<iBase_EntityHandle>& edge_handles);
00371 
00373   static int init;
00374 
00375 #ifdef HAVE_MOAB
00376 
00379   MBInterface* moab_instance() {return mk_core()->moab_instance();}
00380 
00390   iBase_TagHandle get_tag(const char* name, int size, unsigned flags, MBDataType type,
00391                           const void* def_value = NULL, bool create_if_missing = true);
00392   
00399   iBase_TagHandle get_various_length_tag(const char* name,
00400                                          unsigned store, MBDataType type);
00401 
00405   int make_scd_hexes();
00406 
00410   int make_uscd_hexes();
00411 
00416   int construct_obb_tree();
00417 
00421   void set_tree_root(ModelEnt* me);
00422 
00426   void set_division();
00427 
00430   void find_intersections();
00431 
00436   void fire_rays(int dir);
00437 
00447   bool fire_ray(int& nIntersect, double startPnt[3],
00448                 double endPnt[3], double tol, int dir,
00449                 double rayLength);
00450 
00460   bool move_ray(int& nIntersect, double* startPnt, double* endPnt,
00461                 double tol, int dir, bool bMoveOnce);
00462 
00468   bool is_same_direct_to_ray(int i, int dir);
00469 
00470   // ! GeomTopoTool instance
00471   moab::GeomTopoTool* m_GeomTopoTool;
00472 
00473   // ! Tree root
00474   MBEntityHandle m_hTreeRoot;
00475 
00476   // ! OBB tree tool instance
00477   MBOrientedBoxTreeTool* m_hObbTree;
00478 
00479   // ! intersected surface geometry list
00480   std::vector<MBEntityHandle> m_vhInterSurf;
00481 
00482   // ! intersected facet list
00483   std::vector<MBEntityHandle> m_vhInterFacet;
00484 
00485   // ! overlapped surface list
00486   std::map<MBEntityHandle, int> m_mhOverlappedSurf;
00487 
00488   std::map<MBEntityHandle, MBEntityHandle>  m_mRootSets;
00489 
00490   double m_minCoord[3], m_maxCoord[3];
00491 #endif
00492 };
00493 
00494 inline void EBMesher::increase_box(double box_increase)
00495 {
00496   m_boxIncrease = box_increase;
00497 }
00498 
00499 inline void EBMesher::use_whole_geom(int use)
00500 {
00501   m_bUseWholeGeom = use;
00502 }
00503 
00504 inline void EBMesher::use_mesh_geometry(bool use)
00505 {
00506   m_bUseMeshGeom = use;
00507 }
00508 }
00509 
00510 #endif
00511 
00512   
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines