CHECKSOLVEROPTIONS - standardize simulation options appended to params.mat Use this to achieve consistent params.mat whether created by dsSimulate(), dsWriteDynaSimSolver(), or dsWriteMatlabSolver(). Author: Jason Sherfey, PhD <jssherfey@gmail.com> Copyright (C) 2016 Jason Sherfey, Boston University, USA
0001 function options = dsCheckSolverOptions(options) 0002 %CHECKSOLVEROPTIONS - standardize simulation options appended to params.mat 0003 % 0004 % Use this to achieve consistent params.mat whether created by dsSimulate(), 0005 % dsWriteDynaSimSolver(), or dsWriteMatlabSolver(). 0006 % 0007 % Author: Jason Sherfey, PhD <jssherfey@gmail.com> 0008 % Copyright (C) 2016 Jason Sherfey, Boston University, USA 0009 0010 % standardize and set defaults 0011 keyvals = dsOptions2Keyval(options); 0012 options=dsCheckOptions(keyvals,{... 0013 'tspan',[0 100],[],... % [beg,end] (units must be consistent with dt and equations) 0014 'downsample_factor',1,[],... % downsampling applied during simulation (only every downsample_factor-time point is stored in memory or written to disk) 0015 'random_seed','shuffle',[],... % seed for random number generator (usage: rng(random_seed)) 0016 'solver','rk4',[],... % DynaSim and built-in Matlab solvers 0017 'disk_flag',0,[],... % whether to write to disk during simulation instead of storing in memory 0018 'dt',.01,[],... % time step used for fixed step DynaSim solvers 0019 'datafile','data.csv',[],... % name of data file if disk_flag=1 0020 'compile_flag',exist('codegen','file')==6,[],... % whether to prepare script for being compiled using coder instead of interpreting Matlab 0021 'verbose_flag',1,[],... 0022 'matlab_solver_options',[],[],... 0023 },false); 0024 0025 field_order={'tspan','downsample_factor','random_seed','solver','disk_flag',... 0026 'dt','datafile','compile_flag','verbose_flag','matlab_solver_options'}; 0027 0028 if options.compile_flag==1 0029 % <-- copied from dsWriteDynaSimSolver.m --> 0030 % todo: make seed string (eg, 'shuffle') from param struct work with coder (options.compile_flag=1) 0031 % (currently raises error: "String input must be constant") 0032 % workaround: (shuffle here and get numeric seed for MEX-compatible params.mat) 0033 rng_wrapper(options.random_seed); 0034 options.random_seed=getfield(rng_wrapper,'Seed'); 0035 end 0036 0037 % standardize field order 0038 options=orderfields(options,field_order); 0039 0040 % Remove matlab_solver_options if empty 0041 if isempty(options.matlab_solver_options) 0042 options = rmfield(options, 'matlab_solver_options'); 0043 end