LORENE
mtbl_cf_arithm.C
1/*
2 * Arithmetical operations for class Mtbl_cf
3 *
4 */
5
6/*
7 * Copyright (c) 1999-2000 Jean-Alain Marck
8 * Copyright (c) 1999-2001 Eric Gourgoulhon
9 * Copyright (c) 1999-2001 Philippe Grandclement
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: mtbl_cf_arithm.C,v 1.5 2016/12/05 16:17:59 j_novak Exp $
34 * $Log: mtbl_cf_arithm.C,v $
35 * Revision 1.5 2016/12/05 16:17:59 j_novak
36 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
37 *
38 * Revision 1.4 2014/10/13 08:53:08 j_novak
39 * Lorene classes and functions now belong to the namespace Lorene.
40 *
41 * Revision 1.3 2014/10/06 15:13:15 j_novak
42 * Modified #include directives to use c++ syntax.
43 *
44 * Revision 1.2 2002/10/16 14:36:43 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.1.1 2001/11/20 15:19:27 e_gourgoulhon
49 * LORENE
50 *
51 * Revision 2.6 2000/09/27 14:25:15 eric
52 * Multiplication par un double : on met le resultat a ETATZERO si x == 0.
53 *
54 * Revision 2.5 2000/08/16 10:43:18 eric
55 * Suppression du membre dzpuis.
56 *
57 * Revision 2.4 1999/10/26 08:09:03 eric
58 * Ajout de protection dzpuis dans +=, -=
59 *
60 * Revision 2.3 1999/10/18 15:07:34 eric
61 * La fonction membre annule() est rebaptisee annule_hard().
62 *
63 * Revision 2.2 1999/10/13 15:50:49 eric
64 * *** empty log message ***
65 *
66 * Revision 2.1 1999/10/01 14:50:14 eric
67 * Ajout des operations manquantes.
68 *
69 * Revision 2.0 1999/06/23 12:36:43 phil
70 * *** empty log message ***
71 *
72 *
73 * $Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf_arithm.C,v 1.5 2016/12/05 16:17:59 j_novak Exp $
74 *
75 */
76
77
78// Fichiers include
79// ----------------
80#include <cmath>
81#include <cassert>
82#include <cstdlib>
83
84#include "mtbl_cf.h"
85
86 //********************//
87 // OPERATEURS UNAIRES //
88 //********************//
89
90// + Mtbl_cf
91// ---------
92namespace Lorene {
94{
95 // Protection
96 assert(t1.get_etat() != ETATNONDEF) ;
97
98 return t1 ;
99}
100
101
102// - Mtbl_cf
103// ---------
105{
106
107 // Protection
108 assert(t1.get_etat() != ETATNONDEF) ;
109
110 // Cas particulier
111 if (t1.get_etat() == ETATZERO) {
112 return t1 ;
113 }
114
115 // Cas general
116 assert(t1.get_etat() == ETATQCQ) ; // sinon...
117 Mtbl_cf r(t1) ; // Mtbl_cf resultat
118
119 for (int i=0 ; i<r.get_nzone() ; i++) {
120 *(r.t)[i] = -(*(t1.t)[i]) ;
121 }
122 return r ;
123}
124
125 //**********//
126 // ADDITION //
127 //**********//
128
129// Mtbl_cf + Mtbl_cf
130// -----------------
131Mtbl_cf operator+(const Mtbl_cf& t1, const Mtbl_cf& t2)
132{
133 // Protection
134 assert(t1.get_etat() != ETATNONDEF) ;
135 assert(t2.get_etat() != ETATNONDEF) ;
136 assert(t1.get_mg() == t2.get_mg()) ;
137 assert(t1.base == t2.base) ;
138
139 // Cas particulier
140 if (t1.get_etat() == ETATZERO) {
141 return t2 ;
142 }
143 if (t2.get_etat() == ETATZERO) {
144 return t1 ;
145 }
146 assert(t1.get_etat() == ETATQCQ) ; // sinon...
147 assert(t2.get_etat() == ETATQCQ) ; // sinon...
148
149 // Cas general
150 int nz = t1.get_nzone() ;
151
152 Mtbl_cf r(t1) ; // Mtbl resultat
153
154 for (int i=0 ; i<nz ; i++) {
155 *(r.t)[i] += *(t2.t)[i] ;
156 }
157
158 return r ;
159}
160
161
162
163 //**************//
164 // SOUSTRACTION //
165 //**************//
166
167// Mtbl_cf - Mtbl_cf
168// -----------------
169Mtbl_cf operator-(const Mtbl_cf& t1, const Mtbl_cf& t2)
170{
171 // Protection
172 assert(t1.get_etat() != ETATNONDEF) ;
173 assert(t2.get_etat() != ETATNONDEF) ;
174 assert(t1.get_mg() == t2.get_mg()) ;
175 assert(t1.base == t2.base) ;
176
177 // Cas particulier
178 if (t1.get_etat() == ETATZERO) {
179 return - t2 ;
180 }
181 if (t2.get_etat() == ETATZERO) {
182 return t1 ;
183 }
184 assert(t1.get_etat() == ETATQCQ) ; // sinon...
185 assert(t2.get_etat() == ETATQCQ) ; // sinon...
186
187 // Cas general
188 int nz = t1.get_nzone() ;
189
190 Mtbl_cf r(t1) ; // Mtbl_cf resultat
191
192 for (int i=0 ; i<nz ; i++) {
193 *(r.t)[i] -= *(t2.t)[i] ;
194 }
195
196 return r ;
197}
198
199
200 //****************//
201 // MULTIPLICATION //
202 //****************//
203
204
205// Mtbl_cf * double
206// ----------------
207Mtbl_cf operator*(const Mtbl_cf& t1, double x) // Mtbl_cf * double
208{
209
210 // Protection
211 assert(t1.get_etat() != ETATNONDEF) ;
212
213 // Cas particulier
214 if ((t1.get_etat() == ETATZERO) || ( x == double(1) )) {
215 return t1 ;
216 }
217
218 // Cas general
219 assert(t1.get_etat() == ETATQCQ) ; // sinon...
220
221 Mtbl_cf r(t1) ; // Mtbl_cf resultat
222
223 if ( x == double(0) ) {
224 r.set_etat_zero() ;
225 }
226 else{
227 int nz = t1.get_nzone() ;
228 for (int i=0 ; i<nz ; i++) {
229 *(r.t)[i] *= x ;
230 }
231 }
232
233 return r ;
234}
235
236// double * Mtbl_cf
237// ----------------
238Mtbl_cf operator*(double x, const Mtbl_cf& t1)
239{
240 return t1 * x ;
241}
242
243// Mtbl_cf * int
244// -------------
245Mtbl_cf operator*(const Mtbl_cf& t1, int m)
246{
247 return t1 * double(m) ;
248}
249
250// int * Mtbl_cf
251// -------------
252Mtbl_cf operator*(int m, const Mtbl_cf& t1)
253{
254 return t1 * double(m) ;
255}
256
257
258 //**********//
259 // DIVISION //
260 //**********//
261
262
263// Mtbl_cf / double
264// ----------------
265Mtbl_cf operator/(const Mtbl_cf& t1, double x)
266{
267
268 // Protection
269 assert(t1.get_etat() != ETATNONDEF) ;
270 if ( x == double(0) ) {
271 cout << "Mtbl_cf division by 0 !" << endl ;
272 abort() ;
273 }
274
275 // Cas particulier
276 if ((t1.get_etat() == ETATZERO) || ( x == double(1) )) {
277 return t1 ;
278 }
279
280 // Cas general
281 assert(t1.get_etat() == ETATQCQ) ; // sinon...
282
283 Mtbl_cf r(t1) ; // Mtbl_cf resultat
284 int nz = t1.get_nzone() ;
285 for (int i=0 ; i<nz ; i++) {
286 *(r.t)[i] /= x ;
287 }
288
289 return r ;
290}
291
292// Mtbl_cf / int
293// -------------
294Mtbl_cf operator/(const Mtbl_cf& t1, int n)
295{
296 return t1/double(n) ;
297}
298
299
300
301 //*******************//
302 // operateurs +=,... //
303 //*******************//
304
305void Mtbl_cf::operator+=(const Mtbl_cf & mi) {
306
307 // Protection
308 assert(mg == mi.get_mg()) ; // meme grille
309 assert(base == mi.base) ; // meme base
310 assert(etat != ETATNONDEF) ; // etat defini
311 assert(mi.get_etat() != ETATNONDEF) ; // etat defini
312
313 // Cas particulier
314 if (mi.get_etat() == ETATZERO) {
315 return ;
316 }
317
318 // Cas general
319
320 if (etat == ETATZERO) {
321 annule_hard() ;
322 }
323 for (int i=0 ; i<nzone ; i++) {
324 *(t[i]) += *(mi.t[i]) ;
325 }
326}
327
328void Mtbl_cf::operator-=(const Mtbl_cf & mi) {
329
330 // Protection
331 assert(mg == mi.get_mg()) ; // meme grille
332 assert(base == mi.base) ; // meme base
333 assert(etat != ETATNONDEF) ; // etat defini
334 assert(mi.get_etat() != ETATNONDEF) ; // etat defini
335
336 // Cas particulier
337 if (mi.get_etat() == ETATZERO) {
338 return ;
339 }
340
341 // Cas general
342
343 if (etat == ETATZERO) {
344 annule_hard() ;
345 }
346 for (int i=0 ; i<nzone ; i++) {
347 *(t[i]) -= *(mi.t[i]) ;
348 }
349}
350
351}
Coefficients storage for the multi-domain spectral method.
Definition mtbl_cf.h:196
Base_val base
Bases of the spectral expansions.
Definition mtbl_cf.h:210
int get_etat() const
Returns the logical state.
Definition mtbl_cf.h:466
const Mg3d * mg
Pointer on the multi-grid Mgd3 on which this is defined.
Definition mtbl_cf.h:202
void operator-=(const Mtbl_cf &)
-= Mtbl_cf
int get_nzone() const
Returns the number of zones (domains).
Definition mtbl_cf.h:469
const Mg3d * get_mg() const
Returns the Mg3d on which the Mtbl_cf is defined.
Definition mtbl_cf.h:463
int etat
Logical state (ETATNONDEF , ETATQCQ or ETATZERO ).
Definition mtbl_cf.h:206
Tbl ** t
Array (size nzone ) of pointers on the Tbl 's which contain the spectral coefficients in each domain.
Definition mtbl_cf.h:215
Mtbl_cf(const Mg3d &mgrid, const Base_val &basis)
Constructor.
Definition mtbl_cf.C:127
void operator+=(const Mtbl_cf &)
+= Mtbl_cf
void annule_hard()
Sets the Mtbl_cf to zero in a hard way.
Definition mtbl_cf.C:315
int nzone
Number of domains (zones).
Definition mtbl_cf.h:204
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