[14621] | 1 | %TOOLKITS class definition
|
---|
| 2 | %
|
---|
| 3 | % Usage:
|
---|
| 4 | % obj=toolkits();
|
---|
| 5 |
|
---|
| 6 | classdef 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:
|
---|
| 24 | % md.toolkits=addoptions(md.toolkits,DiagnosticHorizAnalysisEnum(),stokesoptions());
|
---|
| 25 | % md.toolkits=addoptions(md.toolkits,DiagnosticHorizAnalysisEnum());
|
---|
| 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:
|
---|
| 42 | if ispetsc,
|
---|
| 43 | %MUMPS is the default toolkits
|
---|
| 44 | if ismumps(),
|
---|
| 45 | obj.DefaultAnalysis = mumpsoptions();
|
---|
| 46 | else
|
---|
| 47 | obj.DefaultAnalysis = iluasmoptions();
|
---|
| 48 | end
|
---|
[14621] | 49 | else
|
---|
[14881] | 50 | obj.DefaultAnalysis = issmsolver();
|
---|
[14621] | 51 | end
|
---|
| 52 |
|
---|
| 53 | end % }}}
|
---|
| 54 | function disp(obj) % {{{
|
---|
| 55 | analyses=properties(obj);
|
---|
| 56 | disp(sprintf('List of toolkits options per analysis:\n'));
|
---|
| 57 | for i=1:numel(analyses),
|
---|
| 58 | analysis=analyses{i};
|
---|
| 59 | disp([analysis ':']);
|
---|
| 60 | disp(obj.(analysis));
|
---|
| 61 | end
|
---|
| 62 | end % }}}
|
---|
| 63 | function md = checkconsistency(obj,md,solution,analyses) % {{{
|
---|
| 64 | analyses=properties(obj);
|
---|
| 65 | for i=1:numel(analyses),
|
---|
| 66 | if isempty(fieldnames(obj.(analyses{i})))
|
---|
| 67 | md = checkmessage(md,['md.toolkits.' analyses{i} ' is empty']);
|
---|
| 68 | end
|
---|
| 69 | end
|
---|
| 70 | end % }}}
|
---|
| 71 | function ToolkitsFile(toolkits,filename) % {{{
|
---|
[14623] | 72 | %TOOLKITSFILE - build toolkits file
|
---|
[14621] | 73 | %
|
---|
| 74 | % Build a Petsc compatible options file, from the toolkits model field + return options string.
|
---|
| 75 | % This file will also be used when the toolkit used is 'issm' instead of 'petsc'
|
---|
| 76 | %
|
---|
| 77 | % Usage: ToolkitsFile(toolkits,filename);
|
---|
| 78 |
|
---|
| 79 | %open file for writing
|
---|
| 80 | fid=fopen(filename,'w');
|
---|
| 81 | if fid==-1,
|
---|
| 82 | error(['ToolkitsFile error: could not open ' filename ' for writing']);
|
---|
| 83 | end
|
---|
| 84 |
|
---|
| 85 | %write header
|
---|
| 86 | fprintf(fid,'%s%s%s\n','%Toolkits options file: ',filename,' written from Matlab toolkits array');
|
---|
| 87 |
|
---|
| 88 | %start writing options
|
---|
| 89 | analyses=properties(toolkits);
|
---|
| 90 | for i=1:numel(analyses),
|
---|
| 91 | analysis=analyses{i};
|
---|
| 92 | options=toolkits.(analysis);
|
---|
| 93 |
|
---|
| 94 | %first write analysis:
|
---|
| 95 | fprintf(fid,'\n+%s\n',analysis); %append a + to recognize it's an analysis enum
|
---|
| 96 |
|
---|
| 97 | %now, write options
|
---|
| 98 | optionslist=fieldnames(options);
|
---|
| 99 | for j=1:numel(optionslist),
|
---|
| 100 | optionname=optionslist{j};
|
---|
| 101 | optionvalue=options.(optionname);
|
---|
| 102 |
|
---|
| 103 | if isempty(optionvalue),
|
---|
| 104 | %this option has only one argument
|
---|
| 105 | fprintf(fid,'-%s\n',optionname);
|
---|
| 106 | else
|
---|
| 107 | %option with value. value can be string or scalar
|
---|
| 108 | if isnumeric(optionvalue),
|
---|
| 109 | fprintf(fid,'-%s %g\n',optionname,optionvalue);
|
---|
| 110 | elseif ischar(optionvalue),
|
---|
| 111 | fprintf(fid,'-%s %s\n',optionname,optionvalue);
|
---|
| 112 | else
|
---|
| 113 | error(['ToolkitsFile error: option ' optionname ' is not well formatted']);
|
---|
| 114 | end
|
---|
| 115 | end
|
---|
| 116 | end
|
---|
| 117 | end
|
---|
| 118 |
|
---|
| 119 | fclose(fid);
|
---|
| 120 | end %}}}
|
---|
| 121 | end
|
---|
| 122 | end
|
---|