forked from jhill1/open-stratigraphy-model
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_sed.py
117 lines (90 loc) · 3.68 KB
/
run_sed.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
from sediment import *
import libspud
import sys
import argparse
#should be an osml file
def Main():
#Import the command line arguments and return them
parser = argparse.ArgumentParser(description='input a file name')
parser.add_argument('--v','--verbose', action='store_true', help="Verbose output: mainly graphics at each time step", default=False)
parser.add_argument('file_name', help='Insert the file name of the simulation you wish to run. It should end with.osml')
parser.add_argument('created_file_name', help='Insert the name of the file you are generating. It should end in .pvd')
args = parser.parse_args()
libspud.clear_options()
file_name = args.file_name
Verbose = args.v
new = args.created_file_name
return file_name, Verbose, new
def New_File(New):
try:
NewFile = File(New)
except:
print 'File name not given for new file. Use -h for more information. Hint: it should end in .pvd'
sys.exit()
return NewFile
def Parameters(file_name):
try:
libspud.load_options(file_name)
except:
print "This file doesn't exist or is the wrong file type. It should be a .osml file. Use -h for help"
sys.exit()
try:
start = float(libspud.get_option('/diffusion_model/timestepping/start_time',))
end = float(libspud.get_option('/diffusion_model/timestepping/end_time'))
time_step = float(libspud.get_option('/diffusion_model/timestepping/timestep'))
mesh_int = int(libspud.get_option('/diffusion_model/mesh/initial_mesh_size'))
alpha = float(libspud.get_option('/diffusion_model/model_parameters/diffusion_coefficient'))
initial_conditions = str(libspud.get_option('/diffusion_model/model_parameters/topography_conditions'))
sediment_conditions =str(libspud.get_option('/diffusion_model/model_parameters/sediment_conditions'))
except:
print 'The information provided was incomplete, please recreate the file'
sys.exit()
if ((start-end) >= 0):
print 'The start time is after the end time'
sys.exit()
elif (time_step == 0):
print 'The time step cannot be 0'
sys.exit()
elif (mesh_int == 0):
print 'The mesh has to have a size greater than 0'
sys.exit()
elif ((end - start) < time_step):
print 'The time step is too large for the total time'
sys.exit()
return start, end, time_step, mesh_int, alpha, initial_conditions, sediment_conditions
def set_up_model(start, end, time_step, mesh_int, alpha, initial_conditions, sediment_conditions, sediment, verbose = 'false'):
#create a simple testcase
model = SedimentModel()
mesh = UnitSquareMesh(mesh_int,mesh_int)
model.set_mesh(mesh)
try:
init_cond = Expression(initial_conditions) # simple slope
init_sed = Expression(sediment_conditions)
except:
print 'Your initial conditions were not valid functions'
sys.exit()
#init_sed = Expression('x[0]') # this gives
# total of above gives a slope of 0 to 2 (over the unit square)
model.set_initial_conditions(init_cond,init_sed)
model.set_start_time(start)
model.set_timestep(time_step)
model.set_end_time(end)
model.set_diffusion_coeff(alpha)
model.init()
model.solve(sediment)
# answer should be 1 everywhere
#plot(model.get_total_height(),interactive=True)
#print model.get_total_height_array()
tha = model.get_total_height_array()
th = model.get_total_height()
sha = model.get_sed_height_array()
sh = model.get_sed_height()
topha = model.get_topographic_height_array()
toph = model.get_topographic_height()
return tha, th, sha, sh, topha, toph
if __name__ == "__main__" :
fname , verbose, new = Main()
NewFile = New_File(new)
start, end, time_step, mesh_int, alpha, initial_conditions = Parameters(fname)
tha, th, sha, sh, topha, toph = set_up_model(start, end, time_step, mesh_int, alpha, initial_conditions, verbose)
NewFile << toph