summaryrefslogtreecommitdiff
path: root/src/voronoi_bound_ini.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/voronoi_bound_ini.c')
-rw-r--r--src/voronoi_bound_ini.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/voronoi_bound_ini.c b/src/voronoi_bound_ini.c
new file mode 100644
index 0000000..38f41cc
--- /dev/null
+++ b/src/voronoi_bound_ini.c
@@ -0,0 +1,79 @@
+
+#include "fracture.h"
+
+void voronoi_bound_ini(finst *instance, double *square_bound,
+ unsigned int width) {
+ unsigned int square_num_verts = 2 * ((width + 1) / 2) * (width / 2 + 1);
+ double total1 = 0;
+ double total2 = 0;
+ double total3 = 0;
+ double total4 = 0;
+ for (unsigned int i = 0; i < instance->network->num_bounds; i++) {
+ for (unsigned int j = 0; j < instance->network->bound_inds[i + 1] -
+ instance->network->bound_inds[i];
+ j++) {
+ double x = instance->network
+ ->vert_coords[2 *
+ instance->network->bound_verts
+ [instance->network->bound_inds[i] + j]];
+ double y =
+ instance->network
+ ->vert_coords[2 *
+ instance->network->bound_verts
+ [instance->network->bound_inds[i] + j] +
+ 1];
+
+ unsigned int vw = (width + 1) / 2;
+ unsigned int xp = (unsigned int)(x * vw);
+ unsigned int yp = (unsigned int)(y * vw);
+
+ if (i == 0) {
+ ((double *)instance->boundary_cond
+ ->x)[instance->network
+ ->bound_verts[instance->network->bound_inds[i] + j]] =
+ square_bound[xp];
+ total1 += square_bound[xp];
+ }
+ if (i == 1) {
+ ((double *)instance->boundary_cond
+ ->x)[instance->network
+ ->bound_verts[instance->network->bound_inds[i] + j]] =
+ square_bound[square_num_verts - vw - 1 + xp];
+ total2 += square_bound[square_num_verts - vw - 1 + xp];
+ }
+ if (i == 2) {
+ ((double *)instance->boundary_cond
+ ->x)[instance->network
+ ->bound_verts[instance->network->bound_inds[i] + j]] =
+ square_bound[(width + 1) / 2 + yp * (width + 1)];
+ total3 += square_bound[(width + 1) / 2 + yp * (width + 1)];
+ }
+ if (i == 3) {
+ ((double *)instance->boundary_cond
+ ->x)[instance->network
+ ->bound_verts[instance->network->bound_inds[i] + j]] =
+ square_bound[(width + 1) / 2 + yp * (width + 1) + width / 2];
+ total4 += square_bound[(width + 1) / 2 + yp * (width + 1) + width / 2];
+ }
+ }
+ }
+
+ ((double *)instance->boundary_cond->x)[instance->network->num_verts] =
+ - total1 / 2 - total2 / 2;
+ ((double *)instance->boundary_cond->x)[instance->network->num_verts + 1] =
+ - total1 / 2 - total2 / 2;
+ ((double *)instance->boundary_cond->x)[instance->network->num_verts + 2] =
+ -total3;
+ ((double *)instance->boundary_cond->x)[instance->network->num_verts + 3] =
+ -total4;
+ /*
+ ((double *)instance->boundary_cond->x)[instance->network->num_verts] =
+ 0;
+ ((double *)instance->boundary_cond->x)[instance->network->num_verts + 1] =
+ 0;
+ ((double *)instance->boundary_cond->x)[instance->network->num_verts + 2] =
+ 0;
+ ((double *)instance->boundary_cond->x)[instance->network->num_verts + 3] =
+ 0;
+ */
+}