source: issm/trunk/src/m/classes/timesteppingadaptive.py@ 26744

Last change on this file since 26744 was 26744, checked in by Mathieu Morlighem, 3 years ago

merged trunk-jpl and trunk for revision 26742

File size: 4.9 KB
Line 
1from fielddisplay import fielddisplay
2from checkfield import checkfield
3from WriteData import WriteData
4
5
6class timesteppingadaptive(object):
7 """
8 TIMESTEPPINGADAPTIVE Class definition
9
10 Usage:
11 timesteppingadaptive = timesteppingadaptive()
12 """
13
14 def __init__(self, *args): # {{{
15 if not len(args):
16 self.start_time = 0.
17 self.final_time = 0.
18 self.time_step_min = 0.
19 self.time_step_max = 0.
20 self.cfl_coefficient = 0.
21 self.interp_forcing = 1
22 self.cycle_forcing = 0
23 self.coupling_time = 0.
24
25 #set defaults
26 self.setdefaultparameters()
27
28 elif len(args) == 1 and args[0].__module__ == 'timestepping':
29 old = args[0]
30 #first call setdefaultparameters:
31 self.setdefaultparameters()
32 self.start_time = old.start_time
33 self.final_time = old.final_time
34 self.interp_forcing = old.interp_forcing
35 self.cycle_forcing = old.cycle_forcing
36 self.coupling_time = old.coupling_time
37
38 else:
39 raise Exception('constructor not supported')
40 #}}}
41
42 def __repr__(self): # {{{
43 string = " timesteppingadaptive parameters:"
44 string = "%s\n%s" % (string, fielddisplay(self, "start_time", "simulation starting time [yr]"))
45 string = "%s\n%s" % (string, fielddisplay(self, "final_time", "final time to stop the simulation [yr]"))
46 string = "%s\n%s" % (string, fielddisplay(self, "time_step_min", "minimum length of time steps [yr]"))
47 string = "%s\n%s" % (string, fielddisplay(self, "time_step_max", "maximum length of time steps [yr]"))
48 string = "%s\n%s" % (string, fielddisplay(self, "cfl_coefficient", "coefficient applied to cfl condition"))
49 string = "%s\n%s" % (string, fielddisplay(self, "interp_forcing", "interpolate in time between requested forcing values ? (0 or 1)"))
50 string = "%s\n%s" % (string, fielddisplay(self, "cycle_forcing", "cycle through forcing ? (0 or 1)"))
51 string = "%s\n%s" % (string, fielddisplay(self, "coupling_time", "coupling time steps with ocean model [yr]"))
52 return string
53 # }}}
54
55 def setdefaultparameters(self): # {{{
56 #time between 2 time steps
57 self.time_step_min = 0.01
58 self.time_step_max = 10.
59 #final time
60 self.final_time = 10. * self.time_step_max
61 #time adaptation?
62 self.cfl_coefficient = 0.5
63 #should we interpolate forcing between timesteps?
64 self.interp_forcing = 1
65 self.cycle_forcing = 0
66 return self
67 #}}}
68
69 def checkconsistency(self, md, solution, analyses): # {{{
70 md = checkfield(md, 'fieldname', 'timestepping.start_time', 'numel', [1], 'NaN', 1, 'Inf', 1)
71 md = checkfield(md, 'fieldname', 'timestepping.final_time', 'numel', [1], 'NaN', 1, 'Inf', 1)
72 md = checkfield(md, 'fieldname', 'timestepping.time_step_min', 'numel', [1], '>=', 0, 'NaN', 1, 'Inf', 1)
73 md = checkfield(md, 'fieldname', 'timestepping.time_step_max', 'numel', [1], '>=', md.timestepping.time_step_min, 'NaN', 1, 'Inf', 1)
74 md = checkfield(md, 'fieldname', 'timestepping.cfl_coefficient', 'numel', [1], '>', 0, '<=', 1)
75 if self.final_time - self.start_time < 0:
76 md.checkmessage("timestepping.final_time should be larger than timestepping.start_time")
77 md = checkfield(md, 'fieldname', 'timestepping.interp_forcing', 'numel', [1], 'values', [0, 1])
78 md = checkfield(md, 'fieldname', 'timestepping.cycle_forcing', 'numel', [1], 'values', [0, 1])
79 md = checkfield(md, 'fieldname', 'timestepping.coupling_time', 'numel', [1], '>=', 0, 'NaN', 1, 'Inf', 1)
80
81 return md
82 # }}}
83
84 def marshall(self, prefix, md, fid): # {{{
85 yts = md.constants.yts
86 WriteData(fid, prefix, 'name', 'md.timestepping.type', 'data', 2, 'format', 'Integer')
87 WriteData(fid, prefix, 'object', self, 'class', 'timestepping', 'fieldname', 'start_time', 'format', 'Double', 'scale', yts)
88 WriteData(fid, prefix, 'object', self, 'class', 'timestepping', 'fieldname', 'final_time', 'format', 'Double', 'scale', yts)
89 WriteData(fid, prefix, 'object', self, 'class', 'timestepping', 'fieldname', 'time_step_min', 'format', 'Double', 'scale', yts)
90 WriteData(fid, prefix, 'object', self, 'class', 'timestepping', 'fieldname', 'time_step_max', 'format', 'Double', 'scale', yts)
91 WriteData(fid, prefix, 'object', self, 'class', 'timestepping', 'fieldname', 'cfl_coefficient', 'format', 'Double')
92 WriteData(fid, prefix, 'object', self, 'class', 'timestepping', 'fieldname', 'interp_forcing', 'format', 'Boolean')
93 WriteData(fid, prefix, 'object', self, 'class', 'timestepping', 'fieldname', 'cycle_forcing', 'format', 'Boolean')
94 WriteData(fid, prefix, 'object', self, 'class', 'timestepping', 'fieldname', 'coupling_time', 'format', 'Double', 'scale', yts)
95 # }}}
Note: See TracBrowser for help on using the repository browser.