Changeset 11870


Ignore:
Timestamp:
04/03/12 09:32:59 (13 years ago)
Author:
Mathieu Morlighem
Message:

Analyses are now dynamic properties of solver

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/solver.m

    r11869 r11870  
    44%      obj=solver();
    55
    6 classdef solver
     6classdef solver < dynamicprops
    77    properties (SetAccess=public)
    8                  options=cell(0,0);
     8                 NoneAnalysis
     9                 %The other properties are dynamic
    910         end
    1011         methods
     
    2122                         %MUMPS is the default solver
    2223                         if ismumps,
    23                                  obj.options={'NoneAnalysis',mumpsoptions};
     24                                 obj.NoneAnalysis=mumpsoptions;
    2425                         else
    25                                  obj.options={'NoneAnalysis',iluasmoptions};
     26                                 obj.NoneAnalysis=iluasmoptions;
    2627                         end
    2728
     
    3233                         analysis=EnumToString(analysis);
    3334
    34                          %first, find out if analysis has already been supplied
    35                          found=false;
    36                          for i=1:size(obj.options,1),
    37                                  inanalysis=obj.options{i,1};
    38                                  if strcmp(inanalysis,analysis),
    39                                          found=true;
    40                                          obj.options{i,1} = analysis;
    41                                          obj.options{i,2} = solveroptions;
    42                                          break;
    43                                  end
     35                         %Create dynamic property if property does not exist yet
     36                         if ~ismember(analysis,properties(obj)),
     37                                 obj.addprop(analysis);
    4438                         end
    4539
    46                          if ~found,
    47                                  obj.options{end+1,1}= analysis;
    48                                  obj.options{end,2}  = solveroptions;
    49                          end
     40                         %Add solver options to analysis
     41                         obj.(analysis) = solveroptions;
    5042                 end
    5143                 %}}}
    5244                 function checkconsistency(obj,md,solution,analyses) % {{{
    53                          for i=1:size(obj.options,1),
    54                                  if ~ischar(obj.options{i,1}),
    55                                          checkmessage('solver is not well formatted: Analyses are not strings');
    56                                  end
    57                          end
     45                         %Nothing checked
    5846                 end % }}}
    5947                 function PetscFile(solver,filename) % {{{
    60                         %PETSCFILE - build petsc file
    61                         %
    62                         %   Build a Petsc compatible options file, from the solver model field  + return options string
    63                         %
    64                         %   Usage:     PetscFile(solver,filename);
     48                %PETSCFILE - build petsc file
     49                %
     50                %   Build a Petsc compatible options file, from the solver model field  + return options string
     51                %
     52                %   Usage:     PetscFile(solver,filename);
    6553
    6654                         %open file for writing
     
    7462
    7563                         %start writing options
    76                          for i=1:size(solver.options,1),
    77                                  analysis=solver.options{i,1};
    78                                  options=solver.options{i,2};
     64                         analyses=properties(solver);
     65                         for i=1:numel(analyses),
     66                                 analysis=analyses{i};
     67                                 options=solver.(analysis);
    7968
    8069                                 %first write analysis:
     
    10695                         fclose(fid);
    10796                 end %}}}
    108                  function disp(obj) % {{{1
    109                         disp(sprintf('   solver parameters:'));
    110 
    111                         for i=1:size(obj.options,1),
    112                                 analysis=obj.options{i,1};
    113                                 ioptions=obj.options{i,2};
    114 
    115                                 string='';
    116                                 for i=1:length(ioptions),
    117                                         option=ioptions{i};
    118                                         if isempty(option),
    119                                                 %do nothing
    120                                         elseif length(option)==1,
    121                                                 %this option has only one argument
    122                                                 string=[string ' -' option{1}];
    123                                         elseif length(option)==2,
    124                                                 %option with value. value can be string or scalar
    125                                                 if isscalar(option{2}),
    126                                                         string=[string ' -' option{1} ' ' num2str(option{2})];
    127                                                 elseif ischar(option{2}),
    128                                                         string=[string ' -' option{1} ' ' option{2}];
    129                                                 else
    130                                                         error(['PetscString error: option #' num2str(i) ' is not well formatted']);
    131                                                 end
    132                                         else
    133                                                 error(['PetscString error: option #' num2str(i) ' is not well formatted']);
    134                                         end
    135                                 end
    136 
    137                                 disp(sprintf('   %s -> ''%s''',analysis,string));
    138                         end
    139                  end
    140                  %}}}
    14197         end
    14298 end
Note: See TracChangeset for help on using the changeset viewer.