MeshKit
1.0
|
00001 #include <assert.h> 00002 00003 #include "meshkit/MeshOp.hpp" 00004 #include "meshkit/MKCore.hpp" 00005 #include "meshkit/ModelEnt.hpp" 00006 00007 //#include "meshkit/FBiGeom.hpp" 00008 00009 namespace MeshKit 00010 { 00011 00012 MeshOp::MeshOp(const MeshOp &mesh_op) 00013 : GraphNode(mesh_op) 00014 { 00015 } 00016 00017 MeshOp::MeshOp(MKCore *mkcore, const MEntVector &me_vec) 00018 : GraphNode(mkcore) 00019 { 00020 if (!me_vec.empty()) { 00021 for (MEntVector::const_iterator vit = me_vec.begin(); vit != me_vec.end(); vit++) 00022 mentSelection[*vit]; 00023 } 00024 } 00025 00026 void MeshOp::setup_boundary() 00027 { 00028 // generic setup code; make sure there are MeshOp's for each of my bounding entities, and create 00029 // ones where necessary (based on default MeshOp for that dimension registered with MOF) 00030 00031 // use separate MeshOps by dimension, since there may be multiple dimension entities in mentSelection 00032 MeshOp *this_op[] = {NULL, NULL, NULL, NULL}; 00033 00034 for (MEntSelection::iterator mit = mentSelection.begin(); mit != mentSelection.end(); mit++) { 00035 ModelEnt *this_ent = (*mit).first; 00036 int dim = this_ent->dimension(); 00037 if (0 == dim) continue; 00038 if (this_ent->get_meshed_state()>=COMPLETE_MESH) 00039 continue; 00040 00041 MEntVector children; 00042 this_ent->get_adjacencies(dim-1, children); 00043 for (MEntVector::iterator chit = children.begin(); chit != children.end(); chit++) { 00044 if ((*chit)->is_meshops_list_empty()) { 00045 // no meshop, need to get one associated with this 00046 if (!this_op[dim-1]) { 00047 this_op[dim-1] = mk_core()->construct_meshop(dim-1); 00048 if (!this_op[dim-1]) throw Error(MK_MESHOP_NOT_FOUND, "No default meshop for this dimension."); 00049 } 00050 this_op[dim-1]->add_modelent(*chit); 00051 } 00052 } 00053 } 00054 00055 // VertexMesher should be inserted after root node to be done before other meshops 00056 // It is because the VertexMesher instance is only one 00057 if (this_op[0]) { 00058 mk_core()->insert_node(this_op[0], this, mk_core()->root_node()); 00059 } 00060 00061 for (int dim = 1; dim <= 3; dim++) { 00062 if (this_op[dim]) 00063 mk_core()->insert_node(this_op[dim], this); 00064 } 00065 } 00066 00067 bool MeshOp::canmesh_vertex(ModelEnt *model_ent) 00068 { 00069 return (model_ent->dimension() == 0); 00070 } 00071 00072 bool MeshOp::canmesh_edge(ModelEnt *model_ent) 00073 { 00074 return (model_ent->dimension() == 1); 00075 } 00076 00077 bool MeshOp::canmesh_face(ModelEnt *model_ent) 00078 { 00079 return (model_ent->dimension() == 2); 00080 } 00081 00082 bool MeshOp::canmesh_region(ModelEnt *model_ent) 00083 { 00084 return (model_ent->dimension() == 3); 00085 } 00086 00087 bool MeshOp::add_modelent(ModelEnt *model_ent) 00088 { 00089 MEntSelection::iterator sit = mentSelection.find(model_ent); 00090 if (sit != mentSelection.end()) return false; 00091 00092 mentSelection[model_ent]; 00093 00094 // add meshop back to model ent 00095 model_ent->add_meshop(this); 00096 00097 return true; 00098 } 00099 00100 bool MeshOp::remove_modelent(ModelEnt *model_ent) 00101 { 00102 MEntSelection::iterator sit = mentSelection.find(model_ent); 00103 if (sit != mentSelection.end()) { 00104 mentSelection.erase(sit); 00105 return true; 00106 } 00107 else return false; 00108 } 00109 00110 MeshOp::~MeshOp() 00111 { 00112 } 00113 00114 void MeshOp::mesh_types(std::vector<moab::EntityType> &mesh_types) 00115 { 00116 const moab::EntityType* types = mesh_types_arr(); 00117 for (int i = 0; types[i] != moab::MBMAXTYPE; ++i) 00118 mesh_types.push_back(types[i]); 00119 } 00120 00121 #ifdef HAVE_FBIGEOM 00122 void MeshOp::create_model_ents_from_previous_ops() 00123 { 00124 // model ents are empty so far... 00125 GraphNode * prevNode = other_node(in_arcs());// assumes one incoming edge!! 00126 00127 MeshOp * prevOp = reinterpret_cast<MeshOp*> (prevNode); 00128 std::string nameOp = prevNode->get_name(); 00129 00130 if (NULL==prevOp) 00131 return; 00132 // if the previous op is MBSplitOp or MBGeomOp, we know what to do 00133 if ( !(nameOp == "MBGeomOp" || nameOp == "MBSplitOp")) 00134 { 00135 return; // do not process yet other OPs 00136 } 00137 00138 00139 MEntSelection & mentsel = prevOp->me_selection(); 00140 if (mentsel.empty()) 00141 return; 00142 ModelEnt * firstMe = (*(mentsel.begin()) ).first; 00143 moab::Range prevModelSet = mentsel[firstMe]; 00144 00145 if (prevModelSet.size()!=1) 00146 return; 00147 00148 // this range has one set that can serve as basis for 00149 // mesh based geometry 00150 // the model ents have no model tag on the sets!! 00151 iGeom::EntitySetHandle rootSet = (iGeom::EntitySetHandle) prevModelSet[0]; 00152 00153 int latestGeomIndex = mk_core()->initialize_mesh_based_geometry(rootSet); 00154 00155 MEntVector model_ents; 00156 // get the model entities of dimension 2, created with the latest FBiGeom!!! 00157 mk_core()->get_entities_by_dimension(2, model_ents, latestGeomIndex); 00158 00159 // add it to the mentSelection!! 00160 if (model_ents.size()==0) 00161 return; // nothing to mesh .... could be an infinite loop maybe we should abort 00162 for (unsigned int i = 0; i<model_ents.size(); i++) 00163 { 00164 moab::Range rr = mentSelection[model_ents[i]]; 00165 rr.clear(); // just to use it , to avoid some warnings 00166 } 00167 00168 /*// redo the setup for the op, as we added more entities 00169 setup_this(); 00170 // we will have to also execute operations before this ... 00171 mk_core()->setup_and_execute();// will relaunch the whole execute// some are marked as 00172 // executed, so no worries*/ 00173 00174 } 00175 #endif 00176 00177 } 00178 00179