Skip to content

Commit

Permalink
fix assert mesh =
Browse files Browse the repository at this point in the history
  • Loading branch information
tf17270 committed May 24, 2024
1 parent 23d4522 commit 6319531
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
3 changes: 2 additions & 1 deletion lyceanem/tests/test_base_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def standard_antenna():
return antenna()



def test_excitation_function_x_u(standard_antenna):
# test that an unrotated antenna with u (horizontal-y) polarisation gives horizontal-y polarisation
desired_E_vector = np.array([1, 0, 0], dtype=np.complex64)
Expand Down Expand Up @@ -138,4 +139,4 @@ def test_excitation_function_x_mz_cp(standard_antenna):
standard_antenna.excitation_function(desired_e_vector=desired_E_vector),
final_vector,
atol=1e-12,
)
)
63 changes: 34 additions & 29 deletions lyceanem/tests/test_geometryfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,60 +17,65 @@ def standard_cube():

def are_meshes_equal(mesh1, mesh2, rtol=1e-5):
# Check vertices
assert np.allclose(mesh1.points, mesh2.points, rtol=rtol)
meshes_are_equal = True
meshes_are_equal = np.allclose(mesh1.points, mesh2.points, rtol=rtol)


# Check cells
assert len(mesh1.cells) == len(mesh2.cells)
meshes_are_equal = len(mesh1.cells) == len(mesh2.cells)
for i in range(len(mesh1.cells)):
assert np.allclose(mesh1.cells[i].data, mesh2.cells[i].data, rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cells[i].data, mesh2.cells[i].data, rtol=rtol)
## normals
print("checking 'normffffals3")

if 'nx' in mesh1.point_data and 'ny' in mesh1.point_data and 'nz' in mesh1.point_data:
if 'nx' in mesh2.point_data and 'ny' in mesh2.point_data and 'nz' in mesh2.point_data:
assert np.allclose(mesh1.point_data['nx'], mesh2.point_data['nx'], rtol=rtol)
assert np.allclose(mesh1.point_data['ny'], mesh2.point_data['ny'], rtol=rtol)
assert np.allclose(mesh1.point_data['nz'], mesh2.point_data['nz'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['nx'], mesh2.point_data['nx'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['ny'], mesh2.point_data['ny'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['nz'], mesh2.point_data['nz'], rtol=rtol)
elif 'Normals' in mesh2.point_data:
assert np.allclose(mesh1.point_data['nx'], mesh2.point_data['Normals'][:,0], rtol=rtol)
assert np.allclose(mesh1.point_data['ny'], mesh2.point_data['Normals'][:,1], rtol=rtol)
assert np.allclose(mesh1.point_data['nz'], mesh2.point_data['Normals'][:,2], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['nx'], mesh2.point_data['Normals'][:,0], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['ny'], mesh2.point_data['Normals'][:,1], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['nz'], mesh2.point_data['Normals'][:,2], rtol=rtol)
else:
assert False
meshes_are_equal *= False
elif 'Normals' in mesh1.point_data:
if 'nx' and 'ny' and 'nz' in mesh2.point_data:
assert np.allclose(mesh1.point_data['Normals'][:,0], mesh2.point_data['nx'], rtol=rtol)
assert np.allclose(mesh1.point_data['Normals'][:,1], mesh2.point_data['ny'], rtol=rtol)
assert np.allclose(mesh1.point_data['Normals'][:,2], mesh2.point_data['nz'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['Normals'][:,0], mesh2.point_data['nx'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['Normals'][:,1], mesh2.point_data['ny'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['Normals'][:,2], mesh2.point_data['nz'], rtol=rtol)
print("checking 'normals3")
elif 'Normals' in mesh2.point_data:
assert np.allclose(mesh1.point_data['Normals'], mesh2.point_data['Normals'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.point_data['Normals'], mesh2.point_data['Normals'], rtol=rtol)
else:
assert False
meshes_are_equal *= False
else:
assert True
meshes_are_equal *= True
##normals cell data
for i in range(len(mesh1.cells)):
if 'nx' and 'ny' and 'nz' in mesh1.cell_data:
if 'nx' and 'ny' and 'nz' in mesh2.cell_data:
assert np.allclose(mesh1.cell_data['nx'], mesh2.cell_data['nx'], rtol=rtol)
assert np.allclose(mesh1.cell_data['ny'], mesh2.cell_data['ny'], rtol=rtol)
assert np.allclose(mesh1.cell_data['nz'], mesh2.cell_data['nz'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['nx'], mesh2.cell_data['nx'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['ny'], mesh2.cell_data['ny'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['nz'], mesh2.cell_data['nz'], rtol=rtol)
elif 'Normals' in mesh2.cell_data:
assert np.allclose(mesh1.cell_data['nx'], mesh2.cell_data['Normals'][:,0], rtol=rtol)
assert np.allclose(mesh1.cell_data['ny'], mesh2.cell_data['Normals'][:,1], rtol=rtol)
assert np.allclose(mesh1.cell_data['nz'], mesh2.cell_data['Normals'][:,2], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['nx'], mesh2.cell_data['Normals'][:,0], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['ny'], mesh2.cell_data['Normals'][:,1], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['nz'], mesh2.cell_data['Normals'][:,2], rtol=rtol)
else:
assert False
meshes_are_equal *= False
elif 'Normals' in mesh1.cell_data:
if 'nx' and 'ny' and 'nz' in mesh2.cell_data:
assert np.allclose(mesh1.cell_data['Normals'][:,0], mesh2.cell_data['nx'], rtol=rtol)
assert np.allclose(mesh1.cell_data['Normals'][:,1], mesh2.cell_data['ny'], rtol=rtol)
assert np.allclose(mesh1.cell_data['Normals'][:,2], mesh2.cell_data['nz'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['Normals'][:,0], mesh2.cell_data['nx'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['Normals'][:,1], mesh2.cell_data['ny'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['Normals'][:,2], mesh2.cell_data['nz'], rtol=rtol)
elif 'Normals' in mesh2.cell_data:
assert np.allclose(mesh1.cell_data['Normals'], mesh2.cell_data['Normals'], rtol=rtol)
meshes_are_equal *= np.allclose(mesh1.cell_data['Normals'], mesh2.cell_data['Normals'], rtol=rtol)
else:
assert False
meshes_are_equal *= False
else:
assert True
meshes_are_equal *= True
return meshes_are_equal



Expand Down

0 comments on commit 6319531

Please sign in to comment.