Debian Codegraph @

Codes/Test/Tensor/test_sym_tensor_decomp.C

raw
1 /*
2 * Code for testing the decomposition of a Sym_tensor in terms of eta/mu/W/X/T
3 * and its transcription for the Poisson operator.
4 *
5 */
6
7 /*
8 * Copyright (c) 2005 Jerome Novak
9 *
10 * This file is part of LORENE.
11 *
12 * LORENE is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation.
15 *
16 * LORENE is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with LORENE; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27 char test_sym_tensor_decomp_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Tensor/test_sym_tensor_decomp.C,v 1.3 2014/10/13 08:54:03 j_novak Exp $" ;
28
29 /*
30 * $Id: test_sym_tensor_decomp.C,v 1.3 2014/10/13 08:54:03 j_novak Exp $
31 * $Log: test_sym_tensor_decomp.C,v $
32 * Revision 1.3 2014/10/13 08:54:03 j_novak
33 * Lorene classes and functions now belong to the namespace Lorene.
34 *
35 * Revision 1.2 2005/09/08 07:40:56 j_novak
36 * Update of set_auxiliary arguments.
37 *
38 * Revision 1.1 2005/05/18 15:31:25 j_novak
39 * *** empty log message ***
40 *
41 *
42 * $Header: /cvsroot/Lorene/Codes/Test/Tensor/test_sym_tensor_decomp.C,v 1.3 2014/10/13 08:54:03 j_novak Exp $
43 *
44 */
45
46 // Lorene headers
47 #include "metric.h"
48 #include "nbr_spx.h"
49 #include "utilitaires.h"
50
51 using namespace Lorene ;
52
53 int main() {
54
55 // Construction of a multi-grid (Mg3d)
56 // -----------------------------------
57
58 int nz = 3 ; // Number of domains
59 int nzm1 = nz - 1 ;
60 int nr = 33 ; // Number of collocation points in r in each domain
61 int nt = 17 ; // Number of collocation points in theta in each domain
62 int np = 32 ; // 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 = SYM ; // no symmetry in phi
65 bool compact = true ; // external domain is compactified
66
67 Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ;
68
69
70 // Construction of an affine mapping (Map_af)
71 // ------------------------------------------
72
73 // Boundaries of each domains
74 double R = 2. ;
75 double r_limits[] = {0., 0.5*R, R, __infinity} ;
76 assert( nz == 3 ) ; // since the above array described only 3 domains
77
78 Map_af map(mgrid, r_limits) ;
79
80
81 // Construction of a flat metric
82 // -----------------------------
83
84 Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation
85 Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation
86
87
88 // Construction of a symmetric tensor field
89 // -----------------------------------------
90
91 const Coord& x = map.x ;
92 const Coord& y = map.y ;
93 const Coord& r = map.r ;
94
95 Sym_tensor hhc(map, CON, map.get_bvect_cart()) ;
96 for (int i=1; i<=3; i++)
97 for (int j=1; j<=i; j++)
98 hhc.set(i,j) = 0 ;
99
100 Scalar tmp(map) ;
101 tmp = r*r*r*r*cos(x*y)*exp(-r*r)/(1+r*r) ;
102 tmp.set_outer_boundary(nzm1, 0.) ;
103 tmp.annule(0,nz-2) ;
104 hhc.set(1,1) = cos(x*y)*exp(-r*r)/(1+r*r) ;
105 hhc.set(1,1).annule_domain(nzm1) ;
106 hhc.set(1,1) += tmp ;
107 for (int i=1; i<=3; i++)
108 for (int j=i; j<=3; j++)
109 hhc.set(i,j).set_dzpuis(4) ;
110
111 hhc.std_spectral_base() ;
112
113 Sym_tensor hhs = hhc ;
114 hhs.change_triad( map.get_bvect_spher() ) ;
115
116 Scalar eta = hhs.eta() ; eta.div_r_dzpuis(4) ;
117 Scalar mu = hhs.mu() ; mu.div_r_dzpuis(4) ;
118 Scalar ww = hhs.www() ;
119 Scalar xx = hhs.xxx() ;
120 Scalar tt = hhs.ttt() ;
121
122 // Test of the eta/mu/W/X decomposition
123 //-------------------------------------
124 Sym_tensor hh_new(map, CON, map.get_bvect_spher()) ;
125 hh_new.set_auxiliary(hhs(1,1), eta, mu, ww, xx, tt) ;
126
127 cout << "Test of the decomposition on eta/mu/W/X potentials : " << endl ;
128 for (int i=1; i<=3; i++)
129 for (int j=i; j<=3; j++) {
130 Scalar raz = (hhs(i,j) - hh_new(i,j)) ;
131 cout << "Component: " << i << " , " << j << ": " ;
132 maxabs(raz) ;
133 cout << endl ;
134 }
135 arrete() ;
136
137
138 Sym_tensor thhs = hhs ;
139 thhs.dec_dzpuis(4) ;
140
141 Sym_tensor thhc = thhs ;
142 thhc.change_triad(map.get_bvect_cart()) ;
143
144
145 Sym_tensor sou_cc(map, CON, map.get_bvect_cart()) ;
146 for (int i=1; i<=3; i++)
147 for (int j=i; j<=3; j++)
148 sou_cc.set(i,j) = thhc(i,j).laplacian(4) ;
149
150 Sym_tensor sou_ss = sou_cc ;
151 sou_ss.change_triad(map.get_bvect_spher()) ;
152
153 maxabs(thhc.divergence(metc), "Divergence cart. comp.") ;
154 maxabs(thhs.divergence(mets), "Divergence spher. comp.") ;
155
156 maxabs(sou_cc.divergence(metc), "Divergence cart. comp. for the source") ;
157 maxabs(sou_ss.divergence(mets), "Divergence spher. comp. for the source") ;
158
159
160 arrete() ;
161
162 cout << "Test of the divergence formulas : " << endl ;
163 Scalar dive(map) ;
164 dive = thhs.eta().lapang() ;
165 dive.div_r() ;
166 dive += 2*thhs(1,1) - thhs.ttt() ;
167 dive.div_r() ;
168 Scalar der = thhs(1,1).dsdr() ; der.dec_dzpuis(2) ;
169 dive += der ;
170 cout << "Comp. r : " << endl ;
171 maxabs(dive) ;
172
173 Scalar div_eta = thhs.eta().dsdr() ;
174 div_eta.dec_dzpuis(2) ;
175 tmp = 2*thhs.eta() ;
176 tmp.div_r() ;
177 div_eta += tmp + thhs.www().lapang() + 2*thhs.www() +0.5*thhs.ttt() ;
178 cout << "Comp. eta : " << endl ;
179 maxabs(div_eta.lapang()) ;
180
181
182 Scalar div_mu = thhs.mu().dsdr() ;
183 div_mu.dec_dzpuis(2) ;
184 tmp = 2*thhs.mu() ;
185 tmp.div_r() ;
186 div_mu += tmp + thhs.xxx().lapang() + 2*thhs.xxx() ;
187 cout << "Comp. mu : " << endl ;
188 maxabs(div_mu.lapang()) ;
189
190 arrete() ;
191
192 // Test of the Poisson equations in terms of eta/mu/W/X
193 //-----------------------------------------------------
194
195 cout << "Test of Poisson equations in terms of eta/mu/W/X/T : " << endl ;
196
197 Scalar trace = thhs(1,1) + thhs(2,2) + thhs(3,3) ;
198 Scalar sou_trace = sou_ss(1,1) + sou_ss(2,2) + sou_ss(3,3) ;
199
200 Scalar test(map) ;
201 test = trace.laplacian(4) -sou_trace ;
202 cout << "Eq. for trace : " << endl ;
203 maxabs(test) ;
204 cout << endl ;
205
206 test = -4*thhs.eta().lapang() ;
207 test.div_r_dzpuis(0) ;
208 test -= 4*thhs(1,1)- 2*thhs.ttt() ;
209 test.div_r_dzpuis(2) ;
210 test.div_r_dzpuis(4) ;
211 test += thhs(1,1).laplacian(4) - sou_ss(1,1) ;
212 cout << "Eq. for h^rr : " << endl ;
213 maxabs(test) ;
214 cout << endl ;
215
216 test = 2*thhs(1,1) ;
217 test.div_r_dzpuis(4) ;
218 tmp = sou_ss.eta() ;
219 tmp.inc_dzpuis() ;
220 div_eta.div_r_dzpuis(4) ;
221 test += thhs.eta().laplacian(4) - tmp -2*div_eta ;
222 cout << "Eq. for eta : " << endl ;
223 maxabs(test.lapang()) ;
224 cout << endl ;
225
226 tmp = sou_ss.mu() ;
227 tmp.inc_dzpuis() ;
228 div_mu.div_r_dzpuis(4) ;
229 test = thhs.mu().laplacian(4) - tmp - 2*div_mu ;
230 cout << "Eq. for mu : " << endl ;
231 maxabs(test) ;
232 cout << endl ;
233
234 test = 2*thhs.eta() ;
235 test.div_r_dzpuis(0) ;
236 test += 2*thhs.www() ;
237 test.div_r_dzpuis(2) ; test.div_r_dzpuis(4) ;
238 test += thhs.www().laplacian(4) - sou_ss.www() ;
239 cout << "Eq. for W : " << endl ;
240 maxabs(test) ;
241 cout << endl ;
242
243 test = 2*thhs.mu() ;
244 test.div_r_dzpuis(0) ;
245 test += 2*thhs.xxx() ;
246 test.div_r_dzpuis(2) ; test.div_r_dzpuis(4) ;
247 test += thhs.xxx().laplacian(4) - sou_ss.xxx() ;
248 cout << "Eq. for X : " << endl ;
249 maxabs(test) ;
250 cout << endl ;
251
252 return EXIT_SUCCESS ;
253 }