mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 13:45:36 -04:00
Fix spherical coords again. (#2538)
This commit is contained in:
parent
19282cb088
commit
7479a9022a
2 changed files with 46 additions and 4 deletions
|
|
@ -1338,7 +1338,7 @@ class CylindricalMesh(StructuredMesh):
|
|||
pts_cartesian[:, 0] = r * np.cos(phi) + self.origin[0]
|
||||
pts_cartesian[:, 1] = r * np.sin(phi) + self.origin[1]
|
||||
pts_cartesian[:, 2] += self.origin[2]
|
||||
|
||||
|
||||
return super().write_data_to_vtk(
|
||||
points=pts_cartesian,
|
||||
filename=filename,
|
||||
|
|
@ -1585,9 +1585,9 @@ class SphericalMesh(StructuredMesh):
|
|||
|
||||
r, theta, phi = pts_spherical[:, 0], pts_spherical[:, 1], pts_spherical[:, 2]
|
||||
|
||||
pts_cartesian[:, 0] = r * np.sin(phi) * np.cos(theta) + self.origin[0]
|
||||
pts_cartesian[:, 1] = r * np.sin(phi) * np.sin(theta) + self.origin[1]
|
||||
pts_cartesian[:, 2] = r * np.cos(phi) + self.origin[2]
|
||||
pts_cartesian[:, 0] = r * np.sin(theta) * np.cos(phi) + self.origin[0]
|
||||
pts_cartesian[:, 1] = r * np.sin(theta) * np.sin(phi) + self.origin[1]
|
||||
pts_cartesian[:, 2] = r * np.cos(theta) + self.origin[2]
|
||||
|
||||
return super().write_data_to_vtk(
|
||||
points=pts_cartesian,
|
||||
|
|
|
|||
|
|
@ -273,3 +273,45 @@ def test_vtk_write_ordering(model, mesh, surface):
|
|||
# need to get flat index with axes reversed due to ordering passed into the VTK file
|
||||
flat_idx = np.ravel_multi_index(tuple(ijk[::-1]), mesh.dimension[::-1])
|
||||
assert vtk_data[flat_idx] == 0.0, err_msg
|
||||
|
||||
|
||||
def test_sphere_mesh_coordinates(run_in_tmpdir):
|
||||
mesh = openmc.SphericalMesh()
|
||||
mesh.r_grid = np.linspace(0.1, 10, 30)
|
||||
mesh.phi_grid = np.linspace(0, 1.5*np.pi, 25)
|
||||
mesh.theta_grid = np.linspace(0, np.pi / 2, 15)
|
||||
|
||||
# write the data to a VTK file (no data)
|
||||
vtk_filename = 'test.vtk'
|
||||
mesh.write_data_to_vtk(vtk_filename, {})
|
||||
|
||||
# read file
|
||||
reader = vtk.vtkStructuredGridReader()
|
||||
reader.SetFileName(str(vtk_filename))
|
||||
reader.Update()
|
||||
|
||||
vtk_grid = reader.GetOutput()
|
||||
|
||||
# create a region that matches the spherical mesh description
|
||||
x = openmc.XPlane()
|
||||
z = openmc.ZPlane()
|
||||
y = openmc.YPlane()
|
||||
s = openmc.Sphere(r=10.0)
|
||||
|
||||
region = +z & +y & -s | -x & -y & +z & -s
|
||||
|
||||
# the VTK interface will update this list when GetCentroid is called
|
||||
centroid = np.zeros(3)
|
||||
|
||||
# ensure all centroids of the sphere mesh are inside the cell region
|
||||
for i in range(vtk_grid.GetNumberOfCells()):
|
||||
# get the cell from the stuctured mesh object
|
||||
cell = vtk_grid.GetCell(i)
|
||||
cell.GetCentroid(centroid)
|
||||
|
||||
# if the coordinate conversion is happening correctly,
|
||||
# every one of the cell centroids should be in the CSG region
|
||||
assert centroid in region, \
|
||||
f'Cell centroid {centroid} not in equivalent ' \
|
||||
f'CSG region for spherical mesh {mesh}'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue