Skip to content

Commit ab1ef2a

Browse files
GENER.py and hdf.py -- implement GENER opcode 8 for power series
1 parent ebfdff9 commit ab1ef2a

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/hsp2/hsp2/GENER.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ def __init__(
3434
else:
3535
self.k = 1.0
3636

37+
# special case for power series case 8
38+
if self.opcode == 8:
39+
# need tables NTERMS and COEFFS
40+
if segment in ddgener["NTERMS"]:
41+
self.nterms = ddgener["NTERMS"][segment]
42+
else:
43+
self.nterms = 2
44+
self.k1 = ddgener["K1"][segment]
45+
self.k2 = ddgener["K2"][segment]
46+
self.k3 = ddgener["K3"][segment]
47+
self.k4 = ddgener["K4"][segment]
48+
self.k5 = ddgener["K5"][segment]
49+
self.k6 = ddgener["K6"][segment]
50+
self.k7 = ddgener["K7"][segment]
51+
3752
# special case for k as constant case 24
3853
if self.opcode == 24:
3954
start, stop, steps = siminfo["start"], siminfo["stop"], siminfo["steps"]
@@ -136,9 +151,11 @@ def _opcode7(self) -> pd.Series:
136151
return np.log10(self.ts_input_1)
137152

138153
def _opcode8(self) -> pd.Series:
139-
# Not presently implemented, read UCI would need to modify to
140-
# process NTERMS and COEFFS sub blocks of GENER block
141-
raise NotImplementedError("GENER OPCODE 8 is not currently supported")
154+
# K(1) + K(2) * A + K(3) * A ** 2
155+
# The user supplies the number of terms and the values of coefficients (K)
156+
return ((self.k1 + (self.k2 * self.ts_input_1) + (self.k3 * (self.ts_input_1 ** 2))
157+
+ (self.k4 * (self.ts_input_1 ** 3))) + (self.k5 * (self.ts_input_1 ** 4))
158+
+ (self.k6 * (self.ts_input_1 ** 7)) + (self.k7 * (self.ts_input_1 ** 8)))
142159

143160
def _opcode9(self) -> pd.Series:
144161
return np.power(self.k, self.ts_input_1)

src/hsp2/hsp2io/hdf.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ def read_uci(self) -> UCI:
6868
else:
6969
start, stop = row.OPNID.split()
7070
for i in range(int(start), int(stop) + 1):
71-
uci.ddgener[module][f"G{i:03d}"] = row[2]
71+
if module != "COEFFS":
72+
uci.ddgener[module][f"G{i:03d}"] = row[2]
73+
else:
74+
for it in range(1, 8):
75+
uci.ddgener[f"K{it:01d}"][f"G{i:03d}"] = row[it+1]
7276
elif op == "FTABLES":
7377
uci.ftables[module] = self._store[path]
7478
elif op == "SPEC_ACTIONS":

0 commit comments

Comments
 (0)