[19753] | 1 | //SMBforcing Class definition
|
---|
| 2 | //
|
---|
| 3 | // Usage:
|
---|
| 4 | // SMB=SMBforcing();
|
---|
| 5 |
|
---|
| 6 | function SMBforcing(){
|
---|
| 7 | //methods
|
---|
| 8 | this.setdefaultparameters = function(){// {{{
|
---|
[19860] | 9 | this.requested_outputs=['default'];
|
---|
[19753] | 10 | } // }}}
|
---|
| 11 | this.disp = function(){ // {{{
|
---|
| 12 | console.log(sprintf(' surface forcings parameters:'));
|
---|
| 13 | fielddisplay(this,'mass_balance','surface mass balance [m/yr ice eq]');
|
---|
[26300] | 14 | fielddisplay(this,'steps_per_step', 'number of smb steps per time step');
|
---|
[19753] | 15 | fielddisplay(this,'requested_outputs','additional outputs requested');
|
---|
[26300] | 16 | fielddisplay(this,'averaging','averaging methods from short to long steps');
|
---|
| 17 | console.log(sprintf('%51s 0: Arithmetic (default)',' '));
|
---|
| 18 | console.log(sprintf('%51s 1: Geometric',' '));
|
---|
| 19 | console.log(sprintf('%51s 2: Harmonic',' '));
|
---|
[19753] | 20 | } // }}}
|
---|
[19791] | 21 | this.defaultoutputs = function(){ // {{{
|
---|
[27403] | 22 | return 'SmbMassBalance';
|
---|
[19791] | 23 | }//}}}
|
---|
[20801] | 24 | this.classname = function(){ // {{{
|
---|
| 25 | return "SMBforcing";
|
---|
| 26 | } // }}}
|
---|
| 27 | this.extrude = function(md) {//{{{
|
---|
| 28 | this.mass_balance=project3d(md,'vector',this.mass_balance,'type','node');
|
---|
[20806] | 29 | return this;
|
---|
[20801] | 30 | }//}}}
|
---|
| 31 | this.initialize = function(md) {// {{{
|
---|
[19759] | 32 |
|
---|
[20801] | 33 | if (isNaN(this.mass_balance)){
|
---|
| 34 | this.mass_balance=NewArrayFill(md.mesh.numberofvertices,0);
|
---|
| 35 | console.log(' no smb.mass_balance specified: values set as zero');
|
---|
| 36 | }
|
---|
[19759] | 37 |
|
---|
[20801] | 38 | } // }}}
|
---|
| 39 | this.checkconsistency = function(md,solution,analyses) { //{{{
|
---|
[26300] | 40 | if (solution=='TransientSolution' && md.transient.issmb == 0) return;
|
---|
[21065] | 41 | if(ArrayAnyEqual(ArrayIsMember('MasstransportAnalysis',analyses),1)){
|
---|
[20801] | 42 | checkfield(md,'fieldname','smb.mass_balance','timeseries',1,'NaN',1,'Inf',1);
|
---|
| 43 | }
|
---|
[21065] | 44 | if(ArrayAnyEqual(ArrayIsMember('BalancethicknessAnalysis',analyses),1)){
|
---|
[20801] | 45 | checkfield(md,'fieldname','smb.mass_balance','size',[md.mesh.numberofvertices,1],'NaN',1,'Inf',1);
|
---|
| 46 | }
|
---|
[26300] | 47 | checkfield(md,'fieldname','smb.steps_per_step','>=',1,'numel',[1]);
|
---|
| 48 | checkfield(md,'fieldname','smb.requested_outputs','stringrow',1);
|
---|
| 49 | checkfield(md,'fieldname','smb.averaging','numel',[1],'values',[0,1,2]);
|
---|
[20801] | 50 | } // }}}
|
---|
| 51 | this.marshall=function(md,prefix,fid) { //{{{
|
---|
[19791] | 52 |
|
---|
[20896] | 53 | var yts=md.constants.yts;
|
---|
[19791] | 54 |
|
---|
[20889] | 55 | WriteData(fid,prefix,'name','md.smb.model','data',1,'format','Integer');
|
---|
[20902] | 56 | WriteData(fid,prefix,'object',this,'class','smb','fieldname','mass_balance','format','DoubleMat','mattype',1,'scale',1./yts,'timeserieslength',md.mesh.numberofvertices+1,'yts',md.constants.yts);
|
---|
[26300] | 57 | WriteData(fid,prefix,'object',this,'fieldname','steps_per_step','format','Integer');
|
---|
| 58 | WriteData(fid,prefix,'object',this,'fieldname','averaging','format','Integer');
|
---|
[19791] | 59 |
|
---|
[20801] | 60 | //process requested outputs
|
---|
| 61 | var outputs = this.requested_outputs.slice();
|
---|
| 62 | for (var i=0;i<outputs.length;i++){
|
---|
| 63 | if (outputs[i] == 'default') {
|
---|
| 64 | outputs.splice(i,1);
|
---|
| 65 | var newoutputs=this.defaultoutputs(md);
|
---|
| 66 | for (var j=0;j<newoutputs.length;j++) outputs.push(newoutputs[j]);
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | WriteData(fid,prefix,'data',outputs,'name','md.smb.requested_outputs','format','StringArray');
|
---|
| 70 |
|
---|
| 71 | }//}}}
|
---|
| 72 | this.fix=function() { //{{{
|
---|
| 73 | }//}}}
|
---|
[19753] | 74 | //properties
|
---|
[20843] | 75 | // {{{
|
---|
[26300] | 76 | this.mass_balance = NaN;
|
---|
| 77 | this.requested_outputs = [];
|
---|
| 78 | this.steps_per_step = 1;
|
---|
| 79 | this.averaging = 0;
|
---|
[19753] | 80 | this.setdefaultparameters();
|
---|
[20843] | 81 | // }}}
|
---|
[19753] | 82 | }
|
---|