aboutsummaryrefslogtreecommitdiff
path: root/relax_test.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-03-22 18:50:55 +0100
committerAnton Khirnov <anton@khirnov.net>2019-03-22 20:12:10 +0100
commitc2ead14543d11a532a8ac564119a7a10160fdc41 (patch)
treec6c6da6d323f47896b85acc4cb75e01dc516c9a1 /relax_test.c
parentaa0b903240d5c0ea5b0af8f5dc5aeb0845fd69b7 (diff)
ell_grid_solve: switch to ndarray in its external API
Diffstat (limited to 'relax_test.c')
-rw-r--r--relax_test.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/relax_test.c b/relax_test.c
index 1e9b962..54155ca 100644
--- a/relax_test.c
+++ b/relax_test.c
@@ -8,6 +8,7 @@
#include "log.h"
#include "mg2d_boundary.h"
#include "mg2d_constants.h"
+#include "ndarray.h"
#define ARRAY_ELEMS(x) (sizeof(x) / sizeof(*x))
#define DOMAIN_SIZE 1.0
@@ -113,24 +114,24 @@ int main(int argc, char **argv)
for (size_t y = 0; y < ctx->domain_size[1]; y++) {
const double y_coord = y * ctx->step[1];
- memset(ctx->u + y * ctx->u_stride, 0, sizeof(*ctx->u) * ctx->domain_size[0]);
+ memset(NDPTR2D(ctx->u, 0, y), 0, sizeof(*ctx->u->data) * ctx->domain_size[0]);
for (size_t x = 0; x < ctx->domain_size[0]; x++) {
const double x_coord = x * ctx->step[0];
- ctx->diff_coeffs[MG2D_DIFF_COEFF_02][ctx->diff_coeffs_stride * y + x] = 1.0;
- ctx->diff_coeffs[MG2D_DIFF_COEFF_20][ctx->diff_coeffs_stride * y + x] = 1.0;
- ctx->diff_coeffs[MG2D_DIFF_COEFF_11][ctx->diff_coeffs_stride * y + x] = 1.0;
+ *NDPTR2D(ctx->diff_coeffs[MG2D_DIFF_COEFF_02], x, y) = 1.0;
+ *NDPTR2D(ctx->diff_coeffs[MG2D_DIFF_COEFF_20], x, y) = 1.0;
+ *NDPTR2D(ctx->diff_coeffs[MG2D_DIFF_COEFF_11], x, y) = 1.0;
- ctx->rhs[y * ctx->rhs_stride + x] = sol_dxx(x_coord, y_coord) + sol_dyy(x_coord, y_coord) + sol_dxy(x_coord, y_coord);
+ *NDPTR2D(ctx->rhs, x, y) = sol_dxx(x_coord, y_coord) + sol_dyy(x_coord, y_coord) + sol_dxy(x_coord, y_coord);
}
- memset(ctx->diff_coeffs[MG2D_DIFF_COEFF_00] + y * ctx->diff_coeffs_stride, 0,
- sizeof(*ctx->diff_coeffs[0]) * ctx->domain_size[0]);
- memset(ctx->diff_coeffs[MG2D_DIFF_COEFF_01] + y * ctx->diff_coeffs_stride, 0,
- sizeof(*ctx->diff_coeffs[0]) * ctx->domain_size[0]);
- memset(ctx->diff_coeffs[MG2D_DIFF_COEFF_10] + y * ctx->diff_coeffs_stride, 0,
- sizeof(*ctx->diff_coeffs[0]) * ctx->domain_size[0]);
+ memset(NDPTR2D(ctx->diff_coeffs[MG2D_DIFF_COEFF_00], 0, y), 0,
+ sizeof(*ctx->diff_coeffs[0]->data) * ctx->domain_size[0]);
+ memset(NDPTR2D(ctx->diff_coeffs[MG2D_DIFF_COEFF_01], 0, y), 0,
+ sizeof(*ctx->diff_coeffs[0]->data) * ctx->domain_size[0]);
+ memset(NDPTR2D(ctx->diff_coeffs[MG2D_DIFF_COEFF_10], 0, y), 0,
+ sizeof(*ctx->diff_coeffs[0]->data) * ctx->domain_size[0]);
}
ret = mg2di_egs_init(ctx);
@@ -140,7 +141,7 @@ int main(int argc, char **argv)
goto fail;
}
- res_old = findmax(ctx->residual, ctx->residual_stride * ctx->domain_size[1]);
+ res_old = findmax(ctx->residual->data, ctx->residual->stride[0] * ctx->domain_size[1]);
for (int i = 0; i < maxiter; i++) {
ret = mg2di_egs_solve(ctx);
@@ -149,7 +150,7 @@ int main(int argc, char **argv)
ret = 1;
goto fail;
}
- res_new = findmax(ctx->residual, ctx->residual_stride * ctx->domain_size[1]);
+ res_new = findmax(ctx->residual->data, ctx->residual->stride[0] * ctx->domain_size[1]);
if (res_new > 1e3) {
fprintf(stderr, "Diverged at step %d: %g -> %g\n", i, res_old, res_new);
goto fail;
@@ -166,7 +167,7 @@ int main(int argc, char **argv)
for (size_t x = 0; x < ctx->domain_size[0]; x++) {
const double x_coord = x * ctx->step[0];
- double err = fabs(ctx->u[y * ctx->u_stride + x] - sol(x_coord, y_coord));
+ double err = fabs(ctx->u->data[y * ctx->u->stride[0] + x] - sol(x_coord, y_coord));
if (err > max_err)
max_err = err;
}