Debian Codegraph @

C++/Source/Connection/connection.C

raw
1 /*
2 * Methods of class Connection.
3 *
4 * (see file connection.h for documentation)
5 *
6 */
7
8 /*
9 * Copyright (c) 2003-2004 Eric Gourgoulhon & Jerome Novak
10 *
11 * This file is part of LORENE.
12 *
13 * LORENE is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation.
16 *
17 * LORENE is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with LORENE; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28 char connection_C[] = "$Header: /cvsroot/Lorene/C++/Source/Connection/connection.C,v 1.19 2014/10/13 08:52:49 j_novak Exp $" ;
29
30 /*
31 * $Id: connection.C,v 1.19 2014/10/13 08:52:49 j_novak Exp $
32 * $Log: connection.C,v $
33 * Revision 1.19 2014/10/13 08:52:49 j_novak
34 * Lorene classes and functions now belong to the namespace Lorene.
35 *
36 * Revision 1.18 2014/10/06 15:13:04 j_novak
37 * Modified #include directives to use c++ syntax.
38 *
39 * Revision 1.17 2004/02/18 18:44:22 e_gourgoulhon
40 * Method Tensor::scontract renammed Tensor::trace.
41 *
42 * Revision 1.16 2004/01/29 15:21:51 e_gourgoulhon
43 * First implementation of method p_divergence.
44 *
45 * Revision 1.15 2004/01/23 07:58:38 e_gourgoulhon
46 * Method p_derive_cov: treatment of dzpuis: entry with dzpuis = 2 is now
47 * allowed (output: dzpuis=3).
48 *
49 * Revision 1.14 2004/01/22 16:15:53 e_gourgoulhon
50 * First operational version of ricci().
51 *
52 * Revision 1.13 2004/01/19 16:57:44 e_gourgoulhon
53 * First implementation of method ricci().
54 * Not tested yet.
55 *
56 * Revision 1.12 2004/01/13 21:33:33 e_gourgoulhon
57 * Corrected a bug in method p_derive_cov: inverted case CON and case COV.
58 *
59 * Revision 1.11 2004/01/04 20:57:51 e_gourgoulhon
60 * -- Data member delta is now of type Tensor_sym (and no longer
61 * Tensor_delta).
62 * -- Better handling of tensor symmetries in method p_derive_cov().
63 *
64 * Revision 1.10 2004/01/01 11:24:04 e_gourgoulhon
65 * Full reorganization of method p_derive_cov: the main loop is now
66 * on the indices of the *output* tensor (to take into account
67 * symmetries in the input and output tensors).
68 *
69 * Revision 1.9 2003/12/30 22:58:27 e_gourgoulhon
70 * -- Replaced member flat_conn (flat connection) by flat_met (flat metric)
71 * -- Added argument flat_met to the constructors of Connection.
72 * -- Suppressed method fait_ricci() (the computation of the Ricci is
73 * now devoted to the virtual method ricci()).
74 * -- Implementation of methods fait_delta() and derive_cov().
75 *
76 * Revision 1.8 2003/12/27 14:59:05 e_gourgoulhon
77 * Method derive_cov() suppressed.
78 *
79 * Revision 1.7 2003/10/16 14:21:36 j_novak
80 * The calculation of the divergence of a Tensor is now possible.
81 *
82 * Revision 1.6 2003/10/11 14:39:49 e_gourgoulhon
83 * Suppressed declaration of unusued arguments in some methods.
84 *
85 * Revision 1.5 2003/10/06 13:58:46 j_novak
86 * The memory management has been improved.
87 * Implementation of the covariant derivative with respect to the exact Tensor
88 * type.
89 *
90 * Revision 1.4 2003/10/03 14:16:04 e_gourgoulhon
91 * Added set_der_0x0 in some constructors.
92 *
93 * Revision 1.3 2003/10/02 21:32:06 e_gourgoulhon
94 * Added constructor from Metric.
95 * Added functions fait_delta and update.
96 *
97 * Revision 1.2 2003/10/01 15:42:49 e_gourgoulhon
98 * still ongoing...
99 *
100 * Revision 1.1 2003/09/29 21:13:08 e_gourgoulhon
101 * First version --- not ready yet.
102 *
103 *
104 *
105 *
106 * $Header: /cvsroot/Lorene/C++/Source/Connection/connection.C,v 1.19 2014/10/13 08:52:49 j_novak Exp $
107 *
108 */
109
110 // C++ headers
111 #include "headcpp.h"
112
113 // C headers
114 #include <cstdlib>
115
116 // Lorene headers
117 #include "connection.h"
118 #include "metric.h"
119
120
121 //-----------------------//
122 // Constructors //
123 //-----------------------//
124
125
126 // Constructor ab initio
127
128 namespace Lorene {
129 Connection::Connection(const Tensor_sym& delta_i,
130 const Metric_flat& flat_met_i)
131 : mp(&(delta_i.get_mp())),
132 triad(delta_i.get_triad()),
133 delta(delta_i),
134 assoc_metric(false),
135 flat_met(&flat_met_i) {
136
137 assert( delta_i.get_valence() == 3 ) ;
138 assert( delta_i.sym_index1() == 1 ) ;
139 assert( delta_i.sym_index2() == 2 ) ;
140 assert( delta_i.get_index_type(0) == CON ) ;
141 assert( delta_i.get_index_type(1) == COV ) ;
142 assert( delta_i.get_index_type(2) == COV ) ;
143
144 set_der_0x0() ;
145 }
146
147
148 // Standard constructor from a metric.
149
150 Connection::Connection(const Metric& met,
151 const Metric_flat& flat_met_i)
152 : mp(&(met.get_mp())),
153 triad(met.cov().get_triad()),
154 delta(*mp, CON, COV, COV, *triad, 1, 2),
155 assoc_metric(true),
156 flat_met(&flat_met_i) {
157
158 fait_delta(met) ; // Computes delta
159
160 set_der_0x0() ;
161 }
162
163
164 // Copy constructor
165
166 Connection::Connection(const Connection& conn_i) : mp(conn_i.mp),
167 triad(conn_i.triad),
168 delta(conn_i.delta),
169 assoc_metric(conn_i.assoc_metric),
170 flat_met(conn_i.flat_met) {
171
172 set_der_0x0() ;
173
174 }
175
176
177 // Constructor for derived classes
178
179 Connection::Connection(const Map& mpi, const Base_vect& bi) : mp(&mpi),
180 triad(&bi),
181 delta(mpi, CON, COV, COV, bi, 1, 2),
182 assoc_metric(false),
183 flat_met(0x0){
184
185 set_der_0x0() ;
186
187 }
188
189
190
191 //-----------------------//
192 // Destructor //
193 //-----------------------//
194
195 Connection::~Connection(){
196
197 del_deriv() ;
198
199 }
200
201 //-----------------------------//
202 // Memory management //
203 //-----------------------------//
204
205 void Connection::del_deriv() const {
206
207 if (p_ricci != 0x0) delete p_ricci ;
208
209 set_der_0x0() ;
210
211 }
212
213 void Connection::set_der_0x0() const {
214
215 p_ricci = 0x0 ;
216
217 }
218
219
220 //-----------------------------//
221 // Mutators / assignment //
222 //-----------------------------//
223
224
225 void Connection::operator=(const Connection& ci) {
226
227 assert( triad == ci.triad ) ;
228 delta = ci.delta ;
229 flat_met = ci.flat_met ;
230
231 del_deriv() ;
232
233 }
234
235 void Connection::update(const Tensor_sym& delta_i) {
236
237 assert(assoc_metric == false) ;
238
239 assert(flat_met != 0x0) ; // to guarantee we are not in a derived class
240
241 assert( delta_i.get_valence() == 3 ) ;
242 assert( delta_i.sym_index1() == 1 ) ;
243 assert( delta_i.sym_index2() == 2 ) ;
244 assert( delta_i.get_index_type(0) == CON ) ;
245 assert( delta_i.get_index_type(1) == COV ) ;
246 assert( delta_i.get_index_type(2) == COV ) ;
247
248 delta = delta_i ;
249
250 del_deriv() ;
251
252 }
253
254
255 void Connection::update(const Metric& met) {
256
257 assert(assoc_metric == true) ;
258
259 assert(flat_met != 0x0) ; // to guarantee we are not in a derived class
260
261 fait_delta(met) ;
262
263 del_deriv() ;
264
265 }
266
267
268
269 //-----------------------------//
270 // Computational methods //
271 //-----------------------------//
272
273
274 //--------------------------------------
275 // Computation of the Delta coefficients
276 //--------------------------------------
277
278 void Connection::fait_delta(const Metric& gam) {
279
280 assert(flat_met != 0x0) ;
281
282 const Tensor& dgam = gam.cov().derive_cov(*flat_met) ;
283
284 for (int k=1; k<=3; k++) {
285 for (int i=1; i<=3; i++) {
286 for (int j=1; j<=i; j++) {
287 Scalar& cc = delta.set(k,i,j) ;
288 cc = 0 ;
289 for (int l=1; l<=3; l++) {
290 cc += gam.con()(k,l) * (
291 dgam(l,j,i) + dgam(i,l,j) - dgam(i,j,l) ) ;
292
293 }
294 cc = 0.5 * cc ;
295 }
296 }
297 }
298
299
300 }
301
302
303 //---------------------
304 // Covariant derivative
305 //---------------------
306
307 Tensor* Connection::p_derive_cov(const Tensor& uu) const {
308
309 // Notations: suffix 0 in name <=> input tensor
310 // suffix 1 in name <=> output tensor
311
312 int valence0 = uu.get_valence() ;
313 int valence1 = valence0 + 1 ;
314 int valence1m1 = valence1 - 1 ; // same as valence0, but introduced for
315 // the sake of clarity
316 int ncomp0 = uu.get_n_comp() ;
317
318 // Protections
319 // -----------
320 if (valence0 >= 1) {
321 assert(uu.get_triad() == triad) ;
322 }
323 assert(flat_met != 0x0) ;
324
325 // Creation of the result (pointer)
326 // --------------------------------
327 Tensor* resu ;
328
329 // If uu is a Scalar, the result is a Vector
330 if (valence0 == 0)
331 resu = new Vector(*mp, COV, triad) ;
332 else {
333
334 // Type of indices of the result :
335 Itbl tipe(valence1) ;
336 const Itbl& tipeuu = uu.get_index_type() ;
337 for (int id = 0; id<valence0; id++) {
338 tipe.set(id) = tipeuu(id) ; // First indices = same as uu
339 }
340 tipe.set(valence1m1) = COV ; // last index is the derivation index
341
342 // if uu is a Tensor_sym, the result is also a Tensor_sym:
343 const Tensor* puu = &uu ;
344 const Tensor_sym* puus = dynamic_cast<const Tensor_sym*>(puu) ;
345 if ( puus != 0x0 ) { // the input tensor is symmetric
346 resu = new Tensor_sym(*mp, valence1, tipe, *triad,
347 puus->sym_index1(), puus->sym_index2()) ;
348 }
349 else {
350 resu = new Tensor(*mp, valence1, tipe, *triad) ; // no symmetry
351 }
352 }
353
354 int ncomp1 = resu->get_n_comp() ;
355
356 Itbl ind1(valence1) ; // working Itbl to store the indices of resu
357 Itbl ind0(valence0) ; // working Itbl to store the indices of uu
358 Itbl ind(valence0) ; // working Itbl to store the indices of uu
359
360 Scalar tmp(*mp) ; // working scalar
361
362 // Determination of the dzpuis parameter of the input --> dz_in
363 // ---------------------------------------------------
364 int dz_in = 0 ;
365 for (int ic=0; ic<ncomp0; ic++) {
366 int dzp = uu(uu.indices(ic)).get_dzpuis() ;
367 assert(dzp >= 0) ;
368 if (dzp > dz_in) dz_in = dzp ;
369 }
370
371 #ifndef NDEBUG
372 // Check : do all components have the same dzpuis ?
373 for (int ic=0; ic<ncomp0; ic++) {
374 if ( !(uu(uu.indices(ic)).check_dzpuis(dz_in)) ) {
375 cout << "######## WARNING #######\n" ;
376 cout << " Connection::p_derive_cov : the tensor components \n"
377 << " do not have all the same dzpuis ! : \n"
378 << " ic, dzpuis(ic), dz_in : " << ic << " "
379 << uu(uu.indices(ic)).get_dzpuis() << " " << dz_in << endl ;
380 }
381 }
382 #endif
383
384
385 // Initialisation to the flat derivative
386 // -------------------------------------
387
388 *resu = uu.derive_cov(*flat_met) ;
389
390 // Addition of the Delta terms
391 // ----------------------------
392 // loop on all the components of the output tensor
393 for (int ic=0; ic<ncomp1; ic++) {
394
395 // indices corresponding to the component no. ic in the output tensor
396 ind1 = resu->indices(ic) ;
397
398 // Indices of the input tensor
399 for (int id = 0; id < valence0; id++) {
400 ind0.set(id) = ind1(id) ;
401 }
402
403 // Value of last index (derivation index)
404 int k = ind1(valence1m1) ;
405
406 tmp = 0 ;
407
408 // Loop on the number of indices of uu
409 for (int id=0; id<valence0; id++) {
410
411 ind = ind0 ;
412
413 switch( uu.get_index_type(id) ) {
414
415 case CON : {
416 for (int l=1; l<=3; l++) {
417 ind.set(id) = l ;
418 tmp += delta(ind0(id), k, l) * uu(ind) ;
419 }
420 break ;
421 }
422
423 case COV : {
424 for (int l=1; l<=3; l++) {
425 ind.set(id) = l ;
426 tmp -= delta(l, k, ind0(id)) * uu(ind) ;
427 }
428 break ;
429 }
430
431 default : {
432 cerr <<
433 "Connection::p_derive_cov : unexpected type of index !\n" ;
434 abort() ;
435 break ;
436 }
437
438 } // end of switch on index type
439
440 } // end of loop on the number of indices of uu
441
442
443 if (dz_in > 0) tmp.dec_dzpuis() ; // to get the same dzpuis as
444 // the flat covariant derivative
445
446 resu->set(ind1) += tmp ; // addition to the flat derivative part
447
448 } // end of loop on all the components of the output tensor
449
450 // C'est fini !
451 // ------------
452
453 return resu ;
454
455 }
456
457
458
459 //---------------------------------
460 // Divergence, returning a pointer.
461 //---------------------------------
462
463 Tensor* Connection::p_divergence(const Tensor& uu) const {
464
465
466 // Notations: suffix 0 in name <=> input tensor
467 // suffix 1 in name <=> output tensor
468
469 int valence0 = uu.get_valence() ;
470 int valence1 = valence0 - 1 ;
471 int valence0m1 = valence0 - 1 ; // same as valence1 but introduced for
472 // the sake of clarity
473 int ncomp0 = uu.get_n_comp() ;
474
475 // Protections
476 // -----------
477 assert (valence0 >= 1) ;
478 assert (uu.get_triad() == triad) ;
479
480 // Last index must be contravariant:
481 assert (uu.get_index_type(valence0m1) == CON) ;
482
483
484 // Creation of the pointer on the result tensor
485 // --------------------------------------------
486 Tensor* resu ;
487
488 if (valence0 == 1) // if u is a Vector, the result is a Scalar
489 resu = new Scalar(*mp) ;
490 else {
491
492 // Type of indices of the result :
493 Itbl tipe(valence1) ;
494 const Itbl& tipeuu = uu.get_index_type() ;
495 for (int id = 0; id<valence1; id++) {
496 tipe.set(id) = tipeuu(id) ; // type of remaining indices =
497 } // same as uu indices
498
499 if (valence0 == 2) { // if u is a rank 2 tensor, the result is a Vector
500 resu = new Vector(*mp, tipe(0), *triad) ;
501 }
502 else {
503 // if uu is a Tensor_sym, the result might be also a Tensor_sym:
504 const Tensor* puu = &uu ;
505 const Tensor_sym* puus = dynamic_cast<const Tensor_sym*>(puu) ;
506 if ( puus != 0x0 ) { // the input tensor is symmetric
507
508 if (puus->sym_index2() != valence0 - 1) {
509
510 // the symmetry is preserved:
511
512 if (valence1 == 2) {
513 resu = new Sym_tensor(*mp, tipe, *triad) ;
514 }
515 else {
516 resu = new Tensor_sym(*mp, valence1, tipe, *triad,
517 puus->sym_index1(), puus->sym_index2()) ;
518 }
519 }
520 else { // the symmetry is lost:
521
522 resu = new Tensor(*mp, valence1, tipe, *triad) ;
523 }
524 }
525 else { // no symmetry in the input tensor:
526 resu = new Tensor(*mp, valence1, tipe, *triad) ;
527 }
528 }
529
530 }
531
532 int ncomp1 = resu->get_n_comp() ;
533
534 Itbl ind0(valence0) ; // working Itbl to store the indices of uu
535 Itbl ind1(valence1) ; // working Itbl to store the indices of resu
536 Itbl ind(valence0) ; // working Itbl to store the indices of uu
537
538 Scalar tmp(*mp) ; // working scalar
539
540
541 // Determination of the dzpuis parameter of the input --> dz_in
542 // ---------------------------------------------------
543 int dz_in = 0 ;
544 for (int ic=0; ic<ncomp0; ic++) {
545 int dzp = uu(uu.indices(ic)).get_dzpuis() ;
546 assert(dzp >= 0) ;
547 if (dzp > dz_in) dz_in = dzp ;
548 }
549
550 #ifndef NDEBUG
551 // Check : do all components have the same dzpuis ?
552 for (int ic=0; ic<ncomp0; ic++) {
553 if ( !(uu(uu.indices(ic)).check_dzpuis(dz_in)) ) {
554 cout << "######## WARNING #######\n" ;
555 cout << " Connection::p_divergence : the tensor components \n"
556 << " do not have all the same dzpuis ! : \n"
557 << " ic, dzpuis(ic), dz_in : " << ic << " "
558 << uu(uu.indices(ic)).get_dzpuis() << " " << dz_in << endl ;
559 }
560 }
561 #endif
562
563 // The 1-form Delta^k_{lk} is required
564 // -----------------------------------
565
566 Vector delta_trace = delta.trace(0,2) ; // Delta^k_{lk}
567
568 // Initialisation to the flat divergence
569 // -------------------------------------
570
571 *resu = uu.divergence(*flat_met) ;
572
573
574 // Addition of the Delta terms
575 // ----------------------------
576 // loop on all the components of the output tensor
577 for (int ic=0; ic<ncomp1; ic++) {
578
579 // indices corresponding to the component no. ic in the output tensor
580 ind1 = resu->indices(ic) ;
581
582 // Indices of the input tensor (but the last one)
583 for (int id = 0; id < valence1; id++) {
584 ind0.set(id) = ind1(id) ;
585 }
586
587 // Addition of the Delta^k_{lk} term
588 tmp = 0 ;
589
590 for (int l=1; l<=3; l++) {
591 ind0.set(valence0m1) = l ; // summation on the last index of uu
592 tmp += delta_trace(l) * uu(ind0) ;
593 }
594
595 ind0.set(valence0m1) = -1 ; // unvalid value for the last index
596 // because it should no longer be used
597
598
599 // Addition of the other Delta terms
600
601 for (int id=0; id<valence1; id++) { // Loop on the number of indices
602 // the result
603
604 ind = ind0 ;
605
606 switch( uu.get_index_type(id) ) {
607
608 case CON : {
609 for (int l=1; l<=3; l++) {
610 ind.set(id) = l ;
611 for (int k=1; k<=3; k++) {
612 ind.set(valence0m1) = k ;
613 tmp += delta(ind0(id), l, k) * uu(ind) ;
614 }
615 }
616 break ;
617 }
618
619 case COV : {
620 for (int l=1; l<=3; l++) {
621 ind.set(id) = l ;
622 for (int k=1; k<=3; k++) {
623 ind.set(valence0m1) = k ;
624 tmp -= delta(l, ind0(id), k) * uu(ind) ;
625 }
626 }
627 break ;
628 }
629
630 default : {
631 cerr <<
632 "Connection::p_divergence : unexpected type of index !\n" ;
633 abort() ;
634 break ;
635 }
636
637 } // end of switch on index type
638
639 } // end of loop on the number of indices of the result
640
641
642 if (dz_in > 0) tmp.dec_dzpuis() ; // to get the same dzpuis as
643 // the flat divergence
644
645 resu->set(ind1) += tmp ; // addition to the flat divergence part
646
647
648 } // end of loop on all the components of the output tensor
649
650 // C'est fini !
651 // ------------
652
653 return resu ;
654
655 }
656
657
658 //--------------
659 // Ricci tensor
660 //--------------
661
662 const Tensor& Connection::ricci() const {
663
664 if (p_ricci == 0x0) { // a new computation is necessary
665
666 if (assoc_metric) { // The Ricci tensor is symmetric if the
667 // connection is associated with some metric
668 p_ricci = new Sym_tensor(*mp, COV, *triad) ;
669 }
670 else {
671 p_ricci = new Tensor(*mp, 2, COV, *triad) ;
672 }
673
674 const Tensor& d_delta = delta.derive_cov(*flat_met) ;
675
676 for (int i=1; i<=3; i++) {
677
678 int jmax = assoc_metric ? i : 3 ;
679
680 for (int j=1; j<=jmax; j++) {
681
682 Scalar tmp1(*mp) ;
683 tmp1.set_etat_zero() ;
684 for (int k=1; k<=3; k++) {
685 tmp1 += d_delta(k,i,j,k) ;
686 }
687
688 Scalar tmp2(*mp) ;
689 tmp2.set_etat_zero() ;
690 for (int k=1; k<=3; k++) {
691 tmp2 += d_delta(k,i,k,j) ;
692 }
693
694 Scalar tmp3(*mp) ;
695 tmp3.set_etat_zero() ;
696 for (int k=1; k<=3; k++) {
697 for (int m=1; m<=3; m++) {
698 tmp3 += delta(k,k,m) * delta(m,i,j) ;
699 }
700 }
701 tmp3.dec_dzpuis() ; // dzpuis 4 -> 3
702
703 Scalar tmp4(*mp) ;
704 tmp4.set_etat_zero() ;
705 for (int k=1; k<=3; k++) {
706 for (int m=1; m<=3; m++) {
707 tmp4 += delta(k,j,m) * delta(m,i,k) ;
708 }
709 }
710 tmp4.dec_dzpuis() ; // dzpuis 4 -> 3
711
712 p_ricci->set(i,j) = tmp1 - tmp2 + tmp3 - tmp4 ;
713
714 }
715 }
716
717 }
718
719 return *p_ricci ;
720
721 }
722
723
724
725
726
727
728
729
730
731
732
733
734
735 }