6 #include <apfDynamicVector.h>
7 #include <apfCavityOp.h>
12 #include <samElementCount.h>
16 static void SmoothField(apf::Field *
f);
22 static double isotropicFormula(
double phi,
double dphi,
double verr,
double hmin,
double hmax,
double phi_s = 0,
double epsFact = 0)
25 double dphi_size_factor;
27 if (fabs(phi_s) < (epsFact*7.5) * hmin)
33 static void setSizeField(apf::Mesh2 *m,apf::MeshEntity *vertex,
double h,apf::MeshTag *marker,apf::Field* sizeField)
37 if(m->hasTag(vertex,marker))
41 h_new =
std::min(h,apf::getScalar(sizeField,vertex,0));
46 m->setIntTag(vertex,marker,&newMark);
48 apf::setScalar(sizeField,vertex,0,h_new);
51 if(!m->isOwned(vertex))
54 m->getRemotes(vertex,remotes);
55 int owningPart=m->getOwner(vertex);
56 PCU_COMM_PACK(owningPart, remotes[owningPart]);
57 PCU_COMM_PACK(owningPart, h_new);
64 size_iso = apf::createLagrangeField(m,
"proteus_size", apf::SCALAR, 1);
66 apf::MeshIterator *it = m->begin(0);
68 while ((ent = m->iterate(it)))
70 int modelTag = m->getModelTag(m->toModel(ent));
77 apf::setScalar(size_iso,ent,0,sizeDesired);
88 if(m->findField(
"interfaceBand"))
89 apf::destroyField(m->findField(
"interfaceBand"));
91 apf::Field* interfaceBand = apf::createLagrangeField(m,
"interfaceBand", apf::SCALAR, 1);
92 apf::Field *phif = m->findField(
"phi");
95 apf::MeshTag* vertexMarker = m->createIntTag(
"vertexMarker",1);
96 apf::MeshIterator *it = m->begin(1);
97 apf::MeshEntity *edge;
102 while ((edge = m->iterate(it)))
104 apf::Adjacent edge_adjVerts;
105 m->getAdjacent(edge,0,edge_adjVerts);
106 apf::MeshEntity *vertex1 = edge_adjVerts[0];
107 apf::MeshEntity *vertex2 = edge_adjVerts[1];
108 double phi1 = apf::getScalar(phif,vertex1,0);
109 double phi2 = apf::getScalar(phif,vertex2,0);
111 if(std::fabs(phi1)>L_band)
113 if(std::fabs(phi2)>L_band)
116 if(caseNumber==1 || caseNumber == 2)
118 setSizeField(m,vertex1,
hPhi,vertexMarker,interfaceBand);
119 setSizeField(m,vertex2,
hPhi,vertexMarker,interfaceBand);
125 setSizeField(m,vertex1,
hPhi,vertexMarker,interfaceBand);
126 setSizeField(m,vertex2,
hPhi,vertexMarker,interfaceBand);
130 setSizeField(m,vertex1,
hmax,vertexMarker,interfaceBand);
131 setSizeField(m,vertex2,
hmax,vertexMarker,interfaceBand);
140 apf::MeshEntity *ent;
142 while(PCU_Comm_Receive())
145 PCU_COMM_UNPACK(ent);
146 PCU_COMM_UNPACK(h_received);
148 double h_current = apf::getScalar(interfaceBand,ent,0);
149 double h_final =
std::min(h_current,h_received);
150 apf::setScalar(interfaceBand,ent,0,h_final);
154 apf::synchronize(interfaceBand);
157 m->destroyTag(vertexMarker);
160 sizeFieldList.push(interfaceBand);
166 apf::Mesh* m = apf::getMesh(levelSet);
167 apf::Adjacent edge_adjVerts;
168 m->getAdjacent(edge,0,edge_adjVerts);
169 apf::MeshEntity *vertex1 = edge_adjVerts[0];
170 apf::MeshEntity *vertex2 = edge_adjVerts[1];
171 double phi1 = apf::getScalar(levelSet,vertex1,0);
172 double phi2 = apf::getScalar(levelSet,vertex2,0);
173 int doesIntersect = 0;
176 return doesIntersect;
193 apf::MeshEntity* vert = inputObject.
vertex;
195 double L_local = inputObject.
L_local;
196 double direction = inputObject.
direction;
198 apf::MeshTag* vertexMaxTraverse = m->findTag(
"maximumTraversal");
199 apf::Field* predictInterfaceBand = m->findField(
"predictInterfaceBand");
200 apf::Field* levelSet = m->findField(
"phi");
202 apf::Vector3 pt_vert;
203 m->getPoint(vert,0,pt_vert);
204 apf::Vector3 difference_vect = pt_vert-actualPosition;
207 int dontContinue = 0;
208 if(m->hasTag(vert,vertexMaxTraverse))
210 double traversalDistance;
211 m->getDoubleTag(vert,vertexMaxTraverse,&traversalDistance);
212 if((L_local-difference_vect.getLength()) < traversalDistance*1.01)
217 double phiCurrent = apf::getScalar(levelSet,vert,0);
218 if((difference_vect.getLength() > L_local) || dontContinue || (phiCurrent*direction<=0))
232 markedVertices.pop();
235 apf::MeshEntity* vert = inputObject.
vertex;
237 double L_local = inputObject.
L_local;
238 double direction = inputObject.
direction;
241 apf::MeshTag* vertexMaxTraverse = m->findTag(
"maximumTraversal");
242 apf::Field* predictInterfaceBand = m->findField(
"predictInterfaceBand");
243 apf::Field* levelSet = m->findField(
"phi");
247 apf::Adjacent vertex_adjVerts;
248 apf::getBridgeAdjacent(m,vert,1,0,vertex_adjVerts);
249 for(
int i=0;i<vertex_adjVerts.getSize();i++)
252 apf::MeshEntity* newVert = vertex_adjVerts[i];
253 inputObject.
vertex=newVert;
259 apf::Vector3 pt_vert;
260 m->getPoint(newVert,0,pt_vert);
261 apf::Vector3 difference_vect = pt_vert-actualPosition;
263 double traversalDistance = L_local-difference_vect.getLength();
264 m->setDoubleTag(newVert,vertexMaxTraverse,&traversalDistance);
267 apf::setScalar(predictInterfaceBand,newVert,0,apf::getScalar(predictInterfaceBand,vert,0));
269 inputObject.
vertex = newVert;
270 markedVertices.push(inputObject);
272 if(m->isShared(newVert))
274 int initialRank = PCU_Comm_Self();
275 double desiredSize = apf::getScalar(predictInterfaceBand,vert,0);
277 m->getRemotes(newVert,remotes);
278 for(apf::Copies::iterator iter=remotes.begin(); iter!=remotes.end();++iter)
280 PCU_COMM_PACK(iter->first, iter->second);
281 PCU_COMM_PACK(iter->first, L_local);
282 PCU_COMM_PACK(iter->first, actualPosition);
283 PCU_COMM_PACK(iter->first, direction);
284 PCU_COMM_PACK(iter->first, initialRank);
285 PCU_COMM_PACK(iter->first, inputObject.
edgeID);
286 PCU_COMM_PACK(iter->first, desiredSize);
293 return needsParallel;
301 apf::Field* interfaceBand = m->findField(
"interfaceBand");
302 apf::Field* velocity = m->findField(
"velocity");
303 apf::Field* levelSet = m->findField(
"phi");
306 apf::Field *gradphi = apf::recoverGradientByVolume(levelSet);
308 apf::Field* predictInterfaceBand = apf::createLagrangeField(m,
"predictInterfaceBand",apf::SCALAR,1);
309 apf::copyData(predictInterfaceBand,interfaceBand);
312 apf::MeshTag* vertexMaxTraverse = m->createDoubleTag(
"maximumTraversal",1);
314 apf::MeshEntity* edge;
315 apf::MeshIterator* it = m->begin(1);
317 std::queue <edgeWalkerInfo> markedVertices;
320 while( (edge = m->iterate(it)) )
325 apf::Adjacent edge_adjVerts;
326 m->getAdjacent(edge,0,edge_adjVerts);
327 apf::MeshEntity *vertex1 = edge_adjVerts[0];
328 apf::MeshEntity *vertex2 = edge_adjVerts[1];
329 double phi1 = apf::getScalar(levelSet,vertex1,0);
330 double phi2 = apf::getScalar(levelSet,vertex2,0);
331 apf::Vector3 pt_1, pt_2;
332 m->getPoint(vertex1,0,pt_1);
333 m->getPoint(vertex2,0,pt_2);
334 apf::Vector3 edgeVector = pt_2-pt_1;
336 double zeroPosition = 2*(-phi1/(phi2-phi1))-1.0;
337 double relativePosition = -phi1/(phi2-phi1);
338 apf::Vector3 actualPosition = (pt_2-pt_1)*relativePosition + pt_1;
340 apf::Vector3 edgePoint(zeroPosition,0.0,0.0);
341 apf::Element* phiElem = apf::createElement(levelSet,edge);
342 apf::Element* gradPhiElem = apf::createElement(gradphi,edge);
343 apf::Element* velocityElem = apf::createElement(velocity,edge);
344 apf::Vector3 localVelocity;
345 apf::getVector(velocityElem,edgePoint,localVelocity);
346 apf::Vector3 localInterfaceNormal;
347 apf::getVector(gradPhiElem,edgePoint,localInterfaceNormal);
348 apf::destroyElement(phiElem);
349 apf::destroyElement(velocityElem);
350 apf::destroyElement(gradPhiElem);
353 double L_local = localVelocity.getLength()*
numAdaptSteps*delta_T;
358 double signValue = localVelocity*localInterfaceNormal;
361 for(
int i=0; i<edge_adjVerts.getSize();i++)
364 inputObject.
vertex = edge_adjVerts[i];
372 markedVertices.push(inputObject);
375 if(m->isShared(inputObject.
vertex))
377 int initialRank = PCU_Comm_Self();
378 double desiredSize = apf::getScalar(predictInterfaceBand,inputObject.
vertex,0);
380 m->getRemotes(inputObject.
vertex,remotes);
381 for(apf::Copies::iterator iter=remotes.begin(); iter!=remotes.end();++iter)
383 PCU_COMM_PACK(iter->first, iter->second);
384 PCU_COMM_PACK(iter->first, L_local);
385 PCU_COMM_PACK(iter->first, actualPosition);
386 PCU_COMM_PACK(iter->first, inputObject.
direction);
387 PCU_COMM_PACK(iter->first, initialRank);
388 PCU_COMM_PACK(iter->first, inputObject.
edgeID);
389 PCU_COMM_PACK(iter->first, desiredSize);
402 while(PCU_Comm_Receive())
404 apf::MeshEntity* vertex;
406 apf::Vector3 actualPosition;
411 PCU_COMM_UNPACK(vertex);
412 PCU_COMM_UNPACK(L_local);
413 PCU_COMM_UNPACK(actualPosition);
414 PCU_COMM_UNPACK(direction);
415 PCU_COMM_UNPACK(initialRank);
416 PCU_COMM_UNPACK(edgeID);
417 PCU_COMM_UNPACK(desiredSize);
420 inputObject.
vertex = vertex;
424 inputObject.
edgeID = edgeID;
428 if(desiredSize < apf::getScalar(predictInterfaceBand,vertex,0))
429 apf::setScalar(predictInterfaceBand,vertex,0,desiredSize);
433 apf::Vector3 pt_vert;
434 m->getPoint(vertex,0,pt_vert);
435 apf::Vector3 difference_vect = pt_vert-actualPosition;
437 double traversalDistance = L_local-difference_vect.getLength();
438 m->setDoubleTag(vertex,vertexMaxTraverse,&traversalDistance);
440 markedVertices.push(inputObject);
447 while(needsParallel>0)
454 while(!markedVertices.empty())
458 PCU_Add_Ints(&needsParallel,1);
461 while( PCU_Comm_Receive() )
463 apf::MeshEntity* vertex;
465 apf::Vector3 actualPosition;
470 PCU_COMM_UNPACK(vertex);
471 PCU_COMM_UNPACK(L_local);
472 PCU_COMM_UNPACK(actualPosition);
473 PCU_COMM_UNPACK(direction);
474 PCU_COMM_UNPACK(initialRank);
475 PCU_COMM_UNPACK(edgeID);
476 PCU_COMM_UNPACK(desiredSize);
480 inputObject.
vertex = vertex;
484 inputObject.
edgeID = edgeID;
488 if(desiredSize < apf::getScalar(predictInterfaceBand,vertex,0))
489 apf::setScalar(predictInterfaceBand,vertex,0,desiredSize);
493 apf::Vector3 pt_vert;
494 m->getPoint(vertex,0,pt_vert);
495 apf::Vector3 difference_vect = pt_vert-actualPosition;
497 double traversalDistance = L_local-difference_vect.getLength();
498 m->setDoubleTag(vertex,vertexMaxTraverse,&traversalDistance);
500 markedVertices.push(inputObject);
505 apf::copyData(interfaceBand,predictInterfaceBand);
506 apf::destroyField(predictInterfaceBand);
507 apf::destroyField(gradphi);
510 apf::MeshIterator* tagIt = m->begin(0);
511 apf::MeshEntity* taggedVertex;
512 while( taggedVertex = m->iterate(tagIt) )
514 if(m->hasTag(taggedVertex,vertexMaxTraverse))
515 m->removeTag(taggedVertex,vertexMaxTraverse);
518 m->destroyTag(vertexMaxTraverse);
522 void MeshAdaptPUMIDrvr::isotropicIntersect()
525 if(m->findField(
"proteus_size"))
526 apf::destroyField(m->findField(
"proteus_size"));
528 size_iso = apf::createFieldOn(m,
"proteus_size", apf::SCALAR);
530 apf::MeshEntity *vert;
531 apf::MeshIterator *it = m->begin(0);
533 apf::Field *field = sizeFieldList.front();
534 apf::copyData(size_iso,field);
537 while(!sizeFieldList.empty())
539 field = sizeFieldList.front();
540 while(vert = m->iterate(it))
542 double value1 = apf::getScalar(size_iso,vert,0);
543 double value2 = apf::getScalar(field,vert,0);
544 double minValue =
std::min(value1,value2);
545 apf::setScalar(size_iso,vert,0,minValue);
557 void MeshAdaptPUMIDrvr::averageToEntity(apf::Field *ef, apf::Field *vf,
558 apf::MeshEntity *ent)
567 apf::Mesh *m = apf::getMesh(ef);
568 apf::Adjacent elements;
569 m->getAdjacent(ent, m->getDimension(), elements);
571 for (std::size_t i = 0; i < elements.getSize(); ++i)
572 s += apf::getScalar(ef, elements[i], 0);
573 s /= elements.getSize();
574 apf::setScalar(vf, ent, 0,
s);
578 void MeshAdaptPUMIDrvr::minToEntity(apf::Field* ef, apf::Field* vf,
579 apf::MeshEntity* ent)
581 apf::Mesh* m = apf::getMesh(ef);
582 apf::Adjacent elements;
583 m->getAdjacent(ent, m->getDimension(), elements);
585 for (std::size_t i=0; i < elements.getSize(); ++i){
587 s = apf::getScalar(ef, elements[i], 0);
588 else if(apf::getScalar(ef,elements[i],0) <
s)
589 s= apf::getScalar(ef,elements[i],0);
591 apf::setScalar(vf, ent, 0,
s);
596 void MeshAdaptPUMIDrvr::volumeAverageToEntity(apf::Field *ef, apf::Field *vf,
597 apf::MeshEntity *ent)
600 apf::Mesh *m = apf::getMesh(ef);
601 apf::Adjacent elements;
602 apf::MeshElement *testElement;
603 m->getAdjacent(ent, m->getDimension(), elements);
605 double VolumeTotal = 0;
606 for (std::size_t i = 0; i < elements.getSize(); ++i)
608 testElement = apf::createMeshElement(m, elements[i]);
609 s += apf::getScalar(ef, elements[i], 0)*apf::measure(testElement);
610 VolumeTotal += apf::measure(testElement);
611 apf::destroyMeshElement(testElement);
614 apf::setScalar(vf, ent, 0,
s);
621 apf::Mesh *m = apf::getMesh(ef);
622 apf::Adjacent elements;
623 m->getAdjacent(ent, m->getDimension(), elements);
625 double errorTotal = 0;
626 for (std::size_t i = 0; i < elements.getSize(); ++i)
628 s += apf::getScalar(ef, elements[i], 0)*apf::getScalar(err,elements[i],0);
629 errorTotal += apf::getScalar(err,elements[i],0);
638 apf::setScalar(vf, ent, 0,
s);
643 static apf::Field *extractSpeed(apf::Field *velocity)
646 apf::Mesh *m = apf::getMesh(velocity);
647 apf::Field *speedF = apf::createLagrangeField(m,
"proteus_speed", apf::SCALAR, 1);
648 apf::MeshIterator *it = m->begin(0);
650 apf::Vector3 vel_vect;
651 while ((
v = m->iterate(it)))
653 apf::getVector(velocity,
v, 0, vel_vect);
654 double speed = vel_vect.getLength();
655 apf::setScalar(speedF,
v, 0, speed);
661 static apf::Matrix3x3 hessianFormula(apf::Matrix3x3
const &g2phi)
664 apf::Matrix3x3 g2phit = apf::transpose(g2phi);
665 return (g2phi + g2phit) / 2;
668 static apf::Field *computeHessianField(apf::Field *grad2phi)
671 apf::Mesh *m = apf::getMesh(grad2phi);
672 apf::Field *hessf = createLagrangeField(m,
"proteus_hess", apf::MATRIX, 1);
673 apf::MeshIterator *it = m->begin(0);
675 while ((
v = m->iterate(it)))
677 apf::Matrix3x3 g2phi;
678 apf::getMatrix(grad2phi,
v, 0, g2phi);
679 apf::Matrix3x3 hess = hessianFormula(g2phi);
680 apf::setMatrix(hessf,
v, 0, hess);
686 static apf::Field *computeMetricField(apf::Field *gradphi, apf::Field *grad2phi, apf::Field *size_iso,
double eps_u)
690 apf::Mesh *m = apf::getMesh(grad2phi);
691 apf::Field *metricf = createLagrangeField(m,
"proteus_metric", apf::MATRIX, 1);
692 apf::MeshIterator *it = m->begin(0);
694 while ((
v = m->iterate(it)))
696 apf::Matrix3x3 g2phi;
697 apf::getMatrix(grad2phi,
v, 0, g2phi);
705 apf::Matrix3x3 hess = hessianFormula(g2phi);
706 apf::Matrix3x3 metric = hess;
709 apf::setMatrix(metricf,
v, 0, metric);
716 static void curveFormula(apf::Matrix3x3
const &h, apf::Vector3
const &g,
719 double a = (h[1][1] + h[2][2]) * g[0] * g[0] + (h[0][0] + h[2][2]) * g[1] * g[1] + (h[0][0] + h[1][1]) * g[2] * g[2];
721 double b = g[0] * g[1] * h[0][1] + g[0] * g[2] * h[0][2] + g[1] * g[2] * h[1][2];
723 double Km = (a - 2 * b) / pow(g * g, 1.5);
725 double c = g[0] * g[0] * (h[1][1] * h[2][2] - h[1][2] * h[1][2]) + g[1] * g[1] * (h[0][0] * h[2][2] - h[0][2] * h[0][2]) + g[2] * g[2] * (h[0][0] * h[1][1] - h[0][1] * h[0][1]);
727 double d = g[0] * g[1] * (h[0][2] * h[1][2] - h[0][1] * h[2][2]) + g[1] * g[2] * (h[0][1] * h[0][2] - h[1][2] * h[0][0]) + g[0] * g[2] * (h[0][1] * h[1][2] - h[0][2] * h[1][1]);
729 double Kg = (
c + 2 * d) / pow(g * g, 2);
732 curve[1] = Km + sqrt(Km * Km - Kg);
733 curve[2] = Km - sqrt(Km * Km - Kg);
736 static apf::Field *getCurves(apf::Field *hessians, apf::Field *gradphi)
738 apf::Mesh *m = apf::getMesh(hessians);
740 curves = apf::createLagrangeField(m,
"proteus_curves", apf::VECTOR, 1);
741 apf::MeshIterator *it = m->begin(0);
743 while ((
v = m->iterate(it)))
745 apf::Matrix3x3 hessian;
746 apf::getMatrix(hessians,
v, 0, hessian);
748 apf::getVector(gradphi,
v, 0, gphi);
750 curveFormula(hessian, gphi, curve);
751 apf::setVector(curves,
v, 0, curve);
757 static void clamp(
double &
v,
double min,
double max)
764 static void clampField(apf::Field *field,
double min,
double max)
767 apf::Mesh *m = apf::getMesh(field);
768 int numcomps = apf::countComponents(field);
769 double components[numcomps];
771 apf::MeshIterator *it = m->begin(0);
772 while ((
v = m->iterate(it)))
775 apf::getComponents(field,
v, 0, &components[0]);
776 for (
int i = 0; i < numcomps; i++)
777 clamp(components[i],
min,
max);
779 apf::setComponents(field,
v, 0, &components[0]);
784 static void scaleFormula(
double phi,
double hmin,
double hmax,
786 apf::Vector3
const &curves,
790 double epsilon = 7.0 * hmin;
791 if (fabs(
phi) < epsilon)
794 scale[1] = sqrt(0.002 / fabs(curves[1]));
795 scale[2] = sqrt(0.002 / fabs(curves[2]));
797 else if (fabs(
phi) < 4 * epsilon)
800 scale[1] = 2 * sqrt(0.002 / fabs(curves[1]));
801 scale[2] = 2 * sqrt(0.002 / fabs(curves[2]));
805 scale = apf::Vector3(1, 1, 1) * hmax;
812 static void scaleFormulaERM(
double phi,
double hmin,
double hmax,
double h_dest,
813 apf::Vector3
const &curves,
814 double lambda[3],
double eps_u, apf::Vector3 &scale,
int nsd,
double maxAspect)
868 scale[0] = h_dest * pow((lambda[1] ) / (lambda[0]), 1.0 / 4.0);
869 scale[1] = sqrt(lambda[0] / lambda[1]) * scale[0];
879 scale[1] = sqrt(lambda[0] / lambda[1]) * scale[0];
880 scale[2] = sqrt(lambda[0] / lambda[2]) * scale[0];
881 if(scale[1]/scale[0] > maxAspect)
882 scale[1] = maxAspect*scale[0];
883 if(scale[2]/scale[0] > maxAspect)
884 scale[2] = maxAspect*scale[0];
885 if(scale[1]/scale[0] > maxAspect || scale[2]/scale[0] > maxAspect){
886 logEvent(
"Scales reached maximum aspect ratio",4);
901 static apf::Field *getSizeScales(apf::Field *phif, apf::Field *curves,
902 double hmin,
double hmax,
int adapt_step)
905 apf::Mesh *m = apf::getMesh(phif);
907 scales = apf::createLagrangeField(m,
"proteus_size_scale", apf::VECTOR, 1);
908 apf::MeshIterator *it = m->begin(0);
910 while ((
v = m->iterate(it)))
912 double phi = apf::getScalar(phif,
v, 0);
914 apf::getVector(curves,
v, 0, curve);
916 scaleFormula(
phi, hmin, hmax, adapt_step, curve, scale);
917 apf::setVector(scales,
v, 0, scale);
929 return wm < other.
wm;
933 static apf::Field *getSizeFrames(apf::Field *hessians, apf::Field *gradphi)
936 apf::Mesh *m = apf::getMesh(gradphi);
938 frames = apf::createLagrangeField(m,
"proteus_size_frame", apf::MATRIX, 1);
939 apf::MeshIterator *it = m->begin(0);
941 while ((
v = m->iterate(it)))
944 apf::getVector(gradphi,
v, 0, gphi);
946 if (gphi.getLength() > 1e-16)
947 dir = gphi.normalize();
949 dir = apf::Vector3(1, 0, 0);
950 apf::Matrix3x3 hessian;
951 apf::getMatrix(hessians,
v, 0, hessian);
952 apf::Vector3 eigenVectors[3];
953 double eigenValues[3];
954 apf::eigen(hessian, eigenVectors, eigenValues);
956 for (
int i = 0; i < 3; ++i)
958 ssa[i].
v = eigenVectors[i];
959 ssa[i].
wm = std::fabs(eigenValues[i]);
961 std::sort(ssa, ssa + 3);
962 assert(ssa[2].wm >= ssa[1].wm);
963 assert(ssa[1].wm >= ssa[0].wm);
964 double firstEigenvalue = ssa[2].
wm;
965 apf::Matrix3x3 frame;
967 if (firstEigenvalue > 1e-16)
969 apf::Vector3 firstEigenvector = ssa[2].
v;
970 frame[1] = apf::reject(firstEigenvector, dir);
971 frame[2] = apf::cross(frame[0], frame[1]);
972 if (frame[2].getLength() < 1e-16)
973 frame = apf::getFrame(dir);
976 frame = apf::getFrame(dir);
977 for (
int i = 0; i < 3; ++i)
978 frame[i] = frame[i].normalize();
979 frame = apf::transpose(frame);
980 apf::setMatrix(frames,
v, 0, frame);
986 static apf::Field *getERMSizeFrames(apf::Field *hessians, apf::Field *gradphi, apf::Field *frame_comps[3])
989 apf::Mesh *m = apf::getMesh(gradphi);
991 frames = m->findField(
"proteus_size_frame");
992 apf::MeshIterator *it = m->begin(0);
994 while ((
v = m->iterate(it)))
996 apf::Matrix3x3 frame(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
998 apf::getVector(gradphi,
v, 0, gphi);
1008 apf::Matrix3x3 hessian;
1009 apf::getMatrix(hessians,
v, 0, hessian);
1010 apf::Vector3 eigenVectors[3];
1011 double eigenValues[3];
1012 apf::eigen(hessian, eigenVectors, eigenValues);
1014 for (
int i = 0; i < 3; ++i)
1016 ssa[i].
v = eigenVectors[i];
1017 ssa[i].
wm = std::fabs(eigenValues[i]);
1021 std::sort(ssa, ssa + 3);
1022 assert(ssa[2].wm >= ssa[1].wm);
1023 assert(ssa[1].wm >= ssa[0].wm);
1024 double firstEigenvalue = ssa[2].
wm;
1025 assert(firstEigenvalue > 1e-12);
1029 frame[0] = ssa[2].
v;
1030 frame[1] = ssa[1].
v;
1031 frame[2] = ssa[0].
v;
1043 for (
int i = 0; i < 3; ++i)
1044 frame[i] = frame[i].normalize();
1045 frame = apf::transpose(frame);
1046 apf::setMatrix(frames,
v, 0, frame);
1047 apf::setVector(frame_comps[0],
v, 0, frame[0]);
1048 apf::setVector(frame_comps[1],
v, 0, frame[1]);
1049 apf::setVector(frame_comps[2],
v, 0, frame[2]);
1058 apf::Field *phif = m->findField(
"phi");
1060 apf::Field *gradphi = apf::recoverGradientByVolume(phif);
1061 apf::Field *grad2phi = apf::recoverGradientByVolume(gradphi);
1062 apf::Field *hess = computeHessianField(grad2phi);
1063 apf::destroyField(grad2phi);
1064 apf::Field *curves = getCurves(hess, gradphi);
1065 freeField(size_scale);
1068 apf::destroyField(curves);
1069 freeField(size_frame);
1070 size_frame = getSizeFrames(hess, gradphi);
1071 apf::destroyField(hess);
1073 apf::destroyField(gradphi);
1074 for (
int i = 0; i < 2; ++i)
1075 SmoothField(size_scale);
1085 int nc = apf::countComponents(
f);
1086 newField = apf::createPackedField(mesh,
"proteus_smooth_new", nc);
1100 if (!this->requestLocality(&e, 1))
1111 mesh->getUp(
vertex, edges);
1113 for (
int i = 0; i < edges.n; ++i)
1115 apf::MeshEntity *ov = apf::getEdgeVertOppositeVert(
1116 mesh, edges.e[i],
vertex);
1133 static void SmoothField(apf::Field *
f)
1136 op.applyToDimension(0);
1139 void getTargetError(apf::Mesh* m, apf::Field* errField,
double &target_error,
double totalError){
1142 logEvent(
"WARNING/ERROR:Parallel implementation is not completed yet",4);
1143 if(m->getDimension()==2){
1144 target_error = totalError/sqrt(m->count(m->getDimension()));
1145 if(PCU_Comm_Self()==0)
1146 std::cout<<
"The estimated target error is "<<target_error<<std::endl;
1149 apf::Field* interfaceField = m->findField(
"vof");
1150 apf::Field* targetField = apf::createField(m,
"targetError",apf::SCALAR,apf::getVoronoiShape(m->getDimension(),1));
1151 apf::MeshEntity* ent;
1152 apf::MeshIterator* it = m->begin(m->getDimension());
1153 apf::MeshElement* element;
1154 apf::Element* vofElem;
1155 std::vector <double> errVect;
1156 while( (ent = m->iterate(it))){
1157 element = apf::createMeshElement(m, ent);
1158 vofElem = apf::createElement(interfaceField,element);
1159 double vofVal = apf::getScalar(vofElem,apf::Vector3(1./3.,1./3.,1./3.));
1161 if(vofVal < 0.9 && vofVal > 0.1){
1162 double errorValue = apf::getScalar(errField,ent,0);
1163 errVect.push_back(errorValue);
1164 apf::setScalar(targetField,ent,0,errorValue);
1167 apf::setScalar(targetField,ent,0,0.0);
1171 if(errVect.size()==0){
1172 target_error = totalError/sqrt(m->count(m->getDimension()));
1175 std::ofstream myfile;
1176 myfile.open(
"interfaceErrors.txt", std::ios::app );
1177 for(
int i=0;i<errVect.size();i++){
1178 myfile << errVect[i]<<std::endl;
1181 std::sort(errVect.begin(),errVect.end());
1182 int vectorSize = errVect.size();
1183 if(vectorSize %2 ==0){
1184 int idx1 = vectorSize/2-1;
1185 target_error = (errVect[idx1]+errVect[idx1+1])/2;
1188 target_error = errVect[(vectorSize-1)/2];
1190 if(PCU_Comm_Self()==0)
1191 std::cout<<
"The estimated target error is "<<target_error<<std::endl;
1199 freeField(size_frame);
1200 freeField(size_scale);
1201 freeField(size_iso);
1204 apf::Field* errField;
1207 errField = m->findField(
"ErrorRegion");
1209 errField = m->findField(
"VMSH1");
1213 apf::MeshIterator *it;
1215 apf::MeshElement *element;
1216 apf::MeshEntity *reg;
1218 if(m->findField(
"errorSize"))
1219 apf::destroyField(m->findField(
"errorSize"));
1220 apf::Field *errorSize = apf::createLagrangeField(m,
"errorSize", apf::SCALAR, 1);
1223 size_scale = apf::createLagrangeField(m,
"proteus_size_scale", apf::VECTOR, 1);
1224 size_frame = apf::createLagrangeField(m,
"proteus_size_frame", apf::MATRIX, 1);
1226 apf::Field *errorSize_reg = apf::createField(m,
"iso_size", apf::SCALAR, apf::getConstant(
nsd));
1227 apf::Field *clipped_vtx = apf::createLagrangeField(m,
"iso_clipped", apf::SCALAR, 1);
1231 int nsd = m->getDimension();
1232 numel = m->count(
nsd);
1233 PCU_Add_Ints(&numel, 1);
1236 if(target_error==0){
1237 if(m->findField(
"vof")!=NULL)
1240 target_error = err_total/sqrt(m->count(
nsd));
1245 if (domainVolume == 0)
1247 double volTotal = 0.0;
1249 while (reg = m->iterate(it))
1251 volTotal += apf::measure(m, reg);
1253 PCU_Add_Doubles(&volTotal, 1);
1254 domainVolume = volTotal;
1255 assert(domainVolume > 0);
1259 double err_curr = 0.0;
1260 double errRho_curr = 0.0;
1261 double errRho_target = target_error / sqrt(domainVolume);
1262 apf::Vector3 err_vect;
1263 while (reg = m->iterate(it))
1267 element = apf::createMeshElement(m, reg);
1269 if (m->getDimension() == 2)
1271 h_old = apf::computeLargestHeightInTri(m,reg);
1274 h_old = apf::computeLargestHeightInTet(m,reg);
1276 err_curr = apf::getScalar(errField, reg, 0);
1285 if(target_error/err_curr <= 1)
1286 h_new = h_old * pow((target_error / err_curr),2.0/(2.0*(1.0)+1.0));
1288 h_new = h_old * pow((target_error / err_curr),2.0/(2.0*(1.0)+3.0));
1291 if(target_error/err_curr <= 1)
1292 h_new = h_old * pow((target_error / err_curr),2.0/(2.0*(1.0)+
nsd));
1294 h_new = h_old * pow((target_error / err_curr),2.0/(2.0*(1.0)+
nsd));
1298 apf::setScalar(errorSize_reg, reg, 0, h_new);
1299 apf::destroyMeshElement(element);
1306 while ((
v = m->iterate(it)))
1311 minToEntity(errorSize_reg, errorSize,
v);
1314 apf::Copies remotes;
1315 m->getRemotes(
v,remotes);
1316 int owningPart=m->getOwner(
v);
1317 PCU_COMM_PACK(owningPart, remotes[owningPart]);
1318 double currentSize = apf::getScalar(errorSize,
v,0);
1319 PCU_COMM_PACK(owningPart,currentSize);
1325 while(PCU_Comm_Receive())
1327 apf::MeshEntity* receivedEnt;
1328 double receivedSize;
1329 PCU_COMM_UNPACK(receivedEnt);
1330 PCU_COMM_UNPACK(receivedSize);
1332 double currentSize = apf::getScalar(errorSize,receivedEnt,0);
1334 if(receivedSize<currentSize)
1336 apf::setScalar(errorSize,receivedEnt,0,receivedSize);
1347 std::cout<<
"Entering anisotropic loop to compute size scales and frames\n";
1348 double eps_u = 0.002;
1354 apf::Field *speedF = extractSpeed(m->findField(
"velocity"));
1355 apf::Field *gradSpeed = apf::recoverGradientByVolume(speedF);
1356 apf::Field *grad2Speed = apf::recoverGradientByVolume(gradSpeed);
1360 apf::Field *metricf = computeMetricField(gradSpeed, grad2Speed, errorSize, eps_u);
1361 apf::Field *frame_comps[3] = {apf::createLagrangeField(m,
"frame_0", apf::VECTOR, 1), apf::createLagrangeField(m,
"frame_1", apf::VECTOR, 1), apf::createLagrangeField(m,
"frame_2", apf::VECTOR, 1)};
1367 while ((
v = m->iterate(it)))
1369 double tempScale = apf::getScalar(errorSize,
v, 0);
1370 if (tempScale <
hmin)
1371 apf::setScalar(clipped_vtx,
v, 0, -1);
1372 else if (tempScale >
hmax)
1373 apf::setScalar(clipped_vtx,
v, 0, 1);
1375 apf::setScalar(clipped_vtx,
v, 0, 0);
1377 apf::setScalar(errorSize,
v,0,tempScale);
1380 while( (
v = m->iterate(it)) ){
1386 apf::Matrix3x3 metric;
1387 apf::getMatrix(metricf,
v, 0, metric);
1389 apf::Vector3 eigenVectors[3];
1390 double eigenValues[3];
1391 apf::eigen(metric, eigenVectors, eigenValues);
1395 for (
int i = 0; i < 3; ++i)
1397 ssa[i].
v = eigenVectors[i];
1398 ssa[i].
wm = std::fabs(eigenValues[i]);
1400 std::sort(ssa, ssa + 3);
1402 assert(ssa[2].wm >= ssa[1].wm);
1403 assert(ssa[1].wm >= ssa[0].wm);
1405 double lambda[3] = {ssa[2].
wm, ssa[1].
wm, ssa[0].
wm};
1407 scaleFormulaERM(
phi,
hmin,
hmax, apf::getScalar(errorSize,
v, 0), curve, lambda, eps_u, scale,
nsd,
maxAspect);
1408 apf::setVector(size_scale,
v, 0, scale);
1411 apf::Matrix3x3 frame(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0);
1414 double firstEigenvalue = ssa[2].
wm;
1415 assert(firstEigenvalue > 1e-12);
1416 frame[0] = ssa[2].
v;
1417 frame[1] = ssa[1].
v;
1418 frame[2] = ssa[0].
v;
1421 for (
int i = 0; i < 3; ++i)
1422 frame[i] = frame[i].normalize();
1423 frame = apf::transpose(frame);
1424 apf::setMatrix(size_frame,
v, 0, frame);
1432 std::cout<<
"Finished grading size 0\n";
1435 std::cout<<
"Finished grading size 1\n";
1438 std::cout<<
"Finished grading size 2\n";
1440 apf::synchronize(size_scale);
1448 char namebuffer[20];
1449 sprintf(namebuffer,
"pumi_preadapt_aniso_%i",
nAdapt);
1450 apf::writeVtkFiles(namebuffer, m);
1453 apf::destroyField(metricf);
1454 apf::destroyField(frame_comps[0]);
1455 apf::destroyField(frame_comps[1]);
1456 apf::destroyField(frame_comps[2]);
1457 apf::destroyField(speedF);
1458 apf::destroyField(gradSpeed);
1459 apf::destroyField(grad2Speed);
1464 while ((
v = m->iterate(it)))
1466 double tempScale = apf::getScalar(errorSize,
v, 0);
1467 if (tempScale <
hmin)
1468 apf::setScalar(clipped_vtx,
v, 0, -1);
1469 else if (tempScale >
hmax)
1470 apf::setScalar(clipped_vtx,
v, 0, 1);
1472 apf::setScalar(clipped_vtx,
v, 0, 0);
1474 apf::setScalar(errorSize,
v, 0, tempScale);
1477 apf::synchronize(errorSize);
1479 if (target_element_count != 0)
1481 sam::scaleIsoSizeField(errorSize, target_element_count);
1486 sizeFieldList.push(errorSize);
1490 apf::destroyField(errorSize_reg);
1491 apf::destroyField(clipped_vtx);
1493 std::cout<<
"Finished Size Field\n";
1500 freeField(size_iso);
1501 size_iso = apf::createLagrangeField(m,
"proteus_size",apf::SCALAR,1);
1502 apf::MeshIterator* it = m->begin(0);
1504 while(
v = m->iterate(it)){
1507 apf::setScalar(size_iso,
v,0,
phi);
1513 double size[2], apf::Adjacent edgAdjVert,
1514 apf::Adjacent vertAdjEdg,
1515 std::queue<apf::MeshEntity*> &markedEdges,
1516 apf::MeshTag* isMarked,
1534 int marker[3] = {0,1,0};
1535 double marginVal = 0.01;
1536 int needsParallel=0;
1538 if(fieldType == apf::SCALAR){
1539 apf::Field* size_iso = m->findField(
"proteus_size");
1541 if(size[idx1]>(gradingFactor*size[idx2])*(1+marginVal))
1543 if(m->isOwned(edgAdjVert[idx1]))
1545 size[idx1] = gradingFactor*size[idx2];
1546 apf::setScalar(size_iso,edgAdjVert[idx1],0,size[idx1]);
1547 m->getAdjacent(edgAdjVert[idx1], 1, vertAdjEdg);
1548 for (std::size_t i=0; i<vertAdjEdg.getSize();++i){
1549 m->getIntTag(vertAdjEdg[i],isMarked,&marker[2]);
1552 m->setIntTag(vertAdjEdg[i],isMarked,&marker[1]);
1553 markedEdges.push(vertAdjEdg[i]);
1560 apf::Copies remotes;
1561 m->getRemotes(edgAdjVert[idx1],remotes);
1562 double newSize = gradingFactor*size[idx2];
1563 int owningPart=m->getOwner(edgAdjVert[idx1]);
1564 PCU_COMM_PACK(owningPart, remotes[owningPart]);
1565 PCU_COMM_PACK(owningPart,newSize);
1571 apf::Field* size_scale = m->findField(
"proteus_size_scale");
1572 apf::Vector3 sizeVec;
1573 if(size[idx1]>(gradingFactor*size[idx2])*(1+marginVal)){
1574 size[idx1] = gradingFactor*size[idx2];
1575 apf::getVector(size_scale,edgAdjVert[idx1],0,sizeVec);
1577 sizeVec[vecPos] = size[idx1]*sizeVec[0];
1580 sizeVec[0] = size[idx1];
1582 apf::setVector(size_scale,edgAdjVert[idx1],0,sizeVec);
1583 m->getAdjacent(edgAdjVert[idx1], 1, vertAdjEdg);
1584 for (std::size_t i=0; i<vertAdjEdg.getSize();++i){
1585 m->getIntTag(vertAdjEdg[i],isMarked,&marker[2]);
1588 m->setIntTag(vertAdjEdg[i],isMarked,&marker[1]);
1589 markedEdges.push(vertAdjEdg[i]);
1594 return needsParallel;
1597 void markEdgesInitial(apf::Mesh* m, std::queue<apf::MeshEntity*> &markedEdges,
double gradingFactor)
1601 int marker[3] = {0,1,0};
1604 apf::MeshTag* isMarked = m->findTag(
"isMarked");
1605 apf::Field* size_iso = m->findField(
"proteus_size");
1606 apf::Adjacent edgAdjVert;
1607 apf::MeshEntity* edge;
1608 apf::MeshIterator* it = m->begin(1);
1609 while((edge=m->iterate(it))){
1610 m->getAdjacent(edge, 0, edgAdjVert);
1611 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
1612 size[i]=apf::getScalar(size_iso,edgAdjVert[i],0);
1614 if( (size[0] > gradingFactor*size[1]) || (size[1] > gradingFactor*size[0]) ){
1616 markedEdges.push(edge);
1618 m->setIntTag(edge,isMarked,&marker[1]);
1621 m->setIntTag(edge,isMarked,&marker[0]);
1627 int serialGradation(apf::Mesh* m, std::queue<apf::MeshEntity*> &markedEdges,
double gradingFactor)
1632 int marker[3] = {0,1,0};
1633 apf::MeshTag* isMarked = m->findTag(
"isMarked");
1634 apf::Field* size_iso = m->findField(
"proteus_size");
1635 apf::Adjacent edgAdjVert;
1636 apf::Adjacent vertAdjEdg;
1637 apf::MeshEntity* edge;
1638 apf::MeshIterator* it = m->begin(1);
1639 int needsParallel=0;
1642 while(!markedEdges.empty()){
1643 edge = markedEdges.front();
1644 m->getAdjacent(edge, 0, edgAdjVert);
1645 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
1646 size[i] = apf::getScalar(size_iso,edgAdjVert[i],0);
1650 vertAdjEdg, markedEdges, isMarked, apf::SCALAR,0, 0);
1652 vertAdjEdg, markedEdges, isMarked, apf::SCALAR,0, 1);
1654 m->setIntTag(edge,isMarked,&marker[0]);
1657 return needsParallel;
1670 logEvent(
"Starting grading",4);
1671 apf::MeshEntity* edge;
1672 apf::Adjacent edgAdjVert;
1673 apf::Adjacent vertAdjEdg;
1675 std::queue<apf::MeshEntity*> markedEdges;
1676 apf::MeshTag* isMarked = m->createIntTag(
"isMarked",1);
1679 int marker[3] = {0,1,0};
1681 apf::MeshIterator* it;
1684 int needsParallel=1;
1686 while(needsParallel)
1691 PCU_Add_Ints(&needsParallel,1);
1693 std::cerr<<
"Sending size info for gradation"<<std::endl;
1696 apf::MeshEntity* ent;
1697 double receivedSize;
1702 std::queue<apf::MeshEntity*> updateRemoteVertices;
1704 apf::Copies remotes;
1706 while(PCU_Comm_Receive())
1708 PCU_COMM_UNPACK(ent);
1709 PCU_COMM_UNPACK(receivedSize);
1711 if(!m->isOwned(ent)){
1712 logEvent(
"THERE WAS AN ERROR",4);
1716 currentSize = apf::getScalar(size_iso,ent,0);
1717 newSize =
std::min(receivedSize,currentSize);
1718 apf::setScalar(size_iso,ent,0,newSize);
1721 m->getAdjacent(ent, 1, vertAdjEdg);
1722 for (std::size_t i=0; i<vertAdjEdg.getSize();++i)
1724 edge = vertAdjEdg[i];
1725 m->getIntTag(vertAdjEdg[i],isMarked,&marker[2]);
1728 markedEdges.push(edge);
1730 m->setIntTag(edge,isMarked,&marker[1]);
1733 updateRemoteVertices.push(ent);
1738 while(!updateRemoteVertices.empty())
1740 ent = updateRemoteVertices.front();
1742 m->getRemotes(ent,remotes);
1743 currentSize = apf::getScalar(size_iso,ent,0);
1744 for(apf::Copies::iterator iter=remotes.begin(); iter!=remotes.end();++iter)
1746 PCU_COMM_PACK(iter->first, iter->second);
1748 updateRemoteVertices.pop();
1753 while(PCU_Comm_Receive())
1756 PCU_COMM_UNPACK(ent);
1758 assert(!m->isOwned(ent));
1760 if(m->isOwned(ent)){
1761 logEvent(
"Problem occurred",4);
1766 m->getAdjacent(ent, 1, vertAdjEdg);
1767 for (std::size_t i=0; i<vertAdjEdg.getSize();++i)
1769 edge = vertAdjEdg[i];
1770 m->getIntTag(vertAdjEdg[i],isMarked,&marker[2]);
1773 markedEdges.push(edge);
1775 m->setIntTag(edge,isMarked,&marker[1]);
1779 apf::synchronize(size_iso);
1785 while((edge=m->iterate(it))){
1786 m->removeTag(edge,isMarked);
1789 m->destroyTag(isMarked);
1792 logEvent(
"Completed grading",4);
1793 return needsParallel;
1803 apf::MeshIterator* it = m->begin(1);
1804 apf::MeshEntity* edge;
1805 apf::Adjacent edgAdjVert;
1806 apf::Adjacent vertAdjEdg;
1807 double gradingFactor = 1.3;
1809 apf::Vector3 sizeVec;
1810 std::queue<apf::MeshEntity*> markedEdges;
1811 apf::MeshTag* isMarked = m->createIntTag(
"isMarked",1);
1812 apf::Field* size_scale = m->findField(
"proteus_size_scale");
1815 int marker[3] = {0,1,0};
1817 while((edge=m->iterate(it))){
1818 m->getAdjacent(edge, 0, edgAdjVert);
1819 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
1820 apf::getVector(size_scale,edgAdjVert[i],0,sizeVec);
1823 if( (size[0] > gradingFactor*size[1]) || (size[1] > gradingFactor*size[0]) ){
1825 markedEdges.push(edge);
1827 m->setIntTag(edge,isMarked,&marker[1]);
1831 m->setIntTag(edge,isMarked,&marker[0]);
1835 while(!markedEdges.empty()){
1836 edge = markedEdges.front();
1837 m->getAdjacent(edge, 0, edgAdjVert);
1838 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
1839 apf::getVector(size_scale,edgAdjVert[i],0,sizeVec);
1843 vertAdjEdg, markedEdges, isMarked, apf::VECTOR,0, 0);
1845 vertAdjEdg, markedEdges, isMarked, apf::VECTOR,0, 1);
1879 m->setIntTag(edge,isMarked,&marker[0]);
1883 while((edge=m->iterate(it))){
1884 m->removeTag(edge,isMarked);
1887 m->destroyTag(isMarked);
1888 apf::synchronize(size_scale);
1897 std::cout<<
"Entered function\n";
1898 apf::MeshIterator* it = m->begin(1);
1899 apf::MeshEntity* edge;
1900 apf::Adjacent edgAdjVert;
1901 apf::Adjacent vertAdjEdg;
1902 double gradingFactor = 1.3;
1904 apf::Vector3 sizeVec;
1905 std::queue<apf::MeshEntity*> markedEdges;
1906 apf::MeshTag* isMarked = m->createIntTag(
"isMarked",1);
1907 apf::Field* size_scale = m->findField(
"proteus_size_scale");
1910 int marker[3] = {0,1,0};
1912 while((edge=m->iterate(it))){
1913 m->getAdjacent(edge, 0, edgAdjVert);
1914 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
1915 apf::getVector(size_scale,edgAdjVert[i],0,sizeVec);
1916 size[i]=sizeVec[idx]/sizeVec[0];
1918 if( (size[0] > gradingFactor*size[1]) || (size[1] > gradingFactor*size[0]) ){
1920 markedEdges.push(edge);
1922 m->setIntTag(edge,isMarked,&marker[1]);
1926 m->setIntTag(edge,isMarked,&marker[0]);
1931 std::cout<<
"Got queue of size "<<markedEdges.size()<<std::endl;
1932 while(!markedEdges.empty()){
1933 edge = markedEdges.front();
1934 m->getAdjacent(edge, 0, edgAdjVert);
1935 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
1936 apf::getVector(size_scale,edgAdjVert[i],0,sizeVec);
1937 size[i]=sizeVec[idx]/sizeVec[0];
1940 vertAdjEdg, markedEdges, isMarked, apf::VECTOR, idx, 0);
1942 vertAdjEdg, markedEdges, isMarked, apf::VECTOR, idx, 1);
1944 m->setIntTag(edge,isMarked,&marker[0]);
1948 while((edge=m->iterate(it))){
1949 m->removeTag(edge,isMarked);
1952 m->destroyTag(isMarked);
1953 apf::synchronize(size_scale);
1963 apf::MeshIterator* it = m->begin(1);
1964 apf::MeshEntity* edge;
1965 apf::Adjacent edgAdjVert;
1966 apf::Adjacent vertAdjEdg;
1969 apf::Vector3 sizeVec;
1970 std::queue<apf::MeshEntity*> markedEdges;
1971 apf::MeshTag* isMarked = m->createIntTag(
"isMarked",1);
1972 apf::Field* size_scale = m->findField(
"proteus_size_scale");
1975 int marker[3] = {0,1,0};
1977 while((edge=m->iterate(it))){
1978 m->getAdjacent(edge, 0, edgAdjVert);
1979 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
1980 apf::getVector(size_scale,edgAdjVert[i],0,sizeVec);
1983 if( (size[0] > gradingFactor*size[1]) || (size[1] > gradingFactor*size[0]) ){
1985 markedEdges.push(edge);
1987 m->setIntTag(edge,isMarked,&marker[1]);
1991 m->setIntTag(edge,isMarked,&marker[0]);
1995 while(!markedEdges.empty()){
1996 edge = markedEdges.front();
1997 m->getAdjacent(edge, 0, edgAdjVert);
1998 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
1999 apf::getVector(size_scale,edgAdjVert[i],0,sizeVec);
2003 vertAdjEdg, markedEdges, isMarked, apf::VECTOR,0, 0);
2005 vertAdjEdg, markedEdges, isMarked, apf::VECTOR,0, 1);
2039 m->setIntTag(edge,isMarked,&marker[0]);
2043 while((edge=m->iterate(it))){
2044 m->removeTag(edge,isMarked);
2047 m->destroyTag(isMarked);
2048 apf::synchronize(size_scale);
2057 if(PCU_Comm_Self()==0)
2058 std::cout<<
"Entered function\n";
2059 apf::MeshIterator* it = m->begin(1);
2060 apf::MeshEntity* edge;
2061 apf::Adjacent edgAdjVert;
2062 apf::Adjacent vertAdjEdg;
2065 apf::Vector3 sizeVec;
2066 std::queue<apf::MeshEntity*> markedEdges;
2067 apf::MeshTag* isMarked = m->createIntTag(
"isMarked",1);
2068 apf::Field* size_scale = m->findField(
"proteus_size_scale");
2071 int marker[3] = {0,1,0};
2073 while((edge=m->iterate(it))){
2074 m->getAdjacent(edge, 0, edgAdjVert);
2075 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
2076 apf::getVector(size_scale,edgAdjVert[i],0,sizeVec);
2077 size[i]=sizeVec[idx]/sizeVec[0];
2079 if( (size[0] > gradingFactor*size[1]) || (size[1] > gradingFactor*size[0]) ){
2081 markedEdges.push(edge);
2083 m->setIntTag(edge,isMarked,&marker[1]);
2087 m->setIntTag(edge,isMarked,&marker[0]);
2092 if(PCU_Comm_Self()==0)
2093 std::cout<<
"Got queue of size "<<markedEdges.size()<<std::endl;
2094 while(!markedEdges.empty()){
2095 edge = markedEdges.front();
2096 m->getAdjacent(edge, 0, edgAdjVert);
2097 for (std::size_t i=0; i < edgAdjVert.getSize(); ++i){
2098 apf::getVector(size_scale,edgAdjVert[i],0,sizeVec);
2099 size[i]=sizeVec[idx]/sizeVec[0];
2102 vertAdjEdg, markedEdges, isMarked, apf::VECTOR, idx, 0);
2104 vertAdjEdg, markedEdges, isMarked, apf::VECTOR, idx, 1);
2106 m->setIntTag(edge,isMarked,&marker[0]);
2110 while((edge=m->iterate(it))){
2111 m->removeTag(edge,isMarked);
2114 m->destroyTag(isMarked);
2115 apf::synchronize(size_scale);