LORENE
grille_val.C
1 /*
2  * Methods for the class Grille_val, and its derivative classes.
3  *
4  * See the file grille_val.h for documentation
5  *
6  */
7 
8 /*
9  * Copyright (c) 2001 Jerome Novak
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: grille_val.C,v 1.8 2016/12/05 16:18:19 j_novak Exp $
34  * $Log: grille_val.C,v $
35  * Revision 1.8 2016/12/05 16:18:19 j_novak
36  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
37  *
38  * Revision 1.7 2014/10/13 08:53:48 j_novak
39  * Lorene classes and functions now belong to the namespace Lorene.
40  *
41  * Revision 1.6 2013/07/15 13:14:41 j_novak
42  * Correcting copy constructor and operator =
43  *
44  * Revision 1.5 2008/02/18 13:53:48 j_novak
45  * Removal of special indentation instructions.
46  *
47  * Revision 1.4 2003/12/19 15:05:14 j_novak
48  * Trying to avoid shadowed variables
49  *
50  * Revision 1.3 2003/10/03 16:17:17 j_novak
51  * Corrected some const qualifiers
52  *
53  * Revision 1.2 2001/12/04 21:27:54 e_gourgoulhon
54  *
55  * All writing/reading to a binary file are now performed according to
56  * the big endian convention, whatever the system is big endian or
57  * small endian, thanks to the functions fwrite_be and fread_be
58  *
59  * Revision 1.1 2001/11/22 13:41:54 j_novak
60  * Added all source files for manipulating Valencia type objects and making
61  * interpolations to and from Meudon grids.
62  *
63  *
64  * $Header: /cvsroot/Lorene/C++/Source/Valencia/grille_val.C,v 1.8 2016/12/05 16:18:19 j_novak Exp $
65  *
66  */
67 
68 // Fichier includes
69 #include "grille_val.h"
70 #include "utilitaires.h"
71 
72  //---------------//
73  // Constructeurs //
74  //---------------//
75 
76 // Fonction auxilliaire
77 namespace Lorene {
78 Tbl* Grille_val::fait_grille1D(const double rmin, const double rmax, const
79  int n)
80 {
81  assert(rmin<rmax) ;
82  Tbl* resu = new Tbl(n) ;
83  double step = (rmax - rmin)/double(n-1) ;
84  resu->set_etat_qcq() ;
85  for (int i=0; i<n; i++) resu->set(i) = rmin + i*step ;
86  return resu ;
87 }
88 
89 // Constructeur 1D
90 Grille_val::Grille_val(const double izrmin, const double izrmax, const
91  int n1, const int fantome):
92  dim(n1), nfantome(fantome), type_t(SYM), type_p(SYM)
93 {
94  assert (n1 > 0) ;
95  zrmin = new double(izrmin) ;
96  zrmax = new double(izrmax) ;
97  double amin = ((n1 + nfantome - 0.5)*izrmin -
98  (nfantome-0.5)*izrmax) / n1 ;
99  double amax = ((n1 + nfantome - 0.5)*izrmax -
100  (nfantome-0.5)*izrmin) / n1 ;
101  zr = fait_grille1D(amin, amax, n1+2*fantome) ;
102  amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ;
103  amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ;
104  zri = fait_grille1D(amin, amax, n1+2*fantome+1) ;
105 }
106 
107 // Constructeur 2D
108 Grille_val::Grille_val(const double izrmin, const double izrmax, const
109  int n2, const int n1, const int itype_t,
110  const int fantome):
111  dim(n2,n1), nfantome(fantome), type_t(itype_t), type_p(SYM)
112 
113 {
114  zrmin = new double(izrmin) ;
115  zrmax = new double(izrmax) ;
116  double amin = ((n1 + nfantome - 0.5)*izrmin -
117  (nfantome-0.5)*izrmax) / n1 ;
118  double amax = ((n1 + nfantome - 0.5)*izrmax -
119  (nfantome-0.5)*izrmin) / n1 ;
120  zr = fait_grille1D(amin, amax, n1+2*fantome) ;
121  amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ;
122  amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ;
123  zri = fait_grille1D(amin, amax, n1+2*fantome+1) ;
124 
125 }
126 
127 // Constructeur 3D
128 Grille_val::Grille_val(const double izrmin, const double izrmax,
129  const int n3, const int n2, const int n1,
130  const int itype_t, const int itype_p,
131  const int fantome ): dim(n3,n2,n1), nfantome(fantome),
132  type_t(itype_t), type_p(itype_p)
133 {
134  zrmin = new double(izrmin) ;
135  zrmax = new double(izrmax) ;
136  double amin = ((n1 + nfantome - 0.5)*izrmin -
137  (nfantome-0.5)*izrmax) / n1 ;
138  double amax = ((n1 + nfantome - 0.5)*izrmax -
139  (nfantome-0.5)*izrmin) / n1 ;
140  zr = fait_grille1D(amin, amax, n1+2*fantome) ;
141  amin = ((n1 + nfantome)*izrmin - nfantome*izrmax) / n1 ;
142  amax = ((n1 + nfantome)*izrmax - nfantome*izrmin) / n1 ;
143  zri = fait_grille1D(amin, amax, n1+2*fantome+1) ;
144 }
145 
146 
147 // Constructeur par recopie
148 Grille_val::Grille_val(const Grille_val & titi): dim(titi.dim),
149  nfantome(titi.nfantome), type_t(titi.type_t), type_p(titi.type_p)
150 {
151  assert(titi.zr != 0x0) ;
152  assert(titi.zri != 0x0) ;
153  assert(titi.zrmin != 0x0) ;
154  assert(titi.zrmax != 0x0) ;
155  zr = new Tbl(*titi.zr) ;
156  zri = new Tbl(*titi.zri) ;
157  zrmin = new double(*titi.zrmin) ;
158  zrmax = new double(*titi.zrmax) ;
159 
160 }
161 
162 // Depuis un fichier
163 Grille_val::Grille_val(FILE* fd):dim(fd) {
164 
165  fread_be(&nfantome, sizeof(int), 1, fd) ;
166  fread_be(&type_t, sizeof(int), 1, fd) ;
167  fread_be(&type_p, sizeof(int), 1, fd) ;
168 
169  double amin, amax ;
170  fread_be(&amin, sizeof(double), 1, fd) ;
171  fread_be(&amax, sizeof(double), 1, fd) ;
172  zrmin = new double(amin) ;
173  zrmax = new double(amax) ;
174  zr = new Tbl(fd) ;
175  zri = new Tbl(fd) ;
176 
177 }
178 
179  //--------------//
180  // Destructeurs //
181  //--------------//
182 
183 // Destructeur
185 
186  assert(zr != 0x0) ;
187  assert(zri != 0x0) ;
188  assert(zrmin != 0x0) ;
189  assert(zrmax != 0x0) ;
190  delete zr ;
191  delete zri ;
192  delete zrmin ;
193  delete zrmax ;
194 
195 }
196 
197  //-------------//
198  // Affectation //
199  //-------------//
200 
201 // Depuis une autre Grille_val
202 void Grille_val::operator=(const Grille_val & titi) {
203 
204  dim = titi.dim ;
205  nfantome = titi.nfantome ;
206  type_t = titi.type_t ;
207  type_p = titi.type_p ;
208 
209  assert(titi.zr != 0x0) ;
210  assert(titi.zri != 0x0) ;
211  assert(titi.zrmin != 0x0) ;
212  assert(titi.zrmax != 0x0) ;
213 
214  for (int i=0; i<dim.dim[0]+2*nfantome; i++)
215  zr->t[i] = titi.zr->t[i] ;
216  for (int i=0; i<dim.dim[0] + 2*nfantome + 1; i++)
217  zri->t[i] = titi.zri->t[i] ;
218  *zrmin = *titi.zrmin ;
219  *zrmax = *titi.zrmax ;
220 }
221 
222  //------------//
223  // Sauvegarde //
224  //------------//
225 
226 // Sauve dans un fchier
227 void Grille_val::sauve(FILE* fd) const {
228 
229  dim.sauve(fd) ;
230  fwrite_be(&nfantome, sizeof(int), 1, fd) ;
231  fwrite_be(&type_t, sizeof(int), 1, fd) ;
232  fwrite_be(&type_p, sizeof(int), 1, fd) ;
233 
234  fwrite_be(zrmin, sizeof(double), 1, fd) ;
235  fwrite_be(zrmax, sizeof(double), 1, fd) ;
236 
237  zr->sauve(fd) ; zri->sauve(fd) ;
238 
239 }
240 
241  //------------//
242  // Impression //
243  //------------//
244 
245 // Operateurs <<
246 ostream& operator<<(ostream& o, const Grille_val & titi) {
247  titi >> o ;
248  return o ;
249 }
250 
251 ostream& Grille_val::operator>>(ostream& o) const {
252  int ndim = dim.ndim ;
253  int nfant = nfantome ;
254  o.precision(4);
255  o.setf(ios::showpoint);
256  o << "*** Grille_val " << ndim << "D" << " size: " ;
257  for (int i = 0; i<ndim-1; i++) {
258  o << dim.dim[ndim-1-i] ;
259  if (ndim-i == 3) o << " x " ;
260  if (ndim-i == 2) o << " x " ;
261  }
262  o << dim.dim[0] << endl ;
263  o << nfant << " hidden cells on each side " << endl ;
264  return o ;
265 }
266 
267  //------------------------------------//
268  // class Gval_cart //
269  //------------------------------------//
270 
271 /*********************************************************************
272  *
273  * Cartesian grid for Godunov-type integration schemes
274  *
275  *********************************************************************/
276 
277  //---------------//
278  // Constructeurs //
279  //---------------//
280 
281 // Constructeur 1D
282 Gval_cart::Gval_cart(const double izmin, const double izmax, const int nz,
283  const int fantome)
284  :Grille_val(izmin, izmax, nz, fantome),
285  xmin(0x0), xmax(0x0),
286  ymin(0x0), ymax(0x0),
287  x(0x0), xi(0x0),
288  y(0x0), yi(0x0){
289 }
290 
291 // Constructeur 2D
292 Gval_cart::Gval_cart(const double ixmin, const double ixmax, const
293  double izmin, const double izmax, const int nx,
294  const int nz, const int itype_t, const int fantome)
295  :Grille_val(izmin, izmax, nx, nz, itype_t, fantome),
296  ymin(0x0), ymax(0x0),
297  y(0x0), yi(0x0)
298 {
299  assert ( (type_t!=SYM) || (izmin >= double(0)) ) ;
300 
301  xmin = new double(ixmin) ;
302  xmax = new double(ixmax) ;
303  double amin = ((nx + nfantome - 0.5)*ixmin -
304  (nfantome-0.5)*ixmax) / nx ;
305  double amax = ((nx + nfantome - 0.5)*ixmax -
306  (nfantome-0.5)*ixmin) / nx ;
307  x = fait_grille1D(amin, amax, nx+2*fantome) ;
308  amin = ((nx + nfantome)*ixmin - nfantome*ixmax) / nx ;
309  amax = ((nx + nfantome)*ixmax - nfantome*ixmin) / nx ;
310  xi = fait_grille1D(amin, amax, nx+2*fantome+1) ;
311 
312 }
313 
314 // Constructeur 3D
315 Gval_cart::Gval_cart(const double iymin, const double iymax,
316  const double ixmin, const double ixmax, const
317  double izmin, const double izmax, const int ny,
318  const int nx, const int nz, const int itype_t,
319  const int itype_p, const int fantome)
320  :Grille_val(izmin, izmax, ny, nx, nz, itype_t, itype_p, fantome)
321 {
322  assert ( (type_t!=SYM) || (izmin >= double(0)) ) ;
323  assert ( (type_p!=SYM) || (iymin >= double(0)) ) ;
324 
325  xmin = new double(ixmin) ;
326  xmax = new double(ixmax) ;
327  double amin = ((nx + nfantome - 0.5)*ixmin -
328  (nfantome-0.5)*ixmax) / nx ;
329  double amax = ((nx + nfantome - 0.5)*ixmax -
330  (nfantome-0.5)*ixmin) / nx ;
331  x = fait_grille1D(amin, amax, nx+2*fantome) ;
332  amin = ((nx + nfantome)*ixmin - nfantome*ixmax) / nx ;
333  amax = ((nx + nfantome)*ixmax - nfantome*ixmin) / nx ;
334  xi = fait_grille1D(amin, amax, nx+2*fantome+1) ;
335 
336  ymin = new double(iymin) ;
337  ymax = new double(iymax) ;
338  amin = ((ny + nfantome - 0.5)*iymin -
339  (nfantome-0.5)*iymax) / ny ;
340  amax = ((ny + nfantome - 0.5)*iymax -
341  (nfantome-0.5)*iymin) / ny ;
342  y = fait_grille1D(amin, amax, ny+2*fantome) ;
343  amin = ((ny + nfantome)*iymin - nfantome*iymax) / ny ;
344  amax = ((ny + nfantome)*iymax - nfantome*iymin) / ny ;
345  yi = fait_grille1D(amin, amax, ny+2*fantome+1) ;
346 
347 }
348 
349 // Constructeur par recopie
351  :Grille_val(titi)
352 {
353  if (titi.x != 0x0) x = new Tbl(*titi.x) ;
354  if (titi.xi != 0x0) xi = new Tbl(*titi.xi) ;
355  if (titi.xmin != 0x0) xmin = new double(*titi.xmin) ;
356  if (titi.xmax != 0x0) xmax = new double(*titi.xmax) ;
357  if (titi.y != 0x0) y = new Tbl(*titi.y) ;
358  if (titi.yi != 0x0) yi = new Tbl(*titi.yi) ;
359  if (titi.ymin != 0x0) ymin = new double(*titi.ymin) ;
360  if (titi.ymax != 0x0) ymax = new double(*titi.ymax) ;
361 
362 }
363 
364 // Depuis un fichier
366  : Grille_val(fd)
367 {
368  double amin, amax ;
369  if (dim.ndim >= 2) {
370  fread_be(&amin, sizeof(double), 1, fd) ;
371  fread_be(&amax, sizeof(double), 1, fd) ;
372  xmin = new double(amin) ;
373  xmax = new double(amax) ;
374  x = new Tbl(fd) ;
375  xi = new Tbl(fd) ;
376  }
377  if (dim.ndim >= 3) {
378  fread_be(&amin, sizeof(double), 1, fd) ;
379  fread_be(&amax, sizeof(double), 1, fd) ;
380  ymin = new double(amin) ;
381  ymax = new double(amax) ;
382  y = new Tbl(fd) ;
383  yi = new Tbl(fd) ;
384  }
385 }
386 
387 
388  //--------------//
389  // Destructeurs //
390  //--------------//
391 
392 // Destructeur
394 
395  if (x != 0x0) delete x ;
396  if (xi != 0x0) delete xi ;
397  if (xmin != 0x0) delete xmin ;
398  if (xmax != 0x0) delete xmax ;
399  if (y != 0x0) delete y ;
400  if (yi != 0x0) delete yi ;
401  if (ymin != 0x0) delete ymin ;
402  if (ymax != 0x0) delete ymax ;
403 
404 }
405 
406  //-------------//
407  // Affectation //
408  //-------------//
409 
410 // Depuis une autre Grille_val
411 void Gval_cart::operator=(const Gval_cart& titi) {
412 
413  Grille_val::operator=(titi) ;
414 
415  if (titi.x != 0x0) *x = *titi.x ;
416  if (titi.xi != 0x0) *xi = *titi.xi ;
417  if (titi.xmin != 0x0) *xmin = *titi.xmin ;
418  if (titi.xmax != 0x0) *xmax = *titi.xmax ;
419  if (titi.y != 0x0) *y = *titi.y ;
420  if (titi.yi != 0x0) *yi = *titi.yi ;
421  if (titi.ymin != 0x0) *ymin = *titi.ymin ;
422  if (titi.ymax != 0x0) *ymax = *titi.ymax ;
423 }
424 
425  //------------//
426  // Sauvegarde //
427  //------------//
428 
429 // save onto a file
430 void Gval_cart::sauve(FILE* fd) const {
431 
432  Grille_val::sauve(fd) ;
433 
434  if (dim.ndim >= 2) {
435  fwrite_be(xmin, sizeof(double), 1, fd) ;
436  fwrite_be(xmax, sizeof(double), 1, fd) ;
437  x->sauve(fd) ; xi->sauve(fd) ;
438  }
439  if (dim.ndim >= 3) {
440  fwrite_be(ymin, sizeof(double), 1, fd) ;
441  fwrite_be(ymax, sizeof(double), 1, fd) ;
442  y->sauve(fd) ; yi->sauve(fd) ;
443  }
444 
445 }
446 
447 
448  //------------//
449  // Impression //
450  //------------//
451 
452 // Operateurs <<
453 ostream& Gval_cart::operator>>(ostream& o) const {
454 
455  int ndim = dim.ndim;
457 
458  o << "*** Cartesian grid ***" << endl ;
459 
460  switch (ndim) {
461 
462  case 1 : {
463  o << "Z nodes: " << endl ;
464  for (int i=0; i<dim.dim[0]; i++) {
465  o << zr->set(i+nfantome) << " " ;
466  }
467  o << endl ;
468  break ;
469  }
470 
471 
472  case 2 : {
473  o << "X nodes: " << endl ;
474  for (int j=0 ; j<dim.dim[1] ; j++) {
475  o << " " << x->set(j+nfantome) ;
476  }
477  o << endl ;
478 
479  o << "Z nodes: " << endl ;
480 
481  for (int i=0 ; i<dim.dim[0] ; i++) {
482  o << " " << zr->set(i+nfantome) ;
483  }
484  o << endl ;
485  break ;
486  }
487 
488  case 3 : {
489  o << "Y nodes: " << endl ;
490  for (int k=0 ; k<dim.dim[2] ; k++) {
491  o << " " << y->set(k+nfantome) ;
492  }
493  o << endl ;
494 
495  o << "X nodes: " << endl ;
496  for (int j=0 ; j<dim.dim[1] ; j++) {
497  o << " " << x->set(j+nfantome) ;
498  }
499  o << endl ;
500 
501  o << "Z nodes: " << endl ;
502 
503  for (int i=0 ; i<dim.dim[0] ; i++) {
504  o << " " << zr->set(i+nfantome) ;
505  }
506  o << endl ;
507  break ;
508  }
509 
510  default : {
511  cout << "operator>> Gval_cart : unexpected dimension !" << endl ;
512  cout << " ndim = " << ndim << endl ;
513  abort() ;
514  break ;
515  }
516  }
517 
518  return o ;
519 }
520  //------------------------------------//
521  // class Gval_spher //
522  //------------------------------------//
523 
524 /*********************************************************************
525  *
526  * Spherical grids for Godunov-type integration schemes
527  *
528  *********************************************************************/
529 
530  //---------------//
531  // Constructeurs //
532  //---------------//
533 
534 // Constructeur 1D
535 Gval_spher::Gval_spher(const double irmin, const double irmax, const int nr,
536  const int fantome)
537  :Grille_val(irmin, irmax, nr, fantome),
538  tet(0x0), teti(0x0),
539  phi(0x0), phii(0x0){
540  assert(irmin>=double(0)) ;
541 }
542 
543 // Constructeur 2D
544 Gval_spher::Gval_spher(const double irmin, const double irmax, const int nt,
545  const int nr, const int itype_t, const int fantome)
546  :Grille_val(irmin, irmax, nt, nr, itype_t, fantome),
547  phi(0x0), phii(0x0)
548 {
549  assert (irmin >= double(0)) ;
550 
551  double tetmin = 0. ;
552  double tetmax = (type_t == SYM ? M_PI_2 : M_PI) ;
553  double amin = ((nt + nfantome - 0.5)*tetmin -
554  (nfantome-0.5)*tetmax) / nt ;
555  double amax = ((nt + nfantome - 0.5)*tetmax -
556  (nfantome-0.5)*tetmin) / nt ;
557  tet = fait_grille1D(amin, amax, nt+2*fantome) ;
558  amin = ((nt + nfantome)*tetmin - nfantome*tetmax) / nt ;
559  amax = ((nt + nfantome)*tetmax - nfantome*tetmin) / nt ;
560  teti = fait_grille1D(amin, amax, nt+2*fantome+1) ;
561 
562 }
563 
564 // Constructeur 3D
565 Gval_spher::Gval_spher(const double irmin, const double irmax, const int np,
566  const int nt, const int nr, const int itype_t,
567  const int itype_p, const int fantome)
568  :Grille_val(irmin, irmax, np, nt, nr, itype_t, itype_p, fantome)
569 {
570  assert (irmin >= double(0)) ;
571 
572 
573  double tetmin = 0. ;
574  double tetmax = (type_t == SYM ? M_PI_2 : M_PI) ;
575  double amin = ((nt + nfantome - 0.5)*tetmin -
576  (nfantome-0.5)*tetmax) / nt ;
577  double amax = ((nt + nfantome - 0.5)*tetmax -
578  (nfantome-0.5)*tetmin) / nt ;
579  tet = fait_grille1D(amin, amax, nt+2*fantome) ;
580  amin = ((nt + nfantome)*tetmin - nfantome*tetmax) / nt ;
581  amax = ((nt + nfantome)*tetmax - nfantome*tetmin) / nt ;
582  teti = fait_grille1D(amin, amax, nt+2*fantome+1) ;
583 
584  double phimin = 0. ;
585  double phimax = ( type_p == SYM ? M_PI : 2.*M_PI) ; //??? a verifier!
586  amin = ((np + nfantome - 0.5)*phimin -
587  (nfantome-0.5)*phimax) / np ;
588  amax = ((np + nfantome - 0.5)*phimax -
589  (nfantome-0.5)*phimin) / np ;
590  phi = fait_grille1D(amin, amax, np+2*fantome) ;
591  amin = ((np + nfantome)*phimin - nfantome*phimax) / np ;
592  amax = ((np + nfantome)*phimax - nfantome*phimin) / np ;
593  phii = fait_grille1D(amin, amax, np+2*fantome+1) ;
594 
595 }
596 
597 // Constructeur par recopie
599  :Grille_val(titi), tet(0x0), teti(0x0), phi(0x0), phii(0x0)
600 {
601  if (titi.tet != 0x0) tet = new Tbl(*titi.tet) ;
602  if (titi.teti != 0x0) teti = new Tbl(*titi.teti) ;
603  if (titi.phi != 0x0) phi = new Tbl(*titi.phi) ;
604  if (titi.phii != 0x0) phii = new Tbl(*titi.phii) ;
605 
606 }
607 
608 // Depuis un fichier
610  : Grille_val(fd)
611 {
612  if (dim.ndim >= 2) {
613  tet = new Tbl(fd) ;
614  teti = new Tbl(fd) ;
615  }
616  if (dim.ndim >= 3) {
617  phi = new Tbl(fd) ;
618  phii = new Tbl(fd) ;
619  }
620 }
621 
622  //--------------//
623  // Destructeurs //
624  //--------------//
625 
626 // Destructeur
628 
629  if (tet != 0x0) delete tet ;
630  if (teti != 0x0) delete teti ;
631  if (phi != 0x0) delete phi ;
632  if (phii != 0x0) delete phii ;
633 
634 }
635 
636  //-------------//
637  // Affectation //
638  //-------------//
639 
640 // Depuis une autre Grille_val
642 
643  Grille_val::operator=(titi) ;
644 
645  if (titi.tet != 0x0) {
646  if (tet == 0x0)
647  tet = new Tbl(*titi.tet) ;
648  else
649  *tet = *titi.tet ;
650  }
651  else {
652  if (tet != 0x0) delete tet ;
653  tet = 0x0 ;
654  }
655  if (titi.teti != 0x0) {
656  if (teti == 0x0)
657  teti = new Tbl(*titi.teti) ;
658  else
659  *teti = *titi.teti ;
660  }
661  else {
662  if (teti != 0x0) delete teti ;
663  teti = 0x0 ;
664  }
665  if (titi.phi != 0x0) {
666  if (phi == 0x0)
667  phi = new Tbl(*titi.phi) ;
668  else
669  *phi = *titi.phi ;
670  }
671  else {
672  if (phi != 0x0) delete phi ;
673  phi = 0x0 ;
674  }
675  if (titi.phii != 0x0) {
676  if (phii == 0x0)
677  phii = new Tbl(*titi.phii) ;
678  else
679  *phii = *titi.phii ;
680  }
681  else {
682  if (phii != 0x0) delete phii ;
683  phii = 0x0 ;
684  }
685 }
686 
687  //------------//
688  // Sauvegarde //
689  //------------//
690 
691 // save onto a file
692 void Gval_spher::sauve(FILE* fd) const {
693 
694  Grille_val::sauve(fd) ;
695 
696  if (dim.ndim >= 2) {
697  tet->sauve(fd) ;
698  teti->sauve(fd) ;
699  }
700  if (dim.ndim >= 3) {
701  phi->sauve(fd) ;
702  phii->sauve(fd) ;
703  }
704 
705 }
706 
707  //------------//
708  // Impression //
709  //------------//
710 
711 // Operateurs <<
712 ostream& Gval_spher::operator>>(ostream& o) const {
713 
714  int ndim = dim.ndim;
716 
717  o << "*** Spherical grid ***" << endl ;
718 
719  switch (ndim) {
720 
721  case 1 : {
722  o << "R nodes: " << endl ;
723  for (int i=0; i<dim.dim[0]; i++) {
724  o << zr->set(i+nfantome) << " " ;
725  }
726  o << endl ;
727  break ;
728  }
729 
730 
731  case 2 : {
732  o << "THETA nodes: " << endl ;
733  for (int j=0 ; j<dim.dim[1] ; j++) {
734  o << " " << tet->set(j+nfantome) ;
735  }
736  o << endl ;
737 
738  o << "R nodes: " << endl ;
739 
740  for (int i=0 ; i<dim.dim[0] ; i++) {
741  o << " " << zr->set(i+nfantome) ;
742  }
743  o << endl ;
744  break ;
745  }
746 
747  case 3 : {
748  o << "PHI nodes: " << endl ;
749  for (int k=0 ; k<dim.dim[2] ; k++) {
750  o << " " << phi->set(k+nfantome) ;
751  }
752  o << endl ;
753 
754  o << "THETA nodes: " << endl ;
755  for (int j=0 ; j<dim.dim[1] ; j++) {
756  o << " " << tet->set(j+nfantome) ;
757  }
758  o << endl ;
759 
760  o << "R nodes: " << endl ;
761 
762  for (int i=0 ; i<dim.dim[0] ; i++) {
763  o << " " << zr->set(i+nfantome) ;
764  }
765  o << endl ;
766  break ;
767  }
768 
769  default : {
770  cout << "operator>> Gval_spher : unexpected dimension !" << endl ;
771  cout << " ndim = " << ndim << endl ;
772  abort() ;
773  break ;
774  }
775  }
776 
777  return o ;
778 }
779 }
virtual void sauve(FILE *) const
Save in a file.
Definition: grille_val.C:227
Tbl * xi
Arrays containing the values of coordinate x on the interfaces.
Definition: grille_val.h:345
double * xmax
Higher boundary for x dimension.
Definition: grille_val.h:335
Tbl * zri
Arrays containing the values of coordinate z (or r) on the interfaces.
Definition: grille_val.h:126
void sauve(FILE *) const
Save in a file.
Definition: dim_tbl.C:185
Lorene prototypes.
Definition: app_hor.h:67
Tbl * y
Arrays containing the values of coordinate y on the nodes.
Definition: grille_val.h:347
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition: tbl.h:301
Tbl * tet
Arrays containing the values of coordinate on the nodes.
Definition: grille_val.h:587
double * zrmax
Higher boundary for z (or r ) direction.
Definition: grille_val.h:120
Tbl * phii
Arrays containing the values of coordinate on the interfaces.
Definition: grille_val.h:593
double * zrmin
Lower boundary for z (or r ) direction.
Definition: grille_val.h:117
void operator=(const Gval_spher &)
Assignment to another Gval_spher.
Definition: grille_val.C:641
double * ymax
Higher boundary for y dimension.
Definition: grille_val.h:339
int type_t
Type of symmetry in :
Definition: grille_val.h:109
Base class for Godunov-type grids.
Definition: grille_val.h:94
double * xmin
Lower boundary for x dimension.
Definition: grille_val.h:333
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:364
virtual void sauve(FILE *) const
Save in a file.
Definition: grille_val.C:692
Tbl * yi
Arrays containing the values of coordinate y on the interfaces.
Definition: grille_val.h:349
double * ymin
Lower boundary for y dimension.
Definition: grille_val.h:337
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: grille_val.C:712
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: grille_val.C:453
Tbl * x
Arrays containing the values of coordinate x on the nodes.
Definition: grille_val.h:343
Tbl * fait_grille1D(const double rmin, const double rmax, const int n)
Auxilliary function used to allocate memory and construct 1D grid.
Definition: grille_val.C:78
Grille_val(const double, const double, const int n1, const int fantome=2)
Standard 1D constructor (the size is to be given without hidden cells)
Definition: grille_val.C:90
Tbl * teti
Arrays containing the values of coordinate on the interfaces.
Definition: grille_val.h:589
double * t
The array of double.
Definition: tbl.h:176
virtual void sauve(FILE *) const
Save in a file.
Definition: grille_val.C:430
Tbl * zr
Arrays containing the values of coordinate z (or r) on the nodes.
Definition: grille_val.h:124
int fwrite_be(const int *aa, int size, int nb, FILE *fich)
Writes integer(s) into a binary file according to the big endian convention.
Definition: fwrite_be.C:73
virtual ~Gval_spher()
Destructor.
Definition: grille_val.C:627
void operator=(const Grille_val &)
Assignment to another Grille_val.
Definition: grille_val.C:202
Tbl * phi
Arrays containing the values of coordinate on the nodes.
Definition: grille_val.h:591
int ndim
Number of dimensions of the Tbl: can be 1, 2 or 3.
Definition: dim_tbl.h:101
int fread_be(int *aa, int size, int nb, FILE *fich)
Reads integer(s) from a binary file according to the big endian convention.
Definition: fread_be.C:72
int nfantome
The number of hidden cells (same on each side)
Definition: grille_val.h:104
Class for spherical Godunov-type grids.
Definition: grille_val.h:579
Class for cartesian Godunov-type grids.
Definition: grille_val.h:325
Dim_tbl dim
The dimensions of the grid.
Definition: grille_val.h:102
Gval_spher(const double irmin, const double irmax, const int nr, const int fantome=2)
Standard 1D constructor.
Definition: grille_val.C:535
Gval_cart(const double izmin, const double izmax, const int n1, const int fantome=2)
Standard 1D constructor.
Definition: grille_val.C:282
virtual ~Grille_val()
Destructor.
Definition: grille_val.C:184
void sauve(FILE *) const
Save in a file.
Definition: tbl.C:329
Basic array class.
Definition: tbl.h:164
void operator=(const Gval_cart &)
Assignment to another Gval_cart.
Definition: grille_val.C:411
virtual ~Gval_cart()
Destructor.
Definition: grille_val.C:393
int type_p
Type of symmetry in :
Definition: grille_val.h:114
virtual ostream & operator>>(ostream &) const
Operator >> (virtual function called by the operator <<).
Definition: grille_val.C:251
int * dim
Array of dimensions (size: ndim).
Definition: dim_tbl.h:102