source: issm/trunk/src/m/classes/toolkits.m@ 26744

Last change on this file since 26744 was 26744, checked in by Mathieu Morlighem, 3 years ago

merged trunk-jpl and trunk for revision 26742

File size: 5.1 KB
Line 
1%TOOLKITS class definition
2%
3% Usage:
4% self=toolkits();
5
6classdef 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 %ADDOPTIONS - add analysis to md.toolkits.analysis
36 %
37 % Optional third parameter adds toolkits options to analysis.
38 %
39 % Usage:
40 % md.toolkits=addoptions(md.toolkits,'StressbalanceAnalysis',FSoptions());
41 % md.toolkits=addoptions(md.toolkits,'StressbalanceAnalysis');
42
43 %Create dynamic property if property does not exist yet
44 if ~ismember(analysis,properties(self)),
45 self.addprop(analysis);
46 end
47
48 %Add toolkits options to analysis
49 if nargin==3,
50 self.(analysis) = varargin{1};
51 end
52 end
53 %}}}
54 function self = setdefaultparameters(self) % {{{
55
56 %default toolkits:
57 if IssmConfig('_HAVE_PETSC_'),
58 %MUMPS is the default toolkits
59 if IssmConfig('_HAVE_MUMPS_'),
60 self.DefaultAnalysis = mumpsoptions();
61 else
62 self.DefaultAnalysis = iluasmoptions();
63 end
64 else
65 if IssmConfig('_HAVE_MUMPS_'),
66 self.DefaultAnalysis = issmmumpssolver();
67 elseif IssmConfig('_HAVE_GSL_'),
68 self.DefaultAnalysis = issmgslsolver();
69 else
70 disp('WARNING: Need at least Mumps or Gsl to define an issm solver type, no default solver assigned');
71 end
72 end
73
74 %Use same solver for Recovery mode
75 self.RecoveryAnalysis = self.DefaultAnalysis;
76
77
78 end % }}}
79 function disp(self) % {{{
80 analyses=properties(self);
81 disp(sprintf('List of toolkits options per analysis:\n'));
82 for i=1:numel(analyses),
83 analysis=analyses{i};
84 disp([analysis ':']);
85 disp(self.(analysis));
86 end
87 end % }}}
88 function md = checkconsistency(self,md,solution,analyses) % {{{
89 analyses=properties(self);
90 for i=1:numel(analyses),
91 switch analyses{i}
92 case 'DefaultAnalysis'
93 case 'RecoveryAnalysis'
94 case 'StressbalanceAnalysis'
95 case 'GLheightadvectionAnalysis'
96 case 'MasstransportAnalysis'
97 case 'ThermalAnalysis'
98 case 'EnthalpyAnalysis'
99 case 'AdjointBalancethicknessAnalysis'
100 case 'BalancethicknessAnalysis'
101 case 'Balancethickness2Analysis'
102 case 'BalancethicknessSoftAnalysis'
103 case 'BalancevelocityAnalysis'
104 case 'DamageEvolutionAnalysis'
105 case 'LoveAnalysis'
106 case 'EsaAnalysis'
107 case 'SealevelchangeAnalysis'
108 otherwise
109 md = checkmessage(md,['md.toolkits.' analyses{i} ' not supported yet']);
110 end
111 if isempty(fieldnames(self.(analyses{i})))
112 md = checkmessage(md,['md.toolkits.' analyses{i} ' is empty']);
113 end
114 end
115 end % }}}
116 function ToolkitsFile(toolkits,filename) % {{{
117 %TOOLKITSFILE - build toolkits file
118 %
119 % Build a Petsc compatible options file, from the toolkits model field + return options string.
120 % This file will also be used when the toolkit used is 'issm' instead of 'petsc'
121 %
122 % Usage: ToolkitsFile(toolkits,filename);
123
124 %open file for writing
125 fid=fopen(filename,'w');
126 if fid==-1,
127 error(['ToolkitsFile error: could not open ' filename ' for writing']);
128 end
129
130 %write header
131 fprintf(fid,'%s%s%s\n','%Toolkits options file: ',filename,' written from Matlab toolkits array');
132
133 %start writing options
134 analyses=properties(toolkits);
135 for i=1:numel(analyses),
136 analysis=analyses{i};
137 options=toolkits.(analysis);
138
139 %first write analysis:
140 fprintf(fid,'\n+%s\n',analysis); %append a + to recognize it's an analysis enum
141
142 %now, write options
143 optionslist=fieldnames(options);
144 for j=1:numel(optionslist),
145 optionname=optionslist{j};
146 optionvalue=options.(optionname);
147
148 if isempty(optionvalue),
149 %this option has only one argument
150 fprintf(fid,'-%s\n',optionname);
151 else
152 %option with value. value can be string or scalar
153 if isnumeric(optionvalue),
154 fprintf(fid,'-%s %g\n',optionname,optionvalue);
155 elseif ischar(optionvalue),
156 fprintf(fid,'-%s %s\n',optionname,optionvalue);
157 else
158 error(['ToolkitsFile error: option ' optionname ' is not well formatted']);
159 end
160 end
161 end
162 end
163
164 fclose(fid);
165 end %}}}
166 function savemodeljs(self,fid,modelname) % {{{
167
168 analyses=properties(self);
169 for i=1:numel(analyses),
170 if isempty(fieldnames(self.(analyses{i})))
171 error(['md.toolkits.' analyses{i} ' is empty']);
172 else
173 writejsstruct(fid,[modelname '.toolkits.' analyses{i}],self.(analyses{i}));
174 end
175 end
176
177 end % }}}
178 end
179 end
Note: See TracBrowser for help on using the repository browser.