Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/meshgen2d/src/BGVertex.cpp
3196 views
1
#include "BGVertex.h"
2
#include "GeometryNode.h"
3
#include "coreGeometry.h"
4
#include <iostream>
5
6
void BGVertex::
7
initInterpolation( )
8
{
9
int i;
10
11
double a[9];
12
double b[3];
13
14
for ( i = 0; i < 3; ++i )
15
{
16
int i1 = (i + 1) % 3, i2 = (i + 2) % 3;
17
a[i] = nodes[i1]->x * nodes[i2]->y - nodes[i2]->x * nodes[i1]->y;
18
a[3 + i] = nodes[i1]->y - nodes[i2]->y;
19
a[6 + i] = nodes[i2]->x - nodes[i1]->x;
20
}
21
22
double det = a[0] + a[1] + a[2];
23
24
int n = 0;
25
double avg = 0.0;
26
27
for( i = 0; i < 3; ++i )
28
{
29
int t = nodes[i]->tag;
30
if( t < 0 ) continue;
31
GeometryNode *nd = static_cast< GeometryNode * >( nodes[i] );
32
b[i] = MAP(nd->delta);
33
avg += b[i];
34
n++;
35
}
36
37
avg /= n;
38
for (i = 0; i < 3; ++i)
39
{
40
if (nodes[i]->tag < 0)
41
b[i] = avg;
42
}
43
44
for ( i = 0; i < 3; ++i )
45
{
46
coeff[i] = (a[3*i] * b[0] + a[3*i+1] * b[1] + a[3*i+2] * b[2]) / det;
47
}
48
}
49
50
double BGVertex::
51
interpolate( const double tx, const double ty )
52
{
53
bool found = false;
54
int i;
55
Vertex *curr = this;
56
Vertex *prev = (Vertex *)0;
57
58
int s[3] = {2,3,1};
59
int e[3] = {1,2,3};
60
61
double x[4],y[4];
62
63
x[0] = tx; y[0] = ty;
64
x[1] = nodes[0]->x; y[1] = nodes[0]->y;
65
x[2] = nodes[1]->x; y[2] = nodes[1]->y;
66
x[3] = nodes[2]->x; y[3] = nodes[2]->y;
67
68
while( !found )
69
{
70
Vertex *test = curr;
71
for(i = 0; i < 3; ++i)
72
{
73
if((curr->vertices[i]) && (curr->vertices[i] != prev) &&
74
orientation(tx,ty,x[s[i]],y[s[i]],x[e[i]],y[e[i]]))
75
{
76
prev = curr;
77
curr = curr->vertices[i];
78
79
x[0] = tx; y[0] = ty;
80
x[1] = curr->nodeAt(0)->x; y[1] = curr->nodeAt(0)->y;
81
x[2] = curr->nodeAt(1)->x; y[2] = curr->nodeAt(1)->y;
82
x[3] = curr->nodeAt(2)->x; y[3] = curr->nodeAt(2)->y;
83
break;
84
}
85
}
86
if( test == curr ) found = true;
87
}
88
89
BGVertex *vtx = static_cast< BGVertex * >( curr );
90
double val = UNMAP(vtx->coeff[0] + vtx->coeff[1] * tx + vtx->coeff[2] * ty);
91
92
return val;
93
}
94
95