File: map_af_poisson2d.C

package info (click to toggle)
lorene 0.0.0~cvs20161116%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 26,472 kB
  • sloc: cpp: 212,946; fortran: 21,645; makefile: 1,750; sh: 4
file content (379 lines) | stat: -rw-r--r-- 10,051 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
/*
 * Method of the class Map_af for the resolution of the 2-D Poisson
 *  equation.
 *
 * (see file map.h for documentation).
 */

/*
 *   Copyright (c) 2000-2001 Eric Gourgoulhon
 *
 *   This file is part of LORENE.
 *
 *   LORENE is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   LORENE is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with LORENE; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


char map_af_poisson2d_C[] = "$Header: /cvsroot/Lorene/C++/Source/Map/map_af_poisson2d.C,v 1.6 2014/10/13 08:53:02 j_novak Exp $" ;

/*
 * $Id: map_af_poisson2d.C,v 1.6 2014/10/13 08:53:02 j_novak Exp $
 * $Log: map_af_poisson2d.C,v $
 * Revision 1.6  2014/10/13 08:53:02  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.5  2012/09/04 14:53:28  j_novak
 * Replacement of the FORTRAN version of huntm by a C one.
 *
 * Revision 1.4  2012/08/12 17:48:36  p_cerda
 * Magnetstar: New classes for magnetstar. Allowing for non-equatorial symmetry in Etoile et al. Adding B_phi in Et_rot_mag.
 *
 * Revision 1.3  2002/09/09 13:54:20  e_gourgoulhon
 *
 * Change of name of the Fortran subroutines
 * 	poisson2d -> poiss2d
 * 	poisson2di -> poiss2di
 * to avoid any clash with Map::poisson2d and Map::poisson2di
 *
 * Revision 1.2  2002/09/09 13:00:39  e_gourgoulhon
 * Modification of declaration of Fortran 77 prototypes for
 * a better portability (in particular on IBM AIX systems):
 * All Fortran subroutine names are now written F77_* and are
 * defined in the new file C++/Include/proto_f77.h.
 *
 * Revision 1.1.1.1  2001/11/20 15:19:27  e_gourgoulhon
 * LORENE
 *
 * Revision 2.1  2000/10/11  15:15:26  eric
 * 1ere version operationnelle.
 *
 * Revision 2.0  2000/10/09  13:47:10  eric
 * *** empty log message ***
 *
 *
 * $Header: /cvsroot/Lorene/C++/Source/Map/map_af_poisson2d.C,v 1.6 2014/10/13 08:53:02 j_novak Exp $
 *
 */

// Header Lorene:
#include "map.h"
#include "cmp.h"
#include "param.h"
#include "proto_f77.h"

//*****************************************************************************

namespace Lorene {

void Map_af::poisson2d(const Cmp& source_mat, const Cmp& source_quad, 
		       Param& par, Cmp& uu) const {
    
    assert(source_mat.get_etat() != ETATNONDEF) ; 
    assert(source_quad.get_etat() != ETATNONDEF) ; 
    assert(source_mat.get_mp()->get_mg() == mg) ; 
    assert(source_quad.get_mp()->get_mg() == mg) ; 
    assert(uu.get_mp()->get_mg() == mg) ; 

    assert( source_quad.check_dzpuis(4) ) ; 
    
    int mpsymm = uu.get_mp()->get_mg()->get_type_t();

    double& lambda = par.get_double_mod(0) ; 

    // Special case of a vanishing source 
    // ----------------------------------

    if (    (source_mat.get_etat() == ETATZERO) 
	 && (source_quad.get_etat() == ETATZERO) ) {
	
	uu = 0 ; 
	lambda = 1 ; 
	return ; 
    }

    // ---------------------------------------------------------------------
    // Preparation of the parameters for the Fortran subroutines F77_poisson2d
    //  and F77_poisson2di
    // ---------------------------------------------------------------------
    
    int nz = mg->get_nzone() ;
    int np1 = 1 ;		// Axisymmetry enforced
    int nt = mg->get_nt(0) ; 
    int nt2 = 0 ;

    switch ( mpsymm ){
    case SYM: {
      nt2 = 2*nt - 1 ;	// Number of points for the theta sampling
      break;				//  in [0,Pi], instead of [0,Pi/2]
    }
    case NONSYM: {
      nt2 = nt;
      break;
    }
    }
      

    // Array NDL
    // ---------
    int* ndl = new int[nz+4] ; 
    ndl[0] = nz ; 
    for (int l=0; l<nz; l++) {
	ndl[1+l] = mg->get_nr(l) ; 
    }
    ndl[1+nz] = nt2 ; 
    ndl[2+nz] = np1 ; 
    ndl[3+nz] = nz ; 
    
    // Array INDD
    // ----------
    int* indd = new int[nz] ; 
    for (int l=0; l<nz; l++) {
	switch ( mg->get_type_r(l) ) {
	    case RARE : {
		indd[l] = 0 ; 
		break ; 
	    }
	    case FIN : {
		indd[l] = 1 ; 
		break ; 
	    }
	    case UNSURR : {
		indd[l] = 2 ; 
		break ; 
	    }
	    default : {
		cout << "Map_af::poisson2d: unknown type_r !" << endl ; 
		abort() ; 
		break ; 
	    }
	}
    }
    
    // Parameters NDR, NDT, NDP and NDZ
    // --------------------------------
    int nrmax = 0 ;
    for (int l=0; l<nz ; l++) {
	nrmax = ( ndl[1+l] > nrmax ) ? ndl[1+l] : nrmax ; 
    }
    int ndr = nrmax + 5 ;   // Le +5 est impose par les routines de resolution
			    // de l'equation de Poisson du type gr2p3s_
    int ndt = nt2 + 2 ;
    int ndp = np1 + 2 ;
    int ndz = nz ; 
    
    // Array ERRE
    // ----------
    
    double* erre = new double [ndz*ndr] ; 
    
    for (int l=0; l<nz; l++) {
	for (int i=0; i<ndl[1+l]; i++) {
	    double xr = mg->get_grille3d(l)->x[i] ;
	    erre[ ndr*l + i ] = alpha[l] * xr + beta[l]  ;
	}
    }

    // Arrays containing the data
    // --------------------------
    
    int ndrt = ndr*ndt ; 
    int ndrtp = ndr*ndt*ndp ; 
    int taille = ndrtp*ndz ;

    double* tsou_m = new double[ taille ] ;    
    double* tsou_q = new double[ taille ] ;    
    double* tuu = new double[ taille ] ;    
    
    // Initialisation to zero :
    for (int i=0; i<taille; i++) {
	tsou_m[i] = 0 ; 
	tsou_q[i] = 0 ; 
	tuu[i] = 0 ; 
    }
    
    // Copy of source_mat into tsou_m
    // ------------------------------
    const Valeur& va_m = source_mat.va ; 
    assert(va_m.get_etat() == ETATQCQ) ; 
    va_m.coef_i() ; 
    const Mtbl* s_m = va_m.c ; 
    assert(s_m->get_etat() == ETATQCQ) ; 
    
    Base_val base_s = va_m.base ; 

    for (int l=0; l<nz; l++) {
	int nr = mg->get_nr(l) ; 
	int nrt = nr*nt ;  
	if (s_m->t[l]->get_etat() == ETATZERO) {
	    for (int k=0; k<np1; k++) {
		for (int j=0; j<nt; j++) {
		    for (int i=0; i<nr; i++) {
			tsou_m[ndrtp*l + ndrt*k + ndr*j + i] = 0 ;
			// point symetrique par rapport au plan theta = pi/2 :
			if ( mpsymm == SYM ) tsou_m[ndrtp*l + ndrt*k + ndr*(nt2-1-j) + i] = 0 ;			
		    }
		}
	    }
	    
	}
	else {
	    assert( s_m->t[l]->get_etat() == ETATQCQ ) ; 
	    for (int k=0; k<np1; k++) {
		for (int j=0; j<nt; j++) {
		    for (int i=0; i<nr; i++) {
			double xx = s_m->t[l]->t[nrt*k + nr*j + i] ;
			tsou_m[ndrtp*l + ndrt*k + ndr*j + i] = xx ;
			// point symetrique par rapport au plan theta = pi/2 :
			if ( mpsymm == SYM ) tsou_m[ndrtp*l + ndrt*k + ndr*(nt2-1-j) + i] = xx ;			
		    }
		}
	    }
	}  // End of case etat != ETATZERO
    }  

    // Copy of source_quad into tsou_q
    // -------------------------------

    if (source_quad.get_etat() != ETATZERO) {

	const Valeur& va_q = source_quad.va ; 
	assert(va_q.get_etat() == ETATQCQ) ; 
	va_q.coef_i() ; 
	const Mtbl* s_q = va_q.c ;  

	assert( va_q.base == base_s ) ; 

	assert(s_q->get_etat() == ETATQCQ) ; 

	for (int l=0; l<nz; l++) {
	    int nr = mg->get_nr(l) ; 
	    int nrt = nr*nt ;  
	    if (s_q->t[l]->get_etat() == ETATZERO) {
		for (int k=0; k<np1; k++) {
		    for (int j=0; j<nt; j++) {
			for (int i=0; i<nr; i++) {
			tsou_q[ndrtp*l + ndrt*k + ndr*j + i] = 0 ;
			// point symetrique par rapport au plan theta = pi/2 :
			if ( mpsymm == SYM ) tsou_q[ndrtp*l + ndrt*k + ndr*(nt2-1-j) + i] = 0 ;			
			}
		    }
		}
	    
	    }
	    else {
		assert( s_q->t[l]->get_etat() == ETATQCQ ) ; 
		for (int k=0; k<np1; k++) {
		    for (int j=0; j<nt; j++) {
			for (int i=0; i<nr; i++) {
			double xx = s_q->t[l]->t[nrt*k + nr*j + i] ;
			tsou_q[ndrtp*l + ndrt*k + ndr*j + i] = xx ;
			// point symetrique par rapport au plan theta = pi/2 :
			if ( mpsymm == SYM ) tsou_q[ndrtp*l + ndrt*k + ndr*(nt2-1-j) + i] = xx ;			
			}
		    }
		}
	    }  // End of case s_q->t[l]->etat != ETATZERO
	}
	
    } // End of case source_quad.etat != ETATZERO  

    //-----------------------------------------------------------
    //  Call of the Fortran subroutine poisson2d_ or poisson2di_
    //-----------------------------------------------------------

    int base_t = (va_m.base).get_base_t(0) ; 

    Base_val base_uu(nz) ;  // Output spectral bases

    switch (base_t) {

        case T_COS :
	case T_COS_P : {
	
	    double lambda0 ; 
	    
	    F77_poiss2d(ndl, &ndr, &ndt, &ndp, indd, erre, tsou_m, tsou_q, 
		       &lambda0, tuu) ;
		      
	    base_uu = base_s ;		// output bases = input bases
		       
	    lambda = lambda0 ; 
	    break ; 	    
	}
        case T_SIN :
	case T_SIN_I : {

	    double* tsou = new double[taille] ; 
	    for (int i=0; i<taille; i++) {
		tsou[i] = tsou_m[i] + tsou_q[i] ; 
	    }

	    F77_poiss2di(ndl, &ndr, &ndt, &ndp, indd, erre, tsou, tuu) ;
		
	    base_uu = base_s ;		// output bases = input bases

	    lambda = double(1) ; 
	    
	    delete [] tsou ; 
	    break ; 	    
	}
	
	default : {
	    cout << "Map_af::poisson2d : unkown theta basis !" << endl ;
	    cout << "  basis : " << hex << base_t << endl ; 
	    abort() ; 
	    break ; 
	}
    }
    
    //-------------------------------
    // Copy of tuu into uu
    //-------------------------------

    uu.allocate_all() ; 
    (uu.va).set_etat_c_qcq() ;	// To make sure that the coefficients are
				//  deleted
    
    for (int l=0; l<nz; l++) {
	int nr = mg->get_nr(l) ; 
	for (int k=0; k<mg->get_np(l); k++) {
	    for (int j=0; j<nt; j++) {
		for (int i=0; i<nr; i++) {
		    uu.set(l, k, j, i) = tuu[ndrtp*l + ndr*j + i]  ;
		}
	    }
	}
    }

    (uu.va).set_base( base_uu ) ;	// Bases for spectral expansions
    
    uu.set_dzpuis(0) ; 
   
    // Cleaning
    // --------
    
    delete [] ndl ; 
    delete [] indd ; 
    delete [] erre ; 
    delete [] tsou_m ; 
    delete [] tsou_q ; 
    delete [] tuu ; 
    
    
}


}