From 07df48225553adc441aa68d65a518b145b80a7f5 Mon Sep 17 00:00:00 2001 From: Dominic Steinitz Date: Wed, 14 Mar 2018 06:53:36 +0000 Subject: The full almost entirely C example tidied --- packages/sundials/src/helpers.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'packages/sundials/src/helpers.c') diff --git a/packages/sundials/src/helpers.c b/packages/sundials/src/helpers.c index 3e1a9a8..d51310c 100644 --- a/packages/sundials/src/helpers.c +++ b/packages/sundials/src/helpers.c @@ -69,3 +69,26 @@ int Jac(realtype t, N_Vector y, N_Vector fy, SUNMatrix J, return 0; /* return with success */ } + + +/* check the computed solution */ +int check_ans(N_Vector y, realtype t, realtype rtol, realtype atol) +{ + int passfail=0; /* answer pass (0) or fail (1) flag */ + realtype ans, err, ewt; /* answer data, error, and error weight */ + realtype ONE=RCONST(1.0); + + /* compute solution error */ + ans = atan(t); + ewt = ONE / (rtol * SUNRabs(ans) + atol); + err = ewt * SUNRabs(NV_Ith_S(y,0) - ans); + + /* is the solution within the tolerances? */ + passfail = (err < ONE) ? 0 : 1; + + if (passfail) { + fprintf(stdout, "\nSUNDIALS_WARNING: check_ans error=%g \n\n", err); + } + + return(passfail); +} -- cgit v1.2.3