[Gmsh] adaptive meshing: using PView

walter steffe walter.steffe at alice.it
Sun Nov 17 10:45:51 CET 2019


Hello everyone, I am still experimenting with adaptive meshing and I wanted to set a background field based on a PView.
I have build the view and related background field with the following code:


 //sf_ele, and getKeysValues are the same as in gmsh-4.4.1-source/demos/api/adapt_mesh.cpp
  getKeysValues(sf_ele, keys, values);


  int viewTag = gmsh::view::add("mesh size");

  const std::vector<double> listdata;
  int nelem=keys.size();
  for(int i=0; i<nelem ; i++){
    int etag=keys[i];
    for(int j=0; j<mesh.elements()[etag]->nodesNum(); j++) listdata.push_back(mesh.elements()[etag]->nodes()[j]->x());
    for(int j=0; j<mesh.elements()[etag]->nodesNum(); j++) listdata.push_back(mesh.elements()[etag]->nodes()[j]->y());
    for(int j=0; j<mesh.elements()[etag]->nodesNum(); j++) listdata.push_back(mesh.elements()[etag]->nodes()[j]->z());
    listdata.insert(listdata.end(),values[i].begin(),values[i].end());
  }
  gmsh::view::addListData(viewTag, "SS", nelem, listdata);

  
  // just to check the data: 
  gmsh::view::write(viewTag, "data.pos");
  // It seems OK

  ...

  GModel *gm0=new GModel();
  #importing of OCC geometry ...

  ...
  

  FieldManager *fields = gm->getFields();
  int fieldTag=1;
  Field *size_f=fields->newField(fieldTag, "PostView");
  size_f->options["ViewTag"]->numericalValue(viewTag);
  fields->setBackgroundFieldId(fieldTag);


  gm->mesh(1);     
  gm->mesh(2);
  gm->mesh(3);


  The problem is that the field computed in BGM_MeshSize is WRONG.

  Following lines are taken from BackgroundMeshTools.cpp:
 
  double BGM_MeshSize(GEntity *ge, double U, double V, double X, double Y,
                    double Z)
{
  ....
  // lc from fields
  double l4 = MAX_LC;
  if(ge){
    FieldManager *fields = ge->model()->getFields();
    if(fields->getBackgroundField() > 0) {
      Field *f = fields->get(fields->getBackgroundField());  
      if(f) l4 = (*f)(X, Y, Z, ge);
    }
  }
 
  ..
}


  I have debugged the code going inside of that computation and I have found that, quite often, it happens that 
  the value returned by (*f)(X, Y, Z, ge) coincides with the coordinate (x,y,or z) of a vertex used in the view data.

  This could be produced by a wrong ordering of data passed to gmsh::view::addListData.
  But the data file printed by gmsh::view::write(viewTag, "data.pos") seems good and the values are not exchanged with 
  the coordinates.

  So I do not understand where is the problem. May you please give me a hint ?


  Thanks in advance,
  Walter Steffè


  
 
  


  




More information about the gmsh mailing list