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