50DelaunayTriangulator :: DelaunayTriangulator(
Domain *d,
double setAlpha) :
61DelaunayTriangulator :: ~DelaunayTriangulator()
74void DelaunayTriangulator :: addUniqueEdgeToPolygon(
Edge2D edge, std :: list< Edge2D > &polygon)
78 for (
auto pos = polygon.begin(); pos != polygon.end(); ) {
79 if ( ( * pos ) == edge ) {
80 pos = polygon.erase(pos);
89 polygon.push_back(edge);
94void DelaunayTriangulator :: generateMesh()
102 for (
int insertedNode = 1; insertedNode <=
nnode; insertedNode++ ) {
105 std :: list< Edge2D >polygon;
135void DelaunayTriangulator :: writeMesh()
142 bool hasNoBcOnItself;
147 PFEM *pfemEngngModel =
dynamic_cast< PFEM *
>(
domain->giveEngngModel() );
148 if ( pfemEngngModel ) {
154 domain->resizeElements(nelem);
157 auto elem = std::make_unique<TR1_2D_PFEM>(num,
domain, gen->giveNode(1), gen->giveNode(2), gen->giveNode(3), mat, cs);
159 domain->setElement(num, std::move(elem));
165 for (
int i = 1; i <=
domain->giveNumberOfDofManagers(); i++ ) {
166 Dof *jDof =
domain->giveDofManager(i)->giveDofWithID(P_f);
174 bool oneIsFree =
false;
175 hasNoBcOnItself =
true;
176 dman =
domain->giveDofManager( el->giveFirstNodeNumber() );
177 for (
Dof *dof: *dman ) {
178 type = dof->giveDofID();
179 if ( ( type == V_u ) || ( type == V_v ) || ( type == V_w ) ) {
180 if ( dof->giveBcId() ) {
181 hasNoBcOnItself =
false;
186 if ( hasNoBcOnItself ) {
189 dynamic_cast< PFEMParticle *
>( dman )->setOnAlphaShape();
191 hasNoBcOnItself =
true;
192 dman =
domain->giveDofManager( el->giveSecondNodeNumber() );
193 for (
Dof *dof: *dman ) {
194 type = dof->giveDofID();
195 if ( ( type == V_u ) || ( type == V_v ) || ( type == V_w ) ) {
196 if ( dof->giveBcId() ) {
197 hasNoBcOnItself =
false;
202 if ( hasNoBcOnItself ) {
205 dynamic_cast< PFEMParticle *
>( dman )->setOnAlphaShape();
208 Dof *dofOnNode1 =
domain->giveDofManager( el->giveFirstNodeNumber() )->giveDofWithID(P_f);
209 dofOnNode1->
setBcId(pressureBC);
211 Dof *dofOnNode2 =
domain->giveDofManager( el->giveSecondNodeNumber() )->giveDofWithID(P_f);
212 dofOnNode2->
setBcId(pressureBC);
219void DelaunayTriangulator :: computeAlphaComplex()
221 bool alphaLengthInitialized =
false;
222 double minimalLength = 1.e6;
225 if ( alphaLengthInitialized ) {
226 minimalLength =
min( gen->giveShortestEdgeLength(), minimalLength );
228 minimalLength = gen->giveShortestEdgeLength();
229 alphaLengthInitialized =
true;
232 int par1 = gen->giveNode(1);
233 int par2 = gen->giveNode(2);
234 int par3 = gen->giveNode(3);
235 double ccRadius = gen->giveCircumRadius();
243 if ( containedEdge ) {
247 if ( ccRadius < outAlph ) {
252 if ( ccRadius > innAlph ) {
272 if ( containedEdge ) {
277 if ( ccRadius < outAlph ) {
282 if ( ccRadius > innAlph ) {
302 if ( containedEdge ) {
307 if ( ccRadius < outAlph ) {
312 if ( ccRadius > innAlph ) {
337 if ( ( * * elIT ) == alphaEdge ) {
348void DelaunayTriangulator :: giveAlphaShape()
354 double outBound = el->giveOuterAlphaBound();
357 if ( el->giveHullFlag() ) {
358 if ( alpha > outBound ) {
362 el->giveShared(1)->setValidFlag(
false);
365 double innBound = el->giveInnerAlphaBound();
366 if ( alpha > outBound && alpha < innBound ) {
368 if ( el->giveShared(1)->giveCircumRadius() > alpha ) {
369 el->giveShared(1)->setValidFlag(
false);
371 el->giveShared(2)->setValidFlag(
false);
375 if ( alpha < outBound ) {
376 for (
int i = 1; i <= 2; i++ ) {
377 el->giveShared(i)->setValidFlag(
false);
385DelaunayTriangulator :: initializeTimers()
403 std :: list< DelaunayTriangle * > nonDelaunayTriangles;
410 for (
auto triangle : nonDelaunayTriangles ) {
414 triangle->setValidFlag(
false);
423 for (
auto polygonIT = polygon.begin(); polygonIT != polygon.end(); polygonIT++ ) {
437DelaunayTriangulator :: giveTimeReport()
451 printf(
"\nUser time consumed by searching: %.3f [s]\n\n", _searchutime);
452 printf(
"\nUser time consumed by building insertion polygon: %.3f [s]\n\n", _polygonutime);
453 printf(
"\nUser time consumed by creating elements: %.3f [s]\n\n", _creativeutime);
454 printf(
"\nUser time consumed by meshing: %.3f [s]\n\n", _utime);
458DelaunayTriangulator :: cleanUpTriangleList()
461 int node1 = ( * genIT )->giveNode(1);
462 int node2 = ( * genIT )->giveNode(2);
463 int node3 = ( * genIT )->giveNode(3);
468 !( ( * genIT )->giveValidFlag() ) ) {
487 auto bottomLeftNode = std::make_unique<Node>(
nnode + 1,
domain);
490 for (
int ci = 1; ci <= 2; ci++ ) {
491 coords.
at(ci) -= diff;
494 bottomLeftNode->setCoordinates(coords);
496 auto bottomRightNode = std::make_unique<Node>(
nnode + 2,
domain);
498 bottomRightNode->setCoordinates(coords);
500 auto topRightNode = std::make_unique<Node>(
nnode + 3,
domain);
502 topRightNode->setCoordinates(coords);
504 auto topLeftNode = std::make_unique<Node>(
nnode + 4,
domain);
506 topLeftNode->setCoordinates(coords);
509 domain->setDofManager(
nnode + 1, std::move(bottomLeftNode));
510 domain->setDofManager(
nnode + 2, std::move(bottomRightNode));
511 domain->setDofManager(
nnode + 3, std::move(topRightNode));
512 domain->setDofManager(
nnode + 4, std::move(topLeftNode));
527 int init = 1,
nnode = this->
domain->giveNumberOfDofManagers();
531 for (
int i = 1; i <=
nnode; i++ ) {
532 auto node =
domain->giveNode(i);
533 const auto &coords = node->giveCoordinates();
536 for (
int j = 1; j <= coords.giveSize(); j++ ) {
537 minc.at(j) = maxc.
at(j) = coords.at(j);
540 for (
int j = 1; j <= coords.giveSize(); j++ ) {
541 if ( coords.at(j) < minc.at(j) ) {
542 minc.at(j) = coords.at(j);
544 if ( coords.at(j) > maxc.
at(j) ) {
545 maxc.
at(j) = coords.at(j);
554 double rootSize = 0.0;
555 for (
int i = 1; i <= 3; i++ ) {
556 rootSize = 1.000001 *
max( rootSize, maxc.
at(i) - minc.at(i) );
562 double resolutionLimit =
min(1.e-3, rootSize / 1.e6);
563 for (
int i = 1; i <= 3; i++ ) {
564 if ( ( maxc.
at(i) - minc.at(i) ) > resolutionLimit ) {
double giveOuterAlphaBound()
Returns the outer limit.
void setOuterAlphaBound(double alphaMin)
Sets the outer limit.
void setSharing(int n, DelaunayTriangle *pTE)
Stores DelaunayTriangle sharing the receiver.
void setHullFlag(bool flag)
Sets the convex hull property.
void setInnerAlphaBound(double alphaMax)
Sets the inner limit.
double giveInnerAlphaBound()
Returns the inner limit.
void setMask(int i, int mask)
Sets the spatial mask.
void giveOrigin(FloatArray &answer)
void setOrigin(FloatArray &coords)
Sets the origin of the bounding box.
void setSize(double s)
Sets the size of the bounding box (all sides are equal).
double giveSize()
Gives the size of the bounding box.
Timer searchingTimer
Measures time needed by searching for non-delaunay triangles.
void addUniqueEdgeToPolygon(Edge2D edge, std ::list< Edge2D > &polygon)
Edge is added to the polygon only if it's not contained. Otherwise both are removed (edge shared by t...
void giveAlphaShape()
Iterates through the edgeList container and compares alpha-value with alphaEdge bounds....
Timer meshingTimer
Measures overall time of triangulation procedure.
void meshPolygon(int insertedNode, InsertTriangleBasedOnCircumcircle &tInsert, std ::list< Edge2D > &polygon)
Retriangulates the polygon.
std ::list< AlphaEdge2D * > alphaShapeEdgeList
Contains resulting alpha-shape in form of a list.
void computeAlphaComplex()
Reads the triangulation and fills tha edgeList container with alpha-shape edges and set their bounds.
Timer polygonTimer
Measures time needed for identifying polygon to be retriangulated.
AlphaEdge2D * giveBackEdgeIfAlreadyContainedInList(AlphaEdge2D &alphaEdge)
void computeBBXBasedOnNodeData(BoundingBox &BBX)
Calculates the bounding box base on the domain's nodes.
std ::list< AlphaEdge2D * > edgeList
contains all edges of the triangulation
OctreeSpatialLocalizerT< DelaunayTriangle * > triangleOctree
Octree with Delaunay triangles allowing fast search.
Domain * domain
Domain of the PFEM problem containing nodes to be triangulated.
void buildInitialBBXMesh(InsertTriangleBasedOnCircumcircle &tInsert)
Identifies the bounding box of pfemparticles and creates initial triangulation consisting of 2 triang...
void cleanUpTriangleList()
Iterates through generalTringleList und removes non-valid ones or those containing bounding box nodes...
void writeMesh()
Writes the mesh into the domain by creating new tr1_2d_pfem elements and prescribes zero-pressure bou...
void initializeTimers()
Initializes Timers and.
Timer creativeTimer
Measures time needed for creating new Delaunay triangles.
void findNonDelaunayTriangles(int insertedNode, InsertTriangleBasedOnCircumcircle &tInsert, std ::list< Edge2D > &polygon)
Looks for non-Delaunay triangles in octree and creates a polygon.
std ::list< DelaunayTriangle * > generalTriangleList
Contains all triangles (even not valid).
const FloatArray & giveCoordinates() const
virtual void setBcId(int bcId)
Overwrites the boundary condition id (0-inactive BC), intended for specific purposes such as coupling...
virtual bool isActive()
Returns the activeFlag.
virtual void setOnAlphaShape(bool newFlag=true)
Sets the alphaShapeFlag.
int giveAssociatedMaterialNumber()
Returns number of material to be associated with created elements.
int giveAssociatedCrossSectionNumber()
Returns number of cross section to be associated with created elements.
int giveAssociatedPressureBC()
Returns number of zero pressure boundary condition to be prescribed on free surface.
FloatArrayF< N > min(const FloatArrayF< N > &a, const FloatArrayF< N > &b)
FloatArrayF< N > max(const FloatArrayF< N > &a, const FloatArrayF< N > &b)
#define VERBOSE_PRINT0(str, number)