| 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 |
char mtbl_cf_math_C[] = "$Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf_math.C,v 1.3 2014/10/13 08:53:08 j_novak Exp $" ; |
| 28 |
|
| 29 |
/* |
| 30 |
* $Id: mtbl_cf_math.C,v 1.3 2014/10/13 08:53:08 j_novak Exp $ |
| 31 |
* $Log: mtbl_cf_math.C,v $ |
| 32 |
* Revision 1.3 2014/10/13 08:53:08 j_novak |
| 33 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 34 |
* |
| 35 |
* Revision 1.2 2014/10/06 15:13:15 j_novak |
| 36 |
* Modified #include directives to use c++ syntax. |
| 37 |
* |
| 38 |
* Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon |
| 39 |
* LORENE |
| 40 |
* |
| 41 |
* Revision 1.3 2000/02/25 10:57:40 eric |
| 42 |
* Suppressions des appels a nettoie(). |
| 43 |
* |
| 44 |
* Revision 1.2 1999/10/29 15:46:20 eric |
| 45 |
* *** empty log message *** |
| 46 |
* |
| 47 |
* Revision 1.1 1999/10/29 15:08:13 eric |
| 48 |
* Initial revision |
| 49 |
* |
| 50 |
* |
| 51 |
* $Header: /cvsroot/Lorene/C++/Source/Mtbl_cf/mtbl_cf_math.C,v 1.3 2014/10/13 08:53:08 j_novak Exp $ |
| 52 |
* |
| 53 |
*/ |
| 54 |
|
| 55 |
// Headers C |
| 56 |
// --------- |
| 57 |
#include <cmath> |
| 58 |
#include <cstdlib> |
| 59 |
|
| 60 |
// Headers Lorene |
| 61 |
// -------------- |
| 62 |
#include "mtbl_cf.h" |
| 63 |
|
| 64 |
|
| 65 |
//----------------// |
| 66 |
// Absolute value // |
| 67 |
//----------------// |
| 68 |
|
| 69 |
namespace Lorene { |
| 70 |
Mtbl_cf abs(const Mtbl_cf& ti) |
| 71 |
{ |
| 72 |
// Protection |
| 73 |
assert(ti.get_etat() != ETATNONDEF) ; |
| 74 |
|
| 75 |
// Cas ETATZERO |
| 76 |
if (ti.get_etat() == ETATZERO) { |
| 77 |
return ti ; |
| 78 |
} |
| 79 |
|
| 80 |
// Cas general |
| 81 |
|
| 82 |
assert(ti.get_etat() == ETATQCQ) ; // sinon... |
| 83 |
|
| 84 |
Mtbl_cf to(ti.get_mg(), ti.base) ; // Mtbl_cf resultat |
| 85 |
|
| 86 |
to.set_etat_qcq() ; |
| 87 |
|
| 88 |
int nzone = ti.get_nzone() ; |
| 89 |
|
| 90 |
for (int l=0 ; l<nzone ; l++) { |
| 91 |
*(to.t[l]) = abs( *(ti.t[l]) ) ; |
| 92 |
} |
| 93 |
|
| 94 |
return to ; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
//-------------------------------// |
| 101 |
// max // |
| 102 |
//-------------------------------// |
| 103 |
|
| 104 |
Tbl max(const Mtbl_cf& mti) { |
| 105 |
|
| 106 |
// Protection |
| 107 |
assert(mti.get_etat() != ETATNONDEF) ; |
| 108 |
|
| 109 |
int nz = mti.get_nzone() ; |
| 110 |
|
| 111 |
Tbl resu(nz) ; |
| 112 |
|
| 113 |
if (mti.get_etat() == ETATZERO) { |
| 114 |
resu.annule_hard() ; |
| 115 |
} |
| 116 |
else { // Cas general |
| 117 |
|
| 118 |
assert(mti.get_etat() == ETATQCQ) ; // sinon.... |
| 119 |
|
| 120 |
resu.set_etat_qcq() ; |
| 121 |
for (int l=0 ; l<nz ; l++) { |
| 122 |
resu.set(l) = max( *(mti.t[l]) ) ; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
return resu ; |
| 127 |
} |
| 128 |
|
| 129 |
//-------------------------------// |
| 130 |
// min // |
| 131 |
//-------------------------------// |
| 132 |
|
| 133 |
Tbl min(const Mtbl_cf& mti) { |
| 134 |
|
| 135 |
// Protection |
| 136 |
assert(mti.get_etat() != ETATNONDEF) ; |
| 137 |
|
| 138 |
int nz = mti.get_nzone() ; |
| 139 |
|
| 140 |
Tbl resu(nz) ; |
| 141 |
|
| 142 |
if (mti.get_etat() == ETATZERO) { |
| 143 |
resu.annule_hard() ; |
| 144 |
} |
| 145 |
else { // Cas general |
| 146 |
|
| 147 |
assert(mti.get_etat() == ETATQCQ) ; // sinon.... |
| 148 |
|
| 149 |
resu.set_etat_qcq() ; |
| 150 |
for (int l=0 ; l<nz ; l++) { |
| 151 |
resu.set(l) = min( *(mti.t[l]) ) ; |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
return resu ; |
| 156 |
} |
| 157 |
|
| 158 |
//-------------------------------// |
| 159 |
// norme // |
| 160 |
//-------------------------------// |
| 161 |
|
| 162 |
Tbl norme(const Mtbl_cf& mti) { |
| 163 |
|
| 164 |
// Protection |
| 165 |
assert(mti.get_etat() != ETATNONDEF) ; |
| 166 |
|
| 167 |
int nz = mti.get_nzone() ; |
| 168 |
|
| 169 |
Tbl resu(nz) ; |
| 170 |
|
| 171 |
if (mti.get_etat() == ETATZERO) { |
| 172 |
resu.annule_hard() ; |
| 173 |
} |
| 174 |
else { // Cas general |
| 175 |
|
| 176 |
assert(mti.get_etat() == ETATQCQ) ; // sinon.... |
| 177 |
|
| 178 |
resu.set_etat_qcq() ; |
| 179 |
for (int l=0 ; l<nz ; l++) { |
| 180 |
resu.set(l) = norme( *(mti.t[l]) ) ; |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
return resu ; |
| 185 |
} |
| 186 |
|
| 187 |
//-------------------------------// |
| 188 |
// diffrel // |
| 189 |
//-------------------------------// |
| 190 |
|
| 191 |
Tbl diffrel(const Mtbl_cf& mt1, const Mtbl_cf& mt2) { |
| 192 |
|
| 193 |
// Protections |
| 194 |
assert(mt1.get_etat() != ETATNONDEF) ; |
| 195 |
assert(mt2.get_etat() != ETATNONDEF) ; |
| 196 |
|
| 197 |
int nz = mt1.get_nzone() ; |
| 198 |
Tbl resu(nz) ; |
| 199 |
|
| 200 |
Mtbl_cf diff = mt1 - mt2 ; |
| 201 |
|
| 202 |
Tbl normdiff = norme(diff) ; |
| 203 |
Tbl norme2 = norme(mt2) ; |
| 204 |
|
| 205 |
assert(normdiff.get_etat() == ETATQCQ) ; |
| 206 |
assert(norme2.get_etat() == ETATQCQ) ; |
| 207 |
|
| 208 |
resu.set_etat_qcq() ; |
| 209 |
for (int l=0; l<nz; l++) { |
| 210 |
if ( norme2(l) == double(0) ) { |
| 211 |
resu.set(l) = normdiff(l) ; |
| 212 |
} |
| 213 |
else{ |
| 214 |
resu.set(l) = normdiff(l) / norme2(l) ; |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
return resu ; |
| 219 |
|
| 220 |
} |
| 221 |
|
| 222 |
//-------------------------------// |
| 223 |
// diffrelmax // |
| 224 |
//-------------------------------// |
| 225 |
|
| 226 |
Tbl diffrelmax(const Mtbl_cf& mt1, const Mtbl_cf& mt2) { |
| 227 |
|
| 228 |
// Protections |
| 229 |
assert(mt1.get_etat() != ETATNONDEF) ; |
| 230 |
assert(mt2.get_etat() != ETATNONDEF) ; |
| 231 |
|
| 232 |
int nz = mt1.get_nzone() ; |
| 233 |
Tbl resu(nz) ; |
| 234 |
|
| 235 |
Tbl max2 = max(abs(mt2)) ; |
| 236 |
|
| 237 |
Mtbl_cf diff = mt1 - mt2 ; |
| 238 |
Tbl maxdiff = max(abs(diff)) ; |
| 239 |
|
| 240 |
assert(maxdiff.get_etat() == ETATQCQ) ; |
| 241 |
assert(max2.get_etat() == ETATQCQ) ; |
| 242 |
|
| 243 |
resu.set_etat_qcq() ; |
| 244 |
for (int l=0; l<nz; l++) { |
| 245 |
if ( max2(l) == double(0) ) { |
| 246 |
resu.set(l) = maxdiff(l) ; |
| 247 |
} |
| 248 |
else{ |
| 249 |
resu.set(l) = maxdiff(l) / max2(l) ; |
| 250 |
} |
| 251 |
} |
| 252 |
|
| 253 |
return resu ; |
| 254 |
|
| 255 |
} |
| 256 |
} |