1
1
// Copyright (C) 2002 Johan Hoffman and Anders Logg.
2
2
// Licensed under the GNU GPL Version 2.
4
#include <dolfin/Node.h>
5
#include <dolfin/Point.h>
4
6
#include <dolfin/Cell.h>
5
7
#include <dolfin/Tetrahedron.h>
7
9
using namespace dolfin;
9
11
//-----------------------------------------------------------------------------
10
int Tetrahedron::noNodes()
12
int Tetrahedron::noNodes() const
14
16
//-----------------------------------------------------------------------------
15
int Tetrahedron::noEdges()
17
int Tetrahedron::noEdges() const
19
21
//-----------------------------------------------------------------------------
20
int Tetrahedron::noFaces()
22
int Tetrahedron::noFaces() const
24
26
//-----------------------------------------------------------------------------
25
int Tetrahedron::noBoundaries()
27
int Tetrahedron::noBound() const
29
31
//-----------------------------------------------------------------------------
30
Cell::Type Tetrahedron::type()
32
Cell::Type Tetrahedron::type() const
32
34
return Cell::TETRAHEDRON;
34
36
//-----------------------------------------------------------------------------
36
real Tetrahedron::ComputeVolume(Grid *grid)
38
// Get the coordinates
39
Point *A = nodes[0]->GetCoord();
40
Point *B = nodes[1]->GetCoord();
41
Point *C = nodes[2]->GetCoord();
42
Point *D = nodes[3]->GetCoord();
44
// Make sure we get full precision
45
real x1, x2, x3, x4, y1, y2, y3, y4, z1, z2, z3, z4;
47
x1 = real(A->x); y1 = real(A->y); z1 = real(A->z);
48
x2 = real(B->x); y2 = real(B->y); z2 = real(B->z);
49
x3 = real(C->x); y3 = real(C->y); z3 = real(C->z);
50
x4 = real(D->x); y4 = real(D->y); z4 = real(D->z);
52
// Formula for volume from http://mathworld.wolfram.com
53
real v = ( x1 * ( y2*z3 + y4*z2 + y3*z4 - y3*z2 - y2*z4 - y4*z3 ) -
54
x2 * ( y1*z3 + y4*z1 + y3*z4 - y3*z1 - y1*z4 - y4*z3 ) +
55
x3 * ( y1*z2 + y4*z1 + y2*z4 - y2*z1 - y1*z4 - y4*z2 ) -
56
x4 * ( y1*z2 + y2*z3 + y3*z1 - y2*z1 - y3*z2 - y1*z3 ) );
58
//display->Message(0,"A = (%f,%f,%f)\nB = (%f,%f,%f)\nC = (%f,%f,%f)\nD = (%f,%f,%f)\n",
64
v = ( v >= 0.0 ? v : -v );
68
//-----------------------------------------------------------------------------
69
real Tetrahedron::ComputeCircumRadius(Grid *grid)
72
real volume = ComputeVolume(grid);
75
real radius = ComputeCircumRadius(grid,volume);
77
//display->Message(0,"v = %f R = %f",volume,radius);
82
//-----------------------------------------------------------------------------
83
real Tetrahedron::ComputeCircumRadius(Grid *grid, real volume)
85
// Get the coordinates
86
Point *A = nodes[0]->GetCoord();
87
Point *B = nodes[1]->GetCoord();
88
Point *C = nodes[2]->GetCoord();
89
Point *D = nodes[3]->GetCoord();
91
// Compute side lengths
92
real a = B->Distance(*C);
93
real b = A->Distance(*C);
94
real c = A->Distance(*B);
95
real aa = A->Distance(*D);
96
real bb = B->Distance(*D);
97
real cc = C->Distance(*D);
99
// Compute "area" of triangle with strange side lengths
103
real s = 0.5*(l1+l2+l3);
104
real area = sqrt(s*(s-l1)*(s-l2)*(s-l3));
106
// Formula for radius from http://mathworld.wolfram.com
107
real R = area/(6.0*volume);
112
//-----------------------------------------------------------------------------
113
bool Tetrahedron::neighbor(ShortList<Node *> &cn, Cell &cell)
37
bool Tetrahedron::neighbor(ShortList<Node *> &cn, Cell &cell) const
115
39
// Two tetrahedrons are neighbors if they have a common face or if they are
116
40
// the same tetrahedron, i.e. if they have 3 or 4 common nodes.