Debian Codegraph @

Codes/Test/Poisson_vect/test_poisson_vect.C

raw
1 /*
2 * Test of the resolution of the vector Poisson equation
3 *
4 */
5
6 /*
7 * Copyright (c) 2004 Jerome Novak
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_poisson_vect_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Poisson_vect/test_poisson_vect.C,v 1.3 2014/10/13 08:54:02 j_novak Exp $" ;
27
28
29 /*
30 * $Id: test_poisson_vect.C,v 1.3 2014/10/13 08:54:02 j_novak Exp $
31 * $Log: test_poisson_vect.C,v $
32 * Revision 1.3 2014/10/13 08:54:02 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.2 2006/06/05 09:48:33 j_novak
36 * Using version 6 of the vector Poisson solver
37 *
38 * Revision 1.1 2004/02/22 15:48:49 j_novak
39 * New code for testing vector Poisson equation.
40 *
41 *
42 * $Header: /cvsroot/Lorene/Codes/Test/Poisson_vect/test_poisson_vect.C,v 1.3 2014/10/13 08:54:02 j_novak Exp $
43 *
44 */
45
46 // Lorene headers
47 #include "metric.h"
48 #include "tenseur.h"
49 #include "nbr_spx.h"
50 #include "utilitaires.h"
51
52 using namespace Lorene ;
53
54 int main() {
55
56 // Construction of a multi-grid (Mg3d)
57 // -----------------------------------
58
59 const int nz = 3 ; // Number of domains
60 int nr = 33 ; // Number of collocation points in r in each domain
61 int nt = 5 ; // Number of collocation points in theta in each domain
62 int np = 6 ; // Number of collocation points in phi in each domain
63 int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane
64 int symmetry_phi = NONSYM ; // no symmetry in phi
65
66 int nbr[] = {nr, nr, nr};
67 int nbt[] = {nt, nt, nt} ;
68 int nbp[] = {np, np, np} ;
69 int tipe_r[] = {RARE, FIN, UNSURR} ;
70 assert( nz == 3 ) ;// since the above arrays are described in only 3 domains
71
72 Mg3d mgrid(nz, nbr, tipe_r, nbt, symmetry_theta, nbp, symmetry_phi) ;
73
74 int nzm1 = nz - 1 ;
75
76 // Construction of an affine mapping (Map_af)
77 // ------------------------------------------
78
79 double R = 2.1 ;
80
81 // Boundaries of each domains
82 double r_limits[] = {0., 0.5*R, R, __infinity} ;
83
84 Map_af map(mgrid, r_limits) ;
85
86
87 // Construction of flat metrics
88 // ----------------------------
89
90 Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation
91 Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation
92
93
94 Scalar xx(map), yy(map), zz(map), rr(map) ;
95 xx = map.x ;
96 yy = map.y ;
97 zz = map.z ;
98 rr = map.r ;
99
100 double lamda = 1. ; //for the vector equation Delta V + lamda grad(div V)
101 int nn ;
102 cout << "Enter n : (source decaying like 1/r^n+4, so n>0 is required)"
103 << endl ;
104 cin >> nn ;
105
106 Vector theo(map, CON, map.get_bvect_cart()) ;
107 Vector theo_zec(map, CON, map.get_bvect_cart()) ;
108 theo.set(1) = xx*rr*rr / (10 * (lamda+1) * pow(R, double(nn+5)))
109 - double(nn + 5) *xx /
110 (6 * (lamda + 1) * double(nn+3) * pow(R, double(nn+3))) ;
111 theo.set(1).annule_domain(nzm1) ;
112 theo_zec.set(1) = xx / ((lamda+1) * nn * (nn+3) * pow(rr, nn+3))
113 - (nn+5) * xx / ((lamda+1) * 15*nn * pow(R,double(nn)) * pow(rr,3)) ;
114 theo_zec.set(1).annule(0,nz-2) ;
115 theo.set(1) += theo_zec(1) ;
116 theo.set(1).set_outer_boundary(nz-1, 0.) ;
117 theo.set(2) = yy*rr*rr / (10 * (lamda+1) * pow(R, double(nn+5)))
118 - double(nn + 5) *yy / (6 * (lamda + 1) * double(nn+3) * pow(R, double(nn+3))) ;
119 theo.set(2).annule_domain(nzm1) ;
120 theo_zec.set(2) = yy / ((lamda+1) * nn * (nn+3) * pow(rr, nn+3))
121 - (nn+5) * yy / ((lamda+1) * 15*nn * pow(R,double(nn)) * pow(rr,3)) ;
122 theo_zec.set(2).annule(0,nz-2) ;
123 theo.set(2) += theo_zec(2) ;
124 theo.set(2).set_outer_boundary(nz-1, 0.) ;
125 theo.set(3) = zz*rr*rr / (10 * (lamda+1) * pow(R, double(nn+5)))
126 - double(nn + 5) *zz / (6 * (lamda + 1) * double(nn+3) * pow(R, double(nn+3))) ;
127 theo.set(3).annule_domain(nzm1) ;
128 theo_zec.set(3) = zz / ((lamda+1) * nn * (nn+3) * pow(rr, nn+3))
129 - (nn+5) * zz / ((lamda+1) * 15*nn * pow(R,double(nn)) * pow(rr,3)) ;
130 theo_zec.set(3).annule(0,nz-2) ;
131 theo.set(3) += theo_zec(3) ;
132 theo.set(3).set_outer_boundary(nz-1, 0.) ;
133 theo.std_spectral_base() ;
134
135 Vector source(map, CON, map.get_bvect_cart()) ;
136 Vector source_zec(map, CON, map.get_bvect_cart()) ;
137 source.set(1) = xx / pow(R, double(nn+5)) ;
138 source.set(1).annule_domain(nzm1) ;
139 source_zec.set(1) = xx / pow(rr, nn+1) ;
140 source_zec.set(1).set_dzpuis(4) ;
141 source_zec.set(1).annule(0, nz-2) ;
142 source.set(1) += source_zec(1) ;
143 source.set(1).set_outer_boundary(nz-1, 0.) ;
144 source.set(2) = yy / pow(R, double(nn+5)) ;
145 source.set(2).annule_domain(nzm1) ;
146 source_zec.set(2) = yy / pow(rr, nn+1) ;
147 source_zec.set(2).set_dzpuis(4) ;
148 source_zec.set(2).annule(0, nz-2) ;
149 source.set(2) += source_zec(2) ;
150 source.set(2).set_outer_boundary(nz-1, 0.) ;
151 source.set(3) = zz / pow(R, double(nn+5)) ;
152 source.set(3).annule_domain(nzm1) ;
153 source_zec.set(3) = zz / pow(rr, nn+1) ;
154 source_zec.set(3).set_dzpuis(4) ;
155 source_zec.set(3).annule(0, nz-2) ;
156 source.set(3) += source_zec(3) ;
157 source.set(3).set_outer_boundary(nz-1, 0.) ;
158 source.std_spectral_base() ;
159
160 Vector source_s = source ;
161 source_s.change_triad( map.get_bvect_spher() ) ;
162 Tenseur source_p(map, 1, CON, map.get_bvect_cart() ) ;
163 source_p.set_etat_qcq() ;
164 for (int i=0; i<3; i++) {
165 source_p.set(i) = Cmp(source(i+1)) ;
166 }
167 Tenseur vect_auxi (map, 1, CON, map.get_bvect_cart()) ;
168 vect_auxi.set_etat_qcq() ;
169 Tenseur scal_auxi (map) ;
170 scal_auxi.set_etat_qcq() ;
171
172 Tenseur resu_p(source_p.poisson_vect(lamda, vect_auxi, scal_auxi)) ;
173 Tenseur theo_p(map, 1, CON, map.get_bvect_cart()) ;
174 theo_p.set_etat_qcq() ;
175 for (int i=0; i<3; i++) {
176 theo_p.set(i) = Cmp(theo(i+1)) ;
177 }
178
179 Vector resus = source_s.poisson(lamda, mets,6) ;
180 Vector resu = resus ;
181 resu.change_triad(map.get_bvect_cart() ) ;
182
183 cout << "Max of relative difference (in cartesian components): " << endl ;
184 for (int i=1; i<=3; i++) {
185 cout << "Component " << i << ": " << endl ;
186 cout << "New version: " << diffrelmax(resu(i), theo(i)) << endl ;
187 cout << "Grandclement et al.: " <<
188 diffrelmax(resu_p(i-1), theo_p(i-1)) << endl ;
189 }
190
191 return EXIT_SUCCESS ;
192 }