MIDAS  0.75
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
arrays.h
Go to the documentation of this file.
1 #ifndef MIDAS_ARRAYS_H
2 #define MIDAS_ARRAYS_H
3 
4 #include "gelib.h"
5 #include "mathlib.h"
6 #include "librw.h"
7 
8 #include <stdio.h>
9 #include <string.h>
10 #include <math.h>
11 
12 
19 namespace midaspace {
20 
21 #define PYP 3
22 
23 struct VectoR;
24 struct PoinT;
25 
26 class Dmtrx;
27 
28 // ********************************************************************************************
29 // *** *** *** *** CLASS ELEM3D *** *** *** ***
30 // ********************************************************************************************
31 struct Elem3D
32 {
33  double x, y, z;
34 
35  Elem3D() { x=y=z = 0.0; }
36  virtual ~Elem3D() { }
37 
38  // *** GET ***
40  double operator[] (int i) const {
41 #ifdef DEBUG
42  if (i<0 || i>2) _errorr ("i out of the range");
43 #endif
44  return ((i==0) ? x : ((i==1) ? y : z));
45  }
47  double& operator[] (int i) {
48 #ifdef DEBUG
49  if (i<0 || i>2) _errorr ("i out of the range");
50 #endif
51  return ((i==0) ? x : ((i==1) ? y : z));
52  }
53 
54  // *** FIND OUT ***
55  bool is_identical_to (const Elem3D *p, double zero) const { return isZero(zero, x - p->x) && isZero(zero, y - p->y) && isZero(zero, z - p->z); }
56  bool is_identical_to (const Elem3D *p) const { return ( x == p->x && y == p->y && z == p->z); }
57 
58  // *** EDIT ***
59  Elem3D* tms (double val) { x *= val; y *= val; z *= val; return this; }
60  Elem3D* dvd (double val) { x /= val; y /= val; z /= val; return this; }
61  Elem3D* add (const Elem3D *p) { x += p->x; y += p->y; z += p->z; return this; }
62  Elem3D* sub (const Elem3D *p) { x -= p->x; y -= p->y; z -= p->z; return this; }
63  Elem3D* copy (const Elem3D *p) { x = p->x; y = p->y; z = p->z; return this; }
64  Elem3D* zero (void) { x = y = z = 0.0; return this; }
65  Elem3D* round2abszero (double zr) { if (fabs(x)<zr) x=0.0; if (fabs(y)<zr) y=0.0; if (fabs(z)<zr) z=0.0; return this; }
66 
67  // *** SET ***
68  bool scan_x (FILE *stream) { return ( fscanf (stream, "%lf", &x) == 1); }
69  bool scan_y (FILE *stream) { return ( fscanf (stream, "%lf", &y) == 1); }
70  bool scan_z (FILE *stream) { return ( fscanf (stream, "%lf", &z) == 1); }
71  bool scan_xyz (FILE *stream) { return ( fscanf (stream, "%lf %lf %lf", &x, &y, &z) == 3); }
72  bool scan_xyz (const char *&src) { sscanf (src, "%lf %lf %lf", &x, &y, &z); return (SP_skip_word(src) && SP_skip_word(src) && SP_skip_word(src)); }
73  bool scan_xyz (const double *src) { x = src[0]; y = src[1]; z = src[2]; return true; }
74 
75  // *** GET ***
76  void copy_to (double *dest) const { dest[0] = x; dest[1] = y; dest[2] = z; }
77 
78  // *** COMPUTE ***
80  double giveScalProduct (const Elem3D *v) const { return x*v->x + y*v->y + z*v->z; }
82  double give_sum (void) const { return x + y + z; }
83 
84  // *** PRINT ***
85 #ifdef DEBUG
86  virtual void printYourself (bool force=false) const { fprintf (stdout, "PoinT [3]:\n% .*e % .*e % .*e\n", PYP, x, PYP, y, PYP, z); }
87 #endif
88 
89 };
90 
91 
92 // ********************************************************************************************
93 // *** *** *** *** CLASS POINT *** *** *** ***
94 // ********************************************************************************************
95 
96 struct PoinT : public Elem3D
97 {
98  // *** EDIT ***
99  PoinT* copy (const PoinT *p) { Elem3D::copy(p); return this; }
100 
101  double dist_to (const PoinT *p) const { return sqrt( this->dist2_to(p) ); }
102  double dist2_to (const PoinT *p) const { return ((x-p->x)*(x-p->x) + (y-p->y)*(y-p->y) + (z-p->z)*(z-p->z)); }
103 
105  inline double dist_to_line (const PoinT *p1, const PoinT *p2) const;
107  void bePointAtAbscissa (const PoinT *p1, const PoinT *p2, double ksi)
108  {
109  x = 0.5 * (p1->x + p2->x + ksi * ( p2->x - p1->x ));
110  y = 0.5 * (p1->y + p2->y + ksi * ( p2->y - p1->y ));
111  z = 0.5 * (p1->z + p2->z + ksi * ( p2->z - p1->z ));
112  }
113 
116  bool give_ksiAtAbscissa (double zero, double norm, const PoinT *p1, const PoinT *p2, double &ksi) const
117  {
118  if ( dist_to_line (p1,p2) > norm*zero ) return false;
119 
121  long i;
122  if (fabs(p1->x - p2->x) > fabs(p1->y - p2->y)) if (fabs(p1->x - p2->x) > fabs(p1->z - p2->z)) i = 0; else i = 2;
123  else if (fabs(p1->y - p2->y) > fabs(p1->z - p2->z)) i = 1; else i = 2;
124 
125  ksi = 2.0 * ( (*this)[i] - (*p1)[i] ) / ( (*p2)[i] - (*p1)[i] ) - 1.0 ;
126 
127  return ( fabs(ksi) < (1.0+zero) );
128  }
129 
131  void beRotatedPoint (const Dmtrx *rot, const PoinT *point);
132 
133  double* d() const
134  {
135  double *a = new double[3];
136  a[0] = x; a[1] = y; a[2] = z;
137  return a;
138  }
139 
140 };
141 
142 
143 // ********************************************************************************************
144 // *** *** *** *** CLASS VectoR *** *** *** ***
145 // ********************************************************************************************
146 
147 struct VectoR : public Elem3D
148 {
149  // *** EDIT ***
150  VectoR* copy (const VectoR *p) { Elem3D::copy(p); return this; }
151 
153  VectoR* beP2P (const PoinT *p1, const PoinT *p2) {
154  x = p2->x - p1->x;
155  y = p2->y - p1->y;
156  z = p2->z - p1->z;
157  return this;
158  }
160  VectoR* beVectProduct (const VectoR *v1, const VectoR *v2) {
161  x = v1->y * v2->z - v2->y * v1->z;
162  y = v1->z * v2->x - v2->z * v1->x;
163  z = v1->x * v2->y - v2->x * v1->y;
164  return this;
165  }
167  VectoR* beVectProduct (const PoinT *p1, const PoinT *p2, const PoinT *p3)
168  { // beVectProduct (p1, p2, p1, p3);
169  x = p2->y*p3->z - p3->y*p2->z + p1->y*(p2->z-p3->z) - p1->z*(p2->y-p3->y);
170  y = p2->z*p3->x - p3->z*p2->x + p1->z*(p2->x-p3->x) - p1->x*(p2->z-p3->z);
171  z = p2->x*p3->y - p3->x*p2->y + p1->x*(p2->y-p3->y) - p1->y*(p2->x-p3->x);
172  return this;
173  }
175  VectoR* beVectProduct (const PoinT *p1, const PoinT *p2, const PoinT *p3, const PoinT *p4)
176  {
177  VectoR v1, v2;
178  v1.beP2P(p1, p2);
179  v2.beP2P(p3, p4);
180 
181  this->beVectProduct (&v1, &v2);
182  return this;
183  }
185  VectoR* normalize (void) { this->dvd( this->give_length() ); return this; }
186 
187  // *** COMPUTE ***
188  double give_length (void) const { return sqrt( x*x + y*y + z*z ); }
189 
190  // *** INFO ***
191  bool is_parallel_with (const VectoR *that, double relZero) const
192  {
193  double l1 = this->give_length();
194  double l2 = that->give_length();
195  if (l1/l2 < relZero || l2/l1 < relZero) _warningg("Lengths of vectors are not proportional");
196 
197  double v1x = this->x/l1; if (fabs(v1x) < relZero) v1x = 0.0;
198  double v1y = this->y/l1; if (fabs(v1y) < relZero) v1y = 0.0;
199  double v1z = this->z/l1; if (fabs(v1z) < relZero) v1z = 0.0;
200 
201  double v2x = that->x/l2; if (fabs(v2x) < relZero) v2x = 0.0;
202  double v2y = that->y/l2; if (fabs(v2y) < relZero) v2y = 0.0;
203  double v2z = that->z/l2; if (fabs(v2z) < relZero) v2z = 0.0;
204 
205  int sign;
206  if (v1x*v2x < 0.0 || v1y*v2y < 0.0 || v1z*v2z < 0.0) sign = -1;
207  else sign = 1;
208 
209  return (fabs(v1x-sign*v2x) < relZero && fabs(v1y-sign*v2y) < relZero && fabs(v1z-sign*v2z) < relZero);
210  }
211 };
212 
214 double PoinT :: dist_to_line (const PoinT *p1, const PoinT *p2) const
215 {
216  VectoR a;
217  a.beVectProduct(p1, p2, this);
218  return ( sqrt((a.x*a.x + a.y*a.y + a.z*a.z) / p1->dist2_to(p2) ) );
219 }
220 
221 // ********************************************************************************************
222 // *** *** *** *** CLASS MatriX *** *** *** ***
223 // ********************************************************************************************
224 struct MatriX
225 {
226  double a[9];
227 
228  MatriX() { }
229  virtual ~MatriX() { }
230 
231  double& at11() { return a[0]; }
232  double& at12() { return a[1]; }
233  double& at13() { return a[2]; }
234  double& at21() { return a[3]; }
235  double& at22() { return a[4]; }
236  double& at23() { return a[5]; }
237  double& at31() { return a[6]; }
238  double& at32() { return a[7]; }
239  double& at33() { return a[8]; }
240 
241  void rotate (Dvctr *v) const;
242  void rotate (double *v) const;
243 
244  void copy_to_row_1 (const VectoR *v) { a[0] = v->x; a[1] = v->y; a[2] = v->z; }
245  void copy_to_row_2 (const VectoR *v) { a[3] = v->x; a[4] = v->y; a[5] = v->z; }
246  void copy_to_row_3 (const VectoR *v) { a[6] = v->x; a[7] = v->y; a[8] = v->z; }
247 
248  void copy_to_col_1 (const VectoR *v) { a[0] = v->x; a[3] = v->y; a[6] = v->z; }
249  void copy_to_col_2 (const VectoR *v) { a[1] = v->x; a[4] = v->y; a[7] = v->z; }
250  void copy_to_col_3 (const VectoR *v) { a[2] = v->x; a[5] = v->y; a[8] = v->z; }
251 };
252 
253 
254 // ********************************************************************************************
255 // *** *** *** *** CLASS ARRAY *** *** *** ***
256 // ********************************************************************************************
257 
258 #ifdef DEBUG
259 #define SRCCHCK if (src==NULL) _errorr("source == NULL");
260 #define AVOID_CNST if (cnst) _errorr("cnst")
261 #define AVOID_EXTA if (exta) _errorr("exta")
262 #else
263 #define SRCCHCK
264 #define AVOID_CNST
265 #define AVOID_EXTA
266 #endif
267 
268 
271 
272 class Dmtrx;
273 
274 class Array
275 {
276  public:
278  Array () { }
280  virtual ~Array () { }
281 
282  // give type def
283  virtual arrayTypedef give_arrayTypedef (void) const = 0;
284 
285  // *** PRINT ***
286 #ifdef DEBUG
287  virtual void printYourself (bool force=false) const = 0;
288 #endif
289 
290 };
291 
292 
293 
294 // ********************************************************************************************
295 // *** *** *** *** CLASS ARRAY1D *** *** *** ***
296 // ********************************************************************************************
297 class Array1d : public Array
298 {
299  public:
301  Array1d () : Array() { }
303  virtual ~Array1d() { }
304 
305  virtual long give_size (void) const = 0;
306 
307  // *** PRINT ***
308  virtual int length_printed (int precision) const = 0;
309  virtual void print (char *stream, int precision, double absZero=0.0) const = 0;
310 };
311 
312 
313 // ********************************************************************************************
314 // *** *** *** *** CLASS XSCAL *** *** *** ***
315 // ********************************************************************************************
316 class Xscal : public Array1d
317 {
318  public:
320  Xscal () : Array1d() { }
322  virtual ~Xscal() { }
323 
324  long give_size (void) const { return 1; }
325 };
326 
327 // ********************************************************************************************
328 // *** *** *** *** CLASS DSCAL *** *** *** ***
329 // ********************************************************************************************
330 class Dscal : public Xscal
331 {
332  public:
333  double a; // value
334 
336  Dscal (void) : Xscal () { a = 0; }
337  Dscal (double val) : Xscal () { a = val; }
339  virtual ~Dscal() { }
340 
342  arrayTypedef give_arrayTypedef (void) const { return ATdouble; }
343 
344  // *** OPERATORS ***
345  double operator() (void) const { return a; }
346  double& operator() (void) { return a; }
347 
348  // *** PRINT ***
349 #ifdef DEBUG
350  virtual void printYourself (bool force=false) const { fprintf (stdout, "Double scalar: % .*e\n", PYP, a); }
351 #endif
352  virtual int length_printed (int precision) const { return 1+2+1+precision+2+NUM_DIGITS_IN_PRINTED_EXPONENT + 1; }
353  virtual void print (char *stream, int precision, double absZero=0.0) const;
354 };
355 
356 
357 
358 // ********************************************************************************************
359 // *** *** *** *** CLASS XVCTR *** *** *** ***
360 // ********************************************************************************************
361 class Xvctr : public Array1d
362 {
363  protected:
364  bool exta; // external allocation, we cannot delete "a"
365  bool cnst; // constant, values can not be changed
366  long shft; // a is shifted
367 
368  long size; // length of array
369  long asize; // length of the allocated array
370 
371 
372  public:
374  Xvctr (long s) : Array1d() { exta = cnst = false; shft = 0; size = asize = s; }
376  virtual ~Xvctr() { }
377 
378  virtual arrayClassType give_classid() const = 0;
379 
380  // *** SET ***
381  virtual void cpat (long i, const Xvctr *p, long j) = 0;
382  virtual void shift (long val) = 0;
383  void deshift (void) { this->shift(-shft); }
384  virtual bool scan (const char *&src) = 0;
385 
386  // *** GET ***
387  virtual long give_size (void) const { return size; }
388 
389  // *** COMPUTE ***
390  virtual double give_lenght (void) const = 0;
392  double give_zero (double abszero, double relzero) const;
393 
394  // *** PRINT ***
395  //virtual int length_printed (int precision) const = 0;
396  virtual int length_printed_vector (int precision) const = 0;
397  virtual int length_printed_tensor (int precision) const = 0;
398  //virtual void print (char *stream, int precision, double absZero=0.0 ) const = 0;
399  virtual void print_vector (char *stream, int precision, double absZero=0.0, bool zerorest=false) const = 0;
400  virtual void print_symtensor (char *stream, int precision, double absZero=0.0, bool zerorest=false) const = 0;
401  virtual void print_symtensor (FILE *stream, int precision, double absZero=0.0, bool zerorest=false) const = 0;
402  //virtual void print_member (char *stream, int precision, long i) const = 0;
403 };
404 
405 // ********************************************************************************************
406 // *** *** *** *** CLASS LVCTR *** *** *** ***
407 // ********************************************************************************************
408 class Lvctr : public Xvctr
409 {
411  long *a;
412 
413  public:
415  Lvctr (void) : Xvctr (0) { a = NULL; }
416  Lvctr (long s) : Xvctr (s) { a = new long[asize]; }
417  Lvctr ( const Lvctr *p) : Xvctr (p->size) { a = new long[asize]; memcpy (a, p->a, size*sizeof(long)); }
418  Lvctr (long s, const long *p) : Xvctr (s) { a = new long[asize]; memcpy (a, p, size*sizeof(long)); }
420  virtual ~Lvctr() { deshift(); if (a && !exta) delete [] a; }
421 
424  arrayTypedef give_arrayTypedef (void) const { return ATlong; }
425 
426  // *** OPERATORS ***
428  long operator[] (long i) const {
429 #ifdef DEBUG
430  if (i<0 || i>=size) _errorr ("i out of the range");
431 #endif
432  return a[i];
433  }
434 
436  long& operator[] (long i) {
437 #ifdef DEBUG
438  if (i<0 || i>=size)
439  _errorr ("i out of the range");
440 #endif
441  return a[i];
442  }
443 
445  Lvctr& operator= (const Lvctr &src) {
447  if ( this == &src ) _errorr("oneself assignment");
448 
449  size = 0;
450  this->realloc (src.size);
451  size = src.size;
452 
453  memcpy (a, src.a, size*sizeof(long));
454 
455  return * this;
456  }
457 
458  // *** SET ***
460  void add (long val) { resize_preserve_vals(size+1); a[size-1] = val; }
462  void add_unique (long val) { if (! this->is_member(val)) this->add(val); }
464  bool is_member (long val) const { return is_member_of_array (val, size, a); }
466  Lvctr* free (void);
468  void realloc (long newsize);
470  Lvctr* resize_preserve_vals (long newsize) { AVOID_CNST; AVOID_EXTA; this->realloc (newsize); size = newsize; return this; }
472  Lvctr* resize_ignore_vals (long newsize) { AVOID_CNST; AVOID_EXTA; size = 0; this->realloc (newsize); size = newsize; return this; }
474  Lvctr* resize_to_asize (void) { AVOID_CNST; AVOID_EXTA; size = asize; return this; }
476  Lvctr* assign_array ( long *array, long s);
477  Lvctr* assign_array (const long *array, long s);
479  void cpat (long i, const Xvctr *p, long j) {
480  const Lvctr *pt = dynamic_cast<const Lvctr *>(p);
481  if (!pt) _errorr("");
482  a[i] = pt->a[j];
483  }
484  void shift (long val) { AVOID_CNST; if (a) { shft += val; a += val; } }
485  bool scan (const char *&src) { return SP_scan_array (src, size, a); }
487  void fillYourselfBy (long val) { memset (a, val, size*sizeof(long)); }
488 
489  // *** GET ***
491  long* give_ptr2val (long i=0) { AVOID_CNST; return a + i; }
492  const long* give_ptr2val (long i=0) const { return a + i; }
493 
494 
495  // *** COMPUTE ***
496  double give_lenght (void) const;
497  long give_sum (void) const;
498  long give_number_of_nonzeros (void) const;
499  long give_number_of_zeros (void) const;
500 
501 
502  // *** EDIT ***
504  void zero (void) { AVOID_CNST; memset (a,0,asize*sizeof(long)); }
506  //
507  //
508  //
509  //
510 
512  //
513  //
514  //
515  //
516  //
517 
523  //void addtms (const Dvctr &src, double tms);
525  //void tmsby (double val);
527  //void dvdby (double val);
528 
530 
531  // *** PRINT ***
532 #ifdef DEBUG
533  virtual void printYourself (bool force) const;
534 #endif
535  //
536  int length_printed (int precision) const;
537  int length_printed_vector (int precision) const;
538  int length_printed_tensor (int precision) const;
539  void print (char *stream, int precision, double absZero=0.0 ) const;
540  void print_vector (char *stream, int precision, double absZero=0.0, bool zerorest=false) const;
541  void print_symtensor (char *stream, int precision, double absZero=0.0, bool zerorest=false) const;
542  void print_symtensor (FILE *stream, int precision, double absZero=0.0, bool zerorest=false) const;
543  //void print_member (char *stream, int precision, long i) const { sprintf (stream, "%ld", a[i]); }
544  //
545  // void print_symtensor (FILE *stream) const;
546  // void print_r2z_symtensor (FILE *stream, double relZero, double absZero) const;
547  // void print_symtensor (char *stream) const;
548  // void print_r2z_symtensor (char *stream, double relZero, double absZero) const;
549 };
550 
551 
552 // ********************************************************************************************
553 // *** *** *** *** CLASS DVCTR *** *** *** ***
554 // ********************************************************************************************
555 
556 class Dvctr : public Xvctr
557 {
558  public:
559  double *a; // array of values
560 
562  Dvctr (void) : Xvctr (0) { a = NULL; }
563  Dvctr (long s) : Xvctr (s) { a = new double[asize]; }
564  Dvctr ( const Dvctr *src) : Xvctr (src->size) { SRCCHCK; a = new double[asize]; memcpy (a, src->a, size*sizeof(double)); }
565  Dvctr (long s, const double *src) : Xvctr (s) { SRCCHCK; a = new double[asize]; memcpy (a, src, size*sizeof(double)); }
566  Dvctr ( const VectoR *src) : Xvctr (3) { SRCCHCK; a = new double[asize]; a[0]=src->x; a[1]=src->y; a[2]=src->z; }
568  virtual ~Dvctr() { deshift(); if (a && !exta) delete [] a; }
569 
571  arrayTypedef give_arrayTypedef (void) const { return ATdouble; }
572 
573  // *** OPERATORS ***
574  double operator[] (long i) const {
575 #ifdef DEBUG
576  if (i<0 || i>=size) _errorr ("i out of the range");
577 #endif
578  return a[i];
579  }
580  double& operator[] (long i) {
581 #ifdef DEBUG
582  if (i<0 || i>=size)
583  _errorr ("i out of the range");
584 #endif
585  return a[i];
586  }
587 
588 
589  // *** SET ***
590  Dvctr* free (void);
591  void realloc (long newsize);
592  // resize, keep values
593  Dvctr* resize_preserve_vals (long newsize) { AVOID_CNST; AVOID_EXTA; this->realloc (newsize); size = newsize; return this; }
594  // resize, ignore values
596  //AVOID_EXTA;
597  if (exta)
598  _errorr("exta");
599  size = 0; this->realloc (newsize); size = newsize; return this; }
600  // resize, ignore values
601  Dvctr* resize_to_asize (void) { AVOID_CNST; AVOID_EXTA; size = asize; return this; }
602  //Dvctr* resizeup (long newsize) { AVOID_CNST; AVOID_EXTA; this->reallocup (newsize); size = newsize; }
603  //Dvctr* resizedown (long newsize) { AVOID_CNST; AVOID_EXTA; this->reallocdown(newsize); size = newsize; }
604 
605  Dvctr* assign_array ( double *array, long s);
606  Dvctr* assign_array (const double *array, long s);
608  void cpat (long i, const Xvctr *p, long j) {
609  const Dvctr *pt = dynamic_cast<const Dvctr *>(p);
610  if (!pt) _errorr("");
611  a[i] = pt->a[j];
612  }
613  void shift (long val) { AVOID_CNST; if (a) { shft += val; a += val; } }
614  bool scan (const char *&src) { return SP_scan_array (src, size, a); }
615 
616  // *** GET ***
618  double* give_ptr2val (long i=0) { AVOID_CNST; return a + i; }
619  const double* give_ptr2val (long i=0) const { return a + i; }
620 
621 
622  // *** COMPUTE ***
623  double give_lenght (void) const;
624  double give_sum (void) const;
625  long give_number_of_nonzeros (void) const;
626 
627 
628  // *** EDIT ***
630  void zero (void) { AVOID_CNST; memset (a,0,size*sizeof(double)); }
632  void beCopyOf (const PoinT &src) { this->resize_ignore_vals(3); a[0] = src.x; a[1] = src.y; a[2] = src.z; }
633  void beCopyOf (const double *src) { AVOID_CNST; memcpy (a, src, size*sizeof(double)); }
634  void beCopyOf (const double *src, long s) { this->resize_ignore_vals(s ); memcpy (a, src, size*sizeof(double)); }
635  void beCopyOf (const Dvctr &src) { this->resize_ignore_vals(src. size); memcpy (a, src.a, size*sizeof(double)); }
636  void beCopyOf (const Dvctr *src) { this->resize_ignore_vals(src->size); memcpy (a, src->a, size*sizeof(double)); }
637 
638  void copy_to (double *dest) const { memcpy (dest, a, size*sizeof(double)); }
639 
641  void append (const Dvctr *src) {
642  AVOID_CNST;
643  this->resize_preserve_vals(size + src->size);
644  memcpy (a+size-src->size, src->a, (size-src->size)*sizeof(double));
645  }
646 
648  void be_tnsr (const Dmtrx &src);
650  void be_vectproduct (const Dvctr &v1, const Dvctr &v2);
652  void be_mean_of (const Dmtrx *src);
654  double give_dotproduct (const Dvctr &v);
655 
656 
660  void add (const Dvctr &src); // this += src
661  void addtms (const Dvctr &src, double tms); // this += tms * src
662  void sbt (const Dvctr &src); // this -= src
663  void tmsby (double val);
664  void dvdby (double val);
665 
667  void tnsrRotWith (const Dmtrx &rot);
668  void tnsrRotWith1 (const Dmtrx &rot);
669  void tnsrRotWith2 (const Dmtrx &rot);
671  void tnsrRotAxisZangle (double a);
673  void normalize (void);
675  double give_zero (double abszero, double relzero) const;
678 
679  // *** PRINT ***
680 #ifdef DEBUG
681  virtual void printYourself (bool force) const;
682 #endif
683  //
684  int length_printed (int precision) const;
685  int length_printed_vector (int precision) const;
686  int length_printed_tensor (int precision) const;
687  void print (char *stream, int precision, double absZero=0.0 ) const;
688  void print_vector (char *stream, int precision, double absZero=0.0, bool zerorest=false) const;
689  void print_symtensor (char *stream, int precision, double absZero=0.0, bool zerorest=false) const;
690  void print_symtensor (FILE *stream, int precision, double absZero=0.0, bool zerorest=false) const;
691 
692 // void print_vector (char *stream, int precision) const;
693 // void print_vector_or_zero (char *stream, int precision) const;
694 // void print_vector_zerorest (char *stream, int precision) const;
695 // void print_member (char *stream, int precision, long i) const { sprintf (stream, "% .*e", precision, a[i]); }
696 // //
697 // void print_symtensor (FILE *stream, int precision) const;
698 // void print_symtensor_zero (FILE *stream, int precision) const;
699 // void print_r2z_symtensor (FILE *stream, int precision, double relZero, double absZero) const;
700 // void print_symtensor (char *stream, int precision) const;
701 // void print_symtensor_zero (char *stream, int precision) const;
702 // void print_r2z_symtensor (char *stream, int precision, double relZero, double absZero) const;
703 };
704 
705 
706 
707 
708 
709 // ********************************************************************************************
710 // *** *** *** *** CLASS XMTRX *** *** *** ***
711 // ********************************************************************************************
712 class Xmtrx : public Array
713 {
714  protected:
715  long crow; // count of rows
716  long ccol; // count of collumns
717  long asize; // length of the allocated array
718 
719  public:
721  Xmtrx (void) : Array() { crow = 0; ccol = 0; asize = crow*ccol; }
722  Xmtrx (long r, long c) : Array() { crow = r; ccol = c; asize = crow*ccol; }
724  virtual ~Xmtrx() { }
725 
726  // *** SET ***
727  // *** GET ***
728  long give_crows (void) const { return crow; }
729  long give_ccols (void) const { return ccol; }
730 };
731 
732 
733 
734 // ********************************************************************************************
735 // *** *** *** *** CLASS LMTRX *** *** *** ***
736 // ********************************************************************************************
737 class Lmtrx : public Xmtrx
738 {
739  public:
740  long *a; // array of values
741 
743  Lmtrx (void) : Xmtrx() { a = NULL; }
744  Lmtrx (long r, long c) : Xmtrx(r,c) { a = new long[asize]; }
746  virtual ~Lmtrx() { if (a) delete [] a; }
747 
748  arrayTypedef give_arrayTypedef (void) const { return ATlong; }
749 
750  // *** SET ***
751  void resize_ignore_vals (long r, long c);
752 
753  // *** GET ***
754  long &operator()(long r, long c) { return a[r*ccol + c]; }
755  const long &operator()(long r, long c) const { return a[r*ccol + c]; }
757  long* give_ptr2val (long r=0, long c=0) { return a + r*ccol + c; }
758  const long* give_ptr2val (long r=0, long c=0) const { return a + r*ccol + c; }
759 
760  // *** PRINT ***
761 #ifdef DEBUG
762  virtual void printYourself (bool force=false) const;
763 #endif
764 
765 };
766 
767 
768 // ********************************************************************************************
769 // *** *** *** *** CLASS DMTRX *** *** *** ***
770 // ********************************************************************************************
771 class Dmtrx : public Xmtrx
772 {
773  protected:
774  double *a; // array of values
775 
776  public:
778  Dmtrx (void) : Xmtrx() { a = NULL; }
779  Dmtrx (long r, long c) : Xmtrx(r,c) { a = new double[asize]; }
780  Dmtrx ( const Dmtrx *src) : Xmtrx(src->crow,src->ccol) { SRCCHCK; a = new double[asize]; memcpy (a, src->a, crow*ccol*sizeof(double)); }
782  virtual ~Dmtrx() { delete [] a; }
783 
784  arrayTypedef give_arrayTypedef (void) const { return ATdouble; }
785 
786  // *** SET ***
787  void resize_ignore_vals (long r, long c);
788 
789  // *** GET ***
790  double &operator()(long r, long c) { return a[r*ccol + c]; }
791  const double &operator()(long r, long c) const { return a[r*ccol + c]; }
793  double* give_ptr2val (long r=0, long c=0) { return a + r*ccol + c; }
794  const double* give_ptr2val (long r=0, long c=0) const { return a + r*ccol + c; }
795 
796 
797  // *** EDIT ***
799  void zero (void) { memset (a, 0, crow*ccol*sizeof(double)); }
801 # ifndef DEBUG
802  void copy_row (long r, const Dvctr &v) { if (ccol != v.give_size()) _errorr("size mismatch"); memcpy (a + r*ccol, v.give_ptr2val(), ccol*sizeof(double)); }
803 # else
804  void copy_row (long r, const Dvctr &v) { memcpy (a + r*ccol, v.give_ptr2val(), ccol*sizeof(double)); }
805 # endif
806  void copy_row (long r, const Elem3D *v) { a[r*ccol] = v->x; a[r*ccol+1] = v->y; a[r*ccol+2] = v->z; }
808  void beCopyOf (const double *src) { memcpy (a, src, crow*ccol*sizeof(double)); }
809  void beCopyOf (const Dmtrx &src) { this->beCopyOf(src. give_ptr2val(0,0)); }
810  void beCopyOf (const Dmtrx *src) { this->beCopyOf(src->give_ptr2val(0,0)); }
812  void be_tnsr (const Dvctr &src);
813  void be_transposition (const Dmtrx &src);
814  void be_mtrxMmtrx (const Dmtrx &A, const Dmtrx &B);
815  void tmsLeftBy (const Dmtrx &src);
816  void tmsRightBy (const Dmtrx &src);
817 
818  // *** COMPUTE ***
819  double give_determinant (void) const;
821  bool GaussSolve (Dvctr &x, const Dvctr &rhs);
822  bool GaussSolve (Dvctr *x, const Dvctr *rhs, long nrhs);
823 
824  // *** PRINT ***
825 #ifdef DEBUG
826  virtual void printYourself (bool force=false) const;
827 #endif
828  //void print_tensor (FILE *stream, int precision) const;
829  void print_tensor (FILE *stream, int precision, double absZero, bool zerorest) const;
830 
831 };
832 
833 
834 } // namespace midaspace
835 
836 #endif // MIDAS_ARRAYS_H
Lvctr * free(void)
Definition: arrays.cpp:131
arrayClassType give_classid() const
Definition: arrays.h:341
virtual void print_symtensor(char *stream, int precision, double absZero=0.0, bool zerorest=false) const =0
bool is_parallel_with(const VectoR *that, double relZero) const
Definition: arrays.h:191
double & at32()
Definition: arrays.h:238
Lvctr * resize_preserve_vals(long newsize)
resize, keep values
Definition: arrays.h:470
Dvctr(long s)
Definition: arrays.h:563
virtual ~Dvctr()
DESTRUCTOR.
Definition: arrays.h:568
void beCopyOf(const double *src)
Definition: arrays.h:808
virtual ~Array()
DESTRUCTOR.
Definition: arrays.h:280
Xvctr(long s)
CONSTRUCTOR.
Definition: arrays.h:374
#define _warningg(_1)
Definition: gelib.h:154
virtual double give_lenght(void) const =0
virtual void print(char *stream, int precision, double absZero=0.0) const =0
VectoR * normalize(void)
Definition: arrays.h:185
Elem3D * round2abszero(double zr)
Definition: arrays.h:65
long * give_ptr2val(long r=0, long c=0)
Definition: arrays.h:757
long * a
Array of values.
Definition: arrays.h:411
virtual void print_vector(char *stream, int precision, double absZero=0.0, bool zerorest=false) const =0
double & operator()(long r, long c)
Definition: arrays.h:790
virtual ~Dmtrx()
DESTRUCTOR.
Definition: arrays.h:782
Dvctr * resize_preserve_vals(long newsize)
Definition: arrays.h:593
double dist2_to(const PoinT *p) const
Definition: arrays.h:102
Lvctr & operator=(const Lvctr &src)
Definition: arrays.h:445
int length_printed_vector(int precision) const
Definition: arrays.cpp:157
bool GaussSolve(Dvctr &x, const Dvctr &rhs)
gaussian eliminatio
Definition: arrays.cpp:811
int length_printed(int precision) const
void round2zero (double zero, double absZero);
Definition: arrays.cpp:510
void tmsLeftBy(const Dmtrx &src)
Definition: arrays.cpp:776
bool scan_z(FILE *stream)
Definition: arrays.h:70
const long * give_ptr2val(long r=0, long c=0) const
Definition: arrays.h:758
Array()
CONSTRUCTOR.
Definition: arrays.h:278
virtual ~Elem3D()
Definition: arrays.h:36
double give_zero(double abszero, double relzero) const
Definition: arrays.cpp:85
int length_printed(int precision) const
Definition: arrays.cpp:156
virtual long give_size(void) const =0
bool is_identical_to(const Elem3D *p, double zero) const
Definition: arrays.h:55
General functions.
virtual bool scan(const char *&src)=0
void dvdby(double val)
Definition: arrays.cpp:384
void copy_to_col_1(const VectoR *v)
Definition: arrays.h:248
Lmtrx(void)
CONSTRUCTOR.
Definition: arrays.h:743
double give_dotproduct(const Dvctr &v)
Definition: arrays.cpp:369
int length_printed_tensor(int precision) const
Definition: arrays.cpp:512
double & at33()
Definition: arrays.h:239
void append(const Dvctr *src)
Definition: arrays.h:641
const double * give_ptr2val(long i=0) const
Definition: arrays.h:619
void print_tensor(FILE *stream, int precision, double absZero, bool zerorest) const
print yourself
Definition: arrays.cpp:981
double & at22()
Definition: arrays.h:235
Input / output function.
long give_size(void) const
Definition: arrays.h:324
void realloc(long newsize)
reallocate up receiver
Definition: arrays.cpp:248
double & at11()
Definition: arrays.h:231
virtual int length_printed_tensor(int precision) const =0
double give_sum(void) const
sum of components
Definition: arrays.h:82
Dvctr * resize_to_asize(void)
Definition: arrays.h:601
virtual int length_printed_vector(int precision) const =0
void copy_to_row_1(const VectoR *v)
Definition: arrays.h:244
void shift(long val)
Definition: arrays.h:484
Lvctr(const Lvctr *p)
Definition: arrays.h:417
void print_vector(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
Definition: arrays.cpp:186
void be_mtrxMmtrx(const Dmtrx &A, const Dmtrx &B)
Definition: arrays.cpp:757
bool SP_skip_word(const char *&src, int n)
... word and space before
Definition: librw.cpp:472
arrayTypedef give_arrayTypedef(void) const
Definition: arrays.h:784
void beRotatedPoint(const Dmtrx *rot, const PoinT *point)
Receiver will be point 'point' rotated by matrix 'rot'. this = rot . point.
Definition: arrays.cpp:60
virtual long give_size(void) const
Definition: arrays.h:387
void normalize(void)
Definition: arrays.cpp:466
long is_member_of_array(ArgType val, long n, const ArgType *array)
check out "val" is member of "array"
Definition: gelib.h:311
Dscal(double val)
Definition: arrays.h:337
void zero(void)
Definition: arrays.h:504
void realloc(long newsize)
reallocate up receiver
Definition: arrays.cpp:97
double & at23()
Definition: arrays.h:236
#define NUM_DIGITS_IN_PRINTED_EXPONENT
Definition: gelib.h:31
void tmsRightBy(const Dmtrx &src)
Definition: arrays.cpp:784
arrayClassType give_classid() const
Definition: arrays.h:423
virtual ~Lvctr()
DESTRUCTOR.
Definition: arrays.h:420
Lvctr * assign_array(long *array, long s)
Definition: arrays.cpp:111
bool is_identical_to(const Elem3D *p) const
Definition: arrays.h:56
void bePointAtAbscissa(const PoinT *p1, const PoinT *p2, double ksi)
receiver will be point at abscissa p1p2 with natural coord ksi
Definition: arrays.h:107
double * d() const
Definition: arrays.h:133
Lvctr(void)
CONSTRUCTOR.
Definition: arrays.h:415
VectoR * beVectProduct(const PoinT *p1, const PoinT *p2, const PoinT *p3)
vector product p1p2 x p1p3
Definition: arrays.h:167
Xmtrx(long r, long c)
Definition: arrays.h:722
virtual arrayTypedef give_arrayTypedef(void) const =0
void copy_to_row_2(const VectoR *v)
Definition: arrays.h:245
Lmtrx(long r, long c)
Definition: arrays.h:744
arrayTypedef give_arrayTypedef(void) const
Definition: arrays.h:748
double dist_to_line(const PoinT *p1, const PoinT *p2) const
give distance from receiver to line defined by p1 and p2
Definition: arrays.h:214
virtual ~MatriX()
Definition: arrays.h:229
double give_sum(void) const
Definition: arrays.cpp:304
long operator[](long i) const
Definition: arrays.h:428
double give_length(void) const
Definition: arrays.h:188
bool scan_x(FILE *stream)
Definition: arrays.h:68
bool scan(const char *&src)
Definition: arrays.h:485
double give_determinant(void) const
Definition: arrays.cpp:797
void be_transposition(const Dmtrx &src)
Definition: arrays.cpp:745
Elem3D * zero(void)
Definition: arrays.h:64
void resize_ignore_vals(long r, long c)
print yourself
Definition: arrays.cpp:711
void sbt(const Dvctr &src)
Definition: arrays.cpp:382
double & at12()
Definition: arrays.h:232
virtual ~Lmtrx()
DESTRUCTOR.
Definition: arrays.h:746
virtual ~Xmtrx()
DESTRUCTOR.
Definition: arrays.h:724
#define AVOID_CNST
Definition: arrays.h:264
virtual int length_printed(int precision) const =0
void be_vectproduct(const Dvctr &v1, const Dvctr &v2)
Definition: arrays.cpp:333
virtual arrayClassType give_classid() const =0
void zero(void)
Definition: arrays.h:630
arrayTypedef give_arrayTypedef(void) const
Definition: arrays.h:571
bool isZero(double zero, double a)
Definition: mathlib.cpp:308
#define SRCCHCK
Definition: arrays.h:263
Dvctr * resize_ignore_vals(long newsize)
Definition: arrays.h:595
void beCopyOf(const PoinT &src)
Definition: arrays.h:632
long give_sum(void) const
Definition: arrays.cpp:148
bool scan_xyz(const char *&src)
Definition: arrays.h:72
arrayTypedef
Definition: arrays.h:270
double operator[](int i) const
Definition: arrays.h:40
Lvctr * resize_to_asize(void)
resize to asize
Definition: arrays.h:474
void tnsrRotWith2(const Dmtrx &rot)
#define AVOID_EXTA
Definition: arrays.h:265
Elem3D * tms(double val)
Definition: arrays.h:59
arrayClassType
Definition: arrays.h:269
void print_vector(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
Definition: arrays.cpp:545
void print(char *stream, int precision, double absZero=0.0) const
Definition: arrays.cpp:530
double & at21()
Definition: arrays.h:234
void be_tnsr(const Dvctr &src)
Definition: arrays.cpp:729
void copy_to_col_3(const VectoR *v)
Definition: arrays.h:250
void copy_to(double *dest) const
Definition: arrays.h:76
VectoR * beVectProduct(const VectoR *v1, const VectoR *v2)
vector product v1 x v2 (cross product)
Definition: arrays.h:160
Lvctr(long s, const long *p)
Definition: arrays.h:418
arrayTypedef give_arrayTypedef(void) const
Definition: arrays.h:424
virtual int length_printed(int precision) const
Definition: arrays.h:352
double give_lenght(void) const
Definition: arrays.cpp:292
void beCopyOf(const Dvctr &src)
Definition: arrays.h:635
bool scan_xyz(FILE *stream)
Definition: arrays.h:71
Array1d()
CONSTRUCTOR.
Definition: arrays.h:301
Dvctr * free(void)
Definition: arrays.cpp:283
Dvctr(void)
CONSTRUCTOR.
Definition: arrays.h:562
void print(char *stream, int precision, double absZero=0.0) const
Definition: arrays.cpp:176
void copy_row(long r, const Dvctr &v)
Definition: arrays.h:802
void beCopyOf(const double *src)
Definition: arrays.h:633
void resize_ignore_vals(long r, long c)
Definition: arrays.cpp:665
Lvctr * resize_ignore_vals(long newsize)
resize, ignore values
Definition: arrays.h:472
double give_lenght(void) const
Definition: arrays.cpp:140
bool scan_y(FILE *stream)
Definition: arrays.h:69
void tnsrRotWith1(const Dmtrx &rot)
void add(const Dvctr &src)
Definition: arrays.cpp:380
void rotate(Dvctr *v) const
Definition: arrays.cpp:30
#define _errorr(_1)
Definition: gelib.h:151
bool scan(const char *&src)
Definition: arrays.h:614
void zero(void)
Definition: arrays.h:799
void add(long val)
add value to size++ position
Definition: arrays.h:460
Dmtrx(void)
CONSTRUCTOR.
Definition: arrays.h:778
void deshift(void)
Definition: arrays.h:383
Xscal()
CONSTRUCTOR.
Definition: arrays.h:320
Mathematic functions.
Dvctr * assign_array(double *array, long s)
Definition: arrays.cpp:262
virtual void print(char *stream, int precision, double absZero=0.0) const
Definition: arrays.cpp:77
virtual ~Array1d()
DESTRUCTOR.
Definition: arrays.h:303
void be_mean_of(const Dmtrx *src)
Definition: arrays.cpp:350
double a[9]
Definition: arrays.h:226
int length_printed_tensor(int precision) const
Definition: arrays.cpp:158
virtual void cpat(long i, const Xvctr *p, long j)=0
double * a
Definition: arrays.h:559
long give_number_of_nonzeros(void) const
Definition: arrays.cpp:149
long & operator()(long r, long c)
Definition: arrays.h:754
virtual ~Xscal()
DESTRUCTOR.
Definition: arrays.h:322
double dist_to(const PoinT *p) const
Definition: arrays.h:101
void tnsrRotAxisZangle(double a)
rotate coord system around axis z by angle
Definition: arrays.cpp:442
double operator()(void) const
Definition: arrays.h:345
Elem3D * add(const Elem3D *p)
Definition: arrays.h:61
void tnsrRotWith(const Dmtrx &rot)
this = rot * this * rot^transp
Definition: arrays.cpp:413
void copy_to(double *dest) const
Definition: arrays.h:638
Dvctr(const Dvctr *src)
Definition: arrays.h:564
void be_tnsr(const Dmtrx &src)
Definition: arrays.cpp:315
double * give_ptr2val(long r=0, long c=0)
Definition: arrays.h:793
Dmtrx(const Dmtrx *src)
Definition: arrays.h:780
void shift(long val)
Definition: arrays.h:613
void fillYourselfBy(long val)
Set all elements of the array to the given value.
Definition: arrays.h:487
Elem3D * copy(const Elem3D *p)
Definition: arrays.h:63
void beCopyOf(const Dmtrx &src)
Definition: arrays.h:809
arrayClassType give_classid() const
Definition: arrays.h:570
Dscal(void)
CONSTRUCTOR.
Definition: arrays.h:336
bool SP_scan_array(const char *&src, int n, ArgType *a)
... array of numbers
Definition: librw.h:233
VectoR * beP2P(const PoinT *p1, const PoinT *p2)
Receiver is set to vector from p1 to p2, i.e. 'this = p2 - p1'.
Definition: arrays.h:153
long give_number_of_zeros(void) const
Definition: arrays.cpp:150
void cpat(long i, const Xvctr *p, long j)
Definition: arrays.h:608
double & at13()
Definition: arrays.h:233
arrayTypedef give_arrayTypedef(void) const
Definition: arrays.h:342
double * a
Definition: arrays.h:774
double * give_ptr2val(long i=0)
return pointer to
Definition: arrays.h:618
virtual ~Xvctr()
DESTRUCTOR.
Definition: arrays.h:376
Lvctr(long s)
Definition: arrays.h:416
long give_number_of_nonzeros(void) const
virtual ~Dscal()
DESTRUCTOR.
Definition: arrays.h:339
long * give_ptr2val(long i=0)
return pointer to
Definition: arrays.h:491
bool scan_xyz(const double *src)
Definition: arrays.h:73
void addtms(const Dvctr &src, double tms)
Definition: arrays.cpp:381
void print_symtensor(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
Definition: arrays.cpp:598
Dmtrx(long r, long c)
Definition: arrays.h:779
void beCopyOf(const Dvctr *src)
Definition: arrays.h:636
const double & operator()(long r, long c) const
Definition: arrays.h:791
void print_symtensor(char *stream, int precision, double absZero=0.0, bool zerorest=false) const
Definition: arrays.cpp:224
virtual void shift(long val)=0
double giveScalProduct(const Elem3D *v) const
scalar product this * e
Definition: arrays.h:80
Elem3D * dvd(double val)
Definition: arrays.h:60
void beCopyOf(const Dmtrx *src)
Definition: arrays.h:810
const long * give_ptr2val(long i=0) const
Definition: arrays.h:492
Dvctr(long s, const double *src)
Definition: arrays.h:565
void copy_to_col_2(const VectoR *v)
Definition: arrays.h:249
PoinT * copy(const PoinT *p)
Definition: arrays.h:99
const double * give_ptr2val(long r=0, long c=0) const
Definition: arrays.h:794
double operator[](long i) const
Definition: arrays.h:574
Xmtrx(void)
CONSTRUCTOR.
Definition: arrays.h:721
long give_ccols(void) const
Definition: arrays.h:729
const long & operator()(long r, long c) const
Definition: arrays.h:755
void add_unique(long val)
add value to size++ position if unique
Definition: arrays.h:462
void copy_to_row_3(const VectoR *v)
Definition: arrays.h:246
Dvctr(const VectoR *src)
Definition: arrays.h:566
void copy_row(long r, const Elem3D *v)
Definition: arrays.h:806
bool is_member(long val) const
Definition: arrays.h:464
#define PYP
Definition: arrays.h:21
VectoR * copy(const VectoR *p)
Definition: arrays.h:150
Elem3D * sub(const Elem3D *p)
Definition: arrays.h:62
double give_zero(double abszero, double relzero) const
VectoR * beVectProduct(const PoinT *p1, const PoinT *p2, const PoinT *p3, const PoinT *p4)
vector product p1p2 x p3p4
Definition: arrays.h:175
int length_printed_vector(int precision) const
Definition: arrays.cpp:511
long give_crows(void) const
Definition: arrays.h:728
void beCopyOf(const double *src, long s)
Definition: arrays.h:634
double & at31()
Definition: arrays.h:237
void tmsby(double val)
Definition: arrays.cpp:391
bool give_ksiAtAbscissa(double zero, double norm, const PoinT *p1, const PoinT *p2, double &ksi) const
compute natural coordinate ksi of receiver at abscissa p1p2 answer: 1(0) = point lays on(out of) absc...
Definition: arrays.h:116
void cpat(long i, const Xvctr *p, long j)
Definition: arrays.h:479