source: branches/1.3/src/core2/RpMeshPrism3D.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.3 KB
Line 
1/*
2 * ----------------------------------------------------------------------
3 *  Rappture::MeshPrism3D
4 *    This is a non-uniform 3D mesh, made of triangles in (x,y) and
5 *    line segments in z.  Their product forms triangular prisms.
6 *
7 * ======================================================================
8 *  AUTHOR:  Michael McLennan, Purdue University
9 *  Copyright (c) 2004-2012  HUBzero Foundation, LLC
10 *
11 *  See the file "license.terms" for information on usage and
12 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 * ======================================================================
14 */
15#include <assert.h>
16#include "RpMeshPrism3D.h"
17
18using namespace Rappture;
19
20CellPrism3D::CellPrism3D()
21{
22    for (int i=0; i < 6; i++) {
23        _nodeIds[i] = -1;
24        _x[i] = 0.0;
25        _y[i] = 0.0;
26        _z[i] = 0.0;
27    }
28}
29
30CellPrism3D::CellPrism3D(const CellPrism3D& cell)
31{
32    for (int i=0; i < 6; i++) {
33        _nodeIds[i] = cell._nodeIds[i];
34        _x[i] = cell._x[i];
35        _y[i] = cell._y[i];
36        _z[i] = cell._z[i];
37    }
38}
39
40CellPrism3D&
41CellPrism3D::operator=(const CellPrism3D& cell)
42{
43    for (int i=0; i < 6; i++) {
44        _nodeIds[i] = cell._nodeIds[i];
45        _x[i] = cell._x[i];
46        _y[i] = cell._y[i];
47        _z[i] = cell._z[i];
48    }
49    return *this;
50}
51
52int&
53CellPrism3D::nodeId(int n)
54{
55    assert(n >= 0 && n < 6);
56    return _nodeIds[n];
57}
58
59double&
60CellPrism3D::x(int n)
61{
62    assert(n >= 0 && n < 6);
63    return _x[n];
64}
65
66double&
67CellPrism3D::y(int n)
68{
69    assert(n >= 0 && n < 6);
70    return _y[n];
71}
72
73double&
74CellPrism3D::z(int n)
75{
76    assert(n >= 0 && n < 6);
77    return _z[n];
78}
79
80int
81CellPrism3D::isOutside() const
82{
83    for (int i=0; i < 6; i++) {
84        if (_nodeIds[i] < 0) {
85            return 1;
86        }
87    }
88    return 0;
89}
90
91MeshPrism3D::MeshPrism3D()
92{
93}
94
95MeshPrism3D::MeshPrism3D(const MeshTri2D& xym, const Mesh1D& zm)
96{
97    _xymesh = xym;
98    _zmesh  = zm;
99}
100
101MeshPrism3D::MeshPrism3D(const MeshPrism3D& mesh)
102    : _xymesh(mesh._xymesh),
103      _zmesh(mesh._zmesh)
104{
105}
106
107MeshPrism3D&
108MeshPrism3D::operator=(const MeshPrism3D& mesh)
109{
110    _xymesh = mesh._xymesh;
111    _zmesh  = mesh._zmesh;
112    return *this;
113}
114
115MeshPrism3D::~MeshPrism3D()
116{
117}
118
119double
120MeshPrism3D::rangeMin(Axis which) const
121{
122    if (which == zaxis) {
123        return _zmesh.rangeMin();
124    }
125    return _xymesh.rangeMin(which);
126}
127
128double
129MeshPrism3D::rangeMax(Axis which) const
130{
131    if (which == zaxis) {
132        return _zmesh.rangeMax();
133    }
134    return _xymesh.rangeMax(which);
135}
136
137CellPrism3D
138MeshPrism3D::locate(const Node3D& node) const
139{
140    CellPrism3D result;
141
142    Node2D xycoord(node.x(), node.y());
143    CellTri2D xycell = _xymesh.locate(xycoord);
144
145    Node1D zcoord(node.z());
146    Cell1D zcell = _zmesh.locate(zcoord);
147
148    if (!xycell.isOutside() && !zcell.isOutside()) {
149        int n = 0;
150        for (int iz=0; iz < 2; iz++) {
151            for (int ixy=0; ixy < 3; ixy++) {
152                int nxy = xycell.nodeId(ixy);
153                int nz = zcell.nodeId(iz);
154                if (nxy >= 0 && nz >= 0) {
155                    result.nodeId(n) = nz*_xymesh.sizeNodes() + nxy;
156                    result.x(n) = xycell.x(ixy);
157                    result.y(n) = xycell.y(ixy);
158                    result.z(n) = zcell.x(iz);
159                }
160                n++;
161            }
162        }
163    }
164    return result;
165}
Note: See TracBrowser for help on using the repository browser.