Acoustic FDTD Solver
|
#include "constant.hpp"
Go to the source code of this file.
Functions | |
double * | vector2array (const std::vector< double > &a) |
copy the content of the vector to an array, which can be directly written to the h5 file. | |
double * | vector2array (const std::vector< double > &a, const unsigned size) |
copy the content of the vector to an array, specified by size. | |
int * | vector2array (const std::vector< int > &a) |
double ** | vector2array (const std::vector< double > &a, const unsigned M, const unsigned N) |
copy the content of the vector to a MxN 2-D array. | |
void | deleteArray (double *data) |
Free the memory space created by vector2array() | |
void | deleteArray (double **data) |
Free the memory space created by vector2array() | |
std::vector< std::vector < double > > | vector2vector (const std::vector< double > &a, const int N, const int M) |
std::vector< double > | array2vector (const double *a, const int size) |
std::vector< std::vector < double > > | array2vector (const double *a, const int N, const int M) |
create a 2-D array from a 1-D array specified by N rows and M columns. | |
double | str2num (const std::string &s) |
Use the std::istd::stringstream to perform the conversion. | |
std::string | num2str (const double x) |
Use the std::ostd::stringstream to perform the conversion. | |
double | matlabfmod (const double x, const double y) |
c++ fmod() is not consistent with Matlab fmod() when handling negative number. | |
std::string | getRandomFileName (std::string &prefix) |
Generate a h5 file name in format of "prefix_year_month_day_hour_minute_random.h5". | |
int | getNextPower (int N, int base) |
void | writeToTxtFile (const std::string file_name, const std::vector< double > &data) |
void | writeToTxtFile (const std::string file_name, const std::vector< std::vector< double > > &data) |
double | bandwidthToGaussianStdDev (unsigned bandwidth_defn, double bandwidth) |
std::vector< double > | solveTridiagonalSystem (const std::vector< double > &a, const std::vector< double > &b, const std::vector< double > &c, const std::vector< double > &d) |
solve Ax = d problem, where A is a tri-diagonal system specified by its lower, main, and upper diagonal. | |
std::vector< double > | solveLinearSystem (const std::vector< std::vector< double > > &S, const std::vector< double > &rhs) |
Solve the linear system S x = t. | |
std::vector< double > | cubic_spline_interp (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &xi) |
Use cubic spline to Interpolate xi based on the data (x, y). | |
double | linear_interp (const std::vector< double > &x, const std::vector< double > &y, const std::vector< std::vector< double > > &z, const double xi, const double yi) |
Bi-linear interpolation over one grid onto another point. | |
void | convertIndex (const int index, const int nZ, int j, int k) |
Convert the integer index to the indices of the two-dimensional vector. | |
void | convertIndex (const int index, const int nY, const int nZ, int i, int j, int k) |
Convert the integer index to the indices of the three-dimensional vector. | |
std::vector< int > | getBilinearInterpolationIndex (const std::vector< double > &z, const double zi) |
std::vector< int > | getBilinearInterpolationIndex (const std::vector< double > &y, const std::vector< double > &z, const double yi, const double zi) |
std::vector< int > | getBilinearInterpolationIndex (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const double xi, const double yi, const double zi) |
To be implemented. | |
std::vector< double > | getBilinearInterpolationCoefficient (const std::vector< double > &z, const double zi) |
std::vector< double > | getBilinearInterpolationCoefficient (const std::vector< double > &y, const std::vector< double > &z, const double yi, const double zi) |
std::vector< double > | getBilinearInterpolationCoefficient (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const double xi, const double yi, const double zi) |
To be implemented. | |
std::vector< std::vector < double > > | cubic_spline_interp (const std::vector< double > &x, const std::vector< double > &y, const std::vector< std::vector< double > > &z, const std::vector< double > &xi, const std::vector< double > &yi) |
std::vector< double > | poly_interp (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &xi) |
Polynomial interpolation. | |
int | findEqual (const std::vector< double > &reference, const double x, int i, int j) |
Find the index of the element which is equal to x. | |
std::vector< int > | findEqual (const std::vector< double > &reference, const double x) |
Find the index of the elements that are equal to x. | |
std::vector< int > | findEqual (const std::vector< std::vector< double > > &reference, const double x) |
bool | approximatelyEqual (const double a, const double b, const double epsilon) |
See knuth book on double comparision. | |
bool | essentiallyEqual (const double a, const double b, const double epsilon) |
See knuth book. | |
bool | definitelyGreaterThan (const double a, const double b, const double epsilon) |
See knuth book. | |
bool | definitelyLessThan (const double a, const double b, const double epsilon) |
See knuth book. | |
std::string | secondToTime (int seconds) |
Parse the input to the string form of "XX hours XX minutes XX seconds". | |
std::vector< double > | estimateAmplitudePhase (const std::vector< double > &data, const double frequency, const double delta_t) |
double | cot (const double x) |
double | acot (const double x) |
bool | isEven (unsigned n) |
bool | isOdd (unsigned n) |
double acot | ( | const double | x | ) |
bool approximatelyEqual | ( | const double | a, |
const double | b, | ||
const double | epsilon | ||
) |
See knuth book on double comparision.
a | first parameter |
b | second parameter |
epsilon | depends on the context, and determines how equal you want the numbers to be. |
std::vector<double> array2vector | ( | const double * | a, |
const int | size | ||
) |
std::vector<std::vector<double> > array2vector | ( | const double * | a, |
const int | N, | ||
const int | M | ||
) |
create a 2-D array from a 1-D array specified by N rows and M columns.
double bandwidthToGaussianStdDev | ( | unsigned | bandwidth_defn, |
double | bandwidth | ||
) |
void convertIndex | ( | const int | index, |
const int | nZ, | ||
int | j, | ||
int | k | ||
) |
Convert the integer index to the indices of the two-dimensional vector.
&index | |
&nZ | |
&j | contain returned value |
&k | contain returned value |
void convertIndex | ( | const int | index, |
const int | nY, | ||
const int | nZ, | ||
int | i, | ||
int | j, | ||
int | k | ||
) |
Convert the integer index to the indices of the three-dimensional vector.
&index | |
&nY | |
&nZ | |
&i | contain returned value |
&j | contain returned value |
&k | contain returned value |
double cot | ( | const double | x | ) |
std::vector<double> cubic_spline_interp | ( | const std::vector< double > & | x, |
const std::vector< double > & | y, | ||
const std::vector< double > & | xi | ||
) |
Use cubic spline to Interpolate xi based on the data (x, y).
From the end points of (x,y), it estimates the the second derivative and uses them as the boudnary boundary condition. If xi falls outside of x, return 0.
x | Uniformly spaced sample point |
y | |
xi | Can be nonuniformly spaced sample point |
std::vector<std::vector<double> > cubic_spline_interp | ( | const std::vector< double > & | x, |
const std::vector< double > & | y, | ||
const std::vector< std::vector< double > > & | z, | ||
const std::vector< double > & | xi, | ||
const std::vector< double > & | yi | ||
) |
x | Uniformly spaced sample point |
y | Uniformly spaced sample point |
z | |
xi | Can be non-uniformly spaced sample point |
yi | Can be non-uniformly spaced sample point |
bool definitelyGreaterThan | ( | const double | a, |
const double | b, | ||
const double | epsilon | ||
) |
See knuth book.
a | first parameter |
b | second parameter |
epsilon | depends on the context, and determines how equal you want the numbers to be. |
bool definitelyLessThan | ( | const double | a, |
const double | b, | ||
const double | epsilon | ||
) |
See knuth book.
a | first parameter |
b | second parameter |
epsilon | depends on the context, and determines how equal you want the numbers to be. |
void deleteArray | ( | double * | data | ) |
Free the memory space created by vector2array()
void deleteArray | ( | double ** | data | ) |
Free the memory space created by vector2array()
bool essentiallyEqual | ( | const double | a, |
const double | b, | ||
const double | epsilon | ||
) |
See knuth book.
a | first parameter |
b | second parameter |
epsilon | depends on the context, and determines how equal you want the numbers to be. |
std::vector<double> estimateAmplitudePhase | ( | const std::vector< double > & | data, |
const double | frequency, | ||
const double | delta_t | ||
) |
int findEqual | ( | const std::vector< double > & | reference, |
const double | x, | ||
int | i, | ||
int | j | ||
) |
Find the index of the element which is equal to x.
Using binary search.
reference | an increasing array without repeating element |
x | specified value |
i | starting index of reference to search |
j | ending index of reference to search |
std::vector<int> findEqual | ( | const std::vector< double > & | reference, |
const double | x | ||
) |
Find the index of the elements that are equal to x.
std::vector<int> findEqual | ( | const std::vector< std::vector< double > > & | reference, |
const double | x | ||
) |
std::vector<double> getBilinearInterpolationCoefficient | ( | const std::vector< double > & | z, |
const double | zi | ||
) |
std::vector<double> getBilinearInterpolationCoefficient | ( | const std::vector< double > & | y, |
const std::vector< double > & | z, | ||
const double | yi, | ||
const double | zi | ||
) |
std::vector<double> getBilinearInterpolationCoefficient | ( | const std::vector< double > & | x, |
const std::vector< double > & | y, | ||
const std::vector< double > & | z, | ||
const double | xi, | ||
const double | yi, | ||
const double | zi | ||
) |
To be implemented.
std::vector<int> getBilinearInterpolationIndex | ( | const std::vector< double > & | z, |
const double | zi | ||
) |
std::vector<int> getBilinearInterpolationIndex | ( | const std::vector< double > & | y, |
const std::vector< double > & | z, | ||
const double | yi, | ||
const double | zi | ||
) |
std::vector<int> getBilinearInterpolationIndex | ( | const std::vector< double > & | x, |
const std::vector< double > & | y, | ||
const std::vector< double > & | z, | ||
const double | xi, | ||
const double | yi, | ||
const double | zi | ||
) |
To be implemented.
int getNextPower | ( | int | N, |
int | base | ||
) |
std::string getRandomFileName | ( | std::string & | prefix | ) |
Generate a h5 file name in format of "prefix_year_month_day_hour_minute_random.h5".
bool isEven | ( | unsigned | n | ) |
bool isOdd | ( | unsigned | n | ) |
double linear_interp | ( | const std::vector< double > & | x, |
const std::vector< double > & | y, | ||
const std::vector< std::vector< double > > & | z, | ||
const double | xi, | ||
const double | yi | ||
) |
Bi-linear interpolation over one grid onto another point.
double matlabfmod | ( | const double | x, |
const double | y | ||
) |
c++ fmod() is not consistent with Matlab fmod() when handling negative number.
This function follows the Matlab convention.
std::string num2str | ( | const double | x | ) |
Use the std::ostd::stringstream to perform the conversion.
std::vector<double> poly_interp | ( | const std::vector< double > & | x, |
const std::vector< double > & | y, | ||
const std::vector< double > & | xi | ||
) |
Polynomial interpolation.
Solving the linear sytem using Boost.
std::string secondToTime | ( | int | seconds | ) |
Parse the input to the string form of "XX hours XX minutes XX seconds".
seconds | std::difftime(). |
std::vector<double> solveLinearSystem | ( | const std::vector< std::vector< double > > & | S, |
const std::vector< double > & | rhs | ||
) |
Solve the linear system S x = t.
It actually uses LU in Boost to invert S' S, and compute x = inv(S' S) S' t.
S | NxN matrix |
rhs | right hand side |
std::vector<double> solveTridiagonalSystem | ( | const std::vector< double > & | a, |
const std::vector< double > & | b, | ||
const std::vector< double > & | c, | ||
const std::vector< double > & | d | ||
) |
solve Ax = d problem, where A is a tri-diagonal system specified by its lower, main, and upper diagonal.
See [Schwarz1989] for the algorithm to perform LU decomposition on A and use backward/forwad substitution solve the system.
a | main diagonal |
b | lower diagonal |
c | upper diagonal |
d | right hand side |
double str2num | ( | const std::string & | s | ) |
Use the std::istd::stringstream to perform the conversion.
double* vector2array | ( | const std::vector< double > & | a | ) |
copy the content of the vector to an array, which can be directly written to the h5 file.
This method dynamically creates an array using new and returns the pointer to it. Cannot be used too often to avoid allocating too much memory space.
a | vector<double> |
double* vector2array | ( | const std::vector< double > & | a, |
const unsigned | size | ||
) |
copy the content of the vector to an array, specified by size.
If size is longer than the size of the vector, 0 will be padded at the end.
int* vector2array | ( | const std::vector< int > & | a | ) |
double** vector2array | ( | const std::vector< double > & | a, |
const unsigned | M, | ||
const unsigned | N | ||
) |
copy the content of the vector to a MxN 2-D array.
The array occupies an contiguous space in the memory.
std::vector<std::vector<double> > vector2vector | ( | const std::vector< double > & | a, |
const int | N, | ||
const int | M | ||
) |
void writeToTxtFile | ( | const std::string | file_name, |
const std::vector< double > & | data | ||
) |
void writeToTxtFile | ( | const std::string | file_name, |
const std::vector< std::vector< double > > & | data | ||
) |