File: poisson_vect_frontiere.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 (844 lines) | stat: -rw-r--r-- 27,526 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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
/*
 *   Copyright (c) 2000-2001 Philippe Grandclement
 *
 *   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_vect_frontiere_C[] = "$Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/poisson_vect_frontiere.C,v 1.9 2014/10/13 08:53:30 j_novak Exp $" ;

/*
 * $Id: poisson_vect_frontiere.C,v 1.9 2014/10/13 08:53:30 j_novak Exp $
 * $Log: poisson_vect_frontiere.C,v $
 * Revision 1.9  2014/10/13 08:53:30  j_novak
 * Lorene classes and functions now belong to the namespace Lorene.
 *
 * Revision 1.8  2014/10/06 15:16:09  j_novak
 * Modified #include directives to use c++ syntax.
 *
 * Revision 1.7  2005/03/11 11:20:26  f_limousin
 * Minor modif
 *
 * Revision 1.6  2005/02/22 18:00:32  f_limousin
 * Correction of an error in the function poisson_vect_binaire(...).
 * Confusion between cartesian and spherical triad for the solution.
 *
 * Revision 1.5  2005/02/08 10:07:07  f_limousin
 * Implementation of poisson_vect_binaire(...) with Vectors (instead of
 * Tenseur) in argument.
 *
 * Revision 1.4  2004/09/28 16:00:15  f_limousin
 * Add function poisson_vect_boundary which is the same as
 * poisson_vect_frontiere but for the new classes Tensor and Scalar.
 *
 * Revision 1.3  2003/10/03 15:58:50  j_novak
 * Cleaning of some headers
 *
 * Revision 1.2  2003/02/13 16:40:25  p_grandclement
 * Addition of various things for the Bin_ns_bh project, non of them being
 * completely tested
 *
 * Revision 1.1.1.1  2001/11/20 15:19:28  e_gourgoulhon
 * LORENE
 *
 * Revision 2.2  2000/10/26  09:08:06  phil
 * *** empty log message ***
 *
 * Revision 2.1  2000/10/26  09:01:18  phil
 * *** empty log message ***
 *
 * Revision 2.0  2000/10/19  09:36:36  phil
 * *** empty log message ***
 *
 *
 * $Header: /cvsroot/Lorene/C++/Source/Non_class_members/PDE/poisson_vect_frontiere.C,v 1.9 2014/10/13 08:53:30 j_novak Exp $
 *
 */

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

// Headers Lorene :
#include "proto.h"
#include "tenseur.h"
#include "tensor.h"
#include "metric.h"

    // USING OOhara
namespace Lorene {
void poisson_vect_frontiere (double lambda, const Tenseur& source, Tenseur& shift, 
	    const Valeur& lim_x, const Valeur& lim_y, const Valeur& lim_z, 
	    int num_front, double precision, int itermax) {
	
    // METTRE TOUT PLEIN D'ASSERT
   
    // Confort
    int nt = lim_x.get_mg()->get_nt(num_front+1) ;
    int np = lim_x.get_mg()->get_np(num_front+1) ;
    int nz = lim_x.get_mg()->get_nzone() ;
    
   if (shift.get_etat() == ETATZERO) {
	shift.set_etat_qcq() ;
	for (int i=0 ; i<3 ; i++)
	    shift.set(i).annule_hard() ;
	shift.set_std_base() ;
    }
    
    Tenseur so (source) ;
    
    // La source scalaire :
    Tenseur cop_so (so) ;
    cop_so.dec2_dzpuis() ;
    cop_so.dec2_dzpuis() ;
    
    Tenseur scal (*so.get_mp()) ;
    scal.set_etat_qcq() ;
    
    Cmp source_scal (contract(cop_so.gradient(), 0, 1)()/(lambda+1)) ;
    source_scal.inc2_dzpuis() ;
    if (source_scal.get_etat()== ETATZERO) {
	source_scal.annule_hard() ;
	source_scal.std_base_scal() ;
	source_scal.set_dzpuis(4) ;
	}

    Tenseur copie_so (so) ;
    copie_so.dec_dzpuis() ;
     
    Tenseur source_vect (*so.get_mp(), 1, CON, *source.get_triad()) ;
    Tenseur auxi (*so.get_mp(), 1, COV, *source.get_triad()) ;
    Cmp grad_shift (source_scal.get_mp()) ;
    
    // La condition sur la derivee du scalaire :
    Valeur lim_scal (lim_x.get_mg()) ;
    Tenseur shift_old (*shift.get_mp(), 1, CON, shift.get_mp()->get_bvect_cart()) ;
    
    int conte = 0 ;
    int indic = 1 ;
   
    while (indic ==1) {
	
	shift_old = shift ;
	
	grad_shift = contract(shift.gradient(), 0, 1)() ;
	grad_shift.dec2_dzpuis() ;
	grad_shift.va.coef_i() ;
	   
   
  
	lim_scal = 1 ; // Permet d'affecter les trucs qui vont bien !
	for (int k=0 ; k<np ; k++)
	    for (int j=0 ; j<nt ; j++)
		lim_scal.set(num_front, k, j, 0) = 
		    grad_shift.va (num_front+1, k, j, 0) ;
	lim_scal.std_base_scal() ;
   
	// On resout la scalaire :
	scal.set() = source_scal.poisson_dirichlet (lim_scal, num_front) ;
    
	// La source vectorielle :
	source_vect.set_etat_qcq() ;
	auxi = scal.gradient() ;
	auxi.inc_dzpuis() ;
	for (int i=0 ; i<3 ; i++)
	    source_vect.set(i) = copie_so(i) - lambda * auxi(i) ;
    
	indic = 0;
	for (int i=0 ; i<3 ; i++)
	    if (source_vect(i).get_etat()==ETATQCQ)
		indic = 1 ;
	if (indic==0) {
	    for (int i=0 ; i<3 ; i++)
		source_vect.set(i).annule_hard() ;
	    source_vect.set_std_base() ;
	}
   
	// On resout les equations de poisson sur le shift :
	shift.set(0) = source_vect(0).poisson_dirichlet (lim_x, num_front) ;
	shift.set(1) = source_vect(1).poisson_dirichlet (lim_y, num_front) ;
	shift.set(2) = source_vect(2).poisson_dirichlet (lim_z, num_front) ;
	
	double erreur = 0 ;
	for (int i=0 ; i<3 ; i++) 
	    if (max(norme(shift(i))) > precision) {
	    Tbl diff (diffrelmax (shift(i), shift_old(i))) ;
	    for (int j=num_front+1 ; j<nz ; j++)
		if (diff(j)> erreur)
		    erreur = diff(j) ;
	    }
	
	cout << "Pas " << conte << " : Difference " << erreur << endl ;
	conte ++ ;
	
	if ((erreur <precision) || (conte > itermax))
	    indic = -1 ;
	}
}



    // USING OOhara
void poisson_vect_boundary (double lambda, const Vector& source,Vector& shift, 
	    const Valeur& lim_x, const Valeur& lim_y, const Valeur& lim_z, 
	    int num_front, double precision, int itermax) {
	
    // On travaille en composantes cartesiennes
    assert(source.get_mp().get_bvect_spher() == *(source.get_triad())) ;
    assert(source.get_mp().get_bvect_spher() == *(shift.get_triad())) ;

 
    // Confort
    int nt = lim_x.get_mg()->get_nt(num_front+1) ;
    int np = lim_x.get_mg()->get_np(num_front+1) ;
    int nz = lim_x.get_mg()->get_nzone() ;
    
    Metric_flat ff(source.get_mp(), source.get_mp().get_bvect_spher()) ;
    
    Vector so (source) ;
    
    // La source scalaire :
    Vector cop_so (so) ;
    cop_so.dec_dzpuis(2) ;
    cop_so.dec_dzpuis(2) ;
    
    Scalar scal (so.get_mp()) ;
    
    Scalar source_scal (contract(cop_so.derive_cov(ff), 0, 1)/(lambda+1)) ;
    source_scal.inc_dzpuis(2) ;
    if (source_scal.get_etat()== ETATZERO) {
	source_scal.annule_hard() ;
	source_scal.std_spectral_base() ;
	source_scal.set_dzpuis(4) ;
	}

    Vector copie_so (so) ;
    copie_so.dec_dzpuis() ;
     
    Vector source_vect (so.get_mp(), CON, *source.get_triad()) ;
    Vector auxi (so.get_mp(), COV, *source.get_triad()) ;
    Scalar grad_shift (source_scal.get_mp()) ;
    
    // La condition sur la derivee du scalaire :
    Valeur lim_scal (lim_x.get_mg()) ;
    Vector shift_old (shift.get_mp(), CON, shift.get_mp().get_bvect_cart()) ;
    
    int conte = 0 ;
    int indic = 1 ;
   
    while (indic ==1) {
	
	shift_old = shift ;
	
	grad_shift = contract(shift.derive_cov(ff), 0, 1) ;
	grad_shift.dec_dzpuis(2) ;
	grad_shift.set_spectral_va().coef_i() ;
	   
     
	lim_scal = 1 ; // Permet d'affecter les trucs qui vont bien !
	for (int k=0 ; k<np ; k++)
	    for (int j=0 ; j<nt ; j++)
		lim_scal.set(num_front, k, j, 0) = 
		    grad_shift.get_spectral_va() (num_front+1, k, j, 0) ;
	lim_scal.std_base_scal() ;
   
	// On resout la scalaire :
	
	source_scal.filtre(4) ;
	scal = source_scal.poisson_dirichlet (lim_scal, num_front) ;
    
	// La source vectorielle :
	source_vect.set_etat_qcq() ;
	auxi = scal.derive_cov(ff) ;
	auxi.inc_dzpuis() ;
	for (int i=1 ; i<=3 ; i++)
	    source_vect.set(i) = copie_so(i) - lambda * auxi(i) ;
    
	indic = 0;
	for (int i=1 ; i<=3 ; i++)
	    if (source_vect(i).get_etat()==ETATQCQ)
		indic = 1 ;
	if (indic==0) {
	    for (int i=1 ; i<=3 ; i++)
		source_vect.set(i).annule_hard() ;
	    source_vect.std_spectral_base() ;
	}

	shift.change_triad(source.get_mp().get_bvect_cart()) ;
	source_vect.change_triad(source.get_mp().get_bvect_cart()) ;

	for (int i=1 ; i<=3 ; i++) 
	    source_vect.set(i).filtre(4) ;

	// On resout les equations de poisson sur le shift :
	shift.set(1) = source_vect(1).poisson_dirichlet (lim_x, num_front) ;
	shift.set(2) = source_vect(2).poisson_dirichlet (lim_y, num_front) ;
	shift.set(3) = source_vect(3).poisson_dirichlet (lim_z, num_front) ;
	
	shift.change_triad(source.get_mp().get_bvect_spher()) ;
	source_vect.change_triad(source.get_mp().get_bvect_spher()) ;

	double erreur = 0 ;
	for (int i=1 ; i<=3 ; i++) 
	    if (max(norme(shift(i))) > precision) {
	    Tbl diff (diffrelmax (shift(i), shift_old(i))) ;
	    for (int j=num_front+1 ; j<nz ; j++)
		if (diff(j)> erreur)
		    erreur = diff(j) ;
	    }
	
	cout << "Pas " << conte << " : Difference " << erreur << endl ;
	conte ++ ;
	
	if ((erreur <precision) || (conte > itermax))
	    indic = -1 ;
	}
}




void poisson_vect_binaire ( double lambda, 
		const Tenseur& source_un, const Tenseur& source_deux, 
		const Valeur& bound_x_un, const Valeur& bound_y_un, 
		const Valeur& bound_z_un, const Valeur& bound_x_deux, 
		const Valeur& bound_y_deux, const Valeur& bound_z_deux, 
		Tenseur& sol_un, Tenseur& sol_deux, int num_front, double precision) {
		    
    // METTRE DES ASSERT
    assert (sol_un.get_etat() != ETATNONDEF) ;
    assert (sol_deux.get_etat() != ETATNONDEF) ;
    
    // Les bases des deux vecteurs doivent etre alignees ou non alignees :
     
    assert (sol_un.get_mp() == source_un.get_mp()) ;
    assert (sol_deux.get_mp() == source_deux.get_mp()) ;
    
    double orientation_un = sol_un.get_mp()->get_rot_phi() ;
    assert ((orientation_un==0) || (orientation_un==M_PI)) ;
    
    double orientation_deux = sol_deux.get_mp()->get_rot_phi() ;
    assert ((orientation_deux==0) || (orientation_deux==M_PI)) ;
    
    int same_orient = (orientation_un == orientation_deux) ? 1 : -1 ;
    
    
    if (sol_un.get_etat() == ETATZERO) {
	sol_un.set_etat_qcq() ;
	for (int i=0 ; i<3 ; i++)
	    sol_un.set(i).annule_hard() ;
	sol_un.set_std_base() ;
    }
    
     if (sol_deux.get_etat() == ETATZERO) {
	sol_deux.set_etat_qcq() ;
	for (int i=0 ; i<3 ; i++)
	    sol_deux.set(i).annule_hard() ;
	sol_deux.set_std_base() ;
    }
    
    Valeur limite_x_un (bound_x_un.get_mg()) ;
    limite_x_un = bound_x_un ;
    Valeur limite_y_un (bound_y_un.get_mg()) ;
    limite_y_un = bound_y_un ;
    Valeur limite_z_un (bound_z_un.get_mg()) ;
    limite_z_un = bound_z_un ;
      
    Valeur limite_x_deux (bound_x_deux.get_mg()) ;
    limite_x_deux = bound_x_deux ;
    Valeur limite_y_deux (bound_y_deux.get_mg()) ;
    limite_y_deux = bound_y_deux ;
    Valeur limite_z_deux (bound_z_deux.get_mg()) ;
    limite_z_deux = bound_z_deux ;
    
    Valeur limite_chi_un (bound_x_un.get_mg()) ;
    limite_chi_un = 0 ;
    limite_chi_un.std_base_scal() ;
    
    Valeur limite_chi_deux (bound_x_deux.get_mg()) ;
    limite_chi_deux = 0 ;
    limite_chi_deux.std_base_scal() ;
    
    Mtbl xa_mtbl_un (source_un.get_mp()->get_mg()) ;
    xa_mtbl_un.set_etat_qcq() ;
    Mtbl ya_mtbl_un (source_un.get_mp()->get_mg()) ;
    ya_mtbl_un.set_etat_qcq() ;
    Mtbl za_mtbl_un (source_un.get_mp()->get_mg()) ;
    za_mtbl_un.set_etat_qcq() ;
    Mtbl xa_mtbl_deux (source_deux.get_mp()->get_mg()) ;
    xa_mtbl_deux.set_etat_qcq() ;
    Mtbl ya_mtbl_deux (source_deux.get_mp()->get_mg()) ;
    ya_mtbl_deux.set_etat_qcq() ;
    Mtbl za_mtbl_deux (source_deux.get_mp()->get_mg()) ;
    za_mtbl_deux.set_etat_qcq() ;
    
    xa_mtbl_un = source_un.get_mp()->xa ;
    ya_mtbl_un = source_un.get_mp()->ya ;
    za_mtbl_un = source_un.get_mp()->za ;
    
    xa_mtbl_deux = source_deux.get_mp()->xa ;
    ya_mtbl_deux = source_deux.get_mp()->ya ;
    za_mtbl_deux = source_deux.get_mp()->za ;
    
    double xabs, yabs, zabs ;
    double air,  theta,  phi ;
    double valeur ;
    
    int nbrep_un = bound_x_un.get_mg()->get_np(num_front) ;
    int nbret_un = bound_x_un.get_mg()->get_nt(num_front) ;
    int nbrep_deux = bound_x_deux.get_mg()->get_np(num_front) ;
    int nbret_deux = bound_x_deux.get_mg()->get_nt(num_front) ;
    int nz_un = bound_x_un.get_mg()->get_nzone() ;
    int nz_deux = bound_x_deux.get_mg()->get_nzone() ;
    
    // La source de l'equation scalaire sur 1
    Tenseur cop_so_un (source_un) ;
    cop_so_un.dec2_dzpuis() ;
    cop_so_un.dec2_dzpuis() ;
    
    Cmp source_scal_un (contract (cop_so_un.gradient(), 0, 1)()/(lambda+1)) ;
    if (source_scal_un.get_etat() == ETATZERO) {
	source_scal_un.annule_hard() ;
	source_scal_un.std_base_scal() ;
    }
    source_scal_un.inc2_dzpuis() ;
    
    // La source de l'equation scalaire sur 2
    Tenseur cop_so_deux (source_deux) ;
    cop_so_deux.dec2_dzpuis() ;
    cop_so_deux.dec2_dzpuis() ;
    
    Cmp source_scal_deux (contract (cop_so_deux.gradient(), 0, 1)()/(lambda+1)) ;
    if (source_scal_deux.get_etat() == ETATZERO) {
	source_scal_deux.annule_hard() ;
	source_scal_deux.std_base_scal() ;
    }
    source_scal_deux.inc2_dzpuis() ;
    
    // Les copies :
    Tenseur copie_so_un (source_un) ;
    copie_so_un.dec_dzpuis() ;
    
    Tenseur copie_so_deux (source_deux) ;
    copie_so_deux.dec_dzpuis() ;
    
    // ON COMMENCE LA BOUCLE :
    Tenseur sol_un_old (sol_un) ;
    Tenseur sol_deux_old (sol_deux) ;
    
    int indic = 1 ;
    int conte = 0 ;
    
    while (indic == 1) {
	
	// On resout les deux equations scalaires :
	Tenseur chi_un (source_scal_un.poisson_dirichlet (limite_chi_un, num_front)) ;
	Tenseur chi_deux (source_scal_deux.poisson_dirichlet (limite_chi_deux, num_front)) ;
	
	// On calcul les source pour les equation vectorielles :
	Tenseur source_vect_un (copie_so_un) ;
	if (source_vect_un.get_etat() == ETATZERO) {
	    source_vect_un.set_etat_qcq() ;
	    for (int i=0 ; i<3 ; i++) {
		source_vect_un.set(i).annule_hard() ;
		source_vect_un.set(i).set_dzpuis(3) ;
		}
	    source_vect_un.set_std_base() ;
	    }
	Tenseur grad_chi_un (chi_un.gradient()) ;
	grad_chi_un.inc_dzpuis() ;
	for (int i=0 ; i<3 ; i++)
	    source_vect_un.set(i) = source_vect_un(i)-lambda*grad_chi_un(i) ;
	
	Tenseur source_vect_deux (copie_so_deux) ;
	if (source_vect_deux.get_etat() == ETATZERO) {
	    source_vect_deux.set_etat_qcq() ;
	    for (int i=0 ; i<3 ; i++) {
		source_vect_deux.set(i).annule_hard() ;
		source_vect_deux.set(i).set_dzpuis(3) ;
		}
	    source_vect_deux.set_std_base() ;
	    }
	Tenseur grad_chi_deux (chi_deux.gradient()) ;
	grad_chi_deux.inc_dzpuis() ;
	for (int i=0 ; i<3 ; i++)
	    source_vect_deux.set(i) = source_vect_deux(i)-lambda*grad_chi_deux(i) ;
	
	
	sol_un_old = sol_un ;
	sol_deux_old = sol_deux ;
	
	// On resout les equation vectorielles :
	sol_un.set(0) = source_vect_un(0).poisson_dirichlet (limite_x_un, num_front) ;
	sol_un.set(1) = source_vect_un(1).poisson_dirichlet (limite_y_un, num_front) ;
	sol_un.set(2) = source_vect_un(2).poisson_dirichlet (limite_z_un, num_front) ;
	sol_deux.set(0) = source_vect_deux(0).poisson_dirichlet (limite_x_deux, num_front) ;
	sol_deux.set(1) = source_vect_deux(1).poisson_dirichlet (limite_y_deux, num_front) ;
	sol_deux.set(2) = source_vect_deux(2).poisson_dirichlet (limite_z_deux, num_front) ;
	
	
	// On modifie les Cl sur chi :
	Cmp div_shift_un (contract(sol_un.gradient(), 0, 1)()) ;
	div_shift_un.dec2_dzpuis() ;
	div_shift_un.va.coef_i() ;
	
	limite_chi_un = 1 ; // Affectation
	for (int k=0 ; k<nbrep_un ; k++)
	    for (int j=0 ; j<nbret_un ; j++)
		limite_chi_un.set(num_front, k, j, 0) =
		    div_shift_un.va (num_front+1, k, j, 0) ;
	limite_chi_un.std_base_scal() ;
	
	Cmp div_shift_deux (contract(sol_deux.gradient(), 0, 1)()) ;
	div_shift_deux.dec2_dzpuis() ;
	div_shift_deux.va.coef_i() ;
	
	limite_chi_deux = 1 ; // Affectation
	for (int k=0 ; k<nbrep_deux ; k++)
	    for (int j=0 ; j<nbret_deux ; j++)
		limite_chi_deux.set(num_front, k, j, 0) =
		    div_shift_deux.va (num_front+1, k, j, 0) ;
	limite_chi_deux.std_base_scal() ;
	
	
	// On modifie les Cl sur sol_un :
	for (int k=0 ; k<nbrep_un ; k++)
	    for (int j=0 ; j<nbret_un ; j++) {
		xabs = xa_mtbl_un (num_front+1, k, j, 0) ;
		yabs = ya_mtbl_un (num_front+1, k, j, 0) ;
		zabs = za_mtbl_un (num_front+1, k, j, 0) ;
		
		source_deux.get_mp()->convert_absolute 
				(xabs, yabs, zabs, air, theta, phi) ;
		
		valeur = sol_deux(0).val_point(air, theta, phi) ;
		limite_x_un.set(num_front, k, j, 0) = 
			bound_x_un(num_front, k, j, 0) - same_orient*valeur ;
		
		valeur = sol_deux(1).val_point(air, theta, phi) ;
		limite_y_un.set(num_front, k, j, 0) = 
			bound_y_un(num_front, k, j, 0) - same_orient*valeur ;
		
		valeur = sol_deux(2).val_point(air, theta, phi) ;
		limite_z_un.set(num_front, k, j, 0) = 
			bound_z_un(num_front, k, j, 0) - valeur ;
	    }
	    
	// On modifie les Cl sur sol_deux :
	for (int k=0 ; k<nbrep_deux ; k++)
	    for (int j=0 ; j<nbret_deux ; j++) {
		xabs = xa_mtbl_deux (num_front+1, k, j, 0) ;
		yabs = ya_mtbl_deux (num_front+1, k, j, 0) ;
		zabs = za_mtbl_deux (num_front+1, k, j, 0) ;
		
		source_un.get_mp()->convert_absolute 
				(xabs, yabs, zabs, air, theta, phi) ;
		
		valeur = sol_un(0).val_point(air, theta, phi) ;
		limite_x_deux.set(num_front, k, j, 0) = 
			bound_x_deux(num_front, k, j, 0) - same_orient*valeur ;
		
		valeur = sol_un(1).val_point(air, theta, phi) ;
		limite_y_deux.set(num_front, k, j, 0) = 
			bound_y_deux(num_front, k, j, 0) - same_orient*valeur ;
		
		valeur = sol_un(2).val_point(air, theta, phi) ;
		limite_z_deux.set(num_front, k, j, 0) = 
			bound_z_deux(num_front, k, j, 0) - valeur ;
	    }
	    
	double erreur = 0 ;
	
	for (int i=0 ; i<3 ; i++) {
	    Tbl diff_un (diffrelmax (sol_un_old(i), sol_un(i))) ;
	    for (int j=num_front+1 ; j<nz_un ; j++)
		if (erreur<diff_un(j))
		    erreur = diff_un(j) ;
	}
	
	for (int i=0 ; i<3 ; i++) {
	    Tbl diff_deux (diffrelmax (sol_deux_old(i), sol_deux(i))) ;
	    for (int j=num_front+1 ; j<nz_deux ; j++)
		if (erreur<diff_deux(j))
		    erreur = diff_deux(j) ;
	}
	
	cout << "Pas " << conte << " : Difference " << erreur << endl ;
	
	if (erreur < precision)
	    indic = -1 ;
	conte ++ ;
	}
}
void poisson_vect_binaire ( double lambda, 
		const Vector& source_un, const Vector& source_deux, 
		const Valeur& bound_x_un, const Valeur& bound_y_un, 
		const Valeur& bound_z_un, const Valeur& bound_x_deux, 
		const Valeur& bound_y_deux, const Valeur& bound_z_deux, 
		Vector& sol_un, Vector& sol_deux, int num_front, double precision) {
		    
    sol_un.change_triad(source_un.get_mp().get_bvect_cart()) ;
    sol_deux.change_triad(source_deux.get_mp().get_bvect_cart()) ;
    
    // Les bases des deux vecteurs doivent etre alignees ou non alignees :
     
    assert (sol_un.get_mp() == source_un.get_mp()) ;
    assert (sol_deux.get_mp() == source_deux.get_mp()) ;
    
    double orientation_un = sol_un.get_mp().get_rot_phi() ;
    assert ((orientation_un==0) || (orientation_un==M_PI)) ;
    
    double orientation_deux = sol_deux.get_mp().get_rot_phi() ;
    assert ((orientation_deux==0) || (orientation_deux==M_PI)) ;
    
    int same_orient = (orientation_un == orientation_deux) ? 1 : -1 ;
    
    Valeur limite_x_un (bound_x_un.get_mg()) ;
    limite_x_un = bound_x_un ;
    Valeur limite_y_un (bound_y_un.get_mg()) ;
    limite_y_un = bound_y_un ;
    Valeur limite_z_un (bound_z_un.get_mg()) ;
    limite_z_un = bound_z_un ;
      
    Valeur limite_x_deux (bound_x_deux.get_mg()) ;
    limite_x_deux = bound_x_deux ;
    Valeur limite_y_deux (bound_y_deux.get_mg()) ;
    limite_y_deux = bound_y_deux ;
    Valeur limite_z_deux (bound_z_deux.get_mg()) ;
    limite_z_deux = bound_z_deux ;
    
    Valeur limite_chi_un (bound_x_un.get_mg()) ;
    limite_chi_un = 0 ;
    limite_chi_un.std_base_scal() ;
    
    Valeur limite_chi_deux (bound_x_deux.get_mg()) ;
    limite_chi_deux = 0 ;
    limite_chi_deux.std_base_scal() ;
    
    Mtbl xa_mtbl_un (source_un.get_mp().get_mg()) ;
    xa_mtbl_un.set_etat_qcq() ;
    Mtbl ya_mtbl_un (source_un.get_mp().get_mg()) ;
    ya_mtbl_un.set_etat_qcq() ;
    Mtbl za_mtbl_un (source_un.get_mp().get_mg()) ;
    za_mtbl_un.set_etat_qcq() ;
    Mtbl xa_mtbl_deux (source_deux.get_mp().get_mg()) ;
    xa_mtbl_deux.set_etat_qcq() ;
    Mtbl ya_mtbl_deux (source_deux.get_mp().get_mg()) ;
    ya_mtbl_deux.set_etat_qcq() ;
    Mtbl za_mtbl_deux (source_deux.get_mp().get_mg()) ;
    za_mtbl_deux.set_etat_qcq() ;
    
    xa_mtbl_un = source_un.get_mp().xa ;
    ya_mtbl_un = source_un.get_mp().ya ;
    za_mtbl_un = source_un.get_mp().za ;
    
    xa_mtbl_deux = source_deux.get_mp().xa ;
    ya_mtbl_deux = source_deux.get_mp().ya ;
    za_mtbl_deux = source_deux.get_mp().za ;
    
    double xabs, yabs, zabs ;
    double air,  theta,  phi ;
    double valeur ;
    
    int nbrep_un = bound_x_un.get_mg()->get_np(num_front) ;
    int nbret_un = bound_x_un.get_mg()->get_nt(num_front) ;
    int nbrep_deux = bound_x_deux.get_mg()->get_np(num_front) ;
    int nbret_deux = bound_x_deux.get_mg()->get_nt(num_front) ;
    int nz_un = bound_x_un.get_mg()->get_nzone() ;
    int nz_deux = bound_x_deux.get_mg()->get_nzone() ;
    
    const Metric_flat& ff_un (source_un.get_mp().flat_met_cart()) ;
    const Metric_flat& ff_deux (source_deux.get_mp().flat_met_cart()) ;

    // La source de l'equation scalaire sur 1
    Vector cop_so_un (source_un) ;
    cop_so_un.dec_dzpuis(2) ;
    cop_so_un.dec_dzpuis(2) ;
    cop_so_un.change_triad(source_un.get_mp().get_bvect_cart()) ;

    
    Scalar source_scal_un (contract (cop_so_un.derive_cov(ff_un), 0, 1)/(lambda+1)) ;
    if (source_scal_un.get_etat() == ETATZERO) {
	source_scal_un.annule_hard() ;
	source_scal_un.std_spectral_base() ;
    }
    source_scal_un.inc_dzpuis(2) ;
    
    // La source de l'equation scalaire sur 2
    Vector cop_so_deux (source_deux) ;
    cop_so_deux.dec_dzpuis(2) ;
    cop_so_deux.dec_dzpuis(2) ;
    cop_so_deux.change_triad(source_deux.get_mp().get_bvect_cart()) ;
   
    Scalar source_scal_deux (contract (cop_so_deux.derive_cov(ff_deux), 0, 1)/(lambda+1)) ;
    if (source_scal_deux.get_etat() == ETATZERO) {
	source_scal_deux.annule_hard() ;
	source_scal_deux.std_spectral_base() ;
    }
    source_scal_deux.inc_dzpuis(2) ;
    
    // Les copies :
    Vector copie_so_un (source_un) ;
    copie_so_un.dec_dzpuis() ;
    copie_so_un.change_triad(source_un.get_mp().get_bvect_cart()) ;

    Vector copie_so_deux (source_deux) ;
    copie_so_deux.dec_dzpuis() ;
    copie_so_deux.change_triad(source_deux.get_mp().get_bvect_cart()) ;
    
    // ON COMMENCE LA BOUCLE :
    Vector sol_un_old (sol_un) ;
    Vector sol_deux_old (sol_deux) ;
    
    int indic = 1 ;
    int conte = 0 ;
    
    while (indic == 1) {
	
	// On resout les deux equations scalaires :
	Scalar chi_un (source_scal_un.poisson_dirichlet (limite_chi_un, num_front)) ;
	Scalar chi_deux (source_scal_deux.poisson_dirichlet (limite_chi_deux, num_front)) ;
	

	// On calcule les sources pour les equations vectorielles :
	Vector source_vect_un (copie_so_un) ;
	Vector grad_chi_un (chi_un.derive_con(ff_un)) ;
	grad_chi_un.inc_dzpuis() ;
	source_vect_un = source_vect_un - lambda*grad_chi_un ;
	

	Vector source_vect_deux (copie_so_deux) ;
	Vector grad_chi_deux (chi_deux.derive_con(ff_deux)) ;
	grad_chi_deux.inc_dzpuis() ;
	source_vect_deux = source_vect_deux - lambda*grad_chi_deux ;
	
	sol_un_old = sol_un ;
	sol_deux_old = sol_deux ;

	// On resout les equations vectorielles :
	sol_un.set(1) = source_vect_un(1).poisson_dirichlet (limite_x_un, num_front) ;
	sol_un.set(2) = source_vect_un(2).poisson_dirichlet (limite_y_un, num_front) ;
	sol_un.set(3) = source_vect_un(3).poisson_dirichlet (limite_z_un, num_front) ;
	sol_deux.set(1) = source_vect_deux(1).poisson_dirichlet (limite_x_deux, num_front) ;
	sol_deux.set(2) = source_vect_deux(2).poisson_dirichlet (limite_y_deux, num_front) ;
	sol_deux.set(3) = source_vect_deux(3).poisson_dirichlet (limite_z_deux, num_front) ;
	
	
	// On modifie les Cl sur chi :
	Scalar div_shift_un (contract(sol_un.derive_cov(ff_un), 0, 1)) ;
	div_shift_un.dec_dzpuis(2) ;
	div_shift_un.get_spectral_va().coef_i() ;
	
	limite_chi_un = 1 ; // Affectation
	for (int k=0 ; k<nbrep_un ; k++)
	    for (int j=0 ; j<nbret_un ; j++)
		limite_chi_un.set(num_front, k, j, 0) =
		    div_shift_un.get_spectral_va() (num_front+1, k, j, 0) ;
	limite_chi_un.std_base_scal() ;
	
	Scalar div_shift_deux (contract(sol_deux.derive_cov(ff_deux), 0, 1)) ;
	div_shift_deux.dec_dzpuis(2) ;
	div_shift_deux.get_spectral_va().coef_i() ;
	
	limite_chi_deux = 1 ; // Affectation
	for (int k=0 ; k<nbrep_deux ; k++)
	    for (int j=0 ; j<nbret_deux ; j++)
		limite_chi_deux.set(num_front, k, j, 0) =
		    div_shift_deux.get_spectral_va() (num_front+1, k, j, 0) ;
	limite_chi_deux.std_base_scal() ;
	
	
	// On modifie les Cl sur sol_un :
	for (int k=0 ; k<nbrep_un ; k++)
	    for (int j=0 ; j<nbret_un ; j++) {
		xabs = xa_mtbl_un (num_front+1, k, j, 0) ;
		yabs = ya_mtbl_un (num_front+1, k, j, 0) ;
		zabs = za_mtbl_un (num_front+1, k, j, 0) ;
		
		source_deux.get_mp().convert_absolute 
				(xabs, yabs, zabs, air, theta, phi) ;
		
		valeur = sol_deux(1).val_point(air, theta, phi) ;
		limite_x_un.set(num_front, k, j, 0) = 
			bound_x_un(num_front, k, j, 0) - same_orient*valeur ;
		
		valeur = sol_deux(2).val_point(air, theta, phi) ;
		limite_y_un.set(num_front, k, j, 0) = 
			bound_y_un(num_front, k, j, 0) - same_orient*valeur ;
		
		valeur = sol_deux(3).val_point(air, theta, phi) ;
		limite_z_un.set(num_front, k, j, 0) = 
			bound_z_un(num_front, k, j, 0) - valeur ;
	    }
	    
	// On modifie les Cl sur sol_deux :
	for (int k=0 ; k<nbrep_deux ; k++)
	    for (int j=0 ; j<nbret_deux ; j++) {
		xabs = xa_mtbl_deux (num_front+1, k, j, 0) ;
		yabs = ya_mtbl_deux (num_front+1, k, j, 0) ;
		zabs = za_mtbl_deux (num_front+1, k, j, 0) ;
		
		source_un.get_mp().convert_absolute 
				(xabs, yabs, zabs, air, theta, phi) ;
		
		valeur = sol_un(1).val_point(air, theta, phi) ;
		limite_x_deux.set(num_front, k, j, 0) = 
			bound_x_deux(num_front, k, j, 0) - same_orient*valeur ;
		
		valeur = sol_un(2).val_point(air, theta, phi) ;
		limite_y_deux.set(num_front, k, j, 0) = 
			bound_y_deux(num_front, k, j, 0) - same_orient*valeur ;
		
		valeur = sol_un(3).val_point(air, theta, phi) ;
		limite_z_deux.set(num_front, k, j, 0) = 
			bound_z_deux(num_front, k, j, 0) - valeur ;
	    }
	    
	double erreur = 0 ;
	
	for (int i=1 ; i<=3 ; i++) {
	    Tbl diff_un (diffrelmax (sol_un_old(i), sol_un(i))) ;
	    for (int j=num_front+1 ; j<nz_un ; j++)
		if (erreur<diff_un(j))
		    erreur = diff_un(j) ;
	}
	
	for (int i=1 ; i<=3 ; i++) {
	    Tbl diff_deux (diffrelmax (sol_deux_old(i), sol_deux(i))) ;
	    for (int j=num_front+1 ; j<nz_deux ; j++)
		if (erreur<diff_deux(j))
		    erreur = diff_deux(j) ;
	}
	
	cout << "Pas " << conte << " : Difference " << erreur << endl ;
	


/*
	maxabs(sol_un.derive_con(ff_un).divergence(ff_un) + lambda * sol_un.divergence(ff_un).derive_con(ff_un) - source_un,
	       "Absolute error in the resolution of the equation for beta") ;  
	cout << endl ;
*/
	

	if (erreur < precision)
	    indic = -1 ;
	conte ++ ;
	}
}
}