forked from eelcovv/gridpro2Foam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.cpp
126 lines (104 loc) · 2.54 KB
/
Node.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* This file belongs to the GridPro2FOAM distribution
Developed by Vincent Rivola and Martin Spel
R.Tech SARL
Parc Technologique Cap Delta
09340 Verniolle
France
For contact information: http://www.rtech.fr/contact.html
or email: support@rtech-engineering.com
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Node.hpp"
#include <math.h>
Node::Node(double setX, double setY, double setZ, bool setBoundaryNode)
{ x=setX;
y=setY;
z=setZ;
equivalent=NULL;
id = -1;
isBoundaryNode=setBoundaryNode;
}
Node::~Node()
{
}
// set my equivalence to node n2, unless it is already set
void Node::SetEquivalent(Node *n2, bool debug)
{
while (n2->GetEquivalent()) n2=n2->GetEquivalent();
Node *n1=this;
while (n1->GetEquivalent()) n1=n1->GetEquivalent();
if (n1->id > n2->id)
n1->equivalent = n2;
else
n2->equivalent = n1;
}
void Node::PrintEquivalent()
{
if (equivalent != NULL)
{ printf("Equivalent:\n");
Print();
equivalent->Print();
}
}
void Node::PrintTecplot(FILE *f)
{
fprintf(f, "%1.13lg %1.13lg %1.13lg\n", x, y, z);
}
void Node::AnalysePeriodic(PeriodicStats *stats, int BC)
{
printf("ID %d\n", id);
if (periodicNeighbor.count(BC)!=0)
{ Node *n2= periodicNeighbor.find(BC)->second;
if (n2)
{ printf("periodic with %d\n", n2->GetRealId());
stats->AddPoint(this,n2);
} else printf("Not periodic ?????\n");
} else
{ printf("Not peridioc for patch %d\n");
}
}
void Node::PrintDebug(FILE *f)
{
fprintf(f, "ID %d\n", id);
fprintf(f, "equiv ID %d\n", GetId());
fprintf(f, "(%1.13lg %1.13lg %1.13lg)\n", x, y, z);
// TODO: loop over maps if (periodicNeighbor) fprintf(f, "Periodic node to ID %d\n", periodicNeighbor->GetRealId());
}
void Node::Print(FILE *f)
{
fprintf(f, "(%1.13lg %1.13lg %1.13lg)\n", x, y, z);
}
double Node::Distance(Node *n2)
{ double dx=x-n2->x;
double dy=y-n2->y;
double dz=z-n2->z;
return sqrt(dx*dx+dy*dy+dz*dz);
}
void Node::SetId(int setId)
{
id=setId;
}
int Node::GetId()
{
if (equivalent != NULL) return equivalent->GetId();
else return id;
}
void Node::SetPeriodicNeighbor(int BC, Node *n2)
{ pair<int,Node*> a(BC,n2);
periodicNeighbor.insert(a);
}
int Node::GetPeriodicId(int BC)
{ if (periodicNeighbor.count(BC)==0) return 0;
Node *n2= periodicNeighbor.find(BC)->second;
return n2->GetId();
}
void Node::SetPeriodicSide(int BC, short n)
{ pair<int,short> a(BC,n);
periodicSide.insert(a);
}
short Node::GetPeriodicSide(int BC)
{ if (periodicSide.count(BC)==0) return 0;
return periodicSide.find(BC)->second;
}