> For the complete documentation index, see [llms.txt](https://applied-physics.gitbook.io/warp-factory/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://applied-physics.gitbook.io/warp-factory/modules/solver-module/getenergytensor.md).

# getEnergyTensor

## Description

The input metric determines the stress-energy tensor by evaluating the field equations. This evaluation does not consider any additions from $$\Lambda$$.&#x20;

<details>

<summary>Einstein Field Equation</summary>

The stress-energy tensor $$T\_{\mu\nu}$$ is found by solving the field equation:

$$T\_{\mu\nu} = \frac{c^4}{8 \pi G} \left( R\_{\mu\nu}-\frac{1}{2}R g\_{\mu\nu} \right)$$

where the Ricci scalar$$R$$ is:

$$R = R\_{\mu\nu} g^{\mu\nu}$$

and the Ricci tensor$$R\_{\mu\nu}$$ is found directly in terms of derivatives of the metric:

$$R\_{\mu \nu}  =-\frac{1}{2} \sum\_{\alpha, \beta=0}^3\left(\frac{\partial^2 g\_{\mu \nu}}{\partial x^\alpha \partial x^\beta}+\frac{\partial^2 g\_{\alpha \beta}}{\partial x^\mu \partial x^\nu}-\frac{\partial^2 g\_{\mu \beta}}{\partial x^\nu \partial x^\alpha}-\frac{\partial^2 g\_{\nu \beta}}{\partial x^\mu \partial x^\alpha}\right) g^{\alpha \beta}$$

$$+\frac{1}{2} \sum\_{\alpha, \beta, \gamma, \delta=0}^3\left(\frac{1}{2} \frac{\partial g\_{\alpha \gamma}}{\partial x^\mu} \frac{\partial g\_{\beta \delta}}{\partial x^\nu}+\frac{\partial g\_{\mu \gamma}}{\partial x^\alpha} \frac{\partial g\_{\nu \delta}}{\partial x^\beta}-\frac{\partial g\_{\mu \gamma}}{\partial x^\alpha} \frac{\partial g\_{\nu \beta}}{\partial x^\delta}\right) g^{\alpha \beta} g^{\gamma \delta}$$

$$-\frac{1}{4} \sum\_{\alpha, \beta, \gamma, \delta=0}^3\left(\frac{\partial g\_{\nu \gamma}}{\partial x^\mu}+\frac{\partial g\_{\mu \gamma}}{\partial x^\nu}-\frac{\partial g\_{\mu \nu}}{\partial x^\gamma}\right)\left(2 \frac{\partial g\_{\beta \delta}}{\partial x^\alpha}-\frac{\partial g\_{\alpha \beta}}{\partial x^\delta}\right) g^{\alpha \beta} g^{\gamma \delta}$$

</details>

## Method

The derivatives of the metric use finite central differencing methods on the spacetime grid.

{% hint style="warning" %}
The grid size defined in the metric must be 5 or greater in any direction for the finite difference to evaluate a derivative on the grid. **If the size in a given direction is <5 then the derivative is assumed to be 0.**
{% endhint %}

## Syntax

`[`<mark style="color:green;">`energy`</mark>`] = getEnergyTensor(`<mark style="color:blue;">`metric`</mark>`,`` `<mark style="color:orange;">`tryGPU`</mark>`,`` `<mark style="color:orange;">`diffOrder`</mark>`)`

### Input Arguments

{% hint style="info" %} <mark style="color:blue;">blue</mark> are required inputs.

<mark style="color:orange;">orange</mark> are optional inputs with native default values.
{% endhint %}

<table><thead><tr><th width="232">Inputs</th><th width="94">Format</th><th width="92">Type</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:blue;"><code>metric</code></mark> </td><td>struct</td><td>object</td><td>Input metric tensor. </td></tr><tr><td><mark style="color:orange;"><code>tryGPU</code></mark> </td><td>1x1 array</td><td>integer</td><td>Use the GPU for evaluations, input either 1 for true or 0 for false. <strong>The default value is 0.</strong></td></tr><tr><td><mark style="color:orange;"><code>diffOrder</code></mark></td><td>1x1 array</td><td>string</td><td>Sets the order of the finite difference method. Accepts either "<em>second</em>" to use second-order or "<em>fourth</em>" to use fourth-order methods. <strong>The default value is fourth order.</strong></td></tr></tbody></table>

### Output Arguments

<table><thead><tr><th width="192">Outputs</th><th width="94.33333333333331">Format</th><th width="96">Type</th><th>Description</th></tr></thead><tbody><tr><td><mark style="color:green;"><code>energy</code></mark></td><td>struct</td><td>object</td><td>Returns the stress-energy tensor with the same grid and frame as the metric tensor. Note that it returns the contravariant form of the tensor, which can also be found by checking the <code>.index</code> field of the struct.</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://applied-physics.gitbook.io/warp-factory/modules/solver-module/getenergytensor.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
