Changeset 11871


Ignore:
Timestamp:
04/03/12 10:11:50 (13 years ago)
Author:
Mathieu Morlighem
Message:

solver is now an object with dynamic properties, and each property is a struct with all the PETSc options

Location:
issm/trunk-jpl/src/m
Files:
9 edited

Legend:

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

    r11870 r11871  
    66classdef solver < dynamicprops
    77    properties (SetAccess=public)
    8                  NoneAnalysis
     8                 NoneAnalysis = struct();
    99                 %The other properties are dynamic
    1010         end
     
    1818                                 end
    1919                         end % }}}
    20                  function obj = setdefaultparameters(obj) % {{{
    21 
    22                          %MUMPS is the default solver
    23                          if ismumps,
    24                                  obj.NoneAnalysis=mumpsoptions;
    25                          else
    26                                  obj.NoneAnalysis=iluasmoptions;
    27                          end
    28 
    29                  end % }}}
    3020                 function obj = addoptions(obj,analysis,solveroptions) % {{{1
    3121
     
    4232                 end
    4333                 %}}}
     34                 function obj = setdefaultparameters(obj) % {{{
     35
     36                         %MUMPS is the default solver
     37                         if ismumps,
     38                                 obj.NoneAnalysis=mumpsoptions;
     39                         else
     40                                 obj.NoneAnalysis=iluasmoptions;
     41                         end
     42
     43                 end % }}}
     44                 function disp(obj) % {{{
     45                         analyses=properties(obj);
     46                         disp(sprintf('List of solver options per analysis:\n'));
     47                         for i=1:numel(analyses),
     48                                 analysis=analyses{i};
     49                                 disp([analysis ':']);
     50                                 disp(obj.(analysis));
     51                         end
     52                 end % }}}
    4453                 function checkconsistency(obj,md,solution,analyses) % {{{
    4554                         %Nothing checked
     
    7180
    7281                                 %now, write options
    73                                  for j=1:size(options,2),
    74                                          option=options{j};
    75                                          if isempty(option),
    76                                                  %do nothing
    77                                          elseif length(option)==1,
     82                                 optionslist=fieldnames(options);
     83                                 for j=1:numel(optionslist),
     84                                         optionname=optionslist{j};
     85                                         optionvalue=options.(optionname);
     86
     87                                         if isempty(optionvalue),
    7888                                                 %this option has only one argument
    79                                                  fprintf(fid,'-%s\n',option{1});
    80                                          elseif length(option)==2,
     89                                                 fprintf(fid,'-%s\n',optionname);
     90                                         else
    8191                                                 %option with value. value can be string or scalar
    82                                                  if isscalar(option{2}),
    83                                                          fprintf(fid,'-%s %g\n',option{1},option{2});
    84                                                  elseif ischar(option{2}),
    85                                                          fprintf(fid,'-%s %s\n',option{1},option{2});
     92                                                 if isscalar(optionvalue),
     93                                                         fprintf(fid,'-%s %g\n',optionname,optionvalue);
     94                                                 elseif ischar(optionvalue),
     95                                                         fprintf(fid,'-%s %s\n',optionname,optionvalue);
    8696                                                 else
    87                                                          error(['PetscFile error: option #' num2str(j) ' is not well formatted']);
     97                                                         error(['PetscFile error: option ' optionname ' is not well formatted']);
    8898                                                 end
    89                                          else
    90                                                  error(['PetscFile error: option #' num2str(j) ' is not well formatted']);
    9199                                         end
    92100                                 end
  • TabularUnified issm/trunk-jpl/src/m/model/solvers/asmoptions.m

    r6005 r11871  
    1 function options=asmoptions(varargin)
     1function asm=asmoptions(varargin)
    22%ASMOPTIONS - return Additive Shwartz Method petsc options
    33%
     
    66                         
    77%retrieve options provided in varargin
    8 arguments=pairoptions(varargin{:});
     8options=pairoptions(varargin{:});
     9asm=struct();
    910
    1011%default asm options
    11 options={{'mat_type','aij'},{'ksp_type','gmres'},{'pc_type','asm'},{'sub_pc_type','lu'},{'pc_asm_overlap',3},{'ksp_max_it',100},{'ksp_rtol',1e-30'}};
    12 
    13 %now, go through our arguments, and write over default options.
    14 for i=1:size(arguments.list,1),
    15         arg1=arguments.list{i,1};
    16         arg2=arguments.list{i,2};
    17         found=0;
    18         for j=1:size(options,2),
    19                 joption=options{j};
    20                 if strcmpi(joption{1},arg1),
    21                         joption{2}=arg2;
    22                         options{j}=joption;
    23                         found=1;
    24                         break;
    25                 end
    26         end
    27         if ~found,
    28                 %this option did not exist, add it:
    29                 options{end+1}={arg1,arg2};
    30         end
    31 end
     12asm.mat_type=getfieldvalue(options,'mat_type','aij');
     13asm.ksp_type=getfieldvalue(options,'ksp_type','gmres');
     14asm.pc_type=getfieldvalue(options,'pc_type','asm');
     15asm.sub_pc_type=getfieldvalue(options,'sub_pc_type','lu');
     16asm.pc_asm_overlap=getfieldvalue(options,'pc_asm_overlap',3);
     17asm.ksp_max_it=getfieldvalue(options,'ksp_max_it',100);
     18asm.ksp_rtol=getfieldvalue(options,'ksp_rtol',1e-30);
  • TabularUnified issm/trunk-jpl/src/m/model/solvers/iluasmoptions.m

    r6671 r11871  
    1 function options=iluasmoptions(varargin)
    2 %ASMOPTIONS - return Additive Shwartz Method with ILU preconditioner petsc options
     1function iluasm=iluasmoptions(varargin)
     2%ILUASMOPTIONS -
    33%
    44%   Usage:
     
    66                         
    77%retrieve options provided in varargin
    8 arguments=pairoptions(varargin{:});
     8options=pairoptions(varargin{:});
     9iluasm=struct();
    910
    1011%default iluasm options
    11 options={{'mat_type','aij'},{'ksp_type','gmres'},{'pc_type','asm'},{'sub_pc_type','ilu'},{'pc_asm_overlap',5},{'ksp_max_it',100},{'ksp_rtol',1e-15'}};
    12 
    13 %now, go through our arguments, and write over default options.
    14 for i=1:size(arguments.list,1),
    15         arg1=arguments.list{i,1};
    16         arg2=arguments.list{i,2};
    17         found=0;
    18         for j=1:size(options,2),
    19                 joption=options{j};
    20                 if strcmpi(joption{1},arg1),
    21                         joption{2}=arg2;
    22                         options{j}=joption;
    23                         found=1;
    24                         break;
    25                 end
    26         end
    27         if ~found,
    28                 %this option did not exist, add it:
    29                 options{end+1}={arg1,arg2};
    30         end
    31 end
     12iluasm.mat_type=getfieldvalue(options,'mat_type''','aij');
     13iluasm.ksp_type=getfieldvalue(options,'ksp_type''','gmres');
     14iluasm.pc_type=getfieldvalue(options,'pc_type''','asm');
     15iluasm.sub_pc_type=getfieldvalue(options,'sub_pc_type''','ilu');
     16iluasm.pc_asm_overlap=getfieldvalue(options,'pc_asm_overlap',5);
     17iluasm.ksp_max_it=getfieldvalue(options,'ksp_max_it',100);
     18iluasm.ksp_rtol=getfieldvalue(options,'ksp_rtol',1e-15);
  • TabularUnified issm/trunk-jpl/src/m/model/solvers/jacobiasmoptions.m

    r6098 r11871  
    1 function options=jacobiasmoptions(varargin)
     1function jacobiasm=jacobiasmoptions(varargin)
    22%ASMOPTIONS - return Additive Shwartz Method with Jacobi preconditioner petsc options
    33%
     
    66                         
    77%retrieve options provided in varargin
    8 arguments=pairoptions(varargin{:});
     8options=pairoptions(varargin{:});
     9jacobiasm=struct();
    910
    1011%default jacobiasm options
    11 options={{'mat_type','aij'},{'ksp_type','gmres'},{'pc_type','asm'},{'sub_pc_type','jacobi'},{'pc_asm_overlap',3},{'ksp_max_it',100},{'ksp_rtol',1e-15'}};
    12 
    13 %now, go through our arguments, and write over default options.
    14 for i=1:size(arguments.list,1),
    15         arg1=arguments.list{i,1};
    16         arg2=arguments.list{i,2};
    17         found=0;
    18         for j=1:size(options,2),
    19                 joption=options{j};
    20                 if strcmpi(joption{1},arg1),
    21                         joption{2}=arg2;
    22                         options{j}=joption;
    23                         found=1;
    24                         break;
    25                 end
    26         end
    27         if ~found,
    28                 %this option did not exist, add it:
    29                 options{end+1}={arg1,arg2};
    30         end
    31 end
     12jacobiasm.mat_type=getfieldvalue(options,'mat_type','aij');
     13jacobiasm.ksp_type=getfieldvalue(options,'ksp_type','gmres');
     14jacobiasm.pc_type=getfieldvalue(options,'pc_type','asm');
     15jacobiasm.sub_pc_type=getfieldvalue(options,'sub_pc_type','jacobi');
     16jacobiasm.pc_asm_overlap=getfieldvalue(options,'pc_asm_overlap',3);
     17jacobiasm.ksp_max_it=getfieldvalue(options,'ksp_max_it',100);
     18jacobiasm.ksp_rtol=getfieldvalue(options,'ksp_rtol',1e-15);
  • TabularUnified issm/trunk-jpl/src/m/model/solvers/jacobicgoptions.m

    r10565 r11871  
    1 function options=jacobiasmoptions(varargin)
     1function jacobicg=jacobiacgoptions(varargin)
    22%ASMOPTIONS - return Additive Shwartz Method with Jacobi preconditioner petsc options
    33%
     
    66                         
    77%retrieve options provided in varargin
    8 arguments=pairoptions(varargin{:});
     8options=pairoptions(varargin{:});
     9jacobicg=struct();
    910
    1011%default jacobiasm options
    11 options={{'mat_type','aij'},{'ksp_type','cg'},{'ksp_max_it',100},{'ksp_rtol',1e-15'}};
    12 
    13 %now, go through our arguments, and write over default options.
    14 for i=1:size(arguments.list,1),
    15         arg1=arguments.list{i,1};
    16         arg2=arguments.list{i,2};
    17         found=0;
    18         for j=1:size(options,2),
    19                 joption=options{j};
    20                 if strcmpi(joption{1},arg1),
    21                         joption{2}=arg2;
    22                         options{j}=joption;
    23                         found=1;
    24                         break;
    25                 end
    26         end
    27         if ~found,
    28                 %this option did not exist, add it:
    29                 options{end+1}={arg1,arg2};
    30         end
    31 end
     12jacobicg.mat_type=getfieldvalue(options,'mat_type','aij');
     13jacobicg.ksp_type=getfieldvalue(options,'ksp_type','cg');
     14jacobicg.ksp_max_it=getfieldvalue(options,'ksp_max_it',100);
     15jacobicg.ksp_rtol=getfieldvalue(options,'ksp_rtol',1e-15);
  • TabularUnified issm/trunk-jpl/src/m/model/solvers/matlaboptions.m

    r6014 r11871  
    1 function options=matlaboptions(varargin)
     1function maltab=matlaboptions(varargin)
    22%MATLABOPTIONS - return Matlab petsc options
    33%
     
    66                         
    77%retrieve options provided in varargin
    8 arguments=pairoptions(varargin{:});
     8options=pairoptions(varargin{:});
     9maltab=struct();
    910
    1011%default matlab options
    11 options={{'ksp_type','matlab'}};
    12 
    13 %now, go through our arguments, and write over default options.
    14 for i=1:size(arguments.list,1),
    15         arg1=arguments.list{i,1};
    16         arg2=arguments.list{i,2};
    17         found=0;
    18         for j=1:size(options,2),
    19                 joption=options{j};
    20                 if strcmpi(joption{1},arg1),
    21                         joption{2}=arg2;
    22                         options{j}=joption;
    23                         found=1;
    24                         break;
    25                 end
    26         end
    27         if ~found,
    28                 %this option did not exist, add it:
    29                 options{end+1}={arg1,arg2};
    30         end
    31 end
     12maltab.ksp_type='matlab';
  • TabularUnified issm/trunk-jpl/src/m/model/solvers/mumpsoptions.m

    r7046 r11871  
    1 function options=mumpsoptions(varargin)
     1function mumps=mumpsoptions(varargin)
    22%MUMPSOPTIONS - return MUMPS direct solver  petsc options
    33%
     
    66
    77%retrieve options provided in varargin
    8 arguments=pairoptions(varargin{:});
     8options=pairoptions(varargin{:});
     9mumps=struct();
    910
    1011%default mumps options
    1112PETSC_VERSION=petscversion();
    1213if PETSC_VERSION==2,
    13         options={{'mat_type','aijmumps'},{'ksp_type','preonly'},{'pc_type','lu'},{'mat_mumps_icntl_14',120},{'pc_factor_shift_positive_definite','true'}};
     14        mumps.mat_type=getfieldvalue(options,'mat_type','aijmumps');
     15        mumps.ksp_type=getfieldvalue(options,'ksp_type','preonly');
     16        mumps.pc_type=getfieldvalue(options,'pc_type','lu');
     17        mumps.mat_mumps_icntl_14=getfieldvalue(options,'mat_mumps_icntl_14',120);
     18        mumps.pc_factor_shift_positive_definite=getfieldvalue(options,'pc_factor_shift_positive_definite','true');
    1419end
    1520if PETSC_VERSION==3,
    16         options={{'mat_type','mpiaij'},{'ksp_type','preonly'},{'pc_type','lu'},{'pc_factor_mat_solver_package','mumps'},{'mat_mumps_icntl_14',120},{'pc_factor_shift_positive_definite','true'}};
    17 
     21        mumps.mat_type=getfieldvalue(options,'mat_type','mpiaij');
     22        mumps.ksp_type=getfieldvalue(options,'ksp_type','preonly');
     23        mumps.pc_type=getfieldvalue(options,'pc_type','lu');
     24        mumps.pc_factor_mat_solver_package=getfieldvalue(options,'pc_factor_mat_solver_package','mumps');
     25        mumps.mat_mumps_icntl_14=getfieldvalue(options,'mat_mumps_icntl_14',120);
     26        mumps.pc_factor_shift_positive_definite=getfieldvalue(options,'pc_factor_shift_positive_definite','true');
    1827end
    19 
    20 %now, go through our arguments, and write over default options.
    21 for i=1:size(arguments.list,1),
    22         arg1=arguments.list{i,1};
    23         arg2=arguments.list{i,2};
    24         found=0;
    25         for j=1:size(options,2),
    26                 joption=options{j};
    27                 if strcmpi(joption{1},arg1),
    28                         joption{2}=arg2;
    29                         options{j}=joption;
    30                         found=1;
    31                         break;
    32                 end
    33         end
    34         if ~found,
    35                 %this option did not exist, add it:
    36                 options{end+1}={arg1,arg2};
    37         end
    38 end
  • TabularUnified issm/trunk-jpl/src/m/model/solvers/soroptions.m

    r6014 r11871  
    1 function options=soroptions(varargin)
     1function sor=soroptions(varargin)
    22%SOROPTIONS - return Relaxation Solver petsc options
    33%
     
    66                         
    77%retrieve options provided in varargin
    8 arguments=pairoptions(varargin{:});
     8options=pairoptions(varargin{:});
     9sor=struct();
    910
    1011%default sor options
    11 options={{'mat_type','aij'},{'ksp_type','cg'},{'pc_type','sor'},{'pc_sor_omega',1.1},{'pc_sor_its',2}};
    12 
    13 %now, go through our arguments, and write over default options.
    14 for i=1:size(arguments.list,1),
    15         arg1=arguments.list{i,1};
    16         arg2=arguments.list{i,2};
    17         found=0;
    18         for j=1:size(options,2),
    19                 joption=options{j};
    20                 if strcmpi(joption{1},arg1),
    21                         joption{2}=arg2;
    22                         options{j}=joption;
    23                         found=1;
    24                         break;
    25                 end
    26         end
    27         if ~found,
    28                 %this option did not exist, add it:
    29                 options{end+1}={arg1,arg2};
    30         end
    31 end
     12sor.mat_type=getfieldvalue(options,'mat_type','aij');
     13sor.ksp_type=getfieldvalue(options,'ksp_type','cg');
     14sor.pc_type=getfieldvalue(options,'pc_type','sor');
     15sor.pc_sor_omega=getfieldvalue(options,'pc_sor_omega',1.1);
     16sor.pc_sor_its=getfieldvalue(options,'pc_sor_its',2);
  • TabularUnified issm/trunk-jpl/src/m/model/solvers/stokesoptions.m

    r8110 r11871  
    1 function options=stokesoptions(varargin)
     1function stokes=stokesoptions(varargin)
    22%STOKESOPTIONS - return STOKES multi-physics solver petsc options
    33%
     
    77%retrieve options provided in varargin
    88arguments=pairoptions(varargin{:});
     9stokes=struct();
    910
    1011%default stokes options
     
    1415end
    1516if PETSC_VERSION==3,
    16         options={{'mat_type','mpiaij'},{'ksp_max_it',1000},{'ksp_type','gmres'},{'pc_type','fieldsplit'},{'pc_field_split_type','schur'},...
    17         {'fieldsplit_0_pc_type','hypre'},{'fieldsplit_0_ksp_type','gmres'},{'fieldsplit_0_pc_hypre_type','boomerang'},...
    18         {'fieldsplit_1_pc_type','jacobi'},{'fieldsplit_1_ksp_type','preonly'},{'issm_option_solver','stokes'}};
     17        stokes.mat_type=getfieldvalue(options,'mat_type','mpiaij');
     18        stokes.ksp_max_it=getfieldvalue(options,'ksp_max_it',1000);
     19        stokes.ksp_type=getfieldvalue(options,'ksp_type','gmres');
     20        stokes.pc_type=getfieldvalue(options,'pc_type','fieldsplit');
     21        stokes.pc_field_split_type=getfieldvalue(options,'pc_field_split_type','schur');
     22        stokes.fieldsplit_0_pc_type=getfieldvalue(options,'fieldsplit_0_pc_type','hypre');
     23        stokes.fieldsplit_0_ksp_type=getfieldvalue(options,'fieldsplit_0_ksp_type','gmres');
     24        stokes.fieldsplit_0_pc_hypre_type=getfieldvalue(options,'fieldsplit_0_pc_hypre_type','boomerang');
     25        stokes.fieldsplit_1_pc_type=getfieldvalue(options,'fieldsplit_1_pc_type','jacobi');
     26        stokes.fieldsplit_1_ksp_type=getfieldvalue(options,'fieldsplit_1_ksp_type','preonly');
     27        stokes.issm_option_solver=getfieldvalue(options,'issm_option_solver','stokes');
    1928end
    20 
    21 %now, go through our arguments, and write over default options.
    22 for i=1:size(arguments.list,1),
    23         arg1=arguments.list{i,1};
    24         arg2=arguments.list{i,2};
    25         found=0;
    26         for j=1:size(options,2),
    27                 joption=options{j};
    28                 if strcmpi(joption{1},arg1),
    29                         joption{2}=arg2;
    30                         options{j}=joption;
    31                         found=1;
    32                         break;
    33                 end
    34         end
    35         if ~found,
    36                 %this option did not exist, add it:
    37                 options{end+1}={arg1,arg2};
    38         end
    39 end
Note: See TracChangeset for help on using the changeset viewer.