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