forked from respec/HSPsquared
-
Notifications
You must be signed in to change notification settings - Fork 0
/
om_model_linkage.py
42 lines (40 loc) · 1.98 KB
/
om_model_linkage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
The class ModelLinkage is used to translate copy data from one state location to another.
It is also used to make an implicit parent child link to insure that an object is loaded
during a model simulation.
"""
from HSP2.om_model_object import ModelObject
from HSP2.utilities_specl import *
from numba import njit
class ModelLinkage(ModelObject):
def __init__(self, name, container = False, source_path = '', link_type = 1):
super(ModelLinkage, self).__init__(name, container)
if container == False:
# this is required
print("Error: a link must have a container object to serve as the destination")
return False
self.source_path = source_path
self.link_type = link_type # 1 - local parent-child, 2 - local property link (state data), 3 - remote linkage (ts data only)
self.optype = 3 # 0 - shell object, 1 - equation, 2 - datamatrix, 3 - ModelLinkage, 4 - broadcastChannel, 5 - ?
def tokenize(self):
super().tokenize()
# - if this is a data property link then we add op codes to do a copy of data from one state address to another
# - if this is simply a parent-child connection, we do not render op-codes, but we do use this for assigning
# - execution hierarchy
if self.link_type in (2, 3):
src_ix = get_state_ix(self.state_ix, self.state_paths, self.source_path)
if not (src_ix == False):
self.ops = self.ops + [src_ix, self.link_type]
else:
print("Error: link ", self.name, "does not have a valid source path")
#print("tokenize() result", self.ops)
# Function for use during model simulations of tokenized objects
@njit
def step_model_link(op_token, state_ix, ts_ix, step):
if op_token[3] == 1:
return True
elif op_token[3] == 2:
state_ix[op_token[1]] = state_ix[op_token[2]]
elif op_token[3] == 3:
return True
# state_ix[op_token[1]] = ts_ix[op_token[2]][step]