LORENE
scalar_arithm.C
1/*
2 * Arithmetical operations for class Scalar
3 *
4 */
5
6/*
7 * Copyright (c) 2003-2005 Eric Gourgoulhon & Jerome Novak
8 * Copyright (c) 1999-2001 Philippe Grandclement
9 *
10 * This file is part of LORENE.
11 *
12 * LORENE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU 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 * LORENE 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 General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28
29
30
31/*
32 * $Id: scalar_arithm.C,v 1.11 2016/12/05 16:18:18 j_novak Exp $
33 * $Log: scalar_arithm.C,v $
34 * Revision 1.11 2016/12/05 16:18:18 j_novak
35 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
36 *
37 * Revision 1.10 2014/10/13 08:53:46 j_novak
38 * Lorene classes and functions now belong to the namespace Lorene.
39 *
40 * Revision 1.9 2014/10/06 15:16:15 j_novak
41 * Modified #include directives to use c++ syntax.
42 *
43 * Revision 1.8 2005/11/17 15:30:11 e_gourgoulhon
44 * Added arithmetics with Mtbl.
45 *
46 * Revision 1.7 2004/07/06 13:36:29 j_novak
47 * Added methods for desaliased product (operator |) only in r direction.
48 *
49 * Revision 1.6 2004/02/19 10:55:11 e_gourgoulhon
50 * Treatment of case ETATUN in double*Scalar, double/Scalar and
51 * Scalar/double: added the copy of the spectral bases from the
52 * input to the result.
53 *
54 * Revision 1.5 2003/11/03 22:35:45 e_gourgoulhon
55 * Changed output comment when dzpuis conflict.
56 *
57 * Revision 1.4 2003/10/28 21:34:47 e_gourgoulhon
58 * Corrected treatment of the case ETATUN in operator+=, operator-= and
59 * operator*=.
60 *
61 * Revision 1.3 2003/10/10 15:57:29 j_novak
62 * Added the state one (ETATUN) to the class Scalar
63 *
64 * Revision 1.2 2003/10/01 13:04:44 e_gourgoulhon
65 * The method Tensor::get_mp() returns now a reference (and not
66 * a pointer) onto a mapping.
67 *
68 * Revision 1.1 2003/09/24 15:21:45 j_novak
69 * New version
70 *
71 *
72 * $Header: /cvsroot/Lorene/C++/Source/Tensor/Scalar/scalar_arithm.C,v 1.11 2016/12/05 16:18:18 j_novak Exp $
73 *
74 */
75
76// headers C
77#include <cassert>
78#include <cstdlib>
79
80// headers Lorene
81#include "tensor.h"
82#include "type_parite.h"
83
84 //********************//
85 // OPERATEURS UNAIRES //
86 //********************//
87
88namespace Lorene {
89Scalar operator+(const Scalar & ci) {
90 return ci ;
91}
92
93Scalar operator-(const Scalar & ci) {
94
95 // Cas particulier
96 if ((ci.get_etat() == ETATZERO) || (ci.get_etat() == ETATNONDEF)) {
97 return ci ;
98 }
99
100 // Cas general
101 assert( (ci.get_etat() == ETATQCQ) || (ci.get_etat() == ETATUN)) ;
102 Scalar r(ci.get_mp()) ; // Scalar resultat
103 r.set_etat_qcq() ;
104 r.va = - ci.va ;
105 r.set_dzpuis( ci.get_dzpuis() ) ;
106
107 // Termine
108 return r ;
109}
110
111 //**********//
112 // ADDITION //
113 //**********//
114// Scalar + Scalar
115// ---------
116Scalar operator+(const Scalar & c1, const Scalar & c2) {
117
118 if (c1.get_etat() == ETATNONDEF)
119 return c1 ;
120 if (c2.get_etat() == ETATNONDEF)
121 return c2 ;
122 assert(c1.get_mp() == c2.get_mp()) ;
123
124 // Cas particuliers
125 if (c1.get_etat() == ETATZERO) {
126 return c2 ;
127 }
128 if (c2.get_etat() == ETATZERO) {
129 return c1 ;
130 }
131 if (c1.get_etat() == ETATUN) {
132 return (c2 + double(1)) ;
133 }
134 if (c2.get_etat() == ETATUN) {
135 return (c1 + double(1)) ;
136 }
137 assert(c1.get_etat() == ETATQCQ) ;
138 assert(c2.get_etat() == ETATQCQ) ;
139
140 // Cas general
141
142 if ( c1.dz_nonzero() && c2.dz_nonzero() ) {
143 if ( c1.get_dzpuis() != c2.get_dzpuis() ) {
144 cout << "Operation Scalar + Scalar: dzpuis conflict in the external " << endl;
145 cout << " compactified domain ! " << endl ;
146 abort() ;
147 }
148 }
149
150 Scalar r(c1) ; // Le resultat
151 r.va += c2.va ;
152
153 if (c1.dz_nonzero()) {
154 r.set_dzpuis( c1.get_dzpuis() ) ;
155 }
156 else{
157 r.set_dzpuis( c2.get_dzpuis() ) ;
158 }
159
160 // Termine
161 return r ;
162}
163
164// Scalar + Mtbl
165// -------------
166Scalar operator+(const Scalar& c1, const Mtbl& mi) {
167
168 if ((c1.get_etat() == ETATNONDEF) || (mi.get_etat() == ETATNONDEF)) {
169 cerr << "Undifined state in Scalar + Mtbl !" << endl ;
170 abort() ;
171 }
172
173 // Cas particuliers
174
175 if (mi.get_etat() == ETATZERO) {
176 return c1 ;
177 }
178
179 assert( c1.check_dzpuis(0) ) ;
180
181 Scalar resu(c1) ;
182
183 if (c1.get_etat() == ETATZERO) {
184 resu = mi ;
185 }
186 else {
187 if (c1.get_etat() == ETATUN) {
188 resu = double(1) + mi ;
189 }
190 else{
191 assert(resu.get_etat() == ETATQCQ) ; // sinon ...
192 resu.va = resu.va + mi ;
193 }
194 }
195
196 resu.set_dzpuis(0) ;
197
198 return resu ;
199}
200
201// Mtbl + Scalar
202// -------------
203Scalar operator+(const Mtbl& mi, const Scalar& c1) {
204
205 return c1 + mi ;
206}
207
208// Scalar + double
209// ------------
210Scalar operator+(const Scalar& t1, double x)
211{
212 // Protections
213 assert(t1.get_etat() != ETATNONDEF) ;
214
215 // Cas particuliers
216 if (x == double(0)) {
217 return t1 ;
218 }
219
220 assert( t1.check_dzpuis(0) ) ;
221
222 Scalar resu(t1) ;
223
224 if (t1.get_etat() == ETATZERO) {
225 resu = x ;
226 }
227 else {
228 if (t1.get_etat() == ETATUN) {
229 resu = double(1) + x ;
230 }
231 else{
232 assert(resu.get_etat() == ETATQCQ) ; // sinon ...
233 resu.va = resu.va + x ;
234 }
235 }
236
237 resu.set_dzpuis(0) ;
238
239 return resu ;
240}
241
242// double + Scalar
243// ------------
244Scalar operator+(double x, const Scalar& t1)
245{
246 return t1 + x ;
247}
248
249// Scalar + int
250// ---------
251Scalar operator+(const Scalar& t1, int m)
252{
253 return t1 + double(m) ;
254}
255
256// int + Scalar
257// ---------
258Scalar operator+(int m, const Scalar& t1)
259{
260 return t1 + double(m) ;
261}
262
263
264
265
266
267 //**************//
268 // SOUSTRACTION //
269 //**************//
270
271// Scalar - Scalar
272// ---------
273Scalar operator-(const Scalar & c1, const Scalar & c2) {
274
275 if (c1.get_etat() == ETATNONDEF)
276 return c1 ;
277 if (c2.get_etat() == ETATNONDEF)
278 return c2 ;
279
280 assert(c1.get_mp() == c2.get_mp()) ;
281
282 // Cas particuliers
283 if (c1.get_etat() == ETATZERO) {
284 return -c2 ;
285 }
286 if (c2.get_etat() == ETATZERO) {
287 return c1 ;
288 }
289 if (c1.get_etat() == ETATUN) {
290 return -(c2 - double(1)) ;
291 }
292 if (c2.get_etat() == ETATUN) {
293 return (c1 - double(1)) ;
294 }
295 assert(c1.get_etat() == ETATQCQ) ; // sinon...
296 assert(c2.get_etat() == ETATQCQ) ; // sinon...
297
298 // Cas general
299 if ( c1.dz_nonzero() && c2.dz_nonzero() ) {
300 if ( c1.get_dzpuis() != c2.get_dzpuis() ) {
301 cout << "Operation Scalar - Scalar : dzpuis conflict in the external " << endl;
302 cout << " compactified domain ! " << endl ;
303 abort() ;
304 }
305 }
306
307 Scalar r(c1) ; // Le resultat
308 r.va -= c2.va ;
309
310 if (c1.dz_nonzero()) {
311 r.set_dzpuis( c1.get_dzpuis() ) ;
312 }
313 else{
314 r.set_dzpuis( c2.get_dzpuis() ) ;
315 }
316
317 // Termine
318 return r ;
319}
320
321// Scalar - Mtbl
322// -------------
323Scalar operator-(const Scalar& t1, const Mtbl& mi) {
324
325 // Protections
326 assert(t1.get_etat() != ETATNONDEF) ;
327
328 // Cas particuliers
329 if (mi.get_etat() == ETATZERO) {
330 return t1 ;
331 }
332
333 assert( t1.check_dzpuis(0) ) ;
334
335 Scalar resu(t1) ;
336
337 if (t1.get_etat() == ETATZERO) {
338 resu = - mi ;
339 }
340 else{
341 if (t1.get_etat() == ETATUN) {
342 resu = double(1) - mi ;
343 }
344 else{
345 assert(resu.get_etat() == ETATQCQ) ; // sinon ...
346 resu.va = resu.va - mi ;
347 }
348 }
349 resu.set_dzpuis(0) ;
350
351 return resu ;
352}
353
354// Mtbl - Scalar
355// -------------
356Scalar operator-(const Mtbl& mi, const Scalar& t1) {
357
358 return - (t1 - mi) ;
359}
360
361// Scalar - double
362// ------------
363Scalar operator-(const Scalar& t1, double x)
364{
365 // Protections
366 assert(t1.get_etat() != ETATNONDEF) ;
367
368 // Cas particuliers
369 if (x == double(0)) {
370 return t1 ;
371 }
372
373 assert( t1.check_dzpuis(0) ) ;
374
375 Scalar resu(t1) ;
376
377 if (t1.get_etat() == ETATZERO) {
378 resu = - x ;
379 }
380 else{
381 if (t1.get_etat() == ETATUN) {
382 resu = double(1) - x ;
383 }
384 else{
385 assert(resu.get_etat() == ETATQCQ) ; // sinon ...
386 resu.va = resu.va - x ;
387 }
388 }
389 resu.set_dzpuis(0) ;
390
391 return resu ;
392}
393
394// double - Scalar
395// ------------
396Scalar operator-(double x, const Scalar& t1)
397{
398 return - (t1 - x) ;
399}
400
401// Scalar - int
402// ---------
403Scalar operator-(const Scalar& t1, int m)
404{
405 return t1 - double(m) ;
406}
407
408// int - Scalar
409// ---------
410Scalar operator-(int m, const Scalar& t1)
411{
412 return double(m) - t1 ;
413}
414
415
416
417
418
419
420 //****************//
421 // MULTIPLICATION //
422 //****************//
423
424// Scalar * Scalar
425// ---------
426Scalar operator*(const Scalar& c1, const Scalar& c2) {
427
428
429 // Cas particuliers
430 if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)){
431 return c1 ;
432 }
433 if ((c2.get_etat() == ETATZERO)|| (c2.get_etat() == ETATNONDEF)) {
434 return c2 ;
435 }
436 if (c1.get_etat() == ETATUN)
437 return c2 ;
438
439 if (c2.get_etat() == ETATUN)
440 return c1 ;
441
442 assert(c1.get_etat() == ETATQCQ) ; // sinon...
443 assert(c2.get_etat() == ETATQCQ) ; // sinon...
444
445 // Protection
446 assert( c1.get_mp() == c2.get_mp() ) ;
447
448 // Cas general
449 Scalar r(c1) ; // Le resultat
450 r.va *= c2.va ;
451
452 r.set_dzpuis( c1.get_dzpuis() + c2.get_dzpuis() ) ;
453
454 // Termine
455 return r ;
456}
457
458// Scalar % Scalar (multiplication with desaliasing)
459// -------------------------------------------
460Scalar operator%(const Scalar& c1, const Scalar& c2) {
461
462
463 // Cas particuliers
464 if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)){
465 return c1 ;
466 }
467 if ((c2.get_etat() == ETATZERO)|| (c2.get_etat() == ETATNONDEF)) {
468 return c2 ;
469 }
470 if (c1.get_etat() == ETATUN)
471 return c2 ;
472 if (c2.get_etat() == ETATUN)
473 return c1 ;
474
475 assert(c1.get_etat() == ETATQCQ) ; // sinon...
476 assert(c2.get_etat() == ETATQCQ) ; // sinon...
477
478 // Protection
479 assert(c1.get_mp() == c2.get_mp()) ;
480
481 // Cas general
482 Scalar r( c1.get_mp() ) ; // Le resultat
483 r.set_etat_qcq() ;
484 r.va = c1.va % c2.va ;
485
486 r.set_dzpuis( c1.get_dzpuis() + c2.get_dzpuis() ) ;
487
488 // Termine
489 return r ;
490}
491
492// Scalar | Scalar (multiplication with desaliasing in r)
493// ------------------------------------------------------
494Scalar operator|(const Scalar& c1, const Scalar& c2) {
495
496
497 // Cas particuliers
498 if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)){
499 return c1 ;
500 }
501 if ((c2.get_etat() == ETATZERO)|| (c2.get_etat() == ETATNONDEF)) {
502 return c2 ;
503 }
504 if (c1.get_etat() == ETATUN)
505 return c2 ;
506 if (c2.get_etat() == ETATUN)
507 return c1 ;
508
509 assert(c1.get_etat() == ETATQCQ) ; // sinon...
510 assert(c2.get_etat() == ETATQCQ) ; // sinon...
511
512 // Protection
513 assert(c1.get_mp() == c2.get_mp()) ;
514
515 // Cas general
516 Scalar r( c1.get_mp() ) ; // Le resultat
517 r.set_etat_qcq() ;
518 r.va = c1.va | c2.va ;
519
520 r.set_dzpuis( c1.get_dzpuis() + c2.get_dzpuis() ) ;
521
522 // Termine
523 return r ;
524}
525
526
527// Mtbl * Scalar
528// -------------
529
530Scalar operator*(const Mtbl& mi, const Scalar& c1) {
531
532 // Particular cases
533 if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)) {
534 return c1 ;
535 }
536
537 Scalar r(c1.get_mp()) ;
538 if (c1.get_etat() == ETATUN) {
539 r = mi ;
540 }
541 else {
542 assert(c1.get_etat() == ETATQCQ) ; // sinon...
543
544 // Cas general
545 r.set_dzpuis( c1.get_dzpuis() ) ;
546
547 if ( mi.get_etat() == ETATZERO) {
548 r.set_etat_zero() ;
549 }
550 else {
551 r.set_etat_qcq() ;
552 r.va = mi * c1.va ;
553 }
554 }
555
556 // Termine
557 return r ;
558
559}
560
561// Scalar * Mtbl
562// -------------
563
564Scalar operator*(const Scalar& c1, const Mtbl& mi) {
565
566 return mi * c1 ;
567}
568
569// double * Scalar
570// ------------
571Scalar operator*(double a, const Scalar& c1) {
572
573 // Cas particuliers
574 if ((c1.get_etat() == ETATZERO) || (c1.get_etat() == ETATNONDEF)) {
575 return c1 ;
576 }
577
578 if (a == double(1))
579 return c1 ;
580
581 Scalar r(c1.get_mp()) ;
582 if (c1.get_etat() == ETATUN) {
583 r = a ;
584 r.set_spectral_base(c1.get_spectral_va().get_base()) ;
585 }
586 else {
587 assert(c1.get_etat() == ETATQCQ) ; // sinon...
588
589 // Cas general
590 r.set_dzpuis( c1.get_dzpuis() ) ;
591
592 if ( a == double(0) ) {
593 r.set_etat_zero() ;
594 }
595 else {
596 r.set_etat_qcq() ;
597 r.va = a * c1.va ;
598 }
599 }
600
601 // Termine
602 return r ;
603}
604
605
606// Scalar * double
607// ------------
608Scalar operator*(const Scalar& t1, double x)
609{
610 return x * t1 ;
611}
612
613// Scalar * int
614// ---------
615Scalar operator*(const Scalar& t1, int m)
616{
617 return t1 * double(m) ;
618}
619
620// int * Scalar
621// ---------
622Scalar operator*(int m, const Scalar& t1)
623{
624 return double(m) * t1 ;
625}
626
627
628
629
630
631
632
633 //**********//
634 // DIVISION //
635 //**********//
636
637
638// Scalar / Scalar
639// ---------
640Scalar operator/(const Scalar& c1, const Scalar& c2) {
641
642 // Protections
643 assert(c1.get_etat() != ETATNONDEF) ;
644 assert(c2.get_etat() != ETATNONDEF) ;
645 assert(c1.get_mp() == c2.get_mp()) ;
646
647 // Cas particuliers
648 if (c2.get_etat() == ETATZERO) {
649 cout << "Division by 0 in Scalar / Scalar !" << endl ;
650 abort() ;
651 }
652 if (c1.get_etat() == ETATZERO) {
653 return c1 ;
654 }
655 if (c1.get_etat() == ETATUN)
656 return double(1)/c2 ;
657 if (c2.get_etat() == ETATUN)
658 return c1 ;
659
660 // Cas general
661
662 assert(c1.get_etat() == ETATQCQ) ; // sinon...
663 assert(c2.get_etat() == ETATQCQ) ; // sinon...
664
665 Scalar r(c1.get_mp()) ; // Le resultat
666
667 r.set_etat_qcq() ;
668 r.va = c1.va / c2.va ;
669
670 r.set_dzpuis( c1.get_dzpuis() - c2.get_dzpuis() ) ;
671
672 // Termine
673 return r ;
674}
675
676// Scalar / Mtbl
677// -------------
678Scalar operator/(const Scalar& c1, const Mtbl& mi) {
679
680 if (c1.get_etat() == ETATNONDEF) return c1 ;
681
682 // Cas particuliers
683 if ( mi.get_etat() == ETATZERO ) {
684 cout << "Division by 0 in Scalar / Mtbl !" << endl ;
685 abort() ;
686 }
687 if (c1.get_etat() == ETATZERO) {
688 return c1 ;
689 }
690 Scalar r(c1.get_mp()) ; // Le resultat
691
692 if (c1.get_etat() == ETATUN) {
693 r = double(1) / mi ;
694 }
695 else {
696 assert(c1.get_etat() == ETATQCQ) ; // sinon...
697
698 r.set_etat_qcq() ;
699 r.va = c1.va / mi ;
700
701 r.set_dzpuis( c1.get_dzpuis() ) ;
702 }
703 // Termine
704 return r ;
705}
706
707
708// Mtbl / Scalar
709// -------------
710Scalar operator/(const Mtbl& mi, const Scalar& c2) {
711
712 if (c2.get_etat() == ETATNONDEF)
713 return c2 ;
714
715 if (c2.get_etat() == ETATZERO) {
716 cout << "Division by 0 in Mtbl / Scalar !" << endl ;
717 abort() ;
718 }
719 Scalar r(c2.get_mp()) ; // Le resultat
720 if (c2.get_etat() == ETATUN) {
721 r = mi ;
722 }
723 else {
724 assert(c2.get_etat() == ETATQCQ) ; // sinon...
725
726 r.set_dzpuis( - c2.get_dzpuis() ) ;
727
728 if ( mi.get_etat() == ETATZERO ) {
729 r.set_etat_zero() ;
730 }
731 else {
732 r.set_etat_qcq() ;
733 r.va = mi / c2.va ;
734 }
735 }
736
737 // Termine
738 return r ;
739}
740
741
742// Scalar / double
743// -------------
744Scalar operator/(const Scalar& c1, double x) {
745
746 if (c1.get_etat() == ETATNONDEF)
747 return c1 ;
748
749 // Cas particuliers
750 if ( x == double(0) ) {
751 cout << "Division by 0 in Scalar / double !" << endl ;
752 abort() ;
753 }
754 if (c1.get_etat() == ETATZERO) {
755 return c1 ;
756 }
757 Scalar r(c1.get_mp()) ; // Le resultat
758
759 if (c1.get_etat() == ETATUN) {
760 r = double(1)/x ;
761 r.set_spectral_base(c1.get_spectral_va().get_base()) ;
762 }
763 else {
764 assert(c1.get_etat() == ETATQCQ) ; // sinon...
765
766 r.set_etat_qcq() ;
767 r.va = c1.va / x ;
768
769 r.set_dzpuis( c1.get_dzpuis() ) ;
770 }
771 // Termine
772 return r ;
773}
774
775
776// double / Scalar
777// ------------
778Scalar operator/(double x, const Scalar& c2) {
779
780 if (c2.get_etat() == ETATNONDEF)
781 return c2 ;
782
783 if (c2.get_etat() == ETATZERO) {
784 cout << "Division by 0 in double / Scalar !" << endl ;
785 abort() ;
786 }
787 Scalar r(c2.get_mp()) ; // Le resultat
788 if (c2.get_etat() == ETATUN) {
789 r = x ;
790 r.set_spectral_base(c2.get_spectral_va().get_base()) ;
791 }
792 else {
793 assert(c2.get_etat() == ETATQCQ) ; // sinon...
794
795 r.set_dzpuis( - c2.get_dzpuis() ) ;
796
797 if ( x == double(0) ) {
798 r.set_etat_zero() ;
799 }
800 else {
801 r.set_etat_qcq() ;
802 r.va = x / c2.va ;
803 }
804 }
805
806 // Termine
807 return r ;
808}
809
810
811// Scalar / int
812// ---------
813Scalar operator/(const Scalar& c1, int m) {
814
815 return c1 / double(m) ;
816
817}
818
819
820// int / Scalar
821// ---------
822Scalar operator/(int m, const Scalar& c2) {
823
824 return double(m) / c2 ;
825
826}
827
828 //*******************//
829 // operateurs +=,... //
830 //*******************//
831
832//---------
833// += Scalar
834//---------
835
836void Scalar::operator+=(const Scalar & ci) {
837
838 // Protection
839 assert(mp == &(ci.get_mp()) ) ; // meme mapping
840 if (etat == ETATNONDEF)
841 return ;
842
843 // Cas particulier
844 if (ci.get_etat() == ETATZERO) {
845 return ;
846 }
847
848 if (ci.get_etat() == ETATNONDEF) {
850 return ;
851 }
852
853 // Cas general
854
855
856 if ( dz_nonzero() && ci.dz_nonzero() ) {
857 if ( dzpuis != ci.dzpuis ) {
858 cout << "Operation += Scalar : dzpuis conflict in the external " << endl;
859 cout << " compactified domain ! " << endl ;
860 abort() ;
861 }
862 }
863
864 if (etat == ETATZERO) {
865 (*this) = ci ;
866 }
867 else {
868 va += ci.va ;
869 if (etat == ETATUN) {
870 etat = ETATQCQ ; // since the case ci.etat == ETATZERO
871 } // has been treated above
872
873 assert(etat == ETATQCQ) ;
874
875 if( ci.dz_nonzero() ) {
876 set_dzpuis(ci.dzpuis) ;
877 }
878 }
879 // Menage (a ne faire qu'a la fin seulement)
880 del_deriv() ;
881
882
883}
884
885//---------
886// -= Scalar
887//---------
888
889void Scalar::operator-=(const Scalar & ci) {
890
891 // Protection
892 assert(mp == &(ci.get_mp()) ) ; // meme mapping
893 if (etat == ETATNONDEF)
894 return ;
895
896 // Cas particulier
897 if (ci.get_etat() == ETATZERO) {
898 return ;
899 }
900
901 if (ci.get_etat() == ETATNONDEF) {
903 return ;
904 }
905
906 // Cas general
907 if ( dz_nonzero() && ci.dz_nonzero() ) {
908 if ( dzpuis != ci.dzpuis ) {
909 cout << "Operation -= Scalar : dzpuis conflict in the external " << endl;
910 cout << " compactified domain ! " << endl ;
911 abort() ;
912 }
913 }
914
915
916 if (etat == ETATZERO) {
917 (*this) = -ci ;
918 }
919 else {
920 va -= ci.va ;
921
922 if (etat == ETATUN) {
923 etat = ETATQCQ ; // since the case ci.etat == ETATZERO
924 } // has been treated above
925
926 assert(etat == ETATQCQ) ;
927
928 if( ci.dz_nonzero() ) {
929 set_dzpuis(ci.dzpuis) ;
930 }
931 }
932 // Menage (a ne faire qu'a la fin seulement)
933 del_deriv() ;
934}
935
936//---------
937// *= Scalar
938//---------
939
940void Scalar::operator*=(const Scalar & ci) {
941
942 // Protection
943 assert(mp == &(ci.get_mp()) ) ; // meme mapping
944 if (etat == ETATNONDEF)
945 return ;
946
947 // Cas particulier
948 if (ci.get_etat() == ETATZERO) {
949 set_etat_zero() ;
950 return ;
951 }
952
953 if (etat == ETATZERO) {
954 return ;
955 }
956
957 if (ci.get_etat() == ETATUN) {
958 return ;
959 }
960
961 if (etat == ETATUN) {
962 operator=(ci) ;
963 return ;
964 }
965
966 if (ci.get_etat() == ETATNONDEF) {
968 return ;
969 }
970
971 // Cas general
972
973 assert(etat == ETATQCQ) ; // sinon....
974
975 va *= ci.va ;
976
977 dzpuis += ci.dzpuis ;
978
979 // Menage (a ne faire qu'a la fin seulement)
980 del_deriv() ;
981
982}
983}
Multi-domain array.
Definition mtbl.h:118
int get_etat() const
Gives the logical state.
Definition mtbl.h:277
Tensor field of valence 0 (or component of a tensorial field).
Definition scalar.h:393
virtual void del_deriv() const
Logical destructor of the derivatives.
Definition scalar.C:293
int get_dzpuis() const
Returns dzpuis.
Definition scalar.h:563
void operator=(const Scalar &a)
Assignment to another Scalar defined on the same mapping.
Definition scalar.C:452
bool dz_nonzero() const
Returns true if the last domain is compactified and *this is not zero in this domain.
Definition scalar.C:820
void operator-=(const Scalar &)
-= Scalar
bool check_dzpuis(int dzi) const
Returns false if the last domain is compactified and *this is not zero in this domain and dzpuis is n...
Definition scalar.C:879
void operator+=(const Scalar &)
+= Scalar
virtual void set_etat_zero()
Sets the logical state to ETATZERO (zero).
Definition scalar.C:330
Scalar(const Map &mpi)
Constructor from mapping.
Definition scalar.C:210
const Valeur & get_spectral_va() const
Returns va (read only version).
Definition scalar.h:607
int etat
The logical state ETATNONDEF (undefined), ETATZERO (null), ETATUN (one), or ETATQCQ (ordinary).
Definition scalar.h:402
int get_etat() const
Returns the logical state ETATNONDEF (undefined), ETATZERO (null) or ETATQCQ (ordinary).
Definition scalar.h:560
virtual void set_etat_nondef()
Sets the logical state to ETATNONDEF (undefined).
Definition scalar.C:350
void set_dzpuis(int)
Modifies the dzpuis flag.
Definition scalar.C:814
void operator*=(const Scalar &)
*= Scalar
Valeur va
The numerical value of the Scalar.
Definition scalar.h:411
int dzpuis
Power of r by which the quantity represented by this must be divided in the compactified external d...
Definition scalar.h:409
const Base_val & get_base() const
Return the bases for spectral expansions (member base ).
Definition valeur.h:490
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 &, const Cmp &)
Cmp * Cmp with desaliasing.
Definition cmp_arithm.C:367
Cmp operator+(const Cmp &)
Definition cmp_arithm.C:107
Scalar operator|(const Scalar &, const Scalar &)
Scalar * Scalar with desaliasing only in r.
const Map & get_mp() const
Returns the mapping.
Definition tensor.h:874
const Map *const mp
Mapping on which the numerical values at the grid points are defined.
Definition tensor.h:301
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