mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Merge pull request #2101 from RemDelaporteMathurin/num_mesh_cells
`num_mesh_cells` property for all `StructuredMesh` classes
This commit is contained in:
commit
6549067c43
2 changed files with 7 additions and 6 deletions
|
|
@ -193,6 +193,10 @@ class StructuredMesh(MeshBase):
|
|||
s1 = (slice(1, None),)*ndim + (slice(None),)
|
||||
return (vertices[s0] + vertices[s1]) / 2
|
||||
|
||||
@property
|
||||
def num_mesh_cells(self):
|
||||
return np.prod(self.dimension)
|
||||
|
||||
def write_data_to_vtk(self, points, filename, datasets, volume_normalization=True):
|
||||
"""Creates a VTK object of the mesh
|
||||
|
||||
|
|
@ -344,10 +348,6 @@ class RegularMesh(StructuredMesh):
|
|||
dims = self._dimension
|
||||
return [(u - l) / d for u, l, d in zip(us, ls, dims)]
|
||||
|
||||
@property
|
||||
def num_mesh_cells(self):
|
||||
return np.prod(self._dimension)
|
||||
|
||||
@property
|
||||
def volumes(self):
|
||||
"""Return Volumes for every mesh cell
|
||||
|
|
@ -1547,6 +1547,7 @@ class UnstructuredMesh(MeshBase):
|
|||
"been loaded from a statepoint file.")
|
||||
return len(self._centroids)
|
||||
|
||||
|
||||
@centroids.setter
|
||||
def centroids(self, centroids):
|
||||
cv.check_type("Unstructured mesh centroids", centroids,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ def test_write_data_to_vtk(mesh, tmpdir):
|
|||
# BUILD
|
||||
filename = Path(tmpdir) / "out.vtk"
|
||||
|
||||
data = np.random.random(mesh.dimension[0]*mesh.dimension[1]*mesh.dimension[2])
|
||||
data = np.random.random(mesh.num_mesh_cells)
|
||||
|
||||
# RUN
|
||||
mesh.write_data_to_vtk(filename=filename, datasets={"label1": data, "label2": data})
|
||||
|
|
@ -68,7 +68,7 @@ def test_write_data_to_vtk_size_mismatch(mesh):
|
|||
mesh : openmc.StructuredMesh
|
||||
The mesh to test
|
||||
"""
|
||||
right_size = mesh.dimension[0]*mesh.dimension[1]*mesh.dimension[2]
|
||||
right_size = mesh.num_mesh_cells
|
||||
data = np.random.random(right_size + 1)
|
||||
|
||||
expected_error_msg = "The size of the dataset label should be equal to the number of cells"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue