Skip to content

Commit

Permalink
first cut at implementing other gener operations
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDudaRESPEC committed Oct 31, 2023
1 parent 9c4fd60 commit e78f84c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
45 changes: 34 additions & 11 deletions HSP2/GENER.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Gener():
Currently supports OPCODES 1-7, 9-26
"""

def __init__(self, segment: str, siminfo: Dict, copies: Dict, geners: Dict, ddlinks: Dict, ddgener: Dict) -> None:
def __init__(self, segment: str, siminfo: Dict, copies: Dict, geners: Dict, ddlinks: Dict, ddmasslinks: Dict, tsin: Dict, ddgener: Dict) -> None:
self.ts_input_1 = pd.Series() # type: pd.Series
self. ts_input_2 = pd.Series() # type: pd.Series
self.ts_output = pd.Series() # type: pd.Series
Expand All @@ -36,20 +36,43 @@ def __init__(self, segment: str, siminfo: Dict, copies: Dict, geners: Dict, ddli
if link.SVOLNO in geners:
gener = geners[link.SVOLNO]
ts = gener.get_ts()
if link.MFACTOR != 1: ts *= link.MFACTOR
if link.MFACTOR != 1 and link.MFACTOR != '': ts *= link.MFACTOR
else:
raise NotImplementedError(
f"Invalid SVOL. This GENER operation does not exist. '{link.SVOLNO}'")
else:
raise NotImplementedError(f"Invalid SVOL. GENER module does not currently support reading TimeSeries for '{link.SVOL}'")

if link.TGRPN == 'INPUT' and link.TMEMN == 'ONE':
self.ts_input_1 = ts
elif link.TGRPN == 'INPUT' and link.TMEMN == 'TWO':
self.ts_input_2 = ts
else:
raise AttributeError(f"No attribute {link.TGRPN}{link.THEMN} to assign TimeSeries. Should be either 'INPUTONE' or 'INPUTWO'")

# get timeseries from other operations
if 'ONE' in tsin:
self.ts_input_1 = tsin['ONE']
if 'TWO' in tsin:
self.ts_input_2 = tsin['TWO']
if not 'ONE' in tsin and not 'TWO' in tsin:
raise NotImplementedError(f"Invalid SVOL for '{link.SVOLNO}'")

if link.SVOL == 'COPY' or link.SVOL == 'GENER':
if link.MLNO != '':
# also have to loop thru associated masslinks
mldata = ddmasslinks[link.MLNO]
for dat in mldata:
mfactor = dat.MFACTOR
afactr = link.AFACTR
factor = afactr * mfactor
ts = ts * factor
if dat.TMEMN == 'ONE':
self.ts_input_1 = ts
elif dat.TMEMN == 'TWO':
self.ts_input_2 = ts
else:
raise AttributeError(
f"No attribute {dat.THEMN} to assign TimeSeries. Should be either 'INPUTONE' or 'INPUTTWO'")
else:
if link.TGRPN == 'INPUT' and link.TMEMN == 'ONE':
self.ts_input_1 = ts
elif link.TGRPN == 'INPUT' and link.TMEMN == 'TWO':
self.ts_input_2 = ts
else:
raise AttributeError(f"No attribute {link.TGRPN}{link.THEMN} to assign TimeSeries. Should be either 'INPUTONE' or 'INPUTTWO'")

self._execute_gener()

def get_ts(self) -> pd.Series:
Expand Down
10 changes: 7 additions & 3 deletions HSP2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,12 @@ def main(io_manager:IOManager, saveall:bool=False, jupyterlab:bool=True) -> None
copy_instances[segment] = activities[operation](io_manager, siminfo, ddext_sources[(operation,segment)])
elif operation == 'GENER':
try:
gener_instances[segment] = activities[operation](segment, siminfo, copy_instances, gener_instances, ddlinks, ddgener)
ts = get_timeseries(io_manager, ddext_sources[(operation, segment)], siminfo)
ts = get_gener_timeseries(ts, gener_instances, ddlinks[segment], ddmasslinks)
get_flows(io_manager, ts, {}, uci, segment, ddlinks, ddmasslinks, siminfo['steps'], msg)
gener_instances[segment] = activities[operation](segment, siminfo, copy_instances, gener_instances, ddlinks, ddmasslinks, ts, ddgener)
except NotImplementedError as e:
print(f"GENER '{segment}' encountered unsupported feature during initialization and may not function correctly. Unsupported feature: '{e}'")
print(f"GENER '{segment}' may not function correctly. '{e}'")
else:

# now conditionally execute all activity modules for the op, segment
Expand Down Expand Up @@ -324,7 +327,8 @@ def get_flows(io_manager:SupportsReadTS, ts, flags, uci, segment, ddlinks, ddmas
# KLUDGE until remaining HSP2 modules are available.
if tmemn not in {'IVOL', 'ICON', 'IHEAT', 'ISED', 'ISED1', 'ISED2', 'ISED3',
'IDQAL', 'ISQAL1', 'ISQAL2', 'ISQAL3',
'OXIF', 'NUIF1', 'NUIF2', 'PKIF', 'PHIF'}:
'OXIF', 'NUIF1', 'NUIF2', 'PKIF', 'PHIF',
'ONE', 'TWO'}:
continue
if (sgrpn == 'OFLOW' and smemn == 'OVOL') or (sgrpn == 'ROFLOW' and smemn == 'ROVOL'):
sgrpn = 'HYDR'
Expand Down

0 comments on commit e78f84c

Please sign in to comment.