32 #ifndef MUMECH_ELEMENTARY_FUNCTIONS_H 33 #define MUMECH_ELEMENTARY_FUNCTIONS_H 41 #define _MATHEMATICA_SYNTAX_ 0 42 #define _STANDARD_SYNTAX_ 1 83 double acosh(
double x);
95 void OpenFile( FILE **file,
char *name,
const char mode[] );
97 void OpenFile( FILE* &file,
char name[],
int mode );
139 inline bool*
Allocate1Dbz (
long d1) {
bool *a =
new bool [d1]; memset (a, 0, d1*
sizeof(
bool ));
return a; }
141 inline bool**
Allocate1Dbp (
long d1) {
bool **a =
new bool* [d1]; memset (a, 0, d1*
sizeof(
bool* ));
return a; }
145 inline int*
Allocate1Di (
long d1) {
int *a =
new int [d1];
return a; }
148 inline double*
Allocate1Dd (
long d1) {
double *a =
new double [d1];
return a; }
150 inline double*
Allocate1Ddz (
long d1) {
double *a =
new double [d1]; memset (a, 0, d1*
sizeof(
double ));
return a; }
152 inline double**
Allocate1Ddp (
long d1) {
return (
double**) memset (
new double* [d1], 0, d1*
sizeof(
double* )); }
154 inline double***
Allocate1Ddpp (
long d1) {
double ***a =
new double**[d1]; memset (a, 0, d1*
sizeof(
double**));
return a; }
158 inline void CleanVector (
double *a,
long n) { memset (a, 0, n *
sizeof(
double)); }
160 inline void CleanVector (
int *a,
long n) { memset (a, 0, n *
sizeof(
int) ); }
162 inline void CleanVector (
long *a,
long n) { memset (a, 0, n *
sizeof(
long) ); }
167 inline double GiveSumMembersVector (
const double *a,
long n) {
double s=0.0;
while (n--) s+= *(a++);
return s; }
171 inline void CopyVector (
const double *src,
double *dest,
long n) {
if(src==dest)
return; memcpy(dest, src, n *
sizeof(
double)); }
173 inline void CopyVector (
const long *src,
long *dest,
long n) {
if(src==dest)
return; memcpy(dest, src, n *
sizeof(
long )); }
175 inline void CopyVector (
const int *src,
int *dest,
long n) {
if(src==dest)
return; memcpy(dest, src, n *
sizeof(
int )); }
178 inline void AddVector (
const double *a,
double *b,
long n) {
while (n--) b[n] += a[n]; }
180 inline void AddVector (
const int *a,
int *b,
long n) {
while (n--) b[n] += a[n]; }
183 inline void SubtractVector (
const double *a,
double *b,
long n) {
while (n--) b[n] -= a[n]; }
186 inline void SubtractTwoVectors (
const double *v1,
const double *v2,
double *answer,
long n) {
while (n--) answer[n] = v1[n] - v2[n]; }
192 inline void SumTwoVectors (
const double *v1,
const double *v2,
double *answer,
long n) {
while (n--) answer[n] = v1[n] + v2[n]; }
196 inline void AddVectorMultipledBy (
double mlt,
const double *a,
double *b,
long n) {
while (n--) b[n] += mlt * a[n]; }
199 inline void DivideVector (
double *a,
long n,
double val) {
while (n--) a[n] /= val; }
202 inline void MultiplyVector (
double *a,
long n,
double val) {
while (n--) a[n] *= val; }
213 void ReadDataTo3DArray(
double *** p_array,
char * p_file_name,
int no_fields,
int no_rows,
260 inline void DeleteArray2D (
bool **array,
long d1) {
if (array == NULL)
return;
while (d1--)
delete [] array[d1];
delete []
array; array = NULL; }
262 inline void DeleteArray2D (
double **array,
long d1) {
if (array == NULL)
return;
while (d1--)
delete [] array[d1];
delete []
array; array = NULL; }
264 inline void DeleteArray3D (
double ***array,
long d1,
long d2) {
if (array == NULL)
return;
while (d1--)
DeleteArray2D(array[d1], d2);
delete []
array; array = NULL; }
268 inline void CleanArray2D (
int **a,
long rows,
long columns) {
while (rows--) memset (a[rows], 0, columns *
sizeof(
int )); }
270 inline void CleanArray2d (
double **a,
long rows,
long columns) {
while (rows--) memset (a[rows], 0, columns *
sizeof(
double)); }
275 void CopyArray2D (
const double*
const* src,
double** dest,
long d1,
long d2);
279 void CopyArray3D (
const double ***src,
double ***dest,
long d1,
long d2,
long d3);
282 void AddArray2D (
const double*
const* src,
double** dest,
long d1,
long d2);
284 void AddArray3D (
double ***src,
double ***dest,
long d1,
long d2,
long d3);
287 void DivideArray2D (
double** a,
double val,
long d1,
long d2);
292 void SubtractTwoArrays2D (
const double*
const* a1,
const double*
const* a2,
double **answer,
long d1,
long d2);
315 inline void copyMatrix_1Dto2D (
const double *v,
double **m,
long n) {
for (
long i=0; i<n; i++) memcpy (m[i], v+i*n, n *
sizeof(
double)); }
323 inline void copyMatrix_2Dto1D (
const double*
const* m,
double *v,
long n) {
for (
long i=0; i<n; i++) memcpy (v+i*n, m[i], n *
sizeof(
double)); }
328 inline void giveUnitMatrix3x3 (
double *m) { m[1] = m[2] = m[3] = m[5] = m[6] = m[7] = 0.0; m[0] = m[4] = m[8] = 1.0; }
345 void printMatrix(
double * mtrx,
int n,
const char * notice );
348 void printMatrix(
double ** mtrx,
int n,
const char * notice );
351 void printVector(
double * vect,
int n,
const char * notice );
354 void printVector(
int * vect,
int n,
const char * notice );
double give_curvature(double x, double a, double b)
double GiveSumMembersVector(const double *a, long n)
Function returns sum of all member of 'array'.
double ** Allocate1Ddp(long d1)
Function allocates ('new' command) a 1d array of double* pointers set to NULL.
void CopyArray3D(const double ***src, double ***dest, long d1, long d2, long d3)
Function copy two 3D double arrays with dimensions d1xd2xd3 from 'src' to 'dest'. ...
double * Allocate1Dd(long d1)
Function allocates ('new' command) a 1d array of double.
double *** Allocate1Ddpp(long d1)
Function allocates ('new' command) a 1d array of double** pointers set to NULL.
void ReadDataToVector(int *p_array, char *p_file_name)
description: function initializes an 'int' vector by values from a given file
double give_quadNormTwoVectors(const double *v1, const double *v2, int n)
Function returns the quadratic norm of two vectors of length 'n'.
void GoToEndOfLine(FILE *fr)
description: functions moves the cursor the the end of line (EOLN) in a text file last edit: 1...
void AddVectorMultipledBy(double mlt, const double *a, double *b, long n)
Function add given number of components multiplied by 'mlt' from vector 'a' to vector 'b'...
void CleanArray2D(int **a, long rows, long columns)
Function cleans an 2d 'int' array, initialize each value being 0-zero.
void CloseFile(FILE *file)
description: function closes a previously opened file and tests the succes of the closing note: funct...
void giveUnitMatrix3x3(double *m)
Function sets 3X3 matrix to unit matrix.
#define array(MAT, ROWS, COLS, ROW, COL)
void giveInverseMatrix2x2(double *answer, const double *m)
Function computes inverse of the row-wise saved 2x2 matrix 'm'.
void CopyVector(const double *src, double *dest, long n)
Function copy given number of components from vector, 'a' to vector 'b'.
void giveInverseMatrix6x6to12(double *answer, const double *m)
Function computes inverse of the eshelby-like 3x3 matrix 'm' saved in reduced 6x6to12 form...
int GetRangeOfFileRows(char *p_name)
Funkce zapise LENGTH bytu z BUFFER do docasneho souboru.
int GetRangeOfFileColumns_ii(char *p_name)
Function gives the number columns of a file structured as a table.
void giveInverseMatrix3x3to5(double *answer, const double *m)
Function computes inverse of the eshelby-like 3x3 matrix 'm' saved in reduced 3x3to5 form...
void CopyArray2D(const double *const *src, double **dest, long d1, long d2)
Function copy two 2D double arrays with dimensions d1xd2 from 'src' to 'dest'.
void giveMatrixVectorProduct(const double *mtrx, const double *vect, double *resVect, long n)
Function gives the product of a regular matrix with a vector.
void AddScalarToVector(long s, long *v, long n)
Function add given number of components from vector 'a' to vector 'b'.
int * Allocate1Di(long d1)
Function allocates ('new' command) a 1d array of int.
void printVectorRowForm(double *vect, int n, const char *notice)
Function prints the vector of double values as row.
void AddArray2D(const double *const *src, double **dest, long d1, long d2)
Function add 2D double array with dimensions d1xd2 from 'src' to 'dest'.
void SubtractTwoVectors(const double *v1, const double *v2, double *answer, long n)
Function subtracts two vectors of entries. answer = v1 - v2.
void printVector(double *vect, int n, const char *notice)
Function prints the vector of double values as column.
void SubtractTwoArrays2D(const double *const *a1, const double *const *a2, double **answer, long d1, long d2)
Function subtracts two 2D double arrays with dimensions d1xd2. answer = v1 - v2.
double * Allocate1Ddz(long d1)
Function allocates ('new' command) a 1d array of double set to zero.
void CleanArray2d(double **a, long rows, long columns)
Function cleans an 2d 'double' array, initialize each value being 0-zero.
void DeleteArray3D(double ***array, long d1, long d2)
Function deletes a 3D 'double' array of dimension d1 x d2 x ??, allocated by new. ...
double acosh(double x)
Inverse hyperbolic cosine.
void SumTwoVectors(const double *v1, const double *v2, double *answer, long n)
Function sums two vectors of entries. resVec = vec1 - vec2.
void SubtractVector(const double *a, double *b, long n)
Function subtracts given number of components vector 'a' from vector 'b'; b -= a. ...
void copyMatrix_2Dto1D(const double *const *m, double *v, long n)
Function copies 2D matrix saved in 2d array m[n][n] to row-wise vector v[n * n].
void DivideVector(double *a, long n, double val)
Function divides 'n' components of field 'a' by value 'val'.
void giveMatrixMatrixProduct(const double *mtrx1, const double *mtrx2, double *resMtrx, long n)
Function gives the product of two regular matrices.
void MultiplyVector(double *a, long n, double val)
Function multiplies 'n' components of field 'a' by value 'val'.
void ReadDataToArray(double **p_array, char *p_file_name)
description: function initializes a 2D 'double' array from a given file
void giveInverseMatrix3x3(double *answer, const double *m)
Function computes inverse of the row-wise saved 3x3 matrix 'm'.
void PrintProgress(double procento, int incr)
Operations with arrays of chars.
void printMatrix(double *mtrx, int n, const char *notice)
Function prints a matrix which are saved in 'row-by-row' C arrangement as 1D arrays.
double GiveSumMembersArray2D(const double **a, long d1, long d2)
Function returns sum of all member of array 'a'.
bool ** Allocate1Dbp(long d1)
Function allocates ('new' command) a 1d array of bool* pointers set to NULL.
void DeleteArray2D(bool **array, long d1)
Function deletes a 2D 'bool' array of dimension d1 x ??, allocated by new.
bool * Allocate1Dbz(long d1)
Function allocates ('new' command) a 1d array of bool set to zero.
void ReadDataTo3DArray(double ***p_array, char *p_file_name, int no_fields, int no_rows, int no_columns)
description: function initializes a 3D 'double' array by values from a given file ...
double ** AllocateArray2D(long d1, long d2)
Operations with 2d, 3d, 4d arrays of various sizes.
void AddArray3D(double ***src, double ***dest, long d1, long d2, long d3)
Function add 3D double array with dimensions d1xd2xd3 from 'src' to 'dest'.
double giveVectorLength(const double *point_1, const double *point_2)
void LatexPreambule(FILE *fw)
description: function prints a simple preamble of a LaTEX document last edit: 16.05.2007
void OpenFile(FILE **file, char *name, const char mode[])
Operations with file descriptors.
void giveUnitMatrix2x2(double *m)
Function sets 3x3 matrix to unit matrix.
void copyMatrix_1Dto2D(const double *v, double **m, long n)
Function copies 2D matrix saved in row-wise vector v[n * n] to 2d array m[n][n].
double give_VectorVectorProduct(const double *v1, const double *v2, long n)
Operations with 1d arrays of various length.
double giveVolumeEllipsoid(double a, double b, double c)
Function gives the volume of an allipsoid defined by its semiaxes a, b, c.
void CleanVector(double *a, long n)
Functin cleans a 'double' vector, initialize each value being 0-zero.
void LatexEnd(FILE *fw)
description: function prints the end (closing part) of LaTEX document last edit: 16.05.2007
void AddVector(const double *a, double *b, long n)
Function add given number of components from vector 'a' to vector 'b', b += a.
bool isNumberPresentInVector(int number, int *vect, int range)
description: function returns TRUE/FALSE if a occurs/doesn't occurs in a , respectively ...
void DivideArray2D(double **a, double val, long d1, long d2)
Function divides 2D double array 'a' with dimensions d1xd2 by value 'val'.
void giveTransposedMatrix(const double *mtrx, double *T_mtrx, int n)
Function gives the trasposition of a matrix saved in row-by-row C arrangement.
int GetRangeOfFileColumns(char *p_name)
Function gives the number columns of the file such as is not necessarilly.