Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Centre for cylinder & spherical meshes #2256

Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
facc199
marks
RemDelaporteMathurin Oct 5, 2022
2a4c8bb
centre attribute to CylindricalMesh and SphericalMesh
RemDelaporteMathurin Oct 7, 2022
c20b351
write to xml
RemDelaporteMathurin Oct 7, 2022
81ac9b0
setters/getters
RemDelaporteMathurin Oct 7, 2022
f0f5e34
read centre from xml
RemDelaporteMathurin Oct 7, 2022
5787616
added two tests to check centre was written/read to/from xml
RemDelaporteMathurin Oct 7, 2022
16add87
now reads back from xml
RemDelaporteMathurin Oct 7, 2022
21200d9
offsets the write_to_vtk coordinates
RemDelaporteMathurin Oct 7, 2022
896ae27
centre to centre_
RemDelaporteMathurin Oct 7, 2022
d194e00
test if grid_ is defined in this scope
RemDelaporteMathurin Oct 7, 2022
a104c1f
[skip ci] removed test
RemDelaporteMathurin Oct 7, 2022
bdd13ba
attempt #2
RemDelaporteMathurin Oct 7, 2022
e394637
declare variable with auto
RemDelaporteMathurin Oct 7, 2022
61b4f30
declaring centre_ in C file
RemDelaporteMathurin Oct 7, 2022
fc5aa68
removed auto + ;
RemDelaporteMathurin Oct 7, 2022
e1dbe49
correct type for centre_
RemDelaporteMathurin Oct 7, 2022
1ed096f
added centre tag to standard
RemDelaporteMathurin Oct 7, 2022
5632a40
Merge branch 'develop' into centre_for_cylinder_spherical_meshes
RemDelaporteMathurin Oct 7, 2022
94547f7
new type for centre_
RemDelaporteMathurin Oct 11, 2022
15f45bc
substract before mapping
RemDelaporteMathurin Oct 11, 2022
27e3bb4
array<double, 3> for origin CylindricalMesh
RemDelaporteMathurin Oct 11, 2022
76fbdf7
centre to origin
RemDelaporteMathurin Oct 11, 2022
b2d1729
origin_ instead of origin
RemDelaporteMathurin Oct 11, 2022
adad6e7
Making origin type Positiong. Adding function to parse position from …
pshriwise Oct 11, 2022
3bdb123
Merge branch 'centre_for_cylinder_spherical_meshes' of https://github…
RemDelaporteMathurin Oct 11, 2022
408f2fd
Merge branch 'pshriwise-centre_for_cylinder_spherical_meshes' into ce…
RemDelaporteMathurin Oct 11, 2022
a97b202
updated to_hdf5
RemDelaporteMathurin Oct 11, 2022
3792c6f
fixed unit test
RemDelaporteMathurin Oct 11, 2022
48d75ac
fixed cylindrical mesh test
RemDelaporteMathurin Oct 11, 2022
c6b89fe
fixed gold standard
RemDelaporteMathurin Oct 11, 2022
444a800
Naming tally in activation unit test
pshriwise Oct 12, 2022
9ecaafa
Merge pull request #3 from pshriwise/centre_for_cylinder_spherical_me…
RemDelaporteMathurin Oct 12, 2022
b0743df
fixed cv.check_type origin
RemDelaporteMathurin Oct 21, 2022
b874d83
only translate when origin is not 0, 0, 0
RemDelaporteMathurin Oct 21, 2022
f60f95f
[skip ci] removed # TODOs
RemDelaporteMathurin Nov 18, 2022
c5affa8
Review suggestions
RemDelaporteMathurin Nov 21, 2022
6d787d5
Apply suggestions from code review
RemDelaporteMathurin Nov 21, 2022
8681751
check length origin
RemDelaporteMathurin Nov 21, 2022
df1a45b
origin from_hdf5
RemDelaporteMathurin Nov 21, 2022
b63ec9c
read mesh optional
RemDelaporteMathurin Nov 21, 2022
f51f181
fixed optional xml reading
RemDelaporteMathurin Nov 21, 2022
3325667
minor version bump for statepoint files
RemDelaporteMathurin Nov 21, 2022
10a9518
origin is tuple + fixed any
RemDelaporteMathurin Nov 21, 2022
f0721ac
Apply suggestions from code review
RemDelaporteMathurin Nov 21, 2022
11eee75
Corrections to application of origin for sphere and cyl mesh
pshriwise Jan 26, 2023
b22c7e8
Adding test cases for cylindrical mesh
pshriwise Jan 26, 2023
3703fdb
Adding origin to sphere and cyl mesh str
pshriwise Jan 26, 2023
b1a5d0b
Merge pull request #4 from pshriwise/centre_for_cylinder_spherical_me…
RemDelaporteMathurin Jan 30, 2023
17d88d8
added tests for spherical mesh
RemDelaporteMathurin Jan 30, 2023
90995dc
Merge branch 'develop' into centre_for_cylinder_spherical_meshes
RemDelaporteMathurin Feb 2, 2023
1e94a0c
fixed theta_grid spherical mesh
RemDelaporteMathurin Feb 2, 2023
af16239
Updating mesh centre tests.
pshriwise Feb 8, 2023
ef2ef4d
Merge pull request #5 from pshriwise/centre_for_cylinder_spherical_me…
RemDelaporteMathurin Feb 13, 2023
c634a14
added origin to docstrings
RemDelaporteMathurin Feb 17, 2023
f961fc9
[skip ci] Modified the XML specs
RemDelaporteMathurin Feb 21, 2023
2f9f500
removed check and always offset origin
RemDelaporteMathurin Feb 27, 2023
c61e735
empty_like instead of copy
RemDelaporteMathurin Feb 27, 2023
9ca6f1b
fixed docstrings for origin
RemDelaporteMathurin Feb 27, 2023
972e1c1
[skip ci] Minor refactoring
RemDelaporteMathurin Feb 27, 2023
308be3f
Update openmc/mesh.py
RemDelaporteMathurin Feb 27, 2023
c71c134
added grids in statepoint specs
RemDelaporteMathurin Feb 27, 2023
5946763
Moving origin data member down into Cylindrical/Spherical mesh using …
pshriwise Mar 4, 2023
b02e558
Adding docstring. Updating method name
pshriwise Mar 5, 2023
1b29adb
Merge pull request #6 from pshriwise/centre_for_cylinder_spherical_me…
RemDelaporteMathurin Mar 6, 2023
527f5f7
Merge branch 'develop' into centre_for_cylinder_spherical_meshes
pshriwise Mar 6, 2023
ab4237c
use get_reshaped_data in tests
RemDelaporteMathurin Mar 7, 2023
024c51a
Merge branch 'centre_for_cylinder_spherical_meshes' of https://github…
RemDelaporteMathurin Mar 7, 2023
2d573c3
Merge branch 'develop' into centre_for_cylinder_spherical_meshes
pshriwise Mar 16, 2023
bb5f727
Update IO format docs for meshes
paulromano Mar 21, 2023
a091bee
Merge pull request #7 from paulromano/pr-2256-docs
RemDelaporteMathurin Mar 22, 2023
10f2a94
Merge branch 'develop' into centre_for_cylinder_spherical_meshes
RemDelaporteMathurin Mar 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 42 additions & 2 deletions openmc/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def _grids(self):
pass

@property
def vertices(self):
def vertices(self): # TODO needs changing
RemDelaporteMathurin marked this conversation as resolved.
Show resolved Hide resolved
"""Return coordinates of mesh vertices.

Returns
Expand All @@ -178,7 +178,7 @@ def vertices(self):
return np.stack(np.meshgrid(*self._grids, indexing='ij'), axis=-1)

@property
def centroids(self):
def centroids(self): # TODO needs changing
RemDelaporteMathurin marked this conversation as resolved.
Show resolved Hide resolved
"""Return coordinates of mesh element centroids.

Returns
Expand Down Expand Up @@ -1052,6 +1052,7 @@ def __init__(self, mesh_id=None, name=''):
self._r_grid = None
self._phi_grid = [0.0, 2*pi]
self._z_grid = None
self._centre = [0., 0., 0.]

@property
def dimension(self):
Expand All @@ -1063,6 +1064,10 @@ def dimension(self):
def n_dimension(self):
return 3

@property
def centre(self):
return self._centre

@property
def r_grid(self):
return self._r_grid
Expand All @@ -1089,6 +1094,11 @@ def indices(self):
for p in range(1, np + 1)
for r in range(1, nr + 1))

@centre.setter
def centre(self, coords):
cv.check_type('mesh r_grid', coords, Iterable, Real)
self._centre = np.asarray(coords)

@r_grid.setter
def r_grid(self, grid):
cv.check_type('mesh r_grid', grid, Iterable, Real)
Expand Down Expand Up @@ -1160,6 +1170,9 @@ def to_xml_element(self):
subelement = ET.SubElement(element, "z_grid")
subelement.text = ' '.join(map(str, self.z_grid))

subelement = ET.SubElement(element, "centre")
subelement.text = ' '.join(map(str, self.centre))

return element

@classmethod
Expand All @@ -1183,6 +1196,8 @@ def from_xml_element(cls, elem):
mesh.r_grid = [float(x) for x in get_text(elem, "r_grid").split()]
mesh.phi_grid = [float(x) for x in get_text(elem, "phi_grid").split()]
mesh.z_grid = [float(x) for x in get_text(elem, "z_grid").split()]
mesh.centre = [float(x) for x in get_text(elem, "centre").split()]

return mesh

@property
Expand Down Expand Up @@ -1236,6 +1251,11 @@ def write_data_to_vtk(self, filename, datasets, volume_normalization=True):
pts_cartesian[:, 0] = r * np.cos(phi)
pts_cartesian[:, 1] = r * np.sin(phi)

# offset with centre
pts_cartesian[:, 0] = pts_cartesian[:, 0] + self.centre[0]
pts_cartesian[:, 1] = pts_cartesian[:, 1] + self.centre[1]
pts_cartesian[:, 2] = pts_cartesian[:, 2] + self.centre[2]

return super().write_data_to_vtk(
points=pts_cartesian,
filename=filename,
Expand Down Expand Up @@ -1284,6 +1304,7 @@ def __init__(self, mesh_id=None, name=''):
self._r_grid = None
self._theta_grid = [0, pi]
self._phi_grid = [0, 2*pi]
self._centre = [0., 0., 0.]

@property
def dimension(self):
Expand All @@ -1295,6 +1316,10 @@ def dimension(self):
def n_dimension(self):
return 3

@property
def centre(self):
return self._centre

@property
def r_grid(self):
return self._r_grid
Expand All @@ -1321,6 +1346,11 @@ def indices(self):
for t in range(1, nt + 1)
for r in range(1, nr + 1))

@centre.setter
def centre(self, coords):
cv.check_type('mesh r_grid', coords, Iterable, Real)
self._centre = np.asarray(coords)

@r_grid.setter
def r_grid(self, grid):
cv.check_type('mesh r_grid', grid, Iterable, Real)
Expand Down Expand Up @@ -1392,6 +1422,9 @@ def to_xml_element(self):
subelement = ET.SubElement(element, "phi_grid")
subelement.text = ' '.join(map(str, self.phi_grid))

subelement = ET.SubElement(element, "centre")
subelement.text = ' '.join(map(str, self.centre))

return element

@classmethod
Expand All @@ -1415,6 +1448,8 @@ def from_xml_element(cls, elem):
mesh.r_grid = [float(x) for x in get_text(elem, "r_grid").split()]
mesh.theta_grid = [float(x) for x in get_text(elem, "theta_grid").split()]
mesh.phi_grid = [float(x) for x in get_text(elem, "phi_grid").split()]
mesh.centre = [float(x) for x in get_text(elem, "centre").split()]

return mesh

@property
Expand Down Expand Up @@ -1470,6 +1505,11 @@ def write_data_to_vtk(self, filename, datasets, volume_normalization=True):
pts_cartesian[:, 1] = r * np.sin(phi) * np.sin(theta)
pts_cartesian[:, 2] = r * np.cos(phi)

# offset with centre
pts_cartesian[:, 0] = pts_cartesian[:, 0] + self.centre[0]
pts_cartesian[:, 1] = pts_cartesian[:, 1] + self.centre[1]
pts_cartesian[:, 2] = pts_cartesian[:, 2] + self.centre[2]

return super().write_data_to_vtk(
points=pts_cartesian,
filename=filename,
Expand Down
15 changes: 15 additions & 0 deletions src/mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,7 @@ CylindricalMesh::CylindricalMesh(pugi::xml_node node) : StructuredMesh {node}
grid_[0] = get_node_array<double>(node, "r_grid");
grid_[1] = get_node_array<double>(node, "phi_grid");
grid_[2] = get_node_array<double>(node, "z_grid");
centre_ = get_node_array<double>(node, "centre");

if (int err = set_grid()) {
fatal_error(openmc_err_msg);
Expand Down Expand Up @@ -983,6 +984,11 @@ StructuredMesh::MeshIndex CylindricalMesh::get_indices(
mapped_r[1] += 2 * M_PI;
}

// TODO: pass centre as argument
mapped_r[0] += centre_[0]
mapped_r[1] += centre_[1]
mapped_r[2] += centre_[2]

MeshIndex idx = StructuredMesh::get_indices(mapped_r, in_mesh);

idx[1] = sanitize_phi(idx[1]);
Expand Down Expand Up @@ -1187,6 +1193,7 @@ SphericalMesh::SphericalMesh(pugi::xml_node node) : StructuredMesh {node}
grid_[0] = get_node_array<double>(node, "r_grid");
grid_[1] = get_node_array<double>(node, "theta_grid");
grid_[2] = get_node_array<double>(node, "phi_grid");
centre_ = get_node_array<double>(node, "centre");

if (int err = set_grid()) {
fatal_error(openmc_err_msg);
Expand Down Expand Up @@ -1216,6 +1223,14 @@ StructuredMesh::MeshIndex SphericalMesh::get_indices(
mapped_r[2] += 2 * M_PI;
}

// test
coucou = grid_[0]
shimwell marked this conversation as resolved.
Show resolved Hide resolved

// TODO: pass centre as argument
RemDelaporteMathurin marked this conversation as resolved.
Show resolved Hide resolved
mapped_r[0] += centre_[0]
mapped_r[1] += centre_[1]
mapped_r[2] += centre_[2]

MeshIndex idx = StructuredMesh::get_indices(mapped_r, in_mesh);

idx[1] = sanitize_theta(idx[1]);
Expand Down
30 changes: 30 additions & 0 deletions tests/unit_tests/test_cylindrical_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import openmc
import numpy as np

def test_centre_read_write_to_xml():
"""Tests that the centre attribute can be written and read back to XML
"""
# build
mesh = openmc.CylindricalMesh()
mesh.phi_grid = [1, 2, 3]
mesh.z_grid = [1, 2, 3]
mesh.r_grid = [1, 2, 3]

mesh.centre = [0.1, 0.2, 0.3]

tally = openmc.Tally()

mesh_filter = openmc.MeshFilter(mesh)
tally.filters.append(mesh_filter)

tally.scores.append("heating")

tallies = openmc.Tallies([tally])

tallies.export_to_xml()

# read back
new_tallies = openmc.Tallies.from_xml()
new_tally = new_tallies[0]
new_mesh = new_tally.filters[0].mesh
assert np.allclose(new_mesh.centre, mesh.centre)
30 changes: 30 additions & 0 deletions tests/unit_tests/test_spherical_mesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import openmc
import numpy as np

def test_centre_read_write_to_xml():
"""Tests that the centre attribute can be written and read back to XML
"""
# build
mesh = openmc.SphericalMesh()
mesh.phi_grid = [1, 2, 3]
mesh.theta_grid = [1, 2, 3]
mesh.r_grid = [1, 2, 3]

mesh.centre = [0.1, 0.2, 0.3]

tally = openmc.Tally()

mesh_filter = openmc.MeshFilter(mesh)
tally.filters.append(mesh_filter)

tally.scores.append("heating")

tallies = openmc.Tallies([tally])

tallies.export_to_xml()

# read back
new_tallies = openmc.Tallies.from_xml()
new_tally = new_tallies[0]
new_mesh = new_tally.filters[0].mesh
assert np.allclose(new_mesh.centre, mesh.centre)