Metric()

The main object in PyGRO is the metric_engine object which is used to describe the spacetime metric.

class pygro.metric_engine.Metric(**kwargs)

This is the main symbolic tool within PyGRO to perform tensorial calculations starting from the spacetime metric. The Metric object can be initialized in two separate ways:

Interactive mode

In this case the Metric has to be initialized without any additional argument. Later the Metric.initialize_metric() method should be called without additional arguments in order to enter the interactive mode. During this phase the user will be asked to input:

  • The name of the spacetime.

  • The symbolic coordinates in which the metric is expressed.

  • The symbolic expression of the spacetime metric which can be either expressed as a line elemnt \(ds^2 = g_{\mu\nu}dx^\mu dx^\nu\) or as the single components \(g_{\mu\nu}\) of the metric tensor.

  • The symbolix expression of transformation functions to pseudo-cartesian coordinates which can be useful to Visualize the results.

After the insertion of all the required information the metric is initialized.

Functional mode

In this case the Metric object is initialized without interactive input by the user. The arguments to build the metric can be either passed to the Metric constructor upon class initialization,

>>> spacetime_metric = pygro.Metric(**kwargs)

or as arguments to the Metric.initialize_metric() method:

>>> spacetime_metric = pygro.Metric()
>>> spacetime_metric.initialize_metric(**kwargs)

The **kwargs that can be passed to initialize a Metric object are the following:

Parameters
  • name (str) – The name of the metric to initialize.

  • coordinates (list of str) – Four-dimensional list containing the symbolic expression of the space-time coordinates in which the line_element argument is written.

  • line_element (str) – A string containing the symbolic expression of the line element (that will be parsed using sympy) expressed in the space-time coordinates defined in the coordinates argument.

Note

Test

After successful initialization, the Metric instance has the following attributes:

Variables

g – The symbolic representation of the metric tensor. It is a \(4\times4\) sympy.Matrix object.

Christoffel(mu, nu, rho)

The mu-nu-rho Christoffel symbol, \(\Gamma^{\mu}_{ u ho}\) related to the metric tensor.

get_constant(parameter)

Returns the value of the constant parameter, if defined.

initialize_metric(**kwargs)

Initializes the Metric either in Interactive or Functional mode.

Parameters

**kwargs – to pass only to access Functional mode. In this case, required parameters are name, coordinates and line_element, but additional parameters can and must be passed on occasions (see Define your own-spacetime to see examples).

load_metric(filename, verbose=True, **params)

Loads the metric from a .metric file which has been saved through the Metric.save_metric() method.

Parameters

filename (str) – The name of the .metric file from which to load the metric.

save_metric(filename)

Saves the metric into a .metric file which can later be loaded with the Metric.load_metric() method.

Parameters

filename (str) – The name of the .metric file in which to save the metric.

set_expression_to_parameter(param, expr_str)

Selects the param element from the metric.parameters dictionary, sets its kind to "expr" and assignes to it a value which is the sybolic parsed espresion in the expr_str argument.

Parameters
  • param (str) – The symbolic name of the parameter to modify.

  • expr_str (str) – The symbolic expresison to assign to this parameter.

set_function_to_parameter(param, function, **derivatives)

Selects the param element from the metric.parameters dictionary, sets its kind to "py" and assignes as its value the function method that is passed as argument.

Note

The function argument must be a method which admits four floats and returns a single float as results. However, in the line_element argument, upon initialization of the Metric, only explicit coordinate dependences of the functional parameter must be indicated. Moreover, for each of the explicit coordinate dependence of the function its derivative should also be passed in argument

Example

Parameters
  • param (str) – The symbolic name of the parameter to modify.

  • expr_str (str) – The symbolic expresison to assign to this parameter.