How to perform a remesh operation?
Hi, I'm using gmsh in my work. But I don't know how to use it to do remesh in my problem. In my problems, assuming there are two regions A and B, A is inside B and will move to another position at next time step. The mesh inside A should keep fixed and unchanged. So region B should be remesh.
I have tried many method to do it but none of them succeed.
-
I write a geo file and call gmsh to do it. Each point has been given its mesh size. At each time step, I change region A's coordinates in geo file and recall gmsh. The results shows at different steps, the mesh points on the boundary edges of A keeps unchanged, but the number of mesh points inside A is different in different time step. And in some position, there exists over refinement problem which I tried to deal it with background mesh control, but in this situation, I can't control the mesh inside A anymore. If it can be done in geo file, can someone give me some examples?
-
After a lot of tests, I gradually realized that geo file maybe couldn't meet my requirements. So I tried to call gmsh API and also built gmsh source code with my project. thus I can know gmsh's mesh process and function. I tried to modify face A's boundary's points and remesh face B, but it tell me "Error : Unable to recover the edge 1381 (1/1661) on curve 31 (on surface 10)". Now I'm trying to understand the mesh algorithms, but it seems difficult. Here is my test function. How should I move the boundary of A and correct do B's remeshment?
void test1(){ int myargn = 6; char myargv[] = {(char)"gmsh",(char*)"-setnumber",(char*)"disp",(char*)"0.001",(char*)"-format",(char*)"msh2",(char*)"-v",(char*)"1000"}; gmsh::initialize(myargn,myargv); gmsh::option::setNumber("General.Terminal", 1); gmsh::open("JRS1250.geo"); // gmsh::model::mesh::generate(2); // GModel::current()->mesh(2); GModel* model = GModel::current(); GenerateMesh(model, 2); /** delete air domain's mesh / int tag_xiantie = 1; int tag_air = 10; double xdisp = 0; double ydisp = 1; for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it){ / delete air domain's mesh **/ if((it)->tag() == tag_air){ qDebug()<<"deleting air surface "<<tag_air; deMeshGFace dem; dem((it)); } } std::vector indexMov; for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it){ / move xiantie's mesh **/ qDebug()<<"surface tag: "<<(*it)->tag()<<"\t node num: "<<(it)->getNumMeshVertices(); if((it)->tag() == tag_xiantie){ qDebug()<<"moving armature mesh..."; / modify the mesh points **/ for(std::size_t j = 0; j < (*it)->getNumMeshVertices(); j++) { (*it)->getMeshVertex(j)->setXYZ((*it)->getMeshVertex(j)->x()-xdisp, (it)->getMeshVertex(j)->y()-ydisp, (it)->getMeshVertex(j)->z()); } / modify the mesh point on the edge **/ std::set<MVertex *, MVertexLessThanNum> all_vertices; for(auto e : (*it)->edges()){ // all_vertices.clear(); qDebug()<<"edge tag: "<tag()<<"\t node num: "<getNumMeshVertices(); indexMov.push_back(e->tag()); for(auto line : e->lines){ MVertex *v1 = line->getVertex(0); MVertex *v2 = line->getVertex(1);
all_vertices.insert(v1);
all_vertices.insert(v2);
}
}
qDebug()<<"all_vertices size:"<<all_vertices.size();
for(std::set<MVertex *, MVertexLessThanNum>::iterator ite = all_vertices.begin();ite != all_vertices.end(); ite++) {
(*ite)->setXYZ((*ite)->x()-xdisp,
(*ite)->y()-ydisp,
(*ite)->z());
}
/** 修改几何顶点坐标 **/
// qDebug()<<"bound vertice size:"<<(*it)->vertices().size(); // for(auto v : (*it)->vertices()){ // qDebug()<<"vertice tag:"<tag()<<"\t num: "<getNumMeshVertices(); // for(std::size_t j = 0; j < v->getNumMeshVertices(); j++){ // qDebug()<tag()<<" x:"<getMeshVertex(j)->x()-xdisp<<"y:"<getMeshVertex(j)->y()-ydisp; // v->getMeshVertex(j)->setXYZ(v->getMeshVertex(j)->x()-xdisp, // v->getMeshVertex(j)->y()-ydisp, // v->getMeshVertex(j)->z()); // } // } } }
for(GModel::fiter it = model->firstFace(); it != model->lastFace(); ++it){
/** remesh air domain **/
if((*it)->tag() == tag_air){
qDebug()<<"remesh air domain...";
(*it)->mesh(true);
}
}
gmsh::write("JRS1250.msh");
gmsh::finalize();
qDebug()<<"结束";
}