Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/csg/meshsurf.cpp
3206 views
1
#include <mystdlib.h>
2
3
#include <csg.hpp>
4
#include <meshing.hpp>
5
6
7
8
namespace netgen
9
{
10
/*
11
Meshing2Surfaces :: Meshing2Surfaces (const Surface & asurface)
12
: surface(asurface)
13
{
14
;
15
}
16
*/
17
Meshing2Surfaces :: Meshing2Surfaces (const Surface & asurf,
18
const Box<3> & abb)
19
: Meshing2(abb), surface(asurf)
20
{
21
;
22
}
23
24
25
void Meshing2Surfaces :: DefineTransformation (const Point3d & p1, const Point3d & p2,
26
const PointGeomInfo * geominfo1,
27
const PointGeomInfo * geominfo2)
28
{
29
((Surface&)surface).DefineTangentialPlane (p1, p2);
30
}
31
32
void Meshing2Surfaces :: TransformToPlain (const Point3d & locpoint,
33
const MultiPointGeomInfo & geominfo,
34
Point2d & planepoint,
35
double h, int & zone)
36
{
37
Point<2> hp;
38
surface.ToPlane (locpoint, hp, h, zone);
39
planepoint.X() = hp(0);
40
planepoint.Y() = hp(1);
41
}
42
43
int Meshing2Surfaces :: TransformFromPlain (Point2d & planepoint,
44
Point3d & locpoint,
45
PointGeomInfo & gi,
46
double h)
47
{
48
Point<3> hp;
49
Point<2> hp2 (planepoint.X(), planepoint.Y());
50
surface.FromPlane (hp2, hp, h);
51
locpoint = hp;
52
gi.trignum = 1;
53
return 0;
54
}
55
56
57
58
double Meshing2Surfaces :: CalcLocalH (const Point3d & p, double gh) const
59
{
60
return surface.LocH (p, 3, 1, gh);
61
/*
62
double loch = mesh.lochfunc->GetH(p);
63
if (gh < loch) loch = gh;
64
return loch;
65
*/
66
}
67
68
69
70
71
72
73
MeshOptimize2dSurfaces :: MeshOptimize2dSurfaces (const CSGeometry & ageometry)
74
: MeshOptimize2d(), geometry(ageometry)
75
{
76
;
77
}
78
79
80
void MeshOptimize2dSurfaces :: ProjectPoint (INDEX surfind, Point<3> & p) const
81
{
82
Point<3> hp = p;
83
geometry.GetSurface(surfind)->Project (hp);
84
p = hp;
85
}
86
87
void MeshOptimize2dSurfaces :: ProjectPoint2 (INDEX surfind, INDEX surfind2,
88
Point<3> & p) const
89
{
90
Point<3> hp = p;
91
ProjectToEdge ( geometry.GetSurface(surfind),
92
geometry.GetSurface(surfind2), hp);
93
p = hp;
94
}
95
96
97
void MeshOptimize2dSurfaces ::
98
GetNormalVector(INDEX surfind, const Point<3> & p, Vec<3> & n) const
99
{
100
Vec<3> hn = n;
101
geometry.GetSurface(surfind)->CalcGradient (p, hn);
102
hn.Normalize();
103
n = hn;
104
105
/*
106
if (geometry.GetSurface(surfind)->Inverse())
107
n *= -1;
108
*/
109
}
110
111
112
113
114
115
116
117
RefinementSurfaces :: RefinementSurfaces (const CSGeometry & ageometry)
118
: Refinement(), geometry(ageometry)
119
{
120
if(geometry.GetNSurf() == 0)
121
cerr << endl
122
<< "WARNING: Intializing 2D refinement with 0-surface geometry" << endl
123
<< "==========================================================" << endl
124
<< endl << endl;
125
}
126
127
RefinementSurfaces :: ~RefinementSurfaces ()
128
{
129
;
130
}
131
132
void RefinementSurfaces ::
133
PointBetween (const Point<3> & p1, const Point<3> & p2, double secpoint,
134
int surfi,
135
const PointGeomInfo & gi1,
136
const PointGeomInfo & gi2,
137
Point<3> & newp, PointGeomInfo & newgi)
138
{
139
Point<3> hnewp;
140
hnewp = p1+secpoint*(p2-p1);
141
if (surfi != -1)
142
{
143
geometry.GetSurface (surfi) -> Project (hnewp);
144
newgi.trignum = 1;
145
}
146
147
newp = hnewp;
148
}
149
150
void RefinementSurfaces ::
151
PointBetween (const Point<3> & p1, const Point<3> & p2, double secpoint,
152
int surfi1, int surfi2,
153
const EdgePointGeomInfo & ap1,
154
const EdgePointGeomInfo & ap2,
155
Point<3> & newp, EdgePointGeomInfo & newgi)
156
{
157
Point<3> hnewp = p1+secpoint*(p2-p1);
158
//(*testout) << "hnewp " << hnewp << " s1 " << surfi1 << " s2 " << surfi2 << endl;
159
if (surfi1 != -1 && surfi2 != -1 && surfi1 != surfi2)
160
{
161
netgen::ProjectToEdge (geometry.GetSurface(surfi1),
162
geometry.GetSurface(surfi2),
163
hnewp);
164
// (*testout) << "Pointbetween, newp = " << hnewp << endl
165
// << ", err = " << sqrt (sqr (hnewp(0))+ sqr(hnewp(1)) + sqr (hnewp(2))) - 1 << endl;
166
newgi.edgenr = 1;
167
//(*testout) << "hnewp (a1) " << hnewp << endl;
168
}
169
else if (surfi1 != -1)
170
{
171
geometry.GetSurface (surfi1) -> Project (hnewp);
172
//(*testout) << "hnewp (a2) " << hnewp << endl;
173
}
174
175
newp = hnewp;
176
};
177
178
Vec<3> RefinementSurfaces :: GetTangent (const Point<3> & p, int surfi1, int surfi2,
179
const EdgePointGeomInfo & ap1) const
180
{
181
Vec<3> n1 = geometry.GetSurface (surfi1)->GetNormalVector (p);
182
Vec<3> n2 = geometry.GetSurface (surfi2)->GetNormalVector (p);
183
Vec<3> tau = Cross (n1, n2).Normalize();
184
return tau;
185
}
186
187
Vec<3> RefinementSurfaces :: GetNormal (const Point<3> & p, int surfi1,
188
const PointGeomInfo & gi) const
189
{
190
return geometry.GetSurface (surfi1)->GetNormalVector (p);
191
}
192
193
194
195
void RefinementSurfaces :: ProjectToSurface (Point<3> & p, int surfi)
196
{
197
if (surfi != -1)
198
geometry.GetSurface (surfi) -> Project (p);
199
};
200
201
void RefinementSurfaces :: ProjectToEdge (Point<3> & p, int surfi1, int surfi2, const EdgePointGeomInfo & egi) const
202
{
203
netgen::ProjectToEdge (geometry.GetSurface(surfi1),
204
geometry.GetSurface(surfi2),
205
p);
206
207
}
208
209
210
}
211
212