| 1 |
/* |
| 2 |
* Methods of class Map_log |
| 3 |
* |
| 4 |
* (see file map.h for documentation) |
| 5 |
* |
| 6 |
*/ |
| 7 |
|
| 8 |
/* |
| 9 |
* Copyright (c) 2004 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 |
char map_log_C[] = "$Header $" ; |
| 31 |
|
| 32 |
/* |
| 33 |
* $Id: map_log.C,v 1.3 2014/10/13 08:53:05 j_novak Exp $ |
| 34 |
* $Log: map_log.C,v $ |
| 35 |
* Revision 1.3 2014/10/13 08:53:05 j_novak |
| 36 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 37 |
* |
| 38 |
* Revision 1.2 2014/10/06 15:13:13 j_novak |
| 39 |
* Modified #include directives to use c++ syntax. |
| 40 |
* |
| 41 |
* Revision 1.1 2004/06/22 08:49:58 p_grandclement |
| 42 |
* Addition of everything needed for using the logarithmic mapping |
| 43 |
* |
| 44 |
* |
| 45 |
* $Header: /cvsroot/Lorene/C++/Source/Map/map_log.C,v 1.3 2014/10/13 08:53:05 j_novak Exp $ |
| 46 |
* |
| 47 |
*/ |
| 48 |
|
| 49 |
// headers C |
| 50 |
#include <cmath> |
| 51 |
|
| 52 |
// headers Lorene |
| 53 |
#include "itbl.h" |
| 54 |
#include "tbl.h" |
| 55 |
#include "coord.h" |
| 56 |
#include "grilles.h" |
| 57 |
#include "map.h" |
| 58 |
|
| 59 |
|
| 60 |
//---------------// |
| 61 |
// Constructeurs // |
| 62 |
//---------------// |
| 63 |
|
| 64 |
// Constructor from a grid |
| 65 |
// ----------------------- |
| 66 |
namespace Lorene { |
| 67 |
Map_log::Map_log (const Mg3d& mgrille, const Tbl& bornes, const Itbl& typevar) : |
| 68 |
Map_radial(mgrille), alpha (mgrille.get_nzone()), beta (mgrille.get_nzone()), |
| 69 |
type_var(typevar) |
| 70 |
|
| 71 |
{ |
| 72 |
// Les bornes |
| 73 |
int nzone = mg->get_nzone() ; |
| 74 |
|
| 75 |
alpha.set_etat_qcq() ; |
| 76 |
beta.set_etat_qcq() ; |
| 77 |
|
| 78 |
for (int l=0 ; l<nzone ; l++) { |
| 79 |
switch (type_var(l)) { |
| 80 |
case AFFINE: { |
| 81 |
switch (mg->get_type_r(l)) { |
| 82 |
case RARE: { |
| 83 |
alpha.set(l) = bornes(l+1) - bornes(l) ; |
| 84 |
beta.set(l) = bornes(l) ; |
| 85 |
break ; |
| 86 |
} |
| 87 |
|
| 88 |
case FIN: { |
| 89 |
alpha.set(l) = (bornes(l+1) - bornes(l)) * .5 ; |
| 90 |
beta.set(l) = (bornes(l+1) + bornes(l)) * .5 ; |
| 91 |
break ; |
| 92 |
} |
| 93 |
|
| 94 |
case UNSURR: { |
| 95 |
double umax = 1./bornes(l) ; |
| 96 |
double umin = 1./bornes(l+1) ; |
| 97 |
alpha.set(l) = (umin - umax) * .5 ; // u est une fonction decroissante |
| 98 |
beta.set(l) = (umin + umax) * .5 ; // de l'indice i en r |
| 99 |
break ; |
| 100 |
} |
| 101 |
|
| 102 |
default: { |
| 103 |
cout << "Map_log::Map_log: unkown type_r ! " << endl ; |
| 104 |
abort () ; |
| 105 |
break ; |
| 106 |
} |
| 107 |
|
| 108 |
} |
| 109 |
break ; |
| 110 |
} |
| 111 |
case LOG:{ |
| 112 |
switch (mg->get_type_r(l)) { |
| 113 |
case FIN: { |
| 114 |
alpha.set(l) = (log(bornes(l+1)) - log(bornes(l))) * .5 ; |
| 115 |
beta.set(l) = (log(bornes(l+1)) + log(bornes(l))) * .5 ; |
| 116 |
break ; |
| 117 |
} |
| 118 |
|
| 119 |
default: { |
| 120 |
cout << "Map_log::Map_log: unkown type_r ! " << endl ; |
| 121 |
abort () ; |
| 122 |
break ; |
| 123 |
} |
| 124 |
} |
| 125 |
break ; |
| 126 |
} |
| 127 |
|
| 128 |
default: { |
| 129 |
cout << "Map_log::Map_log: unkown type_r ! " << endl ; |
| 130 |
abort () ; |
| 131 |
break ; |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
set_coord() ; |
| 137 |
} |
| 138 |
|
| 139 |
Map_log::Map_log (const Map_log& so) : Map_radial (*so.mg), alpha(so.alpha), beta(so.beta), |
| 140 |
type_var(so.type_var) { |
| 141 |
set_coord() ; |
| 142 |
} |
| 143 |
|
| 144 |
|
| 145 |
Map_log::Map_log (const Mg3d& mgrille, FILE* fd) : Map_radial (mgrille, fd), |
| 146 |
alpha (mgrille.get_nzone()), |
| 147 |
beta (mgrille.get_nzone()), |
| 148 |
type_var (mgrille.get_nzone()) { |
| 149 |
Tbl alpha_lu (fd) ; |
| 150 |
Tbl beta_lu (fd) ; |
| 151 |
Itbl type_lu (fd) ; |
| 152 |
|
| 153 |
alpha = alpha_lu ; |
| 154 |
beta = beta_lu ; |
| 155 |
type_var = type_lu ; |
| 156 |
|
| 157 |
set_coord() ; |
| 158 |
} |
| 159 |
|
| 160 |
Map_log::~Map_log() {} |
| 161 |
|
| 162 |
// Sauvegarde : |
| 163 |
void Map_log::sauve(FILE* fd) const { |
| 164 |
|
| 165 |
Map_radial::sauve(fd) ; |
| 166 |
alpha.sauve(fd) ; |
| 167 |
beta.sauve(fd) ; |
| 168 |
type_var.sauve(fd) ; |
| 169 |
} |
| 170 |
|
| 171 |
// Comparison operator : |
| 172 |
bool Map_log::operator==(const Map& mpi) const { |
| 173 |
|
| 174 |
// Precision of the comparison |
| 175 |
double precis = 1e-10 ; |
| 176 |
bool resu = true ; |
| 177 |
|
| 178 |
// Dynamic cast pour etre sur meme Map... |
| 179 |
const Map_log* mp0 = dynamic_cast<const Map_log*>(&mpi) ; |
| 180 |
if (mp0 == 0x0) |
| 181 |
resu = false ; |
| 182 |
else { |
| 183 |
if (*mg != *(mpi.get_mg())) |
| 184 |
resu = false ; |
| 185 |
|
| 186 |
if (fabs(ori_x-mpi.get_ori_x()) > precis) resu = false ; |
| 187 |
if (fabs(ori_y-mpi.get_ori_y()) > precis) resu = false ; |
| 188 |
if (fabs(ori_z-mpi.get_ori_z()) > precis) resu = false ; |
| 189 |
|
| 190 |
if (bvect_spher != mpi.get_bvect_spher()) resu = false ; |
| 191 |
if (bvect_cart != mpi.get_bvect_cart()) resu = false ; |
| 192 |
|
| 193 |
if (diffrelmax (alpha, mp0->alpha) > precis) resu = false ; |
| 194 |
if (diffrelmax (beta, mp0->beta) > precis) resu = false ; |
| 195 |
if (diffrelmax(type_var, mp0->type_var) > precis) resu = false ; |
| 196 |
} |
| 197 |
|
| 198 |
return resu ; |
| 199 |
} |
| 200 |
//------------// |
| 201 |
// Impression // |
| 202 |
//------------// |
| 203 |
|
| 204 |
ostream & Map_log::operator>>(ostream & ost) const { |
| 205 |
|
| 206 |
ost << "Log mapping (class Map_log)" << endl ; |
| 207 |
int nz = mg->get_nzone() ; |
| 208 |
for (int l=0; l<nz; l++) { |
| 209 |
ost << " Domain #" << l << " ; Variable type " ; |
| 210 |
if (type_var(l) == AFFINE) |
| 211 |
ost << "affine : " ; |
| 212 |
if (type_var(l) == LOG) |
| 213 |
ost << "log : " ; |
| 214 |
ost << "alpha_l = " << alpha(l) |
| 215 |
<< " , beta_l = " << beta(l) << endl ; |
| 216 |
} |
| 217 |
|
| 218 |
|
| 219 |
ost << " Coord r : " ; |
| 220 |
for (int l=0; l<nz; l++) { |
| 221 |
int nrm1 = mg->get_nr(l) - 1 ; |
| 222 |
ost << " " << (+r)(l, 0, 0, nrm1) ; |
| 223 |
} |
| 224 |
ost << endl ; |
| 225 |
|
| 226 |
return ost ; |
| 227 |
} |
| 228 |
|
| 229 |
// Affectation to a affine mapping : |
| 230 |
void Map_log::operator=(const Map_af& mpi) { |
| 231 |
|
| 232 |
assert(mpi.get_mg() == mg) ; |
| 233 |
|
| 234 |
set_ori( mpi.get_ori_x(), mpi.get_ori_y(), mpi.get_ori_z() ) ; |
| 235 |
|
| 236 |
set_rot_phi( mpi.get_rot_phi() ) ; |
| 237 |
|
| 238 |
// The members bvect_spher and bvect_cart are treated by the functions |
| 239 |
// set_ori and set_rot_phi. |
| 240 |
|
| 241 |
for (int l=0; l<mg->get_nzone(); l++){ |
| 242 |
alpha.set(l) = mpi.get_alpha()[l] ; |
| 243 |
beta.set(l) = mpi.get_beta()[l] ; |
| 244 |
} |
| 245 |
|
| 246 |
type_var = AFFINE ; |
| 247 |
|
| 248 |
reset_coord() ; |
| 249 |
set_coord() ; |
| 250 |
} |
| 251 |
|
| 252 |
|
| 253 |
//-------------------------------------------------// |
| 254 |
// Assignement of the Coord building functions // |
| 255 |
//-------------------------------------------------// |
| 256 |
|
| 257 |
void Map_log::set_coord(){ |
| 258 |
|
| 259 |
// ... Coord's introduced by the base class Map : |
| 260 |
r.set(this, map_log_fait_r) ; |
| 261 |
tet.set(this, map_log_fait_tet) ; |
| 262 |
phi.set(this, map_log_fait_phi) ; |
| 263 |
sint.set(this, map_log_fait_sint) ; |
| 264 |
cost.set(this, map_log_fait_cost) ; |
| 265 |
sinp.set(this, map_log_fait_sinp) ; |
| 266 |
cosp.set(this, map_log_fait_cosp) ; |
| 267 |
|
| 268 |
x.set(this, map_log_fait_x) ; |
| 269 |
y.set(this, map_log_fait_y) ; |
| 270 |
z.set(this, map_log_fait_z) ; |
| 271 |
|
| 272 |
xa.set(this, map_log_fait_xa) ; |
| 273 |
ya.set(this, map_log_fait_ya) ; |
| 274 |
za.set(this, map_log_fait_za) ; |
| 275 |
|
| 276 |
// ... Coord's introduced by the base class Map_radial : |
| 277 |
xsr.set(this, map_log_fait_xsr) ; |
| 278 |
dxdr.set(this, map_log_fait_dxdr) ; |
| 279 |
drdt.set(this, map_log_fait_drdt) ; |
| 280 |
stdrdp.set(this, map_log_fait_stdrdp) ; |
| 281 |
srdrdt.set(this, map_log_fait_srdrdt) ; |
| 282 |
srstdrdp.set(this, map_log_fait_srstdrdp) ; |
| 283 |
sr2drdt.set(this, map_log_fait_sr2drdt) ; |
| 284 |
sr2stdrdp.set(this, map_log_fait_sr2stdrdp) ; |
| 285 |
d2rdx2.set(this, map_log_fait_d2rdx2) ; |
| 286 |
lapr_tp.set(this, map_log_fait_lapr_tp) ; |
| 287 |
d2rdtdx.set(this, map_log_fait_d2rdtdx) ; |
| 288 |
sstd2rdpdx.set(this, map_log_fait_sstd2rdpdx) ; |
| 289 |
sr2d2rdt2.set(this, map_log_fait_sr2d2rdt2) ; |
| 290 |
|
| 291 |
// ... Coord's introduced by the base Map_log itself |
| 292 |
dxdlnr.set(this, map_log_fait_dxdlnr) ; |
| 293 |
} |
| 294 |
} |