-
Notifications
You must be signed in to change notification settings - Fork 667
Export large weight window files through openmc.lib without XML serialization #4057
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
base: develop
Are you sure you want to change the base?
Changes from all commits
92ce1e7
4aeabad
9708ec0
ed9b48c
b4633d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -265,6 +265,75 @@ def axis_labels(self): | |
| """tuple of str : Names of the mesh axes, one per dimension.""" | ||
| pass | ||
|
|
||
| def to_lib_object(self, uid: int | None = None, | ||
| base_dir: PathLike | None = None): | ||
| """Create a corresponding :mod:`openmc.lib` mesh. | ||
|
|
||
| The OpenMC shared library must be initialized before calling this | ||
| method. The returned object is tied to the active library session and | ||
| becomes invalid when that session is finalized. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| uid : int, optional | ||
| ID to assign to the library mesh. If omitted, the ID of this mesh | ||
| is used. | ||
| base_dir : path-like, optional | ||
| Directory used to resolve relative filenames for unstructured | ||
| meshes. If omitted, the current working directory is used. | ||
|
|
||
| Returns | ||
| ------- | ||
| openmc.lib.Mesh | ||
| The corresponding library mesh. The concrete type depends on the | ||
| type of this mesh. | ||
|
|
||
| Raises | ||
| ------ | ||
| RuntimeError | ||
| If the OpenMC shared library has not been initialized. | ||
|
|
||
| """ | ||
| import openmc.lib | ||
|
|
||
| if not openmc.lib.is_initialized: | ||
| raise RuntimeError( | ||
| 'The OpenMC shared library must be initialized before ' | ||
| 'creating a library mesh.') | ||
|
|
||
| if uid is None: | ||
| uid = self.id | ||
| base_dir = Path.cwd() if base_dir is None else Path(base_dir) | ||
|
|
||
| if isinstance(self, RegularMesh): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO, each mesh subclass should implement how to convert itself to its lib counterpart.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tend to agree. In the vein of my other comment, this also feels appropriate for a e.g. lib_mesh = openmc.lib.Mesh.from_python_object(spherical_mesh).This makes it more natural (to me) to ensure that the |
||
| lib_mesh = openmc.lib.RegularMesh(uid=uid) | ||
| lib_mesh.dimension = self.dimension | ||
| lib_mesh.set_parameters( | ||
| lower_left=self.lower_left, upper_right=self.upper_right) | ||
| elif isinstance(self, RectilinearMesh): | ||
| lib_mesh = openmc.lib.RectilinearMesh(uid=uid) | ||
| lib_mesh.set_grid(self.x_grid, self.y_grid, self.z_grid) | ||
| elif isinstance(self, CylindricalMesh): | ||
| lib_mesh = openmc.lib.CylindricalMesh(uid=uid) | ||
| lib_mesh.set_grid(self.r_grid, self.phi_grid, self.z_grid) | ||
| lib_mesh.origin = self.origin | ||
| elif isinstance(self, SphericalMesh): | ||
| lib_mesh = openmc.lib.SphericalMesh(uid=uid) | ||
| lib_mesh.set_grid(self.r_grid, self.theta_grid, self.phi_grid) | ||
| lib_mesh.origin = self.origin | ||
| elif isinstance(self, UnstructuredMesh): | ||
| filename = Path(self.filename) | ||
| if not filename.is_absolute(): | ||
| filename = base_dir / filename | ||
| lib_mesh = openmc.lib.UnstructuredMesh.from_file( | ||
| filename.resolve(), self.library, uid=uid, | ||
| length_multiplier=self.length_multiplier, options=self.options) | ||
| else: | ||
| raise TypeError(f'Unsupported mesh type: {type(self)}') | ||
|
|
||
| lib_mesh.name = self.name | ||
| return lib_mesh | ||
|
|
||
| def __repr__(self): | ||
| string = type(self).__name__ + '\n' | ||
| string += '{0: <16}{1}{2}\n'.format('\tID', '=\t', self._id) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add some tests for these new functions in
test_lib.py