From 4f4cf365eae07e04298459bf8f9e27ad0cfcc834 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Wed, 5 Dec 2018 19:16:28 -0500 Subject: now takes Lx and Ly for anisotropic fracture --- lib/src/graph.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'lib/src/graph.cpp') diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp index e5f374e..f2e8065 100644 --- a/lib/src/graph.cpp +++ b/lib/src/graph.cpp @@ -1,10 +1,11 @@ #include "graph.hpp" -graph::graph(unsigned int L) { - double dx = 1.0 / L; - unsigned int nv = 2 * pow(L / 2, 2); - unsigned int ne = pow(L, 2); +graph::graph(unsigned int Nx, unsigned int Ny) { + L = {(double)Nx, (double)Ny}; + + unsigned int ne = Nx * Ny; + unsigned int nv = ne / 2; vertices.resize(nv); edges.reserve(ne); @@ -13,22 +14,22 @@ graph::graph(unsigned int L) { dual_edges.reserve(ne); for (unsigned int i = 0; i < nv; i++) { - vertices[i].r.x = dx * ((1 + i / (L / 2)) % 2 + 2 * (i % (L / 2))); - vertices[i].r.y = dx * (i / (L / 2)); + vertices[i].r.x = (double)((1 + i / (Nx / 2)) % 2 + 2 * (i % (Nx / 2))); + vertices[i].r.y = (double)(i / (Nx / 2)); - dual_vertices[i].r.x = dx * ((i / (L / 2)) % 2 + 2 * (i % (L / 2))); - dual_vertices[i].r.y = dx * (i / (L / 2)); + dual_vertices[i].r.x = (double)((i / (Nx / 2)) % 2 + 2 * (i % (Nx / 2))); + dual_vertices[i].r.y = (double)(i / (Nx / 2)); } - for (unsigned int x = 0; x < L; x++) { - for (unsigned int y = 0; y < L; y++) { - unsigned int v1 = (L * x) / 2 + ((y + x % 2) / 2) % (L / 2); - unsigned int v2 = ((L * (x + 1)) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2)) % nv; + for (unsigned int x = 0; x < Ny; x++) { + for (unsigned int y = 0; y < Nx; y++) { + unsigned int v1 = (Nx * x) / 2 + ((y + x % 2) / 2) % (Nx / 2); + unsigned int v2 = ((Nx * (x + 1)) / 2 + ((y + (x + 1) % 2) / 2) % (Nx / 2)) % nv; edges.push_back({v1, v2}); - unsigned int dv1 = (L * x) / 2 + ((y + (x + 1) % 2) / 2) % (L / 2); - unsigned int dv2 = ((L * (x + 1)) / 2 + ((y + x % 2) / 2) % (L / 2)) % nv; + unsigned int dv1 = (Nx * x) / 2 + ((y + (x + 1) % 2) / 2) % (Nx / 2); + unsigned int dv2 = ((Nx * (x + 1)) / 2 + ((y + x % 2) / 2) % (Nx / 2)) % nv; dual_edges.push_back({dv1, dv2}); } -- cgit v1.2.3-70-g09d2