Skip to content

Commit

Permalink
Add data type option to HexaData and readnek
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinvis committed Dec 15, 2021
1 parent 8b7176f commit a2500dc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Security in case of vulnerabilities.
- Attributes `lr1` and `var` {class}`pymech.core.Elem` are tuples instead of lists
- Attributes of {class}`pymech.core.DataLims` are now immutable tuples
- {func}`pymech.dataset.open_mfdataset` is now a partial function. This change should be fully backwards compatible
- {func}`pymech.neksuite.readnek` has a `dtype` option to set the floating point data type.

### Deprecated

Expand Down
4 changes: 2 additions & 2 deletions pymech/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def face_center(self, i):
class HexaData:
"""A class containing data related to a hexahedral mesh"""

def __init__(self, ndim, nel, lr1, var, nbc=0):
def __init__(self, ndim, nel, lr1, var, nbc=0, dtype="float64"):
self.ndim = ndim
self.nel = nel
self.ncurv = []
Expand All @@ -236,7 +236,7 @@ def __init__(self, ndim, nel, lr1, var, nbc=0):
self.istep = []
self.wdsz = []
self.endian = []
self.elem = [Elem(var, lr1, nbc) for _ in repeat(nel)]
self.elem = [Elem(var, lr1, nbc, dtype) for _ in repeat(nel)]
self.elmap = np.linspace(1, nel, nel, dtype=np.int32)

def __repr__(self):
Expand Down
10 changes: 6 additions & 4 deletions pymech/neksuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ def read_header(fp: io.BufferedReader) -> Header:


# ==============================================================================
def readnek(fname):
def readnek(fname, dtype="float64"):
"""A function for reading binary data from the nek5000 binary format
Parameters
----------
fname : str
file name
File name
dtype : str
Floating point data type. See also :class:`pymech.core.Elem`.
"""
#
try:
Expand Down Expand Up @@ -190,14 +192,14 @@ def readnek(fname):
#
# read element map for the file
elmap = infile.read(4 * h.nb_elems_file)
elmap = list(struct.unpack(emode + h.nb_elems_file * "i", elmap))
elmap = struct.unpack(emode + h.nb_elems_file * "i", elmap)
#
# ---------------------------------------------------------------------------
# READ DATA
# ---------------------------------------------------------------------------
#
# initialize data structure
data = HexaData(h.nb_dims, h.nb_elems, h.orders, h.nb_vars, 0)
data = HexaData(h.nb_dims, h.nb_elems, h.orders, h.nb_vars, 0, dtype)
data.time = h.time
data.istep = h.istep
data.wdsz = h.wdsz
Expand Down

0 comments on commit a2500dc

Please sign in to comment.