| 1 |
// Lorene headers |
| 2 |
#include "metric.h" |
| 3 |
#include "cmp.h" |
| 4 |
#include "nbr_spx.h" |
| 5 |
#include "utilitaires.h" |
| 6 |
#include "graphique.h" |
| 7 |
|
| 8 |
using namespace Lorene ; |
| 9 |
|
| 10 |
int main() { |
| 11 |
|
| 12 |
// Construction of a multi-grid (Mg3d) |
| 13 |
// ----------------------------------- |
| 14 |
|
| 15 |
const int nz = 3 ; // Number of domains |
| 16 |
int nr =33 ; // Number of collocation points in r in each domain |
| 17 |
int nt = 5 ; // Number of collocation points in theta in each domain |
| 18 |
int np = 6 ; // Number of collocation points in phi in each domain |
| 19 |
int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane |
| 20 |
int symmetry_phi = NONSYM ; // no symmetry in phi |
| 21 |
|
| 22 |
int nbr[] = {nr, nr , nr}; |
| 23 |
int nbt[] = {nt, nt, nt} ; |
| 24 |
int nbp[] = {np, np, np} ; |
| 25 |
int tipe_r[] = {RARE, FIN, UNSURR} ; |
| 26 |
assert( nz == 3 ) ;// since the above arrays are described in only 3 domains |
| 27 |
int nzm1 = nz - 1 ; |
| 28 |
|
| 29 |
Mg3d mgrid(nz, nbr, tipe_r, nbt, symmetry_theta, nbp, symmetry_phi) ; |
| 30 |
|
| 31 |
// Construction of an affine mapping (Map_af) |
| 32 |
// ------------------------------------------ |
| 33 |
|
| 34 |
// Boundaries of each domains |
| 35 |
double r_limits[] = {0., 1., 2., __infinity} ; |
| 36 |
|
| 37 |
Map_af map(mgrid, r_limits) ; |
| 38 |
|
| 39 |
|
| 40 |
// Construction of flat metrics |
| 41 |
// ---------------------------- |
| 42 |
|
| 43 |
Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation |
| 44 |
Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation |
| 45 |
|
| 46 |
|
| 47 |
// Construction of a divergence free vector field |
| 48 |
// ---------------------------------------------- |
| 49 |
|
| 50 |
const Coord& r = map.r ; |
| 51 |
Scalar sint(map), cost(map) ; |
| 52 |
sint = map.sint ; |
| 53 |
cost = map.cost ; |
| 54 |
|
| 55 |
Scalar comp_l2 = 3*cost*cost - 1 ; |
| 56 |
comp_l2.std_spectral_base() ; |
| 57 |
|
| 58 |
Scalar num(map) ; |
| 59 |
num = 3 - r*r*r*r ; |
| 60 |
num.std_spectral_base() ; |
| 61 |
|
| 62 |
Base_val ma_base(nz) ; |
| 63 |
ma_base.set_base_r(0, R_CHEBPIM_I) ; |
| 64 |
for (int i=1; i<nz-1; i++) |
| 65 |
ma_base.set_base_r(i, R_CHEB) ; |
| 66 |
ma_base.set_base_r(nz-1, R_CHEBU) ; |
| 67 |
ma_base.set_base_t(T_COSSIN_CP) ; |
| 68 |
ma_base.set_base_p(P_COSSIN) ; |
| 69 |
|
| 70 |
Mtbl denom0(mgrid) ; |
| 71 |
denom0 = 1/(r*r*r*r) ; |
| 72 |
Scalar unsur4(map) ; |
| 73 |
unsur4 = 1 / (1 + r*r*r*r) ; |
| 74 |
unsur4.annule_domain(nz-1) ; |
| 75 |
unsur4.std_spectral_base() ; |
| 76 |
|
| 77 |
Scalar la_zec(map) ; |
| 78 |
la_zec = 1 ; |
| 79 |
la_zec.annule(0,nz-2) ; |
| 80 |
la_zec.set_dzpuis(4) ; |
| 81 |
Scalar tmp(map) ; |
| 82 |
tmp = 1 / (1 + denom0) ; |
| 83 |
tmp.annule(0, nz-2) ; |
| 84 |
la_zec *= tmp ; |
| 85 |
unsur4 += la_zec ; |
| 86 |
|
| 87 |
Scalar rtrois(map), denom1(map), denom2(map), denom3(map) ; |
| 88 |
rtrois = r*r*r ; |
| 89 |
rtrois.set_spectral_base(ma_base) ; |
| 90 |
denom1 = 1 / (r*r*r*r + 1) ; |
| 91 |
denom1.std_spectral_base() ; |
| 92 |
denom2 = unsur4 * denom1 ; |
| 93 |
denom3 = denom2*denom1 ; |
| 94 |
Scalar denom4 = denom3*denom1 ; |
| 95 |
|
| 96 |
Vector vvs1(map, CON, map.get_bvect_spher()) ; |
| 97 |
vvs1.set(1) = denom1 *comp_l2 ; |
| 98 |
vvs1.set(1).set_outer_boundary(nzm1, 0) ; |
| 99 |
vvs1.set(1).mult_r() ; |
| 100 |
vvs1.set(1).set_outer_boundary(nzm1, 0) ; |
| 101 |
vvs1.set(2) = - num*denom1*denom1 ; |
| 102 |
vvs1.set(2).set_outer_boundary(nzm1, 0) ; |
| 103 |
vvs1.set(2).mult_rsint() ; |
| 104 |
vvs1.set(2).mult_cost() ; |
| 105 |
vvs1.set(3) = -denom1 ; |
| 106 |
vvs1.set(3).set_outer_boundary(nzm1, 0) ; |
| 107 |
vvs1.set(3).mult_rsint() ; |
| 108 |
vvs1.set(3).set_outer_boundary(nzm1, 0) ; |
| 109 |
vvs1.std_spectral_base() ; |
| 110 |
|
| 111 |
Vector source_s(map, CON, map.get_bvect_spher()) ; |
| 112 |
source_s.set(1) = -(32 * denom3 + 4 * denom2)*rtrois*comp_l2 ; |
| 113 |
source_s.set(1).set_outer_boundary(nzm1, 0) ; |
| 114 |
source_s.set(2) = ( 384 * denom4 - 192 * denom3 - 12 * denom2)*rtrois ; |
| 115 |
source_s.set(2).set_outer_boundary(nzm1, 0) ; |
| 116 |
source_s.set(2).set_spectral_base(ma_base) ; |
| 117 |
source_s.set(2).mult_sint() ; |
| 118 |
source_s.set(2).mult_cost() ; |
| 119 |
source_s.set(3) = (32*denom3 - 4 * denom2) * rtrois ; |
| 120 |
source_s.set(3).set_outer_boundary(nzm1, 0) ; |
| 121 |
source_s.std_spectral_base() ; |
| 122 |
source_s.set(3).set_spectral_base(ma_base) ; |
| 123 |
source_s.set(3).mult_sint() ; |
| 124 |
|
| 125 |
cout << "Divergence of source : " << endl ; |
| 126 |
cout << "---------------------- " << endl << endl ; |
| 127 |
source_s.divergence(mets).spectral_display(0x0, 1.e-12) ; |
| 128 |
int sd ; cin >> sd ; |
| 129 |
|
| 130 |
Scalar pot_source = source_s.potential(mets) ; |
| 131 |
cout << "Source potential: " << endl ; |
| 132 |
cout << "----------------- " << endl << endl ; |
| 133 |
pot_source.spectral_display(0x0, 1.e-13) ; |
| 134 |
cin >> sd ; |
| 135 |
|
| 136 |
Vector_divfree source_df = source_s.div_free(mets) ; |
| 137 |
|
| 138 |
cout << "Difference with the div_free part of the source : " << endl; |
| 139 |
cout << "------------------------------------------------- " << endl << endl ; |
| 140 |
Vector v_diff = source_df - source_s ; |
| 141 |
v_diff.dec_dzpuis(4) ; |
| 142 |
v_diff.spectral_display(0x0, 1.e-13) ; |
| 143 |
cout << endl ; |
| 144 |
cin >> sd ; |
| 145 |
|
| 146 |
Vector_divfree sol_df = source_df.poisson() ; |
| 147 |
Vector diff_df = sol_df - vvs1 ; |
| 148 |
cout << "Difference with analytic solution: " << endl ; |
| 149 |
cout << "---------------------------------- " << endl ; |
| 150 |
for (int i=1; i<4; i++) |
| 151 |
cout << max(abs(diff_df(i))) << endl ; |
| 152 |
cout << endl ; |
| 153 |
|
| 154 |
Vector sol = sol_df ; |
| 155 |
cout << "Divergence of the solution : " << endl ; |
| 156 |
cout << "---------------------------- " << endl ; |
| 157 |
Scalar dive = sol.divergence(mets) ; |
| 158 |
dive.dec_dzpuis(2) ; |
| 159 |
dive.spectral_display(0x0, 1.e-12) ; |
| 160 |
|
| 161 |
Scalar eta_theo = num*denom1*denom1*comp_l2 / 6 ; |
| 162 |
eta_theo.std_spectral_base() ; |
| 163 |
eta_theo.set_outer_boundary(nzm1,0) ; |
| 164 |
eta_theo.mult_r() ; |
| 165 |
|
| 166 |
Scalar eta = sol_df.eta() ; |
| 167 |
cout << "Difference in eta : " << endl ; |
| 168 |
cout << "------------------- " << endl ; |
| 169 |
cout << max(abs(eta- eta_theo)) << endl ; |
| 170 |
|
| 171 |
Scalar mu_theo(map) ; |
| 172 |
mu_theo = denom1 ; |
| 173 |
mu_theo.set_outer_boundary(nzm1,0) ; |
| 174 |
mu_theo.mult_r() ; |
| 175 |
mu_theo.mult_cost() ; |
| 176 |
|
| 177 |
Scalar mu = sol_df.mu() ; |
| 178 |
cout << "Diffrence in mu: " << endl ; |
| 179 |
cout << "------------------- " << endl ; |
| 180 |
cout << max(abs(mu - mu_theo)) << endl ; |
| 181 |
|
| 182 |
return EXIT_SUCCESS ; |
| 183 |
} |