summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2019-02-06 14:01:21 +0100
committerAnton Khirnov <anton@khirnov.net>2019-02-06 14:07:32 +0100
commit5ad647c4637e80341574ee6631ead49bf13e0299 (patch)
treee9c7f30337dc18685fdd17f9db9d77a0618badef
parent472c95da5fbea917407ecc70709dbd65a2e22507 (diff)
boundary: add public functions for querying boundary information
Should allow treating boundaries in a generic manner. API bump
-rw-r--r--boundary.c59
-rw-r--r--libmg2d.v2
-rw-r--r--mg2d_boundary.h28
3 files changed, 88 insertions, 1 deletions
diff --git a/boundary.c b/boundary.c
index 86803fc..419a310 100644
--- a/boundary.c
+++ b/boundary.c
@@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <errno.h>
#include <stddef.h>
#include <stdlib.h>
@@ -73,3 +74,61 @@ void mg2di_bc_free(MG2DBoundary **pbnd)
free(bnd);
*pbnd = NULL;
}
+
+static const struct {
+ unsigned int coord_idx;
+ unsigned int is_upper;
+} boundary_def[] = {
+ [MG2D_BOUNDARY_0L] = {
+ .coord_idx = 0,
+ .is_upper = 0,
+ },
+ [MG2D_BOUNDARY_0U] = {
+ .coord_idx = 0,
+ .is_upper = 1,
+ },
+ [MG2D_BOUNDARY_1L] = {
+ .coord_idx = 1,
+ .is_upper = 0
+ },
+ [MG2D_BOUNDARY_1U] = {
+ .coord_idx = 1,
+ .is_upper = 1,
+ },
+};
+
+int mg2d_bnd_coord_idx(enum MG2DBoundaryLoc loc)
+{
+ if (loc < 0 || loc >= ARRAY_ELEMS(boundary_def))
+ return -EINVAL;
+
+ return boundary_def[loc].coord_idx;
+}
+
+int mg2d_bnd_is_upper(enum MG2DBoundaryLoc loc)
+{
+ if (loc < 0 || loc >= ARRAY_ELEMS(boundary_def))
+ return -EINVAL;
+
+ return boundary_def[loc].is_upper;
+}
+
+int mg2d_bnd_out_dir(enum MG2DBoundaryLoc loc)
+{
+ int ret = mg2d_bnd_is_upper(loc);
+
+ if (ret < 0)
+ return 0;
+
+ return ret ? 1 : -1;
+}
+
+enum MG2DBoundaryLoc mg2d_bnd_id(int coord_idx, int is_upper)
+{
+ for (int i = 0; i < ARRAY_ELEMS(boundary_def); i++) {
+ if (boundary_def[i].coord_idx == coord_idx &&
+ boundary_def[i].is_upper == is_upper)
+ return i;
+ }
+ return MG2D_BOUNDARY_NONE;
+}
diff --git a/libmg2d.v b/libmg2d.v
index 400c46f..7fb72b7 100644
--- a/libmg2d.v
+++ b/libmg2d.v
@@ -1,4 +1,4 @@
-LIBMG2D_7 {
+LIBMG2D_8 {
global: mg2d_*;
local: *;
};
diff --git a/mg2d_boundary.h b/mg2d_boundary.h
index 4a7dcee..12c897f 100644
--- a/mg2d_boundary.h
+++ b/mg2d_boundary.h
@@ -45,6 +45,10 @@ enum MG2DBCType {
*/
enum MG2DBoundaryLoc {
/**
+ * Undefined boundary location.
+ */
+ MG2D_BOUNDARY_NONE = -1,
+ /**
* coord0 lower
*/
MG2D_BOUNDARY_0L,
@@ -94,4 +98,28 @@ typedef struct MG2DBoundary {
MG2DBoundaryInternal *priv;
} MG2DBoundary;
+/**
+ * @return index of the coordinate that is kept constant along this boundary
+ * (x: 0, y: 1)
+ */
+int mg2d_bnd_coord_idx(enum MG2DBoundaryLoc loc);
+
+/**
+ * @return 1 if this is the upper boundary, 0 for the lower one
+ */
+int mg2d_bnd_is_upper(enum MG2DBoundaryLoc loc);
+
+/**
+ * @return 1 if the corresponding variable increases in the direction from the
+ * computational domain across the boundary, -1 if it decreases.
+ *
+ * @note this is equivalent to (mg2d_bnd_is_upper(loc) ? 1 : -1)
+ */
+int mg2d_bnd_out_dir(enum MG2DBoundaryLoc loc);
+
+/**
+ * Construct the boundary id from coordinate and upper/lower specification.
+ */
+enum MG2DBoundaryLoc mg2d_bnd_id(int coord_idx, int is_upper);
+
#endif // MG2D_BOUNDARY_H