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

Last change on this file since 16560 was 16560, checked in by Mathieu Morlighem, 11 years ago

merged trunk-jpl and trunk for revision 16554

File size: 3.7 KB
RevLine 
[14621]1%TOOLKITS class definition
2%
3% Usage:
4% obj=toolkits();
5
6classdef toolkits < dynamicprops
7 properties (SetAccess=public)
[14689]8 DefaultAnalysis = struct();
[14621]9 %The other properties are dynamic
10 end
11 methods
12 function obj = toolkits(varargin) % {{{
13 switch nargin
14 case 0
15 obj=setdefaultparameters(obj);
16 case 1
17 obj=structtoobj(obj,varargin{1});
18 otherwise
19 error('constructor not supported');
20 end
21 end % }}}
22 function obj = addoptions(obj,analysis,varargin) % {{{
23 % Usage example:
[16137]24 % md.toolkits=addoptions(md.toolkits,StressbalanceAnalysisEnum(),FSoptions());
25 % md.toolkits=addoptions(md.toolkits,StressbalanceAnalysisEnum());
[14621]26
27 %Convert analysis from enum to string
28 analysis=EnumToString(analysis);
29
30 %Create dynamic property if property does not exist yet
31 if ~ismember(analysis,properties(obj)),
32 obj.addprop(analysis);
33 end
34
35 %Add toolkits options to analysis
36 if nargin==3, obj.(analysis) = varargin{1}; end
37 end
38 %}}}
39 function obj = setdefaultparameters(obj) % {{{
40
[14881]41 %default toolkits:
[16137]42 if IssmConfig('_HAVE_PETSC_'),
[14881]43 %MUMPS is the default toolkits
[16137]44 if IssmConfig('_HAVE_MUMPS_'),
[14881]45 obj.DefaultAnalysis = mumpsoptions();
46 else
47 obj.DefaultAnalysis = iluasmoptions();
48 end
[14621]49 else
[16560]50 if IssmConfig('_HAVE_MUMPS_'),
51 obj.DefaultAnalysis = issmmumpssolver();
52 elseif IssmConfig('_HAVE_GSL_'),
53 obj.DefaultAnalysis = issmgslsolver();
54 else
55 error('Need at least Mumps or Gsl to define an issm solver type');
56 end
[14621]57 end
58
59 end % }}}
60 function disp(obj) % {{{
61 analyses=properties(obj);
62 disp(sprintf('List of toolkits options per analysis:\n'));
63 for i=1:numel(analyses),
64 analysis=analyses{i};
65 disp([analysis ':']);
66 disp(obj.(analysis));
67 end
68 end % }}}
69 function md = checkconsistency(obj,md,solution,analyses) % {{{
70 analyses=properties(obj);
71 for i=1:numel(analyses),
72 if isempty(fieldnames(obj.(analyses{i})))
73 md = checkmessage(md,['md.toolkits.' analyses{i} ' is empty']);
74 end
75 end
76 end % }}}
77 function ToolkitsFile(toolkits,filename) % {{{
[14623]78 %TOOLKITSFILE - build toolkits file
[14621]79 %
80 % Build a Petsc compatible options file, from the toolkits model field + return options string.
81 % This file will also be used when the toolkit used is 'issm' instead of 'petsc'
82 %
83 % Usage: ToolkitsFile(toolkits,filename);
84
85 %open file for writing
86 fid=fopen(filename,'w');
87 if fid==-1,
88 error(['ToolkitsFile error: could not open ' filename ' for writing']);
89 end
90
91 %write header
92 fprintf(fid,'%s%s%s\n','%Toolkits options file: ',filename,' written from Matlab toolkits array');
93
94 %start writing options
95 analyses=properties(toolkits);
96 for i=1:numel(analyses),
97 analysis=analyses{i};
98 options=toolkits.(analysis);
99
100 %first write analysis:
101 fprintf(fid,'\n+%s\n',analysis); %append a + to recognize it's an analysis enum
102
103 %now, write options
104 optionslist=fieldnames(options);
105 for j=1:numel(optionslist),
106 optionname=optionslist{j};
107 optionvalue=options.(optionname);
108
109 if isempty(optionvalue),
110 %this option has only one argument
111 fprintf(fid,'-%s\n',optionname);
112 else
113 %option with value. value can be string or scalar
114 if isnumeric(optionvalue),
115 fprintf(fid,'-%s %g\n',optionname,optionvalue);
116 elseif ischar(optionvalue),
117 fprintf(fid,'-%s %s\n',optionname,optionvalue);
118 else
119 error(['ToolkitsFile error: option ' optionname ' is not well formatted']);
120 end
121 end
122 end
123 end
124
125 fclose(fid);
126 end %}}}
127 end
128 end
Note: See TracBrowser for help on using the repository browser.