Debian Codegraph @

Codes/Tutorial/simple_poisson.C

raw
1 /*
2 * Resolution of a simple Poisson equation.
3 *
4 */
5
6 /*
7 * Copyright (c) 2004 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 simple_poisson_C[] = "$Header: /cvsroot/Lorene/Codes/Tutorial/simple_poisson.C,v 1.7 2014/10/13 08:54:03 j_novak Exp $" ;
27
28 /*
29 * $Id: simple_poisson.C,v 1.7 2014/10/13 08:54:03 j_novak Exp $
30 * $Log: simple_poisson.C,v $
31 * Revision 1.7 2014/10/13 08:54:03 j_novak
32 * Lorene classes and functions now belong to the namespace Lorene.
33 *
34 * Revision 1.6 2007/12/20 09:11:10 jl_cornou
35 * Correction of an error in op_sxpun about Jacobi(0,2) polynomials
36 *
37 * Revision 1.5 2007/12/11 15:28:27 jl_cornou
38 * Jacobi(0,2) polynomials partially implemented
39 *
40 * Revision 1.4 2005/03/25 20:29:57 e_gourgoulhon
41 * Use of new graphical routines for Scalar and Vector.
42 *
43 * Revision 1.3 2004/02/27 21:19:12 e_gourgoulhon
44 * Benefits from the fact that now derive_cov applied to a scalar
45 * returns a reference on a Vector (treatment of dpot).
46 *
47 * Revision 1.2 2004/02/16 13:00:00 e_gourgoulhon
48 * Added the C headers (not required by GNU g++ !!!).
49 *
50 * Revision 1.1 2004/02/15 22:08:16 e_gourgoulhon
51 * The example with Poisson equation is now in file simple_poisson.C.
52 * simple_wave.C contains now an example of resolution of d'Alembert
53 * equation. The time evolution is managed thanks to the new
54 * class Evolution_std.
55 *
56 *
57 *
58 * $Header: /cvsroot/Lorene/Codes/Tutorial/simple_poisson.C,v 1.7 2014/10/13 08:54:03 j_novak Exp $
59 *
60 */
61
62 // C++ headers
63 #include "headcpp.h"
64
65 // C headers
66 #include "stdlib.h"
67 #include "assert.h"
68 #include "math.h"
69
70 // Lorene headers
71 #include "nbr_spx.h"
72 #include "tensor.h"
73 #include "metric.h"
74 #include "graphique.h"
75 #include "utilitaires.h"
76
77 using namespace Lorene ;
78
79 int main() {
80
81 // Setup of a multi-domain grid (Lorene class Mg3d)
82 // ------------------------------------------------
83
84 int nz = 3 ; // Number of domains
85 int nr = 7 ; // Number of collocation points in r in each domain
86 int nt = 5 ; // Number of collocation points in theta in each domain
87 int np = 8 ; // Number of collocation points in phi in each domain
88 int symmetry_theta = SYM ; // symmetry with respect to the equatorial plane
89 int symmetry_phi = NONSYM ; // no symmetry in phi
90 bool compact = true ; // external domain is compactified
91
92 // Multi-domain grid construction:
93 Mg3d mgrid(nz, nr, nt, np, symmetry_theta, symmetry_phi, compact) ;
94
95 cout << mgrid << endl ;
96
97
98 // Setup of an affine mapping : grid --> physical space (Lorene class Map_af)
99 // --------------------------------------------------------------------------
100
101 // radial boundaries of each domain:
102 double r_limits[] = {0., 2., 3., __infinity} ;
103 assert( nz == 3 ) ; // since the above array described only 3 domains
104
105 Map_af map(mgrid, r_limits) ; // Mapping construction
106
107 cout << map << endl ;
108
109 // Denomination of various coordinates associated with the mapping
110 // ---------------------------------------------------------------
111
112 const Coord& r = map.r ; // r field
113 const Coord& th = map.tet ; // theta field
114 const Coord& phi = map.phi ; // phi field
115 const Coord& x = map.x ; // x field
116 const Coord& y = map.y ; // y field
117 const Coord& z = map.z ; // z field
118
119 // Setup of a scalar field (source of the Poisson equation)
120 // --------------------------------------------------------
121
122 Scalar source(map) ; // construction of an object of Lorene class Scalar
123
124 source = 2* exp( - r*r ) * (1 + x + x*y) ;
125
126 source.annule_domain(nz-1) ; // The source is set to zero in the last
127 // domain
128
129 source.std_spectral_base() ; // sets the bases for the spectral expansions
130 // to the standard ones for a scalar field
131
132 cout << source << endl ; // prints to screen
133
134
135 source.spectral_display() ; // prints the spectral expansions
136
137
138
139 // 1-D visualization via PGPLOT
140 // ----------------------------
141
142 des_meridian(source, 0., 1.1* r_limits[nz-1], "source", 1) ;
143 arrete() ;
144
145 // 2-D visualization via PGPLOT
146 // ----------------------------
147
148 des_coupe_z(source, 0., 2, "Source") ;
149
150
151 // 3-D visualization via OpenDX
152 // ----------------------------
153
154 double z0 = 0 ; // section plane : z = z0
155
156 source.visu_section('z', z0, -2., 2., -1.5, 1.5, "Example of section vis.") ;
157
158 source.visu_box(-2., 2., -1.5, 1.5, -1., 1., "Example of volume rendering", 0x0) ;
159
160 // Resolution of a Poisson equation
161 // --------------------------------
162
163 Scalar pot = source.poisson() ;
164
165 cout << "Solution of the Poisson equation : " << endl ;
166
167 pot.spectral_display() ; // prints the spectral expansions
168
169 des_coupe_z( pot, 0., 2, "Potential") ;
170
171 // pot.visu_section('z', z0, -2., 2., -1.5, 1.5, "Potential", "pot") ;
172
173 // Construction of a flat metric
174 // -----------------------------
175
176 Metric_flat mets(map, map.get_bvect_spher()) ; // spherical representation
177 Metric_flat metc(map, map.get_bvect_cart()) ; // Cartesian representation
178
179 // Gradient of the potential
180 // -------------------------
181
182 Vector dpot = pot.derive_cov(metc) ;
183 dpot.dec_dzpuis(2) ;
184
185 des_coupe_vect_z(dpot, 0., -2., 0.5, 2, "Gradient of potential") ;
186
187 dpot.visu_arrows(-1., 1., -1., 1., -1., 1., "Gradient of potential",
188 "gradient") ;
189
190
191 return EXIT_SUCCESS ;
192 }