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

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

merged trunk-jpl and trunk for revision 27230

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