LORENE
mtbl_cf_math.C
1/*
2 * Mathematical functions related to the Mtbl_cf class
3 */
4
5/*
6 * Copyright (c) 1999-2001 Eric Gourgoulhon
7 *
8 * This file is part of LORENE.
9 *
10 * LORENE is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * LORENE is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with LORENE; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
25
26
27
28
29/*
30 * $Id: mtbl_cf_math.C,v 1.4 2016/12/05 16:18:00 j_novak Exp $
31 * $Log: mtbl_cf_math.C,v $
32 * Revision 1.4 2016/12/05 16:18:00 j_novak
33 * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
34 *
35 * Revision 1.3 2014/10/13 08:53:08 j_novak
36 * Lorene classes and functions now belong to the namespace Lorene.
37 *
38 * Revision 1.2 2014/10/06 15:13:15 j_novak
39 * Modified #include directives to use c++ syntax.
40 *
41 * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
42 * LORENE
43 *
44 * Revision 1.3 2000/02/25 10:57:40 eric
45 * Suppressions des appels a nettoie().
46 *
47 * Revision 1.2 1999/10/29 15:46:20 eric
48 * *** empty log message ***
49 *
50 * Revision 1.1 1999/10/29 15:08:13 eric
51 * Initial revision
52 *
53 *
54 * $Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf_math.C,v 1.4 2016/12/05 16:18:00 j_novak Exp $
55 *
56 */
57
58// Headers C
59// ---------
60#include <cmath>
61#include <cstdlib>
62
63// Headers Lorene
64// --------------
65#include "mtbl_cf.h"
66
67
68 //----------------//
69 // Absolute value //
70 //----------------//
71
72namespace Lorene {
74{
75 // Protection
76 assert(ti.get_etat() != ETATNONDEF) ;
77
78 // Cas ETATZERO
79 if (ti.get_etat() == ETATZERO) {
80 return ti ;
81 }
82
83 // Cas general
84
85 assert(ti.get_etat() == ETATQCQ) ; // sinon...
86
87 Mtbl_cf to(ti.get_mg(), ti.base) ; // Mtbl_cf resultat
88
89 to.set_etat_qcq() ;
90
91 int nzone = ti.get_nzone() ;
92
93 for (int l=0 ; l<nzone ; l++) {
94 *(to.t[l]) = abs( *(ti.t[l]) ) ;
95 }
96
97 return to ;
98}
99
100
101
102
103 //-------------------------------//
104 // max //
105 //-------------------------------//
106
107Tbl max(const Mtbl_cf& mti) {
108
109 // Protection
110 assert(mti.get_etat() != ETATNONDEF) ;
111
112 int nz = mti.get_nzone() ;
113
114 Tbl resu(nz) ;
115
116 if (mti.get_etat() == ETATZERO) {
117 resu.annule_hard() ;
118 }
119 else { // Cas general
120
121 assert(mti.get_etat() == ETATQCQ) ; // sinon....
122
123 resu.set_etat_qcq() ;
124 for (int l=0 ; l<nz ; l++) {
125 resu.set(l) = max( *(mti.t[l]) ) ;
126 }
127 }
128
129 return resu ;
130}
131
132 //-------------------------------//
133 // min //
134 //-------------------------------//
135
136Tbl min(const Mtbl_cf& mti) {
137
138 // Protection
139 assert(mti.get_etat() != ETATNONDEF) ;
140
141 int nz = mti.get_nzone() ;
142
143 Tbl resu(nz) ;
144
145 if (mti.get_etat() == ETATZERO) {
146 resu.annule_hard() ;
147 }
148 else { // Cas general
149
150 assert(mti.get_etat() == ETATQCQ) ; // sinon....
151
152 resu.set_etat_qcq() ;
153 for (int l=0 ; l<nz ; l++) {
154 resu.set(l) = min( *(mti.t[l]) ) ;
155 }
156 }
157
158 return resu ;
159}
160
161 //-------------------------------//
162 // norme //
163 //-------------------------------//
164
165Tbl norme(const Mtbl_cf& mti) {
166
167 // Protection
168 assert(mti.get_etat() != ETATNONDEF) ;
169
170 int nz = mti.get_nzone() ;
171
172 Tbl resu(nz) ;
173
174 if (mti.get_etat() == ETATZERO) {
175 resu.annule_hard() ;
176 }
177 else { // Cas general
178
179 assert(mti.get_etat() == ETATQCQ) ; // sinon....
180
181 resu.set_etat_qcq() ;
182 for (int l=0 ; l<nz ; l++) {
183 resu.set(l) = norme( *(mti.t[l]) ) ;
184 }
185 }
186
187 return resu ;
188}
189
190 //-------------------------------//
191 // diffrel //
192 //-------------------------------//
193
194Tbl diffrel(const Mtbl_cf& mt1, const Mtbl_cf& mt2) {
195
196 // Protections
197 assert(mt1.get_etat() != ETATNONDEF) ;
198 assert(mt2.get_etat() != ETATNONDEF) ;
199
200 int nz = mt1.get_nzone() ;
201 Tbl resu(nz) ;
202
203 Mtbl_cf diff = mt1 - mt2 ;
204
205 Tbl normdiff = norme(diff) ;
206 Tbl norme2 = norme(mt2) ;
207
208 assert(normdiff.get_etat() == ETATQCQ) ;
209 assert(norme2.get_etat() == ETATQCQ) ;
210
211 resu.set_etat_qcq() ;
212 for (int l=0; l<nz; l++) {
213 if ( norme2(l) == double(0) ) {
214 resu.set(l) = normdiff(l) ;
215 }
216 else{
217 resu.set(l) = normdiff(l) / norme2(l) ;
218 }
219 }
220
221 return resu ;
222
223}
224
225 //-------------------------------//
226 // diffrelmax //
227 //-------------------------------//
228
229Tbl diffrelmax(const Mtbl_cf& mt1, const Mtbl_cf& mt2) {
230
231 // Protections
232 assert(mt1.get_etat() != ETATNONDEF) ;
233 assert(mt2.get_etat() != ETATNONDEF) ;
234
235 int nz = mt1.get_nzone() ;
236 Tbl resu(nz) ;
237
238 Tbl max2 = max(abs(mt2)) ;
239
240 Mtbl_cf diff = mt1 - mt2 ;
241 Tbl maxdiff = max(abs(diff)) ;
242
243 assert(maxdiff.get_etat() == ETATQCQ) ;
244 assert(max2.get_etat() == ETATQCQ) ;
245
246 resu.set_etat_qcq() ;
247 for (int l=0; l<nz; l++) {
248 if ( max2(l) == double(0) ) {
249 resu.set(l) = maxdiff(l) ;
250 }
251 else{
252 resu.set(l) = maxdiff(l) / max2(l) ;
253 }
254 }
255
256 return resu ;
257
258}
259}
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
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
Tbl ** t
Array (size nzone ) of pointers on the Tbl 's which contain the spectral coefficients in each domain.
Definition mtbl_cf.h:215
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition mtbl_cf.C:303
Basic array class.
Definition tbl.h:161
int get_etat() const
Gives the logical state.
Definition tbl.h:394
void annule_hard()
Sets the Tbl to zero in a hard way.
Definition tbl.C:375
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition tbl.C:364
double & set(int i)
Read/write of a particular element (index i) (1D case).
Definition tbl.h:281
Tbl diffrel(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (norme version).
Definition cmp_math.C:507
Tbl norme(const Cmp &)
Sums of the absolute values of all the values of the Cmp in each domain.
Definition cmp_math.C:484
Tbl min(const Cmp &)
Minimum values of a Cmp in each domain.
Definition cmp_math.C:461
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition cmp_math.C:438
Cmp abs(const Cmp &)
Absolute value.
Definition cmp_math.C:413
Tbl diffrelmax(const Cmp &a, const Cmp &b)
Relative difference between two Cmp (max version).
Definition cmp_math.C:542
Lorene prototypes.
Definition app_hor.h:67