LORENE
cmp_test_poisson.C
1 /*
2  * Method of class Cmp to check if a Poisson equation has been correctly
3  * solved.
4  *
5  * (see file cmp.h for documentation)
6  *
7  */
8 
9 /*
10  * Copyright (c) 2000-2001 Eric Gourgoulhon
11  *
12  * This file is part of LORENE.
13  *
14  * LORENE is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 2 of the License, or
17  * (at your option) any later version.
18  *
19  * LORENE is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with LORENE; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27  *
28  */
29 
30 
31 
32 
33 /*
34  * $Id: cmp_test_poisson.C,v 1.4 2016/12/05 16:17:49 j_novak Exp $
35  * $Log: cmp_test_poisson.C,v $
36  * Revision 1.4 2016/12/05 16:17:49 j_novak
37  * Suppression of some global variables (file names, loch, ...) to prevent redefinitions
38  *
39  * Revision 1.3 2014/10/13 08:52:48 j_novak
40  * Lorene classes and functions now belong to the namespace Lorene.
41  *
42  * Revision 1.2 2002/10/16 14:36:34 j_novak
43  * Reorganization of #include instructions of standard C++, in order to
44  * use experimental version 3 of gcc.
45  *
46  * Revision 1.1.1.1 2001/11/20 15:19:27 e_gourgoulhon
47  * LORENE
48  *
49  * Revision 2.0 2000/10/05 14:22:24 eric
50  * *** empty log message ***
51  *
52  *
53  * $Header: /cvsroot/Lorene/C++/Source/Cmp/cmp_test_poisson.C,v 1.4 2016/12/05 16:17:49 j_novak Exp $
54  *
55  */
56 
57 // Headers Lorene
58 #include "cmp.h"
59 
60 namespace Lorene {
61 Tbl Cmp::test_poisson(const Cmp& uu, ostream& ostr, bool detail) const {
62 
63  assert( uu.get_mp() == mp ) ;
64 
65  // Computation of the absolute and relative errors
66  // -----------------------------------------------
67 
68  int dzi ;
69  if ( check_dzpuis(4) ) {
70  dzi = 4 ;
71  }
72  else{
73  if ( check_dzpuis(2) ) {
74  dzi = 2 ;
75  }
76  else{
77  assert( check_dzpuis(0) ) ;
78  dzi = 0 ;
79  }
80  }
81 
82  Tbl tdiff = max( abs( uu.laplacien(dzi) - *this ) ) ;
83 
84  Tbl tmax = max( abs(*this) ) ;
85 
86  int nz = mp->get_mg()->get_nzone() ;
87  int nzm1 = nz - 1 ;
88 
89  Tbl trel(nz) ;
90  trel.set_etat_qcq() ;
91 
92  if ( (dzpuis == 0) || (tmax(nzm1) == double(0)) ) {
93 
94  double s_max = max( tmax ) ;
95 
96  for (int l=0; l<nz; l++) {
97  trel.set(l) = tdiff(l) / s_max ;
98  }
99 
100  }
101  else{
102 
103  double s_max = 0 ;
104  for (int l=0; l<nzm1; l++) {
105  s_max = (tmax(l) > s_max) ? tmax(l) : s_max ;
106  }
107 
108  for (int l=0; l<nzm1; l++) {
109  trel.set(l) = tdiff(l) / s_max ;
110  }
111 
112  trel.set(nzm1) = tdiff(nzm1) / tmax(nzm1) ;
113 
114  }
115 
116  // All the errors are set in the same output 2-D Tbl
117  // -------------------------------------------------
118 
119  Tbl err(3, nz) ;
120 
121  err.set_etat_qcq() ;
122 
123  for(int l=0; l<nz; l++) {
124  err.set(0, l) = trel(l) ;
125  err.set(1, l) = tdiff(l) ;
126  err.set(2, l) = tmax(l) ;
127  }
128 
129  // Display
130  // -------
131 
132  if (detail) {
133  ostr << "Max. source :" ;
134  for (int l=0; l<nz; l++) {
135  ostr << " " << err(2, l) ;
136  }
137 
138  ostr << endl << "Abs. error : " ;
139  for (int l=0; l<nz; l++) {
140  ostr << " " << err(1, l) ;
141  }
142  }
143 
144  ostr << endl << "Rel. error : " ;
145  for (int l=0; l<nz; l++) {
146  ostr << " " << err(0, l) ;
147  }
148 
149  ostr << endl ;
150 
151  return err ;
152 
153 }
154 
155 }
const Map * get_mp() const
Returns the mapping.
Definition: cmp.h:901
Component of a tensorial field *** DEPRECATED : use class Scalar instead ***.
Definition: cmp.h:446
Lorene prototypes.
Definition: app_hor.h:67
const Mg3d * get_mg() const
Gives the Mg3d on which the mapping is defined.
Definition: map.h:783
double & set(int i)
Read/write of a particular element (index i) (1D case)
Definition: tbl.h:301
void set_etat_qcq()
Sets the logical state to ETATQCQ (ordinary state).
Definition: tbl.C:364
int dzpuis
Power of r by which the quantity represented by this must be divided in the external compactified zo...
Definition: cmp.h:461
int get_nzone() const
Returns the number of domains.
Definition: grilles.h:465
Tbl max(const Cmp &)
Maximum values of a Cmp in each domain.
Definition: cmp_math.C:438
Tbl test_poisson(const Cmp &uu, ostream &ostr, bool detail=false) const
Checks if a Poisson equation with *this as a source has been correctly solved.
const Map * mp
Reference mapping.
Definition: cmp.h:451
Cmp abs(const Cmp &)
Absolute value.
Definition: cmp_math.C:413
bool check_dzpuis(int dzi) const
Returns false if the last domain is compactified and *this is not zero in this domain and dzpuis is n...
Definition: cmp.C:718
Basic array class.
Definition: tbl.h:164
const Cmp & laplacien(int zec_mult_r=4) const
Returns the Laplacian of *this.
Definition: cmp_deriv.C:245