-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
General relativity #2558
General relativity #2558
Conversation
There is already the galgebra module (with Schwarzschild solution somewhere in the examples/). @Krastanov, probably could comment this. |
@@ -0,0 +1,25 @@ | |||
from sympy.tensor.components import * | |||
from sympy.physics.gr.ricci import * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about putting this file in sympy/physics/gr/tests
?
The code has to be put inside functions starting with test_
I believe this code should use other sympy modules that already exist. For example In my opinion you should use the tensor objects in I am writing a PR to add support for Unfortunately, it depends on Have a look at the tensor module documentation: http://docs.sympy.org/dev/modules/tensor/tensor.html There is also a diffgeom module in sympy, have a look at its documentation: http://docs.sympy.org/dev/modules/diffgeom.html Unfortunately tensors in the tensor module are not yet compatible with the diffgeom module, there is need to devise a way to have them interact. Let me know if you find these points interesting. |
@Krastanov : can you further explain the design for the |
I think that Krastanov is very busy lately. I will try to explain. The idea behind it is this: Indices are not integers, they are types, so we have
When you define a tensor, you define a
Suppose you have a A Indices with a minus are contravariant, without sign they are covariant: When you create a Index contraction: Indices can be repeated just once, unless they are contracted: The point here is that there is still no way to handle tensors as matrices (I mean, with integer indices accessing data at a certain position). That's what I try to fix in the PR I just linked, I'm not sure how much time will it take before it is merged into master. The idea is to add the second notation with square brackets, so you would access tensor as a matrix by typing: |
Have a look at: #2514 It depends on the Have a look at the tests to see how it works. |
@Upabjojr I'll think a little bit more and may reply you more later. Here are just something I want to clarify first. I show the class That's the reason we need some general metric in Riemannian geometry (as Lorentz is just a special case of metric diag(1, -1, ..., -1)). However, it seems just more natural to think about metric as a rank-2 tensor, rather a property of the index. That's the reason I feel |
The tensor module is meant to work in an abstract manner, i.e. when you don't know anything about matrices. The idea is that you can still manipulate tensor expressions, even if the metric and tensor components are unknown to you. It's an abstract layer above what tensors are really used for in physics. For example, we merged into master branch an algorithm to compute traces of gamma matrices without specifying neither the metric matrix, nor the values of the gamma matrices. You can find it in I further plan to write a pattern matching algorithm in the future which would allow to perform complex tensor operations without knowledge of the array composition or matrix of metrics. In the end, that's what textbooks usually do, you handle tensor expressions by their properties, you don't calculate by hand a matrix product on every contraction, right?
The metric values are considered only when you descend this layer of abstraction and start using data values inside a tensor. That's what my PR does, but the rules provided by the abstract layer and index types have still to hold (so we can raise an error if someone is trying to do something that has no sense, even if the matrix product would allow to do that). Regarding normal indices: it's true, Dirac spinor index and color-index are equal if used as covariant or contravariant indices. But we don't know that when using tensors abstractly (only after you define the metric). Yet the gamma matrix algorithm works well. |
Thanks for the explanation of For the other part, I still feel quite confusing. Gamma matrix have two kind of indices, one has the dimensional of spacetime, other one has dimensional 2^floor(spacetime/2) -- in normal 4d spacetime, both of them are 4. Normally when we write \gamma_\mu^{ab}, \mu is the spacetime index, and a,b are the Clifford algebra indices. I don't know which one are you talking about. But WE KNOW THE METRICS for both of them: the spacetime index has metric diag(1, -1, -1, -1) (because Quantum Field Theory assumes Special Relativity, i.e., in flat spacetime; things are more complicated in string theory, but people use gamma matrix under assumptions), and Clifford algebra indices just have diag(1, 1, 1, 1). You can do abstract calculation without knowing the detail of the metric form, but at that time your metric (which looks like g_\mu\nu) is just a normal rank-2 tensor in the manifold you care (and \mu, \nu have the dimensional of that manifold -- they may be the spacetime indices, Dirac spinor index, color-index, but they are just some special conditions and those conditions are much simpler than the general case). |
By the way, by "you handle tensor expressions by their properties, you don't calculate by hand a matrix product on every contraction", I think you mean the typical gamma matrix calculations in QFT textbooks (you keep use the rules such as {\gamma_\mu, \gamma_\nu} = 2 g_\mu\nu). You can do it abstractly, because you are follow the definition of Clifford algebra, and at that level, you don't have Direc spinor indices at all. Only when you define your representation (to use a 4x4 matrix with complex number elements to represent your Clifford algebra structure -- we call it gamma matrix) you involve Direc spinor indices. And you defined the metric at the same time (which is the trivial one diag(1, 1, 1, 1)). |
Yes, that's one of the reasons. So you can avoid contracting a Lorentz index and a spinor index in a gamma matrix tensor. Besides,
Gamma matrices have been merged into sympy as a 1-rank tensor representing matrices. The reason for this was that it is boring to write all spinor indices, but I am correcting this problem in this PR: Here you can define auto-matrix indices, i.e. tensor indices which get automatically filled if missing. So you can easily handle matrix multiplication. There is another problem, the dimension is stored in Lorentz instead of DiracSpinor (as previously there were no such indices), that has to be corrected.
Dirac spinor indices will be added. Rule-based tensor manipulation can be extended even outside of gamma matrix algebra. In any case before trying rule-based approaches, it is better to write a simple pattern matching function for tensors, otherwise rules involve lots of for-loops. I think the best that can be done now, is to define GR tensors as subclasses of In the physics module, there is already a |
@Upabjojr I'll wait to see your work. |
|
||
Examples | ||
======== | ||
>>> from sympy import symbols, sin, cos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
insert a blank line before this line
SymPy Bot Summary: 🔴 Failed after merging ozooxo/general_relativity (91ad9c6) into master (ced4df3). |
@jrioux Thanks. I'll fix the simple code problems (like |
Hi @ozooxo , my PRs concerning data on tensors have so far been merged into master. If you want, you can try to use the tensor module. Unfortunately it is still not possible to have partial and covariant derivatives of tensor expressions. I am currently working on a code clean up of the tensor module, after that I'll probably go on and define something like If I were to approach GR, I would try to insert objects from the |
I tried to fix the format problems. All the single blank line/double blank lines should be right now. Every class is a subclass of
and I completely don't know why. Can anybody tell me what's the possible problem for that? |
I also moved |
SymPy Bot Summary: 🔴 Failed after merging ozooxo/general_relativity (32d79f0) into master (518f83b). |
SymPy Bot Summary: 🔴 Failed after merging ozooxo/general_relativity (19cba75) into master (5e822ef). |
Take a look at this: http://krastanov.files.wordpress.com/2012/07/schwarzschild.pdf Apparently there's a bug on the diffgeom module and some functions are not documented. I missed that Riemann and Ricci tensor component calculations have already been included into SymPy since 2012. |
@Upabjojr IMHO, general relativity can be a project idea for GSoC in future? Can we include this in ideas list? |
General relativity is a very broad subject. In hindsight, my suggestion is to avoid trying implementing general relativity, it's better to extend the current SymPy modules in a way to allow computations to be easier. Relativity has a lot to do with multilinear algebra, SymPy has a more robust support than 5 years ago. |
Closing this PR in reference to the above comment. Though, if there is a scope of continuing this work, please let us know in the comments below, or if you can, feel free to re-open this PR. Thanks for the contributions. |
I add some functions for:
(1) Tensor calculations in the component form, includes (a) tensor product, (b) partial derivative which gives some higher ranked tensor, and (c) Einstein summation for a tensor with dummy indices.
(2) General Relativity related functions to calculate Riemann curvature tensor, Ricci tensor, and Ricci scalar.
I include a test file which shows that the calculation for Ricci scalar on the surface of a sphere, and for Schwarzschild metric are correct.