rsvs3D  0.0.0
Codes for the c++ implementation of the 3D RSVS
RSVSmath.hpp
Go to the documentation of this file.
1 
10 #ifndef RSVSMATH_H_INCLUDED
11 #define RSVSMATH_H_INCLUDED
12 
13 namespace param
14 {
15 namespace dev
16 {
17 class rsvseps;
18 }
19 } // namespace param
20 
21 //=================================
22 // included dependencies
23 #include <cmath>
24 #include <vector>
25 
26 #include "vectorarray.hpp"
29 // needed for grid::coordlist (Things in mesh need a refactor)
30 #include "mesh.hpp"
31 
32 //==================================
33 // Code
34 // NOTE: function in a class definition are IMPLICITELY INLINED
35 // ie replaced by their code at compile time
36 
37 class TriFunc
38 {
39  protected:
40  std::vector<double> const *p0 = NULL;
41  std::vector<double> const *p1 = NULL;
42  std::vector<double> const *p2 = NULL;
43 
44  double fun;
45  ArrayVec<double> jac;
46  ArrayVec<double> hes;
47 
48  bool isReady;
49  bool isCalc;
50  int nTarg; // target length of vectors
51 
52  bool MakeValidField(std::vector<double> *TriFunc::*mp);
53 
54  public:
55  // Check validity
56  bool CheckValid();
57  bool MakeValid();
58  void PreCalc();
59  // Build a valid object
60  void assign(const std::vector<double> &in0, const std::vector<double> &in1, const std::vector<double> &in2);
61  void assign(const std::vector<double> *in0, const std::vector<double> *in1, const std::vector<double> *in2);
62  void assign(int pRepI, const std::vector<double> &pRep);
63  void ReturnDatPoint(double **a, ArrayVec<double> **b, ArrayVec<double> **c);
64  virtual void Calc() = 0; // Virtual function that calculates
65 
66  TriFunc()
67  {
68  fun = 0;
69  nTarg = 3;
70  jac.assign(1, 3 * nTarg, fun);
71  hes.assign(3 * nTarg, 3 * nTarg, fun);
72  isReady = false;
73  isCalc = false;
74  }
75  explicit TriFunc(int a)
76  {
77  nTarg = a;
78  fun = 0;
79  jac.assign(1, 3 * nTarg, fun);
80  hes.assign(3 * nTarg, 3 * nTarg, fun);
81  isReady = false;
82  isCalc = false;
83  }
84 };
85 
86 class CoordFunc
87 {
88  protected:
89  grid::coordlist coords;
90 
91  double fun;
92  ArrayVec<double> funA;
93  ArrayVec<double> jac;
94  ArrayVec<double> hes;
95 
96  bool isReady;
97  bool isCalc;
98 
99  int nDim; // target length of vectors
100  int nCoord; // target length of vectors
101  int nFun;
102 
103  bool MakeValidField(std::vector<double> const *mp);
104  void InitialiseArrays();
105 
106  public:
107  // Check validity
108  bool CheckValid();
109  bool MakeValid();
110  void PreCalc();
111  // Build a valid object
112  void assign(grid::coordlist &coords);
113  void assign(int pRepI, const std::vector<double> &pRep);
114  void ReturnDat(double &a, ArrayVec<double> &b, ArrayVec<double> &c);
115  void ReturnDat(ArrayVec<double> &a, ArrayVec<double> &b, ArrayVec<double> &c);
116  void ReturnDatPoint(double **a, ArrayVec<double> **b, ArrayVec<double> **c);
117  void ReturnDatPoint(ArrayVec<double> **a, ArrayVec<double> **b, ArrayVec<double> **c);
118  virtual void Calc() = 0; // Virtual function that calculates the function
119 
120  void ResetDim(int n)
121  {
122  nDim = n;
123  InitialiseArrays();
124  }
125  void ResetNCoord(int n)
126  {
127  nCoord = n;
128  InitialiseArrays();
129  }
130  void ResetNFun(int n)
131  {
132  nFun = n;
133  InitialiseArrays();
134  }
135  CoordFunc()
136  {
137  nDim = 3;
138  nCoord = 3;
139  nFun = 1;
140  InitialiseArrays();
141  }
142  explicit CoordFunc(int n1)
143  {
144  nDim = n1;
145  nCoord = 3;
146  nFun = 1;
147  InitialiseArrays();
148  }
149  CoordFunc(int n1, int n2)
150  {
151  nDim = n1;
152  nCoord = n2;
153  nFun = 1;
154  InitialiseArrays();
155  }
156 
157  CoordFunc(int n1, int n2, int n3)
158  {
159  nDim = n1;
160  nCoord = n2;
161  nFun = n3;
162  InitialiseArrays();
163  }
164  virtual ~CoordFunc()
165  {
166  coords.clear();
167  }
168 };
169 
170 class Volume : public TriFunc
171 {
172  using TriFunc::fun;
173  using TriFunc::hes;
174  using TriFunc::jac;
175  using TriFunc::p0;
176  using TriFunc::p1;
177  using TriFunc::p2;
178  using TriFunc::PreCalc;
179  using TriFunc::TriFunc;
180 
181  public:
182  void Calc() override;
183  void CalcFD();
184 };
185 
186 class Area : public TriFunc
187 {
188  using TriFunc::fun;
189  using TriFunc::hes;
190  using TriFunc::jac;
191  using TriFunc::p0;
192  using TriFunc::p1;
193  using TriFunc::p2;
194  using TriFunc::PreCalc;
195  using TriFunc::TriFunc;
196 
197  public:
198  void Calc() override;
199 };
200 
201 class LengthEdge : public CoordFunc
202 {
203  using CoordFunc::coords;
204  using CoordFunc::fun;
205  using CoordFunc::hes;
206  using CoordFunc::jac;
207  using CoordFunc::PreCalc;
208 
209  public:
210  void Calc() override;
211  LengthEdge() : CoordFunc(3, 2)
212  {
213  }
214 };
215 
216 class Volume2 : public CoordFunc
217 {
218  using CoordFunc::coords;
219  using CoordFunc::fun;
220  using CoordFunc::hes;
221  using CoordFunc::jac;
222  using CoordFunc::PreCalc;
223 
224  public:
225  void Calc() override;
226  Volume2() : CoordFunc(3, 7)
227  {
228  }
229 };
230 
231 class SurfCentroid : public CoordFunc
232 {
233  protected:
234  // using CoordFunc::PreCalc;
235  using CoordFunc::coords;
236  using CoordFunc::fun;
237  using CoordFunc::hes;
238  using CoordFunc::jac;
239  using CoordFunc::nCoord;
240 
241  std::vector<double> centroid;
242  double edgeLength = 0.0;
243  bool calcDeriv = true;
244 
245  public:
246  void Disp();
247  void Calc() override;
248  void CalcFD();
249  void assigncentroid(const std::vector<double> &vecin);
250 
251  const ArrayVec<double> &jac_ptr() const
252  {
253  return ((this->jac));
254  };
255  const ArrayVec<double> &hes_ptr() const
256  {
257  return ((this->hes));
258  };
259 
260  SurfCentroid() : CoordFunc(3, 4, 3)
261  {
262  centroid.assign(nDim, 0);
263  };
264  explicit SurfCentroid(int a) : CoordFunc(3, a, 3)
265  {
266  nCoord = a;
267  centroid.assign(nDim, 0);
268  };
269 };
270 
271 void SetEnvironmentEpsilon(const param::dev::rsvseps &rsvsEpsilons);
272 
273 int Test_SurfCentreDerivatives();
274 
275 #endif
bool MakeValidField(std::vector< double > const *mp)
CoordFunc supports the same stuff as tri func but can have any number of points.
Definition: RSVSmath.cpp:154
\TODO refactor mesh.hpp into mesh and coord headers to allow smaller includes
Definition: RSVSmath.hpp:38
Class for control of rsvs epsilon.
Definition: parameters.hpp:257
Provides all the mesh tools used for the generation of 3D grids and geometries.
std::vector< const std::vector< double > * > coordlist
Defines a list of coordinates.
Definition: mesh.hpp:87
Namespace containing the parameter classes used to control execution of the 3D-RSVS program.
Definition: main.hpp:15
Provides a 2D std::vector based container.