From 95c1143cfca90714d3c5b27e57bd6d359322e328 Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Wed, 15 Sep 2021 10:20:57 -0500 Subject: [PATCH] Add length_multiplier to python API. Refs #1872 --- docs/source/io_formats/tallies.rst | 4 ++++ openmc/mesh.py | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/source/io_formats/tallies.rst b/docs/source/io_formats/tallies.rst index ad72273690..7f95f29850 100644 --- a/docs/source/io_formats/tallies.rst +++ b/docs/source/io_formats/tallies.rst @@ -318,6 +318,10 @@ attributes/sub-elements: :dimension: The number of mesh cells in each direction. (For regular mesh only.) + :length_multiplier: + A multiplicative factor to apply to the mesh coordinates in all directions. + (For unstructured mesh only.) + :lower_left: The lower-left corner of the structured mesh. If only two coordinates are given, it is assumed that the mesh is an x-y mesh. (For regular mesh only.) diff --git a/openmc/mesh.py b/openmc/mesh.py index 0e35aa6fea..f542ac5fe1 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -611,6 +611,8 @@ class UnstructuredMesh(MeshBase): ---------- filename : str Location of the unstructured mesh file + length_multiplier: float + Constant multiplier to apply to mesh coordinates mesh_id : int Unique identifier for the mesh name : str @@ -626,11 +628,16 @@ class UnstructuredMesh(MeshBase): Name of the mesh filename : str Name of the file containing the unstructured mesh + length_multiplier: float + Multiplicative factor to apply to mesh coordinates library : str Mesh library used for the unstructured mesh tally output : bool Indicates whether or not automatic tally output should be generated for this mesh + specified_length_multiplier: bool + Indicates whether a non-unity length multiplier has been + applied to this mesh volumes : Iterable of float Volumes of the unstructured mesh elements total_volume : float @@ -639,13 +646,15 @@ class UnstructuredMesh(MeshBase): An iterable of element centroid coordinates, e.g. [(0.0, 0.0, 0.0), (1.0, 1.0, 1.0), ...] """ - def __init__(self, filename, library, mesh_id=None, name=''): + def __init__(self, filename, library, mesh_id=None, name='', length_multiplier=1.0): super().__init__(mesh_id, name) self.filename = filename self._volumes = None self._centroids = None self.library = library self._output = True + self._specified_length_multiplier = False + self.length_multiplier = length_multiplier @property def filename(self): @@ -713,6 +722,18 @@ class UnstructuredMesh(MeshBase): Iterable, Real) self._centroids = centroids + @property + def length_multiplier(self): + return self._length_multiplier + + @length_multiplier.setter + def length_multiplier(self, length_multiplier): + cv.check_type("Unstructured mesh length multiplier", length_multiplier, Real) + self._length_multiplier = length_multiplier + + if (self._length_multiplier != 1.0): + self._specified_length_multiplier = True + def __repr__(self): string = super().__repr__() string += '{: <16}=\t{}\n'.format('\tFilename', self.filename) @@ -836,6 +857,9 @@ class UnstructuredMesh(MeshBase): subelement = ET.SubElement(element, "filename") subelement.text = self.filename + if (self._specified_length_multiplier): + element.set("length_multiplier", str(self.length_multiplier)) + return element @classmethod