Debian Codegraph @

C++/Source/Metrique/metrique.C

raw
1 /*
2 * Methods of class Metrique
3 *
4 * (see file metrique.h for documentation)
5 *
6 */
7
8 /*
9 * Copyright (c) 1999-2001 Philippe Grandclement
10 * Copyright (c) 2002 Jerome Novak
11 *
12 * This file is part of LORENE.
13 *
14 * LORENE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * LORENE is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with LORENE; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 *
28 */
29
30
31 char metrique_C[] = "$Header: /cvsroot/Lorene/C++/Source/Metrique/metrique.C,v 1.17 2014/10/13 08:53:07 j_novak Exp $" ;
32
33 /*
34 * $Id: metrique.C,v 1.17 2014/10/13 08:53:07 j_novak Exp $
35 * $Log: metrique.C,v $
36 * Revision 1.17 2014/10/13 08:53:07 j_novak
37 * Lorene classes and functions now belong to the namespace Lorene.
38 *
39 * Revision 1.16 2014/10/06 15:13:14 j_novak
40 * Modified #include directives to use c++ syntax.
41 *
42 * Revision 1.15 2003/10/17 13:03:33 f_limousin
43 * Add new functions get_cov(), set_cov() and important changes in the functions set_cov() and set_con().
44 *
45 * Revision 1.14 2003/10/13 10:33:10 f_limousin
46 * *** empty log message ***
47 *
48 * Revision 1.13 2003/10/03 11:41:35 j_novak
49 * Display method corrected.
50 *
51 * Revision 1.12 2003/06/20 14:48:38 f_limousin
52 * The functions set_con() and set_cov() now return a Tenseur_sym&
53 *
54 * Revision 1.11 2003/03/03 19:43:50 f_limousin
55 * Add two new members : set_cov() and set_con().
56 *
57 * Revision 1.10 2003/02/12 18:30:44 f_limousin
58 * Added set_cov and set_con methods
59 *
60 * Revision 1.9 2002/10/16 14:36:42 j_novak
61 * Reorganization of #include instructions of standard C++, in order to
62 * use experimental version 3 of gcc.
63 *
64 * Revision 1.8 2002/08/14 15:31:17 j_novak
65 * The ZEC is now correctly treated in Metconf. A test code is added in
66 * Codes/Test/Metrique
67 *
68 * Revision 1.7 2002/08/14 13:46:15 j_novak
69 * Derived quantities of a Tenseur can now depend on several Metrique's
70 *
71 * Revision 1.6 2002/08/13 08:02:45 j_novak
72 * Handling of spherical vector/tensor components added in the classes
73 * Mg3d and Tenseur. Minor corrections for the class Metconf.
74 *
75 * Revision 1.5 2002/08/08 15:10:45 j_novak
76 * The flag "plat" has been added to the class Metrique to show flat metrics.
77 *
78 * Revision 1.4 2002/08/07 16:14:11 j_novak
79 * class Tenseur can now also handle tensor densities, this should be transparent to older codes
80 *
81 * Revision 1.3 2002/08/02 15:07:41 j_novak
82 * Member function determinant has been added to the class Metrique.
83 * A better handling of spectral bases is now implemented for the class Tenseur.
84 *
85 * Revision 1.2 2001/12/04 21:27:54 e_gourgoulhon
86 *
87 * All writing/reading to a binary file are now performed according to
88 * the big endian convention, whatever the system is big endian or
89 * small endian, thanks to the functions fwrite_be and fread_be
90 *
91 * Revision 1.1.1.1 2001/11/20 15:19:28 e_gourgoulhon
92 * LORENE
93 *
94 * Revision 2.2 2000/02/09 19:31:42 eric
95 * Ajout de l'argument triad dans le constructeur par lecture de fichier.
96 * La triade de decomposition doit desormais figurer en argument des
97 * constructeurs de Tenseur.
98 *
99 * Revision 2.1 2000/01/10 17:21:30 eric
100 * Modif des #include
101 *
102 * Revision 2.0 1999/12/02 17:19:15 phil
103 * *** empty log message ***
104 *
105 *
106 * $Header: /cvsroot/Lorene/C++/Source/Metrique/metrique.C,v 1.17 2014/10/13 08:53:07 j_novak Exp $
107 *
108 */
109
110 // Headers C
111 #include <cstdlib>
112 #include <cassert>
113 #include <cmath>
114
115 // Headers Lorene
116 #include "metrique.h"
117 #include "utilitaires.h"
118 #include "tenseur.h"
119
120 namespace Lorene {
121 //Constructeur standard (ne fait pas grand chose) :
122
123 Metrique::Metrique (const Map& mapping, bool plate) :
124 mp(&mapping), plat(plate) {
125
126 p_met_con = 0x0 ;
127 p_met_cov = 0x0 ;
128 set_der_0x0() ;
129 etat = ETATNONDEF ;
130
131 dependances = new (const Tenseur* [N_DEPEND]) ;
132 for (int i=0 ; i<N_DEPEND ; i++)
133 dependances[i] = 0x0 ;
134 }
135
136 // COPY :
137 Metrique::Metrique (const Metrique& source) : mp(source.mp),
138 plat(source.plat) {
139
140 if (source.p_met_con != 0x0)
141 p_met_con = new Tenseur_sym(*source.p_met_con) ;
142 else
143 p_met_con = 0x0 ;
144
145 if (source.p_met_cov != 0x0)
146 p_met_cov = new Tenseur_sym(*source.p_met_cov) ;
147 else
148 p_met_cov = 0x0 ;
149
150 if (source.p_gamma != 0x0)
151 p_gamma = new Tenseur_sym(*source.p_gamma) ;
152 else
153 p_gamma = 0x0 ;
154
155
156 if (source.p_ricci != 0x0)
157 p_ricci = new Tenseur_sym(*source.p_ricci) ;
158 else
159 p_ricci = 0x0 ;
160
161 if (source.p_ricci_scal != 0x0)
162 p_ricci_scal = new Tenseur(*source.p_ricci_scal) ;
163 else
164 p_ricci_scal = 0x0 ;
165
166 if (source.p_determinant != 0x0)
167 p_determinant = new Tenseur(*source.p_determinant) ;
168 else
169 p_determinant = 0x0 ;
170
171 dependances = new (const Tenseur* [N_DEPEND]) ;
172 for (int i=0 ; i<N_DEPEND ; i++)
173 dependances[i] = 0x0 ;
174 etat = source.etat ;
175 }
176
177
178 // Constructeur from Tensor d'ordre 2 symetrique :
179 Metrique::Metrique (const Tenseur_sym &source, bool plate) :
180 mp(source.get_mp()), plat(plate) {
181
182 assert (source.get_etat() != ETATNONDEF) ;
183 assert (source.get_valence() == 2) ;
184
185 // On regarde si on est en covariant ou contravariant ;
186 int tipe = source.get_type_indice(0) ;
187 assert (source.get_type_indice(1) == tipe) ;
188
189 if (tipe == CON) {
190 p_met_con = new Tenseur_sym (source) ;
191 p_met_cov = 0x0 ;
192 }
193 else {
194 p_met_cov = new Tenseur_sym (source) ;
195 p_met_con = 0x0 ;
196 }
197
198 set_der_0x0() ;
199 dependances = new (const Tenseur* [N_DEPEND]) ;
200 for (int i=0 ; i<N_DEPEND ; i++)
201 dependances[i] = 0x0 ;
202 etat = source.get_etat() ;
203 }
204
205 // From a file and a mapping :
206 Metrique::Metrique (const Map& mapping, const Base_vect& triad,
207 FILE* fd) : mp(&mapping){
208
209 fread_be (&etat, sizeof(int), 1, fd) ;
210 int plate ;
211 fread_be (&plate, sizeof(int), 1, fd) ;
212 plat = plate ;
213
214 p_met_cov = 0x0 ;
215 p_met_con = 0x0 ;
216 set_der_0x0() ;
217
218 if (etat == ETATQCQ) {
219 int indic ;
220 fread_be (&indic, sizeof(int), 1, fd) ;
221 switch (indic) {
222 case COV : {
223 p_met_cov = new Tenseur_sym(mapping, triad, fd) ;
224 break ;
225 }
226 case CON : {
227 p_met_con = new Tenseur_sym(mapping, triad, fd) ;
228 break ;
229 }
230 default :
231 break ;
232 }
233 }
234 dependances = new (const Tenseur* [N_DEPEND]) ;
235 for (int i=0 ; i<N_DEPEND ; i++)
236 dependances[i] = 0x0 ;
237 }
238
239 //Destructor :
240 Metrique::~Metrique() {
241 del_dependances() ;
242 delete [] dependances ;
243 del_t() ;
244 }
245
246 //Destructeur logique
247 void Metrique::del_t() {
248
249 if (p_met_con != 0x0) {
250 delete p_met_con ;
251 p_met_con = 0x0 ;
252 }
253
254 if (p_met_cov != 0x0) {
255 delete p_met_cov ;
256 p_met_cov = 0x0 ;
257 }
258
259 del_deriv() ;
260 etat = ETATNONDEF ;
261 }
262
263 void Metrique::del_deriv() {
264 if (p_gamma != 0x0)
265 delete p_gamma ;
266
267 if (p_ricci != 0x0)
268 delete p_ricci ;
269
270 if (p_ricci_scal != 0x0)
271 delete p_ricci_scal ;
272
273 if (p_determinant != 0x0)
274 delete p_determinant ;
275
276 set_der_0x0() ;
277 }
278
279 void Metrique::set_der_0x0() {
280 p_gamma = 0x0 ;
281 p_ricci = 0x0 ;
282 p_ricci_scal = 0x0 ;
283 p_determinant = 0x0 ;
284 }
285
286 void Metrique::del_dependances() {
287 for (int i=0 ; i<N_DEPEND ; i++)
288 if (dependances[i] != 0x0) {
289 int j = dependances[i]->get_place_met(*this) ;
290 if (j!=-1) dependances[i]->del_derive_met(j) ;
291 dependances[i] = 0x0 ;
292 }
293 }
294
295 void Metrique::set_etat_nondef() {
296
297 del_t() ;
298 del_dependances() ;
299 etat = ETATNONDEF ;
300 }
301
302 void Metrique::set_etat_zero() {
303
304 del_t() ;
305 del_dependances() ;
306 etat = ETATZERO ;
307 }
308
309
310 void Metrique::set_etat_con_qcq() {
311
312 del_dependances() ;
313 if (p_met_con == 0x0)
314 p_met_con = new Tenseur_sym (*mp, 2, CON, mp->get_bvect_cart()) ;
315
316 if (p_met_cov != 0x0) {
317 delete p_met_cov ;
318 p_met_cov = 0x0 ;
319 }
320
321 del_deriv() ;
322 etat = ETATQCQ ;
323 }
324
325
326 void Metrique::set_etat_cov_qcq() {
327
328 del_dependances() ;
329 if (p_met_cov == 0x0)
330 p_met_cov = new Tenseur_sym(*mp, 2, COV, mp->get_bvect_cart()) ;
331
332 if (p_met_con != 0x0) {
333 delete p_met_con ;
334 p_met_con = 0x0 ;
335 }
336
337 del_deriv() ;
338 etat = ETATQCQ ;
339 }
340
341
342 Cmp& Metrique::set_cov (int ind1, int ind2) {
343
344 assert ((ind1 >= 0) && (ind1 < 3)) ;
345 assert ((ind2 >= 0) && (ind2 < 3)) ;
346
347 del_dependances() ;
348 del_deriv() ;
349
350 if (p_met_cov == 0x0)
351 fait_cov() ;
352
353 if (p_met_con != 0x0) {
354 delete p_met_con ;
355 p_met_con = 0x0 ;
356 }
357
358 return p_met_cov->set(ind1, ind2);
359
360 }
361
362
363 Cmp& Metrique::set_con (int ind1, int ind2) {
364
365 assert ((ind1 >= 0) && (ind1 < 3)) ;
366 assert ((ind2 >= 0) && (ind2 < 3)) ;
367
368 del_dependances() ;
369 del_deriv() ;
370
371 if (p_met_con == 0x0)
372 fait_con() ;
373
374 if (p_met_cov != 0x0) {
375 delete p_met_cov ;
376 p_met_cov = 0x0 ;
377 }
378
379 return p_met_con->set(ind1, ind2);
380
381 }
382
383
384 const Cmp& Metrique::get_cov (int ind1, int ind2) const {
385
386 assert ((ind1 >= 0) && (ind1 < 3)) ;
387 assert ((ind2 >= 0) && (ind2 < 3)) ;
388
389 if (p_met_cov == 0x0)
390 fait_cov() ;
391
392 return p_met_cov->set(ind1, ind2) ;
393 }
394
395
396 const Cmp& Metrique::get_con (int ind1, int ind2) const {
397
398 assert ((ind1 >= 0) && (ind1 < 3)) ;
399 assert ((ind2 >= 0) && (ind2 < 3)) ;
400
401 if (p_met_con == 0x0)
402 fait_con() ;
403
404 return p_met_con->set(ind1, ind2);
405 }
406
407
408 Tenseur_sym& Metrique::set_cov () {
409
410 del_dependances() ;
411 del_deriv() ;
412
413 if (p_met_cov == 0x0)
414 fait_cov() ;
415
416 if (p_met_con != 0x0) {
417 delete p_met_con ;
418 p_met_con = 0x0 ;
419 }
420
421 return *(p_met_cov) ;
422
423 }
424
425 Tenseur_sym& Metrique::set_con () {
426
427 del_dependances() ;
428 del_deriv() ;
429
430 if (p_met_con == 0x0)
431 fait_con() ;
432
433 if (p_met_cov != 0x0) {
434 delete p_met_cov ;
435 p_met_cov = 0x0 ;
436 }
437
438 return *(p_met_con) ;
439
440 }
441
442 const Tenseur_sym& Metrique::get_cov () const {
443
444 if (p_met_cov == 0x0)
445 fait_cov() ;
446
447 return *(p_met_cov) ;
448 }
449
450 const Tenseur_sym& Metrique::get_con () const {
451
452 if (p_met_con == 0x0)
453 fait_con() ;
454
455 return *(p_met_con) ;
456 }
457
458
459
460 //AFFECTATIONS :
461
462 void Metrique::operator= (const Metrique& source) {
463
464 assert(source.etat != ETATNONDEF) ;
465 // Sur la meme grille ?
466 assert (source.mp == mp) ;
467
468 del_dependances() ;
469 del_t() ;
470
471 plat = source.plat ;
472 if (source.etat == ETATZERO)
473 set_etat_zero() ;
474 else {
475 if (source.p_met_con != 0x0)
476 p_met_con = new Tenseur_sym (*source.p_met_con) ;
477 if (source.p_met_cov != 0x0)
478 p_met_cov = new Tenseur_sym (*source.p_met_cov) ;
479 if (source.p_gamma != 0x0)
480 p_gamma = new Tenseur_sym (*source.p_gamma) ;
481 if (source.p_ricci != 0x0)
482 p_ricci = new Tenseur_sym(*source.p_ricci) ;
483 if (source.p_ricci_scal != 0x0)
484 p_ricci_scal = new Tenseur(*source.p_ricci_scal) ;
485 if (source.p_determinant != 0x0)
486 p_determinant = new Tenseur(*source.p_determinant) ;
487 etat = ETATQCQ ;
488 }
489 }
490
491
492 void Metrique::operator= (const Tenseur_sym& source) {
493
494 assert (source.get_etat() != ETATNONDEF) ;
495 // Sur la meme grille ?
496 assert (source.get_mp() == mp) ;
497
498 del_dependances() ;
499 del_t() ;
500
501 assert (source.get_valence() == 2) ;
502 int tipe = source.get_type_indice(0) ;
503 assert (source.get_type_indice(1) == tipe) ;
504
505 if (tipe == COV)
506 p_met_cov = new Tenseur_sym (source) ;
507 else
508 p_met_con = new Tenseur_sym (source) ;
509
510 etat = source.get_etat() ;
511 }
512
513
514 // Le cout :
515 ostream& operator<<(ostream& flux, const Metrique & source) {
516
517 switch (source.etat) {
518
519 case ETATNONDEF : {
520 flux << "Undefined metric in operator << ." << endl ;
521 break ;
522 }
523 case ETATZERO : {
524 flux << "Nul metric." << endl ;
525 break ;
526 }
527
528 case ETATQCQ : {
529
530 if (source.plat) flux << "Flat metric" << endl ;
531 if (source.p_met_con != 0x0) {
532 flux << "CONTRA-variant representation : " << endl ;
533 flux << *source.p_met_con << endl ;
534 flux << "-------------------------------------------" << endl ;
535 }
536 else
537 flux << "CONTRA-variant representation unknown : " << endl ;
538
539 if (source.p_met_cov != 0x0) {
540 flux << "CO-variant representation : " << endl ;
541 flux << *source.p_met_cov << endl ;
542 flux << "-------------------------------------------" << endl ;
543 }
544 else
545 flux << "CO-variant representation unknown : " << endl ;
546
547 if (source.p_gamma == 0x0)
548 flux << "Christoffel unknown." << endl ;
549 else
550 flux << "Christoffel known." << endl ;
551
552 if (source.p_ricci == 0x0)
553 flux << "Ricci unknown." << endl ;
554 else
555 flux << "Ricci known." << endl ;
556
557 if (source.p_ricci_scal == 0x0)
558 flux << "Ricci scalar unknown." << endl ;
559 else
560 flux << "Ricci scalar known." << endl ;
561
562 if (source.p_determinant == 0x0)
563
564
565 flux << "determinant unknown." << endl ;
566 else
567 flux << "determinant known." << endl ;
568 break ;
569 }
570 default : {
571 abort() ;
572 break ;
573 }
574 }
575 return flux ;
576 }
577
578 void Metrique::sauve(FILE* fd) const {
579
580 fwrite_be(&etat, sizeof(int), 1, fd) ;
581 int plate = plat ;
582 fwrite_be(&plate, sizeof(int), 1, fd) ;
583
584 if (etat == ETATQCQ) {
585
586 // Dis ce que l'on a sauve ...
587 int indic ;
588 if (p_met_cov != 0x0)
589 indic = COV ;
590 else if (p_met_con != 0x0)
591 indic = CON ;
592 else indic = 0 ;
593 fwrite_be(&indic, sizeof(int), 1, fd) ;
594 switch (indic) {
595 case COV : {
596 p_met_cov->sauve(fd) ;
597 break ;
598 }
599 case CON : {
600 p_met_con->sauve(fd) ;
601 break ;
602 }
603 default : {
604 break ;
605 }
606 }
607 }
608 }
609
610
611 // Gestion des bases spectrales :
612 void Metrique:: set_std_base() {
613
614 del_deriv() ;
615 if (p_met_con != 0x0)
616 p_met_con->set_std_base() ;
617
618 if (p_met_cov != 0x0)
619 p_met_cov->set_std_base() ;
620 }
621
622
623
624 // LES ROUTINES D'INVERSION ...
625 void Metrique::fait_con() const {
626
627 if (p_met_con != 0x0)
628 return ;
629 else
630 if (p_met_cov == 0x0) {
631 cout << "Covariant representation unknown. " << endl ;
632 abort() ;
633 }
634
635 else
636 p_met_con = new Tenseur_sym (fait_inverse(*p_met_cov)) ;
637 }
638
639 void Metrique::fait_cov() const {
640
641 if (p_met_cov != 0x0)
642 return ;
643 else
644 if (p_met_con == 0x0) {
645 cout << "Contravariant representation unknown. " << endl ;
646 abort() ;
647 }
648
649 else
650 p_met_cov = new Tenseur_sym(fait_inverse(*p_met_con)) ;
651
652 }
653
654
655
656
657 // Le calcul des Christoffel, cas general :
658 void Metrique::fait_gamma() const {
659
660 assert (etat != ETATNONDEF) ;
661 if (p_gamma != 0x0)
662 return ;
663
664 else // Calcul a faire :
665 {
666 Itbl tipe (3) ;
667 tipe.set_etat_qcq() ;
668 tipe.set(0) = CON ; tipe.set(1) = COV ; tipe.set(2) = COV ;
669 p_gamma = new Tenseur_sym (*mp, 3, tipe, mp->get_bvect_cart() ) ;
670 bool cart = cov().get_triad()->identify() ==
671 (mp->get_bvect_cart()).identify() ;
672
673 if ( (etat == ETATZERO) || (plat && cart) )
674 p_gamma->set_etat_zero() ;
675 else {
676 p_gamma->set_etat_qcq() ;
677
678 Tenseur t1 (contract(con(), 1, cov().gradient(), 2)) ;
679 Tenseur t2 (contract(con(), 1, cov().gradient(), 0)) ;
680
681 Cmp auxi(mp) ;
682
683 // Boucle sur les composantes :
684 for (int i=0 ; i<3 ; i++)
685 for (int j=0 ; j<3 ; j++)
686 for (int k=j ; k<3 ; k++) {
687 auxi = 0.5*(t1(i, j, k)+t1(i, k, j)-t2(i, j, k)) ;
688 p_gamma->set(i, j, k) = auxi ;
689 }
690 }
691 }
692 }
693
694
695 // Calcul de ricci :
696 void Metrique::fait_ricci() const {
697
698 assert(etat != ETATNONDEF) ;
699 if (p_ricci != 0x0)
700 return ;
701
702 else {
703 p_ricci = new Tenseur_sym (*mp, 2, COV, mp->get_bvect_cart() ) ;
704 if ( (etat == ETATZERO) || (plat) )
705 p_ricci->set_etat_zero() ;
706 else {
707
708 p_ricci->set_etat_qcq() ;
709
710 Tenseur_sym copie_gamma(gamma()) ;
711 copie_gamma.dec2_dzpuis() ;
712 Tenseur_sym grad(copie_gamma.gradient()) ;
713 grad.inc_dzpuis() ;
714
715 Tenseur_sym T1 (contract(grad, 0, 1)) ;
716
717 Tenseur_sym T2 (contract(grad, 1, 2)) ;
718
719 Tenseur auxi_un (contract(gamma(), 0, 2)) ;
720 Tenseur_sym T3 (contract(auxi_un, 0, gamma(), 0)) ;
721 T3.dec_dzpuis() ;
722
723 Tenseur auxi_deux (contract(gamma(), 1, gamma(), 0)) ;
724 Tenseur_sym T4 (contract(auxi_deux, 0, 3)) ;
725 T4.dec_dzpuis() ;
726
727 *p_ricci = T1-T2+T3-T4 ;
728 }
729 }
730 }
731
732 // Calcul du scalaire de ricci :
733 void Metrique::fait_ricci_scal() const {
734
735 assert(etat != ETATNONDEF) ;
736 if (p_ricci_scal != 0x0)
737 return ;
738
739 else {
740
741 p_ricci_scal = new Tenseur(*mp) ; // Il s'agit d'un scalaire ...
742 if ( (etat == ETATZERO) || (plat) )
743 p_ricci_scal->set_etat_zero() ;
744 else {
745
746 p_ricci_scal->set_etat_qcq() ;
747 Tenseur auxi(contract(con(), 1, ricci(), 1)) ;
748 *p_ricci_scal = contract(auxi, 0, 1) ;
749 }
750 }
751 }
752
753
754 // Calcul du determinant :
755 void Metrique::fait_determinant() const {
756
757 assert(etat != ETATNONDEF) ;
758 if (p_determinant != 0x0)
759 return ;
760
761 else {
762
763 p_determinant = new Tenseur(*mp, this, 2) ;
764 if (etat == ETATZERO)
765 p_determinant->set_etat_zero() ;
766 else {
767
768 p_determinant->set_etat_qcq() ;
769
770 p_determinant->set() = cov()(0, 0)*cov()(1, 1)*cov()(2, 2)
771 + cov()(0, 1)*cov()(1, 2)*cov()(2, 0)
772 + cov()(0, 2)*cov()(1, 0)*cov()(2, 1)
773 - cov()(2, 0)*cov()(1, 1)*cov()(0, 2)
774 - cov()(2, 1)*cov()(1, 2)*cov()(0, 0)
775 - cov()(2, 2)*cov()(1, 0)*cov()(0, 1) ;
776 }
777 }
778 }
779
780
781 Tenseur_sym fait_inverse (const Tenseur_sym& s) {
782
783 assert (s.get_etat() == ETATQCQ) ;
784 assert (s.get_valence() == 2) ;
785 assert (s.get_type_indice(0) == s.get_type_indice(1)) ;
786
787 //Le resultat :
788 Tenseur_sym res (*s.get_mp(), 2, -s.get_type_indice(0), *(s.get_triad()),
789 s.get_metric(), -s.get_poids() ) ;
790 res.set_etat_qcq() ;
791
792 // le determinant :
793 Cmp determ1(s.get_mp()) ;
794 determ1 = double(1)/(s(0, 0)*s(1, 1)*s(2, 2)+s(0, 1)*s(1, 2)*s(0, 2)
795 +s(0, 2)*s(0, 1)*s(1, 2)-s(0, 2)*s(1, 1)*s(0, 2)
796 -s(1, 2)*s(1, 2)*s(0, 0)-s(2, 2)*s(0, 1)*s(0, 1)) ;
797
798 int sgn ; // Le signe du co-facteur ...
799 int l_up, l_down, c_left, c_right ; // Coordonnees du cofacteur :
800
801 Cmp cofacteur(s.get_mp()) ;
802
803 for (int i=0 ; i<3 ; i++) {
804 sgn = 1 ;
805 for (int j=i ; j<3 ; j++) {
806
807 switch (j) {
808
809 case 0 : {
810 c_left = 1 ;
811 c_right = 2 ;
812 break ;
813 }
814 case 1 : {
815 c_left = 0 ;
816 c_right = 2 ;
817 break ;
818 }
819 default : {
820 c_left = 0 ;
821 c_right = 1 ;
822 break ;
823 }
824 }
825
826 switch (i) {
827
828 case 0 : {
829 l_up = 1 ;
830 l_down = 2 ;
831 break ;
832 }
833 case 1 : {
834 l_up = 0 ;
835 l_down = 2 ;
836 break ;
837 }
838 default : {
839 l_up = 0 ;
840 l_down = 1 ;
841 break ;
842 }
843 }
844
845 cofacteur = sgn*(s(l_up, c_left)*s(l_down, c_right)-
846 s(l_up, c_right)*s(l_down, c_left))*determ1 ;
847
848 res.set(i, j) = cofacteur ;
849 sgn *= -1 ;
850 }
851 }
852 return res ;
853 }
854
855 const Tenseur_sym& Metrique::con() const{
856 if (p_met_con == 0x0)
857 fait_con() ;
858 return *p_met_con ;
859 }
860
861 const Tenseur_sym& Metrique::cov() const{
862 if (p_met_cov == 0x0)
863 fait_cov() ;
864 return *p_met_cov ;
865 }
866
867 const Tenseur_sym& Metrique::gamma() const{
868 if (p_gamma == 0x0)
869 fait_gamma() ;
870 return *p_gamma ;
871 }
872
873 const Tenseur_sym& Metrique::ricci() const{
874 if (p_ricci == 0x0)
875 fait_ricci() ;
876 return *p_ricci ;
877 }
878
879 const Tenseur& Metrique::ricci_scal() const{
880 if (p_ricci_scal == 0x0)
881 fait_ricci_scal() ;
882 return *p_ricci_scal ;
883 }
884
885 const Tenseur& Metrique::determinant() const{
886 if (p_determinant == 0x0)
887 fait_determinant() ;
888 return *p_determinant ;
889 }
890 }