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