1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * Rappture::FieldPrism3D |
---|
4 | * This is a continuous, linear function defined by a series of |
---|
5 | * points on a 3D prismatic mesh. It's a scalar field defined |
---|
6 | * in 3D space. |
---|
7 | * |
---|
8 | * ====================================================================== |
---|
9 | * AUTHOR: Michael McLennan, Purdue University |
---|
10 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
11 | * |
---|
12 | * See the file "license.terms" for information on usage and |
---|
13 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
14 | * ====================================================================== |
---|
15 | */ |
---|
16 | #include "RpFieldPrism3D.h" |
---|
17 | |
---|
18 | using namespace Rappture; |
---|
19 | |
---|
20 | FieldPrism3D::FieldPrism3D() |
---|
21 | : _valuelist(), |
---|
22 | _meshPtr(NULL), |
---|
23 | _counter(0) |
---|
24 | { |
---|
25 | } |
---|
26 | |
---|
27 | FieldPrism3D::FieldPrism3D(const MeshTri2D& xyg, const Mesh1D& zg) |
---|
28 | : _valuelist(), |
---|
29 | _meshPtr(NULL), |
---|
30 | _counter(0) |
---|
31 | { |
---|
32 | _meshPtr = Ptr<MeshPrism3D>( new MeshPrism3D(xyg,zg) ); |
---|
33 | int npts = xyg.sizeNodes()*zg.size(); |
---|
34 | _valuelist.reserve(npts); |
---|
35 | } |
---|
36 | |
---|
37 | FieldPrism3D::FieldPrism3D(const FieldPrism3D& field) |
---|
38 | : _valuelist(field._valuelist), |
---|
39 | _meshPtr(field._meshPtr), |
---|
40 | _counter(field._counter) |
---|
41 | { |
---|
42 | } |
---|
43 | |
---|
44 | FieldPrism3D& |
---|
45 | FieldPrism3D::operator=(const FieldPrism3D& field) |
---|
46 | { |
---|
47 | _valuelist = field._valuelist; |
---|
48 | _meshPtr = field._meshPtr; |
---|
49 | _counter = field._counter; |
---|
50 | return *this; |
---|
51 | } |
---|
52 | |
---|
53 | FieldPrism3D::~FieldPrism3D() |
---|
54 | { |
---|
55 | } |
---|
56 | |
---|
57 | double |
---|
58 | FieldPrism3D::rangeMin(Axis which) const |
---|
59 | { |
---|
60 | if (!_meshPtr.isNull()) { |
---|
61 | return _meshPtr->rangeMin(which); |
---|
62 | } |
---|
63 | return 0.0; |
---|
64 | } |
---|
65 | |
---|
66 | double |
---|
67 | FieldPrism3D::rangeMax(Axis which) const |
---|
68 | { |
---|
69 | if (!_meshPtr.isNull()) { |
---|
70 | return _meshPtr->rangeMax(which); |
---|
71 | } |
---|
72 | return 0.0; |
---|
73 | } |
---|
74 | |
---|
75 | FieldPrism3D& |
---|
76 | FieldPrism3D::define(int nodeId, double f) |
---|
77 | { |
---|
78 | while (_valuelist.size() <= (unsigned int)nodeId) { |
---|
79 | _valuelist.push_back(NAN); |
---|
80 | } |
---|
81 | _valuelist[nodeId] = f; |
---|
82 | |
---|
83 | if (isnan(_vmin) || isnan(_vmax)) { |
---|
84 | _vmin = _vmax = f; |
---|
85 | } else { |
---|
86 | if (f < _vmin) { _vmin = f; } |
---|
87 | if (f > _vmax) { _vmax = f; } |
---|
88 | } |
---|
89 | return *this; |
---|
90 | } |
---|
91 | |
---|
92 | double |
---|
93 | FieldPrism3D::value(double x, double y, double z, double outside) const |
---|
94 | { |
---|
95 | if (!_meshPtr.isNull()) { |
---|
96 | CellPrism3D cell = _meshPtr->locate(Node3D(x,y,z)); |
---|
97 | |
---|
98 | // outside the defined data? then return the outside value |
---|
99 | if (cell.isOutside()) { |
---|
100 | return outside; |
---|
101 | } |
---|
102 | |
---|
103 | // interpolate first xy triangle |
---|
104 | double fz0, fz1, phi[3]; |
---|
105 | |
---|
106 | Node2D node( x, y ); |
---|
107 | Node2D n1( cell.x(0), cell.y(0) ); |
---|
108 | Node2D n2( cell.x(1), cell.y(1) ); |
---|
109 | Node2D n3( cell.x(2), cell.y(2) ); |
---|
110 | |
---|
111 | CellTri2D tri(0, &n1, &n2, &n3); |
---|
112 | tri.barycentrics(node, phi); |
---|
113 | |
---|
114 | fz0 = phi[0]*_valuelist[ cell.nodeId(0) ] |
---|
115 | + phi[1]*_valuelist[ cell.nodeId(1) ] |
---|
116 | + phi[2]*_valuelist[ cell.nodeId(2) ]; |
---|
117 | |
---|
118 | // interpolate second xy triangle |
---|
119 | fz1 = phi[0]*_valuelist[ cell.nodeId(3) ] |
---|
120 | + phi[1]*_valuelist[ cell.nodeId(4) ] |
---|
121 | + phi[2]*_valuelist[ cell.nodeId(5) ]; |
---|
122 | |
---|
123 | double zrange = cell.z(5) - cell.z(0); |
---|
124 | |
---|
125 | if (zrange == 0.0) { |
---|
126 | // interval undefined? then return avg value |
---|
127 | return 0.5*(fz1+fz0); |
---|
128 | } |
---|
129 | // interpolate along z-axis |
---|
130 | double delz = z - cell.z(0); |
---|
131 | return fz0 + (delz/zrange)*(fz1-fz0); |
---|
132 | } |
---|
133 | return outside; |
---|
134 | } |
---|
135 | |
---|
136 | double |
---|
137 | FieldPrism3D::valueMin() const |
---|
138 | { |
---|
139 | return _vmin; |
---|
140 | } |
---|
141 | |
---|
142 | double |
---|
143 | FieldPrism3D::valueMax() const |
---|
144 | { |
---|
145 | return _vmax; |
---|
146 | } |
---|