Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ElmerCSC
GitHub Repository: ElmerCSC/elmerfem
Path: blob/devel/post/src/elements/4node_tetra.c
3203 views
1
/*****************************************************************************
2
*
3
* Elmer, A Finite Element Software for Multiphysical Problems
4
*
5
* Copyright 1st April 1995 - , CSC - IT Center for Science Ltd., Finland
6
*
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License
9
* as published by the Free Software Foundation; either version 2
10
* of the License, or (at your option) any later version.
11
*
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
*
17
* You should have received a copy of the GNU General Public License
18
* along with this program (in file fem/GPL-2); if not, write to the
19
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
* Boston, MA 02110-1301, USA.
21
*
22
*****************************************************************************/
23
24
/*******************************************************************************
25
*
26
* Definition of 4 node tetra element
27
*
28
*******************************************************************************
29
*
30
* Author: Juha Ruokolainen
31
*
32
* Address: CSC - IT Center for Science Ltd.
33
* Keilaranta 14, P.O. BOX 405
34
* 02101 Espoo, Finland
35
* Tel. +358 0 457 2723
36
* Telefax: +358 0 457 2302
37
* EMail: [email protected]
38
*
39
* Date: 4 Oct 1995
40
*
41
******************************************************************************/
42
43
#include "../elmerpost.h"
44
#include <elements.h>
45
46
/*
47
* Four node tetra volume element.
48
*
49
* 3
50
* /|\
51
* / | \
52
* / | \
53
* / | \
54
* / 2 \
55
* / / \ \
56
* / / \ \ w v
57
* / / \ \ | /
58
* // \ \ |/
59
* 0-----------------1 ----u
60
*
61
*
62
*/
63
64
static double A[4][4],N[4][4];
65
66
static double NodeU[] = { 0.0, 1.0, 0.0, 0.0 };
67
static double NodeV[] = { 0.0, 0.0, 1.0, 0.0 };
68
static double NodeW[] = { 0.0, 0.0, 0.0, 1.0 };
69
70
71
/*******************************************************************************
72
*
73
* Name: elm_4node_tetra_triangulate
74
*
75
* Purpose: Triangulate an element. The process also builds up an edge
76
* table and adds new nodes to node table. The triangulation
77
* and edge table is stored in geometry_t *geom-structure.
78
*
79
* Parameters:
80
*
81
* Input: (geometry_t *) pointer to structure holding triangulation
82
* (element_t *) element to triangulate
83
*
84
* Output: (geometry_t *) structure is modified
85
*
86
* Return value: FALSE if malloc() fails, TRUE otherwise
87
*
88
******************************************************************************/
89
static int elm_4node_tetra_triangulate( geometry_t *geom,element_t *tetra )
90
{
91
element_t triangle;
92
int i,j;
93
int geo_add_edge();
94
int elm_3node_triangle_triangulate();
95
96
97
if ( GlobalOptions.VolumeSides )
98
{
99
int topo[4];
100
101
triangle.DisplayFlag = TRUE;
102
triangle.Topology = topo;
103
for( i=0; i<MAX_GROUP_IDS; i++ ) triangle.GroupIds[i] = tetra->GroupIds[i];
104
105
for( i=0; i<4; i++ )
106
{
107
for( j=0; j<3; j++ )
108
{
109
triangle.Topology[j] = tetra->Topology[ElmTetraFace[i][j]];
110
}
111
if ( !elm_3node_triangle_triangulate( geom, &triangle, tetra ) ) return FALSE;
112
}
113
} else {
114
if ( !geo_add_edge( geom, tetra->Topology[0],tetra->Topology[2],tetra ) ) return FALSE;
115
if ( !geo_add_edge( geom, tetra->Topology[1],tetra->Topology[2],tetra ) ) return FALSE;
116
if ( !geo_add_edge( geom, tetra->Topology[0],tetra->Topology[3],tetra ) ) return FALSE;
117
if ( !geo_add_edge( geom, tetra->Topology[1],tetra->Topology[3],tetra ) ) return FALSE;
118
if ( !geo_add_edge( geom, tetra->Topology[2],tetra->Topology[3],tetra ) ) return FALSE;
119
}
120
121
return TRUE;
122
}
123
124
/*******************************************************************************
125
*
126
* Name: elm_4node_tetra_point_inside
127
* (
128
* double *nx,double *ny,double *nz,
129
* double px, double py, double pz,
130
* double *u,double *v,double *w
131
* )
132
*
133
* Purpose: Find if point (px,py,pz) is inside the element, and return
134
* element coordinates of the point.
135
*
136
* Parameters:
137
*
138
* Input: (double *) nx,ny,nz n coordinates
139
* (double) px,py,pz point to consider
140
*
141
* Output: (double *) u,v,w point in element coordinates if inside
142
*
143
* Return value: in/out status
144
*
145
* NOTES: the goal here can be hard for more involved element types. kind of
146
* trivial for this one...
147
*
148
******************************************************************************/
149
int elm_4node_tetra_point_inside
150
(
151
double *nx, double *ny, double *nz,
152
double px, double py, double pz, double *u,double *v,double *w
153
)
154
{
155
double B00,B01,B02,B10,B11,B12,B20,B21,B22;
156
double A00,A01,A02,A10,A11,A12,A20,A21,A22,detA;
157
158
if ( px > MAX(MAX(MAX(nx[0],nx[1]),nx[2]),nx[3])) return FALSE;
159
if ( py > MAX(MAX(MAX(ny[0],ny[1]),ny[2]),ny[3])) return FALSE;
160
if ( pz > MAX(MAX(MAX(nz[0],nz[1]),nz[2]),nz[3])) return FALSE;
161
162
if ( px < MIN(MIN(MIN(nx[0],nx[1]),nx[2]),nx[3])) return FALSE;
163
if ( py < MIN(MIN(MIN(ny[0],ny[1]),ny[2]),ny[3])) return FALSE;
164
if ( pz < MIN(MIN(MIN(nz[0],nz[1]),nz[2]),nz[3])) return FALSE;
165
166
A00 = nx[1] - nx[0];
167
A01 = nx[2] - nx[0];
168
A02 = nx[3] - nx[0];
169
170
A10 = ny[1] - ny[0];
171
A11 = ny[2] - ny[0];
172
A12 = ny[3] - ny[0];
173
174
A20 = nz[1] - nz[0];
175
A21 = nz[2] - nz[0];
176
A22 = nz[3] - nz[0];
177
178
detA = A00*(A11*A22 - A12*A21);
179
detA += A01*(A12*A20 - A10*A22);
180
detA += A02*(A10*A21 - A11*A20);
181
if ( ABS(detA) < AEPS )
182
{
183
fprintf( stderr, "4node_tetra_inside: SINGULAR (huh?).\n" );
184
return FALSE;
185
}
186
187
detA = 1 / detA;
188
189
B00 = (A11*A22 - A12*A21)*detA;
190
B10 = (A12*A20 - A10*A22)*detA;
191
B20 = (A10*A21 - A11*A20)*detA;
192
193
B01 = (A21*A02 - A01*A22)*detA;
194
B11 = (A00*A22 - A20*A02)*detA;
195
B21 = (A01*A20 - A00*A21)*detA;
196
197
B02 = (A01*A12 - A11*A02)*detA;
198
B12 = (A10*A02 - A00*A12)*detA;
199
B22 = (A00*A11 - A10*A01)*detA;
200
201
px -= nx[0];
202
py -= ny[0];
203
pz -= nz[0];
204
205
*u = B00*px + B01*py + B02*pz;
206
if ( *u < 0.0 || *u > 1.0 ) return FALSE;
207
208
*v = B10*px + B11*py + B12*pz;
209
if ( *v < 0.0 || *v > 1.0 ) return FALSE;
210
211
*w = B20*px + B21*py + B22*pz;
212
if ( *w < 0.0 || *w > 1.0 ) return FALSE;
213
214
return (*u+*v+*w) <= 1.0;
215
}
216
217
218
/*******************************************************************************
219
*
220
* Name: elm_4node_tetra_isoline
221
*
222
* Purpose: Extract a isoline from triangle with given threshold
223
*
224
* Parameters:
225
*
226
* Input: (double) K, contour threshold
227
* (double *) F, contour quantity
228
* (double *) C, color quantity
229
* (double *) X,Y,Z vertex coords.
230
*
231
* Output: (line_t *) place to store the line
232
*
233
* Return value: number of lines generated (0,...,4)
234
*
235
******************************************************************************/
236
static int elm_4node_tetra_isoline
237
(
238
double K, double *F, double *C,double *X,double *Y,double *Z,line_t *Line
239
)
240
{
241
double f[3],c[3],x[3],y[3],z[3];
242
243
int i, j, k, n=0, above=0;
244
int elm_3node_triangle_isoline();
245
246
for( i=0; i<4; i++ ) above += F[i]>K;
247
if ( above == 0 || above == 4 ) return 0;
248
249
for( i=0; i<4; i++ )
250
{
251
for( j=0; j<3; j++ )
252
{
253
k = ElmTetraFace[i][j];
254
f[j] = F[k];
255
c[j] = C[k];
256
x[j] = X[k];
257
y[j] = Y[k];
258
z[j] = Z[k];
259
}
260
n += elm_3node_triangle_isoline( K,f,c,x,y,z,&Line[n] );
261
}
262
263
return n;
264
}
265
266
267
/*******************************************************************************
268
*
269
* Name: elm_4node_tetra_isosurface
270
*
271
* Purpose: Extract isosurfaces for element
272
*
273
* Parameters:
274
*
275
* Input: (double ) K: contour threshold
276
* (double *) F: contour quantity values at nodes
277
* (double *) C: color quantity values at nodes
278
* (double *) X,Y,Z: node coordinates
279
* (double *) U,V,W: normal vector at nodes
280
*
281
* Output: (polygon_t *)Polygon, output triangles (0,1 or 2) triangles
282
*
283
* Return value: How many triangles we've got...
284
*
285
******************************************************************************/
286
int elm_4node_tetra_isosurface
287
(
288
double K,double *F,double *C, double *X,double *Y,double *Z,
289
double *U,double *V,double *W, polygon_t *Polygon
290
)
291
{
292
double t,tx[4],ty[4],tz[4],tu[4],tv[4],tw[4],tf[4],tc[4];
293
double ax,ay,az,bx,by,bz,nx,ny,nz;
294
295
int S0 = F[0] > K;
296
int S1 = F[1] > K;
297
int S2 = F[2] > K;
298
int S3 = F[3] > K;
299
300
int S = S0+S1+S2+S3,I[4],j;
301
302
if ( S==0 || S==4 ) return 0;
303
304
if ( S==1 || S==3 )
305
{
306
if ( (S==1 && S0) || (S==3 && !S0) )
307
{
308
I[0] = 0;
309
I[1] = 1;
310
I[2] = 2;
311
I[3] = 3;
312
} else if ( (S==1 && S1) || (S==3 && !S1) )
313
{
314
I[0] = 1;
315
I[1] = 0;
316
I[2] = 2;
317
I[3] = 3;
318
} else if ( (S==1 && S2) || (S==3 && !S2) )
319
{
320
I[0] = 2;
321
I[1] = 0;
322
I[2] = 1;
323
I[3] = 3;
324
} else if ( (S==1 && S3) || (S==3 && !S3) )
325
{
326
I[0] = 3;
327
I[1] = 0;
328
I[2] = 1;
329
I[3] = 2;
330
} else { return 0; }
331
332
for( j=1; j<4; j++ )
333
{
334
t = (K-F[I[0]]) / (F[I[j]]-F[I[0]]);
335
Polygon->x[j-1] = t*(X[I[j]]-X[I[0]]) + X[I[0]];
336
Polygon->y[j-1] = t*(Y[I[j]]-Y[I[0]]) + Y[I[0]];
337
Polygon->z[j-1] = t*(Z[I[j]]-Z[I[0]]) + Z[I[0]];
338
Polygon->u[j-1] = t*(U[I[j]]-U[I[0]]) + U[I[0]];
339
Polygon->v[j-1] = t*(V[I[j]]-V[I[0]]) + V[I[0]];
340
Polygon->w[j-1] = t*(W[I[j]]-W[I[0]]) + W[I[0]];
341
Polygon->c[j-1] = t*(C[I[j]]-C[I[0]]) + C[I[0]];
342
Polygon->f[j-1] = K;
343
}
344
345
ax = Polygon->x[1] - Polygon->x[0];
346
ay = Polygon->y[1] - Polygon->y[0];
347
az = Polygon->z[1] - Polygon->z[0];
348
349
bx = Polygon->x[2] - Polygon->x[0];
350
by = Polygon->y[2] - Polygon->y[0];
351
bz = Polygon->z[2] - Polygon->z[0];
352
353
nx = ay*bz - az*by;
354
ny = az*bx - ax*bz;
355
nz = ax*by - ay*bx;
356
357
ax = Polygon->u[0] + Polygon->u[1] + Polygon->u[2];
358
ay = Polygon->v[0] + Polygon->v[1] + Polygon->v[2];
359
az = Polygon->w[0] + Polygon->w[1] + Polygon->w[2];
360
361
if ( nx*ax + ny*ay + nz*az < 0.0 )
362
{
363
double s;
364
365
#define swap( x,y ) { s=x; x=y; y=s; }
366
367
swap( Polygon->x[1], Polygon->x[2] );
368
swap( Polygon->y[1], Polygon->y[2] );
369
swap( Polygon->z[1], Polygon->z[2] );
370
swap( Polygon->u[1], Polygon->u[2] );
371
swap( Polygon->v[1], Polygon->v[2] );
372
swap( Polygon->w[1], Polygon->w[2] );
373
swap( Polygon->f[1], Polygon->f[2] );
374
swap( Polygon->c[1], Polygon->c[2] );
375
376
#undef swap
377
}
378
379
return 1;
380
} else
381
{
382
if ( (S0 && S1) || (!S0 && !S1) )
383
{
384
t = (K-F[0])/ (F[2]-F[0]);
385
tx[0] = t*(X[2]-X[0]) + X[0];
386
ty[0] = t*(Y[2]-Y[0]) + Y[0];
387
tz[0] = t*(Z[2]-Z[0]) + Z[0];
388
tu[0] = t*(U[2]-U[0]) + U[0];
389
tv[0] = t*(V[2]-V[0]) + V[0];
390
tw[0] = t*(W[2]-W[0]) + W[0];
391
tc[0] = t*(C[2]-C[0]) + C[0];
392
tf[0] = K;
393
394
t = (K-F[1]) / (F[2]-F[1]);
395
tx[1] = t*(X[2]-X[1]) + X[1];
396
ty[1] = t*(Y[2]-Y[1]) + Y[1];
397
tz[1] = t*(Z[2]-Z[1]) + Z[1];
398
tu[1] = t*(U[2]-U[1]) + U[1];
399
tv[1] = t*(V[2]-V[1]) + V[1];
400
tw[1] = t*(W[2]-W[1]) + W[1];
401
tc[1] = t*(C[2]-C[1]) + C[1];
402
tf[1] = K;
403
404
t = (K-F[1]) / (F[3]-F[1]);
405
tx[2] = t*(X[3]-X[1]) + X[1];
406
ty[2] = t*(Y[3]-Y[1]) + Y[1];
407
tz[2] = t*(Z[3]-Z[1]) + Z[1];
408
tu[2] = t*(U[3]-U[1]) + U[1];
409
tv[2] = t*(V[3]-V[1]) + V[1];
410
tw[2] = t*(W[3]-W[1]) + W[1];
411
tc[2] = t*(C[3]-C[1]) + C[1];
412
tf[2] = K;
413
414
t = (K-F[0]) / (F[3]-F[0]);
415
tx[3] = t*(X[3]-X[0]) + X[0];
416
ty[3] = t*(Y[3]-Y[0]) + Y[0];
417
tz[3] = t*(Z[3]-Z[0]) + Z[0];
418
tu[3] = t*(U[3]-U[0]) + U[0];
419
tv[3] = t*(V[3]-V[0]) + V[0];
420
tw[3] = t*(W[3]-W[0]) + W[0];
421
tc[3] = t*(C[3]-C[0]) + C[0];
422
tf[3] = K;
423
}
424
else if ( (S0 && S2) || (!S0 && !S2) )
425
{
426
t = (K-F[0]) / (F[1]-F[0]);
427
tx[0] = t*(X[1]-X[0]) + X[0];
428
ty[0] = t*(Y[1]-Y[0]) + Y[0];
429
tz[0] = t*(Z[1]-Z[0]) + Z[0];
430
tu[0] = t*(U[1]-U[0]) + U[0];
431
tv[0] = t*(V[1]-V[0]) + V[0];
432
tw[0] = t*(W[1]-W[0]) + W[0];
433
tc[0] = t*(C[1]-C[0]) + C[0];
434
tf[0] = K;
435
436
t = (K-F[2]) / (F[1]-F[2]);
437
tx[1] = t*(X[1]-X[2]) + X[2];
438
ty[1] = t*(Y[1]-Y[2]) + Y[2];
439
tz[1] = t*(Z[1]-Z[2]) + Z[2];
440
tu[1] = t*(U[1]-U[2]) + U[2];
441
tv[1] = t*(V[1]-V[2]) + V[2];
442
tw[1] = t*(W[1]-W[2]) + W[2];
443
tc[1] = t*(C[1]-C[2]) + C[2];
444
tf[1] = K;
445
446
t = (K-F[2]) / (F[3]-F[2]);
447
tx[2] = t*(X[3]-X[2]) + X[2];
448
ty[2] = t*(Y[3]-Y[2]) + Y[2];
449
tz[2] = t*(Z[3]-Z[2]) + Z[2];
450
tu[2] = t*(U[3]-U[2]) + U[2];
451
tv[2] = t*(V[3]-V[2]) + V[2];
452
tw[2] = t*(W[3]-W[2]) + W[2];
453
tc[2] = t*(C[3]-C[2]) + C[2];
454
tf[2] = K;
455
456
t = (K-F[0]) / (F[3]-F[0]);
457
tx[3] = t*(X[3]-X[0]) + X[0];
458
ty[3] = t*(Y[3]-Y[0]) + Y[0];
459
tz[3] = t*(Z[3]-Z[0]) + Z[0];
460
tu[3] = t*(U[3]-U[0]) + U[0];
461
tv[3] = t*(V[3]-V[0]) + V[0];
462
tw[3] = t*(W[3]-W[0]) + W[0];
463
tc[3] = t*(C[3]-C[0]) + C[0];
464
tf[3] = K;
465
}
466
else if ( (S0 && S3) || (!S0 && !S3) )
467
{
468
t = (K-F[0]) / (F[1]-F[0]);
469
tx[0] = t*(X[1]-X[0]) + X[0];
470
ty[0] = t*(Y[1]-Y[0]) + Y[0];
471
tz[0] = t*(Z[1]-Z[0]) + Z[0];
472
tu[0] = t*(U[1]-U[0]) + U[0];
473
tv[0] = t*(V[1]-V[0]) + V[0];
474
tw[0] = t*(W[1]-W[0]) + W[0];
475
tc[0] = t*(C[1]-C[0]) + C[0];
476
tf[0] = K;
477
478
t = (K-F[3]) / (F[1]-F[3]);
479
tx[1] = t*(X[1]-X[3]) + X[3];
480
ty[1] = t*(Y[1]-Y[3]) + Y[3];
481
tz[1] = t*(Z[1]-Z[3]) + Z[3];
482
tu[1] = t*(U[1]-U[3]) + U[3];
483
tv[1] = t*(V[1]-V[3]) + V[3];
484
tw[1] = t*(W[1]-W[3]) + W[3];
485
tc[1] = t*(C[1]-C[3]) + C[3];
486
tf[1] = K;
487
488
t = (K-F[3]) / (F[2]-F[3]);
489
tx[2] = t*(X[2]-X[3]) + X[3];
490
ty[2] = t*(Y[2]-Y[3]) + Y[3];
491
tz[2] = t*(Z[2]-Z[3]) + Z[3];
492
tu[2] = t*(U[2]-U[3]) + U[3];
493
tv[2] = t*(V[2]-V[3]) + V[3];
494
tw[2] = t*(W[2]-W[3]) + W[3];
495
tc[2] = t*(C[2]-C[3]) + C[3];
496
tf[2] = K;
497
498
t = (K-F[0]) / (F[2]-F[0]);
499
tx[3] = t*(X[2]-X[0]) + X[0];
500
ty[3] = t*(Y[2]-Y[0]) + Y[0];
501
tz[3] = t*(Z[2]-Z[0]) + Z[0];
502
tu[3] = t*(U[2]-U[0]) + U[0];
503
tv[3] = t*(V[2]-V[0]) + V[0];
504
tw[3] = t*(W[2]-W[0]) + W[0];
505
tc[3] = t*(C[2]-C[0]) + C[0];
506
tf[3] = K;
507
}
508
509
Polygon[0].x[0] = tx[0];
510
Polygon[0].y[0] = ty[0];
511
Polygon[0].z[0] = tz[0];
512
Polygon[0].u[0] = tu[0];
513
Polygon[0].v[0] = tv[0];
514
Polygon[0].w[0] = tw[0];
515
Polygon[0].f[0] = tf[0];
516
Polygon[0].c[0] = tc[0];
517
518
ax = tx[1] - tx[0];
519
ay = ty[1] - ty[0];
520
az = tz[1] - tz[0];
521
522
bx = tx[2] - tx[0];
523
by = ty[2] - ty[0];
524
bz = tz[2] - tz[0];
525
526
nx = ay*bz - az*by;
527
ny = az*bx - ax*bz;
528
nz = ax*by - ay*bx;
529
530
ax = tu[0] + tu[1] + tu[2] + tu[3];
531
ay = tv[0] + tv[1] + tv[2] + tv[3];
532
az = tw[0] + tw[1] + tw[2] + tw[3];
533
534
if ( nx*ax + ny*ay + nz*az >= 0.0 )
535
{
536
Polygon[0].x[1] = tx[1];
537
Polygon[0].y[1] = ty[1];
538
Polygon[0].z[1] = tz[1];
539
Polygon[0].u[1] = tu[1];
540
Polygon[0].v[1] = tv[1];
541
Polygon[0].w[1] = tw[1];
542
Polygon[0].f[1] = tf[1];
543
Polygon[0].c[1] = tc[1];
544
545
Polygon[0].x[2] = tx[2];
546
Polygon[0].y[2] = ty[2];
547
Polygon[0].z[2] = tz[2];
548
Polygon[0].u[2] = tu[2];
549
Polygon[0].v[2] = tv[2];
550
Polygon[0].w[2] = tw[2];
551
Polygon[0].f[2] = tf[2];
552
Polygon[0].c[2] = tc[2];
553
} else
554
{
555
Polygon[0].x[1] = tx[2];
556
Polygon[0].y[1] = ty[2];
557
Polygon[0].z[1] = tz[2];
558
Polygon[0].u[1] = tu[2];
559
Polygon[0].v[1] = tv[2];
560
Polygon[0].w[1] = tw[2];
561
Polygon[0].f[1] = tf[2];
562
Polygon[0].c[1] = tc[2];
563
564
Polygon[0].x[2] = tx[1];
565
Polygon[0].y[2] = ty[1];
566
Polygon[0].z[2] = tz[1];
567
Polygon[0].u[2] = tu[1];
568
Polygon[0].v[2] = tv[1];
569
Polygon[0].w[2] = tw[1];
570
Polygon[0].f[2] = tf[1];
571
Polygon[0].c[2] = tc[1];
572
}
573
574
Polygon[1].x[0] = tx[0];
575
Polygon[1].y[0] = ty[0];
576
Polygon[1].z[0] = tz[0];
577
Polygon[1].u[0] = tu[0];
578
Polygon[1].v[0] = tv[0];
579
Polygon[1].w[0] = tw[0];
580
Polygon[1].f[0] = tf[0];
581
Polygon[1].c[0] = tc[0];
582
583
ax = tx[2] - tx[0];
584
ay = ty[2] - ty[0];
585
az = tz[2] - tz[0];
586
587
bx = tx[3] - tx[0];
588
by = ty[3] - ty[0];
589
bz = tz[3] - tz[0];
590
591
nx = ay*bz - az*by;
592
ny = az*bx - ax*bz;
593
nz = ax*by - ay*bx;
594
595
ax = tu[0] + tu[1] + tu[2] + tu[3];
596
ay = tv[0] + tv[1] + tv[2] + tv[3];
597
az = tw[0] + tw[1] + tw[2] + tw[3];
598
599
if ( nx*ax + ny*ay + nz*az >= 0.0 )
600
{
601
Polygon[1].x[1] = tx[2];
602
Polygon[1].y[1] = ty[2];
603
Polygon[1].z[1] = tz[2];
604
Polygon[1].u[1] = tu[2];
605
Polygon[1].v[1] = tv[2];
606
Polygon[1].w[1] = tw[2];
607
Polygon[1].f[1] = tf[2];
608
Polygon[1].c[1] = tc[2];
609
610
Polygon[1].x[2] = tx[3];
611
Polygon[1].y[2] = ty[3];
612
Polygon[1].z[2] = tz[3];
613
Polygon[1].u[2] = tu[3];
614
Polygon[1].v[2] = tv[3];
615
Polygon[1].w[2] = tw[3];
616
Polygon[1].f[2] = tf[3];
617
Polygon[1].c[2] = tc[3];
618
} else
619
{
620
Polygon[1].x[1] = tx[3];
621
Polygon[1].y[1] = ty[3];
622
Polygon[1].z[1] = tz[3];
623
Polygon[1].u[1] = tu[3];
624
Polygon[1].v[1] = tv[3];
625
Polygon[1].w[1] = tw[3];
626
Polygon[1].f[1] = tf[3];
627
Polygon[1].c[1] = tc[3];
628
629
Polygon[1].x[2] = tx[2];
630
Polygon[1].y[2] = ty[2];
631
Polygon[1].z[2] = tz[2];
632
Polygon[1].u[2] = tu[2];
633
Polygon[1].v[2] = tv[2];
634
Polygon[1].w[2] = tw[2];
635
Polygon[1].f[2] = tf[2];
636
Polygon[1].c[2] = tc[2];
637
}
638
639
return 2;
640
}
641
642
return 0;
643
}
644
645
/*******************************************************************************
646
*
647
* Name: elm_4node_tetra_shape_functions
648
*
649
* Purpose: Initialize element shape function array. Internal only.
650
*
651
* Parameters:
652
*
653
* Input: Global (filewise) variables NodeU,NodeV,NodeW
654
*
655
* Output: Global (filewise) variable N[4][4], will contain
656
* shape function coefficients
657
*
658
* Return value: void
659
*
660
******************************************************************************/
661
static void elm_4node_tetra_shape_functions()
662
{
663
double u,v,w;
664
int i,j;
665
666
for( i=0; i<4; i++ )
667
{
668
u = NodeU[i];
669
v = NodeV[i];
670
w = NodeW[i];
671
672
A[i][0] = 1;
673
A[i][1] = u;
674
A[i][2] = v;
675
A[i][3] = w;
676
}
677
678
lu_mtrinv( (double *)A,4 );
679
680
for( i=0; i<4; i++ )
681
for( j=0; j<4; j++ ) N[i][j] = A[j][i];
682
}
683
684
/*******************************************************************************
685
*
686
* Name: elm_4node_tetra_fvalue
687
*
688
* Purpose: return value of a quantity given on nodes at point (u,v)
689
* Use trough (element_type_t *) structure.
690
*
691
* Parameters:
692
*
693
* Input: (double *) quantity values at nodes
694
* (double u,double v) point where values are evaluated
695
*
696
* Output: none
697
*
698
* Return value: quantity value
699
*
700
******************************************************************************/
701
static double elm_4node_tetra_fvalue(double *F,double u,double v,double w)
702
{
703
double R=0.0;
704
int i;
705
706
for( i=0; i<4; i++ )
707
{
708
R += F[i]*(N[i][0]+N[i][1]*u+N[i][2]*v+N[i][3]*w);
709
}
710
711
return R;
712
}
713
714
/*******************************************************************************
715
*
716
* Name: elm_4node_tetra_dndu_fvalue
717
*
718
* Purpose: return value of a first partial derivate in (v) of a
719
* quantity given on nodes at point (u,v).
720
* Use trough (element_type_t *) structure.
721
*
722
*
723
* Parameters:
724
*
725
* Input: (double *) quantity values at nodes
726
* (double u,double v,double w) point where values are evaluated
727
*
728
* Output: none
729
*
730
* Return value: quantity value
731
*
732
******************************************************************************/
733
static double elm_4node_tetra_dndu_fvalue(double *F,double u,double v,double w)
734
{
735
double R=0.0;
736
int i;
737
738
for( i=0; i<4; i++ ) R += F[i]*N[i][1];
739
740
return R;
741
}
742
743
/*******************************************************************************
744
*
745
* Name: elm_4node_tetra_dndv_fvalue
746
*
747
* Purpose: return value of a first partial derivate in (v) of a
748
* quantity given on nodes at point (u,v,w).
749
* Use trough (element_type_t *) structure.
750
*
751
*
752
* Parameters:
753
*
754
* Input: (double *) quantity values at nodes
755
* (double u,double v,double w) point where values are evaluated
756
*
757
* Output: none
758
*
759
* Return value: quantity value
760
*
761
******************************************************************************/
762
static double elm_4node_tetra_dndv_fvalue(double *F,double u,double v,double w)
763
{
764
double R=0.0;
765
int i;
766
767
for( i=0; i<4; i++ ) R += F[i]*N[i][2];
768
769
return R;
770
}
771
772
/*******************************************************************************
773
*
774
* Name: elm_4node_tetra_dndw_fvalue
775
*
776
* Purpose: return value of a first partial derivate in (w) of a
777
* quantity given on nodes at point (u,v,w)
778
* Use trough (element_type_t *) structure.
779
*
780
*
781
* Parameters:
782
*
783
* Input: (double *) quantity values at nodes
784
* (double u,double v,double w) point where values are evaluated
785
*
786
* Output: none
787
*
788
* Return value: quantity value
789
*
790
******************************************************************************/
791
static double elm_4node_tetra_dndw_fvalue(double *F,double u,double v,double w)
792
{
793
double R=0.0;
794
int i;
795
796
for( i=0; i<4; i++ ) R += F[i]*N[i][3];
797
798
return R;
799
}
800
801
/******************************************************************************
802
*
803
* Name: elm_4node_tetra_initialize
804
*
805
* Purpose: Register the element type
806
*
807
* Parameters:
808
*
809
* Input: (char *) description of the element
810
* (int) numeric code for the element
811
*
812
* Output: Global list of element types is modified
813
*
814
* Return value: malloc() success
815
*
816
******************************************************************************/
817
int elm_4node_tetra_initialize()
818
{
819
static char *Name = "ELM_4NODE_TETRA";
820
821
element_type_t ElementDef;
822
int elm_add_element_type();
823
824
elm_4node_tetra_shape_functions();
825
826
ElementDef.ElementName = Name;
827
ElementDef.ElementCode = 504;
828
829
ElementDef.NumberOfNodes = 4;
830
831
ElementDef.NodeU = NodeU;
832
ElementDef.NodeV = NodeV;
833
ElementDef.NodeW = NodeW;
834
835
ElementDef.PartialU = (double (*)())elm_4node_tetra_dndu_fvalue;
836
ElementDef.PartialV = (double (*)())elm_4node_tetra_dndv_fvalue;
837
ElementDef.PartialW = (double (*)())elm_4node_tetra_dndw_fvalue;
838
839
ElementDef.FunctionValue = (double (*)())elm_4node_tetra_fvalue;
840
ElementDef.Triangulate = (int (*)())elm_4node_tetra_triangulate;
841
ElementDef.IsoLine = (int (*)())elm_4node_tetra_isoline;
842
ElementDef.IsoSurface = (int (*)())elm_4node_tetra_isosurface;
843
ElementDef.PointInside = (int (*)())elm_4node_tetra_point_inside;
844
845
return elm_add_element_type( &ElementDef );
846
}
847
848
849