muMECH  1.0
elementaryFunctions.cpp
Go to the documentation of this file.
1 //********************************************************************************************************
2 // code: ### ### ##### #### ## ##
3 // ## ## ######## ## ## ## ## ##
4 // ## ## ## ## ## ### ## ######
5 // ## ## ## ## ## ## ## ## ##
6 // ##### ## ## ##### #### ## ##
7 // ##
8 //
9 // name: elementaryFunctions.cpp
10 // author(s): Jan Novak
11 // language: C, C++
12 // license: This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU Lesser General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU Lesser General Public License for more details.
21 //
22 // You should have received a copy of the GNU Lesser General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 //********************************************************************************************************
26 
27 #include <math.h>
28 #include "macros.h"
29 #include "elementaryFunctions.h"
30 #include "types.h"
31 
32 #include "gelib.h"
33 
34 #include <string.h>
35 
36 
37 namespace mumech {
38 
39 
40 
41 // *******************************************************************************************************
42 // /** Operations with arrays of chars **/
43 // /** *** VARIOUS FUNCTIONS *** **/
44 // ***************************************************|***************************************************
45 
51 //int GetPosition( double ** array, double number, int column, int rozsah )
52 //{
53 // int i = 0;
54 // //int position = 0;
55 // for( i = 0; i < rozsah; i++ ){
56 // if( ABS( array[i][column] - number ) < MACHINE_EPS ){
57 // return( i );
58 // }else ;
59 // }
60 // _warningg( "GetPosition: searched number not found, FALSE returned\n");
61 // return( FALSE );
62 //}//end of function: GetPosition( )
63 
64 
65 //********************************************************************************************************
66 // description: function prints the iteration progress to console in 'per-cent'
67 // last edit: 04.02.2007
68 //--------------------------------------------------------------------------------------------------------
69 // note: @incr - the increment of a loop which progress to be print
70 // @procento = ( double ) iter_max/100, where iter_max is the maximum nuber of loop increment
71 // e. g.: for( incr = 0; incr < iter_max, incr++ )
72 // THIS FUNCTION IS GENERALLY TIME CONSUMING, useful just for small loops or
73 // debuging purposes
74 //********************************************************************************************************
75 void PrintProgress( double procento, int incr )
76 {
77  printf("%3.0lf%%\b\b\b\b", ( ( double ) incr / procento ) );
78  return ;
79 }//end of function: PrintProgress( )
80 
81 //********************************************************************************************************
82 // description: function prints the iteration progress to console, function prints a mark '\/'
83 // last edit: 04.02.2007
84 //--------------------------------------------------------------------------------------------------------
85 // note: function requires the allocation of a pinter to 'time', i.e.:
86 // time_t * p_time;
87 // p_time = ( clock_t * ) malloc( sizeof( clock_t ) );
88 // The syntax of the function in a programm then is as follows:
89 // * p_time = clock();
90 // PrintProgress( p_time );
91 //********************************************************************************************************
92 void PrintProgress( clock_t * p_time )
93 {
94  double timer = 0.;
95 
96  timer = * p_time / ( double ) CLOCKS_PER_SEC;
97  if( timer > ( 2/24.) ) printf( "-\b" ); else ;
98  if( timer > ( 4/24.) ) printf( "\\\b" ); else ;
99  if( timer > ( 6/24.) ) printf( "|\b" ); else ;
100  if( timer > ( 8/24.) ){
101  printf( "/\b" );
102  * p_time = 0;
103  }else ;
104  return ;
105 }//end of function: PrintProgress( )
106 
107 
109 double giveVolumeEllipsoid (double a, double b, double c)
110 {
111  return ( 4. * PI * a * b * c / 3. );
112 }
113 
114 double give_curvature (double x, double a, double b)
115 {
117 return b/a + (1.0-b/a) / (0.5*PI) * x;
118 }
119 
121 double acosh(double x)
122 {
123  return log(x + sqrt(x + 1.0) * sqrt(x - 1.0));
124 }
125 
126 
127 
128 
129 // *******************************************************************************************************
130 // /** Operations with file descriptors **/
131 // /** *** FILE PROCESSING *** **/
132 // ***************************************************|***************************************************
133 
134 
137 void OpenFile( FILE **file, char *name, const char mode[] )
138 {
139  if ((*file = fopen(name, mode)) == NULL){
140  FileError("open", name);
141  }else ;
142 
143  return ;
144 }
145 
148 void OpenFile( FILE* &file, char name[], int mode )
149 {
150  switch( mode ){
151  case _READ_ :
152  file = fopen( name, "r" );
153  break;
154  case _WRITE_ :
155  file = fopen( name, "w" );
156  break;
157  case _ADD_ :
158  file = fopen( name, "a" );
159  break;
160  default:
161  _errorr("OpenFile: ERROR: no valid opening mode selected\n");
162  break;
163  }
164 
165  if (file == NULL ){
166  FileError("open", name);
167  }
168 
169  return;
170 }
171 
174 void CloseFile( FILE *file )
175 {
176  if ((fclose(file)) == EOF){
177  FileError("close", "");
178  }else ;
179 
180  return ;
181 }
182 
185 void GoToEndOfLine( FILE * fr )
186 {
187  int c = 0;
188 
189  while( ( c = getc( fr ) ) != '\n' ){
190  ;
191  }
192 }
193 
196 void LatexPreambule( FILE * fw )
197 {
198  fprintf( fw, "\\documentclass[a4paper,11pt]{article}\n");
199  fprintf( fw, "\\usepackage[pdftex]{graphicx}\n" );
200  fprintf( fw, "\\usepackage{fullpage}\n" );
201  fprintf( fw, "\\usepackage{latexsym}\n" );
202  fprintf( fw, "\n\n\\begin{document}\n\n" );
203  fprintf( fw, "\\renewcommand{\\arraystretch}{1.2}\n" );
204 
205  return ;
206 }
207 
210 void LatexEnd( FILE * fw )
211 {
212  fprintf( fw, "\n\n\\end{document}\n" );
213  return ;
214 }
215 
216 //help:
217 
220 //file_descriptor WriteTmp( char * buffer, size_t length )
221 //{
222 // errol;
223 // /* Vytvori nazev souboru a samotny soubor. XXXXXX bude
224 // * prepsano nejakymi znaky, aby bylo jmeno unikatni. */
225 // char temp_filename[] = "/tmp/temp_file.XXXXXX";
226 // int fd = mkstemp( temp_filename );
227 // /* Zrusi jmeno souboru v filesystemu, az se
228 // * uzavre deskriptor souboru soubor se smaze. */
229 // unlink( temp_filename );
230 // /* Zapise velikost zapisovanych dat v bytech. */
231 // write( fd, &length, sizeof( length ) );
232 // /* Nyni zapise samotna data. */
233 // write( fd, buffer, length );
234 // /* Vrati deskriptor souboru docasneho souboru */
235 // return( fd );
236 //}
237 
238 
239 // *******************************************************************************************************
240 // /** Operations with arrays of chars **/
241 // /** *** STRING PROCESSING *** **/
242 // ***************************************************|***************************************************
243 
244 //********************************************************************************************************
245 // description: function gives the number of lins of a file
246 // last edit: 30.10.2004
247 //--------------------------------------------------------------------------------------------------------
248 // note: @name - pointer to the string containing the name of a file
249 //********************************************************************************************************
250 int GetRangeOfFileRows(char * p_name)
251 {
252  FILE * fr;
253  OpenFile (&fr, p_name, "r");
254  int c = 0, i = 0;
255  while ((c = getc(fr)) != EOF){
256  if(c == '\n'){
257  i++;
258  }
259  }
260  CloseFile (fr);
261  return(i);
262 }//end of function: GetRangeOfFileRows( )
263 
264 //********************************************************************************************************
265 // description: function gives the number columns of the file such as is not necessarilly
266 // structured as a table
267 // last edit: 3.11.2004, 18.11.2009
268 //--------------------------------------------------------------------------------------------------------
269 // note: @p_name - pointer to the string containing the name of a file
270 //********************************************************************************************************
271 int GetRangeOfFileColumns(char * p_name)
272 {
273  FILE * fr;
274  int i = 0, rows = 0;
275  double value = 0.;
276 
277  OpenFile (&fr, p_name, "r");
278 
279  while ((fscanf(fr, "%lf", &value)) == 1){
280  i++;
281  }
282 
283  rows = GetRangeOfFileRows(p_name);
284 
285  if( rows == 0 ){
286  _errorr("GetRangeOfFileColumns: no lines in tested file\n");
287  }else ;
288 
289  CloseFile (fr);
290  return (int) (i/rows);
291 }//end of function: GetRangeOfFileColumns( )
292 
293 //********************************************************************************************************
294 // description: function gives the number columns of a file structured as a table
295 // last edit: 13.04.2006
296 //--------------------------------------------------------------------------------------------------------
297 // note: Contrary to a prevois function 'GetRangeOfFileColumns( )', this function counts
298 // and returns just the number of entris in the first row of the @p_name file
299 //********************************************************************************************************
300 int GetRangeOfFileColumns_ii(char * p_name)
301 {
302  FILE * fr, * fw;
303  int i = 0, c = 0;
304  double value = 0.;
305  char tmp_file[] = "tmp_fileXXXXXX";
306 
307  OpenFile (&fr, p_name, "r");
308  //mkstemp( tmp_file );
309  //thrue uot the blank characters
310  while( ( c = getc(fr) ) == ' ' || c == '\t' || c == '\n'){
311  ;
312  }
313 
314  OpenFile (&fw, tmp_file, "w");
315  //writing of a temporary file
316  putc( c, fw );
317  while( ( c = getc(fr) ) != '\n' ){
318  putc( c, fw );
319  }
320 
321  CloseFile (fr);
322  CloseFile (fw);
323 
324  //reading of double values in the first line
325  OpenFile(&fr, tmp_file, "r");
326  while ((fscanf(fr, "%lf", &value)) == 1){
327  i++;
328  }
329 
330  CloseFile (fr);
331  remove( tmp_file );
332 
333  return ( i );
334 }//end of function: GetRangeOfFileColumns_ii( )
335 
336 
337 
338 
339 // *******************************************************************************************************
340 // /** Operations with 1d arrays of various length **/
341 // /** *** GENERAL VECTOR OPERATIONS *** **/
342 // ***************************************************|***************************************************
343 
345 double give_VectorVectorProduct (const double *v1, const double *v2, long n)
346 {
347  double prd = 0.0;
348  while (n--)
349  prd += v1[n] * v2[n];
350 
351  return prd;
352 }
354 double give_quadNormTwoVectors (const double *v1, const double *v2, int n)
355 {
356  double norm = 0.0;
357  while (n--)
358  norm += SQR( v1[n] - v2[n] );
359 
360  return sqrt( norm );
361 }
362 
364 void ReadDataToArray( double ** p_array, char * p_file_name )
365 {
366  FILE * fr;
367  int i = 0, j = 0, rows = 0, columns= 0;
368 
369  rows = GetRangeOfFileRows(p_file_name);
370  columns = GetRangeOfFileColumns_ii(p_file_name);
371 
372  OpenFile (&fr, p_file_name, "r");
373 
374  for(i = 0; i < rows; i++){
375  for(j = 0; j < columns; j++){
376  fscanf(fr, "%lf", &p_array[i][j]);
377  }
378  }
379  CloseFile (fr);
380 }
381 
383 void ReadDataTo3DArray( double *** p_array, char * p_file_name, int no_fields, int no_rows, int no_columns )
384 {
385  FILE * fr;
386  int i = 0, j = 0, k = 0;
387 
388  OpenFile(&fr, p_file_name, "r");
389 
390  for(i = 0; i < no_fields; i++){
391  for(j = 0; j < no_rows; j++){
392  for(k = 0; k < no_columns; k++){
393  fscanf(fr, "%lf", &p_array[i][j][k]);
394  }
395  }
396  }
397  CloseFile(fr);
398 }
399 
401 void ReadDataToArray( int ** p_array, char * p_file_name )
402 {
403  FILE * fr;
404  int i = 0, j = 0, rows = 0, columns= 0;
405 
406  rows = GetRangeOfFileRows(p_file_name);
407  columns = GetRangeOfFileColumns(p_file_name);
408 
409  OpenFile (&fr, p_file_name, "r");
410 
411  for(i = 0; i < rows; i++){
412  for(j = 0; j < columns; j++){
413  fscanf(fr, "%d", &p_array[i][j]);
414  }
415  }
416  CloseFile (fr);
417 }
418 
420 void ReadDataToVector( int * p_array, char * p_file_name )
421 {
422  FILE * fr;
423  int i = 0, rows = 0;
424 
425  rows = GetRangeOfFileRows(p_file_name);
426 
427  OpenFile (&fr, p_file_name, "r");
428 
429  for(i = 0; i < rows; i++){
430  fscanf(fr, "%d", &p_array[i]);
431  }
432 
433  CloseFile (fr);
434 }
435 
437 double giveVectorLength (const double *point_1, const double *point_2)
438 {
439  double length = 0.;
440 
441  length = SQR( point_1[0] - point_2[0] )
442  + SQR( point_1[1] - point_2[1] )
443  + SQR( point_1[2] - point_2[2] );
444 
445  return sqrt( length );
446 }
447 
449 double giveVectorLength (double rx, double ry, double rz)
450 {
451  double length = 0.;
452 
453  length = SQR( rx ) + SQR( ry ) + SQR( rz );
454 
455  return sqrt( length );
456 }
457 
458 
460 bool isNumberPresentInVector (int number, int *vect, int range)
461 {
462  while (range--)
463  if (vect[range] == number)
464  return true;
465 
466  return false;
467 }
468 
469 
470 
471 // // ** ALLOCATION OF ARRAYS BY MALLOC FUNCTION. PLEASE, USE FUNCTION AllocateVector AND AllocateArrays INSTEAD.
472 // // ** Allocation by 'new' is exclusively adopted to avoid mismatch between malloc and new.
473 //
474 //
475 // //********************************************************************************************************
476 // // description: function allocates a 'double' vector
477 // // last edit: 25.1.2007, 18.11.2009
478 // //********************************************************************************************************
479 // void CreateVector( double* &vector, int range )
480 // {
481 // int i = 0;
482 //
483 // vector = ( (double *) malloc(range * sizeof(double)) );
484 //
485 // if( vector == NULL){
486 // _errorr( "CreateVector: Alocation of 'double' vector failed\n");
487 // }else;
488 //
489 // for(i = 0; i < range; i++){
490 // vector[i] = 0.;
491 // }
492 //
493 // return ;
494 // }//end of function: CreateVector( )
495 //
496 //
497 
498 // //********************************************************************************************************
499 // // description: function deletes a 2D 'int' array
500 // // last edit: 25.1.2007, 18.11.2009
501 // //********************************************************************************************************
502 // void DeleteArray( int ** array, int rows )
503 // {
504 // for( int i = 0; i < rows; i++ ){
505 // free( ( void * )array[i] );
506 // }
507 // free( ( void ** )array );
508 // array = NULL;
509 // return ;
510 // }//end of function: DeleteArray( )
511 
512 // //********************************************************************************************************
513 // // description: function realocates the (extends/cuts) alrady allocated memory to 'double'
514 // // last edit: 25.1.2007, 18.11.2009
515 // //--------------------------------------------------------------------------------------------------------
516 // // note: @howmany - howmany members will be attached to existing vector
517 // //********************************************************************************************************
518 // void ExtendVector( double* &vector, int howmany )
519 // {
520 // // tuto fci nemuzu pouzit
521 // errol;
522 //
523 //
524 // vector = ( (double *) realloc( vector, howmany * sizeof( double ) ) );
525 //
526 // if( vector == NULL){
527 // _errorr( "ExtendVector: reallocation of 'double' memory failed\n");
528 // }else;
529 //
530 // return ;
531 // }//end of function: ExtendVector( )
532 //
533 
534 
535 
536 // *******************************************************************************************************
537 // /** Operations with 2d, 3d, 4d arrays of various sizes **/
538 // /** *** GENERAL ARRAY OPERATIONS *** **/
539 // ***************************************************|***************************************************
540 
542 double** AllocateArray2D (long d1, long d2)
543 {
544  double **array = new double*[d1];
545  while (d1--) array[d1] = new double[d2];
546  return array;
547 }
549 void AllocateArray2D (double **&array, long d1, long d2)
550 {
551  if (array != NULL) _errorr("allocation of non NULL array");
552  array = AllocateArray2D(d1,d2);
553 }
554 
555 
556 // /// Function allocates a 2D 'double' d1xd2 array by 'new' command. First dimension is 'all', second dim only one i1-th.
557 // double** AllocateArray2Dao (long d1, long d2, long i1)
558 // {
559 // double **array = new double*[d1];
560 // memset (array, 0, d1*sizeof(double*));
561 //
562 // array[i1] = new double[d2];
563 // return array;
564 // }
565 // /// Function allocates a 2D 'double' array by 'new' command.
566 // void AllocateArray2Dao (double **&array, long d1, long d2, long i1)
567 // {
568 // if (array != NULL) _errorr("allocation of non NULL array");
569 // array = AllocateArray2D(d1,d2,i1);
570 // }
571 
573 void CopyArray2D (const double* const* src, double **dest, long d1, long d2)
574 {
575  long i, j;
576 
577  for (i=0; i<d1; i++)
578  for (j=0; j<d2; j++)
579  dest[i][j] = src[i][j];
580 
581  // pouzij toto memcpy(b, a, n * sizeof(double)); }
582 
583 }
585 void CopyArray3D (const double ***src, double ***dest, long d1, long d2, long d3)
586 {
587  long i, j, k;
588 
589  for (i=0; i<d1; i++)
590  for (j=0; j<d2; j++)
591  for (k=0; k<d3; k++)
592  dest[i][j][k] = src[i][j][k];
593 
594  // pouzij toto memcpy(b, a, n * sizeof(double)); }
595 
596 }
597 
599 void AddArray2D (const double* const* src, double** dest, long d1, long d2)
600 {
601  long i, j;
602 
603  for (i=0; i<d1; i++)
604  for (j=0; j<d2; j++)
605  dest[i][j] += src[i][j];
606 
607 }
609 void AddArray3D (double ***src, double ***dest, long d1, long d2, long d3)
610 {
611  long i, j, k;
612 
613  for (i=0; i<d1; i++)
614  for (j=0; j<d2; j++)
615  for (k=0; k<d3; k++)
616  dest[i][j][k] += src[i][j][k];
617 
618 }
619 
621 void DivideArray2D (double** a, double val, long d1, long d2)
622 {
623  long i, j;
624 
625  for (i=0; i<d1; i++)
626  for (j=0; j<d2; j++)
627  a[i][j] /= val;
628 
629 }
630 
631 
632 
634 void SubtractTwoArrays2D (const double* const* a1, const double* const* a2, double **answer, long d1, long d2)
635 {
636  long i, j;
637 
638  for (i=0; i<d1; i++)
639  for (j=0; j<d2; j++)
640  answer[i][j] = a1[i][j] - a2[i][j];
641 }
642 
643 
645 void giveInverseMatrix2x2 (double *answer, const double *m)
646 {
647  double det = m[0]*m[3] - m[1]*m[2];
648 
649  answer[0] = m[3] / det;
650  answer[1] = -m[1] / det;
651  answer[2] = -m[2] / det;
652  answer[3] = m[0] / det;
653 }
654 
656 void giveInverseMatrix3x3 (double *answer, const double *m)
657 {
658  double det = m[0]*m[4]*m[8] - m[0]*m[5]*m[7] - m[1]*m[3]*m[8] + m[1]*m[5]*m[6] + m[2]*m[3]*m[7] - m[2]*m[4]*m[6];
659 
660  answer[0] = (m[4]*m[8] - m[5]*m[7]) / det;
661  answer[1] = -(m[1]*m[8] - m[2]*m[7]) / det;
662  answer[2] = (m[1]*m[5] - m[2]*m[4]) / det;
663 
664  answer[3] = -(m[3]*m[8] - m[5]*m[6]) / det;
665  answer[4] = (m[0]*m[8] - m[2]*m[6]) / det;
666  answer[5] = -(m[0]*m[5] - m[2]*m[3]) / det;
667 
668  answer[6] = (m[3]*m[7] - m[4]*m[6]) / det;
669  answer[7] = -(m[0]*m[7] - m[1]*m[6]) / det;
670  answer[8] = (m[0]*m[4] - m[1]*m[3]) / det;
671 }
672 
673 
675 void giveInverseMatrix3x3to5 (double *answer, const double *m)
676 {
677  giveInverseMatrix2x2 (answer, m);
678 
679  answer[4] = 1.0 / m[4];
680 }
682 void giveInverseMatrix6x6to12 (double *answer, const double *m)
683 {
684  giveInverseMatrix3x3 (answer, m);
685 
686  answer[ 9] = 1.0 / m[ 9];
687  answer[10] = 1.0 / m[10];
688  answer[11] = 1.0 / m[11];
689 }
690 
691 
692 
693 
694 //local constant definitions
695 #define _at( mtrx, i, j, n ) mtrx[i * n + j] //n - number of rows of the matrix @mtrx
696 
697 
698 //********************************************************************************************************
699 // description: function gives the product of a regular matrix with a vector. Both matrix and the vector
700 // are saved in 'row-by-row' C arrangement as 1D arrays
701 // last edit: 27. 11. 2009
702 // -------------------------------------------------------------------------------------------------------
703 // note: @mtrx - '@n x @n' regular matrix
704 // @vect - '@n x 1' input vector
705 // @resVect - '@n x 1' resulting vector of a product
706 // @n - number of rows of a matrix or number of vector entries
707 //********************************************************************************************************
708 void giveMatrixVectorProduct (const double *mtrx, const double *vect, double *resVect, long n)
709 {
710  double *auxResVect = NULL;
711 
712  // in case of in-place product
713  if (vect == resVect) auxResVect = new double[n];
714  // in case of out-of-place product
715  else auxResVect = resVect;
716 
717  CleanVector (auxResVect, n);
718 
719  // matrix vector product
720  int i, j;
721  for (i = 0; i < n; i++)
722  for (j = 0; j < n; j++)
723  auxResVect[i] += _at( mtrx, i, j, n ) * vect[j];
724 
725 
726  // initialization of resulting vecotor cleaning of allocated memory
727  if (vect == resVect) {
728  CopyVector (auxResVect, resVect, n);
729  delete [] auxResVect;
730  }
731  else
732  auxResVect = NULL;
733 
734 }
735 
736 
745 void giveMatrixMatrixProduct (const double *mtrx1, const double *mtrx2, double *resMtrx, long n)
746 {
747  if (mtrx1 == mtrx2 || mtrx1 == resMtrx || mtrx2 == resMtrx) errol;
748 
749  CleanVector(resMtrx, n*n);
750 
751  long i, j, k;
752  for (i = 0; i < n; i++)
753  for (j = 0; j < n; j++)
754  for (k = 0; k < n; k++)
755  _at( resMtrx, i, j, n ) += _at( mtrx1, i, k, n ) * _at( mtrx2, k, j, n );
756 
757 }
758 
759 
766 void giveTransposedMatrix( const double * mtrx, double * T_mtrx, int n )
767 {
768  //Ts's
769  for( int i = 0; i < n; i++ ){
770  for( int j = 0; j < n; j++ ){
771  _at( T_mtrx, i, j, n ) = _at( mtrx, j, i, n );
772  }
773  }
774 }
775 
776 //********************************************************************************************************
777 // description: function prints a matrix which is saved in 'row-by-row' C arrangement as 1D array
778 // last edit: 02. 12. 2009
779 // -------------------------------------------------------------------------------------------------------
780 // note: @mtrx - '@n x @n' regular matrix
781 // @n - number of rows of printed matrix
782 //********************************************************************************************************
783 void printMatrix( double * mtrx, int n, const char * notice )
784 {
785  printf( "%s", notice );
786  for( int i = 0; i < n; i++ ){
787  for( int j = 0; j < n; j++ ){
788  if( ABS( _at( mtrx, j, i, n ) ) > MACHINE_EPS_PRN ){
789  printf( "%.6e ", _at( mtrx, j, i, n ) );
790  }
791  else{
792  printf( "%.6e ", 0. );
793  }
794  }printf( "\n" );
795  }
796 
797  return ;
798 }//end of function: printMatrix( )
799 
800 
801 //********************************************************************************************************
802 // description: function prints a matrix which is saved as 2D array
803 // last edit: 02. 12. 2009
804 // -------------------------------------------------------------------------------------------------------
805 // note: @mtrx - '@n x @n' regular matrix
806 // @n - number of rows of printed matrix
807 //********************************************************************************************************
808 void printMatrix( double ** mtrx, int n, const char * notice )
809 {
810  printf( "%s", notice );
811  for( int i = 0; i < n; i++ ){
812  for( int j = 0; j < n; j++ ){
813  if( ABS( mtrx[i][j] ) > MACHINE_EPS_PRN ){
814  printf( "%.6e ", mtrx[i][j] );
815  }
816  else{
817  printf( "%.6e ", 0. );
818  }
819  }printf( "\n" );
820  }
821 
822  return ;
823 }//end of function: printMatrix( )
824 
825 
826 //********************************************************************************************************
827 // description: function prints the vector of double values as column
828 // last edit: 08. 12. 2009
829 // -------------------------------------------------------------------------------------------------------
830 // note: @vect - '@n x 1' vector
831 // @n - number of vector entries
832 //********************************************************************************************************
833 void printVector( double * vect, int n, const char * notice )
834 {
835  printf( "%s", notice );
836  for( int i = 0; i < n; i++ ){
837  if( ABS( vect[i] ) > MACHINE_EPS_PRN ){
838  printf( "%.6e\n", vect[i] );
839  }
840  else{
841  printf( "%.6e\n", 0. );
842  }
843  }
844 
845  return ;
846 }//end of function: printVector( )
847 
848 //********************************************************************************************************
849 // description: function prints the vector of integers as column
850 // last edit: 08. 12. 2009
851 // -------------------------------------------------------------------------------------------------------
852 // note: @vect - '@n x 1' vector
853 // @n - number of vector entries
854 //********************************************************************************************************
855 void printVector( int * vect, int n, const char * notice )
856 {
857  printf( "%s", notice );
858  for( int i = 0; i < n; i++ ){
859  printf( "%d\n", vect[i] );
860  }
861 
862  return ;
863 }//end of function: printVector( )
864 
865 
866 
867 //********************************************************************************************************
868 // description: function prints the vector of double values as row
869 // last edit: 08. 12. 2009
870 // -------------------------------------------------------------------------------------------------------
871 // note: @vect - '@n x 1' vector
872 // @n - number of vector entries
873 //********************************************************************************************************
874 void printVectorRowForm( double * vect, int n, const char * notice )
875 {
876  printf( "%s", notice );
877  for( int i = 0; i < n; i++ ){
878  if( ABS( vect[i] ) > MACHINE_EPS_PRN ){
879  printf( "%.6e, ", vect[i] );
880  }
881  else{
882  printf( "%.6e, ", 0. );
883  }
884  }printf( "\n" );
885 
886  return ;
887 }//end of function: printVectorRowForm( )
888 
889 //********************************************************************************************************
890 // description: function prints the vector of integers as row
891 // last edit: 08. 12. 2009
892 // -------------------------------------------------------------------------------------------------------
893 // note: @vect - '@n x 1' vector
894 // @n - number of vector entries
895 //********************************************************************************************************
896 void printVectorRowForm( int * vect, int n, const char * notice )
897 {
898  printf( "%s", notice );
899  for( int i = 0; i < n; i++ ){
900  printf( "%d, ", vect[i] );
901  }printf( "\n" );
902 
903  return ;
904 }//end of function: printVectorRowForm( )
905 
906 
907 } // end of namespace mumech
908 
909 /*end of file*/
double give_curvature(double x, double a, double b)
void CopyArray3D(const double ***src, double ***dest, long d1, long d2, long d3)
Function copy two 3D double arrays with dimensions d1xd2xd3 from &#39;src&#39; to &#39;dest&#39;. ...
file of various types and symbolic constant definitions
void ReadDataToVector(int *p_array, char *p_file_name)
description: function initializes an &#39;int&#39; 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 &#39;n&#39;.
void GoToEndOfLine(FILE *fr)
description: functions moves the cursor the the end of line (EOLN) in a text file last edit: 1...
General functions.
void CloseFile(FILE *file)
description: function closes a previously opened file and tests the succes of the closing note: funct...
#define PI
Definition: macros.h:71
#define array(MAT, ROWS, COLS, ROW, COL)
Definition: meso3d.cpp:139
void giveInverseMatrix2x2(double *answer, const double *m)
Function computes inverse of the row-wise saved 2x2 matrix &#39;m&#39;.
void CopyVector(const double *src, double *dest, long n)
Function copy given number of components from vector, &#39;a&#39; to vector &#39;b&#39;.
void giveInverseMatrix6x6to12(double *answer, const double *m)
Function computes inverse of the eshelby-like 3x3 matrix &#39;m&#39; 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 &#39;m&#39; 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 &#39;src&#39; to &#39;dest&#39;.
void giveMatrixVectorProduct(const double *mtrx, const double *vect, double *resVect, long n)
Function gives the product of a regular matrix with a vector.
#define errol
Definition: gelib.h:151
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 &#39;src&#39; to &#39;dest&#39;.
The header file of usefull macros.
void printVector(double *vect, int n, const char *notice)
Function prints the vector of double values as column.
Collection of the functions of basic manipulations, some of them can be used instead of their counter...
#define _at(mtrx, i, j, n)
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.
#define ABS(a)
Definition: macros.h:118
double acosh(double x)
Inverse hyperbolic cosine.
#define MACHINE_EPS_PRN
Definition: macros.h:69
#define SQR(a)
Definition: macros.h:97
void giveMatrixMatrixProduct(const double *mtrx1, const double *mtrx2, double *resMtrx, long n)
Function gives the product of two regular matrices.
#define FileError(fmode, name)
Definition: macros.h:77
#define _errorr(_1)
Definition: gelib.h:160
void ReadDataToArray(double **p_array, char *p_file_name)
description: function initializes a 2D &#39;double&#39; array from a given file
void giveInverseMatrix3x3(double *answer, const double *m)
Function computes inverse of the row-wise saved 3x3 matrix &#39;m&#39;.
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 &#39;row-by-row&#39; C arrangement as 1D arrays.
void ReadDataTo3DArray(double ***p_array, char *p_file_name, int no_fields, int no_rows, int no_columns)
description: function initializes a 3D &#39;double&#39; 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 &#39;src&#39; to &#39;dest&#39;.
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.
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 &#39;double&#39; 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
bool isNumberPresentInVector(int number, int *vect, int range)
description: function returns TRUE/FALSE if a occurs/doesn&#39;t occurs in a , respectively ...
void DivideArray2D(double **a, double val, long d1, long d2)
Function divides 2D double array &#39;a&#39; with dimensions d1xd2 by value &#39;val&#39;.
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.