commit b20d98f6b06ea0e385280a38cbe515f7ce7461fd
parent d2defaaef06b36edc9efa367124872959e130003
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 13 Mar 2024 12:25:52 +0100
Rename H function's default arguments and update its tests
The constant that defines the default arguments of the H function
contains 3D in its name to indicate that it is defined for the 3D
version of the H function.
A tabulation test was incorrect. It checked the step argument as if it
was an absolute step, whereas it is now relative to each tab entry.
Finally, we now test the swf_H3d_inverse function in the same way as the
inversion calculated from a tab.
Diffstat:
3 files changed, 16 insertions(+), 19 deletions(-)
diff --git a/src/swf.h b/src/swf.h
@@ -62,9 +62,9 @@ struct swf_H_tabulate_args {
/* The H function's default tab values guarantee both numerical accuracy and a
* small memory footprint */
-#define SWF_H_TABULATE_ARGS_DEFAULT__ {7.5e-3, 3.337, 1e-3, 0, NULL}
-static const struct swf_H_tabulate_args SWF_H_TABULATE_ARGS_DEFAULT =
- SWF_H_TABULATE_ARGS_DEFAULT__;
+#define SWF_H3D_TABULATE_ARGS_DEFAULT__ {7.5e-3, 3.337, 1e-3, 0, NULL}
+static const struct swf_H_tabulate_args SWF_H3D_TABULATE_ARGS_DEFAULT =
+ SWF_H3D_TABULATE_ARGS_DEFAULT__;
/* Forward declarations of opaque data types */
struct swf_tabulation;
diff --git a/src/swf_H.c b/src/swf_H.c
@@ -41,10 +41,6 @@ check_swf_H_tabulate_args(const struct swf_H_tabulate_args* args)
if(args->step <= 0)
return RES_BAD_ARG;
- /* Delta X cannot be greater than the X range */
- if(args->step > args->x_max - args->x_min)
- return RES_BAD_ARG;
-
return RES_OK;
}
diff --git a/src/test_swf_H3d.c b/src/test_swf_H3d.c
@@ -27,7 +27,7 @@
static INLINE void
check_tabulation_creation(void)
{
- struct swf_H_tabulate_args args = SWF_H_TABULATE_ARGS_DEFAULT;
+ struct swf_H_tabulate_args args = SWF_H3D_TABULATE_ARGS_DEFAULT;
struct swf_tabulation* tab = NULL;
CHK(swf_H3d_tabulate(NULL, &tab) == RES_BAD_ARG);
@@ -40,18 +40,15 @@ check_tabulation_creation(void)
CHK(swf_tabulation_ref_put(tab) == RES_OK);
CHK(swf_tabulation_ref_put(tab) == RES_OK);
- args.x_min = SWF_H_TABULATE_ARGS_DEFAULT.x_max;
- args.x_max = SWF_H_TABULATE_ARGS_DEFAULT.x_min;
+ args.x_min = SWF_H3D_TABULATE_ARGS_DEFAULT.x_max;
+ args.x_max = SWF_H3D_TABULATE_ARGS_DEFAULT.x_min;
CHK(swf_H3d_tabulate(&args, &tab) == RES_BAD_ARG);
args.x_max = args.x_min;
CHK(swf_H3d_tabulate(&args, &tab) == RES_BAD_ARG);
- args.x_min = SWF_H_TABULATE_ARGS_DEFAULT.x_min;
- args.x_max = SWF_H_TABULATE_ARGS_DEFAULT.x_max;
- args.step = args.x_max - args.x_min + 1.e-3;
- CHK(swf_H3d_tabulate(&args, &tab) == RES_BAD_ARG);
-
+ args.x_min = SWF_H3D_TABULATE_ARGS_DEFAULT.x_min;
+ args.x_max = SWF_H3D_TABULATE_ARGS_DEFAULT.x_max;
args.step = 0;
CHK(swf_H3d_tabulate(&args, &tab) == RES_BAD_ARG);
@@ -61,11 +58,11 @@ check_tabulation_creation(void)
}
static void
-check_tabulation_inversion(void)
+check_inversion(void)
{
const double nsteps = 10;
- struct swf_H_tabulate_args args = SWF_H_TABULATE_ARGS_DEFAULT;
+ struct swf_H_tabulate_args args = SWF_H3D_TABULATE_ARGS_DEFAULT;
struct swf_tabulation* tab = NULL;
double pHx = 0;
double x0 = 0;
@@ -82,8 +79,10 @@ check_tabulation_inversion(void)
const double Hx = swf_H3d_eval(x);
const double xl = swf_tabulation_inverse(tab, SWF_LINEAR, Hx);
const double xq = swf_tabulation_inverse(tab, SWF_QUADRATIC, Hx);
+ const double xi = swf_H3d_inverse(Hx);
const double errl = fabs((x - xl) / x);
const double errq = fabs((x - xq) / x);
+ const double erri = fabs((x - xi) / x);
/* Do not check the value of x if the corresponding H is indistinguishable
* from an H calculated from a previous x. In other words, the H's are
@@ -91,13 +90,15 @@ check_tabulation_inversion(void)
* inversion result, numerically speaking. */
if(Hx == pHx) continue;
- printf("%e %e %e %e\n", x, Hx, errq, errl);
+ printf("%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);
+ CHK(erri < 1.e-7);
} else {
CHK(errl < 1.e-3);
CHK(errq < 1.e-3);
+ CHK(erri < 1.e-3);
}
pHx = Hx;
}
@@ -115,7 +116,7 @@ main(int argc, char** argv)
(void)argc, (void)argv;
check_tabulation_creation();
- check_tabulation_inversion();
+ check_inversion();
CHK(mem_allocated_size() == 0);
return 0;
}