Mercurial > repos > public > sbplib
changeset 616:818d52d4928f feature/grids
Add helper function for convergence runs on discretizations
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 11 Oct 2017 16:01:22 +0200 |
parents | 68f9c16569fa |
children | 4ced7d47bd1f |
files | +noname/calculateErrors.m |
diffstat | 1 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/+noname/calculateErrors.m Wed Oct 11 16:01:22 2017 +0200 @@ -0,0 +1,40 @@ +% [discr, trueSolution] = schemeFactory(m) +% where trueSolution should be a timeSnapshot of the true solution a time T +% T is the end time +% m are grid size parameters. +% N are number of timesteps to use for each gird size +% timeOpt are options for the timeStepper +function e = calculateErrors(schemeFactory, T, m, N, errorFun, timeOpt) + assertType(schemeFactory, 'function_handle'); + assertNumberOfArguments(schemeFactory, 1); + assertScalar(T); + assert(length(m) == length(N), 'Vectors m and N must have the same length'); + assertType(errorFun, 'function_handle'); + assertNumberOfArguments(errorFun, 2); + default_arg('timeOpt'); + + e = []; + for i = 1:length(m) + done = timeTask('m = %3d ', m(i)); + + [discr, trueSolution] = schemeFactory(m(i)); + + timeOpt.k = T/N(i); + ts = discr.getTimestepper(timeOpt); + ts.stepTo(N(i), true); + approxSolution = discr.getTimeSnapshot(ts); + + e(i) = errorFun(trueSolution, approxSolution); + + fprintf('e = %.4e', e(i)) + done() + end + fprintf('\n') +end + + +%% Example error function +% u_true = grid.evalOn(dr.grid, @(x,y)trueSolution(T,x,y)); +% err = u_true-u_false; +% e(i) = norm(err)/norm(u_true); +% % e(i) = sqrt(err'*d.H*d.J*err/(u_true'*d.H*d.J*u_true));