commit fb1c12d777941290f1e819e23698a928f2cb3451
parent 389749abaad9bc4a007c0a11beb89452499bb331
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 13 Mar 2024 17:07:10 +0100
Plot the error on the H^{-1} calculated by the tests
This gives the user a visual indication of the numerical precision of
the functions offered.
Diffstat:
4 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
@@ -10,3 +10,5 @@ tags
*.pc
test_*
!test_*.[ch]
+*.dat
+*.pdf
diff --git a/Makefile b/Makefile
@@ -120,6 +120,10 @@ SWF_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs swf-local.pc)
test: build_tests
@$(SHELL) make.sh run_test $(TEST_SRC)
+ if command -v gnuplot > /dev/null; then \
+ gnuplot -e "func='H_{2d}'; data='H2d.dat'" src/ploterr.gp > H2d_error.pdf; \
+ gnuplot -e "func='H_{3d}'; data='H3d.dat'" src/ploterr.gp > H3d_error.pdf; \
+ fi
build_tests: build_library $(TEST_DEP) .test
@$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
@@ -129,6 +133,7 @@ build_tests: build_library $(TEST_DEP) .test
clean_test:
$(SHELL) make.sh clean_test $(TEST_SRC)
+ rm -f H2d.dat H3d.dat H2d_error.pdf H3d_error.pdf
$(TEST_DEP): config.mk swf-local.pc
@$(CC) $(CFLAGS_EXE) $(SWF_CFLAGS) $(RSYS_CFLAGS) \
diff --git a/src/ploterr.gp b/src/ploterr.gp
@@ -0,0 +1,16 @@
+# Copyright (C) 2024 |Méso|Star> (contact@meso-star.com)
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved. This file is offered as-is,
+# without any warranty.
+
+set terminal pdf
+set logscale y
+
+set title func." inversion error"
+set xlabel func."(x)"
+set ylabel "Relative error of ".func."^{-1}(x)"
+plot data u 2:5 title "Dichotomy" w l, \
+ data u 2:3 title "Quadratic" w l, \
+ data u 2:4 title "Linear" w l
diff --git a/src/test_swf_HXd.h b/src/test_swf_HXd.h
@@ -80,6 +80,7 @@ Xd(check_tabulation_creation)(void)
static void
Xd(check_inversion)(void)
{
+ FILE* fp = NULL;
const double nsteps = 10;
struct swf_H_tabulate_args args = SWF_HXD_TABULATE_ARGS_DEFAULT;
@@ -88,6 +89,9 @@ Xd(check_inversion)(void)
double x0 = 0;
size_t i = 0;
+ fp=fopen("H"STR(TEST_SWF_DIMENSION)"d.dat", "w");
+ CHK(fp != NULL);
+
CHK(swf_HXd_tabulate(&args, &tab) == RES_OK);
for(x0 = args.x_min; x0 <= args.x_max; x0 += x0*args.step) {
@@ -110,7 +114,7 @@ Xd(check_inversion)(void)
* inversion result, numerically speaking. */
if(Hx == pHx) continue;
- printf("%e %e %e %e %e\n", x, Hx, errq, errl, erri);
+ fprintf(fp, "%e %e %e %e %e\n", x, Hx, errq, errl, erri);
if(1e-9 < Hx && Hx < (1.0 - 1e-9)) {
CHK(errl < 1.e-5);
CHK(errq < 1.e-7);
@@ -124,6 +128,7 @@ Xd(check_inversion)(void)
}
}
+ CHK(fclose(fp) == 0);
CHK(swf_tabulation_ref_put(tab) == RES_OK);
}