Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/meshgen2d/src/VoronoiVertex.cpp
3196 views
1
#include "VoronoiVertex.h"
2
#include "Border.h"
3
#include <math.h>
4
#include <iostream>
5
6
void VoronoiVertex::
7
discretize(NodeMap& fixedNodes, NodeMap& allNodes, std::list< Element* >& allElements )
8
{
9
triangulate();
10
11
removeBoundaryConnectors();
12
generate();
13
exportNodes( allNodes, allElements );
14
}
15
16
void VoronoiVertex::
17
generate()
18
{
19
std::cout << "Generating" << std::endl;
20
21
const double sqrt3 = 1.7320508075688772935274463415059;
22
23
double ref;
24
std::list< Vertex* >::iterator vxIt;
25
for( vxIt = allVertices.begin(); vxIt != allVertices.end(); ++vxIt )
26
{
27
Vertex *vtx = (*vxIt);
28
if( !(vtx->isDeleted() || vtx->isExternal() ))
29
{
30
ref = bg->interpolate( vtx->vx, vtx->vy );
31
if( !vtx->rightSize( ref / sqrt3 ) )
32
{
33
actives.insert( vtx );
34
}
35
}
36
}
37
38
size_t steps = 1;
39
40
while( actives.size() > 0 )
41
{
42
Vertex *vtx = actives.first();
43
44
MeshNode *nd = new MeshNode( vtx->vx, vtx->vy );
45
46
int i = 0;
47
48
if( addSite( vtx, nd, false, false ) == true )
49
{
50
if( deleted.size() == 1 )
51
{
52
// This is a terrible hack and we get a lot of it wrong!
53
vtx->unDelete();
54
deleted.clear();
55
delete nd;
56
}
57
else
58
{
59
actives.removeRelevants( deleted );
60
61
int len = newVertices.size();
62
for( int i = 0; i < len; ++i )
63
{
64
newVertices[i]->setBody( 1 );
65
ref = bg->interpolate( newVertices[i]->vx, newVertices[i]->vy );
66
if( !newVertices[i]->rightSize( ref / sqrt3 ) )
67
{
68
actives.insert( newVertices[i] );
69
}
70
}
71
}
72
}
73
74
recycle();
75
}
76
}
77
78
79