Changeset 9564


Ignore:
Timestamp:
09/01/11 16:32:35 (14 years ago)
Author:
Mathieu Morlighem
Message:

made a class solver out of petscoptions

Location:
issm/trunk/src/m
Files:
5 deleted
3 edited
1 moved

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/classes/model/model.m

    r9563 r9564  
    88                 % {{{1
    99                 %Careful here: no other class should be used as default value this is a bug of matlab
    10                  %in what follows, any field is defined according to the following convention:
    11                  %field={defaultvalue,marshall?,data type,matrix type}
     10                 cluster = modelfield('default',0,'marshall',false);
     11                 verbose = modelfield('default',0,'marshall',true,'preprocess','marshallverbose','format','Integer');
     12                 results = modelfield('default',0,'marshall',false);
     13                 solver  = modelfield('default',0,'marshall',false);
     14
     15                 %FIXME: all other fields should belong to other classes
    1216
    1317                 %Model general information
     
    195199                 requested_outputs               = modelfield('default',NaN,'marshall',true,'format','DoubleMat','mattype',3);
    196200                 %Debugging
    197                  verbose                        = modelfield('default',0,'marshall',true,'preprocess','marshallverbose','format','Integer');
    198201                 mem_debug                      = modelfield('default',0,'marshall',false);
    199202                 gprof                          = modelfield('default',0,'marshall',false);
     
    201204                 output_frequency               = modelfield('default',0,'marshall',true,'format','Integer');
    202205                 results_on_vertices            = modelfield('default',0,'marshall',true,'format','Boolean');
    203                  results                        = modelfield('default',struct(),'marshall',false);
    204206                 vx                             = modelfield('default',NaN,'marshall',true,'format','DoubleMat','mattype',1);
    205207                 vy                             = modelfield('default',NaN,'marshall',true,'format','DoubleMat','mattype',1);
     
    223225                 
    224226                 %Parallelisation
    225                  cluster       = modelfield('default',NaN,'marshall',false);
    226227                 outlog        = modelfield('default','','marshall',false);
    227228                 errlog        = modelfield('default','','marshall',false);
     
    230231                 %dummy
    231232                 dummy = modelfield('default',NaN,'marshall',false);
    232 
    233                  %PETSc and MATLAB solver string
    234                  petscoptions  = modelfield('default',NaN,'marshall',false);
    235233
    236234                 %Analysis
     
    534532                         end
    535533
     534                         %initialize subclasses
     535                         md.cluster=none;
     536                         md.solver=solver;
     537                         md.solver=addoptions(md.solver,DiagnosticVertAnalysisEnum,mumpsoptions);
     538                         md.results=struct();
     539
     540
    536541                         %Materials parameters
    537542
     
    712717
    713718                         %cluster set as none for serial
    714                          md.cluster=none;
    715719
    716720                         %this option can be activated to load automatically the results
     
    727731                         md.hydro_kn=0;
    728732
    729                          %set petsc options for different analysis
    730                          md.petscoptions=petscoptions;
    731                          md.petscoptions=addoptions(md.petscoptions,DiagnosticVertAnalysisEnum,mumpsoptions);
    732733
    733734                         %Rheology law: what is the temperature dependence of B with T
  • issm/trunk/src/m/classes/solver.m

    r9530 r9564  
    1 %PETSCOPTIONS class definition
     1%SOLVER class definition
    22%
    33%   Usage:
    4 %      options=petscoptions();
     4%      obj=solver();
    55
    6 classdef petscoptions
     6classdef solver
    77    properties (SetAccess=public)
    8                  % {{{1
    98                 options={NoneAnalysisEnum,mumpsoptions};
    10                  %used when marshalling
    11                  %}}}
    129         end
    1310         methods
    14                  function disp(o) % {{{1
     11                 function disp(obj) % {{{1
    1512                         %  display the object
    1613                         disp(sprintf('class ''%s'' object ''%s'' = \n',class(o),inputname(1)));
    1714                         %  display the options
    18                          for i=1:size(o.options,1),
    19                                  analysis=o.options{i,1};
    20                                  ioptions=o.options{i,2};
    21                                  string=petscoptiontostring(ioptions);
     15                         for i=1:size(obj.options,1),
     16                                 analysis=obj.options{i,1};
     17                                 ioptions=obj.options{i,2};
     18                                 string=PetscString(ioptions);
    2219                                 disp(sprintf('   %s -> ''%s''',EnumToString(analysis),string));
    2320                         end
     
    2522                 end
    2623                 %}}}
    27                  function o=addoptions(o,analysis,solveroptions) % {{{1
     24                 function obj=addoptions(obj,analysis,solveroptions) % {{{1
    2825                         %first, find out if analysis has already been supplied
    29                          found=0;
    30                          for i=1:size(o.options,1),
    31                                  inanalysis=o.options{i,1};
     26                         found=false;
     27                         for i=1:size(obj.options,1),
     28                                 inanalysis=obj.options{i,1};
    3229                                 if inanalysis==analysis,
    33                                          found=1;
    34                                          o.options{i,1}=analysis;
    35                                          o.options{i,2}=solveroptions;
     30                                         found=true;
     31                                         obj.options{i,1}=analysis;
     32                                         obj.options{i,2}=solveroptions;
    3633                                         break;
    3734                                 end
    3835                         end
    3936                         if ~found,
    40                                  o.options{end+1,1}=analysis;
    41                                  o.options{end,2}=solveroptions;
     37                                 obj.options{end+1,1}=analysis;
     38                                 obj.options{end,2}=solveroptions;
    4239                         end
    4340                 end
    4441                 %}}}
    45         end
    46 end
     42                 function PetscFile(solver,filename) % {{{
     43                         %PETSCFILE - build petsc file
     44                         %
     45                         %   Build a Petsc compatible options file, from the solver model field  + return options string
     46                         %
     47                         %   Usage:     PetscFile(solver,filename);
     48
     49                         %open file for writing
     50                         fid=fopen(filename,'w');
     51                         if fid==-1,
     52                                 error(['PetscFile error: could not open ' filename ' for writing']);
     53                         end
     54
     55                         %write header
     56                         fprintf(fid,'%s%s%s\n','%Petsc options file: ',filename,' written from Matlab solver array');
     57
     58                         %start writing options
     59                         for i=1:size(solver.options,1),
     60                                 analysis=solver.options{i,1};
     61                                 options=solver.options{i,2};
     62
     63                                 %first write analysis:
     64                                 fprintf(fid,'\n+%s\n',EnumToString(analysis)); %append a + to recognize it's an analysis enum
     65
     66                                 %now, write options
     67                                 for j=1:size(options,2),
     68                                         option=options{j};
     69                                         if isempty(option),
     70                                                 %do nothing
     71                                         elseif length(option)==1,
     72                                                 %this option has only one argument
     73                                                 fprintf(fid,'-%s\n',option{1});
     74                                         elseif length(option)==2,
     75                                                 %option with value. value can be string or scalar
     76                                                 if isscalar(option{2}),
     77                                                         fprintf(fid,'-%s %g\n',option{1},option{2});
     78                                                 elseif ischar(option{2}),
     79                                                         fprintf(fid,'-%s %s\n',option{1},option{2});
     80                                                 else
     81                                                         error(['PetscFile error: option #' num2str(j) ' is not well formatted']);
     82                                                 end
     83                                         else
     84                                                 error(['PetscFile error: option #' num2str(j) ' is not well formatted']);
     85                                         end
     86                                 end
     87                         end
     88
     89                         fclose(fid);
     90                 end %}}}
     91                 function string=PetscString(solver) % {{{
     92
     93                         %initialize string:
     94                         string='';
     95
     96                         %start writing options
     97                         for i=1:length(solver),
     98                                 option=solver{i};
     99                                 if isempty(option),
     100                                         %do nothing
     101                                 elseif length(option)==1,
     102                                         %this option has only one argument
     103                                         string=[string ' -' option{1}];
     104                                 elseif length(option)==2,
     105                                         %option with value. value can be string or scalar
     106                                         if isscalar(option{2}),
     107                                                 string=[string ' -' option{1} ' ' num2str(option{2})];
     108                                         elseif ischar(option{2}),
     109                                                 string=[string ' -' option{1} ' ' option{2}];
     110                                         else
     111                                                 error(['PetscString error: option #' num2str(i) ' is not well formatted']);
     112                                         end
     113                                 else
     114                                         error(['PetscString error: option #' num2str(i) ' is not well formatted']);
     115                                 end
     116                         end
     117                 end % }}}
     118         end
     119 end
  • issm/trunk/src/m/model/display/displayparallel.m

    r6525 r9564  
    1414fielddisplay(md,'alloc_cleanup','allocation cleanup before starting a job, default 1');
    1515fielddisplay(md,'waitonlock','maximum number of minutes to wait for batch results, or return 0');
    16 disp('petsc options:');
    17 disp(md.petscoptions)
  • issm/trunk/src/m/model/solve.m

    r9561 r9564  
    6161
    6262%write a template file for issm to use, in parallel
    63 PetscOptions2PetscFile(md.petscoptions,[md.name '.petsc']);
     63PetscFile(md.solver,[md.name '.petsc']);
    6464
    6565%If running in parallel, we have a different way of launching the solution
Note: See TracChangeset for help on using the changeset viewer.