source: branches/1.3/src/core2/RpFieldPrism3D.cc @ 5348

Last change on this file since 5348 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

File size: 3.6 KB
Line 
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-2012  HUBzero Foundation, LLC
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
18using namespace Rappture;
19
20FieldPrism3D::FieldPrism3D()
21  : _valuelist(),
22    _vmin(NAN),
23    _vmax(NAN),
24    _meshPtr(NULL),
25    _counter(0)
26{
27}
28
29FieldPrism3D::FieldPrism3D(const MeshTri2D& xyg, const Mesh1D& zg)
30  : _valuelist(),
31    _vmin(NAN),
32    _vmax(NAN),
33    _meshPtr(NULL),
34    _counter(0)
35{
36    _meshPtr = Ptr<MeshPrism3D>( new MeshPrism3D(xyg,zg) );
37    int npts = xyg.sizeNodes()*zg.size();
38    _valuelist.reserve(npts);
39}
40
41FieldPrism3D::FieldPrism3D(const FieldPrism3D& field)
42  : _valuelist(field._valuelist),
43    _vmin(field._vmin),
44    _vmax(field._vmax),
45    _meshPtr(field._meshPtr),
46    _counter(field._counter)
47{
48}
49
50FieldPrism3D&
51FieldPrism3D::operator=(const FieldPrism3D& field)
52{
53    _valuelist = field._valuelist;
54    _vmin = field._vmin;
55    _vmax = field._vmax;
56    _meshPtr = field._meshPtr;
57    _counter = field._counter;
58    return *this;
59}
60
61FieldPrism3D::~FieldPrism3D()
62{
63}
64
65double
66FieldPrism3D::rangeMin(Axis which) const
67{
68    if (!_meshPtr.isNull()) {
69        return _meshPtr->rangeMin(which);
70    }
71    return 0.0;
72}
73
74double
75FieldPrism3D::rangeMax(Axis which) const
76{
77    if (!_meshPtr.isNull()) {
78        return _meshPtr->rangeMax(which);
79    }
80    return 0.0;
81}
82
83FieldPrism3D&
84FieldPrism3D::define(int nodeId, double f)
85{
86    if (_valuelist.size() < (unsigned int)(nodeId+1)) {
87        _valuelist.resize((unsigned int)(nodeId+1), NAN);
88    }
89    _valuelist[nodeId] = f;
90
91    if (isnan(_vmin) || isnan(_vmax)) {
92        _vmin = _vmax = f;
93    } else {
94        if (f < _vmin) { _vmin = f; }
95        if (f > _vmax) { _vmax = f; }
96    }
97    return *this;
98}
99
100double
101FieldPrism3D::value(double x, double y, double z, double outside) const
102{
103    if (!_meshPtr.isNull()) {
104        CellPrism3D cell = _meshPtr->locate(Node3D(x,y,z));
105
106        // outside the defined data? then return the outside value
107        if (cell.isOutside()) {
108            return outside;
109        }
110
111        // interpolate first xy triangle
112        double fz0, fz1, phi[3];
113
114        Node2D node( x, y );
115        Node2D n1( cell.x(0), cell.y(0) );
116        Node2D n2( cell.x(1), cell.y(1) );
117        Node2D n3( cell.x(2), cell.y(2) );
118
119        CellTri2D tri(0, &n1, &n2, &n3);
120        tri.barycentrics(node, phi);
121
122        fz0 = phi[0]*_valuelist[ cell.nodeId(0) ]
123            + phi[1]*_valuelist[ cell.nodeId(1) ]
124            + phi[2]*_valuelist[ cell.nodeId(2) ];
125
126        // interpolate second xy triangle
127        fz1 = phi[0]*_valuelist[ cell.nodeId(3) ]
128            + phi[1]*_valuelist[ cell.nodeId(4) ]
129            + phi[2]*_valuelist[ cell.nodeId(5) ];
130
131        double zrange = cell.z(5) - cell.z(0);
132
133        if (zrange == 0.0) {
134            // interval undefined? then return avg value
135            return 0.5*(fz1+fz0);
136        }
137        // interpolate along z-axis
138        double delz = z - cell.z(0);
139        return fz0 + (delz/zrange)*(fz1-fz0);
140    }
141    return outside;
142}
143
144double
145FieldPrism3D::valueMin() const
146{
147    return _vmin;
148}
149
150double
151FieldPrism3D::valueMax() const
152{
153    return _vmax;
154}
Note: See TracBrowser for help on using the repository browser.