aboutsummaryrefslogtreecommitdiff
path: root/relax_test.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-02-06 14:07:46 +0100
committerAnton Khirnov <anton@khirnov.net>2019-02-06 14:07:46 +0100
commit6aa61c3e38a164b5d015d6ab67e15a46a5b9bc15 (patch)
tree596f3ddfe04edc478196f53e9f1c81691d5cae96 /relax_test.c
parent5ad647c4637e80341574ee6631ead49bf13e0299 (diff)
relax_test: use the new boundary API to simplify code
Diffstat (limited to 'relax_test.c')
-rw-r--r--relax_test.c61
1 files changed, 15 insertions, 46 deletions
diff --git a/relax_test.c b/relax_test.c
index c635949..1e9b962 100644
--- a/relax_test.c
+++ b/relax_test.c
@@ -9,6 +9,9 @@
#include "mg2d_boundary.h"
#include "mg2d_constants.h"
+#define ARRAY_ELEMS(x) (sizeof(x) / sizeof(*x))
+#define DOMAIN_SIZE 1.0
+
#if 1
static double sol(double x, double y)
{
@@ -79,41 +82,17 @@ int main(int argc, char **argv)
ctx->logger.log = mg2di_log_default_callback;
- ctx->step[0] = 1.0 / (N - 1.0);
- ctx->step[1] = 1.0 / (N - 1.0);
+ ctx->step[0] = DOMAIN_SIZE / (N - 1.0);
+ ctx->step[1] = DOMAIN_SIZE / (N - 1.0);
ctx->fd_stencil = 2;
- {
- MG2DBoundary *bnd = ctx->boundaries[MG2D_BOUNDARY_0L];
-
- bnd->type = MG2D_BC_TYPE_FIXVAL;
-
- memset(bnd->val, 0, N * sizeof(*bnd->val));
-
- for (int j = 1; j < ctx->fd_stencil; j++) {
- double *dst = bnd->val + j * bnd->val_stride;
-
- for (ptrdiff_t k = -j; k < (ptrdiff_t)ctx->domain_size[1] + j; k++)
- dst[k] = sol(-j * ctx->step[0], k * ctx->step[1]);
- }
- }
- {
- MG2DBoundary *bnd = ctx->boundaries[MG2D_BOUNDARY_0U];
-
- bnd->type = MG2D_BC_TYPE_FIXVAL;
-
- memset(bnd->val, 0, N * sizeof(*bnd->val));
-
- for (int j = 1; j < ctx->fd_stencil; j++) {
- double *dst = bnd->val + j * bnd->val_stride;
+ for (int bnd_loc = 0; bnd_loc < ARRAY_ELEMS(ctx->boundaries); bnd_loc++) {
+ MG2DBoundary *bnd = ctx->boundaries[bnd_loc];
+ const int ci = mg2d_bnd_coord_idx(bnd_loc);
+ const int bnd_dir = mg2d_bnd_out_dir(bnd_loc);
- for (ptrdiff_t k = -j; k < (ptrdiff_t)ctx->domain_size[1] + j; k++)
- dst[k] = sol((N - 1 + j) * ctx->step[0], k * ctx->step[1]);
- }
- }
- {
- MG2DBoundary *bnd = ctx->boundaries[MG2D_BOUNDARY_1L];
+ double coord[2];
bnd->type = MG2D_BC_TYPE_FIXVAL;
@@ -122,22 +101,12 @@ int main(int argc, char **argv)
for (int j = 1; j < ctx->fd_stencil; j++) {
double *dst = bnd->val + j * bnd->val_stride;
- for (ptrdiff_t k = -j; k < (ptrdiff_t)ctx->domain_size[0] + j; k++)
- dst[k] = sol(k * ctx->step[0], -j * ctx->step[1]);
- }
- }
- {
- MG2DBoundary *bnd = ctx->boundaries[MG2D_BOUNDARY_1U];
+ coord[ci] = mg2d_bnd_is_upper(bnd_loc) * DOMAIN_SIZE + bnd_dir * j * ctx->step[ci];
- bnd->type = MG2D_BC_TYPE_FIXVAL;
-
- memset(bnd->val, 0, N * sizeof(*bnd->val));
-
- for (int j = 1; j < ctx->fd_stencil; j++) {
- double *dst = bnd->val + j * bnd->val_stride;
-
- for (ptrdiff_t k = -j; k < (ptrdiff_t)ctx->domain_size[0] + j; k++)
- dst[k] = sol(k * ctx->step[0], (N - 1 + j) * ctx->step[1]);
+ for (ptrdiff_t k = -j; k < N + j; k++) {
+ coord[!ci] = k * ctx->step[!ci];
+ dst[k] = sol(coord[0], coord[1]);
+ }
}
}