Skip to content

Commit 8f4676b

Browse files
committed
add a first order version of SSA
1 parent 4b220ca commit 8f4676b

File tree

4 files changed

+126
-1
lines changed

4 files changed

+126
-1
lines changed

pinnicle/physics/constants.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ def __init__(self, **kwargs):
1414
self.variable_ub = {'u': 1.0e4/self.yts, 'v':1.0e4/self.yts, 's':3.6e3, 'H':3500.0, 'C':1.0e4, 'a': 5.0/self.yts, 'B': 7.0e8}
1515
self.variable_lb['taub'] = 0.0
1616
self.variable_ub['taub'] = 1.0e6
17+
self.variable_lb['B11'] = -1.0e10
18+
self.variable_ub['B11'] = 1.0e10
19+
self.variable_lb['B12'] = -1.0e10
20+
self.variable_ub['B12'] = 1.0e10
21+
self.variable_lb['B22'] = -1.0e10
22+
self.variable_ub['B22'] = 1.0e10
1723
# add more if needed
1824
self.variable_lb['u_base'] = -1.0e4/self.yts
1925
self.variable_ub['u_base'] = 1.0e4/self.yts

pinnicle/physics/stressbalance.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,98 @@ def _pde_jax(self, nn_input_var, nn_output_var): #{{{
284284
return [f1, f2] #}}}
285285
#}}}
286286
#}}}
287+
# SSA first order {{{
288+
class SSAFirstEquationParameter(EquationParameter, Constants):
289+
""" default parameters for SSA first order form
290+
"""
291+
_EQUATION_TYPE = 'SSA First'
292+
def __init__(self, param_dict={}):
293+
# load necessary constants
294+
Constants.__init__(self)
295+
super().__init__(param_dict)
296+
297+
def set_default(self):
298+
self.input = ['x', 'y']
299+
self.output = ['u', 'v', 's', 'H', 'taub', 'B11', 'B12', 'B22']
300+
self.output_lb = [self.variable_lb[k] for k in self.output]
301+
self.output_ub = [self.variable_ub[k] for k in self.output]
302+
self.data_weights = [1.0e-8*self.yts**2.0, 1.0e-8*self.yts**2.0, 1.0e-6, 1.0e-6, 1.0e-10, 0.0, 0.0, 0.0]
303+
self.residuals = ["f"+self._EQUATION_TYPE+"1", "f"+self._EQUATION_TYPE+"2", "dB11", "dB12", "dB22"]
304+
self.pde_weights = [1.0e-10, 1.0e-10, 1e-10, 1e-10, 1e-10]
305+
306+
# scalar variables: name:value
307+
self.scalar_variables = {
308+
'n': 3.0, # exponent of Glen's flow law
309+
'B':1.26802073401e+08 # -8 degree C, cuffey
310+
}
311+
class SSA_First(EquationBase): #{{{
312+
""" SSA on 2D problem with uniform B, no friction law, but use taub
313+
"""
314+
_EQUATION_TYPE = 'SSA First'
315+
def __init__(self, parameters=SSATauEquationParameter()):
316+
super().__init__(parameters)
317+
def _pde(self, nn_input_var, nn_output_var): #{{{
318+
""" residual of SSA 2D PDEs
319+
320+
Args:
321+
nn_input_var: global input to the nn
322+
nn_output_var: global output from the nn
323+
"""
324+
# get the ids
325+
xid = self.local_input_var["x"]
326+
yid = self.local_input_var["y"]
327+
328+
uid = self.local_output_var["u"]
329+
vid = self.local_output_var["v"]
330+
sid = self.local_output_var["s"]
331+
Hid = self.local_output_var["H"]
332+
tauid = self.local_output_var["taub"]
333+
B11id = self.local_output_var["B11"]
334+
B12id = self.local_output_var["B12"]
335+
B22id = self.local_output_var["B22"]
336+
337+
# spatial derivatives
338+
u_x = jacobian(nn_output_var, nn_input_var, i=uid, j=xid)
339+
v_x = jacobian(nn_output_var, nn_input_var, i=vid, j=xid)
340+
u_y = jacobian(nn_output_var, nn_input_var, i=uid, j=yid)
341+
v_y = jacobian(nn_output_var, nn_input_var, i=vid, j=yid)
342+
s_x = jacobian(nn_output_var, nn_input_var, i=sid, j=xid)
343+
s_y = jacobian(nn_output_var, nn_input_var, i=sid, j=yid)
344+
345+
# unpacking normalized output
346+
u = slice_column(nn_output_var, uid)
347+
v = slice_column(nn_output_var, vid)
348+
H = slice_column(nn_output_var, Hid)
349+
taub = slice_column(nn_output_var, tauid)
350+
B11 = slice_column(nn_output_var, B11id)
351+
B12 = slice_column(nn_output_var, B12id)
352+
B22 = slice_column(nn_output_var, B22id)
353+
354+
eta = 0.5*self.B *(u_x**2.0 + v_y**2.0 + 0.25*(u_y+v_x)**2.0 + u_x*v_y+self.eps)**(0.5*(1.0-self.n)/self.n)
355+
# stress tensor
356+
etaH = eta * H
357+
dB11 = B11 - etaH*(4*u_x + 2*v_y)
358+
dB22 = B22 - etaH*(4*v_y + 2*u_x)
359+
dB12 = B12 - etaH*( u_y + v_x)
360+
361+
# Getting the other derivatives
362+
sigma11 = jacobian(nn_output_var, nn_input_var, i=B11id, j=xid)
363+
sigma12 = jacobian(nn_output_var, nn_input_var, i=B12id, j=yid)
364+
365+
sigma21 = jacobian(nn_output_var, nn_input_var, i=B12id, j=xid)
366+
sigma22 = jacobian(nn_output_var, nn_input_var, i=B22id, j=yid)
367+
368+
# compute the basal stress
369+
u_norm = (u**2+v**2+self.eps**2)**0.5
370+
371+
f1 = sigma11 + sigma12 - abs(taub)*u/(u_norm) - self.rhoi*self.g*H*s_x
372+
f2 = sigma21 + sigma22 - abs(taub)*v/(u_norm) - self.rhoi*self.g*H*s_y
373+
374+
return [f1, f2, dB11, dB12, dB22] #}}}
375+
def _pde_jax(self, nn_input_var, nn_output_var): #{{{
376+
return self._pde(nn_input_var, nn_output_var) #}}}
377+
#}}}
378+
#}}}
287379
# SSA variable B {{{
288380
class SSAVariableBEquationParameter(EquationParameter, Constants):
289381
""" default parameters for SSA, with spatially varying rheology B

tests/test_pde.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ def test_SSA_pde_function():
5959
assert y[0].shape == (10,1)
6060
assert y[1].shape == (10,1)
6161

62+
def test_SSA_first_pde_function():
63+
hp_local = dict(hp)
64+
hp_local["equations"] = {"SSA First":{}}
65+
experiment = pinn.PINN(params=hp_local)
66+
experiment.compile()
67+
y = experiment.model.predict(experiment.model_data.X['u'], operator=experiment.physics.operator("SSA First"))
68+
assert len(y) == 5
69+
assert y[0].shape == (10,1)
70+
assert y[1].shape == (10,1)
71+
6272
def test_SSA_VB_pde_function():
6373
hp_local = dict(hp)
6474
hp_local["equations"] = {"SSA_VB":{}}

tests/test_physics.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ def test_Physics_SSAVB():
7070
assert phy.data_weights[3] == 1
7171
assert len(phy.pde_weights) == 2
7272

73+
def test_Physics_SSAfisrt():
74+
SSA = {}
75+
SSA["scalar_variables"] = {"n":3}
76+
hp = {}
77+
hp["equations"] = {"SSA First":SSA}
78+
phy = Physics(PhysicsParameter(hp))
79+
80+
assert phy.input_var == ['x', 'y']
81+
assert phy.output_var == ['u', 'v', 's', 'H', 'taub','B11','B12','B22']
82+
assert phy.residuals == ['fSSA First1', 'fSSA First2', 'dB11', 'dB12', 'dB22']
83+
assert len(phy.output_lb) == 8
84+
assert len(phy.output_ub) == 8
85+
assert len(phy.data_weights) == 8
86+
assert len(phy.pde_weights) == 5
87+
7388
def test_Physics_SSAtau():
7489
SSA = {}
7590
SSA["scalar_variables"] = {"n":3}
@@ -223,7 +238,7 @@ def test_operator():
223238
SSA["scalar_variables"] = {"B":1.26802073401e+08}
224239

225240
hp = {}
226-
hp["equations"] = {"MC":{}, "SSA":SSA, "SSA_VB":{}, "SSA Taub":{}, "MOLHO":{}, "Mass transport":{}, "Time_Invariant":{},
241+
hp["equations"] = {"MC":{}, "SSA":SSA, "SSA_VB":{}, "SSA Taub":{}, "SSA First":{}, "MOLHO":{}, "Mass transport":{}, "Time_Invariant":{},
227242
"Weertman":{}, "MOLHO Taub":{}}
228243
phy = Physics(PhysicsParameter(hp))
229244

@@ -233,6 +248,8 @@ def test_operator():
233248
assert phy.operator('ssa')
234249
assert phy.operator('SSA_VB')
235250
assert phy.operator('ssa_vb')
251+
assert phy.operator('SSA First')
252+
assert phy.operator('ssa first')
236253
assert phy.operator('SSA Taub')
237254
assert phy.operator('ssa taub')
238255
assert phy.operator('molho')

0 commit comments

Comments
 (0)