Hello everyone. I’ll do it quick, ’cause I’m really tired, and by the way, today… Feb. 8th, I’m turning 30 years old 🙂
First of all, I create a page in my google site for the GRmodule files. Note that the name is GRmodule and not GR-module, because the dash is not admissible in a module name (beginner mistake!)
In the last post…
The Metric class was defined, and the first steps of the implementation were walked.
Inverting the metric
Once the components of the metric are given, one can call the invert method for assigning the inverse of the metric. Don’t know why, but I’d like to keep track of what’s going on! so, I change a little bit the code from Sergei, and my invert method returns the inverse metric tensor,
def invert(self): '''Find the inverse of the metric and store the result in a Metric object self.inverse''' '''Create a unit matrix of dimension dim''' temp = sympy.eye(self.dim) '''Assign the values of the metric to temp''' for key in self.components.keys(): id = tuple(np.abs(key)) temp[id] = self.components[key] '''invert the matrix with inv() from sympy''' inv = temp.inv() '''convert the matrix in a dictionary''' inverse = self._dictkeycopy(self.components) for i in range(self.dim): for j in range(self.dim): inverse[i,j] = inv[i,j] self.inverse = Metric(self.coord,rank=(2,0),sh=(1,1),symbol='g_inv') self.inverse.components = inverse return self.inverse
First a temporal matrix is created, and just for assuring it’s invertible, one creates a unit matrix of dimension dim. That’s what the sympy.eye does!
Secondly, the values of the metric are assigned to temp.
The temp matrix is inverted. The sympy command to inver a matrix is inv.
Next, the inverse matrix is converted in a dictionary (just like in previous cases).
Finally, the characteristic of tensor is given to the inverse matrix object… and it’s returned!, i.e., it can be assigned.
In the implementation file the components of the metric are assigned, the metric is invert… and the result of the inversion is printed.
How to run it?!
$ python Proof-GR-module.py > Result.txt
$ emacs Result.txt
Happy B-day to me!!! 🙂