[19753] | 1 | //TIMESTEPPING class definition
|
---|
| 2 | //
|
---|
| 3 | // Usage:
|
---|
| 4 | // timestepping=new timestepping();
|
---|
| 5 |
|
---|
| 6 | function timestepping (){
|
---|
| 7 | //methods
|
---|
| 8 | this.setdefaultparameters = function(){// {{{
|
---|
| 9 | //time between 2 time steps
|
---|
| 10 | this.time_step=1./2.;
|
---|
| 11 |
|
---|
| 12 | //final time
|
---|
| 13 | this.final_time=10.*this.time_step;
|
---|
| 14 |
|
---|
| 15 | //time adaptation?
|
---|
| 16 | this.time_adapt=0;
|
---|
| 17 | this.cfl_coefficient=0.5;
|
---|
| 18 |
|
---|
| 19 | //should we interpolate forcings between timesteps?
|
---|
| 20 | this.interp_forcings=1;
|
---|
| 21 |
|
---|
| 22 | //In years by default
|
---|
| 23 | this.in_years = 1;
|
---|
| 24 |
|
---|
| 25 | }// }}}
|
---|
| 26 | this.disp= function(){// {{{
|
---|
| 27 | console.log(sprintf(' timestepping parameters:'));
|
---|
| 28 |
|
---|
| 29 | if(this.in_years) unit = 'yr';
|
---|
| 30 | else unit = 's';
|
---|
| 31 | fielddisplay(this,'start_time','simulation starting time ['+ unit + ']');
|
---|
| 32 | fielddisplay(this,'final_time','final time to stop the simulation ['+ unit + ']');
|
---|
| 33 | fielddisplay(this,'time_step','length of time steps [' +unit+ ']');
|
---|
| 34 | fielddisplay(this,'time_adapt','use cfl condition to define time step ? (0 or 1) ');
|
---|
| 35 | fielddisplay(this,'cfl_coefficient','coefficient applied to cfl condition');
|
---|
| 36 | fielddisplay(this,'interp_forcings','interpolate in time between requested forcing values ? (0 or 1)');
|
---|
| 37 | fielddisplay(this,'in_years','time unit, 1: years, 0: seconds');
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | }// }}}
|
---|
[19791] | 41 | this.classname= function(){// {{{
|
---|
| 42 | return "timestepping";
|
---|
| 43 |
|
---|
| 44 | }// }}}
|
---|
[19780] | 45 | this.checkconsistency = function(md,solution,analyses) { //{{{
|
---|
| 46 |
|
---|
| 47 | checkfield(md,'fieldname','timestepping.start_time','numel',[1],'NaN',1);
|
---|
| 48 | checkfield(md,'fieldname','timestepping.final_time','numel',[1],'NaN',1);
|
---|
| 49 | checkfield(md,'fieldname','timestepping.time_step','numel',[1],'>=',0,'NaN',1);
|
---|
| 50 | checkfield(md,'fieldname','timestepping.time_adapt','numel',[1],'values',[0,1]);
|
---|
| 51 | checkfield(md,'fieldname','timestepping.cfl_coefficient','numel',[1],'>',0,'<=',1);
|
---|
| 52 | checkfield(md,'fieldname','timestepping.interp_forcings','numel',[1],'values',[0,1]);
|
---|
| 53 | if (this.final_time-this.start_time<0){
|
---|
| 54 | md.checkmessage('timestepping.final_time should be larger than timestepping.start_time');
|
---|
| 55 | }
|
---|
| 56 | } // }}}
|
---|
[19791] | 57 | this.marshall=function(md,fid) { //{{{
|
---|
| 58 |
|
---|
| 59 | var scale;
|
---|
| 60 | if (this.in_years) scale = 365.0*24.0*3600.0;
|
---|
| 61 | else scale = 1.;
|
---|
| 62 |
|
---|
| 63 | WriteData(fid,'object',this,'fieldname','start_time','format','Double','scale',scale);
|
---|
| 64 | WriteData(fid,'object',this,'fieldname','final_time','format','Double','scale',scale);
|
---|
| 65 | WriteData(fid,'object',this,'fieldname','time_step','format','Double','scale',scale);
|
---|
| 66 | WriteData(fid,'object',this,'fieldname','time_adapt','format','Boolean');
|
---|
| 67 | WriteData(fid,'object',this,'fieldname','cfl_coefficient','format','Double');
|
---|
| 68 | WriteData(fid,'object',this,'fieldname','interp_forcings','format','Boolean');
|
---|
| 69 |
|
---|
| 70 | }//}}}
|
---|
[19753] | 71 | //properties
|
---|
| 72 | // {{{
|
---|
| 73 | this.start_time = 0.;
|
---|
| 74 | this.final_time = 0.;
|
---|
| 75 | this.time_step = 0.;
|
---|
| 76 | this.time_adapt = 0;
|
---|
| 77 | this.cfl_coefficient = 0.;
|
---|
| 78 | this.interp_forcings = 1;
|
---|
| 79 | this.in_years = 1;
|
---|
| 80 |
|
---|
| 81 | this.setdefaultparameters();
|
---|
| 82 | //}}}
|
---|
| 83 | }
|
---|