-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new test for constraint function
- Loading branch information
1 parent
9ba0f7e
commit fea65b9
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |