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