Skip to content

Commit

Permalink
added new test for constraint function
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasHelfer committed Dec 29, 2023
1 parent 9ba0f7e commit fea65b9
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test_Constraints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import torch
from GeneralRelativity.FourthOrderDerivatives import diff1, diff2
from GeneralRelativity.Utils import (
get_box_format,
TensorDict,
cut_ghosts,
keys,
keys_all,
)
from GeneralRelativity.TensorAlgebra import (
compute_christoffel,
compute_christoffel_fast,
)
import os
import sys


def test_Constraints():
# Define the path to the test data files for variable X
filenamesX = os.path.dirname(__file__) + "/TestData/Xdata_level0_step*"

# Number of variables in the data
num_varsX = 104

# Read the data in a box format
dataX = get_box_format(filenamesX, num_varsX)

# Tolerance for comparison
tol = 1e-12

# Compute the differential value
oneoverdx = 64.0 / 4.0

# Prepare the data and compute derivatives using TensorDict
vars = TensorDict(cut_ghosts(dataX), keys_all)
d1 = TensorDict(diff1(dataX, oneoverdx), keys_all)
h_UU = torch.inverse(vars["h"])
chris = compute_christoffel(d1["h"], h_UU)

assert (f"{torch.mean(torch.abs(out['Ham']-vars['Ham']))}") < tol


if __name__ == "__main__":
test_Constraints()

0 comments on commit fea65b9

Please sign in to comment.