void backgroundMesh2D::unset() { for (unsigned int i = 0; i < vertices.size(); i++) delete vertices[i]; for (unsigned int i = 0; i < getNumMeshElements(); i++) delete elements[i]; if (octree)delete octree; octree=NULL; }
void BGMBase::export_vector(const std::string &filename, const VectorStorageType &_whatToPrint) const { FILE *f = Fopen(filename.c_str(), "w"); if(!f) { Msg::Error("Could not open file '%s'", filename.c_str()); return; } fprintf(f, "View \"Background Mesh\"{\n"); const MElement *elem; int nvertex; int type; for(unsigned int i = 0; i < getNumMeshElements(); i++) { elem = getElement(i); nvertex = elem->getNumVertices(); type = elem->getType(); const char *s = 0; switch(type) { case TYPE_PNT: s = "VP"; break; case TYPE_LIN: s = "VL"; break; case TYPE_TRI: s = "VT"; break; case TYPE_QUA: s = "VQ"; break; case TYPE_TET: s = "VS"; break; case TYPE_HEX: s = "VH"; break; case TYPE_PRI: s = "VI"; break; case TYPE_PYR: s = "VY"; break; default: throw; } fprintf(f, "%s(", s); const MVertex *v; std::vector<double> values(nvertex * 3); for(int iv = 0; iv < nvertex; iv++) { v = elem->getVertex(iv); std::vector<double> temp = get_nodal_value(v, _whatToPrint); for(int j = 0; j < 3; j++) values[iv * 3 + j] = temp[j]; GPoint p = get_GPoint_from_MVertex(v); fprintf(f, "%g,%g,%g", p.x(), p.y(), p.z()); if(iv != nvertex - 1) fprintf(f, ","); else fprintf(f, "){"); } for(int iv = 0; iv < nvertex; iv++) { for(int j = 0; j < 3; j++) { fprintf(f, "%g", values[iv * 3 + j]); if(!((iv == nvertex - 1) && (j == 2))) fprintf(f, ","); else fprintf(f, "};\n"); } } } fprintf(f, "};\n"); fclose(f); }
void BGMBase::export_scalar(const std::string &filename, const DoubleStorageType &_whatToPrint) const { FILE *f = Fopen(filename.c_str(), "w"); if(!f) { Msg::Error("Could not open file '%s'", filename.c_str()); return; } fprintf(f, "View \"Background Mesh\"{\n"); const MElement *elem; int nvertex; int type; for(unsigned int i = 0; i < getNumMeshElements(); i++) { elem = getElement(i); nvertex = elem->getNumVertices(); type = elem->getType(); const char *s = 0; switch(type) { case TYPE_PNT: s = "SP"; break; case TYPE_LIN: s = "SL"; break; case TYPE_TRI: s = "ST"; break; case TYPE_QUA: s = "SQ"; break; case TYPE_TET: s = "SS"; break; case TYPE_HEX: s = "SH"; break; case TYPE_PRI: s = "SI"; break; case TYPE_PYR: s = "SY"; break; default: throw; } fprintf(f, "%s(", s); const MVertex *v; std::vector<double> values(nvertex); for(int iv = 0; iv < nvertex; iv++) { v = elem->getVertex(iv); values[iv] = get_nodal_value(v, _whatToPrint); // GPoint p = gf->point(SPoint2(v->x(),v->y())); GPoint p = get_GPoint_from_MVertex(v); fprintf(f, "%g,%g,%g", p.x(), p.y(), p.z()); if(iv != nvertex - 1) fprintf(f, ","); else fprintf(f, "){"); } for(int iv = 0; iv < nvertex; iv++) { fprintf(f, "%g", values[iv]); if(iv != nvertex - 1) fprintf(f, ","); else fprintf(f, "};\n"); } } fprintf(f, "};\n"); fclose(f); }
void backgroundMesh2D::updateSizes() { DoubleStorageType::iterator itv = sizeField.begin(); for ( ; itv != sizeField.end(); ++itv) { SPoint2 p; MVertex *v = _2Dto3D[itv->first]; double lc; if (v->onWhat()->dim() == 0) { lc = sizeFactor * BGM_MeshSize(v->onWhat(), 0,0,v->x(),v->y(),v->z()); } else if (v->onWhat()->dim() == 1) { double u; v->getParameter(0, u); lc = sizeFactor * BGM_MeshSize(v->onWhat(), u, 0, v->x(), v->y(), v->z()); } else { GFace *face = dynamic_cast<GFace*>(gf); if(!face) { Msg::Error("Entity is not a face in background mesh"); return; } reparamMeshVertexOnFace(v, face, p); lc = sizeFactor * BGM_MeshSize(face, p.x(), p.y(), v->x(), v->y(), v->z()); } // printf("2D -- %g %g 3D -- %g %g\n",p.x(),p.y(),v->x(),v->y()); itv->second = min(lc,itv->second); itv->second = max(itv->second, sizeFactor * CTX::instance()->mesh.lcMin); itv->second = min(itv->second, sizeFactor * CTX::instance()->mesh.lcMax); } // do not allow large variations in the size field // (Int. J. Numer. Meth. Engng. 43, 1143-1165 (1998) MESH GRADATION // CONTROL, BOROUCHAKI, HECHT, FREY) std::set<MEdge,Less_Edge> edges; for (unsigned int i = 0; i < getNumMeshElements(); i++) { for (int j = 0; j < getElement(i)->getNumEdges(); j++) { edges.insert(getElement(i)->getEdge(j)); } } const double _beta = 1.3; for (int i=0; i<0; i++) { std::set<MEdge,Less_Edge>::iterator it = edges.begin(); for ( ; it != edges.end(); ++it) { MVertex *v0 = it->getVertex(0); MVertex *v1 = it->getVertex(1); MVertex *V0 = _2Dto3D[v0]; MVertex *V1 = _2Dto3D[v1]; DoubleStorageType::iterator s0 = sizeField.find(V0); DoubleStorageType::iterator s1 = sizeField.find(V1); if (s0->second < s1->second)s1->second = min(s1->second,_beta*s0->second); else s0->second = min(s0->second,_beta*s1->second); } } }