1 | %SOLIDEARTH class definition
|
---|
2 | %
|
---|
3 | % Usage:
|
---|
4 | % solidearth=solidearth();
|
---|
5 |
|
---|
6 | classdef solidearth
|
---|
7 | properties (SetAccess=public)
|
---|
8 | settings = solidearthsettings();
|
---|
9 | external = [];
|
---|
10 | lovenumbers = lovenumbers();
|
---|
11 | rotational = rotational();
|
---|
12 | planetradius = planetradius('earth');
|
---|
13 | requested_outputs = {};
|
---|
14 | transitions = {};
|
---|
15 | partitionice = [];
|
---|
16 | partitionhydro = [];
|
---|
17 | partitionocean = [];
|
---|
18 | end
|
---|
19 | methods (Static)
|
---|
20 | function self = loadobj(self) % {{{
|
---|
21 | % This function is directly called by matlab when a model object is
|
---|
22 | % loaded. If the input is a struct it is an old version of this class and
|
---|
23 | % old fields must be recovered (make sure they are in the deprecated
|
---|
24 | % model properties)
|
---|
25 |
|
---|
26 | if isstruct(self)
|
---|
27 | % 2021, Jan 10
|
---|
28 | if isfield(self,'sealevel')
|
---|
29 | self.initialsealevel = self.sealevel;
|
---|
30 | end
|
---|
31 | self = structtoobj(solidearth(),self);
|
---|
32 |
|
---|
33 | end
|
---|
34 | end% }}}
|
---|
35 | end
|
---|
36 | methods
|
---|
37 | function self = solidearth(varargin) % {{{
|
---|
38 | switch nargin
|
---|
39 | case 0
|
---|
40 | self=setdefaultparameters(self,'earth');
|
---|
41 | case 1
|
---|
42 | self=setdefaultparameters(self,varargin{:});
|
---|
43 | otherwise
|
---|
44 | error('solidearth constructor error message: zero or one argument only!');
|
---|
45 | end
|
---|
46 | end % }}}
|
---|
47 | function disp(self) % {{{
|
---|
48 | disp(sprintf(' solidearth inputs, forcings and settings:'));
|
---|
49 |
|
---|
50 | fielddisplay(self,'planetradius','planet radius [m]');
|
---|
51 | fielddisplay(self,'transitions','indices into parts of the mesh that will be icecaps');
|
---|
52 | fielddisplay(self,'requested_outputs','additional outputs requested');
|
---|
53 | fielddisplay(self,'partitionice','ice partition vector for barystatic contribution');
|
---|
54 | fielddisplay(self,'partitionhydro','hydro partition vector for barystatic contribution');
|
---|
55 | fielddisplay(self,'partitionocean','ocean partition vector for barystatic contribution');
|
---|
56 | if isempty(self.external), fielddisplay(self,'external','external solution, of the type solidearthsolution'); end
|
---|
57 | self.settings.disp();
|
---|
58 | self.lovenumbers.disp();
|
---|
59 | self.rotational.disp();
|
---|
60 | if ~isempty(self.external),
|
---|
61 | self.external.disp();
|
---|
62 | end
|
---|
63 |
|
---|
64 | end % }}}
|
---|
65 | function self = setdefaultparameters(self,planet) % {{{
|
---|
66 |
|
---|
67 | %output default:
|
---|
68 | self.requested_outputs={'default'};
|
---|
69 |
|
---|
70 | %transitions should be a cell array of vectors:
|
---|
71 | self.transitions={};
|
---|
72 |
|
---|
73 | %no partitions requested for barystatic contribution:
|
---|
74 | self.partitionice=[];
|
---|
75 | self.partitionhydro=[];
|
---|
76 | self.partitionocean=[];
|
---|
77 |
|
---|
78 | %no external solutions by default:
|
---|
79 | self.external=[];
|
---|
80 |
|
---|
81 | %earth radius
|
---|
82 | self.planetradius= planetradius(planet);
|
---|
83 |
|
---|
84 | end % }}}
|
---|
85 | function md = checkconsistency(self,md,solution,analyses) % {{{
|
---|
86 |
|
---|
87 | if ~ismember('SealevelchangeAnalysis',analyses) | (strcmp(solution,'TransientSolution') & md.transient.isslc==0),
|
---|
88 | return;
|
---|
89 | end
|
---|
90 |
|
---|
91 | md = checkfield(md,'fieldname','solidearth.requested_outputs','stringrow',1);
|
---|
92 |
|
---|
93 | self.settings.checkconsistency(md,solution,analyses);
|
---|
94 | self.lovenumbers.checkconsistency(md,solution,analyses);
|
---|
95 | self.rotational.checkconsistency(md,solution,analyses);
|
---|
96 | if ~isempty(self.external),
|
---|
97 | if ~isa(self.external,'solidearthsolution'),
|
---|
98 | error('solidearth consistency check: external field should be a solidearthsolution');
|
---|
99 | end
|
---|
100 | self.external.checkconsistency(md,solution,analyses);
|
---|
101 | end
|
---|
102 |
|
---|
103 | end % }}}
|
---|
104 | function list=defaultoutputs(self,md) % {{{
|
---|
105 | list = {'Sealevel'};
|
---|
106 | end % }}}
|
---|
107 | function marshall(self,prefix,md,fid) % {{{
|
---|
108 |
|
---|
109 | WriteData(fid,prefix,'object',self,'fieldname','planetradius','format','Double');
|
---|
110 | WriteData(fid,prefix,'object',self,'fieldname','transitions','format','MatArray');
|
---|
111 |
|
---|
112 | if ~isempty(self.partitionice),
|
---|
113 | npartice=max(self.partitionice)+2;
|
---|
114 | else
|
---|
115 | npartice=0;
|
---|
116 | end
|
---|
117 | if ~isempty(self.partitionhydro),
|
---|
118 | nparthydro=max(self.partitionhydro)+2;
|
---|
119 | else
|
---|
120 | nparthydro=0;
|
---|
121 | end
|
---|
122 | if ~isempty(self.partitionocean),
|
---|
123 | npartocean=max(self.partitionocean)+2;
|
---|
124 | else
|
---|
125 | npartocean=0;
|
---|
126 | end
|
---|
127 |
|
---|
128 | WriteData(fid,prefix,'object',self,'fieldname','partitionice','mattype',1,'format','DoubleMat');
|
---|
129 | WriteData(fid,prefix,'data',npartice,'format','Integer','name','md.solidearth.npartice');
|
---|
130 | WriteData(fid,prefix,'object',self,'fieldname','partitionhydro','mattype',1,'format','DoubleMat');
|
---|
131 | WriteData(fid,prefix,'data',nparthydro,'format','Integer','name','md.solidearth.nparthydro');
|
---|
132 | WriteData(fid,prefix,'object',self,'fieldname','partitionocean','mattype',1,'format','DoubleMat');
|
---|
133 | WriteData(fid,prefix,'data',npartocean,'format','Integer','name','md.solidearth.npartocean');
|
---|
134 |
|
---|
135 | self.settings.marshall(prefix,md,fid);
|
---|
136 | self.lovenumbers.marshall(prefix,md,fid);
|
---|
137 | self.rotational.marshall(prefix,md,fid);
|
---|
138 | if ~isempty(self.external),
|
---|
139 | WriteData(fid,prefix,'data',1,'format','Integer','name','md.solidearth.isexternal');
|
---|
140 | self.external.marshall(prefix,md,fid);
|
---|
141 | else
|
---|
142 | WriteData(fid,prefix,'data',0,'format','Integer','name','md.solidearth.isexternal');
|
---|
143 | end
|
---|
144 |
|
---|
145 | %process requested outputs
|
---|
146 | outputs = self.requested_outputs;
|
---|
147 | pos = find(ismember(outputs,'default'));
|
---|
148 | if ~isempty(pos),
|
---|
149 | outputs(pos) = []; %remove 'default' from outputs
|
---|
150 | outputs = [outputs defaultoutputs(self,md)]; %add defaults
|
---|
151 | end
|
---|
152 | WriteData(fid,prefix,'data',outputs,'name','md.solidearth.requested_outputs','format','StringArray');
|
---|
153 |
|
---|
154 | end % }}}
|
---|
155 | function self = extrude(self,md) % {{{
|
---|
156 | end % }}}
|
---|
157 | function savemodeljs(self,fid,modelname) % {{{
|
---|
158 |
|
---|
159 | self.settings.savemodeljs(fid,modelname);
|
---|
160 | self.lovenumbers.savemodeljs(fid,modelname);
|
---|
161 | self.rotational.savemodeljs(fid,modelname);
|
---|
162 | if ~isempty(self.external),
|
---|
163 | self.external.savemodeljs(fid,modelname);
|
---|
164 | end
|
---|
165 | writejscellstring(fid,[modelname '.solidearth.requested_outputs'],self.requested_outputs);
|
---|
166 | writejscellarray(fid,[modelname '.solidearth.transitions'],self.transitions);
|
---|
167 | writejscellarray(fid,[modelname '.solidearth.partition'],self.partition);
|
---|
168 | end % }}}
|
---|
169 | end
|
---|
170 | end
|
---|