Repository: einsteinpy/einsteinpy

Issue:
Stress-Energy-Momentum Tensor Module
🎯 **Goal**

 * Create Stress-Energy-Momentum Tensor Module
 * This class would focus on the computation of the ​ Stress-Energy Coefficient​
 
![image](https://user-images.githubusercontent.com/51050291/62061595-cc25aa80-b227-11e9-9554-c45b03f4e525.png)

📋  **Steps to solve the problem**

 * Comment below about what you've started working on.
 * Add, commit, push your changes
 * Submit a pull request and add this in comments - `Addresses #<put issue number here>`
 * Ask for a review in comments section of pull request
 * Celebrate your contribution to this project 🎉


Discussion:
pep8speaks: Hello @OVSofia! Thanks for opening this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:

* In the file [`src/einsteinpy/symbolic/stress_energy_momentum.py`](https://github.com/einsteinpy/einsteinpy/blob/b78b1d96752c002436aa10a717d3a2aeaf085b1d/src/einsteinpy/symbolic/stress_energy_momentum.py):

> [Line 23:121](https://github.com/einsteinpy/einsteinpy/blob/b78b1d96752c002436aa10a717d3a2aeaf085b1d/src/einsteinpy/symbolic/stress_energy_momentum.py#L23): [E501](https://duckduckgo.com/?q=pep8%20E501) line too long (134 > 120 characters)
> [Line 50:13](https://github.com/einsteinpy/einsteinpy/blob/b78b1d96752c002436aa10a717d3a2aeaf085b1d/src/einsteinpy/symbolic/stress_energy_momentum.py#L50): [W503](https://duckduckgo.com/?q=pep8%20W503) line break before binary operator
> [Line 51:13](https://github.com/einsteinpy/einsteinpy/blob/b78b1d96752c002436aa10a717d3a2aeaf085b1d/src/einsteinpy/symbolic/stress_energy_momentum.py#L51): [W503](https://duckduckgo.com/?q=pep8%20W503) line break before binary operator




codecov[bot]: # [Codecov](https://codecov.io/gh/einsteinpy/einsteinpy/pull/317?src=pr&el=h1) Report
> Merging [#317](https://codecov.io/gh/einsteinpy/einsteinpy/pull/317?src=pr&el=desc) into [master](https://codecov.io/gh/einsteinpy/einsteinpy/commit/cc772ca0ac8c4135eb2c44337640ad7fe4723221?src=pr&el=desc) will **decrease** coverage by `0.12%`.
> The diff coverage is `86.36%`.

[![Impacted file tree graph](https://codecov.io/gh/einsteinpy/einsteinpy/pull/317/graphs/tree.svg?width=650&token=H3oDVYA11f&height=150&src=pr)](https://codecov.io/gh/einsteinpy/einsteinpy/pull/317?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #317      +/-   ##
==========================================
- Coverage   94.03%   93.91%   -0.13%     
==========================================
  Files          38       38              
  Lines        1458     1478      +20     
==========================================
+ Hits         1371     1388      +17     
- Misses         87       90       +3
```


| [Impacted Files](https://codecov.io/gh/einsteinpy/einsteinpy/pull/317?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/einsteinpy/symbolic/stress\_energy\_momentum.py](https://codecov.io/gh/einsteinpy/einsteinpy/pull/317/diff?src=pr&el=tree#diff-c3JjL2VpbnN0ZWlucHkvc3ltYm9saWMvc3RyZXNzX2VuZXJneV9tb21lbnR1bS5weQ==) | `86.95% <86.36%> (-13.05%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/einsteinpy/einsteinpy/pull/317?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/einsteinpy/einsteinpy/pull/317?src=pr&el=footer). Last update [cc772ca...e3d157c](https://codecov.io/gh/einsteinpy/einsteinpy/pull/317?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

OVSofia: @ritzvik  Should I pass to Schouten Tensor #314? Or should I do something else?
ritzvik: > @ritzvik Should I pass to Schouten Tensor #314? Or should I do something else?

I'll review this today! chill! 🤣 
ritzvik: @OVSofia squash n rebase!
OVSofia: > @OVSofia squash n rebase!


I had to do it in two parts (commits) so that the squash did not repeat commits from other PRs  >.< 
ritzvik: Ok I'll take care of this! Complete the PR #322 

Patch:
diff --git a/docs/source/api/symbolic/stress_energy_momentum.rst b/docs/source/api/symbolic/stress_energy_momentum.rst
new file mode 100644
index 0000000..0aa88df
--- /dev/null
+++ b/docs/source/api/symbolic/stress_energy_momentum.rst
@@ -0,0 +1,8 @@
+Stress Energy Momentum Tensor Module
+====================================
+
+This module contains the class for obtaining Stress Energy Momentum Tensor
+related to a Metric belonging to any arbitrary space-time symbolically:
+
+.. automodule:: einsteinpy.symbolic.stress_energy_momentum
+    :members:
diff --git a/docs/source/api/symbolic/symbolic_index.rst b/docs/source/api/symbolic/symbolic_index.rst
index c245e6b..927ec12 100644
--- a/docs/source/api/symbolic/symbolic_index.rst
+++ b/docs/source/api/symbolic/symbolic_index.rst
@@ -16,4 +16,5 @@ calculations related to General Relativity.
     ricci
     weyl
     einstein
-    vector
\ No newline at end of file
+    vector
+    stress_energy_momentum
diff --git a/src/einsteinpy/symbolic/stress_energy_momentum.py b/src/einsteinpy/symbolic/stress_energy_momentum.py
index b147520..45bc077 100644
--- a/src/einsteinpy/symbolic/stress_energy_momentum.py
+++ b/src/einsteinpy/symbolic/stress_energy_momentum.py
@@ -1,5 +1,91 @@
-from einsteinpy.symbolic.tensor import BaseRelativityTensor
+import numpy as np
+
+from einsteinpy.symbolic.constants import Cosmo_Const, G, c
+from einsteinpy.symbolic.einstein import EinsteinTensor
+from einsteinpy.symbolic.tensor import BaseRelativityTensor, _change_config
 
 
 class StressEnergyMomentumTensor(BaseRelativityTensor):
-    pass
+    """
+    Inherits from ~einsteinpy.symbolic.tensor.BaseRelativityTensor
+    Class for defining Stress-Energy Coefficient Tensor
+    """
+
+    def __init__(self, arr, syms, config="ll", parent_metric=None):
+        """
+        Constructor and Initializer
+
+        Parameters
+        ----------
+        arr : ~sympy.tensor.array.dense_ndim_array.ImmutableDenseNDimArray or list
+            Sympy Array or multi-dimensional list containing Sympy Expressions
+        syms : tuple or list
+            Tuple of crucial symbols denoting time-axis, 1st, 2nd, and 3rd axis (t,x1,x2,x3)
+        config : str
+            Configuration of contravariant and covariant indices in tensor. 'u' for upper and 'l' for lower indices. Defaults to 'll'.
+        parent_metric : ~einsteinpy.symbolic.metric.MetricTensor or None
+            Corresponding Metric for the Stress-Energy Coefficient Tensor.
+            Defaults to None.
+
+        Raises
+        ------
+        TypeError
+            Raised when arr is not a list or sympy Array
+        TypeError
+            syms is not a list or tuple
+        ValueError
+            config has more or less than 2 indices
+
+        """
+        super(StressEnergyMomentumTensor, self).__init__(
+            arr=arr, syms=syms, config=config, parent_metric=parent_metric
+        )
+        self._order = 2
+        if not len(config) == self._order:
+            raise ValueError("config should be of length {}".format(self._order))
+
+    @classmethod
+    def from_metric(cls, metric):
+        if metric.config != "ll":
+            metric = metric.inv()
+        t_einstein = EinsteinTensor.from_metric(metric)
+        stress_tensor = (
+            c ** 4
+            / (8 * np.pi * G)
+            * (t_einstein.tensor() - Cosmo_Const * metric.tensor())
+        )
+        return cls(stress_tensor, metric.syms, config="ll", parent_metric=metric)
+
+    def change_config(self, newconfig="ul", metric=None):
+        """
+        Changes the index configuration(contravariant/covariant)
+
+        Parameters
+        ----------
+        newconfig : str
+            Specify the new configuration. Defaults to 'ul'
+        metric : ~einsteinpy.symbolic.metric.MetricTensor or None
+            Parent metric tensor for changing indices.
+            Already assumes the value of the metric tensor from which it was initialized if passed with None.
+            Compulsory if somehow does not have a parent metric. Defaults to None.
+
+        Returns
+        -------
+        ~einsteinpy.symbolic.stress_energy_momentum.StressEnergyMomentumTensor
+            New tensor with new configuration. Defaults to 'ul'
+
+        Raises
+        ------
+        Exception
+            Raised when a parent metric could not be found.
+
+        """
+        if metric is None:
+            metric = self._parent_metric
+        if metric is None:
+            raise Exception("Parent Metric not found, can't do configuration change")
+        new_tensor = _change_config(self, metric, newconfig)
+        new_obj = EinsteinTensor(
+            new_tensor, self.syms, config=newconfig, parent_metric=metric
+        )
+        return new_obj


Test patch:
diff --git a/src/einsteinpy/tests/test_symbolic/test_stress_energy_momentum.py b/src/einsteinpy/tests/test_symbolic/test_stress_energy_momentum.py
new file mode 100644
index 0000000..8508119
--- /dev/null
+++ b/src/einsteinpy/tests/test_symbolic/test_stress_energy_momentum.py
@@ -0,0 +1,54 @@
+import numpy as np
+import sympy
+from sympy import cos, sin, sinh
+
+from einsteinpy.symbolic import MetricTensor, StressEnergyMomentumTensor
+
+
+def schwarzschild_metric():
+    symbolstr = "t r theta phi"
+    syms = sympy.symbols(symbolstr)
+    G, M, c, a = sympy.symbols("G M c a")
+    # using metric values of schwarschild space-time
+    # a is schwarzschild radius
+    list2d = np.zeros((4, 4), dtype=int).tolist()
+    list2d[0][0] = 1 - (a / syms[1])
+    list2d[1][1] = -1 / ((1 - (a / syms[1])) * (c ** 2))
+    list2d[2][2] = -1 * (syms[1] ** 2) / (c ** 2)
+    list2d[3][3] = -1 * (syms[1] ** 2) * (sympy.sin(syms[2]) ** 2) / (c ** 2)
+    sch = MetricTensor(list2d, syms)
+    return sch
+
+
+def test_StressEnergyMomentumTensor_ValueError_wrong_config_length():
+    testarr = np.ones((4, 4), dtype=int).tolist()
+    syms = sympy.symbols("t x y z")
+    try:
+        obj = StressEnergyMomentumTensor(
+            testarr, syms, config="lll", parent_metric=None
+        )
+        assert False
+    except ValueError:
+        assert True
+
+
+def test_StressEnergyMomentumTensor_change_config_no_parent_metric():
+    testarr = np.ones((4, 4), dtype=int).tolist()
+    syms = sympy.symbols("t x y z")
+    obj = StressEnergyMomentumTensor(testarr, syms, config="ll")
+    try:
+        obj2 = obj.change_config("lu")
+        assert False
+    except Exception:
+        assert True
+
+
+def test_StressEnergyMomentumTensor_cyclic_config_change():
+    metric = schwarzschild_metric()
+    t1 = StressEnergyMomentumTensor.from_metric(metric)
+    t2 = t1.change_config("ul")
+    t3 = t2.change_config("ll")
+    assert t1.config == "ll" and t3.config == "ll"
+    compare = sympy.Array(np.zeros((4, 4), dtype=int))
+    testarr = sympy.simplify(t1.tensor() - t3.tensor())
+    assert testarr == compare