Debian Codegraph @

Codes/Test/Cmp/test_cmp_val_point.C

raw
1 /*
2 * Test code for the function Cmp::val_point
3 *
4 */
5
6 /*
7 * Copyright (c) 2002 Eric Gourgoulhon
8 *
9 * This file is part of LORENE.
10 *
11 * LORENE is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2
13 * as published by the Free Software Foundation.
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 char test_cmp_val_point_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Cmp/test_cmp_val_point.C,v 1.5 2014/10/13 08:54:00 j_novak Exp $" ;
27
28 /*
29 * $Id: test_cmp_val_point.C,v 1.5 2014/10/13 08:54:00 j_novak Exp $
30 * $Log: test_cmp_val_point.C,v $
31 * Revision 1.5 2014/10/13 08:54:00 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.4 2014/10/06 15:12:52 j_novak
35 * Modified #include directives to use c++ syntax.
36 *
37 * Revision 1.3 2002/10/16 14:37:16 j_novak
38 * Reorganization of #include instructions of standard C++, in order to
39 * use experimental version 3 of gcc.
40 *
41 * Revision 1.2 2002/05/11 12:40:55 e_gourgoulhon
42 * Added test for the basis T_COSSIN_SI.
43 *
44 * Revision 1.1 2002/05/05 16:26:47 e_gourgoulhon
45 * Initial commit
46 *
47 *
48 * $Header: /cvsroot/Lorene/Codes/Test/Cmp/test_cmp_val_point.C,v 1.5 2014/10/13 08:54:00 j_novak Exp $
49 *
50 */
51
52 // C headers
53 #include <cstdlib>
54
55 // Lorene headers
56 #include "cmp.h"
57 #include "nbr_spx.h"
58
59 using namespace Lorene ;
60
61 int main() {
62
63 //-----------------------------------------------------------------------
64 // Input data : number of points, types of sampling, etc...
65 //-----------------------------------------------------------------------
66
67 int nz = 3 ; // Number of domains
68
69 int nr = 5 ; // Number of points in r (in each domain)
70 int nt = 7 ; // Number of points in theta (in each domain)
71 int np = 8 ; // Number of points in phi (in each domain)
72
73 // Type of sampling in theta:
74 // SYM : theta in [0,pi/2] (symmetry with respect equatorial plane)
75 // NONSYM : theta in [0,pi] (no symmetry)
76 int type_t = SYM ;
77
78 // Type of sampling in phi:
79 // SYM : phi in [0,pi[ (symmetry phi --> phi + pi)
80 // NONSYM : phi in [0,2 pi[ (no symmetry)
81 int type_p = NONSYM ;
82
83 // Shall the outermost domain be compactified ?
84 bool compact = true ;
85
86 // Boundaries of the domains:
87 double* bornes = new double[nz+1];
88
89 for (int l=0; l<nz; l++) {
90 bornes[l] = 2*l ;
91 }
92 if (compact) {
93 bornes[nz] = __infinity ;
94 }
95 else {
96 bornes[nz] = 2*nz ;
97 }
98
99 //-----------------------------------------------------------------------
100 // Construction of a multi-grid
101 //-----------------------------------------------------------------------
102
103 const Mg3d mg(nz, nr, nt, np, type_t, type_p, compact) ;
104
105 //-----------------------------------------------------------------------
106 // Construction of a mapping
107 //-----------------------------------------------------------------------
108
109 const Map_af mp(mg, bornes) ;
110
111 const Coord& r = mp.r ;
112 const Coord& tet = mp.tet ;
113 const Coord& phi = mp.phi ;
114 const Coord& x = mp.x ;
115 const Coord& y = mp.y ;
116 const Coord& z = mp.z ;
117 // const Coord& cost = mp.cost ;
118 // const Coord& sint = mp.sint ;
119 // const Coord& cosp = mp.cosp ;
120 // const Coord& sinp = mp.sinp ;
121
122 //-----------------------------------------------------------------------
123 // Construction of a Cmp
124 //-----------------------------------------------------------------------
125
126 Cmp aa(mp) ;
127 Cmp aa_aux(mp) ; // auxilliary Cmp to construct aa
128
129 /*
130 *********** Test of R_CHEBPIM_I and T_COSSIN_SP ************
131
132 aa_aux = x + z*z + x*y ;
133 aa_aux.annule(nz-1) ;
134
135 // Spectral expansion bases :
136 aa_aux.std_base_scal() ; // standard basis for a symmetric scalar field
137
138 aa = aa_aux.srdsdt() ;
139
140 *
141 ***************************************************************
142 */
143
144 /*
145 *********** Test of R_CHEBPIM_P and T_COSSIN_SI **************
146 */
147 aa_aux = ( x + z*z + x*y ) * z * x ;
148 aa_aux.std_base_scal() ;
149 aa_aux.va.set_base_r(0, R_CHEBPIM_I) ;
150 aa_aux.va.set_base_t(T_COSSIN_CI) ;
151
152 aa = aa_aux.srdsdt() ;
153
154 /*
155 ***************************************************************
156 */
157
158 aa.va.coef() ;
159
160 aa.affiche_seuil(cout) ;
161
162 //----------------------------------------------------------------------
163 // Call to the val_point function
164 //----------------------------------------------------------------------
165
166 double r0, theta0, phi0 ;
167 do {
168 cout << endl << "r ? (negative value to quit) " << endl ;
169 cin >> r0 ;
170 if (r0 >=0 ) {
171 cout << "theta ?" << endl ;
172 cin >> theta0 ;
173 cout << "phi ?" << endl ;
174 cin >> phi0 ;
175
176 double aa0 = aa.val_point(r0, theta0, phi0) ;
177 cout << "value at the point (" << r0 << "," << theta0 << ","
178 << phi0 << ") : " << aa0 << endl ;
179 }
180 }
181 while (r0 >= 0.) ;
182
183
184 // Test on every grid point
185 // ------------------------
186 Cmp bb(mp) ;
187 bb.allocate_all() ;
188 Mtbl mr = r ;
189 Mtbl mtet = tet ;
190 Mtbl mphi = phi ;
191 for (int l=0; l<nz; l++) {
192 for (int k=0; k<np; k++) {
193 for (int j=0; j<nt; j++) {
194 for (int i=0; i<nr; i++) {
195 double r1 = mr(l,k,j,i) ;
196 double t1 = mtet(l,k,j,i) ;
197 double p1 = mphi(l,k,j,i) ;
198 bb.set(l,k,j,i) = aa.val_point(r1,t1,p1) ;
199 }
200 }
201 }
202 }
203 bb.annule(nz-1) ;
204
205 Cmp diff = aa - bb ;
206 cout << "Test at every grid point:" << endl ;
207 // cout << diff << endl ;
208 diff.affiche_seuil(cout, 1) ;
209 cout << endl << "Maximum value of the difference in each domain: " << endl ;
210 cout << max(diff) << endl ;
211
212 //----------------------------------------------------------------------
213 // clean exit
214 //----------------------------------------------------------------------
215
216 delete [] bornes ;
217
218 return EXIT_SUCCESS ;
219 }
220