~ubuntu-branches/debian/squeeze/gmsh/squeeze

« back to all changes in this revision

Viewing changes to Geo/GModelIO_OCC.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Prud'homme, Christophe Prud'homme
  • Date: 2009-09-27 17:36:40 UTC
  • mfrom: (1.4.2 upstream)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090927173640-meoeywl4f5hq5qas
Tags: 2.4.2.dfsg-1
[Christophe Prud'homme]
* New upstream release
  + solver code refactoring
  + better IDE integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#include "OpenFile.h"
17
17
#include "OCC_Connect.h"
18
18
 
19
 
#if defined(HAVE_OCC_MESH_CONSTRAINTS)
20
 
#include "MeshGmsh_Constrain.hxx"
21
 
#include "MeshGmsh_VertexConstrain.hxx"
22
 
#include "MeshGmsh_EdgeConstrain.hxx"
23
 
#endif
24
 
 
25
19
#if defined(HAVE_OCC)
26
20
 
27
21
void OCC_Internals::buildLists()
984
978
  return 1;
985
979
}
986
980
 
987
 
#if defined(HAVE_OCC_MESH_CONSTRAINTS)
988
 
 
989
 
static void _applyOCCMeshConstraintsOnVertices
990
 
  (GModel *m, MeshGmsh_DataMapOfShapeOfVertexConstrain &constraints)
991
 
992
 
  for(GModel::viter it = m->firstVertex(); it != m->lastVertex(); ++it){
993
 
    GVertex *gv = *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));
999
 
 
1000
 
      // 1) characteristic length constraint
1001
 
      double lc = c.GetSize();
1002
 
      if(lc >= 0.){
1003
 
        Msg::Debug("... setting mesh size = %g", lc);
1004
 
        gv->setPrescribedMeshSizeAtVertex(lc);
1005
 
      }
1006
 
 
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){
1013
 
          GFace *gf = *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);
1020
 
          }
1021
 
        }
1022
 
      }
1023
 
    }
1024
 
  }
1025
 
}
1026
 
 
1027
 
static void _applyOCCMeshConstraintsOnEdges
1028
 
  (GModel *m, MeshGmsh_DataMapOfShapeOfEdgeConstrain &constraints)
1029
 
{
1030
 
  for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it){
1031
 
    GEdge *ge = *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));
1037
 
 
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();
1045
 
        if(n < 2){
1046
 
          Msg::Error("We need at least two points in the edge constraint");
1047
 
        }
1048
 
        else if(nodePar.Length() != n){
1049
 
          Msg::Error("Wrong number of parameters in edge constraint: %d != %d",
1050
 
                     nodeNum.Length(), nodePar.Length());
1051
 
        }
1052
 
        else{
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);
1071
 
          }
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));
1078
 
          }
1079
 
        }
1080
 
      }
1081
 
 
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){
1086
 
          GFace *gf = *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);
1095
 
          }
1096
 
        }
1097
 
      }
1098
 
    }
1099
 
  }
1100
 
 
1101
 
  // set better characteristic length for all edges with no imposed
1102
 
  // mesh
1103
 
  int num_ele = 0;
1104
 
  double lc_avg = 0.;
1105
 
  for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it){
1106
 
    GEdge *ge = *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();
1110
 
  }
1111
 
  if(num_ele) lc_avg /= (double)num_ele;
1112
 
  if(lc_avg){
1113
 
    Msg::Debug("Setting default char length to %g", lc_avg);
1114
 
    for(GModel::eiter it = m->firstEdge(); it != m->lastEdge(); ++it){
1115
 
      GEdge *ge = *it;
1116
 
      if(ge->meshAttributes.Method == MESH_NONE){
1117
 
        ge->getBeginVertex()->setPrescribedMeshSizeAtVertex(lc_avg);
1118
 
        ge->getEndVertex()->setPrescribedMeshSizeAtVertex(lc_avg);
1119
 
      }
1120
 
    }
1121
 
  }
1122
 
}
1123
 
#endif
1124
 
 
1125
 
int GModel::applyOCCMeshConstraints(const void *constraints)
1126
 
{
1127
 
#if defined(HAVE_OCC_MESH_CONSTRAINTS)
1128
 
  MeshGmsh_Constrain *c = (MeshGmsh_Constrain*)constraints;
1129
 
 
1130
 
  MeshGmsh_DataMapOfShapeOfVertexConstrain vertexConstraints;
1131
 
  c->GetVertexConstrain(vertexConstraints);
1132
 
  _applyOCCMeshConstraintsOnVertices(this,vertexConstraints);
1133
 
 
1134
 
  MeshGmsh_DataMapOfShapeOfEdgeConstrain edgeConstraints;
1135
 
  c->GetEdgeConstrain(edgeConstraints);
1136
 
  _applyOCCMeshConstraintsOnEdges(this,edgeConstraints);
1137
 
  return 1;
1138
 
#else
1139
 
  return 0;
1140
 
#endif
1141
 
}
1142
 
 
1143
981
#else
1144
982
 
1145
983
void GModel::_deleteOCCInternals()
1188
1026
  return 0;
1189
1027
}
1190
1028
 
1191
 
int GModel::applyOCCMeshConstraints(const void *constraints)
1192
 
{
1193
 
  Msg::Error("Gmsh must be compiled with OpenCascade support to apply "
1194
 
             "OCC mesh constraints");
1195
 
  return 0;
1196
 
}
1197
 
 
1198
1029
void GModel::addShape(std::string name, std::vector<double> &p, 
1199
1030
                      std::string op)
1200
1031
{