987
#if defined(HAVE_OCC_MESH_CONSTRAINTS)
989
static void _applyOCCMeshConstraintsOnVertices
990
(GModel *m, MeshGmsh_DataMapOfShapeOfVertexConstrain &constraints)
992
for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); ++it){
994
if(gv->getNativeType() != GEntity::OpenCascadeModel) continue;
995
TopoDS_Shape *s = (TopoDS_Shape*)gv->getNativePtr();
996
if(constraints.IsBound(*s)) {
997
Msg::Debug("Found mesh contraints on vertex %d", gv->tag());
998
const MeshGmsh_VertexConstrain &c(constraints.Find(*s));
1000
// 1) characteristic length constraint
1001
double lc = c.GetSize();
1003
Msg::Debug("... setting mesh size = %g", lc);
1004
gv->setPrescribedMeshSizeAtVertex(lc);
1007
// 2) embedding constraint
1008
if(c.IsEmbedded() && !c.GetFace().IsNull()){
1009
TopoDS_Shape shape = c.GetFace();
1010
Standard_Integer nodeNum;
1011
c.GetNodeNumber(nodeNum);
1012
for(GModel::fiter it2 = m->firstFace(); it2 != m->lastFace(); ++it2){
1014
if(gf->getNativeType() != GEntity::OpenCascadeModel) continue;
1015
TopoDS_Shape *shape2 = (TopoDS_Shape*)gf->getNativePtr();
1016
if(shape.IsSame(*shape2)){
1017
Msg::Debug("... embedding vertex %d in face %d", nodeNum, gf->tag());
1018
gv->mesh_vertices[0]->forceNum(nodeNum);
1019
gf->addEmbeddedVertex(gv);
1027
static void _applyOCCMeshConstraintsOnEdges
1028
(GModel *m, MeshGmsh_DataMapOfShapeOfEdgeConstrain &constraints)
1030
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it){
1032
if(ge->getNativeType() != GEntity::OpenCascadeModel) continue;
1033
TopoDS_Shape *s = (TopoDS_Shape*)ge->getNativePtr();
1034
if(constraints.IsBound(*s)) {
1035
Msg::Debug("Found mesh contraints on edge %d", ge->tag());
1036
const MeshGmsh_EdgeConstrain &c(constraints.Find(*s));
1038
// 1) prescribed mesh constraint
1039
if(c.IsMeshImposed()){
1040
TColStd_SequenceOfInteger nodeNum;
1041
c.GetNodesNumber(nodeNum);
1042
TColStd_SequenceOfReal nodePar;
1043
c.GetParameters(nodePar);
1044
int n = nodeNum.Length();
1046
Msg::Error("We need at least two points in the edge constraint");
1048
else if(nodePar.Length() != n){
1049
Msg::Error("Wrong number of parameters in edge constraint: %d != %d",
1050
nodeNum.Length(), nodePar.Length());
1053
// set the mesh as immutable
1054
ge->meshAttributes.Method = MESH_NONE;
1055
// set the correct tags on the boundary vertices
1056
bool invert = (nodePar.Value(1) > nodePar.Value(n));
1057
int numbeg = nodeNum.Value(invert ? n : 1);
1058
int numend = nodeNum.Value(invert ? 1 : n);
1059
Msg::Debug("... beg=%d end=%d", numbeg, numend);
1060
ge->getBeginVertex()->mesh_vertices[0]->forceNum(numbeg);
1061
ge->getEndVertex()->mesh_vertices[0]->forceNum(numend);
1062
// set the mesh on the edge
1063
for(int i = 2; i < n; i++){
1064
int num = nodeNum.Value(invert ? n - i + 1 : i);
1065
double u = nodePar.Value(invert ? n - i + 1 : i);
1066
GPoint p = ge->point(u);
1067
Msg::Debug("... adding mesh vertex num=%d u=%g xyz=(%g,%g,%g)",
1068
num, u, p.x(), p.y(), p.z());
1069
MEdgeVertex *v = new MEdgeVertex(p.x(), p.y(), p.z(), ge, u, -1., num);
1070
ge->mesh_vertices.push_back(v);
1072
for(unsigned int i = 0; i < ge->mesh_vertices.size() + 1; i++){
1073
MVertex *v0 = (i == 0) ?
1074
ge->getBeginVertex()->mesh_vertices[0] : ge->mesh_vertices[i - 1];
1075
MVertex *v1 = (i == ge->mesh_vertices.size()) ?
1076
ge->getEndVertex()->mesh_vertices[0] : ge->mesh_vertices[i];
1077
ge->lines.push_back(new MLine(v0, v1));
1082
// 2) embedding constraint
1083
if(c.IsEmbedded() && !c.GetFace().IsNull()){
1084
TopoDS_Shape shape = c.GetFace();
1085
for(GModel::fiter it2 = m->firstFace(); it2 != m->lastFace(); ++it2){
1087
if(gf->getNativeType() != GEntity::OpenCascadeModel) continue;
1088
TopoDS_Shape *shape2 = (TopoDS_Shape*)gf->getNativePtr();
1089
if(shape.IsSame(*shape2)){
1090
Msg::Debug("... embedding edge in face %d", gf->tag());
1091
gf->addEmbeddedEdge(ge);
1092
// the surface might have this edge as an open wire: make
1093
// sure to remove it
1094
gf->delFreeEdge(ge);
1101
// set better characteristic length for all edges with no imposed
1105
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it){
1107
for(unsigned int i = 0; i < ge->lines.size(); i++)
1108
lc_avg += ge->lines[i]->getVertex(0)->distance(ge->lines[i]->getVertex(1));
1109
num_ele += ge->lines.size();
1111
if(num_ele) lc_avg /= (double)num_ele;
1113
Msg::Debug("Setting default char length to %g", lc_avg);
1114
for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it){
1116
if(ge->meshAttributes.Method == MESH_NONE){
1117
ge->getBeginVertex()->setPrescribedMeshSizeAtVertex(lc_avg);
1118
ge->getEndVertex()->setPrescribedMeshSizeAtVertex(lc_avg);
1125
int GModel::applyOCCMeshConstraints(const void *constraints)
1127
#if defined(HAVE_OCC_MESH_CONSTRAINTS)
1128
MeshGmsh_Constrain *c = (MeshGmsh_Constrain*)constraints;
1130
MeshGmsh_DataMapOfShapeOfVertexConstrain vertexConstraints;
1131
c->GetVertexConstrain(vertexConstraints);
1132
_applyOCCMeshConstraintsOnVertices(this,vertexConstraints);
1134
MeshGmsh_DataMapOfShapeOfEdgeConstrain edgeConstraints;
1135
c->GetEdgeConstrain(edgeConstraints);
1136
_applyOCCMeshConstraintsOnEdges(this,edgeConstraints);
1145
983
void GModel::_deleteOCCInternals()