-
-
Notifications
You must be signed in to change notification settings - Fork 405
/
metric.py
3081 lines (2520 loc) · 122 KB
/
metric.py
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
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
r"""
Pseudo-Riemannian Metrics and Degenerate Metrics
The class :class:`PseudoRiemannianMetric` implements pseudo-Riemannian metrics
on differentiable manifolds over `\RR`. The derived class
:class:`PseudoRiemannianMetricParal` is devoted to metrics with values on a
parallelizable manifold.
The class :class:`DegenerateMetric` implements degenerate (or null or lightlike)
metrics on differentiable manifolds over `\RR`. The derived class
:class:`DegenerateMetricParal` is devoted to metrics with values on a
parallelizable manifold.
AUTHORS:
- Eric Gourgoulhon, Michal Bejger (2013-2015) : initial version
- Pablo Angulo (2016) : Schouten, Cotton and Cotton-York tensors
- Florentin Jaffredo (2018) : series expansion for the inverse metric
- Hans Fotsing Tetsing (2019) : degenerate metrics
- Marius Gerbershagen (2022) : compute volume forms with contravariant indices
only as needed
REFERENCES:
- [KN1963]_
- [Lee1997]_
- [ONe1983]_
- [DB1996]_
- [DS2010]_
"""
# *****************************************************************************
# Copyright (C) 2015 Eric Gourgoulhon <eric.gourgoulhon@obspm.fr>
# Copyright (C) 2015 Michal Bejger <bejger@camk.edu.pl>
# Copyright (C) 2016 Pablo Angulo <pang@cancamusa.net>
# Copyright (C) 2018 Florentin Jaffredo <florentin.jaffredo@polytechnique.edu>
# Copyright (C) 2019 Hans Fotsing Tetsing <hans.fotsing@aims-cameroon.org>
#
# Distributed under the terms of the GNU General Public License (GPL)
# as published by the Free Software Foundation; either version 2 of
# the License, or (at your option) any later version.
# https://www.gnu.org/licenses/
# *****************************************************************************
from __future__ import annotations
from typing import TYPE_CHECKING, overload
from sage.manifolds.differentiable.tensorfield import TensorField
from sage.manifolds.differentiable.tensorfield_paral import TensorFieldParal
from sage.rings.integer import Integer
if TYPE_CHECKING:
from sage.manifolds.differentiable.diff_form import DiffForm
class PseudoRiemannianMetric(TensorField):
r"""
Pseudo-Riemannian metric with values on an open subset of a
differentiable manifold.
An instance of this class is a field of nondegenerate symmetric bilinear
forms (metric field) along a differentiable manifold `U` with
values on a differentiable manifold `M` over `\RR`, via a differentiable
mapping `\Phi: U \rightarrow M`.
The standard case of a metric field *on* a manifold corresponds to `U=M`
and `\Phi = \mathrm{Id}_M`. Other common cases are `\Phi` being an
immersion and `\Phi` being a curve in `M` (`U` is then an open interval
of `\RR`).
A *metric* `g` is a field on `U`, such that at each point `p\in U`, `g(p)`
is a bilinear map of the type:
.. MATH::
g(p):\ T_q M\times T_q M \longrightarrow \RR
where `T_q M` stands for the tangent space to the
manifold `M` at the point `q=\Phi(p)`, such that `g(p)` is symmetric:
`\forall (u,v)\in T_q M\times T_q M, \ g(p)(v,u) = g(p)(u,v)`
and nondegenerate:
`(\forall v\in T_q M,\ \ g(p)(u,v) = 0) \Longrightarrow u=0`.
.. NOTE::
If `M` is parallelizable, the class :class:`PseudoRiemannianMetricParal`
should be used instead.
INPUT:
- ``vector_field_module`` -- module `\mathfrak{X}(U,\Phi)` of vector
fields along `U` with values on `\Phi(U)\subset M`
- ``name`` -- name given to the metric
- ``signature`` -- (default: ``None``) signature `S` of the metric as a
single integer: `S = n_+ - n_-`, where `n_+` (resp. `n_-`) is the number
of positive terms (resp. number of negative terms) in any diagonal
writing of the metric components; if ``signature`` is ``None``, `S` is
set to the dimension of manifold `M` (Riemannian signature)
- ``latex_name`` -- (default: ``None``) LaTeX symbol to denote the metric;
if ``None``, it is formed from ``name``
EXAMPLES:
Let us construct the standard metric on the sphere `S^2`, described in
terms of stereographic coordinates, from the North pole (open subset `U`)
and from the South pole (open subset `V`)::
sage: M = Manifold(2, 'S^2', start_index=1)
sage: U = M.open_subset('U') ; V = M.open_subset('V')
sage: M.declare_union(U,V) # S^2 is the union of U and V
sage: c_xy.<x,y> = U.chart() ; c_uv.<u,v> = V.chart() # stereographic coord
sage: xy_to_uv = c_xy.transition_map(c_uv, (x/(x^2+y^2), y/(x^2+y^2)),
....: intersection_name='W', restrictions1= x^2+y^2!=0,
....: restrictions2= u^2+v^2!=0)
sage: uv_to_xy = xy_to_uv.inverse()
sage: eU = c_xy.frame() ; eV = c_uv.frame()
sage: g = M.metric('g') ; g
Riemannian metric g on the 2-dimensional differentiable manifold S^2
The metric is considered as a tensor field of type (0,2) on `S^2`::
sage: g.parent()
Module T^(0,2)(S^2) of type-(0,2) tensors fields on the 2-dimensional
differentiable manifold S^2
We define `g` by its components on domain `U`::
sage: g[eU,1,1], g[eU,2,2] = 4/(1+x^2+y^2)^2, 4/(1+x^2+y^2)^2
sage: g.display(eU)
g = 4/(x^2 + y^2 + 1)^2 dx⊗dx + 4/(x^2 + y^2 + 1)^2 dy⊗dy
A matrix view of the components::
sage: g[eU,:]
[4/(x^2 + y^2 + 1)^2 0]
[ 0 4/(x^2 + y^2 + 1)^2]
The components of `g` on domain `V` expressed in terms of coordinates
`(u,v)` are obtained by applying (i) the tensor transformation law on
`W = U\cap V` and (ii) some analytical continuation::
sage: W = U.intersection(V)
sage: g.add_comp_by_continuation(eV, W, chart=c_uv)
sage: g.apply_map(factor, frame=eV, keep_other_components=True) # for a nicer display
sage: g.display(eV)
g = 4/(u^2 + v^2 + 1)^2 du⊗du + 4/(u^2 + v^2 + 1)^2 dv⊗dv
At this stage, the metric is fully defined on the whole sphere. Its
restriction to some subdomain is itself a metric (by default, it bears the
same symbol)::
sage: g.restrict(U)
Riemannian metric g on the Open subset U of the 2-dimensional
differentiable manifold S^2
sage: g.restrict(U).parent()
Free module T^(0,2)(U) of type-(0,2) tensors fields on the Open subset
U of the 2-dimensional differentiable manifold S^2
The parent of `g|_U` is a free module because is `U` is a parallelizable
domain, contrary to `S^2`. Actually, `g` and `g|_U` have different Python
type::
sage: type(g)
<class 'sage.manifolds.differentiable.metric.PseudoRiemannianMetric'>
sage: type(g.restrict(U))
<class 'sage.manifolds.differentiable.metric.PseudoRiemannianMetricParal'>
As a field of bilinear forms, the metric acts on pairs of vector fields,
yielding a scalar field::
sage: a = M.vector_field({eU: [x, 2+y]}, name='a')
sage: a.add_comp_by_continuation(eV, W, chart=c_uv)
sage: b = M.vector_field({eU: [-y, x]}, name='b')
sage: b.add_comp_by_continuation(eV, W, chart=c_uv)
sage: s = g(a,b) ; s
Scalar field g(a,b) on the 2-dimensional differentiable manifold S^2
sage: s.display()
g(a,b): S^2 → ℝ
on U: (x, y) ↦ 8*x/(x^4 + y^4 + 2*(x^2 + 1)*y^2 + 2*x^2 + 1)
on V: (u, v) ↦ 8*(u^3 + u*v^2)/(u^4 + v^4 + 2*(u^2 + 1)*v^2 + 2*u^2 + 1)
The inverse metric is::
sage: ginv = g.inverse() ; ginv
Tensor field inv_g of type (2,0) on the 2-dimensional differentiable
manifold S^2
sage: ginv.parent()
Module T^(2,0)(S^2) of type-(2,0) tensors fields on the 2-dimensional
differentiable manifold S^2
sage: latex(ginv)
g^{-1}
sage: ginv.display(eU)
inv_g = (1/4*x^4 + 1/4*y^4 + 1/2*(x^2 + 1)*y^2 + 1/2*x^2 + 1/4) ∂/∂x⊗∂/∂x
+ (1/4*x^4 + 1/4*y^4 + 1/2*(x^2 + 1)*y^2 + 1/2*x^2 + 1/4) ∂/∂y⊗∂/∂y
sage: ginv.display(eV)
inv_g = (1/4*u^4 + 1/4*v^4 + 1/2*(u^2 + 1)*v^2 + 1/2*u^2 + 1/4) ∂/∂u⊗∂/∂u
+ (1/4*u^4 + 1/4*v^4 + 1/2*(u^2 + 1)*v^2 + 1/2*u^2 + 1/4) ∂/∂v⊗∂/∂v
We have::
sage: ginv.restrict(U) is g.restrict(U).inverse()
True
sage: ginv.restrict(V) is g.restrict(V).inverse()
True
sage: ginv.restrict(W) is g.restrict(W).inverse()
True
To get the volume form (Levi-Civita tensor) associated with `g`, we have
first to define an orientation on `S^2`. The standard orientation is that
in which ``eV`` is right-handed; indeed, once supplemented by the outward
unit normal, ``eV`` give birth to a right-handed frame with respect to the
standard orientation of the ambient Euclidean space `E^3`. With such an
orientation, ``eU`` is then left-handed and in order to define an
orientation on the whole of `S^2`, we introduce a vector frame
on `U` by swapping ``eU``'s vectors::
sage: f = U.vector_frame('f', (eU[2], eU[1]))
sage: M.set_orientation([eV, f])
We have then, factorizing the components for a nicer display::
sage: eps = g.volume_form() ; eps
2-form eps_g on the 2-dimensional differentiable manifold S^2
sage: eps.apply_map(factor, frame=eU, keep_other_components=True)
sage: eps.apply_map(factor, frame=eV, keep_other_components=True)
sage: eps.display(eU)
eps_g = -4/(x^2 + y^2 + 1)^2 dx∧dy
sage: eps.display(eV)
eps_g = 4/(u^2 + v^2 + 1)^2 du∧dv
The unique non-trivial component of the volume form is, up to a sign
depending of the chosen orientation, nothing but the square root of the
determinant of `g` in the corresponding frame::
sage: eps[[eU,1,2]] == -g.sqrt_abs_det(eU)
True
sage: eps[[eV,1,2]] == g.sqrt_abs_det(eV)
True
The Levi-Civita connection associated with the metric `g`::
sage: nabla = g.connection() ; nabla
Levi-Civita connection nabla_g associated with the Riemannian metric g
on the 2-dimensional differentiable manifold S^2
sage: latex(nabla)
\nabla_{g}
The Christoffel symbols `\Gamma^i_{\ \, jk}` associated with some
coordinates::
sage: g.christoffel_symbols(c_xy)
3-indices components w.r.t. Coordinate frame (U, (∂/∂x,∂/∂y)), with
symmetry on the index positions (1, 2)
sage: g.christoffel_symbols(c_xy)[:]
[[[-2*x/(x^2 + y^2 + 1), -2*y/(x^2 + y^2 + 1)],
[-2*y/(x^2 + y^2 + 1), 2*x/(x^2 + y^2 + 1)]],
[[2*y/(x^2 + y^2 + 1), -2*x/(x^2 + y^2 + 1)],
[-2*x/(x^2 + y^2 + 1), -2*y/(x^2 + y^2 + 1)]]]
sage: g.christoffel_symbols(c_uv)[:]
[[[-2*u/(u^2 + v^2 + 1), -2*v/(u^2 + v^2 + 1)],
[-2*v/(u^2 + v^2 + 1), 2*u/(u^2 + v^2 + 1)]],
[[2*v/(u^2 + v^2 + 1), -2*u/(u^2 + v^2 + 1)],
[-2*u/(u^2 + v^2 + 1), -2*v/(u^2 + v^2 + 1)]]]
The Christoffel symbols are nothing but the connection coefficients w.r.t.
the coordinate frame::
sage: g.christoffel_symbols(c_xy) is nabla.coef(c_xy.frame())
True
sage: g.christoffel_symbols(c_uv) is nabla.coef(c_uv.frame())
True
Test that `\nabla` is the connection compatible with `g`::
sage: t = nabla(g) ; t
Tensor field nabla_g(g) of type (0,3) on the 2-dimensional
differentiable manifold S^2
sage: t.display(eU)
nabla_g(g) = 0
sage: t.display(eV)
nabla_g(g) = 0
sage: t == 0
True
The Riemann curvature tensor of `g`::
sage: riem = g.riemann() ; riem
Tensor field Riem(g) of type (1,3) on the 2-dimensional differentiable
manifold S^2
sage: riem.display(eU)
Riem(g) = 4/(x^4 + y^4 + 2*(x^2 + 1)*y^2 + 2*x^2 + 1) ∂/∂x⊗dy⊗dx⊗dy
- 4/(x^4 + y^4 + 2*(x^2 + 1)*y^2 + 2*x^2 + 1) ∂/∂x⊗dy⊗dy⊗dx
- 4/(x^4 + y^4 + 2*(x^2 + 1)*y^2 + 2*x^2 + 1) ∂/∂y⊗dx⊗dx⊗dy
+ 4/(x^4 + y^4 + 2*(x^2 + 1)*y^2 + 2*x^2 + 1) ∂/∂y⊗dx⊗dy⊗dx
sage: riem.display(eV)
Riem(g) = 4/(u^4 + v^4 + 2*(u^2 + 1)*v^2 + 2*u^2 + 1) ∂/∂u⊗dv⊗du⊗dv
- 4/(u^4 + v^4 + 2*(u^2 + 1)*v^2 + 2*u^2 + 1) ∂/∂u⊗dv⊗dv⊗du
- 4/(u^4 + v^4 + 2*(u^2 + 1)*v^2 + 2*u^2 + 1) ∂/∂v⊗du⊗du⊗dv
+ 4/(u^4 + v^4 + 2*(u^2 + 1)*v^2 + 2*u^2 + 1) ∂/∂v⊗du⊗dv⊗du
The Ricci tensor of `g`::
sage: ric = g.ricci() ; ric
Field of symmetric bilinear forms Ric(g) on the 2-dimensional
differentiable manifold S^2
sage: ric.display(eU)
Ric(g) = 4/(x^4 + y^4 + 2*(x^2 + 1)*y^2 + 2*x^2 + 1) dx⊗dx
+ 4/(x^4 + y^4 + 2*(x^2 + 1)*y^2 + 2*x^2 + 1) dy⊗dy
sage: ric.display(eV)
Ric(g) = 4/(u^4 + v^4 + 2*(u^2 + 1)*v^2 + 2*u^2 + 1) du⊗du
+ 4/(u^4 + v^4 + 2*(u^2 + 1)*v^2 + 2*u^2 + 1) dv⊗dv
sage: ric == g
True
The Ricci scalar of `g`::
sage: r = g.ricci_scalar() ; r
Scalar field r(g) on the 2-dimensional differentiable manifold S^2
sage: r.display()
r(g): S^2 → ℝ
on U: (x, y) ↦ 2
on V: (u, v) ↦ 2
In dimension 2, the Riemann tensor can be expressed entirely in terms of
the Ricci scalar `r`:
.. MATH::
R^i_{\ \, jlk} = \frac{r}{2} \left( \delta^i_{\ \, k} g_{jl}
- \delta^i_{\ \, l} g_{jk} \right)
This formula can be checked here, with the r.h.s. rewritten as
`-r g_{j[k} \delta^i_{\ \, l]}`::
sage: delta = M.tangent_identity_field()
sage: riem == - r*(g*delta).antisymmetrize(2,3)
True
"""
_derived_objects = ('_connection', '_ricci_scalar', '_weyl',
'_schouten', '_cotton', '_cotton_york')
def __init__(self, vector_field_module, name, signature=None,
latex_name=None):
r"""
Construct a metric.
TESTS::
sage: M = Manifold(2, 'M')
sage: U = M.open_subset('U') ; V = M.open_subset('V')
sage: M.declare_union(U,V) # M is the union of U and V
sage: c_xy.<x,y> = U.chart() ; c_uv.<u,v> = V.chart()
sage: xy_to_uv = c_xy.transition_map(c_uv, (x+y, x-y),
....: intersection_name='W', restrictions1= x>0,
....: restrictions2= u+v>0)
sage: uv_to_xy = xy_to_uv.inverse()
sage: W = U.intersection(V)
sage: e_xy = c_xy.frame() ; e_uv = c_uv.frame()
sage: XM = M.vector_field_module()
sage: from sage.manifolds.differentiable.metric import \
....: PseudoRiemannianMetric
sage: g = PseudoRiemannianMetric(XM, 'g', signature=0); g
Lorentzian metric g on the 2-dimensional differentiable
manifold M
sage: g[e_xy,0,0], g[e_xy,1,1] = -(1+x^2), 1+y^2
sage: g.add_comp_by_continuation(e_uv, W, c_uv)
sage: TestSuite(g).run(skip=['_test_category', '_test_pickling'])
.. TODO::
- fix _test_pickling (in the superclass TensorField)
- add a specific parent to the metrics, to fit with the category
framework
"""
TensorField.__init__(self, vector_field_module, (0,2),
name=name, latex_name=latex_name, sym=(0,1))
# signature:
ndim = self._ambient_domain.dimension()
if signature is None:
signature = ndim
else:
if not isinstance(signature, (int, Integer)):
raise TypeError("the metric signature must be an integer")
if (signature < - ndim) or (signature > ndim):
raise ValueError("metric signature out of range")
if (signature+ndim)%2 == 1:
if ndim%2 == 0:
raise ValueError("the metric signature must be even")
else:
raise ValueError("the metric signature must be odd")
self._signature = signature
# the pair (n_+, n_-):
self._signature_pm = ((ndim+signature)//2, (ndim-signature)//2)
self._indic_signat = 1 - 2*(self._signature_pm[1]%2) # (-1)^n_-
# Initialization of derived quantities:
PseudoRiemannianMetric._init_derived(self)
def _repr_(self):
r"""
String representation of the object.
TESTS::
sage: M = Manifold(5, 'M')
sage: g = M.metric('g')
sage: g._repr_()
'Riemannian metric g on the 5-dimensional differentiable manifold M'
sage: g = M.metric('g', signature=3)
sage: g._repr_()
'Lorentzian metric g on the 5-dimensional differentiable manifold M'
sage: g = M.metric('g', signature=1)
sage: g._repr_()
'Pseudo-Riemannian metric g on the 5-dimensional differentiable manifold M'
"""
n = self._ambient_domain.dimension()
s = self._signature
if s == n:
description = "Riemannian metric "
elif s == n-2 or s == 2-n:
description = "Lorentzian metric "
else:
description = "Pseudo-Riemannian metric "
description += self._name + " "
return self._final_repr(description)
def _new_instance(self):
r"""
Create an instance of the same class as ``self`` with the same
signature.
TESTS::
sage: M = Manifold(5, 'M')
sage: g = M.metric('g', signature=3)
sage: g1 = g._new_instance(); g1
Lorentzian metric unnamed metric on the 5-dimensional
differentiable manifold M
sage: type(g1) == type(g)
True
sage: g1.parent() is g.parent()
True
sage: g1.signature() == g.signature()
True
"""
return type(self)(self._vmodule, 'unnamed metric',
signature=self._signature,
latex_name=r'\mbox{unnamed metric}')
def _init_derived(self):
r"""
Initialize the derived quantities.
TESTS::
sage: M = Manifold(5, 'M')
sage: g = M.metric('g')
sage: g._init_derived()
"""
# Initialization of quantities pertaining to the mother class:
TensorField._init_derived(self)
# inverse metric:
inv_name = 'inv_' + self._name
inv_latex_name = self._latex_name + r'^{-1}'
self._inverse = self._vmodule.tensor((2,0), name=inv_name,
latex_name=inv_latex_name,
sym=(0,1))
for attr in self._derived_objects:
self.__setattr__(attr, None)
self._determinants = {} # determinants in various frames
self._sqrt_abs_dets = {} # sqrt(abs(det g)) in various frames
self._vol_forms = [] # volume form and associated tensors
def _del_derived(self):
r"""
Delete the derived quantities.
TESTS::
sage: M = Manifold(5, 'M')
sage: g = M.metric('g')
sage: g._del_derived()
"""
# First the derived quantities from the mother class are deleted:
TensorField._del_derived(self)
# The inverse metric is cleared:
self._del_inverse()
# The connection, Ricci scalar and Weyl tensor are reset to None:
# The Schouten, Cotton and Cotton-York tensors are reset to None:
for attr in self._derived_objects:
self.__setattr__(attr, None)
# The dictionary of determinants over the various frames is cleared:
self._determinants.clear()
self._sqrt_abs_dets.clear()
# The volume form and the associated tensors is deleted:
del self._vol_forms[:]
def _del_inverse(self):
r"""
Delete the inverse metric.
TESTS::
sage: M = Manifold(5, 'M')
sage: g = M.metric('g')
sage: g._del_inverse()
"""
self._inverse._restrictions.clear()
self._inverse._del_derived()
def signature(self):
r"""
Signature of the metric.
OUTPUT:
- signature `S` of the metric, defined as the integer
`S = n_+ - n_-`, where `n_+` (resp. `n_-`) is the number of
positive terms (resp. number of negative terms) in any diagonal
writing of the metric components
EXAMPLES:
Signatures on a 2-dimensional manifold::
sage: M = Manifold(2, 'M')
sage: g = M.metric('g') # if not specified, the signature is Riemannian
sage: g.signature()
2
sage: h = M.metric('h', signature=0)
sage: h.signature()
0
"""
return self._signature
def restrict(self, subdomain, dest_map=None):
r"""
Return the restriction of the metric to some subdomain.
If the restriction has not been defined yet, it is constructed here.
INPUT:
- ``subdomain`` -- open subset `U` of the metric's domain (must be an
instance of :class:`~sage.manifolds.differentiable.manifold.DifferentiableManifold`)
- ``dest_map`` -- (default: ``None``) destination map
`\Phi:\ U \rightarrow V`, where `V` is a subdomain of
``self._codomain``
(type: :class:`~sage.manifolds.differentiable.diff_map.DiffMap`)
If None, the restriction of ``self._vmodule._dest_map`` to `U` is
used.
OUTPUT:
- instance of :class:`PseudoRiemannianMetric` representing the
restriction.
EXAMPLES::
sage: M = Manifold(5, 'M')
sage: g = M.metric('g', signature=3)
sage: U = M.open_subset('U')
sage: g.restrict(U)
Lorentzian metric g on the Open subset U of the
5-dimensional differentiable manifold M
sage: g.restrict(U).signature()
3
See the top documentation of :class:`PseudoRiemannianMetric` for more
examples.
"""
if subdomain == self._domain:
return self
if subdomain not in self._restrictions:
# Construct the restriction at the tensor field level:
resu = TensorField.restrict(self, subdomain, dest_map=dest_map)
# the type is correctly handled by TensorField.restrict, i.e.
# resu is of type self.__class__, but the signature is not handled
# by TensorField.restrict; we have to set it here:
resu._signature = self._signature
resu._signature_pm = self._signature_pm
resu._indic_signat = self._indic_signat
# Restrictions of derived quantities:
resu._inverse = self.inverse().restrict(subdomain)
for attr in self._derived_objects:
derived = self.__getattribute__(attr)
if derived is not None:
resu.__setattr__(attr, derived.restrict(subdomain))
if self._vol_forms != []:
for eps in self._vol_forms:
resu._vol_forms.append(eps.restrict(subdomain))
# NB: no initialization of resu._determinants nor
# resu._sqrt_abs_dets
# The restriction is ready:
self._restrictions[subdomain] = resu
return self._restrictions[subdomain]
def set(self, symbiform):
r"""
Defines the metric from a field of symmetric bilinear forms
INPUT:
- ``symbiform`` -- instance of
:class:`~sage.manifolds.differentiable.tensorfield.TensorField`
representing a field of symmetric bilinear forms
EXAMPLES:
Metric defined from a field of symmetric bilinear forms on a
non-parallelizable 2-dimensional manifold::
sage: M = Manifold(2, 'M')
sage: U = M.open_subset('U') ; V = M.open_subset('V')
sage: M.declare_union(U,V) # M is the union of U and V
sage: c_xy.<x,y> = U.chart() ; c_uv.<u,v> = V.chart()
sage: xy_to_uv = c_xy.transition_map(c_uv, (x+y, x-y), intersection_name='W',
....: restrictions1= x>0, restrictions2= u+v>0)
sage: uv_to_xy = xy_to_uv.inverse()
sage: W = U.intersection(V)
sage: eU = c_xy.frame() ; eV = c_uv.frame()
sage: h = M.sym_bilin_form_field(name='h')
sage: h[eU,0,0], h[eU,0,1], h[eU,1,1] = 1+x, x*y, 1-y
sage: h.add_comp_by_continuation(eV, W, c_uv)
sage: h.display(eU)
h = (x + 1) dx⊗dx + x*y dx⊗dy + x*y dy⊗dx + (-y + 1) dy⊗dy
sage: h.display(eV)
h = (1/8*u^2 - 1/8*v^2 + 1/4*v + 1/2) du⊗du + 1/4*u du⊗dv
+ 1/4*u dv⊗du + (-1/8*u^2 + 1/8*v^2 + 1/4*v + 1/2) dv⊗dv
sage: g = M.metric('g')
sage: g.set(h)
sage: g.display(eU)
g = (x + 1) dx⊗dx + x*y dx⊗dy + x*y dy⊗dx + (-y + 1) dy⊗dy
sage: g.display(eV)
g = (1/8*u^2 - 1/8*v^2 + 1/4*v + 1/2) du⊗du + 1/4*u du⊗dv
+ 1/4*u dv⊗du + (-1/8*u^2 + 1/8*v^2 + 1/4*v + 1/2) dv⊗dv
"""
if not isinstance(symbiform, TensorField):
raise TypeError("the argument must be a tensor field")
if symbiform._tensor_type != (0,2):
raise TypeError("the argument must be of tensor type (0,2)")
if symbiform._sym != ((0,1),):
raise TypeError("the argument must be symmetric")
if not symbiform._domain.is_subset(self._domain):
raise TypeError("the symmetric bilinear form is not defined " +
"on the metric domain")
self._del_derived()
self._restrictions.clear()
if isinstance(symbiform, TensorFieldParal):
rst = self.restrict(symbiform._domain)
rst.set(symbiform)
else:
for dom, symbiform_rst in symbiform._restrictions.items():
rst = self.restrict(dom)
rst.set(symbiform_rst)
def inverse(self, expansion_symbol=None, order=1):
r"""
Return the inverse metric.
INPUT:
- ``expansion_symbol`` -- (default: ``None``) symbolic variable; if
specified, the inverse will be expanded in power series with respect
to this variable (around its zero value)
- ``order`` -- integer (default: 1); the order of the expansion
if ``expansion_symbol`` is not ``None``; the *order* is defined as
the degree of the polynomial representing the truncated power series
in ``expansion_symbol``; currently only first order inverse is
supported
If ``expansion_symbol`` is set, then the zeroth order metric must be
invertible. Moreover, subsequent calls to this method will return
a cached value, even when called with the default value (to enable
computation of derived quantities). To reset, use :meth:`_del_derived`.
OUTPUT:
- instance of
:class:`~sage.manifolds.differentiable.tensorfield.TensorField`
with ``tensor_type`` = (2,0) representing the inverse metric
EXAMPLES:
Inverse of the standard metric on the 2-sphere::
sage: M = Manifold(2, 'S^2', start_index=1)
sage: U = M.open_subset('U') ; V = M.open_subset('V')
sage: M.declare_union(U,V) # S^2 is the union of U and V
sage: c_xy.<x,y> = U.chart() ; c_uv.<u,v> = V.chart() # stereographic coord.
sage: xy_to_uv = c_xy.transition_map(c_uv, (x/(x^2+y^2), y/(x^2+y^2)),
....: intersection_name='W', restrictions1= x^2+y^2!=0,
....: restrictions2= u^2+v^2!=0)
sage: uv_to_xy = xy_to_uv.inverse()
sage: W = U.intersection(V) # the complement of the two poles
sage: eU = c_xy.frame() ; eV = c_uv.frame()
sage: g = M.metric('g')
sage: g[eU,1,1], g[eU,2,2] = 4/(1+x^2+y^2)^2, 4/(1+x^2+y^2)^2
sage: g.add_comp_by_continuation(eV, W, c_uv)
sage: ginv = g.inverse(); ginv
Tensor field inv_g of type (2,0) on the 2-dimensional differentiable manifold S^2
sage: ginv.display(eU)
inv_g = (1/4*x^4 + 1/4*y^4 + 1/2*(x^2 + 1)*y^2 + 1/2*x^2 + 1/4) ∂/∂x⊗∂/∂x
+ (1/4*x^4 + 1/4*y^4 + 1/2*(x^2 + 1)*y^2 + 1/2*x^2 + 1/4) ∂/∂y⊗∂/∂y
sage: ginv.display(eV)
inv_g = (1/4*u^4 + 1/4*v^4 + 1/2*(u^2 + 1)*v^2 + 1/2*u^2 + 1/4) ∂/∂u⊗∂/∂u
+ (1/4*u^4 + 1/4*v^4 + 1/2*(u^2 + 1)*v^2 + 1/2*u^2 + 1/4) ∂/∂v⊗∂/∂v
Let us check that ``ginv`` is indeed the inverse of ``g``::
sage: s = g.contract(ginv); s # contraction of last index of g with first index of ginv
Tensor field of type (1,1) on the 2-dimensional differentiable manifold S^2
sage: s == M.tangent_identity_field()
True
"""
# Is the inverse metric up to date?
for dom, rst in self._restrictions.items():
self._inverse._restrictions[dom] = rst.inverse(
expansion_symbol=expansion_symbol,
order=order) # forces the update
# of the restriction
return self._inverse
def connection(self, name=None, latex_name=None, init_coef=True):
r"""
Return the unique torsion-free affine connection compatible with
``self``.
This is the so-called Levi-Civita connection.
INPUT:
- ``name`` -- (default: ``None``) name given to the Levi-Civita
connection; if ``None``, it is formed from the metric name
- ``latex_name`` -- (default: ``None``) LaTeX symbol to denote the
Levi-Civita connection; if ``None``, it is set to ``name``, or if the
latter is None as well, it formed from the symbol `\nabla` and the
metric symbol
- ``init_coef`` -- (default: ``True``) determines whether the
connection coefficients are initialized, as Christoffel symbols
in the top charts of the domain of ``self`` (i.e. disregarding
the subcharts)
OUTPUT:
- the Levi-Civita connection, as an instance of
:class:`~sage.manifolds.differentiable.levi_civita_connection.LeviCivitaConnection`
EXAMPLES:
Levi-Civita connection associated with the Euclidean metric on
`\RR^3`::
sage: M = Manifold(3, 'R^3', start_index=1)
Let us use spherical coordinates on `\RR^3`::
sage: U = M.open_subset('U') # the complement of the half-plane (y=0, x>=0)
sage: c_spher.<r,th,ph> = U.chart(r'r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
sage: g = U.metric('g')
sage: g[1,1], g[2,2], g[3,3] = 1, r^2 , (r*sin(th))^2 # the Euclidean metric
sage: g.connection()
Levi-Civita connection nabla_g associated with the Riemannian
metric g on the Open subset U of the 3-dimensional differentiable
manifold R^3
sage: g.connection().display() # Nonzero connection coefficients
Gam^r_th,th = -r
Gam^r_ph,ph = -r*sin(th)^2
Gam^th_r,th = 1/r
Gam^th_th,r = 1/r
Gam^th_ph,ph = -cos(th)*sin(th)
Gam^ph_r,ph = 1/r
Gam^ph_th,ph = cos(th)/sin(th)
Gam^ph_ph,r = 1/r
Gam^ph_ph,th = cos(th)/sin(th)
Test of compatibility with the metric::
sage: Dg = g.connection()(g) ; Dg
Tensor field nabla_g(g) of type (0,3) on the Open subset U of the
3-dimensional differentiable manifold R^3
sage: Dg == 0
True
sage: Dig = g.connection()(g.inverse()) ; Dig
Tensor field nabla_g(inv_g) of type (2,1) on the Open subset U of
the 3-dimensional differentiable manifold R^3
sage: Dig == 0
True
"""
from sage.manifolds.differentiable.levi_civita_connection import \
LeviCivitaConnection
if self._connection is None:
if latex_name is None:
if name is None:
latex_name = r'\nabla_{' + self._latex_name + '}'
else:
latex_name = name
if name is None:
name = 'nabla_' + self._name
self._connection = LeviCivitaConnection(self, name,
latex_name=latex_name,
init_coef=init_coef)
return self._connection
def christoffel_symbols(self, chart=None):
r"""
Christoffel symbols of ``self`` with respect to a chart.
INPUT:
- ``chart`` -- (default: ``None``) chart with respect to which the
Christoffel symbols are required; if none is provided, the
default chart of the metric's domain is assumed.
OUTPUT:
- the set of Christoffel symbols in the given chart, as an instance of
:class:`~sage.tensor.modules.comp.CompWithSym`
EXAMPLES:
Christoffel symbols of the flat metric on `\RR^3` with respect to
spherical coordinates::
sage: M = Manifold(3, 'R3', r'\RR^3', start_index=1)
sage: U = M.open_subset('U') # the complement of the half-plane (y=0, x>=0)
sage: X.<r,th,ph> = U.chart(r'r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
sage: g = U.metric('g')
sage: g[1,1], g[2,2], g[3,3] = 1, r^2, r^2*sin(th)^2
sage: g.display() # the standard flat metric expressed in spherical coordinates
g = dr⊗dr + r^2 dth⊗dth + r^2*sin(th)^2 dph⊗dph
sage: Gam = g.christoffel_symbols() ; Gam
3-indices components w.r.t. Coordinate frame (U, (∂/∂r,∂/∂th,∂/∂ph)),
with symmetry on the index positions (1, 2)
sage: type(Gam)
<class 'sage.tensor.modules.comp.CompWithSym'>
sage: Gam[:]
[[[0, 0, 0], [0, -r, 0], [0, 0, -r*sin(th)^2]],
[[0, 1/r, 0], [1/r, 0, 0], [0, 0, -cos(th)*sin(th)]],
[[0, 0, 1/r], [0, 0, cos(th)/sin(th)], [1/r, cos(th)/sin(th), 0]]]
sage: Gam[1,2,2]
-r
sage: Gam[2,1,2]
1/r
sage: Gam[3,1,3]
1/r
sage: Gam[3,2,3]
cos(th)/sin(th)
sage: Gam[2,3,3]
-cos(th)*sin(th)
Note that a better display of the Christoffel symbols is provided by
the method :meth:`christoffel_symbols_display`::
sage: g.christoffel_symbols_display()
Gam^r_th,th = -r
Gam^r_ph,ph = -r*sin(th)^2
Gam^th_r,th = 1/r
Gam^th_ph,ph = -cos(th)*sin(th)
Gam^ph_r,ph = 1/r
Gam^ph_th,ph = cos(th)/sin(th)
"""
if chart is None:
frame = self._domain._def_chart._frame
else:
frame = chart._frame
return self.connection().coef(frame)
def christoffel_symbols_display(self, chart=None, symbol=None,
latex_symbol=None, index_labels=None, index_latex_labels=None,
coordinate_labels=True, only_nonzero=True,
only_nonredundant=True):
r"""
Display the Christoffel symbols w.r.t. to a given chart, one
per line.
The output is either text-formatted (console mode) or LaTeX-formatted
(notebook mode).
INPUT:
- ``chart`` -- (default: ``None``) chart with respect to which the
Christoffel symbols are defined; if none is provided, the
default chart of the metric's domain is assumed.
- ``symbol`` -- (default: ``None``) string specifying the
symbol of the connection coefficients; if ``None``, 'Gam' is used
- ``latex_symbol`` -- (default: ``None``) string specifying the LaTeX
symbol for the components; if ``None``, '\\Gamma' is used
- ``index_labels`` -- (default: ``None``) list of strings representing
the labels of each index; if ``None``, coordinate symbols are used
except if ``coordinate_symbols`` is set to ``False``, in which case
integer labels are used
- ``index_latex_labels`` -- (default: ``None``) list of strings
representing the LaTeX labels of each index; if ``None``, coordinate
LaTeX symbols are used, except if ``coordinate_symbols`` is set to
``False``, in which case integer labels are used
- ``coordinate_labels`` -- (default: ``True``) boolean; if ``True``,
coordinate symbols are used by default (instead of integers)
- ``only_nonzero`` -- (default: ``True``) boolean; if ``True``, only
nonzero connection coefficients are displayed
- ``only_nonredundant`` -- (default: ``True``) boolean; if ``True``,
only nonredundant (w.r.t. the symmetry of the last two indices)
connection coefficients are displayed
EXAMPLES:
Christoffel symbols of the flat metric on `\RR^3` with respect to
spherical coordinates::
sage: M = Manifold(3, 'R3', r'\RR^3', start_index=1)
sage: U = M.open_subset('U') # the complement of the half-plane (y=0, x>=0)
sage: X.<r,th,ph> = U.chart(r'r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi')
sage: g = U.metric('g')
sage: g[1,1], g[2,2], g[3,3] = 1, r^2, r^2*sin(th)^2
sage: g.display() # the standard flat metric expressed in spherical coordinates
g = dr⊗dr + r^2 dth⊗dth + r^2*sin(th)^2 dph⊗dph
sage: g.christoffel_symbols_display()
Gam^r_th,th = -r
Gam^r_ph,ph = -r*sin(th)^2
Gam^th_r,th = 1/r
Gam^th_ph,ph = -cos(th)*sin(th)
Gam^ph_r,ph = 1/r
Gam^ph_th,ph = cos(th)/sin(th)
To list all nonzero Christoffel symbols, including those that can be
deduced by symmetry, use ``only_nonredundant=False``::
sage: g.christoffel_symbols_display(only_nonredundant=False)
Gam^r_th,th = -r
Gam^r_ph,ph = -r*sin(th)^2
Gam^th_r,th = 1/r
Gam^th_th,r = 1/r
Gam^th_ph,ph = -cos(th)*sin(th)
Gam^ph_r,ph = 1/r
Gam^ph_th,ph = cos(th)/sin(th)
Gam^ph_ph,r = 1/r
Gam^ph_ph,th = cos(th)/sin(th)
Listing all Christoffel symbols (except those that can be deduced by
symmetry), including the vanishing one::
sage: g.christoffel_symbols_display(only_nonzero=False)
Gam^r_r,r = 0
Gam^r_r,th = 0
Gam^r_r,ph = 0
Gam^r_th,th = -r
Gam^r_th,ph = 0
Gam^r_ph,ph = -r*sin(th)^2
Gam^th_r,r = 0
Gam^th_r,th = 1/r
Gam^th_r,ph = 0
Gam^th_th,th = 0
Gam^th_th,ph = 0
Gam^th_ph,ph = -cos(th)*sin(th)
Gam^ph_r,r = 0
Gam^ph_r,th = 0
Gam^ph_r,ph = 1/r
Gam^ph_th,th = 0
Gam^ph_th,ph = cos(th)/sin(th)
Gam^ph_ph,ph = 0
Using integer labels::
sage: g.christoffel_symbols_display(coordinate_labels=False)
Gam^1_22 = -r
Gam^1_33 = -r*sin(th)^2
Gam^2_12 = 1/r
Gam^2_33 = -cos(th)*sin(th)
Gam^3_13 = 1/r
Gam^3_23 = cos(th)/sin(th)
"""
if chart is None:
chart = self._domain.default_chart()
return self.connection().display(frame=chart.frame(), chart=chart,
symbol=symbol, latex_symbol=latex_symbol,
index_labels=index_labels, index_latex_labels=index_latex_labels,
coordinate_labels=coordinate_labels, only_nonzero=only_nonzero,
only_nonredundant=only_nonredundant)
def riemann(self, name=None, latex_name=None):
r"""
Return the Riemann curvature tensor associated with the metric.
This method is actually a shortcut for ``self.connection().riemann()``