LORENE
arithm_tbl_val.C
1 /*
2  * Methods for making calculations with Godunov-type arrays.
3  *
4  * See the file tbl_val.h for documentation
5  *
6  */
7 
8 /*
9  * Copyright (c) 2001 Jerome Novak
10  *
11  * This file is part of LORENE.
12  *
13  * LORENE is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * LORENE is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with LORENE; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26  *
27  */
28 
29 
30 char ARITHM_TBL_VAL_C[] = "$Header: /cvsroot/Lorene/C++/Source/Valencia/arithm_tbl_val.C,v 1.5 2014/10/13 08:53:48 j_novak Exp $" ;
31 
32 /*
33  * $Id: arithm_tbl_val.C,v 1.5 2014/10/13 08:53:48 j_novak Exp $
34  * $Log: arithm_tbl_val.C,v $
35  * Revision 1.5 2014/10/13 08:53:48 j_novak
36  * Lorene classes and functions now belong to the namespace Lorene.
37  *
38  * Revision 1.4 2003/10/02 07:00:19 e_gourgoulhon
39  * Changed the = signs in some assert's to ==
40  *
41  * Revision 1.3 2002/11/12 10:03:54 j_novak
42  * The method "Tbl_val::get_gval" has been changed to "get_grid".
43  *
44  * Revision 1.2 2002/10/16 14:37:15 j_novak
45  * Reorganization of #include instructions of standard C++, in order to
46  * use experimental version 3 of gcc.
47  *
48  * Revision 1.1 2001/11/22 13:41:54 j_novak
49  * Added all source files for manipulating Valencia type objects and making
50  * interpolations to and from Meudon grids.
51  *
52  *
53  * $Header: /cvsroot/Lorene/C++/Source/Valencia/arithm_tbl_val.C,v 1.5 2014/10/13 08:53:48 j_novak Exp $
54  *
55  */
56 
57 // headers Lorene
58 #include "tbl_val.h"
59 
60  //********************//
61  // OPERATEURS UNAIRES //
62  //********************//
63 
64 // + Tbl_val
65 // -----
66 namespace Lorene {
68 {
69  // Protection
70  assert(t1.get_etat() != ETATNONDEF) ;
71 
72  return t1 ;
73 }
74 
75 // - Tbl_val
76 // -----
78 {
79  // Protection
80  assert(t1.get_etat() != ETATNONDEF) ;
81 
82  // Cas particulier
83  if (t1.get_etat() == ETATZERO) {
84  return t1 ;
85  }
86 
87  // Cas general
88  Tbl_val r(t1.get_grille()) ; // Tbl_val resultat
89  r.set_etat_qcq() ;
90  for (int i=0 ; i<r.get_taille() ; i++)
91  (r.t)[i] = - (t1.t)[i] ;
92 
93  for (int i=0 ; i<r.get_taille_i(0) ; i++)
94  (r.tzri)[i] = - (t1.tzri)[i] ;
95 
96  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
97  (r.txti)[i] = - (t1.txti)[i] ;
98 
99  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
100  (r.typi)[i] = - (t1.typi)[i] ;
101 
102  return r ;
103 }
104 
105  //**********//
106  // ADDITION //
107  //**********//
108 
109 // Tbl_val + Tbl_val
110 // ---------
111 Tbl_val operator+(const Tbl_val& t1, const Tbl_val& t2)
112 {
113 
114  // Protection
115  assert(t1.get_etat() != ETATNONDEF) ;
116  assert(t2.get_etat() != ETATNONDEF) ;
117  assert(t1.get_ndim() == t2.get_ndim()) ;
118  for (int i=0 ; i<t1.get_ndim() ; i++) {
119  assert( t1.get_dim(i) == t2.get_dim(i) ) ;
120  }
121 
122  // Traitement des cas particuliers
123  if (t1.get_etat() == ETATZERO) {
124  return t2 ;
125  }
126  if (t2.get_etat() == ETATZERO) {
127  return t1 ;
128  }
129 
130  // Cas general
131  assert(t1.get_etat() == ETATQCQ) ; // sinon...
132  assert(t2.get_etat() == ETATQCQ) ; // sinon...
133 
134  Tbl_val r(t1) ; // Tbl_val resultat
135  for (int i=0 ; i<r.get_taille() ; i++) {
136  (r.t)[i] += (t2.t)[i] ;
137  }
138  for (int i=0 ; i<r.get_taille_i(0) ; i++)
139  (r.tzri)[i] += (t2.tzri)[i] ;
140 
141  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
142  (r.txti)[i] *= (t2.txti)[i] ;
143 
144  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
145  (r.typi)[i] *= (t2.typi)[i] ;
146 
147 
148  // Termine
149  return r ;
150 }
151 
152 // Tbl_val + double
153 // ------------
154 Tbl_val operator+(const Tbl_val& t1, double x)
155 {
156  // Protection
157  assert(t1.get_etat() != ETATNONDEF) ;
158 
159  // Cas particulier
160  if ( x == double(0) ) {
161  return t1 ;
162  }
163 
164  // Cas general
165  Tbl_val r(t1) ; // Tbl_val resultat
166  r.set_etat_qcq() ;
167  for (int i=0 ; i<r.get_taille() ; i++) {
168  (r.t)[i] += x ;
169  }
170  for (int i=0 ; i<r.get_taille_i(0) ; i++)
171  (r.tzri)[i] += x ;
172 
173  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
174  (r.txti)[i] += x ;
175 
176  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
177  (r.typi)[i] += x;
178 
179  return r ;
180 }
181 
182 // double + Tbl_val
183 // ------------
184 Tbl_val operator+(double x, const Tbl_val& t1)
185 {
186  return t1 + x ;
187 }
188 
189 // Tbl_val + int
190 // ---------
191 Tbl_val operator+(const Tbl_val& t1, int n)
192 {
193  return t1 + double(n) ;
194 }
195 
196 // int + Tbl_val
197 // ---------
198 Tbl_val operator+(int n, const Tbl_val& t1)
199 {
200  return t1 + double(n) ;
201 }
202 
203 
204  //**************//
205  // SOUSTRACTION //
206  //**************//
207 
208 // Tbl_val - Tbl_val
209 // ---------
210 Tbl_val operator-(const Tbl_val& t1, const Tbl_val& t2)
211 {
212 
213  // Protection
214  assert(t1.get_etat() != ETATNONDEF) ;
215  assert(t2.get_etat() != ETATNONDEF) ;
216  assert(t1.get_ndim() == t2.get_ndim()) ;
217  for (int i=0 ; i<t1.get_ndim() ; i++) {
218  assert( t1.get_dim(i) == t2.get_dim(i) ) ;
219  }
220 
221  // Traitement des cas particuliers
222  if (t1.get_etat() == ETATZERO) {
223  return -t2 ;
224  }
225  if (t2.get_etat() == ETATZERO) {
226  return t1 ;
227  }
228 
229  // Cas general
230  assert(t1.get_etat() == ETATQCQ) ; // sinon...
231  assert(t2.get_etat() == ETATQCQ) ; // sinon...
232 
233  Tbl_val r(t1) ; // Tbl_val resultat
234  for (int i=0 ; i<r.get_taille() ; i++) {
235  (r.t)[i] -= (t2.t)[i] ;
236  }
237  for (int i=0 ; i<r.get_taille_i(0) ; i++)
238  (r.tzri)[i] -= (t2.tzri)[i] ;
239 
240  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
241  (r.txti)[i] -= (t2.txti)[i] ;
242 
243  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
244  (r.typi)[i] -= (t2.typi)[i] ;
245 
246 
247  // Termine
248  return r ;
249 }
250 
251 
252 // Tbl_val - double
253 // ------------
254 Tbl_val operator-(const Tbl_val& t1, double x)
255 {
256  // Protection
257  assert(t1.get_etat() != ETATNONDEF) ;
258 
259  // Cas particulier
260  if ( x == double(0) ) {
261  return t1 ;
262  }
263 
264  // Cas general
265  Tbl_val r(t1) ; // Tbl_val resultat
266  r.set_etat_qcq() ;
267  for (int i=0 ; i<r.get_taille() ; i++) {
268  (r.t)[i] -= x ;
269  }
270  for (int i=0 ; i<r.get_taille_i(0) ; i++)
271  (r.tzri)[i] -= x ;
272 
273  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
274  (r.txti)[i] -= x ;
275 
276  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
277  (r.typi)[i] -= x ;
278 
279 
280  return r ;
281 }
282 
283 // Tbl_val - int
284 // ---------
285 Tbl_val operator-(const Tbl_val& t1, int n)
286 {
287  return t1 - double(n) ;
288 }
289 
290 // double - Tbl_val
291 // ------------
292 Tbl_val operator-(double x, const Tbl_val& t1)
293 {
294  // Protection
295  assert(t1.get_etat() != ETATNONDEF) ;
296 
297  // Cas particulier
298  if ( x == double(0) ) {
299  return -t1 ;
300  }
301 
302  // Cas general
303  Tbl_val r(t1) ; // Tbl_val resultat
304  r.set_etat_qcq() ;
305  for (int i=0 ; i<r.get_taille() ; i++) {
306  (r.t)[i] -= x ;
307  }
308  for (int i=0 ; i<r.get_taille_i(0) ; i++)
309  (r.tzri)[i] -= x ;
310 
311  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
312  (r.txti)[i] -= x ;
313 
314  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
315  (r.typi)[i] -= x ;
316 
317  return -r ;
318 }
319 
320 // int - Tbl_val
321 // ---------
322 Tbl_val operator-(int n, const Tbl_val& t1)
323 {
324  return double(n) - t1 ;
325 }
326 
327 //****************//
328 // MULTIPLICATION //
329 //****************//
330 
331 // Tbl_val * Tbl_val
332 // ---------
333 Tbl_val operator*(const Tbl_val& t1, const Tbl_val& t2)
334 {
335  // Protection
336  assert(t1.get_etat() != ETATNONDEF) ;
337  assert(t2.get_etat() != ETATNONDEF) ;
338  assert(t1.get_ndim() == t2.get_ndim()) ;
339  for (int i=0 ; i<t1.get_ndim() ; i++) {
340  assert( t1.get_dim(i) == t2.get_dim(i) ) ;
341  }
342 
343  // Cas particulier
344  if (t1.get_etat() == ETATZERO) {
345  return t1 ;
346  }
347  if (t2.get_etat() == ETATZERO) {
348  return t2 ;
349  }
350 
351  // Cas general
352  assert(t1.get_etat() == ETATQCQ) ; // sinon...
353  assert(t2.get_etat() == ETATQCQ) ; // sinon...
354 
355  Tbl_val r(t1) ;
356  for (int i=0 ; i<r.get_taille() ; i++) {
357  (r.t)[i] *= (t2.t)[i] ;
358  }
359  for (int i=0 ; i<r.get_taille_i(0) ; i++)
360  (r.tzri)[i] *= (t2.tzri)[i] ;
361 
362  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
363  (r.txti)[i] *= (t2.txti)[i] ;
364 
365  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
366  (r.typi)[i] *= (t2.typi)[i] ;
367 
368  // Termine
369  return r ;
370 }
371 
372 // Tbl_val * double
373 // ------------
374 Tbl_val operator*(const Tbl_val& t1, double x)
375 {
376  // Protection
377  assert(t1.get_etat() != ETATNONDEF) ;
378 
379  // Cas particulier
380  if ((t1.get_etat() == ETATZERO) || ( x == double(1) )) {
381  return t1 ;
382  }
383 
384  // Cas general
385  assert(t1.get_etat() == ETATQCQ) ; // sinon...
386 
387  Tbl_val r(t1) ; // Tbl_val resultat
388 
389  if (x == double(0)) {
390  r.set_etat_zero() ;
391  }
392  else {
393  for (int i=0 ; i<r.get_taille() ; i++) {
394  (r.t)[i] *= x ;
395  }
396  for (int i=0 ; i<r.get_taille_i(0) ; i++)
397  (r.tzri)[i] *= x ;
398 
399  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
400  (r.txti)[i] *= x ;
401 
402  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
403  (r.typi)[i] *= x ;
404 
405 
406  }
407 
408  // Termine
409  return r ;
410 }
411 
412 // double * Tbl_val
413 // ------------
414 Tbl_val operator*(double x, const Tbl_val& t1)
415 {
416  return t1 * x ;
417 }
418 
419 // Tbl_val * int
420 // ---------
421 Tbl_val operator*(const Tbl_val& t1, int n)
422 {
423  return t1 * double(n) ;
424 }
425 
426 // int * Tbl_val
427 // ---------
428 Tbl_val operator*(int n, const Tbl_val& t1)
429 {
430  return t1 * double(n) ;
431 }
432 
433 //**********//
434 // DIVISION //
435 //**********//
436 
437 // Tbl_val / Tbl_val
438 // ---------
439 Tbl_val operator/(const Tbl_val& t1, const Tbl_val& t2)
440 {
441  // Protection
442  assert(t1.get_etat() != ETATNONDEF) ;
443  assert(t2.get_etat() != ETATNONDEF) ;
444  assert(t1.get_ndim() == t2.get_ndim()) ;
445  for (int i=0 ; i<t1.get_ndim() ; i++) {
446  assert( t1.get_dim(i) == t2.get_dim(i) ) ;
447  }
448 
449  // Cas particuliers
450  if (t2.get_etat() == ETATZERO) {
451  cout << "Division by 0 in Tbl_val/Tbl_val !" << endl ;
452  abort() ;
453  }
454  if (t1.get_etat() == ETATZERO) {
455  return t1 ;
456  }
457 
458  // Cas general
459  assert(t1.get_etat() == ETATQCQ) ; // sinon...
460  assert(t2.get_etat() == ETATQCQ) ; // sinon...
461 
462  Tbl_val r(t1) ; // Tbl_val resultat
463  for (int i=0 ; i<r.get_taille() ; i++) {
464  (r.t)[i] /= (t2.t)[i] ;
465  }
466  for (int i=0 ; i<r.get_taille_i(0) ; i++)
467  (r.tzri)[i] /= (t2.tzri)[i] ;
468 
469  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
470  (r.txti)[i] /= (t2.txti)[i] ;
471 
472  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
473  (r.typi)[i] /= (t2.typi)[i] ;
474 
475 
476  // Termine
477  return r ;
478 }
479 
480 // Tbl_val / double
481 // ------------
482 Tbl_val operator/(const Tbl_val& t1, double x)
483 {
484  // Protection
485  assert(t1.get_etat() != ETATNONDEF) ;
486  if ( x == double(0) ) {
487  cout << "Division by 0 in Tbl_val/double !" << endl ;
488  abort() ;
489  }
490 
491  // Cas particulier
492  if ((t1.get_etat() == ETATZERO) || ( x == double(1) )) {
493  return t1 ;
494  }
495 
496  // Cas general
497  assert(t1.get_etat() == ETATQCQ) ; // sinon...
498 
499  Tbl_val r(t1) ; // Tbl_val resultat
500  for (int i=0 ; i<r.get_taille() ; i++) {
501  (r.t)[i] /= x ;
502  }
503  for (int i=0 ; i<r.get_taille_i(0) ; i++)
504  (r.tzri)[i] /= x ;
505 
506  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
507  (r.txti)[i] /= x ;
508 
509  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
510  (r.typi)[i] /= x ;
511 
512 
513 
514  return r ;
515 }
516 
517 // Tbl_val / int
518 // ---------
519 Tbl_val operator/(const Tbl_val& t1, int n)
520 {
521  return t1 / double(n) ;
522 }
523 
524 // double / Tbl_val
525 // ------------
526 Tbl_val operator/(double x, const Tbl_val& t1)
527 {
528  // Protection
529  assert(t1.get_etat() != ETATNONDEF) ;
530 
531  // Cas particuliers
532  if (t1.get_etat() == ETATZERO) {
533  cout << "Division by 0 in double/Tbl_val !" << endl ;
534  abort() ;
535  }
536 
537  // Cas general
538  assert(t1.get_etat() == ETATQCQ) ; // sinon...
539 
540  Tbl_val r(t1.get_grille()) ; // Tbl_val resultat, a priori NONDEF
541 
542  if ( x == double(0) ) {
543  r.set_etat_zero() ;
544  }
545  else {
546  r.set_etat_qcq() ;
547  for (int i=0 ; i<r.get_taille() ; i++) {
548  (r.t)[i] = x / (t1.t)[i] ;
549  }
550  for (int i=0 ; i<r.get_taille_i(0) ; i++)
551  (r.tzri)[i] = x / (t1.tzri)[i] ;
552 
553  if (t1.txti != 0x0) for (int i=0 ; i<r.get_taille_i(1) ; i++)
554  (r.txti)[i] = x / (t1.txti)[i] ;
555 
556  if (t1.typi != 0x0) for (int i=0 ; i<r.get_taille_i(2) ; i++)
557  (r.typi)[i] = x / (t1.typi)[i] ;
558 
559 
560  }
561 
562  // Termine
563  return r ;
564 }
565 
566 // int / Tbl_val
567 // ---------
568 Tbl_val operator/(int n, const Tbl_val& t1)
569 {
570  return double(n) / t1 ;
571 }
572 
573 //*******************//
574 // operateurs +=,... //
575 //*******************//
576 
577 void Tbl_val::operator+=(const Tbl_val & ti) {
578 
579  // Protection
580  assert(gval == ti.gval) ;
581  assert(etat != ETATNONDEF) ;
582  assert(ti.get_etat() != ETATNONDEF) ;
583 
584  // Cas particulier
585  if (ti.get_etat() == ETATZERO) {
586  return ;
587  }
588 
589  // Cas general
590  int n = get_taille() ;
591  switch(etat) {
592  case ETATZERO:
593  set_etat_qcq() ;
594  for (int i=0 ; i<n ; i++) {
595  t[i] = ti.t[i] ;
596  }
597  for (int i=0 ; i < get_taille_i(0) ; i++)
598  tzri[i] = ti.tzri[i] ;
599 
600  if (ti.txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
601  txti[i] = ti.txti[i] ;
602 
603  if (ti.typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
604  typi[i] = ti.typi[i] ;
605 
606  break ;
607 
608  case ETATQCQ:
609  for (int i=0 ; i<n ; i++) {
610  t[i] += ti.t[i] ;
611  }
612  for (int i=0 ; i < get_taille_i(0) ; i++)
613  tzri[i] += ti.tzri[i] ;
614 
615  if (ti.txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
616  txti[i] += ti.txti[i] ;
617 
618  if (ti.typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
619  typi[i] += ti.typi[i] ;
620  break ;
621 
622  default:
623  cout << "etat inconnu " << __FILE__ << endl ;
624  abort() ;
625  break ;
626  }
627 
628  // Termine
629 }
630 
631 void Tbl_val::operator+=(double x) {
632 
633  // Protection
634  assert(etat != ETATNONDEF) ;
635 
636  // Cas particulier
637  if ( x == double(0) ) {
638  return ;
639  }
640 
641  // Cas general
642  int n = get_taille() ;
643  switch(etat) {
644  case ETATZERO:
645  set_etat_qcq() ;
646  for (int i=0 ; i<n ; i++) {
647  t[i] = x ;
648  }
649  for (int i=0 ; i < get_taille_i(0) ; i++)
650  tzri[i] = x ;
651 
652  if (txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
653  txti[i] = x ;
654 
655  if (typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
656  typi[i] = x ;
657  break ;
658 
659  case ETATQCQ:
660  for (int i=0 ; i<n ; i++) {
661  t[i] += x ;
662  }
663  for (int i=0 ; i < get_taille_i(0) ; i++)
664  tzri[i] += x ;
665 
666  if (txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
667  txti[i] += x ;
668 
669  if (typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
670  typi[i] += x ;
671 
672  break ;
673 
674  default:
675  cout << "etat inconnu " << __FILE__ << endl ;
676  abort() ;
677  break ;
678  }
679 
680  // Termine
681 }
682 
683 void Tbl_val::operator-=(const Tbl_val & ti) {
684 
685  // Protection
686  assert(gval == ti.gval) ;
687  assert(etat != ETATNONDEF) ;
688  assert(ti.get_etat() != ETATNONDEF) ;
689 
690  // Cas particulier
691  if (ti.get_etat() == ETATZERO) {
692  return ;
693  }
694 
695  // Cas general
696  int n = get_taille() ;
697  switch(etat) {
698  case ETATZERO:
699  set_etat_qcq() ;
700  for (int i=0 ; i<n ; i++) {
701  t[i] = - ti.t[i] ;
702  }
703  for (int i=0 ; i < get_taille_i(0) ; i++)
704  tzri[i] = - ti.tzri[i] ;
705 
706  if (ti.txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
707  txti[i] = - ti.txti[i] ;
708 
709  if (ti.typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
710  typi[i] = - ti.typi[i] ;
711 
712  break ;
713 
714  case ETATQCQ:
715  for (int i=0 ; i<n ; i++) {
716  t[i] -= ti.t[i] ;
717  }
718  for (int i=0 ; i < get_taille_i(0) ; i++)
719  tzri[i] -= ti.tzri[i] ;
720 
721  if (ti.txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
722  txti[i] -= ti.txti[i] ;
723 
724  if (ti.typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
725  typi[i] -= ti.typi[i] ;
726 
727  break ;
728 
729  default:
730  cout << "etat inconnu " << __FILE__ << endl ;
731  abort() ;
732  break ;
733  }
734 
735  // Termine
736 }
737 
738 void Tbl_val::operator-=(double x) {
739 
740  // Protection
741  assert(etat != ETATNONDEF) ;
742 
743  // Cas particulier
744  if ( x == double(0) ) {
745  return ;
746  }
747 
748  // Cas general
749  int n = get_taille() ;
750  switch(etat) {
751  case ETATZERO:
752  set_etat_qcq() ;
753  for (int i=0 ; i<n ; i++) {
754  t[i] = - x ;
755  }
756  for (int i=0 ; i < get_taille_i(0) ; i++)
757  tzri[i] = - x ;
758 
759  if (txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
760  txti[i] = - x ;
761 
762  if (typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
763  typi[i] = - x ;
764 
765  break ;
766 
767  case ETATQCQ:
768  for (int i=0 ; i<n ; i++) {
769  t[i] -= x ;
770  }
771  for (int i=0 ; i < get_taille_i(0) ; i++)
772  tzri[i] -= x ;
773 
774  if (txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
775  txti[i] -= x ;
776 
777  if (typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
778  typi[i] -= x ;
779 
780  break ;
781 
782  default:
783  cout << "etat inconnu " << __FILE__ << endl ;
784  abort() ;
785  break ;
786  }
787 
788  // Termine
789 }
790 
791 void Tbl_val::operator*=(const Tbl_val & ti) {
792 
793  // Protection
794  assert(gval == ti.gval) ;
795  assert(etat != ETATNONDEF) ;
796  assert(ti.get_etat() != ETATNONDEF) ;
797 
798  // Cas particulier
799  if (etat == ETATZERO) {
800  return ;
801  }
802  if (ti.get_etat() == ETATZERO) {
803  set_etat_zero() ;
804  return ;
805  }
806 
807  // Cas general
808  assert(etat == ETATQCQ) ;
809  for (int i=0 ; i<get_taille() ; i++) {
810  t[i] *= ti.t[i] ;
811  }
812  for (int i=0 ; i < get_taille_i(0) ; i++)
813  tzri[i] *= ti.tzri[i] ;
814 
815  if (ti.txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
816  txti[i] *= ti.txti[i] ;
817 
818  if (ti.typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
819  typi[i] *= ti.typi[i] ;
820 
821  // Termine
822 }
823 
824 void Tbl_val::operator*=(double x) {
825 
826  // Protection
827  assert(etat != ETATNONDEF) ;
828 
829  // Cas particulier
830  if ( x == double(0) ) {
831  set_etat_zero() ;
832  return ;
833  }
834  if (etat == ETATZERO) {
835  return ;
836  }
837 
838  // Cas general
839  assert(etat == ETATQCQ) ;
840  for (int i=0 ; i<get_taille() ; i++) {
841  t[i] *= x ;
842  }
843  for (int i=0 ; i < get_taille_i(0) ; i++)
844  tzri[i] *= x ;
845 
846  if (txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
847  txti[i] *= x ;
848 
849  if (typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
850  typi[i] *= x ;
851 
852  // Termine
853 }
854 
855 void Tbl_val::operator/=(const Tbl_val & ti) {
856 
857  // Protection
858  assert(gval == ti.gval) ;
859  assert(etat != ETATNONDEF) ;
860  assert(ti.get_etat() != ETATNONDEF) ;
861 
862  // Cas particulier
863  if (ti.get_etat() == ETATZERO) {
864  cout << "Division by 0 in Tbl_val::operator/=(const Tbl_val &) !" << endl ;
865  abort() ;
866  }
867  if (etat == ETATZERO) {
868  return ;
869  }
870 
871  // Cas general
872  assert(etat == ETATQCQ) ;
873  assert(ti.get_etat() == ETATQCQ) ;
874  int n = get_taille() ;
875  for (int i=0 ; i<n ; i++) {
876  t[i] /= ti.t[i] ;
877  }
878  for (int i=0 ; i < get_taille_i(0) ; i++)
879  tzri[i] /= ti.tzri[i] ;
880 
881  if (ti.txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
882  txti[i] /= ti.txti[i] ;
883 
884  if (ti.typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
885  typi[i] /= ti.typi[i] ;
886 
887  // Termine
888 }
889 
890 void Tbl_val::operator/=(double x) {
891 
892  // Protection
893  assert(etat != ETATNONDEF) ;
894 
895  // Cas particulier
896  if ( x == double(0) ) {
897  cout << "Division by 0 in Tbl_val::operator/=(double ) !" << endl ;
898  abort() ;
899  }
900  if (etat == ETATZERO) {
901  return ;
902  }
903 
904  // Cas general
905  assert(etat == ETATQCQ) ;
906  int n = get_taille() ;
907  for (int i=0 ; i<n ; i++) {
908  t[i] /= x ;
909  }
910  for (int i=0 ; i < get_taille_i(0) ; i++)
911  tzri[i] /= x ;
912 
913  if (txti != 0x0) for (int i=0 ; i < get_taille_i(1) ; i++)
914  txti[i] /= x ;
915 
916  if (typi != 0x0) for (int i=0 ; i < get_taille_i(2) ; i++)
917  typi[i] /= x ;
918 
919  // Termine
920 }
921 
922 }
Lorene prototypes.
Definition: app_hor.h:64
int get_ndim() const
Gives the number of dimensions (ie dim->ndim )
Definition: tbl_val.h:482
Base_val operator*(const Base_val &, const Base_val &)
This operator is used when calling multiplication or division of Valeur .
int etat
logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition: tbl_val.h:103
void operator+=(const Tbl_val &)
Addition of a Tbl_val to this.
Cmp operator/(const Cmp &, const Cmp &)
Cmp / Cmp.
Definition: cmp_arithm.C:457
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl_val.C:294
void operator-=(const Tbl_val &)
Subtraction of a Tbl_val to this.
void operator/=(const Tbl_val &)
Division of this by a Tbl_val.
void operator*=(const Tbl_val &)
Multiplication of this by a Tbl_val.
int get_taille_i(int i) const
Gives the size of the interface arrays (including the hidden cells)
Definition: tbl_val.h:469
Cmp operator+(const Cmp &)
Definition: cmp_arithm.C:104
int get_etat() const
Gives the logical state.
Definition: tbl_val.h:459
void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition: tbl_val.C:280
double * tzri
The array at z (or r) interfaces.
Definition: tbl_val.h:116
Finite-difference array intended to store field values.
Definition: tbl_val.h:97
double * typi
The array at y (or ) interfaces.
Definition: tbl_val.h:120
int get_dim(int i) const
Gives the i th dimension (ie dim->dim[i] , without hidden cells)
Definition: tbl_val.h:485
double * t
The array of double at the nodes.
Definition: tbl_val.h:114
int get_taille() const
Gives the size of the node array (including the hidden cells)
Definition: tbl_val.h:462
Cmp operator-(const Cmp &)
- Cmp
Definition: cmp_arithm.C:108
double * txti
The array at x (or ) interfaces.
Definition: tbl_val.h:118
const Grille_val * gval
The Grille_val (cartesian or spherical) on which the array is defined.
Definition: tbl_val.h:110
const Grille_val * get_grille() const
Returns a pointer on the grid on which the Tbl_val is defined.
Definition: tbl_val.h:491