source: branches/1.7/src/core2/RpFieldTri2D.cc @ 6313

Last change on this file since 6313 was 5679, checked in by ldelgass, 9 years ago

Full merge 1.3 branch to uq branch to sync. Fixed partial subdirectory merge
by removing mergeinfo from lang/python/Rappture directory.

  • Property svn:eol-style set to native
File size: 3.0 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-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 "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    _valuelist.reserve(grid.sizeNodes());
38}
39
40FieldTri2D::FieldTri2D(const FieldTri2D& field)
41  : _valuelist(field._valuelist),
42    _vmin(field._vmin),
43    _vmax(field._vmax),
44    _meshPtr(field._meshPtr),
45    _counter(field._counter)
46{
47}
48
49FieldTri2D&
50FieldTri2D::operator=(const FieldTri2D& field)
51{
52    _valuelist = field._valuelist;
53    _vmin = field._vmin;
54    _vmax = field._vmax;
55    _meshPtr = field._meshPtr;
56    _counter = field._counter;
57    return *this;
58}
59
60FieldTri2D::~FieldTri2D()
61{
62}
63
64int
65FieldTri2D::size() const
66{
67    return _meshPtr->sizeNodes();
68}
69
70Node2D&
71FieldTri2D::atNode(int pos)
72{
73    static Node2D null(0.0,0.0);
74
75    if (!_meshPtr.isNull()) {
76        return _meshPtr->atNode(pos);
77    }
78    return null;
79}
80
81double
82FieldTri2D::rangeMin(Axis which) const
83{
84    if (!_meshPtr.isNull()) {
85        return _meshPtr->rangeMin(which);
86    }
87    return 0.0;
88}
89
90double
91FieldTri2D::rangeMax(Axis which) const
92{
93    if (!_meshPtr.isNull()) {
94        return _meshPtr->rangeMax(which);
95    }
96    return 0.0;
97}
98
99FieldTri2D&
100FieldTri2D::define(int nodeId, double f)
101{
102    if (_valuelist.size() < (unsigned int)(nodeId+1)) {
103        _valuelist.resize((unsigned int)(nodeId+1), NAN);
104    }
105    _valuelist[nodeId] = f;
106
107    if (isnan(_vmin) || isnan(_vmax)) {
108        _vmin = _vmax = f;
109    } else {
110        if (f < _vmin) { _vmin = f; }
111        if (f > _vmax) { _vmax = f; }
112    }
113    return *this;
114}
115
116double
117FieldTri2D::value(double x, double y, double outside) const
118{
119    if (!_meshPtr.isNull()) {
120        Node2D node(x,y);
121        CellTri2D cell = _meshPtr->locate(node);
122
123        if (!cell.isNull()) {
124            double phi[3];
125            cell.barycentrics(node, phi);
126
127            int n0 = cell.nodeId(0);
128            int n1 = cell.nodeId(1);
129            int n2 = cell.nodeId(2);
130
131            return phi[0]*_valuelist[n0]
132                 + phi[1]*_valuelist[n1]
133                 + phi[2]*_valuelist[n2];
134        }
135    }
136    return outside;
137}
138
139double
140FieldTri2D::valueMin() const
141{
142    return _vmin;
143}
144
145double
146FieldTri2D::valueMax() const
147{
148    return _vmax;
149}
Note: See TracBrowser for help on using the repository browser.