1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * Rappture::Mesh1D |
---|
4 | * This is a non-uniform mesh for 1-dimensional structures. |
---|
5 | * It's like a string of x-coordinates that form the range for |
---|
6 | * an X-Y plot. Nodes can be added to and deleted from the mesh, |
---|
7 | * and the interval containing a given coordinate can be found |
---|
8 | * quickly, to support interpolation operations. |
---|
9 | * |
---|
10 | * ====================================================================== |
---|
11 | * AUTHOR: Michael McLennan, Purdue University |
---|
12 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
13 | * |
---|
14 | * See the file "license.terms" for information on usage and |
---|
15 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
16 | * ====================================================================== |
---|
17 | */ |
---|
18 | #ifndef RPMESH1D_H |
---|
19 | #define RPMESH1D_H |
---|
20 | |
---|
21 | #include <deque> |
---|
22 | #include <RpNode.h> |
---|
23 | #include <RpSerializable.h> |
---|
24 | |
---|
25 | namespace Rappture { |
---|
26 | |
---|
27 | class Cell1D { |
---|
28 | public: |
---|
29 | Cell1D(); |
---|
30 | Cell1D(int n0, double x0, int n1, double x1); |
---|
31 | int& nodeId(int n); |
---|
32 | double& x(int n); |
---|
33 | |
---|
34 | int isOutside() const; |
---|
35 | |
---|
36 | private: |
---|
37 | int _nodeIds[2]; |
---|
38 | double _x[2]; |
---|
39 | }; |
---|
40 | |
---|
41 | class Mesh1D : public Serializable { |
---|
42 | public: |
---|
43 | Mesh1D(); |
---|
44 | Mesh1D(double x0, double x1, int npts); |
---|
45 | Mesh1D(const Mesh1D& mesh); |
---|
46 | Mesh1D& operator=(const Mesh1D& mesh); |
---|
47 | virtual ~Mesh1D(); |
---|
48 | |
---|
49 | virtual Node1D& add(const Node1D& node); |
---|
50 | virtual Mesh1D& remove(int nodeId); |
---|
51 | virtual Mesh1D& remove(const Node1D& node); |
---|
52 | virtual Mesh1D& clear(); |
---|
53 | |
---|
54 | virtual int size() const; |
---|
55 | virtual Node1D& at(int pos); |
---|
56 | virtual double rangeMin() const; |
---|
57 | virtual double rangeMax() const; |
---|
58 | |
---|
59 | virtual Cell1D locate(const Node1D& node) const; |
---|
60 | |
---|
61 | // required for base class Serializable: |
---|
62 | const char* serializerType() const { return "Mesh1D"; } |
---|
63 | char serializerVersion() const { return 'A'; } |
---|
64 | |
---|
65 | void serialize_A(SerialBuffer& buffer) const; |
---|
66 | static Ptr<Serializable> create(); |
---|
67 | Outcome deserialize_A(SerialBuffer& buffer); |
---|
68 | |
---|
69 | protected: |
---|
70 | virtual int _locateInterval(double x) const; |
---|
71 | virtual void _rebuildNodeIdMap(); |
---|
72 | |
---|
73 | private: |
---|
74 | std::deque<Node1D> _nodelist; // list of all nodes, in sorted order |
---|
75 | int _counter; // auto counter for node IDs |
---|
76 | |
---|
77 | std::deque<int> _id2node; // maps node Id => index in _nodelist |
---|
78 | int _id2nodeDirty; // non-zero => _id2node needs to be rebuilt |
---|
79 | |
---|
80 | // methods for serializing/deserializing version 'A' |
---|
81 | static SerialConversion versionA; |
---|
82 | }; |
---|
83 | |
---|
84 | } // namespace Rappture |
---|
85 | |
---|
86 | #endif /*RPMESH1D_H*/ |
---|