Skip to content

Commit 4c4ba24

Browse files
Nightly Botcwsmith
Nightly Bot
authored andcommitted
Merging develop into master
2 parents e305d01 + 9c3069b commit 4c4ba24

File tree

7 files changed

+49
-8
lines changed

7 files changed

+49
-8
lines changed

Diff for: apf/apfMesh.cc

+15
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ bool Mesh::canSnap()
175175
return gmi_can_eval(getModel());
176176
}
177177

178+
bool Mesh::canGetClosestPoint()
179+
{
180+
return gmi_can_get_closest_point(getModel());
181+
}
182+
178183
bool Mesh::canGetModelNormal()
179184
{
180185
return gmi_has_normal(getModel());
@@ -252,6 +257,16 @@ bool Mesh::isInClosureOf(ModelEntity* g, ModelEntity* target){
252257
return (res == 1) ? true : false;
253258
}
254259

260+
bool Mesh::isOnModel(ModelEntity* g, Vector3 p, double scale)
261+
{
262+
Vector3 to;
263+
double param[2];
264+
gmi_ent* c = (gmi_ent*)g;
265+
gmi_closest_point(getModel(), c, &p[0], &to[0], param);
266+
double ratio = (to - p).getLength() / scale;
267+
return ratio < 0.001;
268+
}
269+
255270
void Mesh::getPoint(MeshEntity* e, int node, Vector3& p)
256271
{
257272
getVector(coordinateField,e,node,p);

Diff for: apf/apfMesh.h

+4
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ class Mesh
285285
ModelEntity* findModelEntity(int type, int tag);
286286
/** \brief return true if the geometric model supports snapping */
287287
bool canSnap();
288+
/** \brief return true if the geometric model supports get closest point */
289+
bool canGetClosestPoint();
288290
/** \brief return true if the geometric model supports normal computation */
289291
bool canGetModelNormal();
290292
/** \brief evaluate parametric coordinate (p) as a spatial point (x) */
@@ -310,6 +312,8 @@ class Mesh
310312
Vector3 const& param, Vector3& x);
311313
/** \brief checks if g is in the closure of the target */
312314
bool isInClosureOf(ModelEntity* g, ModelEntity* target);
315+
/** \brief checks if p is on model g */
316+
bool isOnModel(ModelEntity* g, Vector3 p, double scale);
313317
/** \brief get the distribution of the mesh's coordinate field */
314318
FieldShape* getShape() const;
315319
/** \brief get the mesh's coordinate field */

Diff for: crv/crvBezier.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void getGregoryBlendedTransformationCoefficients(int blend, int type,
131131
apf::NewArray<double>& c);
132132

133133
/** \brief a per entity version of above */
134-
void snapToInterpolate(apf::Mesh2* m, apf::MeshEntity* e);
134+
void snapToInterpolate(apf::Mesh2* m, apf::MeshEntity* e, bool isNew = false);
135135

136136
/** \brief compute the matrix to transform between Bezier and Lagrange Points
137137
\details this is a support function, not actual ever needed.

Diff for: crv/crvCurveMesh.cc

+18-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void convertInterpolationPoints(apf::Mesh2* m, apf::MeshEntity* e,
4444
apf::destroyElement(elem);
4545
}
4646

47-
void snapToInterpolate(apf::Mesh2* m, apf::MeshEntity* e)
47+
void snapToInterpolate(apf::Mesh2* m, apf::MeshEntity* e, bool isNew)
4848
{
4949
PCU_ALWAYS_ASSERT(m->canSnap());
5050
int type = m->getType(e);
@@ -56,9 +56,18 @@ void snapToInterpolate(apf::Mesh2* m, apf::MeshEntity* e)
5656
m->setPoint(e,0,pt);
5757
return;
5858
}
59+
// e is an edge or a face
60+
// either way, get a length-scale by computing
61+
// the distance b/w first two downward verts
62+
apf::MeshEntity* down[12];
63+
m->getDownward(e, 0, down);
64+
apf::Vector3 p0, p1;
65+
m->getPoint(down[0], 0, p0);
66+
m->getPoint(down[1], 0, p1);
67+
double lengthScale = (p1 - p0).getLength();
5968
apf::FieldShape * fs = m->getShape();
6069
int non = fs->countNodesOn(type);
61-
apf::Vector3 p, xi, pt(0,0,0);
70+
apf::Vector3 p, xi, pt0, pt(0,0,0);
6271
for(int i = 0; i < non; ++i){
6372
apf::ModelEntity* g = m->toModel(e);
6473
fs->getNodeXi(type,i,xi);
@@ -67,7 +76,13 @@ void snapToInterpolate(apf::Mesh2* m, apf::MeshEntity* e)
6776
else
6877
transferParametricOnTriSplit(m,e,xi,p);
6978
m->snapToModel(g,p,pt);
70-
m->setPoint(e,i,pt);
79+
if (isNew || !m->canGetClosestPoint()) {
80+
m->setPoint(e,i,pt);
81+
continue;
82+
}
83+
m->getPoint(e,i,pt0);
84+
if (!m->isOnModel(g, pt0, lengthScale))
85+
m->setPoint(e,i,pt);
7186
}
7287
}
7388

Diff for: crv/crvShapeHandler.cc

+4-4
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class BezierTransfer : public ma::SolutionTransfer
149149
for (int i = 0; i < ne; ++i){
150150
if(shouldSnap && midEdgeVerts[i] &&
151151
isBoundaryEntity(mesh,midEdgeVerts[i])){
152-
snapToInterpolate(mesh,midEdgeVerts[i]);
152+
snapToInterpolate(mesh,midEdgeVerts[i],true);
153153
}
154154
}
155155
int np = mesh->getShape()->getEntityShape(parentType)->countNodes();
@@ -173,7 +173,7 @@ class BezierTransfer : public ma::SolutionTransfer
173173

174174
// do snapping here, inside refinement
175175
if (isBdryEnt && shouldSnap){
176-
snapToInterpolate(mesh,newEntities[i]);
176+
snapToInterpolate(mesh,newEntities[i],true);
177177
} else if (useLinear && !isBdryEnt) {
178178
// boundary entities that don't get snapped should interpolate
179179
if(childType == apf::Mesh::EDGE){
@@ -538,7 +538,7 @@ class BezierHandler : public ma::ShapeHandler
538538
if (newType != apf::Mesh::EDGE)
539539
{
540540
if (snap && P > 2){
541-
snapToInterpolate(mesh,newEntities[i]);
541+
snapToInterpolate(mesh,newEntities[i],true);
542542
convertInterpolationPoints(mesh,newEntities[i],n,ni,bt->coeffs[2]);
543543
} else {
544544
for (int j = 0; j < ni; ++j){
@@ -548,7 +548,7 @@ class BezierHandler : public ma::ShapeHandler
548548
}
549549
} else {
550550
if (snap){
551-
snapToInterpolate(mesh,newEntities[i]);
551+
snapToInterpolate(mesh,newEntities[i],true);
552552
convertInterpolationPoints(mesh,newEntities[i],n,ni,bt->coeffs[1]);
553553
} else {
554554
setLinearEdgePoints(mesh,newEntities[i]);

Diff for: gmi/gmi.c

+5
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ int gmi_can_eval(struct gmi_model* m)
8585
return m->ops->eval != NULL;
8686
}
8787

88+
int gmi_can_get_closest_point(struct gmi_model* m)
89+
{
90+
return m->ops->closest_point != NULL;
91+
}
92+
8893
int gmi_has_normal(struct gmi_model* m)
8994
{
9095
return m->ops->normal != NULL;

Diff for: gmi/gmi.h

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ struct gmi_ent* gmi_find(struct gmi_model* m, int dim, int tag);
145145
struct gmi_set* gmi_adjacent(struct gmi_model* m, struct gmi_ent* e, int dim);
146146
/** \brief check whether the model implements gmi_eval */
147147
int gmi_can_eval(struct gmi_model* m);
148+
/** \brief check whether the model gmi_closest_point */
149+
int gmi_can_get_closest_point(struct gmi_model* m);
148150
/** \brief check whether the model implements gmi_normal */
149151
int gmi_has_normal(struct gmi_model* m);
150152
/** \brief evaluate the parametric definition of a model boundary entity

0 commit comments

Comments
 (0)