1515from devsim import *
1616debug = False
1717def CreateSolution (device , region , name ):
18- '''
19- Creates solution variables
20- As well as their entries on each edge
21- '''
22- node_solution (name = name , device = device , region = region )
23- edge_from_node_model (node_model = name , device = device , region = region )
18+ '''
19+ Creates solution variables
20+ As well as their entries on each edge
21+ '''
22+ node_solution (name = name , device = device , region = region )
23+ edge_from_node_model (node_model = name , device = device , region = region )
2424
2525def CreateNodeModel (device , region , model , expression ):
26- '''
27- Creates a node model
28- '''
29- result = node_model (device = device , region = region , name = model , equation = expression )
30- if debug :
31- print (("NODEMODEL {d} {r} {m} \" {re}\" " .format (d = device , r = region , m = model , re = result )))
26+ '''
27+ Creates a node model
28+ '''
29+ result = node_model (device = device , region = region , name = model , equation = expression )
30+ if debug :
31+ print (("NODEMODEL {d} {r} {m} \" {re}\" " .format (d = device , r = region , m = model , re = result )))
3232
3333def CreateNodeModelDerivative (device , region , model , expression , * vars ):
34- '''
35- Create a node model derivative
36- '''
37- for v in vars :
38- CreateNodeModel (device , region ,
39- "{m}:{v}" .format (m = model , v = v ),
40- "diff({e},{v})" .format (e = expression , v = v ))
41- #"simplify(diff({e},{v}))".format(e=expression, v=v))
34+ '''
35+ Create a node model derivative
36+ '''
37+ for v in vars :
38+ CreateNodeModel (device , region ,
39+ "{m}:{v}" .format (m = model , v = v ),
40+ "diff({e},{v})" .format (e = expression , v = v ))
41+ #"simplify(diff({e},{v}))".format(e=expression, v=v))
4242
4343
4444def CreateContactNodeModel (device , contact , model , expression ):
45- '''
46- Creates a contact node model
47- '''
48- result = contact_node_model (device = device , contact = contact , name = model , equation = expression )
49- if debug :
50- print (("CONTACTNODEMODEL {d} {c} {m} \" {re}\" " .format (d = device , c = contact , m = model , re = result )))
45+ '''
46+ Creates a contact node model
47+ '''
48+ result = contact_node_model (device = device , contact = contact , name = model , equation = expression )
49+ if debug :
50+ print (("CONTACTNODEMODEL {d} {c} {m} \" {re}\" " .format (d = device , c = contact , m = model , re = result )))
5151
5252
5353def CreateContactNodeModelDerivative (device , contact , model , expression , variable ):
54- '''
55- Creates a contact node model derivative
56- '''
57- CreateContactNodeModel (device , contact ,
58- "{m}:{v}" .format (m = model , v = variable ),
59- "diff({e}, {v})" .format (e = expression , v = variable ))
60- #"simplify(diff({e}, {v}))".format(e=expression, v=variable))
54+ '''
55+ Creates a contact node model derivative
56+ '''
57+ CreateContactNodeModel (device , contact ,
58+ "{m}:{v}" .format (m = model , v = variable ),
59+ "diff({e}, {v})" .format (e = expression , v = variable ))
60+ #"simplify(diff({e}, {v}))".format(e=expression, v=variable))
6161
6262def CreateEdgeModel (device , region , model , expression ):
63- '''
64- Creates an edge model
65- '''
66- result = edge_model (device = device , region = region , name = model , equation = expression )
67- if debug :
68- print ("EDGEMODEL {d} {r} {m} \" {re}\" " .format (d = device , r = region , m = model , re = result ));
63+ '''
64+ Creates an edge model
65+ '''
66+ result = edge_model (device = device , region = region , name = model , equation = expression )
67+ if debug :
68+ print ("EDGEMODEL {d} {r} {m} \" {re}\" " .format (d = device , r = region , m = model , re = result ));
6969
7070def CreateEdgeModelDerivatives (device , region , model , expression , variable ):
71- '''
72- Creates edge model derivatives
73- '''
74- CreateEdgeModel (device , region ,
75- "{m}:{v}@n0" .format (m = model , v = variable ),
76- "diff({e}, {v}@n0)" .format (e = expression , v = variable ))
77- #"simplify(diff({e}, {v}@n0))".format(e=expression, v=variable))
78- CreateEdgeModel (device , region ,
79- "{m}:{v}@n1" .format (m = model , v = variable ),
80- "diff({e}, {v}@n1)" .format (e = expression , v = variable ))
81- #"simplify(diff({e}, {v}@n1))".format(e=expression, v=variable))
71+ '''
72+ Creates edge model derivatives
73+ '''
74+ CreateEdgeModel (device , region ,
75+ "{m}:{v}@n0" .format (m = model , v = variable ),
76+ "diff({e}, {v}@n0)" .format (e = expression , v = variable ))
77+ #"simplify(diff({e}, {v}@n0))".format(e=expression, v=variable))
78+ CreateEdgeModel (device , region ,
79+ "{m}:{v}@n1" .format (m = model , v = variable ),
80+ "diff({e}, {v}@n1)" .format (e = expression , v = variable ))
81+ #"simplify(diff({e}, {v}@n1))".format(e=expression, v=variable))
8282
8383def CreateContactEdgeModel (device , contact , model , expression ):
84- '''
85- Creates a contact edge model
86- '''
87- result = contact_edge_model (device = device , contact = contact , name = model , equation = expression )
88- if debug :
89- print (("CONTACTEDGEMODEL {d} {c} {m} \" {re}\" " .format (d = device , c = contact , m = model , re = result )))
84+ '''
85+ Creates a contact edge model
86+ '''
87+ result = contact_edge_model (device = device , contact = contact , name = model , equation = expression )
88+ if debug :
89+ print (("CONTACTEDGEMODEL {d} {c} {m} \" {re}\" " .format (d = device , c = contact , m = model , re = result )))
9090
9191def CreateContactEdgeModelDerivative (device , contact , model , expression , variable ):
92- '''
93- Creates contact edge model derivatives with respect to variable on node
94- '''
95- CreateContactEdgeModel (device , contact , "{m}:{v}" .format (m = model , v = variable ), "diff({e}, {v})" .format (e = expression , v = variable ))
96- #CreateContactEdgeModel(device, contact, "{m}:{v}".format(m=model, v=variable), "simplify(diff({e}, {v}))".format(e=expression, v=variable))
92+ '''
93+ Creates contact edge model derivatives with respect to variable on node
94+ '''
95+ CreateContactEdgeModel (device , contact , "{m}:{v}" .format (m = model , v = variable ), "diff({e}, {v})" .format (e = expression , v = variable ))
96+ #CreateContactEdgeModel(device, contact, "{m}:{v}".format(m=model, v=variable), "simplify(diff({e}, {v}))".format(e=expression, v=variable))
9797
9898def CreateInterfaceModel (device , interface , model , expression ):
99- '''
100- Creates a interface node model
101- '''
102- result = interface_model (device = device , interface = interface , name = model , equation = expression )
103- if debug :
104- print (("INTERFACEMODEL {d} {i} {m} \" {re}\" " .format (d = device , i = interface , m = model , re = result )))
99+ '''
100+ Creates a interface node model
101+ '''
102+ result = interface_model (device = device , interface = interface , name = model , equation = expression )
103+ if debug :
104+ print (("INTERFACEMODEL {d} {i} {m} \" {re}\" " .format (d = device , i = interface , m = model , re = result )))
105105
106106#def CreateInterfaceModelDerivative(device, interface, model, expression, variable):
107107# '''
@@ -110,74 +110,74 @@ def CreateInterfaceModel(device, interface, model, expression):
110110# CreateInterfaceModel(device, interface, "{m}:{v}".format(m=model, v=variable), "simplify(diff({e}, {v}))".format(e=expression, v=variable))
111111
112112def CreateContinuousInterfaceModel (device , interface , variable ):
113- mname = "continuous{0}" .format (variable )
114- meq = "{0}@r0 - {0}@r1" .format (variable )
115- mname0 = "{0}:{1}@r0" .format (mname , variable )
116- mname1 = "{0}:{1}@r1" .format (mname , variable )
117- CreateInterfaceModel (device , interface , mname , meq )
118- CreateInterfaceModel (device , interface , mname0 , "1" )
119- CreateInterfaceModel (device , interface , mname1 , "-1" )
120- return mname
113+ mname = "continuous{0}" .format (variable )
114+ meq = "{0}@r0 - {0}@r1" .format (variable )
115+ mname0 = "{0}:{1}@r0" .format (mname , variable )
116+ mname1 = "{0}:{1}@r1" .format (mname , variable )
117+ CreateInterfaceModel (device , interface , mname , meq )
118+ CreateInterfaceModel (device , interface , mname0 , "1" )
119+ CreateInterfaceModel (device , interface , mname1 , "-1" )
120+ return mname
121121
122122
123123def InEdgeModelList (device , region , model ):
124- '''
125- Checks to see if this edge model is available on device and region
126- '''
127- return model in get_edge_model_list (device = device , region = region )
124+ '''
125+ Checks to see if this edge model is available on device and region
126+ '''
127+ return model in get_edge_model_list (device = device , region = region )
128128
129129def InNodeModelList (device , region , model ):
130- '''
131- Checks to see if this node model is available on device and region
132- '''
133- return model in get_node_model_list (device = device , region = region )
130+ '''
131+ Checks to see if this node model is available on device and region
132+ '''
133+ return model in get_node_model_list (device = device , region = region )
134134
135135#### Make sure that the model exists, as well as it's node model
136136def EnsureEdgeFromNodeModelExists (device , region , nodemodel ):
137- '''
138- Checks if the edge models exists
139- '''
140- if not InNodeModelList (device , region , nodemodel ):
141- raise "{} must exist"
142-
143- emlist = get_edge_model_list (device = device , region = region )
144- emtest = ("{0}@n0" .format (nodemodel ) and "{0}@n1" .format (nodemodel ))
145- if not emtest :
146- if debug :
147- print ("INFO: Creating ${0}@n0 and ${0}@n1" .format (nodemodel ))
148- edge_from_node_model (device = device , region = region , node_model = nodemodel )
137+ '''
138+ Checks if the edge models exists
139+ '''
140+ if not InNodeModelList (device , region , nodemodel ):
141+ raise "{} must exist"
142+
143+ emlist = get_edge_model_list (device = device , region = region )
144+ emtest = ("{0}@n0" .format (nodemodel ) and "{0}@n1" .format (nodemodel ))
145+ if not emtest :
146+ if debug :
147+ print ("INFO: Creating ${0}@n0 and ${0}@n1" .format (nodemodel ))
148+ edge_from_node_model (device = device , region = region , node_model = nodemodel )
149149
150150def CreateElementModel2d (device , region , model , expression ):
151- result = element_model (device = device , region = region , name = model , equation = expression )
152- if debug :
153- print (("ELEMENTMODEL {d} {r} {m} \" {re}\" " .format (d = device , r = region , m = model , re = result )))
151+ result = element_model (device = device , region = region , name = model , equation = expression )
152+ if debug :
153+ print (("ELEMENTMODEL {d} {r} {m} \" {re}\" " .format (d = device , r = region , m = model , re = result )))
154154
155155
156156def CreateElementModelDerivative2d (device , region , model_name , expression , * args ):
157- if len (args ) == 0 :
158- raise ValueError ("Must specify a list of variable names" )
159- for i in args :
160- for j in ("@en0" , "@en1" , "@en2" ):
161- CreateElementModel2d (device , region , "{0}:{1}{2}" .format (model_name , i , j ), "diff({0}, {1}{2})" .format (expression , i , j ))
157+ if len (args ) == 0 :
158+ raise ValueError ("Must specify a list of variable names" )
159+ for i in args :
160+ for j in ("@en0" , "@en1" , "@en2" ):
161+ CreateElementModel2d (device , region , "{0}:{1}{2}" .format (model_name , i , j ), "diff({0}, {1}{2})" .format (expression , i , j ))
162162
163163### edge_model is the name of the edge model to be created
164164def CreateGeometricMean (device , region , nmodel , emodel ):
165165 edge_average_model (device = device , region = region , edge_model = emodel , node_model = nmodel , average_type = "geometric" )
166166
167167def CreateGeometricMeanDerivative (device , region , nmodel , emodel , * args ):
168- if len (args ) == 0 :
169- raise ValueError ("Must specify a list of variable names" )
170- for i in args :
171- edge_average_model (device = device , region = region , edge_model = emodel , node_model = nmodel ,
172- derivative = i , average_type = "geometric" )
168+ if len (args ) == 0 :
169+ raise ValueError ("Must specify a list of variable names" )
170+ for i in args :
171+ edge_average_model (device = device , region = region , edge_model = emodel , node_model = nmodel ,
172+ derivative = i , average_type = "geometric" )
173173
174174def CreateArithmeticMean (device , region , nmodel , emodel ):
175175 edge_average_model (device = device , region = region , edge_model = emodel , node_model = nmodel , average_type = "arithmetic" )
176176
177177def CreateArithmeticMeanDerivative (device , region , nmodel , emodel , * args ):
178- if len (args ) == 0 :
179- raise ValueError ("Must specify a list of variable names" )
180- for i in args :
181- edge_average_model (device = device , region = region , edge_model = emodel , node_model = nmodel ,
182- derivative = i , average_type = "arithmetic" )
178+ if len (args ) == 0 :
179+ raise ValueError ("Must specify a list of variable names" )
180+ for i in args :
181+ edge_average_model (device = device , region = region , edge_model = emodel , node_model = nmodel ,
182+ derivative = i , average_type = "arithmetic" )
183183
0 commit comments