MeshKit  1.0
QuadMesh.cpp
Go to the documentation of this file.
00001 #include "meshkit/QuadMesh.hpp"
00002 #include "meshkit/MKCore.hpp"
00003 #include "meshkit/ModelEnt.hpp"
00004 #include "meshkit/Mesh.hpp"
00005 #include "meshkit/JaalMoabConverter.hpp"
00006 #include "meshkit/Tri2Quad.hpp"
00007 #include <vector>
00008 #include <math.h>
00009 
00010 namespace MeshKit
00011 {
00012 moab::EntityType QuadMesher_tps[] = {moab::MBVERTEX, moab::MBQUAD, moab::MBMAXTYPE};
00013 
00014 const moab::EntityType* QuadMesher::output_types()
00015   { return QuadMesher_tps; }
00016 
00017 //---------------------------------------------------------------------------//
00018 // Construction Function for Edge Mesher
00019 QuadMesher::QuadMesher(MKCore *mk_core, const MEntVector &me_vec) 
00020         : MeshScheme(mk_core, me_vec) //, schemeType(EQUAL)
00021 {
00022 }
00023 
00024 // setup function: set up the number of intervals for edge meshing through the 
00025 // sizing function
00026 void QuadMesher::setup_this()
00027 {
00028   setup_boundary();
00029    
00030     // Make sure everything has a tri mesher or is meshed 
00031   MEntVector need_trimesher;
00032   MEntSelection::iterator i;
00033   std::vector<moab::EntityType> types;
00034   std::vector<MeshOp*> ops;
00035   std::vector<MeshOp*>::iterator j;   
00036   for (i = me_selection().begin(); i != me_selection().end(); ++i) {
00037     ModelEnt* ent = i->first;
00038     if (ent->get_meshed_state() == COMPLETE_MESH)
00039       continue;
00040     ops.clear();
00041     ent->get_meshops( ops );
00042     bool found_one = false;
00043     for (j = ops.begin(); j != ops.end(); ++j) {
00044       types.clear();
00045       (*j)->mesh_types( types );
00046       if (std::find(types.begin(), types.end(), moab::MBTRI) != types.end()) {
00047         found_one = true;
00048         break;
00049       }
00050     }
00051     
00052     if (!found_one)
00053       need_trimesher.push_back( ent );
00054   }
00055   
00056   if (need_trimesher.empty())
00057     return;
00058 
00059     // find a tri mesher 
00060   std::vector<MeshOpProxy*> avail_ops;
00061   mk_core()->meshop_by_mesh_type( moab::MBTRI, avail_ops );
00062   if (avail_ops.empty())
00063     return; // throw exception or just hope that everthing already has a tri mesh?
00064   MeshOp* tri_mesher = mk_core()->construct_meshop( avail_ops.front(), need_trimesher );
00065   
00066     // tell core that the tri mesher needs to run before this
00067   mk_core()->insert_node( tri_mesher, this );
00068 }
00069 
00070 void QuadMesher::execute_this()
00071 {
00072 
00073   Jaal::Tri2Quads t2quad;
00074   JaalMoabConverter meshconverter;
00075   Jaal::Mesh *m = NULL;
00076 
00077   iMesh_Instance imesh = mk_core()->imesh_instance()->instance();
00078   MEntSelection::iterator i;
00079   for (i = me_selection().begin(); i != me_selection().end(); ++i) {
00080     ModelEnt* ent = i->first;
00081     std::unique_ptr<Jaal::Mesh> trimesh(meshconverter.fromMOAB( imesh, m, (iBase_EntitySetHandle)ent->mesh_handle() ));
00082     std::unique_ptr<Jaal::Mesh> quadmesh(t2quad.getQuadMesh( trimesh.get(), 1));
00083     meshconverter.toMOAB( quadmesh.get(), imesh, (iBase_EntitySetHandle)(ent->mesh_handle()) );
00084     ent->commit_mesh( i->second, COMPLETE_MESH );
00085   }
00086 
00087 }
00088 
00089 } // namespace MeshKit
00090 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines