1 | %TOOLKITS class definition
|
---|
2 | %
|
---|
3 | % Usage:
|
---|
4 | % self=toolkits();
|
---|
5 |
|
---|
6 | classdef toolkits < dynamicprops
|
---|
7 | properties (SetAccess=public)
|
---|
8 | DefaultAnalysis = struct();
|
---|
9 | RecoveryAnalysis = struct();
|
---|
10 | %The other properties are dynamic
|
---|
11 | end
|
---|
12 | methods (Static)
|
---|
13 | function self = loadobj(self) % {{{
|
---|
14 | % This function is directly called by matlab when a model object is
|
---|
15 | % loaded. Update old properties here
|
---|
16 |
|
---|
17 | if isempty(fieldnames(self.RecoveryAnalysis));
|
---|
18 | disp('WARNING: updating toolkits (RecoveryAnalysis not set)');
|
---|
19 | self.RecoveryAnalysis = self.DefaultAnalysis;
|
---|
20 | end
|
---|
21 | end% }}}
|
---|
22 | end
|
---|
23 | methods
|
---|
24 | function self = toolkits(varargin) % {{{
|
---|
25 | switch nargin
|
---|
26 | case 0
|
---|
27 | self=setdefaultparameters(self);
|
---|
28 | case 1
|
---|
29 | self=structtoobj(self,varargin{1});
|
---|
30 | otherwise
|
---|
31 | error('constructor not supported');
|
---|
32 | end
|
---|
33 | end % }}}
|
---|
34 | function self = addoptions(self,analysis,varargin) % {{{
|
---|
35 | % Usage example:
|
---|
36 | % md.toolkits=addoptions(md.toolkits,'StressbalanceAnalysis',FSoptions());
|
---|
37 | % md.toolkits=addoptions(md.toolkits,'StressbalanceAnalysis');
|
---|
38 |
|
---|
39 | %Create dynamic property if property does not exist yet
|
---|
40 | if ~ismember(analysis,properties(self)),
|
---|
41 | self.addprop(analysis);
|
---|
42 | end
|
---|
43 |
|
---|
44 | %Add toolkits options to analysis
|
---|
45 | if nargin==3, self.(analysis) = varargin{1}; end
|
---|
46 | end
|
---|
47 | %}}}
|
---|
48 | function self = setdefaultparameters(self) % {{{
|
---|
49 |
|
---|
50 | %default toolkits:
|
---|
51 | if IssmConfig('_HAVE_PETSC_'),
|
---|
52 | %MUMPS is the default toolkits
|
---|
53 | if IssmConfig('_HAVE_MUMPS_'),
|
---|
54 | self.DefaultAnalysis = mumpsoptions();
|
---|
55 | else
|
---|
56 | self.DefaultAnalysis = iluasmoptions();
|
---|
57 | end
|
---|
58 | else
|
---|
59 | if IssmConfig('_HAVE_MUMPS_'),
|
---|
60 | self.DefaultAnalysis = issmmumpssolver();
|
---|
61 | elseif IssmConfig('_HAVE_GSL_'),
|
---|
62 | self.DefaultAnalysis = issmgslsolver();
|
---|
63 | else
|
---|
64 | disp('WARNING: Need at least Mumps or Gsl to define an issm solver type, no default solver assigned');
|
---|
65 | end
|
---|
66 | end
|
---|
67 |
|
---|
68 | %Use same solver for Recovery mode
|
---|
69 | self.RecoveryAnalysis = self.DefaultAnalysis;
|
---|
70 |
|
---|
71 |
|
---|
72 | end % }}}
|
---|
73 | function disp(self) % {{{
|
---|
74 | analyses=properties(self);
|
---|
75 | disp(sprintf('List of toolkits options per analysis:\n'));
|
---|
76 | for i=1:numel(analyses),
|
---|
77 | analysis=analyses{i};
|
---|
78 | disp([analysis ':']);
|
---|
79 | disp(self.(analysis));
|
---|
80 | end
|
---|
81 | end % }}}
|
---|
82 | function md = checkconsistency(self,md,solution,analyses) % {{{
|
---|
83 | analyses=properties(self);
|
---|
84 | for i=1:numel(analyses),
|
---|
85 | switch analyses{i}
|
---|
86 | case 'DefaultAnalysis'
|
---|
87 | case 'RecoveryAnalysis'
|
---|
88 | case 'StressbalanceAnalysis'
|
---|
89 | case 'MasstransportAnalysis'
|
---|
90 | case 'ThermalAnalysis'
|
---|
91 | case 'BalancethicknessAnalysis'
|
---|
92 | case 'Balancethickness2Analysis'
|
---|
93 | case 'BalancethicknessSoftAnalysis'
|
---|
94 | case 'BalancevelocityAnalysis'
|
---|
95 | case 'DamageEvolutionAnalysis'
|
---|
96 | case 'LoveAnalysis'
|
---|
97 | case 'EsaAnalysis'
|
---|
98 | case 'SealevelriseAnalysis'
|
---|
99 | otherwise
|
---|
100 | md = checkmessage(md,['md.toolkits.' analyses{i} ' not supported yet']);
|
---|
101 | end
|
---|
102 | if isempty(fieldnames(self.(analyses{i})))
|
---|
103 | md = checkmessage(md,['md.toolkits.' analyses{i} ' is empty']);
|
---|
104 | end
|
---|
105 | end
|
---|
106 | end % }}}
|
---|
107 | function ToolkitsFile(toolkits,filename) % {{{
|
---|
108 | %TOOLKITSFILE - build toolkits file
|
---|
109 | %
|
---|
110 | % Build a Petsc compatible options file, from the toolkits model field + return options string.
|
---|
111 | % This file will also be used when the toolkit used is 'issm' instead of 'petsc'
|
---|
112 | %
|
---|
113 | % Usage: ToolkitsFile(toolkits,filename);
|
---|
114 |
|
---|
115 | %open file for writing
|
---|
116 | fid=fopen(filename,'w');
|
---|
117 | if fid==-1,
|
---|
118 | error(['ToolkitsFile error: could not open ' filename ' for writing']);
|
---|
119 | end
|
---|
120 |
|
---|
121 | %write header
|
---|
122 | fprintf(fid,'%s%s%s\n','%Toolkits options file: ',filename,' written from Matlab toolkits array');
|
---|
123 |
|
---|
124 | %start writing options
|
---|
125 | analyses=properties(toolkits);
|
---|
126 | for i=1:numel(analyses),
|
---|
127 | analysis=analyses{i};
|
---|
128 | options=toolkits.(analysis);
|
---|
129 |
|
---|
130 | %first write analysis:
|
---|
131 | fprintf(fid,'\n+%s\n',analysis); %append a + to recognize it's an analysis enum
|
---|
132 |
|
---|
133 | %now, write options
|
---|
134 | optionslist=fieldnames(options);
|
---|
135 | for j=1:numel(optionslist),
|
---|
136 | optionname=optionslist{j};
|
---|
137 | optionvalue=options.(optionname);
|
---|
138 |
|
---|
139 | if isempty(optionvalue),
|
---|
140 | %this option has only one argument
|
---|
141 | fprintf(fid,'-%s\n',optionname);
|
---|
142 | else
|
---|
143 | %option with value. value can be string or scalar
|
---|
144 | if isnumeric(optionvalue),
|
---|
145 | fprintf(fid,'-%s %g\n',optionname,optionvalue);
|
---|
146 | elseif ischar(optionvalue),
|
---|
147 | fprintf(fid,'-%s %s\n',optionname,optionvalue);
|
---|
148 | else
|
---|
149 | error(['ToolkitsFile error: option ' optionname ' is not well formatted']);
|
---|
150 | end
|
---|
151 | end
|
---|
152 | end
|
---|
153 | end
|
---|
154 |
|
---|
155 | fclose(fid);
|
---|
156 | end %}}}
|
---|
157 | function savemodeljs(self,fid,modelname) % {{{
|
---|
158 |
|
---|
159 | analyses=properties(self);
|
---|
160 | for i=1:numel(analyses),
|
---|
161 | if isempty(fieldnames(self.(analyses{i})))
|
---|
162 | error(['md.toolkits.' analyses{i} ' is empty']);
|
---|
163 | else
|
---|
164 | writejsstruct(fid,[modelname '.toolkits.' analyses{i}],self.(analyses{i}));
|
---|
165 | end
|
---|
166 | end
|
---|
167 |
|
---|
168 | end % }}}
|
---|
169 | end
|
---|
170 | end
|
---|