File: poisson_compact.C

package info (click to toggle)
lorene 0.0.0~cvs20161116%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 26,444 kB
  • ctags: 13,953
  • sloc: cpp: 212,946; fortran: 21,645; makefile: 1,750; sh: 4
file content (488 lines) | stat: -rw-r--r-- 13,174 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/*
 *   Copyright (c) 2000-2006 Philippe Grandclement
 *   Copyright (c) 2007 Michal Bejger
 *   Copyright (c) 2007 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 poisson_compact_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/poisson_compact.C,v 1.6 2014/10/13 08:53:29 j_novak Exp $" ;

/*
 * $Id: poisson_compact.C,v 1.6 2014/10/13 08:53:29 j_novak Exp $
 * $Log: poisson_compact.C,v $
 * Revision 1.6  2014/10/13 08:53:29  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.5  2014/10/06 15:16:09  j_novak
 * Modified #include directives to use c++ syntax.
 *
 * Revision 1.4  2007/10/16 21:54:23  e_gourgoulhon
 * Added new function sol_poisson_compact (multi-domain version).
 *
 * Revision 1.3  2006/09/05 13:39:46  p_grandclement
 * update of the bin_ns_bh project
 *
 * Revision 1.2  2002/10/16 14:37:12  j_novak
 * Reorganization of #include instructions of standard C++, in order to
 * use experimental version 3 of gcc.
 *
 * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
 * LORENE
 *
 * Revision 2.2  2000/03/16  16:28:06  phil
 * Version entirement revue et corrigee
 *
 * Revision 2.1  2000/03/09  13:51:55  phil
 * *** empty log message ***
 *
 * Revision 2.0  2000/03/09  13:44:56  phil
 * *** empty log message ***
 *
 *
 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/poisson_compact.C,v 1.6 2014/10/13 08:53:29 j_novak Exp $
 *
 */

// Headers C
#include <cstdlib>
#include <cmath>
#include <cassert>

// Headers Lorene
#include "map.h"
#include "diff.h"
#include "matrice.h"
#include "type_parite.h"
#include "proto.h"
#include "base_val.h"
#include "utilitaires.h"

	/////////////////////////////
	//	Single domain version  //
	/////////////////////////////

/*
 * Cette fonction resout, dans le noyau :
 *	a*(1-xi^2)*lap(uu)+b*xi*duu/dxi = source
 * avec a>0 et b<0 ;
 * Pour le stokage des operateurs, il faut faire reamorce = true au
 * debut d'un nouveau calcul.
 */

namespace Lorene {
Mtbl_cf sol_poisson_compact(const Mtbl_cf& source, double a, double b, 
			    bool reamorce)  {
				    
    // Verifications :
    assert (source.get_etat() != ETATNONDEF) ;
    
    assert (a>0) ;
    assert (b<0) ;
    
    // Les tableaux de stockage :
    const int nmax = 200 ;
    static Matrice* tab_op[nmax] ;
    static int nb_deja_fait = 0 ;
    static int l_deja_fait[nmax] ;
    static int n_deja_fait[nmax] ;
    
    if (reamorce) {
	for (int i=0 ; i<nb_deja_fait ; i++)
	    delete tab_op[i] ;
	nb_deja_fait = 0 ;
    }
    
    int nz = source.get_mg()->get_nzone() ;

    // Pour le confort (on ne travaille que dans le noyau) :
    int nr = source.get_mg()->get_nr(0) ;
    int nt = source.get_mg()->get_nt(0) ;
    int np = source.get_mg()->get_np(0) ;
     
    int l_quant ;
    int m_quant ;
    int base_r ;
    
    // La solution ...    
    Mtbl_cf solution(source.get_mg(), source.base) ;
    solution.set_etat_qcq() ;
    solution.t[0]->set_etat_qcq() ;
    
    for (int k=0 ; k<np+1 ; k++)
	for (int j=0 ; j<nt ; j++)
	    if (nullite_plm(j, nt, k, np, source.base) == 1) 
	    {
		 // calcul des nombres quantiques :
	    donne_lm(nz, 0, j, k, source.base, m_quant, l_quant, base_r) ;
	    
        
	    //On gere le cas l_quant == 0 (c'est bien simple y'en a pas !)
	    if (l_quant == 0) {
		for (int i=0 ; i<nr ; i++)
		    solution.set(0, k, j, i) = 0 ;
		}
	    
	    // cas l_quant != 0
	    else {
		// On determine si la matrice a deja ete calculee :
	    int indice = -1 ;
	    
	    // Le cas l==1 est non singulier : pas de base de Gelerkin
	    int taille = (l_quant == 1) ? nr : nr-1 ;
	    
	    Matrice operateur (taille, taille) ;
	    for (int conte=0 ; conte<nb_deja_fait ; conte++)
		if ((l_deja_fait[conte]== l_quant) && (n_deja_fait[conte] == nr))
		    indice = conte ;
	    
	    if (indice == -1) {
		if (nb_deja_fait >= nmax) {
		    cout << "sol_poisson_compact : trop de matrices ..." << endl;
		    abort() ;
		    } 
		// Calcul a faire :
		operateur = a*lap_cpt_mat (nr, l_quant, base_r) 
			    + b*xdsdx_mat(nr, l_quant, base_r) ;
		operateur = combinaison_cpt (operateur, l_quant, base_r) ;
		
		l_deja_fait[nb_deja_fait] = l_quant ;
		n_deja_fait[nb_deja_fait] = nr ;
		tab_op[nb_deja_fait] = new Matrice(operateur) ;

		nb_deja_fait++ ;
		}
	    else {
		// rien a faire :
		operateur = *tab_op[indice] ;
		}
		
	   // La source :
	    Tbl so(taille) ;
	    so.set_etat_qcq() ;
	    for (int i=0 ; i<taille ; i++)
		so.set(i) = source(0, k, j, i) ;
	    so = combinaison_cpt (so, base_r) ;
	    
	    Tbl part (operateur.inverse(so)) ;
	    
	    if (taille == nr)
		for (int i=0 ; i<nr ; i++)
		     solution.set(0, k, j, i) = part(i) ; // cas l==1
	    else {
		solution.set(0, k, j, nr-1) = 0 ;
		for (int i=nr-2 ; i>=0 ; i--)
		    if (base_r == R_CHEBP) { //Gelerkin pair
			solution.set(0, k, j, i) = part(i) ;
			solution.set(0, k, j, i+1) += part(i) ;
			}
		    else { //Gelerkin impaire
	    		solution.set(0, k, j, i) = part(i)*(2*i+3) ;
			solution.set(0, k, j, i+1) += part(i)*(2*i+1) ;
			}
		    }
		}
	    }
	    else   // cas ou nullite_plm = 0 :
		for (int i=0 ; i<nr ; i++)
		    solution.set(0, k, j, i) = 0 ; 
	    
	// Mise a zero du coefficient (inusite) k=np+1
    for (int j=0; j<nt; j++)
	for(int i=0 ; i<nr ; i++)
	    solution.set(0, np+1, j, i) = 0 ; 
	
    for (int zone=1 ; zone<nz ; zone++)
	    solution.t[zone]->set_etat_zero() ;

    return solution ;
}



	/////////////////////////////
	//	Multi domain version  //
	/////////////////////////////


Mtbl_cf sol_poisson_compact(const Map_af& mapping, const Mtbl_cf& source, 
		const Tbl& ac, const Tbl& bc, bool )  {

	// Number of domains inside the star :
	int nzet = ac.get_dim(1) ; 
	assert(nzet<=source.get_mg()->get_nzone()) ; 
	
    // Some checks
    assert (source.get_mg()->get_type_r(0) == RARE) ;
    for (int l=1 ; l<nzet ; l++)
		assert(source.get_mg()->get_type_r(l) == FIN) ;

    // Spectral bases
    const Base_val& base = source.base ;
    
    // Result
    Mtbl_cf resultat(source.get_mg(), base) ;
    resultat.annule_hard() ;

    // donnees sur la zone
    int nr, nt, np ;
    int base_r ;
    double alpha, beta, echelle ;
    int l_quant, m_quant;

    // Determination of the size of the systeme :
    int size = 0 ;
    int max_nr = 0 ;
    for (int l=0 ; l<nzet ; l++) { 
    	nr = mapping.get_mg()->get_nr(l) ;
        size += nr ;
		if (nr > max_nr) max_nr = nr ;
    }
	
    Matrice systeme (size, size) ;
    systeme.set_etat_qcq() ;
    Tbl sec_membre (size) ;
    Tbl soluce (size) ;
    soluce.set_etat_qcq() ;

    np = mapping.get_mg()->get_np(0) ;
    nt = mapping.get_mg()->get_nt(0) ;
    Matrice* work ;
    
    // On bosse pour chaque l, m :
    for (int k=0 ; k<np+1 ; k++)
      for (int j=0 ; j<nt ; j++)
      	if (nullite_plm(j, nt, k, np, base) == 1) {
	
	systeme.annule_hard() ;
	sec_membre.annule_hard() ;
	     
	int column_courant = 0 ;
	int ligne_courant = 0 ;
	
	//--------------------------
	//       NUCLEUS
	//--------------------------
		
	nr = mapping.get_mg()->get_nr(0) ; 
	alpha = mapping.get_alpha()[0] ;
	base.give_quant_numbers (0, k, j, m_quant, l_quant, base_r) ;  

    if (l_quant == 0) {
		for (int i=0 ; i<size ; i++)
 			soluce.set(i) = 0 ;
	}  
	else {

    Diff_dsdx2 		d2_n(base_r, nr) ;		// suffix _n stands for "nucleus"
    Diff_sxdsdx 	sxd_n(base_r, nr) ;
   	Diff_sx2 		sx2_n(base_r, nr) ;
    Diff_x2dsdx2	x2d2_n(base_r,nr) ;
    Diff_xdsdx		xd_n(base_r,nr) ;
    Diff_id			id_n(base_r,nr) ;  
	
	work = new Matrice( ac(0,0) * ( d2_n + 2.*sxd_n -l_quant*(l_quant+1)*sx2_n )
		+ ac(0,2) * ( x2d2_n + 2.*xd_n -l_quant*(l_quant+1)*id_n ) 
		+ alpha * bc(0,1) * xd_n ) ;

	// cout << *work << endl ; 
	// arrete() ; 

	// regularity conditions :
	int nbr_cl = 0 ;
	if (l_quant > 1) {
	     nbr_cl = 1 ;
	     if (l_quant%2==0) {
	        //Even case
		for (int col=0 ; col<nr ; col++)
		    if (col%2==0)
		        systeme.set(ligne_courant, col+column_courant) = 1 ;
		    else 
		        systeme.set(ligne_courant, col+column_courant) = -1 ;
		}
	     else {
	     //Odd case
	         for (int col=0 ; col<nr ; col++)
		    if (col%2==0)
		        systeme.set(ligne_courant, col+column_courant) = 2*col+1 ;
		    else 
		        systeme.set(ligne_courant, col+column_courant) = -(2*col+1) ;
		}
	  ligne_courant ++ ;
	}
	
	// L'operateur :
	for (int lig=0 ; lig<nr-1-nbr_cl ; lig++) {
		for (int col=0 ; col<nr ; col++)
			systeme.set(lig+ligne_courant,col+column_courant) = (*work)(lig,col) ;
			sec_membre.set(lig+ligne_courant) = alpha*alpha*source(0, k, j, lig) ;
	}
	
	delete work ;
	ligne_courant += nr-1-nbr_cl ;
	  
	// Le raccord :
	for (int col=0 ; col<nr ; col++) {
	     // La fonction
	     systeme.set(ligne_courant, col+column_courant) = 1 ;
	     // Sa drive :
	     if (l_quant%2==0)
	         systeme.set(ligne_courant+1, col+column_courant) = 4*col*col/alpha ;
	     else 
	         systeme.set(ligne_courant+1, col+column_courant) = (2*col+1)*(2*col+1)/alpha ;
	}
	column_courant += nr ;
	
		//--------------------------
		//       SHELLS
		//--------------------------

	for (int l=1 ; l<nzet ; l++) {
	
		nr = mapping.get_mg()->get_nr(l) ; 
		alpha = mapping.get_alpha()[l] ;
		beta = mapping.get_beta()[l] ;
		echelle = beta/alpha ;
		double bsa = echelle ; 
		double bsa2 = bsa*bsa ; 
		
        base.give_quant_numbers (l, k, j, m_quant, l_quant, base_r) ;  

		Diff_dsdx		dx(base_r, nr) ; 
	 	Diff_xdsdx		xdx(base_r, nr) ; 
	 	Diff_x2dsdx		x2dx(base_r, nr) ; 
	 	Diff_x3dsdx		x3dx(base_r, nr) ; 
	 	Diff_dsdx2		dx2(base_r, nr) ; 
	 	Diff_xdsdx2		xdx2(base_r, nr) ; 
	 	Diff_x2dsdx2	x2dx2(base_r, nr) ; 
	 	Diff_x3dsdx2	x3dx2(base_r, nr) ; 
    	Diff_id			id(base_r,nr) ;  
    	Diff_mx			mx(base_r,nr) ;  
	
        work = new Matrice ( ac(l,0) * ( x2dx2 + 2.*bsa*xdx2 + bsa2*dx2 + 2.*xdx 
			+ 2.*bsa*dx - l_quant*(l_quant+1)*id )
			+ ac(l,1) * ( x3dx2 + 2.*bsa*x2dx2 + bsa2*xdx2 + 2.*x2dx 
			+ 2.*bsa*xdx - l_quant*(l_quant+1) *mx )
			+ alpha * ( bc(l,0) * ( x2dx + 2.*bsa*xdx + bsa2*dx ) 
					  + bc(l,1) * ( x3dx + 2.*bsa*x2dx + bsa2*xdx ) ) ) ;
	
	   // matching with previous domain :
	   for (int col=0 ; col<nr ; col++) {
	     // La fonction
	     if (col%2==0)
	          systeme.set(ligne_courant, col+column_courant) = -1 ;
	     else 
	          systeme.set(ligne_courant, col+column_courant) = 1 ;
	     // Sa drive :
	     if (col%2==0)
	         systeme.set(ligne_courant+1, col+column_courant) = col*col/alpha ;
	     else 
	         systeme.set(ligne_courant+1, col+column_courant) = -col*col/alpha ;
		}
	  ligne_courant += 2 ;
	  
	  // source must be multiplied by (x+echelle)^2
	  Tbl source_aux(nr) ;
	  source_aux.set_etat_qcq() ;
	  for (int i=0 ; i<nr ; i++)
		source_aux.set(i) = source(l,k,j,i)*alpha*alpha ;
		Tbl xso(source_aux) ;
		Tbl xxso(source_aux) ;
		multx_1d(nr, &xso.t, R_CHEB) ;
		multx_1d(nr, &xxso.t, R_CHEB) ;
		multx_1d(nr, &xxso.t, R_CHEB) ;
		source_aux = beta*beta/alpha/alpha*source_aux+2*beta/alpha*xso+xxso ;
	  
	  // L'operateur :
	  
		for (int lig=0 ; lig<nr-1 ; lig++) {
			for (int col=0 ; col<nr ; col++)
			systeme.set(lig+ligne_courant,col+column_courant) = (*work)(lig,col) ;
			sec_membre.set(lig+ligne_courant) = source_aux(lig) ;
		}
	  
		// cout << *work << endl ; 
		// arrete() ; 

	  delete work ;
	  ligne_courant += nr-2 ;

		if (l<nzet-1) {  // if this not the last shell
	  		//  matching with the next domain 
			for (int col=0 ; col<nr ; col++) {
			// La fonction
			systeme.set(ligne_courant, col+column_courant) = 1 ;
			// Sa drive :
			systeme.set(ligne_courant+1, col+column_courant) = col*col/alpha ;
			}
		}
	     
	  column_courant += nr ;   

	  } // end loop on the shells (index l)
	  
	// cout << "systeme : " << systeme << endl ; 
	// arrete() ;   	
	
	// Solving the system:
 
	systeme.set_band (size, size) ;   
	systeme.set_lu() ;

	// cout << "Determinant: " << systeme.determinant() << endl ; 
	// cout << "Eigenvalues: " << systeme.val_propre() << endl ;

	soluce = systeme.inverse(sec_membre) ;
	
	} // end case l_quant != 0 

	// cout << "soluce: " << soluce << endl ; 
	// arrete() ; 

	// On range :
	int conte = 0 ;
	for (int l=0 ; l<nzet ; l++) {
	     nr = mapping.get_mg()->get_nr(l) ;
	     for (int i=0 ; i<nr ; i++) {
	        resultat.set(l,k,j,i) = soluce(conte) ;
		 	conte++ ;
		}
	}

	} // end case nullite_plm == 1

	return resultat ;

}















}