Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/ElmerGUI/netgen/libsrc/csg/surface.hpp
3206 views
1
#ifndef FILE_SURFACE
2
#define FILE_SURFACE
3
4
/**************************************************************************/
5
/* File: surface.hh */
6
/* Author: Joachim Schoeberl */
7
/* Date: 1. Dez. 95 */
8
/**************************************************************************/
9
10
11
12
13
// class DenseMatrix;
14
// class Box3dSphere;
15
class TriangleApproximation;
16
17
/**
18
Basis class for implicit surface geometry.
19
This class is used for generation of surface meshes
20
in NETGEN as well as for mesh refinement in FEPP.
21
*/
22
23
24
25
26
class Surface
27
{
28
protected:
29
/// invert normal vector
30
bool inverse;
31
/// maximal h in surface
32
double maxh;
33
/// name of surface
34
char * name;
35
/// boundary condition nr
36
int bcprop;
37
///
38
string bcname;
39
40
public:
41
Surface ();
42
/** @name Tangential plane.
43
The tangential plane is used for surface mesh generation.
44
*/
45
46
virtual ~Surface();
47
48
protected:
49
/** @name Points in the surface defining tangential plane.
50
Tangential plane is taken in p1, the local x-axis
51
is directed to p2.
52
*/
53
//@{
54
///
55
Point<3> p1;
56
///
57
Point<3> p2;
58
//@}
59
/** @name Base-vectos for local coordinate system. */
60
//@{
61
/// in plane, directed p1->p2
62
Vec<3> ex;
63
/// in plane
64
Vec<3> ey;
65
/// outer normal direction
66
Vec<3> ez;
67
//@}
68
public:
69
70
void SetName (const char * aname);
71
const char * Name () const { return name; }
72
73
//@{
74
/**
75
Defines tangential plane in ap1.
76
The local x-coordinate axis point to the direction of ap2 */
77
virtual void DefineTangentialPlane (const Point<3> & ap1,
78
const Point<3> & ap2);
79
80
/// Transforms 3d point p3d to local coordinates pplane
81
virtual void ToPlane (const Point<3> & p3d, Point<2> & pplane,
82
double h, int & zone) const;
83
84
/// Transforms point pplane in local coordinates to 3d point
85
virtual void FromPlane (const Point<2> & pplane,
86
Point<3> & p3d, double h) const;
87
//@}
88
89
90
/// Move Point p to closes point in surface
91
virtual void Project (Point<3> & p) const;
92
93
///
94
virtual void SkewProject(Point<3> & p, const Vec<3> & direction) const;
95
96
virtual int IsIdentic (const Surface & /* s2 */, int & /* inv */,
97
double /* eps */) const
98
{ return 0; }
99
100
///
101
virtual int PointOnSurface (const Point<3> & p,
102
double eps = 1e-6) const;
103
104
105
/** @name Implicit function.
106
Calculate function value and derivatives.
107
*/
108
//@{
109
/// Calculate implicit function value in point point
110
virtual double CalcFunctionValue (const Point<3> & point) const = 0;
111
112
/**
113
Calc gradient of implicit function.
114
gradient should be O(1) at surface
115
*/
116
virtual void CalcGradient (const Point<3> & point, Vec<3> & grad) const = 0;
117
118
/**
119
Calculate second derivatives of implicit function.
120
*/
121
virtual void CalcHesse (const Point<3> & point, Mat<3> & hesse) const;
122
123
/**
124
Returns outer normal vector.
125
*/
126
// virtual void GetNormalVector (const Point<3> & p, Vec<3> & n) const;
127
virtual Vec<3> GetNormalVector (const Point<3> & p) const;
128
129
/**
130
Upper bound for spectral norm of Hesse-matrix
131
*/
132
virtual double HesseNorm () const = 0;
133
134
/**
135
Upper bound for spectral norm of Hesse-matrix in the
136
rad - environment of point c.
137
*/
138
virtual double HesseNormLoc (const Point<3> & /* c */,
139
double /* rad */) const
140
{ return HesseNorm (); }
141
//@}
142
143
144
///
145
virtual double MaxCurvature () const;
146
///
147
virtual double MaxCurvatureLoc (const Point<3> & /* c */ ,
148
double /* rad */) const;
149
150
/** Returns any point in the surface.
151
Needed to start surface mesh generation e.g. on sphere */
152
virtual Point<3> GetSurfacePoint () const = 0;
153
154
///
155
bool Inverse () const { return inverse; }
156
///
157
void SetInverse (bool ainverse) { inverse = ainverse; }
158
///
159
virtual void Print (ostream & str) const = 0;
160
161
///
162
virtual void Reduce (const BoxSphere<3> & /* box */) { };
163
///
164
virtual void UnReduce () { };
165
166
/// set max h in surface
167
void SetMaxH (double amaxh) { maxh = amaxh; }
168
///
169
double GetMaxH () const { return maxh; }
170
///
171
int GetBCProperty () const { return bcprop; }
172
///
173
void SetBCProperty (int abc) { bcprop = abc; }
174
175
/** Determine local mesh-size.
176
Find
177
\[ h \leq hmax, \]
178
such that
179
\[ h \times \kappa (x) \leq c \qquad \mbox{in} B(x, h), \]
180
where kappa(x) is the curvature in x. */
181
virtual double LocH (const Point<3> & p, double x,
182
double c, double hmax) const;
183
184
/**
185
Gets Approximation by triangles,
186
where qual is about the number of triangles per radius
187
*/
188
virtual void GetTriangleApproximation (TriangleApproximation & /* tas */,
189
const Box<3> & /* boundingbox */,
190
double /* facets */ ) const { };
191
192
#ifdef MYGRAPH
193
///
194
virtual void Plot (const class ROT3D & /* rot */) const { };
195
#endif
196
197
string GetBCName() const { return bcname; }
198
199
void SetBCName( string abc ) { bcname = abc; }
200
};
201
202
203
inline ostream & operator<< (ostream & ost, const Surface & surf)
204
{
205
surf.Print(ost);
206
return ost;
207
}
208
209
210
211
typedef enum { IS_OUTSIDE = 0, IS_INSIDE = 1, DOES_INTERSECT = 2}
212
INSOLID_TYPE;
213
214
215
216
217
class Primitive
218
{
219
220
public:
221
222
Primitive ();
223
224
virtual ~Primitive();
225
226
227
/*
228
Check, whether box intersects solid defined by surface.
229
230
return values:
231
0 .. box outside solid \\
232
1 .. box in solid \\
233
2 .. can't decide (allowed, iff box is close to solid)
234
*/
235
virtual INSOLID_TYPE BoxInSolid (const BoxSphere<3> & box) const = 0;
236
virtual INSOLID_TYPE PointInSolid (const Point<3> & p,
237
double eps) const = 0;
238
239
virtual void GetTangentialSurfaceIndices (const Point<3> & p,
240
ARRAY<int> & surfind, double eps) const;
241
242
virtual INSOLID_TYPE VecInSolid (const Point<3> & p,
243
const Vec<3> & v,
244
double eps) const = 0;
245
246
// checks if lim s->0 lim t->0 p + t(v1 + s v2) in solid
247
virtual INSOLID_TYPE VecInSolid2 (const Point<3> & p,
248
const Vec<3> & v1,
249
const Vec<3> & v2,
250
double eps) const;
251
252
// checks if p + s v1 + s*s/2 v2 is inside
253
virtual INSOLID_TYPE VecInSolid3 (const Point<3> & p,
254
const Vec<3> & v1,
255
const Vec<3> & v2,
256
double eps) const;
257
258
// like VecInSolid2, but second order approximation
259
virtual INSOLID_TYPE VecInSolid4 (const Point<3> & p,
260
const Vec<3> & v,
261
const Vec<3> & v2,
262
const Vec<3> & m,
263
double eps) const;
264
265
virtual void GetTangentialVecSurfaceIndices (const Point<3> & p, const Vec<3> & v,
266
ARRAY<int> & surfind, double eps) const;
267
268
virtual void GetTangentialVecSurfaceIndices2 (const Point<3> & p, const Vec<3> & v1, const Vec<3> & v2,
269
ARRAY<int> & surfind, double eps) const;
270
271
272
virtual void CalcSpecialPoints (ARRAY<Point<3> > & pts) const { ; }
273
virtual void AnalyzeSpecialPoint (const Point<3> & pt,
274
ARRAY<Point<3> > & specpts) const { ; }
275
virtual Vec<3> SpecialPointTangentialVector (const Point<3> & p, int s1, int s2) const { return Vec<3> (0,0,0); }
276
277
278
virtual int GetNSurfaces() const = 0;
279
virtual Surface & GetSurface (int i = 0) = 0;
280
virtual const Surface & GetSurface (int i = 0) const = 0;
281
282
ARRAY<int> surfaceids;
283
ARRAY<int> surfaceactive;
284
285
int GetSurfaceId (int i = 0) const;
286
void SetSurfaceId (int i, int id);
287
int SurfaceActive (int i) const { return surfaceactive[i]; }
288
virtual int SurfaceInverted (int i = 0) const { return 0; }
289
290
virtual void GetPrimitiveData (const char *& classname,
291
ARRAY<double> & coeffs) const;
292
virtual void SetPrimitiveData (ARRAY<double> & coeffs);
293
static Primitive * CreatePrimitive (const char * classname);
294
295
296
virtual void Reduce (const BoxSphere<3> & /* box */) { };
297
virtual void UnReduce () { };
298
299
virtual Primitive * Copy () const;
300
virtual void Transform (Transformation<3> & trans);
301
};
302
303
304
305
306
class OneSurfacePrimitive : public Surface, public Primitive
307
{
308
public:
309
OneSurfacePrimitive();
310
~OneSurfacePrimitive();
311
312
virtual INSOLID_TYPE PointInSolid (const Point<3> & p,
313
double eps) const;
314
virtual INSOLID_TYPE VecInSolid (const Point<3> & p,
315
const Vec<3> & v,
316
double eps) const;
317
virtual INSOLID_TYPE VecInSolid2 (const Point<3> & p,
318
const Vec<3> & v1,
319
const Vec<3> & v2,
320
double eps) const;
321
322
virtual INSOLID_TYPE VecInSolid3 (const Point<3> & p,
323
const Vec<3> & v1,
324
const Vec<3> & v2,
325
double eps) const;
326
327
virtual INSOLID_TYPE VecInSolid4 (const Point<3> & p,
328
const Vec<3> & v,
329
const Vec<3> & v2,
330
const Vec<3> & m,
331
double eps) const;
332
333
virtual int GetNSurfaces() const;
334
virtual Surface & GetSurface (int i = 0);
335
virtual const Surface & GetSurface (int i = 0) const;
336
};
337
338
339
340
341
342
343
/**
344
Projects point to edge.
345
The point hp is projected to the edge descibed by f1 and f2.
346
It is assumed that the edge is non-degenerated, and the
347
(generalized) Newton method converges.
348
*/
349
extern void ProjectToEdge (const Surface * f1,
350
const Surface * f2,
351
Point<3> & hp);
352
353
354
355
#endif
356
357