source: trunk/src/core2/RpFieldTri2D.cc @ 1030

Last change on this file since 1030 was 446, checked in by mmc, 18 years ago

Fixed memory problems causing core dumps. The reserve() function doesn't
allocate any elements--just makes their later allocation more efficient.

File size: 2.9 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  Rappture::FieldTri2D
4 *    This is a continuous, linear function defined by a series of
5 *    points on a 2D unstructured mesh.  It's a scalar field defined
6 *    in 2D 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 "RpFieldTri2D.h"
17
18using namespace Rappture;
19
20FieldTri2D::FieldTri2D()
21  : _valuelist(),
22    _vmin(NAN),
23    _vmax(NAN),
24    _meshPtr(NULL),
25    _counter(0)
26{
27}
28
29FieldTri2D::FieldTri2D(const MeshTri2D& grid)
30  : _valuelist(),
31    _vmin(NAN),
32    _vmax(NAN),
33    _meshPtr(NULL),
34    _counter(0)
35{
36    _meshPtr = Ptr<MeshTri2D>( new MeshTri2D(grid) );
37}
38
39FieldTri2D::FieldTri2D(const FieldTri2D& field)
40  : _valuelist(field._valuelist),
41    _vmin(field._vmin),
42    _vmax(field._vmax),
43    _meshPtr(field._meshPtr),
44    _counter(field._counter)
45{
46}
47
48FieldTri2D&
49FieldTri2D::operator=(const FieldTri2D& field)
50{
51    _valuelist = field._valuelist;
52    _vmin = field._vmin;
53    _vmax = field._vmax;
54    _meshPtr = field._meshPtr;
55    _counter = field._counter;
56    return *this;
57}
58
59FieldTri2D::~FieldTri2D()
60{
61}
62
63int
64FieldTri2D::size() const
65{
66    return _meshPtr->sizeNodes();
67}
68
69Node2D&
70FieldTri2D::atNode(int pos)
71{
72    static Node2D null(0.0,0.0);
73
74    if (!_meshPtr.isNull()) {
75        return _meshPtr->atNode(pos);
76    }
77    return null;
78}
79
80double
81FieldTri2D::rangeMin(Axis which) const
82{
83    if (!_meshPtr.isNull()) {
84        return _meshPtr->rangeMin(which);
85    }
86    return 0.0;
87}
88
89double
90FieldTri2D::rangeMax(Axis which) const
91{
92    if (!_meshPtr.isNull()) {
93        return _meshPtr->rangeMax(which);
94    }
95    return 0.0;
96}
97
98FieldTri2D&
99FieldTri2D::define(int nodeId, double f)
100{
101    while (_valuelist.size() < nodeId) {
102        _valuelist.push_back(NAN);
103    }
104    _valuelist[nodeId] = f;
105
106    if (isnan(_vmin) || isnan(_vmax)) {
107        _vmin = _vmax = f;
108    } else {
109        if (f < _vmin) { _vmin = f; }
110        if (f > _vmax) { _vmax = f; }
111    }
112    return *this;
113}
114
115double
116FieldTri2D::value(double x, double y, double outside) const
117{
118    if (!_meshPtr.isNull()) {
119        Node2D node(x,y);
120        CellTri2D cell = _meshPtr->locate(node);
121
122        if (!cell.isNull()) {
123            double phi[3];
124            cell.barycentrics(node, phi);
125
126            int n0 = cell.nodeId(0);
127            int n1 = cell.nodeId(1);
128            int n2 = cell.nodeId(2);
129
130            return phi[0]*_valuelist[n0]
131                 + phi[1]*_valuelist[n1]
132                 + phi[2]*_valuelist[n2];
133        }
134    }
135    return outside;
136}
137
138double
139FieldTri2D::valueMin() const
140{
141    return _vmin;
142}
143
144double
145FieldTri2D::valueMax() const
146{
147    return _vmax;
148}
Note: See TracBrowser for help on using the repository browser.