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