ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 01 May 2020 03:10:28 -0500metric perturbations on Sagemanifoldshttps://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/I would like to carry out some metric perturbations within SageManifolds.
To that end, I have defined a 4-dimensional Lorentzian manifold N:
N = Manifold(4, 'N', latex_name=r'\mathcal{N}', structure='Lorentzian')
a global chart:
GC.<x0,x,y,z> = N.chart(r'x0:(-oo,+oo):x^0 x y z')
the corresponding frame eN:
eN = GC.frame()
the unperturbed metric g0:
g0 = N.metric('g0', latex_name=r'g_{(0)}')
the control parameter for the perturbation:
var('eps', latex_name=r'\epsilon', domain='real')
and the perturbation tensor field itself:
g1 = N.tensor_field(0, 2, name='g1', latex_name='g_{1}', sym=(0,1))
Up until here, everything seems to work fine and there are no errors or warnings. However, when I try to define the total perturbed metric, via:
g = g0 + eps*g1
the following error shows up:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-10-e785f6693878> in <module>()
----> 1 g = g0 + epsplus*g1plus
2 g
/home/orca/SageMath/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__add__ (build/cythonized/sage/structure/element.c:10799)()
1229 cdef int cl = classify_elements(left, right)
1230 if HAVE_SAME_PARENT(cl):
-> 1231 return (<Element>left)._add_(right)
1232 # Left and right are Sage elements => use coercion model
1233 if BOTH_ARE_ELEMENT(cl):
/home/orca/SageMath/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.ModuleElement._add_ (build/cythonized/sage/structure/element.c:15170)()
2344 Generic element of a module.
2345 """
-> 2346 cpdef _add_(self, other):
2347 """
2348 Abstract addition method
/home/orca/SageMath/local/lib/python3.7/site-packages/sage/tensor/modules/free_module_tensor.py in _add_(self, other)
2090 basis = self.common_basis(other)
2091 if basis is None:
-> 2092 raise ValueError("no common basis for the addition")
2093 comp_result = self._components[basis] + other._components[basis]
2094 result = self._fmodule.tensor_from_comp(self._tensor_type, comp_result)
ValueError: no common basis for the addition
How is the correct way to define g as the sum of those 2 former tensor fields??? I have also tried
g[eN] = g0[eN] + epsplus*g1plus[eN]
but there is then:
Type Error: unhashable type: 'VectorFieldFreeModule_with_category.element_class'
and also:
g[eN,:] = g0[eN,:] + epsplus*g1plus[eN,:]
but then the error is:
ValueError: no basis could be found for computing the components in the Coordinate frame (N, (d/dx0,d/dx,d/dy,d/dz)).Sun, 26 Apr 2020 16:59:37 -0500https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/Answer by eric_g for <p>I would like to carry out some metric perturbations within SageManifolds.</p>
<p>To that end, I have defined a 4-dimensional Lorentzian manifold N:</p>
<pre><code>N = Manifold(4, 'N', latex_name=r'\mathcal{N}', structure='Lorentzian')
</code></pre>
<p>a global chart:</p>
<pre><code>GC.<x0,x,y,z> = N.chart(r'x0:(-oo,+oo):x^0 x y z')
</code></pre>
<p>the corresponding frame eN:</p>
<pre><code>eN = GC.frame()
</code></pre>
<p>the unperturbed metric g0:</p>
<pre><code>g0 = N.metric('g0', latex_name=r'g_{(0)}')
</code></pre>
<p>the control parameter for the perturbation:</p>
<pre><code>var('eps', latex_name=r'\epsilon', domain='real')
</code></pre>
<p>and the perturbation tensor field itself:</p>
<pre><code>g1 = N.tensor_field(0, 2, name='g1', latex_name='g_{1}', sym=(0,1))
</code></pre>
<p>Up until here, everything seems to work fine and there are no errors or warnings. However, when I try to define the total perturbed metric, via:</p>
<pre><code>g = g0 + eps*g1
</code></pre>
<p>the following error shows up:</p>
<pre><code>---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-10-e785f6693878> in <module>()
----> 1 g = g0 + epsplus*g1plus
2 g
/home/orca/SageMath/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.__add__ (build/cythonized/sage/structure/element.c:10799)()
1229 cdef int cl = classify_elements(left, right)
1230 if HAVE_SAME_PARENT(cl):
-> 1231 return (<Element>left)._add_(right)
1232 # Left and right are Sage elements => use coercion model
1233 if BOTH_ARE_ELEMENT(cl):
/home/orca/SageMath/local/lib/python3.7/site-packages/sage/structure/element.pyx in sage.structure.element.ModuleElement._add_ (build/cythonized/sage/structure/element.c:15170)()
2344 Generic element of a module.
2345 """
-> 2346 cpdef _add_(self, other):
2347 """
2348 Abstract addition method
/home/orca/SageMath/local/lib/python3.7/site-packages/sage/tensor/modules/free_module_tensor.py in _add_(self, other)
2090 basis = self.common_basis(other)
2091 if basis is None:
-> 2092 raise ValueError("no common basis for the addition")
2093 comp_result = self._components[basis] + other._components[basis]
2094 result = self._fmodule.tensor_from_comp(self._tensor_type, comp_result)
ValueError: no common basis for the addition
</code></pre>
<p>How is the correct way to define g as the sum of those 2 former tensor fields??? I have also tried</p>
<pre><code>g[eN] = g0[eN] + epsplus*g1plus[eN]
</code></pre>
<p>but there is then: </p>
<pre><code>Type Error: unhashable type: 'VectorFieldFreeModule_with_category.element_class'
</code></pre>
<p>and also:</p>
<pre><code>g[eN,:] = g0[eN,:] + epsplus*g1plus[eN,:]
</code></pre>
<p>but then the error is: </p>
<pre><code>ValueError: no basis could be found for computing the components in the Coordinate frame (N, (d/dx0,d/dx,d/dy,d/dz)).
</code></pre>
https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?answer=51063#post-id-51063The error is due to the fact that neither `g0` nor `g1` are initialized. They have simply been declared as a metric and a type (0,2) tensor field, but you should initialize their components in some vector frame, in order to fully define them.
Regarding perturbation of tensor fields, note that tensor series expansion have been introduced in Sage 8.8, see the [changelog](https://sagemanifolds.obspm.fr/changelog.html) for details, in particular cell [25] of this [notebook](https://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Notebooks/SM_extremal_Kerr_near_horizon.ipynb) for a concrete example of use. Mon, 27 Apr 2020 09:03:55 -0500https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?answer=51063#post-id-51063Comment by eric_g for <p>The error is due to the fact that neither <code>g0</code> nor <code>g1</code> are initialized. They have simply been declared as a metric and a type (0,2) tensor field, but you should initialize their components in some vector frame, in order to fully define them.</p>
<p>Regarding perturbation of tensor fields, note that tensor series expansion have been introduced in Sage 8.8, see the <a href="https://sagemanifolds.obspm.fr/changelog.html">changelog</a> for details, in particular cell [25] of this <a href="https://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Notebooks/SM_extremal_Kerr_near_horizon.ipynb">notebook</a> for a concrete example of use. </p>
https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?comment=51181#post-id-51181The currrent implementation of tensor calculus in SageMath does not deal with "abstract" tensors, as xAct does, i.e. tensor fields have to be defined by their components in a given frame (usually a coordinate frame). Adding abstract tensor calculus in SageMath could be a nice project, if there are volunteers...Fri, 01 May 2020 03:10:28 -0500https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?comment=51181#post-id-51181Comment by mocalvao for <p>The error is due to the fact that neither <code>g0</code> nor <code>g1</code> are initialized. They have simply been declared as a metric and a type (0,2) tensor field, but you should initialize their components in some vector frame, in order to fully define them.</p>
<p>Regarding perturbation of tensor fields, note that tensor series expansion have been introduced in Sage 8.8, see the <a href="https://sagemanifolds.obspm.fr/changelog.html">changelog</a> for details, in particular cell [25] of this <a href="https://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Notebooks/SM_extremal_Kerr_near_horizon.ipynb">notebook</a> for a concrete example of use. </p>
https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?comment=51078#post-id-51078I was thinking something along the lines of the package xPert (xAct) from MathematicaMon, 27 Apr 2020 13:28:02 -0500https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?comment=51078#post-id-51078Comment by mocalvao for <p>The error is due to the fact that neither <code>g0</code> nor <code>g1</code> are initialized. They have simply been declared as a metric and a type (0,2) tensor field, but you should initialize their components in some vector frame, in order to fully define them.</p>
<p>Regarding perturbation of tensor fields, note that tensor series expansion have been introduced in Sage 8.8, see the <a href="https://sagemanifolds.obspm.fr/changelog.html">changelog</a> for details, in particular cell [25] of this <a href="https://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Notebooks/SM_extremal_Kerr_near_horizon.ipynb">notebook</a> for a concrete example of use. </p>
https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?comment=51067#post-id-51067Dear Eric,
I get the difference between a plain declaration and an initialization; thanks. However, I would like to use, until a certain time, completely general expressions for the components (in the default frame, for instance), that is, arbitrary functions of all the coordinates. Is this feasible? If so, how?Mon, 27 Apr 2020 10:06:32 -0500https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?comment=51067#post-id-51067Comment by eric_g for <p>The error is due to the fact that neither <code>g0</code> nor <code>g1</code> are initialized. They have simply been declared as a metric and a type (0,2) tensor field, but you should initialize their components in some vector frame, in order to fully define them.</p>
<p>Regarding perturbation of tensor fields, note that tensor series expansion have been introduced in Sage 8.8, see the <a href="https://sagemanifolds.obspm.fr/changelog.html">changelog</a> for details, in particular cell [25] of this <a href="https://nbviewer.jupyter.org/github/sagemanifolds/SageManifolds/blob/master/Notebooks/SM_extremal_Kerr_near_horizon.ipynb">notebook</a> for a concrete example of use. </p>
https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?comment=51070#post-id-51070You can use `function('A')(x0,x,y,z)` to initialize some tensor components with an arbitrary function of the coordinates. NB: if you do this for all components, some computations, like the Riemann tensor, will become huge.Mon, 27 Apr 2020 11:00:54 -0500https://ask.sagemath.org/question/51045/metric-perturbations-on-sagemanifolds/?comment=51070#post-id-51070