示例#1
0
int main(int argc, char **argv)
{
  GmshInitialize(argc, argv);
  GmshSetOption("Mesh", "Algorithm", 5.);
  GmshSetOption("General", "Terminal", 1.);

  GModel *m = new GModel();
  m->readMSH("bunny.msh");
  m->fillVertexArrays();

  std::vector<GEntity*> entities;
  m->getEntities(entities);

  for(unsigned int i = 0; i < entities.size(); i++){
    GEntity *ge = entities[i];
    printf("coucou entite %d (dimension %d)\n", ge->tag(), ge->dim());
    if(ge->va_triangles)
      printf("  j'ai un va de triangles: %d vertex\n", ge->va_triangles->getNumVertices());
    if(ge->va_lines)
      printf("  j'ai un va de lignes: %d vertex\n", ge->va_lines->getNumVertices());
  }

  delete m;
  GmshFinalize();
}
示例#2
0
static void setGmshOption(T &n)
{
  std::string opt = n.getAttribute("GmshOption");
  if(opt.empty()) return;
  if(opt == "ResetDatabase"){ // special option to reset the onelab db
    OnelabDatabase::instance()->clear();
    //TODO OnelabDatabase::instance()->reset(false);
    //FlGui::instance()->rebuildTree(false);
    return;
  }
  if(opt == "Reset"){ // reset db + models except current one
    OnelabDatabase::instance()->clear();
    //TODO OnelabDatabase::instance()->reset(false);
    //for(int i = PView::list.size() - 1; i >= 0; i--)
    //  delete PView::list[i];
    //for(int i = GModel::list.size() - 1; i >= 0; i--)
    //  if(GModel::list[i] != GModel::current()) delete GModel::list[i];
    //FlGui::instance()->rebuildTree(false);
    return;
  }
  std::string::size_type dot = opt.find('.');
  if(dot == std::string::npos) return;
  GmshSetOption(opt.substr(0, dot), opt.substr(dot + 1), n.getValue());
  drawContext::global()->draw();
}
示例#3
0
void drawContext::load(std::string filename)
{
  if(locked) return;

  // delete all models and post-processing views
  GmshClearProject();

  // reset onelab database
  onelab::server::instance()->clear();

  // restore default options
  GmshRestoreDefaultOptions();

  // output messages on console
  GmshSetOption("General", "Terminal", 1.0);

  // open the file with Gmsh
  GmshOpenProject(filename);

  // reset openGL view
  eventHandler(10);

  // run onelab clients to populate the database
  onelab_cb("check");

  // mark all parameters as changed to force complete first run
  onelab::server::instance()->setChanged(true);
}
示例#4
0
 JNIEXPORT jint JNICALL Java_org_geuz_onelab_Gmsh_setIntegerOption
 (JNIEnv *env, jobject obj, jstring c, jstring n, jint v)
 {
   const char* tmp;
   tmp = env->GetStringUTFChars(n, NULL);
   const std::string name(tmp, strlen(tmp));
   env->ReleaseStringUTFChars(n, tmp);
   tmp = env->GetStringUTFChars(c, NULL);
   const std::string category(tmp, strlen(tmp));
   env->ReleaseStringUTFChars(c, tmp);
   GmshSetOption(category, name, (unsigned int)v);
 }
示例#5
0
drawContext::drawContext(float fontFactor, bool retina)
{
  GmshInitialize();
  GmshSetOption("General", "Terminal", 1.0);
  onelabUtils::setFirstComputationFlag(false);
  for(int i = 0; i < 3; i++){
    _translate[i] = 0.;
    _scale[i] = 1.;
  }
  setQuaternion(0., 0., 0., 1.);
  _fontFactor = fontFactor;
  _retina = retina;
}
示例#6
0
void gcm::Geo2MeshLoader::createMshFile(string fileName, float tetrSize)
{
    Engine& engine = Engine::getInstance();

    if( engine.getNumberOfWorkers() > 1 )
    {
        if( engine.getRank() != 0 )
        {
            MPI::COMM_WORLD.Barrier();
            createdFiles[fileName] = true;
            return;
        }
    }
    /*
     * TODO@ashevtsov: I don't really understand the meaning of all these options, values
     * have been guessed to get a mesh with acceptable tetrahedra sizes.
     * In future need to undestand GMsh meshing algorithms and set these options correctly.
     */
    LOG_DEBUG("loadGeoScriptFile (" << fileName << "): will mesh with H = " << tetrSize);
    GmshSetOption("General", "Terminal", 1.0);
    GmshSetOption("General", "Verbosity", engine.getGmshVerbosity());
    GmshSetOption("Mesh", "CharacteristicLengthMin", tetrSize);
    GmshSetOption("Mesh", "CharacteristicLengthMax", tetrSize);
    GmshSetOption("Mesh", "Optimize", 1.0);

    GModel gmshModel;
    gmshModel.setFactory ("Gmsh");
    gmshModel.readGEO (fileName);
    LOG_INFO("Creating mesh using gmsh library");
    gmshModel.mesh (3);
    gmshModel.writeMSH (getMshFileName(fileName));
    createdFiles[fileName] = true;

    if (engine.getNumberOfWorkers() > 1)
        MPI::COMM_WORLD.Barrier();
}
示例#7
0
int main(int argc,char *argv[])
{
  if(argc < 6){
    printf("Usage: %s file lx ly lz rmax [levels=1] [refcs=1]\n", argv[0]);
    printf("where\n");
    printf("  'file' contains a CAD model\n");
    printf("  'lx', 'ly' and 'lz' are the sizes of the elements along the"
           " x-, y- and z-axis at the coarsest level\n");
    printf("  'rmax' is the radius of the largest sphere that can be inscribed"
           " in the structure\n");
    printf("  'levels' sets the number of levels in the grid\n");
    printf("  'refcs' selects if curved surfaces should be refined\n");
    return -1;
  }

  GmshInitialize();
  GmshSetOption("General", "Terminal", 1.);
  GmshMergeFile(argv[1]);
  double lx = atof(argv[2]), ly = atof(argv[3]), lz = atof(argv[4]);
  double rmax = atof(argv[5]);
  int levels = (argc > 6) ? atof(argv[6]) : 1;
  int refineCurvedSurfaces = (argc > 7) ? atof(argv[7]) : 1;

  // minimum distance between points in the cloud at the coarsest
  // level
  double sampling = std::min(rmax, std::min(lx, std::min(ly, lz)));

  // radius of the "tube" created around parts to refine at the
  // coarsest level
  double rtube = std::max(lx, std::max(ly, lz)) * 2.;

  GModel *gm = GModel::current();

  std::vector<SPoint3> points;
  Msg::Info("Filling coarse point cloud on surfaces");
  for (GModel::fiter fit = gm->firstFace(); fit != gm->lastFace(); fit++)
    (*fit)->fillPointCloud(sampling, &points);
  Msg::Info("  %d points in the surface cloud", (int)points.size());

  std::vector<SPoint3> refinePoints;
  if(levels > 1){
    double s = sampling / pow(2., levels - 1);
    Msg::Info("Filling refined point cloud on curves and curved surfaces");
    for (GModel::eiter eit = gm->firstEdge(); eit != gm->lastEdge(); eit++)
      fillPointCloud(*eit, s, refinePoints);

    // FIXME: refine this by computing e.g. "mean" curvature
    if(refineCurvedSurfaces){
      for (GModel::fiter fit = gm->firstFace(); fit != gm->lastFace(); fit++)
        if((*fit)->geomType() != GEntity::Plane)
          (*fit)->fillPointCloud(2 * s, &refinePoints);
    }
    Msg::Info("  %d points in the refined cloud", (int)refinePoints.size());
  }

  SBoundingBox3d bb;
  for(unsigned int i = 0; i < points.size(); i++) bb += points[i];
  for(unsigned int i = 0; i < refinePoints.size(); i++) bb += refinePoints[i];
  bb.scale(1.21, 1.21, 1.21);
  SVector3 range = bb.max() - bb.min();
  int NX = range.x() / lx;
  int NY = range.y() / ly;
  int NZ = range.z() / lz;
  if(NX < 2) NX = 2;
  if(NY < 2) NY = 2;
  if(NZ < 2) NZ = 2;

  Msg::Info("  bounding box min: %g %g %g -- max: %g %g %g",
            bb.min().x(), bb.min().y(), bb.min().z(),
            bb.max().x(), bb.max().y(), bb.max().z());
  Msg::Info("  Nx=%d Ny=%d Nz=%d", NX, NY, NZ);

  cartesianBox<double> box(bb.min().x(), bb.min().y(), bb.min().z(),
                           SVector3(range.x(), 0, 0),
                           SVector3(0, range.y(), 0),
                           SVector3(0, 0, range.z()),
                           NX, NY, NZ, levels);

  Msg::Info("Inserting active cells in the cartesian grid");
  Msg::Info("  level %d", box.getLevel());
  for (unsigned int i = 0; i < points.size(); i++)
    insertActiveCells(points[i].x(), points[i].y(), points[i].z(), rmax, box);

  cartesianBox<double> *parent = &box, *child;
  while((child = parent->getChildBox())){
    Msg::Info("  level %d", child->getLevel());
    for(unsigned int i = 0; i < refinePoints.size(); i++)
      insertActiveCells(refinePoints[i].x(), refinePoints[i].y(), refinePoints[i].z(),
                        rtube / pow(2., (levels - child->getLevel())), *child);
    parent = child;
  }

  // remove child cells that do not entirely fill parent cell or for
  // which there is no parent neighbor; then remove parent cells that
  // have children
  Msg::Info("Removing cells to match X-FEM mesh topology constraints");
  removeBadChildCells(&box);
  removeParentCellsWithChildren(&box);

  // we generate duplicate nodes at this point so we can easily access
  // cell values at each level; we will clean up by renumbering after
  // filtering
  Msg::Info("Initializing nodal values in the cartesian grid");
  box.createNodalValues();

  Msg::Info("Computing levelset on the cartesian grid");
  computeLevelset(gm, box);

  Msg::Info("Removing cells outside the structure");
  removeOutsideCells(&box);

  Msg::Info("Renumbering mesh vertices across levels");
  box.renumberNodes();

  bool decomposeInSimplex = false;
  box.writeMSH("yeah.msh", decomposeInSimplex);

  Msg::Info("Done!");
  GmshFinalize();
}