-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermo_mechanical_subduction.py
1334 lines (873 loc) · 39.7 KB
/
thermo_mechanical_subduction.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# coding: utf-8
# ## 2D thermo mechanical subduction models
#
# This notebook develops a simple, flexible model for 2d subduction using Underworld2. All functionality is parallel-compatible. The code has been run on 48 processors, at a vertical resolution of 256 elements (Q1).
#
#
#
#
# This code was written by Dan Sandiford, Louis Moresi and the Underworld Team. It is licensed under the [Creative Commons Attribution 4.0 International License](https://creativecommons.org/licenses/by/4.0/) . We offer this licence to encourage you to modify and share the examples and use them to help you in your research.
#
#
# <hr>
# <a rel="license" href="http://creativecommons.org/licenses/by/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by/4.0/88x31.png" /></a><br />
# ## Notes
#
# ### General
#
# Many of the functions and scripts used here (various parts of the Underworld2 unsupported module) were written by Dan Sandiford during the bloodshed and mayhem of a PhD. This code has minimal safeguards. When things break (they will), post and issue, and we'll try to provide a fix!
#
# ### Checkpointing
#
# All parts of the code that relate to checkpointing have the following identifier:
#
# `#*************CHECKPOINT-BLOCK**************#`
#
# ### Materials
#
# Currently a weak material is added to the top of the lower plate to decouple the plates. For simplicity, in this notebook, there is no functionality for updating the distribution of materials (i.e. creating new crust). An example of one way you could add this functionality can be found here: https://github.com/dansand/materialTransformations
#
#
# ### Solver
#
# We have found the penalty method works well for this problem. This is the default setting. (Unfortunately, it doesn't scale well to 3D.)
#
# ### Resolution and particles
#
# Properly resolving the weak crust is critical to this model, which means that resolution (and particle numbers) need to be quite high (i.e. don't expect quick models on your laptop). The default crust thickness is 15 km. By switching the depth of the model to something like 660 km (upper mantle), you might get away with running at a resolution of ~ 96 elements (vertical). Note that the dyanamics are quite sensitive to the depth of the model. The default resolution and particle density are set low, essentially for model setup purposes.
#
#
# ### nearest neighbour evaluation
#
# In a couple of places a function `nn_evaluation` (nearest neighbour evaluation) is called. This is used whenever we want to map a swarm variable to a mesh variable. This is an alternative to the `uw.utils.MeshVariable_Projection` functionality provided in underworld2.
#
# ### Visualisation
#
# Examples of the both 'native' Underworld2 visualisation, through gLucifer, as well as xdmf file output are provided.
# In[ ]:
# ## Package requirements
#
# Assuming you're running underworld2 through a docker image, you will need the following python packages:
#
# * easydict https://pypi.python.org/pypi/easydict/
#
# It should be simple enough to do `pip install easydict` (though you'll need to do this for each container you start)
#
# You'll also need a copy of this module: https://github.com/dansand/unsupported.git
#
# This is occasionally merged with the official underworld2 module of the same name, but it's safest to grab a copy of the repo:
#
# `git clone https://github.com/dansand/unsupported.git`,
#
# (easiest to clone straight into in the same directory as this notebook.)
#
# To add the module to the pythonpath do:
#
# ```python
# import os
# import sys
#
# if os.getcwd() == '/workspace/newSlab':
# sys.path.append('./unsupported')
#
# ```
# In[46]:
import os
import sys
if '/workspace' in os.getcwd(): #a simple test for the standard Docker image
#sys.path.append('./unsupported') #unsupported module located in current working dir
sys.path.append('../unsupported') #unsupported module located in parent dir.
else:
pass #put your non-docker path here
# In[47]:
import numpy as np
import underworld as uw
import math
from underworld import function as fn
import glucifer
from easydict import EasyDict as edict
import operator
import pickle
#
from unsupported_dan.utilities.interpolation import nn_evaluation
from unsupported_dan.utilities.subduction import slab_top
from unsupported_dan.interfaces.marker2D import markerLine2D
from unsupported_dan.easymodels import checkpoint
from unsupported_dan.easymodels import easy_args
from unsupported_dan.utilities.misc import *
# ## Setup output directories
# In[48]:
###########
#Standard output directory setup
###########
#Model letter identifier demarker
Model = "T"
#Model number identifier demarker:
ModNum = 1
#Any isolated letter / integer command line args are interpreted as Model/ModelNum and read in here
#We use this for doing parameter sweeps
if len(sys.argv) == 1:
ModNum = ModNum
elif sys.argv[1] == '-f': #
ModNum = ModNum
else:
for farg in sys.argv[1:]:
if not '=' in farg: #then assume it's a not a parameter argument
try:
ModNum = int(farg) #try to convert everingthing to a float, else remains string
except ValueError:
Model = farg
###########
#Standard output directory setup
###########
outputPath = "results" + "/" + str(Model) + "/" + str(ModNum) + "/"
imagePath = outputPath + 'images/'
filePath = outputPath + 'files/'
#checkpointPath = outputPath + 'checkpoint/'
dbPath = outputPath + 'gldbs/'
xdmfPath = outputPath + 'xdmf/'
outputFile = 'results_model' + Model + '_' + str(ModNum) + '.dat'
if uw.rank()==0:
# make directories if they don't exist
if not os.path.isdir(outputPath):
os.makedirs(outputPath)
if not os.path.isdir(imagePath):
os.makedirs(imagePath)
if not os.path.isdir(dbPath):
os.makedirs(dbPath)
if not os.path.isdir(filePath):
os.makedirs(filePath)
if not os.path.isdir(xdmfPath):
os.makedirs(xdmfPath)
uw.barrier() #Barrier here so no procs run the check in the next cell too early
# ## Checkpointing
# In[49]:
#*************CHECKPOINT-BLOCK**************#
#cp = checkpoint(outputPath + 'checkpoint/', loadpath='./results/A/1/checkpoint/10')
cp = checkpoint(outputPath + 'checkpoint/')
#*************CHECKPOINT-BLOCK**************#
# ## Model parameters and scaling
#
# Model versatility is controlled by 4 dictionaries,
#
# * 'dp': dimensional parameters
# * 'md': model dictionary (changing numerics, switching certain processes on / off)
# * 'sf': scaling factors
# * 'ndp': non dimensional parameters
#
# The dictionaries use the easyDict format, so that the following format can be applied to items:
#
# ```
#
# key.value = blah
#
# ```
#
# This approach was chosen so that:
#
# 1. the non-dimensionalisation process is fully developed and explicit in each model
# 2. parameters can be easy saved (dictionaries can be 'pickled', written to .csv etc)
# 3. parameters can be easily altered through command line args.
#
# Command line arguments can only be provided to the `dp` and `md` dictionaries. The logic is that the scaling process (non-dimesionalisation) should basically be static, and simply provides a mapping between physical units and model units.
# In[50]:
dp = edict({})
#Main physical paramters
dp.depth=1000e3 #model Depth (width set by md.aspectRatio)
dp.refDensity=3300. #reference density
dp.refGravity=9.8 #surface gravity
dp.viscosityScale=1e20 #reference upper mantle visc.,
dp.refDiffusivity=1e-6 #thermal diffusivity
dp.refExpansivity=3e-5 #surface thermal expansivity
dp.gasConstant=8.314 #gas constant
dp.specificHeat=1250. #Specific heat (Jkg-1K-1)
dp.potentialTemp=1573. #mantle potential temp (K)
dp.surfaceTemp=273. #surface temp (K)
#Rheology - flow law paramters
dp.cohesionMantle=20e6 #mantle cohesion in Byerlee law
dp.cohesionCrust=1e6 #crust cohesion in Byerlee law
dp.frictionMantle=0.2 #mantle friction coefficient in Byerlee law (tan(phi))
dp.frictionCrust=0.02 #crust friction coefficient
dp.diffusionPreExp=5.34e-10 #or 1./1.87e9, pre-exp factor for diffusion creep
dp.diffusionEnergy=3e5
dp.diffusionVolume=5e-6
dp.lowerMantlePreExp=4.23e-15
dp.lowerMantleEnergy=2.0e5
dp.lowerMantleVolume=1.5e-6
dp.lowerMantleViscFac = 30.
#Rheology - cutoff values
dp.viscosityMin=1e18
dp.viscosityMax=1e25 #viscosity max in the mantle material
dp.viscosityMinCrust=1e20 #viscosity min in the weak-crust material
dp.viscosityMaxCrust=1e20 #viscosity max in the weak-crust material
dp.yieldStressMax=300*1e6
dp.crustViscCutoffDepth = 100e3
dp.crustViscEndWidth = 20e3
#Intrinsic Lengths
dp.crustThickness = 15.*1e3 #weak layer thickness on top of slabs
dp.crustMantleDepth=250.*1e3
dp.lowerMantleDepth=660.*1e3
dp.crustLimitDepth=650.*1e3 #Deeper than this, crust material rheology reverts to mantle rheology
#Slab and plate init. parameters
dp.subZoneLoc=-100e3 #X position of subduction zone...km
dp.leftRidge=-1.*(5000e3)
dp.rightRidge=(5000e3)
dp.maxDepth=150e3
dp.theta=40 #Angle of slab
dp.radiusOfCurv = 250e3 #radius of curvature
dp.slabMaxAge=70e6 #age of subduction plate at trench
dp.plateMaxAge=100e6 #max age of slab (Plate model)
dp.opMaxAge=35e6 #age of op
#Misc
dp.stickyAirDepth=100e3 #depth of sticky air layer
dp.viscosityStickyAir=1e19 #stick air viscosity, normal
#derived params
dp.deltaTemp = dp.potentialTemp-dp.surfaceTemp
#Modelling and Physics switches
md = edict({})
md.refineMeshStatic=True
md.stickyAir=False
md.aspectRatio=5.
md.res=32
md.ppc=25 #particles per cell
md.elementType="Q1/dQ0" #"Q2/DPC1"
md.secInvFac=math.sqrt(1.)
md.courantFac=0.5 #extra limitation on timestepping may need to be decreased if using "Q2/DPC1" )
md.thermal = True #thermal system or compositional
md.swarmInitialFac = 0.6 #initial swarm layout will be int(md.ppc*md.swarmInitialFac), popControl will densify later
md.compBuoyancy = False
md.nltol = 0.01
md.maxSteps = 5000
md.checkpointEvery = 100
md.swarmUpdate = 10
md.penaltyMethod = True
md.opuniform = False
md.spuniform = False
md.opfixed = False
md.spfixed = False
md.buoyancyFac = 1.0
#time-based actions
md.filesFreqYears = 1.0e6 #dimensional time in years
uw.barrier()
# In[51]:
##Parse any command-line args
sysArgs = sys.argv
#We want to run this on both the parameter dict, and the model dict
easy_args(sysArgs, dp)
easy_args(sysArgs, md)
uw.barrier()
# In[52]:
sf = edict({})
sf.lengthScale=2900e3
sf.viscosityScale = dp.viscosityScale
sf.stress = (dp.refDiffusivity*sf.viscosityScale)/sf.lengthScale**2
#sf.lithGrad = dp.refDensity*dp.refGravity*(sf.lengthScale)**3/(sf.viscosityScale*dp.refDiffusivity)
sf.lithGrad = (sf.viscosityScale*dp.refDiffusivity) /(dp.refDensity*dp.refGravity*(sf.lengthScale)**3)
sf.velocity = dp.refDiffusivity/sf.lengthScale
sf.strainRate = dp.refDiffusivity/(sf.lengthScale**2)
sf.time = 1./sf.strainRate
sf.actVolume = (dp.gasConstant*dp.deltaTemp)/(dp.refDensity*dp.refGravity*sf.lengthScale)
sf.actEnergy = (dp.gasConstant*dp.deltaTemp)
sf.diffusionPreExp = 1./sf.viscosityScale
sf.deltaTemp = dp.deltaTemp
sf.pressureDepthGrad = (dp.refDensity*dp.refGravity*sf.lengthScale**3)/(dp.viscosityScale*dp.refDiffusivity)
#dimesionless params
ndp = edict({})
ndp.rayleigh = md.buoyancyFac*(dp.refExpansivity*dp.refDensity*dp.refGravity*dp.deltaTemp*sf.lengthScale**3)/(dp.viscosityScale*dp.refDiffusivity)
ndp.dissipation = (dp.refExpansivity*sf.lengthScale*dp.refGravity)/dp.specificHeat
ndp.surfaceTemp = dp.surfaceTemp/sf.deltaTemp #Ts
ndp.potentialTemp = dp.potentialTemp/sf.deltaTemp - ndp.surfaceTemp #Tp' = Tp - TS
#lengths / distances
ndp.depth = dp.depth/sf.lengthScale
ndp.leftLim = -0.5*ndp.depth*md.aspectRatio
ndp.rightLim = 0.5*ndp.depth*md.aspectRatio
ndp.crustThickness = dp.crustThickness/sf.lengthScale
ndp.leftRidge = max(ndp.leftLim, dp.leftRidge/sf.lengthScale)
ndp.rightRidge = min(ndp.rightLim, dp.rightRidge/sf.lengthScale)
ndp.crustLimitDepth = dp.crustLimitDepth/sf.lengthScale
ndp.lowerMantleDepth = dp.lowerMantleDepth/sf.lengthScale
#times - for convenience and sanity the dimensional values are in years, conversion to seconds happens here
ndp.slabMaxAge = dp.slabMaxAge*(3600*24*365)/sf.time
ndp.plateMaxAge = dp.plateMaxAge*(3600*24*365)/sf.time
ndp.opMaxAge = dp.opMaxAge*(3600*24*365)/sf.time
#Rheology - flow law paramters
ndp.cohesionMantle=dp.cohesionMantle/sf.stress #mantle cohesion in Byerlee law
ndp.cohesionCrust=dp.cohesionCrust/sf.stress #crust cohesion in Byerlee law
ndp.frictionMantle=dp.frictionMantle/sf.lithGrad #mantle friction coefficient in Byerlee law (tan(phi))
ndp.frictionCrust=dp.frictionCrust/sf.lithGrad #crust friction coefficient
ndp.diffusionPreExp=dp.diffusionPreExp/sf.diffusionPreExp #pre-exp factor for diffusion creep
ndp.diffusionEnergy=dp.diffusionEnergy/sf.actEnergy
ndp.diffusionVolume=dp.diffusionVolume/sf.actVolume
ndp.lowerMantlePreExp=dp.lowerMantlePreExp/sf.diffusionPreExp
ndp.lowerMantleEnergy=dp.lowerMantleEnergy/sf.actEnergy
ndp.lowerMantleVolume=dp.lowerMantleVolume/sf.actVolume
ndp.yieldStressMax=dp.yieldStressMax/sf.stress
#Rheology - cutoff values
ndp.viscosityMin= dp.viscosityMin /sf.viscosityScale
ndp.viscosityMax=dp.viscosityMax/sf.viscosityScale
ndp.viscosityMinCrust= dp.viscosityMinCrust /sf.viscosityScale
ndp.viscosityMaxCrust = dp.viscosityMaxCrust/sf.viscosityScale
ndp.lowerMantleViscFac = dp.lowerMantleViscFac
ndp.crustViscCutoffDepth = dp.crustViscCutoffDepth/sf.lengthScale
ndp.crustViscEndWidth = dp.crustViscEndWidth/sf.lengthScale
#Slab and plate init. parameters
ndp.subZoneLoc = dp.subZoneLoc/sf.lengthScale
ndp.maxDepth = dp.maxDepth/sf.lengthScale
ndp.radiusOfCurv = dp.radiusOfCurv/sf.lengthScale
# In[53]:
#*************CHECKPOINT-BLOCK**************#
#if restart, attempt to read in saved dicts.
if cp.restart:
try:
with open(os.path.join(cp.loadpath, 'dp.pkl'), 'rb') as fp:
dp = pickle.load(fp)
with open(os.path.join(cp.loadpath, 'sf.pkl'), 'rb') as fp:
sf = pickle.load(fp)
with open(os.path.join(cp.loadpath, 'md.pkl'), 'rb') as fp:
md = pickle.load(fp)
except:
print("couldn't load paramter dictionaries on restart")
#add dicts to the checkpointinng object
cp.addDict(dp, 'dp')
cp.addDict(sf, 'sf')
cp.addDict(md, 'md')
#*************CHECKPOINT-BLOCK**************#
# ## Build Mesh and FE variables
# In[54]:
#Domain and Mesh paramters
yres = int(md.res)
xres = int(md.res*8)
mesh = uw.mesh.FeMesh_Cartesian( elementType = (md.elementType),
elementRes = (xres, yres),
minCoord = (ndp.leftLim, 1. - ndp.depth),
maxCoord = (ndp.rightLim, 1.))
velocityField = uw.mesh.MeshVariable( mesh=mesh, nodeDofCount=2 )
pressureField = uw.mesh.MeshVariable( mesh=mesh.subMesh, nodeDofCount=1 )
temperatureField = uw.mesh.MeshVariable( mesh=mesh, nodeDofCount=1 )
if md.thermal:
temperatureDotField = uw.mesh.MeshVariable( mesh=mesh, nodeDofCount=1 ) #create this only if Adv-diff
diffusivityFn = fn.misc.constant(1.)
# Any extra mesh vars. we want to define (mostly to facilite saving as xdmf)
strainRateField = uw.mesh.MeshVariable( mesh=mesh, nodeDofCount=1 )
viscosityField = uw.mesh.MeshVariable( mesh=mesh, nodeDofCount=1 )
# Here we provide a basic mesh refinement strategy: This refinement function is:
#
# $y_{new} = \frac{ln((\alpha y_n + e) -1)}{ln((\alpha + e) - 1)}$
#
# where $y_n$ are the normalised original coordinates
#
# Note that the horizonal mesh resolution has been set to balance this vertical refinement.
# In[55]:
mesh.reset()
alpha = 5.
am = mesh.minCoord[1]
bm = mesh.maxCoord[1]
yorigscaled = (mesh.data[:,1].copy() - am) /(bm - am)
ynew = (np.log(alpha*yorigscaled + np.e ) -1.)/(np.log(alpha+ np.e ) -1.)
ynew *= (bm - am)
ynew += am
#do the mesh deformation
with mesh.deform_mesh():
mesh.data[:,1] = ynew
# In[57]:
#figMesh= glucifer.Figure(quality=3)
#figMesh.append( glucifer.objects.Mesh(mesh))
#figMesh.show()
#figMesh.save_database('test.gldb')
# In[ ]:
# In[42]:
#*************CHECKPOINT-BLOCK**************#
cp.addObject(velocityField,'velocityField')
cp.addObject(pressureField,'pressureField')
if md.thermal:
cp.addObject(temperatureField,'temperatureField')
cp.addObject(temperatureDotField,'temperatureDotField')
#*************CHECKPOINT-BLOCK**************#
# In[43]:
#print(cp.objDict.keys())
# In[44]:
#*************CHECKPOINT-BLOCK**************#
if cp.restart:
velocityField.load(cp.loadpath + '/velocityField.h5')
pressureField.load(cp.loadpath + '/pressureField.h5')
if md.thermal:
temperatureField.load(cp.loadpath + '/temperatureField.h5')
temperatureDotField.load(cp.loadpath + '/temperatureDotField.h5')
#*************CHECKPOINT-BLOCK**************#
# In[45]:
#miscellaneous Uw functions functions
coordinate = fn.input()
depthFn = mesh.maxCoord[1] - coordinate[1] #a function providing the depth
xFn = coordinate[0] #a function providing the x-coordinate
yFn = coordinate[1]
#Create a binary circle
def inCircleFnGenerator(centre, radius):
coord = fn.input()
offsetFn = coord - centre
return fn.math.dot( offsetFn, offsetFn ) < radius**2
# ## Boundary Conditions
# In[71]:
#Stokes BCs
iWalls = mesh.specialSets["MinI_VertexSet"] + mesh.specialSets["MaxI_VertexSet"]
jWalls = mesh.specialSets["MinJ_VertexSet"] + mesh.specialSets["MaxJ_VertexSet"]
tWalls = mesh.specialSets["MaxJ_VertexSet"]
bWalls =mesh.specialSets["MinJ_VertexSet"]
freeslipBC = uw.conditions.DirichletCondition( variable = velocityField,
indexSetsPerDof = ( iWalls, jWalls) )
# In[72]:
#Energy BCs
if md.thermal:
dirichTempBC = uw.conditions.DirichletCondition( variable=temperatureField,
indexSetsPerDof=(tWalls,) )
# ## Swarm
# In[73]:
#Materials
mantleID = 0
crustID = 1
airID = 2 #in case we use sticky air
#list of all material indexes
material_list = [mantleID, crustID, airID]
# In[74]:
#*************CHECKPOINT-BLOCK**************#
swarm = uw.swarm.Swarm(mesh=mesh, particleEscape=True)
cp.addObject(swarm,'swarm')
materialVariable = swarm.add_variable( dataType="int", count=1 )
cp.addObject(materialVariable,'materialVariable')
proxyTempVariable = swarm.add_variable( dataType="double", count=1 )
if not md.thermal:
cp.addObject(proxyTempVariable,'proxyTempVariable')
if cp.restart:
swarm.load(cp.loadpath + '/swarm.h5')
materialVariable.load(cp.loadpath + '/materialVariable.h5')
if not md.thermal:
proxyTempVariable.load(cp.loadpath + '/proxyTempVariable.h5')
else:
layout = uw.swarm.layouts.PerCellRandomLayout(swarm=swarm, particlesPerCell=int(md.ppc*md.swarmInitialFac))
swarm.populate_using_layout( layout=layout ) # Now use it to populate.
proxyTempVariable.data[:] = 0.0
materialVariable.data[:] = mantleID
#*************CHECKPOINT-BLOCK**************#
# In[75]:
#These variables don;t need checkpointing. They can / should be rebuilt
signedDistanceVariable = swarm.add_variable( dataType="double", count=1 )
#directorVector = swarm.add_variable( dataType="double", count=2)
#directorVector.data[:,:] = 0.0
signedDistanceVariable.data[:] = 0.0
# In[76]:
#Pass this to Figures to see full extent
bBox=((mesh.minCoord[0], mesh.minCoord[1]),(mesh.maxCoord[0], mesh.maxCoord[1]))
# ## Initial Conditions
# In[77]:
#plate depth
#Flags to control plate behaviour: md.opuniform, md.spuniform, md.opfixed, md.spfixed
#T&S 4.126
thicknessAtTrench = 2.32*math.sqrt(1.*ndp.slabMaxAge)
sig = 150e3/sf.lengthScale
ridgeFn = 1. - fn.math.exp(-1.*(xFn - ndp.leftRidge)**2/(2 * sig**2))- fn.math.exp(-1.*(xFn - ndp.rightRidge)**2/(2 * sig**2))
spAge = ndp.slabMaxAge*fn.math.abs((ndp.leftRidge - xFn)/(ndp.subZoneLoc - ndp.leftRidge))
opAge = ndp.opMaxAge*fn.math.abs((ndp.rightRidge - xFn)/(ndp.subZoneLoc - ndp.rightRidge))
if md.spuniform:
if not md.spfixed:
spAge = ridgeFn*ndp.slabMaxAge
else:
spAge = fn.misc.constant(ndp.slabMaxAge)
if md.opuniform:
if not md.opfixed:
opAge = ridgeFn*ndp.opMaxAge
else:
opAge = fn.misc.constant(ndp.opMaxAge)
proxyageFn = fn.branching.conditional([(xFn <= ndp.subZoneLoc, spAge), #idea is to make this arbitrarily complex
(True, opAge)])
# ## Marker lines for slab, fault, tracking
# ### slab top
# In[78]:
help(slab_top)
# In[79]:
#Create some slab gradient functions to use with slab_top()
def linearGradientFn(S):
return np.tan(np.deg2rad(-45.))
def circGradientFn(S):
if S == 0.:
return 0.
elif S < ndp.radiusOfCurv:
return -S/np.sqrt((ndp.radiusOfCurv**2 - S**2))
else:
return -1e5
def polyGradientFn(S):
if S == 0.:
return 0.
else:
return -1*(S/ndp.radiusOfCurv)**2
# In[80]:
ds = 5e3/sf.lengthScale
normal = [1.,0.]
#data = slab_top([ndp.subZoneLoc, 1.0], normal, linearGradientFn, ds, ndp.maxDepth, mesh)
data = slab_top([ndp.subZoneLoc, 1.0], normal, polyGradientFn, ds, ndp.maxDepth, mesh)
#data = slab_top([ndp.subZoneLoc, 1.0], normal, circGradientFn, ds, ndp.maxDepth, mesh)
# In[81]:
slabxs = data[:,0]
slabys = data[:,1]
# In[82]:
slabLine = markerLine2D(mesh, velocityField, slabxs, slabys, thicknessAtTrench, 1.)
# In[83]:
#Assign the signed distance for the slab - in this case we only want the portion where the signed distance is positive
sd, pts = slabLine.compute_signed_distance(swarm.particleCoordinates.data, distance=2.*thicknessAtTrench)
signedDistanceVariable.data[np.logical_and(sd>0, sd<=slabLine.thickness)] = sd[np.logical_and(sd>0, sd<=slabLine.thickness)]
#Note distance=2.*thicknessAtTrench: we actually want to allow distance greater than thicknessAtTrench in the kDTree query,
#as some of these distances will not be orthogonal to the marker line, the dot product in the function will project these distances onto the normal vector
#We'll cull distances greater than thicknessAtTrench with a numpy boolean slice - this helps things work parallel
# In[84]:
slabXConds = operator.and_(xFn > slabxs.min(), xFn < slabxs.max())
slabYConds = depthFn < 1. - slabys.min()
#Two functions we'll use to limit the region of the initial thermal stancil
slabRegion = fn.branching.conditional([(operator.and_(slabXConds,slabYConds), True),
(True, False)])
#slabCirc = inCircleFnGenerator((ndp.subZoneLoc, 1.0 - ndp.maxDepth), ndp.maxDepth)
# In[85]:
bufferlength = 1e3/sf.lengthScale
plateDepthFn = fn.branching.conditional([(depthFn < thicknessAtTrench, depthFn),
(True, 1.)])
plateTempProxFn = ndp.potentialTemp*fn.math.erf((plateDepthFn)/(2.*fn.math.sqrt(1.*proxyageFn)))
slabTempProx = ndp.potentialTemp*fn.math.erf((signedDistanceVariable)/(2.*np.sqrt(1.*ndp.slabMaxAge)))
proxytempConds = fn.branching.conditional([(signedDistanceVariable < bufferlength, plateTempProxFn),
#(operator.and_(slabRegion, slabCirc), fn.misc.min(slabTempProx , plateTempProxFn)),
(slabRegion, fn.misc.min(slabTempProx , plateTempProxFn)),
(True, plateTempProxFn)])
#*************CHECKPOINT-BLOCK**************#
if not cp.restart:
proxyTempVariable.data[:] = proxytempConds.evaluate(swarm)
#*************CHECKPOINT-BLOCK**************#
# ### marker
#
# In this notebook, the markerLine helps us set up the initial distribution of weak material. We take the points that desribe the top of the slab, and we add extra particles along the top of the lower plate (so that there is weak material covering the entirety of the lower plate and slab)
# In[86]:
morexs = np.arange(mesh.minCoord[0] + 100e3/sf.lengthScale, ndp.subZoneLoc, ds)[:-1]
moreys = mesh.maxCoord[1]*np.ones(morexs.shape)
# In[87]:
#Build marker: copy the slab line, then move using the normal vector (director)
markerxs = np.concatenate((morexs,slabxs[:-2]))
markerys = np.concatenate((moreys,slabys[:-2]))
marker = markerLine2D(mesh, velocityField,markerxs, markerys, ndp.crustThickness, 1)
with marker.swarm.deform_swarm():
marker.swarm.particleCoordinates.data[:] += marker.director.data*ndp.crustThickness
marker.rebuild()
marker.swarm.update_particle_owners()
# In[88]:
#inform the mesh of the marker
sd, pts0 = marker.compute_signed_distance(swarm.particleCoordinates.data, distance=thicknessAtTrench)
sp, pts0 = marker.compute_marker_proximity(swarm.particleCoordinates.data, distance=ndp.crustThickness)
#*************CHECKPOINT-BLOCK**************#
if not cp.restart:
materialVariable.data[np.logical_and(sd<0,sp == marker.ID)] = sp[np.logical_and(sd<0,sp == marker.ID)]
#*************CHECKPOINT-BLOCK**************#
# ## Interpolate to temperature field
#
# In[89]:
def swarmToTemp():
_ix, _weights, _dist = nn_evaluation(swarm.particleCoordinates.data, mesh.data, n=4, weighted=True)
#_dist.shape, mesh.data.shape
#if
tempMapTol = 0.2
tempMapMask = _dist.min(axis=1) < tempMapTol*(1. - mesh.minCoord[1])/mesh.elementRes[1]
#temperatureField.data[:] = 0.
temperatureField.data[:] = ndp.potentialTemp #first set to dimensionless potential temp
#now used IDW to assign temp from particles to Field
#this is looking pretty ugly; nn_evaluation could use some grooming
temperatureField.data[:,0][tempMapMask] = np.average(proxyTempVariable.evaluate(swarm)[_ix][tempMapMask][:,:,0],weights=_weights[tempMapMask], axis=1)
#now cleanup any values that have fallen outside the Bcs
temperatureField.data[temperatureField.data > 1.] = ndp.potentialTemp
temperatureField.data[temperatureField.data < 0.] = 0.
#and cleanup the BCs
temperatureField.data[bWalls.data] = ndp.potentialTemp
temperatureField.data[tWalls.data] = 0.
# In[90]:
#map proxy temp (swarm var) to mesh variable
if not cp.restart:
swarmToTemp()
# ## choose temp field to use
# In[91]:
if md.thermal:
temperatureFn = temperatureField
else:
temperatureFn = proxyTempVariable
# ## adiabatic temp correction
# In[1]:
#Adiabatic correction: this is added to the arrhenius laws to simulate the adiabatic component
#note that this applies everywhere the heating that a parcel at the surface at the potential temp. would experience
adiabaticCorrectFn = ndp.potentialTemp*fn.math.exp(ndp.dissipation*depthFn) - ndp.potentialTemp
# In[93]:
#figTemp= glucifer.Figure(quality=3, boundingBox= bBox)
#figTemp.append( glucifer.objects.Points(swarm, temperatureFn + adiabaticCorrectFn, pointSize=1))
#figTempappend( glucifer.objects.Points(swarm, materialVariable, pointSize=1))
#figTemp.show()
# ## Rheology
# In[94]:
symStrainrate = fn.tensor.symmetric(
velocityField.fn_gradient )
#Set up any functions required by the rheology
strainRate_2ndInvariant = fn.tensor.second_invariant(
fn.tensor.symmetric(
velocityField.fn_gradient ))
def safe_visc(func, viscmin=ndp.viscosityMin, viscmax=ndp.viscosityMax):
return fn.misc.max(viscmin, fn.misc.min(viscmax, func))
# In[95]:
##Diffusion Creep
diffusionUM = (1./ndp.diffusionPreExp)* fn.math.exp( ((ndp.diffusionEnergy + (depthFn*ndp.diffusionVolume))/((temperatureFn+ adiabaticCorrectFn + ndp.surfaceTemp))))
diffusionLM = ndp.lowerMantleViscFac*(1./ndp.lowerMantlePreExp)* fn.math.exp( ((ndp.lowerMantleEnergy + (depthFn*ndp.lowerMantleVolume))/((temperatureFn+ adiabaticCorrectFn + ndp.surfaceTemp))))
diffusion = fn.branching.conditional( ((depthFn < ndp.lowerMantleDepth, diffusionUM ),
(True, diffusionLM ) ))
diffusion = safe_visc(diffusion, viscmax=1e5)
#mantle Plasticity
ys = ndp.cohesionMantle + (depthFn*ndp.frictionMantle)
ysf = fn.misc.min(ys, ndp.yieldStressMax)
yielding = ysf/(2.*(strainRate_2ndInvariant) + 1e-15)
##Crust plasticity
crustys = ndp.cohesionCrust + (depthFn*ndp.frictionCrust)
crustysf = fn.misc.min(crustys, ndp.yieldStressMax)
crustyielding0 = crustysf/(2.*(strainRate_2ndInvariant) + 1e-15)
#This bit phases out the weak crust (effective plastic viscosity and visc. max) over specified depths
depthTaperFn = cosine_taper(depthFn, ndp.crustViscCutoffDepth, ndp.crustViscEndWidth)
crustyielding = crustyielding0*(1. - depthTaperFn) + depthTaperFn*yielding
viscmaxCrustFn = ndp.viscosityMaxCrust*(1. - depthTaperFn) + depthTaperFn*ndp.viscosityMax
#combined rheologies for mantle and weak layer (crust / interface)
mantleViscosityFn = safe_visc(fn.misc.min(diffusion, yielding), viscmin=ndp.viscosityMin, viscmax=ndp.viscosityMax)
crustViscosityFn = safe_visc(crustyielding, viscmin=ndp.viscosityMinCrust, viscmax=viscmaxCrustFn)
# In[96]:
viscosityMapFn = fn.branching.map( fn_key = materialVariable,
mapping = {0:mantleViscosityFn,
1:crustViscosityFn} )
# ## Buoyancy
# In[97]:
#Thermal Buoyancy
z_hat = ( 0.0, -1.0 )
thermalBuoyancyFn = ndp.rayleigh*(1. - temperatureFn)
thermalBuoyancyFn *=z_hat
# ## Any other functions we'll need
# In[98]:
###################
#Create integral, max/min templates
###################
globRestFn = 1.
def surfint(Fn = 1., rFn=globRestFn, surfaceIndexSet=mesh.specialSets["MaxJ_VertexSet"]):
return uw.utils.Integral( Fn*rFn, mesh=mesh, integrationType='Surface', surfaceIndexSet=surfaceIndexSet)
# ## Stokes system and solver
# In[99]:
print('got to Stokes')
# In[100]:
stokesPIC = uw.systems.Stokes( velocityField = velocityField,
pressureField = pressureField,
conditions = [freeslipBC,],
fn_viscosity = viscosityMapFn,
fn_bodyforce = thermalBuoyancyFn )
# In[101]:
solver = uw.systems.Solver(stokesPIC)
if md.penaltyMethod:
solver.set_inner_method("mumps")
solver.options.scr.ksp_type="cg"
solver.set_penalty(1.0e7)
solver.options.scr.ksp_rtol = 1.0e-4
else:
solver.options.main.Q22_pc_type='gkgdiag'
solver.options.scr.ksp_rtol=5e-5
solver.set_inner_method('mg')
solver.options.mg.levels = 4