octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Refactoring input check for ode solvers


From: Francesco Faccio
Subject: Refactoring input check for ode solvers
Date: Tue, 2 Aug 2016 19:08:13 +0000

Dear all,

I would like to share with you a new design for input check of ode solvers before implementing it.

This is neccessary to:


- achieve more Matlab compatibility: in Matlab writing odeset ('Jacobian', 'foo') is allowed because the check of options is done inside the solver, while in Octave an error message is printed from the private function ode_struct_value_check.

- have a more elegant handling of errors and default values in standard and special fields of odeset with validateattributes, saving typing.

This will be the structure of any ode solver odexy:

function [varargout] = odexy (fun, t, init, useroptions)
 
  persistent defaults = [];
 
  if (isempty (defaults))
  
    [defaults, classes, attributes] = odedefaults ();
    defaults = odeset (defaults, 'specialfield', defaultvalue, ...);
    classes  = odeset (classes, 'specialfield', {'specialfieldclass1',
                       'specialfieldclass2'}, ...);
    attributes = odeset (classes, 'attributes', {'specialfieldattr1',
                         'specialfieldattr2'}, ...);
  endif
 
  options = odemergeopts (useroptions, defaults, classes, attributes, 'odexy');
 
 
### solve
 
   
endfunction
 
function options = odemergeopts  (useroptions, options, classes,
                                  attributes, fun_name);
  for [value, key] = options;
    if (isfield (useroptions, key)
        && ! isempty (useroptions.(key)))
 
      validateattributes (options.(key), classes.(key),
                          attributes.(key), fun_name, key);
       
      options.(key) = useroptions.(key);
 
    endif
  endfor
endfunction


where function odedefaults is a private function which sets for each field of the option struct of a generic solver its default value and sets which classes and attributes will be tested in validateattributes.

After a call to odedefaults, the developer can modify (through odeset) default values for the specific solver and add new fields to the structure with their classes and attributes to be tested.

Finally, inside private function odemergeopts, the option struct provided by the user is tested and merged with the default struct.


I'm going to write these two private functions and test the code on ode23 and ode45, before ode15i.

Cheers,

Francesco


reply via email to

[Prev in Thread] Current Thread [Next in Thread]