<div dir="ltr"><div>Hi Walter, <br></div><div><br></div><div>My first impression is that it looks like you might indeed be setting the mesh field value using the mesh coordinates. </div><div><br></div><div>It's a little difficult to debug without an actual runnable program or the pos file that shows everything is OK.<br></div><div>Would you mind sharing your program and pos file? <br></div><div><br></div><div>Sincerely, <br></div><div>Max <br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Nov 17, 2019 at 4:49 AM walter steffe <<a href="mailto:walter.steffe@alice.it">walter.steffe@alice.it</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Hello everyone, I am still experimenting with adaptive meshing and I wanted to set a background field based on a PView.<br>
I have build the view and related background field with the following code:<br>
<br>
<br>
//sf_ele, and getKeysValues are the same as in gmsh-4.4.1-source/demos/api/adapt_mesh.cpp<br>
getKeysValues(sf_ele, keys, values);<br>
<br>
<br>
int viewTag = gmsh::view::add("mesh size");<br>
<br>
const std::vector<double> listdata;<br>
int nelem=keys.size();<br>
for(int i=0; i<nelem ; i++){<br>
int etag=keys[i];<br>
for(int j=0; j<mesh.elements()[etag]->nodesNum(); j++) listdata.push_back(mesh.elements()[etag]->nodes()[j]->x());<br>
for(int j=0; j<mesh.elements()[etag]->nodesNum(); j++) listdata.push_back(mesh.elements()[etag]->nodes()[j]->y());<br>
for(int j=0; j<mesh.elements()[etag]->nodesNum(); j++) listdata.push_back(mesh.elements()[etag]->nodes()[j]->z());<br>
listdata.insert(listdata.end(),values[i].begin(),values[i].end());<br>
}<br>
gmsh::view::addListData(viewTag, "SS", nelem, listdata);<br>
<br>
<br>
// just to check the data: <br>
gmsh::view::write(viewTag, "data.pos");<br>
// It seems OK<br>
<br>
...<br>
<br>
GModel *gm0=new GModel();<br>
#importing of OCC geometry ...<br>
<br>
...<br>
<br>
<br>
FieldManager *fields = gm->getFields();<br>
int fieldTag=1;<br>
Field *size_f=fields->newField(fieldTag, "PostView");<br>
size_f->options["ViewTag"]->numericalValue(viewTag);<br>
fields->setBackgroundFieldId(fieldTag);<br>
<br>
<br>
gm->mesh(1); <br>
gm->mesh(2);<br>
gm->mesh(3);<br>
<br>
<br>
The problem is that the field computed in BGM_MeshSize is WRONG.<br>
<br>
Following lines are taken from BackgroundMeshTools.cpp:<br>
<br>
double BGM_MeshSize(GEntity *ge, double U, double V, double X, double Y,<br>
double Z)<br>
{<br>
....<br>
// lc from fields<br>
double l4 = MAX_LC;<br>
if(ge){<br>
FieldManager *fields = ge->model()->getFields();<br>
if(fields->getBackgroundField() > 0) {<br>
Field *f = fields->get(fields->getBackgroundField()); <br>
if(f) l4 = (*f)(X, Y, Z, ge);<br>
}<br>
}<br>
<br>
..<br>
}<br>
<br>
<br>
I have debugged the code going inside of that computation and I have found that, quite often, it happens that <br>
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.<br>
<br>
This could be produced by a wrong ordering of data passed to gmsh::view::addListData.<br>
But the data file printed by gmsh::view::write(viewTag, "data.pos") seems good and the values are not exchanged with <br>
the coordinates.<br>
<br>
So I do not understand where is the problem. May you please give me a hint ?<br>
<br>
<br>
Thanks in advance,<br>
Walter Steffè<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
gmsh mailing list<br>
<a href="mailto:gmsh@onelab.info" target="_blank">gmsh@onelab.info</a><br>
<a href="http://onelab.info/mailman/listinfo/gmsh" rel="noreferrer" target="_blank">http://onelab.info/mailman/listinfo/gmsh</a><br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div>Max Orok</div><div>Contractor<br></div></div><div dir="ltr"><a href="http://www.mevex.com" target="_blank">www.mevex.com</a><br><br><img src="https://docs.google.com/uc?export=download&id=1fHTIiW4OMUjQr1iOkspQ7wiEsxunoOs0&revid=0B6x5w-5zVaEjSkpwbm5oY29jbG1XMzJoYldXTmJpNGFtb3dVPQ" width="164" height="42"><br></div></div></div></div></div></div>