From 873a9f9bedbbfb07d475e271923a7b86464e515f Mon Sep 17 00:00:00 2001 From: pants Date: Wed, 7 Sep 2016 14:55:30 -0400 Subject: more major refactoring --- src/bound_set.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 src/bound_set.c (limited to 'src/bound_set.c') diff --git a/src/bound_set.c b/src/bound_set.c new file mode 100644 index 0000000..9c67f82 --- /dev/null +++ b/src/bound_set.c @@ -0,0 +1,62 @@ + +#include "fracture.h" + +double th_p(double x, double y, double th) { + if (x >= 0 && y >= 0) return th; + else if (x < 0 && y >= 0) return M_PI - th; + else if (x < 0 && y < 0) return th - M_PI; + else return -th; + +} + +double u_y(double x, double y) { + double r = sqrt(pow(x, 2) + pow(y, 2)); + double th = th_p(x, y, atan(fabs(y / x))); + + return sqrt(r) * sin(th / 2); +} + +void bound_set_embedded(double *bound, uint_t L, double notch_len) { + for (uint_t i = 0; i < L / 2; i++) { + double x1, y1, x2, y2, x3, y3, x4, y4; + x1 = (2. * i + 1.) / L - notch_len; y1 = 0.5 - 1.; + x2 = (2. * i + 1.) / L - notch_len; y2 = 0.5 - 0.; + y3 = (2. * i + 1.) / L - 0.5; x3 = 0.5 - 1.; + y4 = (2. * i + 1.) / L - 0.5; x4 = 0.5 - 0.; + + bound[i] = u_y(x1, y1); + bound[L / 2 + i] = u_y(x2, y2); + bound[L + i] = u_y(x3, y3); + bound[3 * L / 2 + i] = u_y(x4, y4); + } +} + +cholmod_dense *bound_set(const graph_t *g, bool vb, double notch_len, cholmod_common *c) { + cholmod_dense *boundary = CHOL_F(zeros)(g->break_dim, 1, CHOLMOD_REAL, c); + double *bound = (double *)boundary->x; + + switch (g->boundary) { + case TORUS_BOUND: + for (uint_t i = 0; i < g->bound_inds[1]; i++) { + bound[g->bound_verts[i]] = 1; + bound[g->nv + i] = -1; + } + bound[g->bound_verts[0]] = 1; + break; + case EMBEDDED_BOUND: + bound_set_embedded(bound, g->L, notch_len); + break; + default: + if (vb) { + for (uint_t i = 0; i < g->bound_inds[1]; i++) { + bound[g->bound_verts[i]] = 1; + } + } else { + bound[0] = 1; + bound[g->nv] = 1; + bound[g->nv + 1] = -1; + } + } + + return boundary; +} -- cgit v1.2.3-70-g09d2