| 1 |
/* |
| 2 |
* Code for testing the divergence-free vector Poisson equation. |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/* |
| 7 |
* Copyright (c) 2003 Eric Gourgoulhon & 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_vdf_poisson_C[] = "$Header: /cvsroot/Lorene/Codes/Test/Poisson_vect/test_vdf_poisson.C,v 1.7 2014/10/13 08:54:02 j_novak Exp $" ; |
| 27 |
|
| 28 |
/* |
| 29 |
* $Id: test_vdf_poisson.C,v 1.7 2014/10/13 08:54:02 j_novak Exp $ |
| 30 |
* $Log: test_vdf_poisson.C,v $ |
| 31 |
* Revision 1.7 2014/10/13 08:54:02 j_novak |
| 32 |
* Lorene classes and functions now belong to the namespace Lorene. |
| 33 |
* |
| 34 |
* Revision 1.6 2014/10/06 15:12:55 j_novak |
| 35 |
* Modified #include directives to use c++ syntax. |
| 36 |
* |
| 37 |
* Revision 1.5 2003/10/29 13:16:11 e_gourgoulhon |
| 38 |
* Change of method name: Scalar::laplacien --> Scalar::laplacian. |
| 39 |
* |
| 40 |
* Revision 1.4 2003/10/29 11:06:11 e_gourgoulhon |
| 41 |
* inc2_dzpuis() replaced by inc_dzpuis(2). |
| 42 |
* |
| 43 |
* Revision 1.3 2003/10/21 13:59:36 e_gourgoulhon |
| 44 |
* new version |
| 45 |
* |
| 46 |
* Revision 1.2 2003/10/20 19:46:41 e_gourgoulhon |
| 47 |
* First successful version. |
| 48 |
* |
| 49 |
* Revision 1.1 2003/10/20 14:46:22 e_gourgoulhon |
| 50 |
* First version |
| 51 |
* |
| 52 |
* |
| 53 |
* $Header: /cvsroot/Lorene/Codes/Test/Poisson_vect/test_vdf_poisson.C,v 1.7 2014/10/13 08:54:02 j_novak Exp $ |
| 54 |
* |
| 55 |
*/ |
| 56 |
|
| 57 |
// C++ headers |
| 58 |
#include "headcpp.h" |
| 59 |
|
| 60 |
// C headers |
| 61 |
#include <cstdlib> |
| 62 |
|
| 63 |
// Lorene headers |
| 64 |
#include "metric.h" |
| 65 |
#include "nbr_spx.h" |
| 66 |
#include "utilitaires.h" |
| 67 |
|
| 68 |
|
| 69 |
using namespace Lorene ; |
| 70 |
|
| 71 |
int main() { |
| 72 |
|
| 73 |
// Construction of a multi-grid (Mg3d) |
| 74 |
// ----------------------------------- |
| 75 |
|
| 76 |
int nz = 3 ; // Number of domains |
| 77 |
int nzm1 = nz - 1 ; |
| 78 |
int nr = 17 ; // Number of collocation points in r in each domain |
| 79 |
int nt = 17; // Number of collocation points in theta in each domain |
| 80 |
int np = 12 ; // Number of collocation points in phi in each domain |
| 81 |
int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane |
| 82 |
int symmetry_phi = NONSYM ; // no symmetry in phi |
| 83 |
bool compact = true ; // external domain is compactified |
| 84 |
|
| 85 |
Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ; |
| 86 |
|
| 87 |
|
| 88 |
// Construction of an affine mapping (Map_af) |
| 89 |
// ------------------------------------------ |
| 90 |
|
| 91 |
// Boundaries of each domains |
| 92 |
double r_limits[] = {0., 0.5, 1., __infinity} ; |
| 93 |
assert( nz == 3 ) ; // since the above array described only 3 domains |
| 94 |
|
| 95 |
Map_af map(mgrid, r_limits) ; |
| 96 |
|
| 97 |
|
| 98 |
// Construction of a flat metric |
| 99 |
// ----------------------------- |
| 100 |
|
| 101 |
Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation |
| 102 |
Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation |
| 103 |
|
| 104 |
|
| 105 |
// Construction of a divergence free vector field |
| 106 |
// ---------------------------------------------- |
| 107 |
|
| 108 |
const Coord& x = map.x ; |
| 109 |
const Coord& y = map.y ; |
| 110 |
const Coord& z = map.z ; |
| 111 |
const Coord& r = map.r ; |
| 112 |
const Coord& cost = map.cost ; |
| 113 |
const Coord& sint = map.sint ; |
| 114 |
const Coord& cosp = map.cosp ; |
| 115 |
const Coord& sinp = map.sinp ; |
| 116 |
|
| 117 |
|
| 118 |
cout << "========================================================" << endl ; |
| 119 |
cout << " Test with a pretty general vector" << endl ; |
| 120 |
cout << " V = curl(A) " << endl ; |
| 121 |
cout << "========================================================" << endl ; |
| 122 |
|
| 123 |
Vector aa(map, CON, map.get_bvect_cart()) ; |
| 124 |
aa.set(1) = z * (x + x*y - 3*z*z) ; |
| 125 |
aa.set(2) = z * ( z*z*x - 2 *y + 1 ); |
| 126 |
aa.set(3) = 1 + x*x - y + x + x*y + z*z ; |
| 127 |
aa.annule_domain(nzm1) ; |
| 128 |
|
| 129 |
Mtbl tced = cost * ( sint*cosp/r + sint*sint*cosp*sinp - 3*cost*cost ) |
| 130 |
/ (r*r*r) ; |
| 131 |
tced = cost / (r*r*r) ; |
| 132 |
aa.set(1).set_domain(nzm1) = tced(nzm1) ; |
| 133 |
|
| 134 |
tced = cost * ( cost*cost*sint*cosp - 2*sint*sinp / r + 1) / (r*r*r) ; |
| 135 |
// aa.set(2).set_domain(nzm1) = tced(nzm1) ; |
| 136 |
|
| 137 |
// tced = (1 + sint*sint*cosp*cosp / r - sint*sinp + sint*cosp*sint*sinp |
| 138 |
// + cost*cost) / (r*r*r) ; |
| 139 |
tced = cost*cost*sint*sinp / (r*r*r) ; |
| 140 |
aa.set(3).set_domain(nzm1) = tced(nzm1) ; |
| 141 |
|
| 142 |
|
| 143 |
aa.std_spectral_base() ; |
| 144 |
aa.set(1).set_spectral_va().set_base_r(0, R_CHEBPIM_I) ; |
| 145 |
aa.set(1).set_spectral_va().set_base_t(T_COSSIN_CI) ; |
| 146 |
aa.set(2).set_spectral_va().set_base_r(0, R_CHEBPIM_I) ; |
| 147 |
aa.set(2).set_spectral_va().set_base_t(T_COSSIN_CI) ; |
| 148 |
aa.set(3).set_spectral_va().set_base_r(0, R_CHEBPIM_P) ; |
| 149 |
aa.set(3).set_spectral_va().set_base_t(T_COSSIN_CP) ; |
| 150 |
|
| 151 |
cout << "aa : " << endl ; |
| 152 |
aa.spectral_display() ; |
| 153 |
arrete() ; |
| 154 |
|
| 155 |
|
| 156 |
// Curl of aa: |
| 157 |
Vector_divfree vvc(map, map.get_bvect_cart(), metc ) ; |
| 158 |
vvc.set(1) = aa(3).dsdy() - aa(2).dsdz() ; |
| 159 |
vvc.set(2) = aa(1).dsdz() - aa(3).dsdx() ; |
| 160 |
vvc.set(3) = aa(2).dsdx() - aa(1).dsdy() ; |
| 161 |
|
| 162 |
cout << "Cartesian components : vvc : " << endl ; |
| 163 |
vvc.spectral_display() ; |
| 164 |
arrete() ; |
| 165 |
|
| 166 |
Vector_divfree vvs = vvc ; |
| 167 |
vvs.change_triad( map.get_bvect_spher() ) ; |
| 168 |
|
| 169 |
cout << "Spherical components : vvs : " << endl ; |
| 170 |
vvs.spectral_display() ; |
| 171 |
arrete() ; |
| 172 |
|
| 173 |
vvs.inc_dzpuis(2) ; |
| 174 |
|
| 175 |
cout << "vvs after inc_dzpuis(2) : " << endl ; |
| 176 |
vvs.spectral_display() ; |
| 177 |
|
| 178 |
cout << "mu : " << endl ; |
| 179 |
cout << "----" << endl ; |
| 180 |
vvs.mu().spectral_display() ; |
| 181 |
|
| 182 |
Vector_divfree wws = vvs.poisson() ; |
| 183 |
|
| 184 |
cout << "Solution wws : " << endl ; |
| 185 |
wws.spectral_display() ; |
| 186 |
arrete() ; |
| 187 |
|
| 188 |
Vector wwc = wws ; |
| 189 |
wwc.change_triad( map.get_bvect_cart() ) ; |
| 190 |
|
| 191 |
cout << "Max divergence wwc : " << max( abs(wwc.divergence(metc)) ) << endl ; |
| 192 |
cout << "Max divergence wws : " << max( abs(wws.divergence(mets)) ) << endl ; |
| 193 |
arrete() ; |
| 194 |
|
| 195 |
Vector vdiff(map, CON, map.get_bvect_cart() ) ; |
| 196 |
vdiff.set(1) = wwc(1).laplacian(2) - vvc(1) ; // dzpuis = 2 |
| 197 |
vdiff.set(2) = wwc(2).laplacian(2) - vvc(2) ; |
| 198 |
vdiff.set(3) = wwc(3).laplacian(2) - vvc(3) ; |
| 199 |
|
| 200 |
cout << "vdiff : " << endl ; |
| 201 |
vdiff.spectral_display() ; |
| 202 |
|
| 203 |
cout << "Max of vdiff : " << endl ; |
| 204 |
for (int i=1; i<=3; i++) { |
| 205 |
cout << max(abs(vdiff(i))) << endl ; |
| 206 |
} |
| 207 |
|
| 208 |
return EXIT_SUCCESS ; |
| 209 |
} |