summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-03-25 18:14:09 +0100
committerAnton Khirnov <anton@khirnov.net>2019-03-25 18:14:09 +0100
commit1b0a89c2f0c1287026f6885ee12030dc0299066f (patch)
tree51482cc7bf39bf1ee45495eccf2f9e65cc248a04
parentf31df936804499db0f456cbe15a524de6ba039cd (diff)
egs: apply the boundary conditions in the correct order
Drop the hack that just ran through the loop twice.
-rw-r--r--ell_grid_solve.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/ell_grid_solve.c b/ell_grid_solve.c
index fdbce7d..63aed59 100644
--- a/ell_grid_solve.c
+++ b/ell_grid_solve.c
@@ -178,13 +178,16 @@ static void boundaries_apply_falloff(double *dst, const ptrdiff_t dst_stride[2],
static void boundaries_apply(EGSContext *ctx)
{
+ static const enum MG2DBCType bnd_type_order[] = { MG2D_BC_TYPE_FIXVAL, MG2D_BC_TYPE_REFLECT, MG2D_BC_TYPE_FALLOFF };
EGSInternal *priv = ctx->priv;
const ptrdiff_t strides[2] = { 1, priv->stride };
int64_t start;
start = gettime();
- for (int tmp = 0; tmp < 2; tmp++)
+ for (int order_idx = 0; order_idx < ARRAY_ELEMS(bnd_type_order); order_idx++) {
for (int i = 0; i < ARRAY_ELEMS(ctx->boundaries); i++) {
+ MG2DBoundary *bnd = ctx->boundaries[i];
+
const int ci = mg2d_bnd_coord_idx(i);
const ptrdiff_t stride_boundary = strides[!ci];
const ptrdiff_t stride_offset = strides[ci];
@@ -194,21 +197,25 @@ static void boundaries_apply(EGSContext *ctx)
double *dst = ctx->u->data + mg2d_bnd_is_upper(i) * ((size_offset - 1) * stride_offset);
const ptrdiff_t dst_strides[] = { stride_boundary, mg2d_bnd_out_dir(i) * stride_offset };
- switch (ctx->boundaries[i]->type) {
+ if (bnd->type != bnd_type_order[order_idx])
+ continue;
+
+ switch (bnd->type) {
case MG2D_BC_TYPE_FIXVAL:
- boundaries_apply_fixval(dst, dst_strides, ctx->boundaries[i]->val,
- ctx->boundaries[i]->val_stride, size_boundary);
+ boundaries_apply_fixval(dst, dst_strides, bnd->val,
+ bnd->val_stride, size_boundary);
break;
case MG2D_BC_TYPE_REFLECT:
- boundaries_apply_reflect(dst, dst_strides, ctx->boundaries[i]->val,
- ctx->boundaries[i]->val_stride, size_boundary);
+ boundaries_apply_reflect(dst, dst_strides, bnd->val,
+ bnd->val_stride, size_boundary);
break;
case MG2D_BC_TYPE_FALLOFF:
- boundaries_apply_falloff(dst, dst_strides, ctx->boundaries[i]->val,
- ctx->boundaries[i]->val_stride, size_boundary, ctx);
+ boundaries_apply_falloff(dst, dst_strides, bnd->val,
+ bnd->val_stride, size_boundary, ctx);
break;
}
}
+ }
/* fill in the corner ghosts */
for (int pos_y = 0; pos_y < 2; pos_y++) {