File: sol_elliptic_boundary.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 (324 lines) | stat: -rw-r--r-- 10,951 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
/*
 *   Copyright (c) 2003 Philippe Grandclement
 *                      Jose Luis Jaramillo
 *                      Francois Limousin
 *
 *   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 version 2
 *   as published by the Free Software Foundation.
 *
 *   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 sol_elliptic_boundary_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/sol_elliptic_boundary.C,v 1.4 2014/10/13 08:53:30 j_novak Exp $" ;

/*
 * $Id: sol_elliptic_boundary.C,v 1.4 2014/10/13 08:53:30 j_novak Exp $
 * $Log: sol_elliptic_boundary.C,v $
 * Revision 1.4  2014/10/13 08:53:30  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.3  2014/10/06 15:16:10  j_novak
 * Modified #include directives to use c++ syntax.
 *
 * Revision 1.2  2008/08/20 15:03:55  n_vasset
 * Correction on how the boundary condition is imposed
 *
 * Revision 1.1  2005/06/09 08:01:05  f_limousin
 * Implement a new function sol_elliptic_boundary() and
 * Vector::poisson_boundary(...) which solve the vectorial poisson
 * equation (method 6) with an inner boundary condition.
 *
 * 
 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/sol_elliptic_boundary.C,v 1.4 2014/10/13 08:53:30 j_novak Exp $
 *
 */

// Header C : 
#include <cstdlib>
#include <cmath>

// Headers Lorene :
#include "param_elliptic.h"
#include "tbl.h"
#include "mtbl_cf.h"
#include "map.h"
          
 
	    //----------------------------------------------
	   //		Version Mtbl_cf
	  //----------------------------------------------



namespace Lorene {
Mtbl_cf elliptic_solver_boundary  (const Param_elliptic& ope_var, const Mtbl_cf& source, 
				   const Mtbl_cf& bound, double fact_dir, double fact_neu )  {
   // Verifications d'usage sur les zones
  int nz = source.get_mg()->get_nzone() ;
  assert (nz>1) ;
  assert (source.get_mg()->get_type_r(0) == RARE) ;
  assert (source.get_mg()->get_type_r(nz-1) == UNSURR) ;
  for (int l=1 ; l<nz-1 ; l++)
    assert(source.get_mg()->get_type_r(l) == FIN) ;
   
  // donnees sur la zone
  int nr, nt, np ;
  
  //Rangement des valeurs intermediaires 
  Tbl *so ;
  Tbl *sol_hom ;
  Tbl *sol_part ;
   
  
  // Rangement des solutions, avant raccordement
  Mtbl_cf solution_part(source.get_mg(), source.base) ;
  Mtbl_cf solution_hom_un(source.get_mg(), source.base) ;
  Mtbl_cf solution_hom_deux(source.get_mg(), source.base) ;
  Mtbl_cf resultat(source.get_mg(), source.base) ;

  solution_part.annule_hard() ;
  solution_hom_un.annule_hard() ;
  solution_hom_deux.annule_hard() ;
  resultat.annule_hard() ;

  // Computation of the SP and SH's in every domain ...
  int conte = 0 ;
  for (int zone=0 ; zone<nz ; zone++) {

    nr = source.get_mg()->get_nr(zone) ;
    nt = source.get_mg()->get_nt(zone) ;
    np = source.get_mg()->get_np(zone) ;

    for (int k=0 ; k<np+1 ; k++)
      for (int j=0 ; j<nt ; j++) {

	if (ope_var.operateurs[conte] != 0x0) {

	  // Calcul de la SH
	  sol_hom = new Tbl(ope_var.operateurs[conte]->get_solh()) ;
	  
	  //Calcul de la SP
	  so = new Tbl(nr) ;
	  so->set_etat_qcq() ;
	  for (int i=0 ; i<nr ; i++)
	    so->set(i) = source(zone, k, j, i) ;
	  
	  sol_part = new Tbl(ope_var.operateurs[conte]->get_solp(*so)) ;
	  
	  // Rangement dans les tableaux globaux ;
	  for (int i=0 ; i<nr ; i++) {
	    solution_part.set(zone, k, j, i) = (*sol_part)(i) ;
	    if (sol_hom->get_ndim()==1)
	      solution_hom_un.set(zone, k, j, i) = (*sol_hom)(i) ;
	    else
	      {
		solution_hom_un.set(zone, k, j, i) = (*sol_hom)(0,i) ;
		solution_hom_deux.set(zone, k, j, i) = (*sol_hom)(1,i) ;
	      }
	  }
	  
	  delete so ;
	  delete sol_hom ;
	  delete sol_part ;
	  
	}
	conte ++ ;
      }
  }


  //-------------------------------------------------
  // ON EST PARTI POUR LE RACCORD (Be careful  ....)
  //-------------------------------------------------
  
  // C'est pas simple toute cette sombre affaire...
  // Que de cas meme nombre de points dans chaque domaines...

  int start = 0 ;
  for (int k=0 ; k<source.get_mg()->get_np(0)+1 ; k++)
    for (int j=0 ; j<source.get_mg()->get_nt(0) ; j++) {
      if (ope_var.operateurs[start] != 0x0) {
	
	int taille = 2*nz - 3 ;
	Matrice systeme (taille, taille) ;
	systeme.set_etat_qcq() ;
	for (int i=0 ; i<taille ; i++)
	  for (int j2=0 ; j2<taille ; j2++)
	    systeme.set(i,j2) = 0 ;
	Tbl sec_membre (taille) ;
	sec_membre.set_etat_qcq() ;
	for (int i=0 ; i<taille ; i++)
	  sec_membre.set(i) = 0 ;
	
	//----------
	//  BOUNDARY :
	//----------
	conte = start ;

	// Boundary value at an angular point
	
	// Setting the right hand side term

	sec_membre.set(0) -= bound.val_in_bound_jk(1, j, k)/sqrt(2.) ; //Relevant value is in the first shell and only in the first coefficient


	//--------------
	// FIRST SHELL :
	//--------------
	
	int l_1=1 ;
	
	// On se met au bon endroit :
	int np_prec_1 = source.get_mg()->get_np(l_1-1) ;
	int nt_prec_1 = source.get_mg()->get_nt(l_1-1) ;
	conte += (np_prec_1+1)*nt_prec_1 ;

 	systeme.set(0, 0) = fact_dir * (-ope_var.G_minus(l_1) * 
 					ope_var.operateurs[conte]->val_sh_one_minus() ) 
	    + fact_neu * 
	 ( -ope_var.dG_minus(l_1)*ope_var.operateurs[conte]->val_sh_one_minus()-  
	  ope_var.G_minus(l_1)*ope_var.operateurs[conte]->der_sh_one_minus() );
	  
	systeme.set(0, 1) = fact_dir * (- ope_var.G_minus(l_1) * 
	  ope_var.operateurs[conte]->val_sh_two_minus() ) + fact_neu *
	  (-ope_var.dG_minus(l_1)*ope_var.operateurs[conte]->val_sh_two_minus()-  
	  ope_var.G_minus(l_1)*ope_var.operateurs[conte]->der_sh_two_minus() ) ;

	//Completing the right hand side term
 	sec_membre.set(0) += fact_dir * (ope_var.F_minus(l_1,k,j) + 
 	  ope_var.G_minus(l_1) * ope_var.operateurs[conte]->val_sp_minus() ) +
 	  fact_neu * ( ope_var.dF_minus(l_1,k,j) + 
 	  ope_var.dG_minus(l_1) * ope_var.operateurs[conte]->val_sp_minus() + 
 	  ope_var.G_minus(l_1) * ope_var.operateurs[conte]->der_sp_minus() )   ;

	
	// Valeurs en +1 :
	systeme.set(2*l_1-1, 2*l_1-2) = ope_var.G_plus(l_1) * 
	  ope_var.operateurs[conte]->val_sh_one_plus() ;
	systeme.set(2*l_1-1, 2*l_1-1) = ope_var.G_plus(l_1) * 
	  ope_var.operateurs[conte]->val_sh_two_plus() ;
	systeme.set(2*l_1, 2*l_1-2) = 
	  ope_var.dG_plus(l_1)*ope_var.operateurs[conte]->val_sh_one_plus()+  
	  ope_var.G_plus(l_1)*ope_var.operateurs[conte]->der_sh_one_plus() ;
	systeme.set(2*l_1, 2*l_1-1) =
	    ope_var.dG_plus(l_1)*ope_var.operateurs[conte]->val_sh_two_plus()+
	  ope_var.G_plus(l_1)*ope_var.operateurs[conte]->der_sh_two_plus() ;
	
	  sec_membre.set(2*l_1-1) -=  ope_var.F_plus(l_1,k,j) + 
	    ope_var.G_plus(l_1) * ope_var.operateurs[conte]->val_sp_plus();
	  sec_membre.set(2*l_1) -=  ope_var.dF_plus(l_1,k,j) + 
	    ope_var.dG_plus(l_1) * ope_var.operateurs[conte]->val_sp_plus() + 
	    ope_var.G_plus(l_1) * ope_var.operateurs[conte]->der_sp_plus() ;
	

	
	//----------
	// SHELLS :
	//----------
//	assert (nz-1 > 2) ;    // At least two shells
	for (int l=2 ; l<nz-1 ; l++) {
	  
	  // On se met au bon endroit :
	  int np_prec = source.get_mg()->get_np(l-1) ;
	  int nt_prec = source.get_mg()->get_nt(l-1) ;
	  conte += (np_prec+1)*nt_prec ;
	  	 
	  systeme.set(2*l-3, 2*l-2) = -ope_var.G_minus(l) * 
	    ope_var.operateurs[conte]->val_sh_one_minus() ;
	  systeme.set(2*l-3, 2*l-1) = - ope_var.G_minus(l) * 
	    ope_var.operateurs[conte]->val_sh_two_minus() ;
	  systeme.set(2*l-2, 2*l-2) = 
	    -ope_var.dG_minus(l)*ope_var.operateurs[conte]->val_sh_one_minus()-  
	    ope_var.G_minus(l)*ope_var.operateurs[conte]->der_sh_one_minus() ;
	  systeme.set(2*l-2, 2*l-1) =
	    -ope_var.dG_minus(l)*ope_var.operateurs[conte]->val_sh_two_minus()-  
	    ope_var.G_minus(l)*ope_var.operateurs[conte]->der_sh_two_minus() ;
	  
	  sec_membre.set(2*l-3) += ope_var.F_minus(l,k,j) + 
	    ope_var.G_minus(l) * ope_var.operateurs[conte]->val_sp_minus() ;
	  sec_membre.set(2*l-2) += ope_var.dF_minus(l,k,j) + 
	    ope_var.dG_minus(l) * ope_var.operateurs[conte]->val_sp_minus() + 
	    ope_var.G_minus(l) * ope_var.operateurs[conte]->der_sp_minus() ;
	  
	  // Valeurs en +1 :
	  systeme.set(2*l-1, 2*l-2) = ope_var.G_plus(l) * 
	    ope_var.operateurs[conte]->val_sh_one_plus() ;
	  systeme.set(2*l-1, 2*l-1) = ope_var.G_plus(l) * 
	    ope_var.operateurs[conte]->val_sh_two_plus() ;
	  systeme.set(2*l, 2*l-2) = 
	    ope_var.dG_plus(l)*ope_var.operateurs[conte]->val_sh_one_plus()+  
	    ope_var.G_plus(l)*ope_var.operateurs[conte]->der_sh_one_plus() ;
	  systeme.set(2*l, 2*l-1) =
	    ope_var.dG_plus(l)*ope_var.operateurs[conte]->val_sh_two_plus()+
	    ope_var.G_plus(l)*ope_var.operateurs[conte]->der_sh_two_plus() ;
	  
	  sec_membre.set(2*l-1) -=  ope_var.F_plus(l,k,j) + 
	    ope_var.G_plus(l) * ope_var.operateurs[conte]->val_sp_plus();
	  sec_membre.set(2*l) -=  ope_var.dF_plus(l,k,j) + 
	    ope_var.dG_plus(l) * ope_var.operateurs[conte]->val_sp_plus() + 
	    ope_var.G_plus(l) * ope_var.operateurs[conte]->der_sp_plus() ;
	}
	
	//-------
	// ZEC :
	//-------
	int np_prec = source.get_mg()->get_np(nz-2) ;
	int nt_prec = source.get_mg()->get_nt(nz-2) ;
	conte += (np_prec+1)*nt_prec ;
	
	systeme.set(taille-2, taille-1) = -ope_var.G_minus(nz-1) * 
	  ope_var.operateurs[conte]->val_sh_one_minus() ;
	systeme.set(taille-1, taille-1) = 
	  -ope_var.dG_minus(nz-1)*ope_var.operateurs[conte]->val_sh_one_minus()-  
	  ope_var.G_minus(nz-1)*ope_var.operateurs[conte]->der_sh_one_minus()  ;
	
	sec_membre.set(taille-2) += ope_var.F_minus(nz-1,k,j) + 
	  ope_var.G_minus(nz-1)*ope_var.operateurs[conte]->val_sp_minus() ;
	sec_membre.set(taille-1) += ope_var.dF_minus(nz-1,k,j) + 
	  ope_var.dG_minus(nz-1) * ope_var.operateurs[conte]->val_sp_minus() + 
	  ope_var.G_minus(nz-1) * ope_var.operateurs[conte]->der_sp_minus() ;
	
	// On resout le systeme ...
	if (taille > 2)
	  systeme.set_band(2,2) ;
	else
	  systeme.set_band(1,1) ;
	
	systeme.set_lu() ;
	Tbl facteur (systeme.inverse(sec_membre)) ;

	// On range tout ca :
  
	// Shells
	for (int l=1 ; l<nz-1 ; l++) {
	  nr = source.get_mg()->get_nr(l) ;
	  for (int i=0 ; i<nr ; i++)
	    resultat.set(l,k,j,i) = solution_part(l,k,j,i) + 
	      facteur(2*l-2)*solution_hom_un(l,k,j,i) +
	      facteur(2*l-1)*solution_hom_deux(l,k,j,i) ;
	}
	
	// Zec
	nr = source.get_mg()->get_nr(nz-1) ;
	for (int i=0 ; i<nr ; i++)
	  resultat.set(nz-1,k,j,i) = solution_part(nz-1,k,j,i) + 
	    facteur(taille-1)*solution_hom_un(nz-1,k,j,i) ;
      }
	start ++ ;
    }
    
  return resultat;
}

}