Acoustic FDTD Solver
Utility.hpp
Go to the documentation of this file.
1 #ifndef UTILITY_HPP
2 #define UTILITY_HPP
3 
4 #include "constant.hpp"
5 
14 double * vector2array(const std::vector<double> &a);
20 double * vector2array(const std::vector<double> &a, const unsigned size);
21 int * vector2array(const std::vector<int> &a);
26 double ** vector2array(const std::vector<double> &a, const unsigned M, const unsigned N);
30 void deleteArray(double* data);
34 void deleteArray(double** data);
35 std::vector<std::vector<double> > vector2vector(const std::vector<double> &a, const int N, const int M);
36 std::vector<double> array2vector(const double *a, const int size);
40 std::vector<std::vector<double> > array2vector(const double *a, const int N, const int M);
41 
45 double str2num(const std::string &s);
46 
50 std::string num2str(const double x);
51 
55 double matlabfmod(const double x, const double y);
56 
62 std::string getRandomFileName(std::string &prefix);
63 
64 int getNextPower(int N, int base);
65 
66 
67 void writeToTxtFile(const std::string file_name, const std::vector<double> &data);
68 void writeToTxtFile(const std::string file_name, const std::vector<std::vector<double> > &data);
69 double bandwidthToGaussianStdDev(unsigned bandwidth_defn, double bandwidth);
70 
83 std::vector<double> solveTridiagonalSystem(const std::vector<double> &a,
84  const std::vector<double> &b,
85  const std::vector<double> &c,
86  const std::vector<double> &d);
94 std::vector<double> solveLinearSystem(const std::vector<std::vector<double> > &S,
95  const std::vector<double> &rhs);
96 
107 std::vector<double> cubic_spline_interp(const std::vector<double> &x,
108  const std::vector<double> &y,
109  const std::vector<double> &xi);
110 
112 double linear_interp(const std::vector<double> &x,
113  const std::vector<double> &y,
114  const std::vector<std::vector<double> > &z,
115  const double xi,
116  const double yi);
117 
118 
125 void convertIndex(const int index, const int nZ, int j, int k);
126 
135 void convertIndex(const int index, const int nY, const int nZ, int i, int j, int k);
136 
140 std::vector<int> getBilinearInterpolationIndex(const std::vector<double> &z,
141  const double zi);
142 
146 std::vector<int> getBilinearInterpolationIndex(const std::vector<double> &y,
147  const std::vector<double> &z,
148  const double yi,
149  const double zi);
151 std::vector<int> getBilinearInterpolationIndex(const std::vector<double> &x,
152  const std::vector<double> &y,
153  const std::vector<double> &z,
154  const double xi,
155  const double yi,
156  const double zi);
157 
158 std::vector<double> getBilinearInterpolationCoefficient(const std::vector<double> &z,
159  const double zi);
160 
161 std::vector<double> getBilinearInterpolationCoefficient(const std::vector<double> &y,
162  const std::vector<double> &z,
163  const double yi,
164  const double zi);
166 std::vector<double> getBilinearInterpolationCoefficient(const std::vector<double> &x,
167  const std::vector<double> &y,
168  const std::vector<double> &z,
169  const double xi,
170  const double yi,
171  const double zi);
179 std::vector<std::vector<double> > cubic_spline_interp(const std::vector<double> &x,
180  const std::vector<double> &y,
181  const std::vector<std::vector<double> > &z,
182  const std::vector<double> &xi,
183  const std::vector<double> &yi);
184 
188 std::vector<double> poly_interp(const std::vector<double> &x,
189  const std::vector<double> &y,
190  const std::vector<double> &xi);
191 
202 int findEqual(const std::vector<double> &reference, const double x, int i, int j);
203 
207 std::vector<int> findEqual(const std::vector<double> &reference, const double x);
208 std::vector<int> findEqual(const std::vector<std::vector<double> > &reference, const double x);
209 
216 bool approximatelyEqual(const double a, const double b, const double epsilon);
217 
224 bool essentiallyEqual(const double a, const double b, const double epsilon);
225 
232 bool definitelyGreaterThan(const double a, const double b, const double epsilon);
233 
240 bool definitelyLessThan(const double a, const double b, const double epsilon);
241 
246 std::string secondToTime(int seconds);
247 
248 std::vector<double> estimateAmplitudePhase(const std::vector<double> &data, const double frequency, const double delta_t);
249 double cot(const double x);
250 double acot(const double x);
251 
252 bool isEven(unsigned n);
253 bool isOdd(unsigned n);
254 
255 #endif