Skip to content

Commit c65d414

Browse files
committed
Added method to compute mesh resolution for rectangular prisms
1 parent f64e275 commit c65d414

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

exodus_helper/element_calculations.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def calculate_volume_element(coords, shape_functions='trilinear'):
1818
Args:
1919
coords (list(list(float))): A length-8 (HEX) list of nodal
2020
coordinate values.
21-
shape_functions (str, optional): The name of the shape function used to
22-
interpolate the element's volume from a list of discrete nodal
21+
shape_functions (str, optional): The name of the shape function used to
22+
interpolate the element's volume from a list of discrete nodal
2323
coordinate values. Defaults to `trilinear`.
2424
2525
Returns:
@@ -190,7 +190,7 @@ def calculate_volume_hexahedron(coords):
190190
numpy.float64: The volume of the hexahedron.
191191
192192
Raises:
193-
AssertionError: The coordinates are not compatible with right-hand
193+
AssertionError: The coordinates are not compatible with right-hand
194194
positive winding.
195195
"""
196196
centroid = np.mean(coords, axis=0)
@@ -215,8 +215,8 @@ def calculate_volume_hexahedron(coords):
215215
return volume
216216

217217

218-
def calculate_volumes_element(mesh, id_blk):
219-
"""Calculate the volume of each element in a specified element block within
218+
def calculate_volumes_element(mesh, id_blk=None):
219+
"""Calculate the volume of each element in a specified element block within
220220
a given mesh.
221221
222222
Args:
@@ -226,8 +226,11 @@ def calculate_volumes_element(mesh, id_blk):
226226
Returns:
227227
numpy.ndarray(float): An array of element volumes ordered by element ID
228228
"""
229-
connectivity, num_elems, num_nodes = mesh.get_elem_connectivity(id_blk)
230-
connectivity = connectivity.reshape((num_elems, num_nodes))
229+
if id_blk:
230+
connectivity, num_elems, num_nodes = mesh.get_elem_connectivity(id_blk)
231+
connectivity = connectivity.reshape((num_elems, num_nodes))
232+
else:
233+
connectivity = mesh.get_elem_connectivity_full()
231234
coords_node = np.column_stack(mesh.get_coords())
232235
volumes_element = np.array(
233236
[calculate_volume_element(coords_node[ns - 1]) for ns in connectivity])
@@ -241,7 +244,7 @@ def calculate_volumes_block(mesh):
241244
mesh (Exodus): The `Exodus` instance of a mesh.
242245
243246
Returns:
244-
numpy.ndarray(float): An array of element volumes ordered by element
247+
numpy.ndarray(float): An array of element volumes ordered by element
245248
block ID.
246249
"""
247250
ids_blk = mesh.get_elem_blk_ids()

exodus_helper/topology.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ def __init__(
176176
self.put_elem_id_map(range(1, num_elements + 1))
177177
self.put_node_id_map(range(1, num_nodes + 1))
178178

179+
@property
180+
def resolution(self):
181+
return self.get_resolution()
182+
179183
@property
180184
def shape(self):
181185
"""tuple(int, int, int): The shape of the mesh."""
@@ -261,6 +265,11 @@ def get_patches_on_surface(self, surface):
261265
[coordinates[f - 1] for f in face[1][:num_check]]))
262266
return patches
263267

268+
def get_resolution(self):
269+
conn = self.get_elem_connectivity_full()
270+
coords = np.column_stack(self.get_coords())
271+
return np.max(np.abs(np.diff(coords[conn[0] - 1], axis=0)), axis=0)
272+
264273
def get_shape(self):
265274
num_xs = self.numElem // self.get_elements_on_surface(1).size
266275
num_ys = self.numElem // self.get_elements_on_surface(3).size

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = 'poetry.core.masonry.api'
44

55
[tool.poetry]
66
name = 'exodus_helper'
7-
version = '1.0.3'
7+
version = '1.0.4'
88
description = 'A package for manipulating ExodusII databases'
99
license = 'BSD-3-Clause'
1010
authors = ['Coleman Alleman <callema@sandia.gov>']

tests/test_exodus_helper.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,20 @@ def test_get_qa_records(mesh):
866866
assert isinstance(record[3], str)
867867

868868

869+
def test_get_resolution(dir_test_file, monkeypatch):
870+
try:
871+
shape = (3, 4, 5)
872+
resolution = (0.3, 0.2, 0.1)
873+
file_path = os.path.join(dir_test_file, 'test_get_shape.g')
874+
monkeypatch.setattr('builtins.input', lambda _: 'y')
875+
mesh = exodus_helper.RectangularPrism(
876+
file_path, shape=shape, resolution=resolution, mode='w')
877+
assert np.allclose(mesh.get_resolution(), resolution)
878+
mesh.close()
879+
finally:
880+
os.remove(file_path)
881+
882+
869883
def test_get_shape(dir_test_file, monkeypatch):
870884
try:
871885
shape = (3, 4, 5)

0 commit comments

Comments
 (0)