Acoustic FDTD Solver
|
#include "Utility.hpp"
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 N) |
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 > &data, 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 *in, 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. | |
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. | |
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 > | 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". | |
double | matlabfmod (const double x, const double y) |
c++ fmod() is not consistent with Matlab fmod() when handling negative number. | |
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 * | in, |
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 | ) |
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<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 | ||
) |
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 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::string secondToTime | ( | int | seconds | ) |
Parse the input to the string form of "XX hours XX minutes XX seconds".
seconds | std::difftime(). |
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 | ||
) |