From e3b663588a30ec4f05afe50c260982bd44a1bb2b Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 24 Jan 2019 19:01:18 -0500 Subject: style changes --- lib/src/graph.cpp | 82 ++++++++++++++++++++++++++--------------------------- lib/src/network.cpp | 40 +++++++++++++------------- 2 files changed, 61 insertions(+), 61 deletions(-) (limited to 'lib/src') diff --git a/lib/src/graph.cpp b/lib/src/graph.cpp index 0cc6a18..526ffeb 100644 --- a/lib/src/graph.cpp +++ b/lib/src/graph.cpp @@ -18,11 +18,11 @@ double mod(double a, double b) { } } -graph::graph(unsigned int Nx, unsigned int Ny) { +graph::graph(unsigned Nx, unsigned Ny) { L = {(double)Nx, (double)Ny}; - unsigned int ne = Nx * Ny; - unsigned int nv = ne / 2; + unsigned ne = Nx * Ny; + unsigned nv = ne / 2; vertices.resize(nv); edges.reserve(ne); @@ -30,7 +30,7 @@ graph::graph(unsigned int Nx, unsigned int Ny) { dual_vertices.resize(nv); dual_edges.reserve(ne); - for (unsigned int i = 0; i < nv; i++) { + for (unsigned i = 0; i < nv; i++) { vertices[i].r.x = (double)((1 + i / (Nx / 2)) % 2 + 2 * (i % (Nx / 2))); vertices[i].r.y = (double)(i / (Nx / 2)); vertices[i].polygon = { @@ -50,18 +50,18 @@ graph::graph(unsigned int Nx, unsigned int Ny) { }; } - for (unsigned int y = 0; y < Ny; y++) { - for (unsigned int x = 0; x < Nx; x++) { - unsigned int v1 = (Nx * y) / 2 + ((x + y % 2) / 2) % (Nx / 2); - unsigned int v2 = ((Nx * (y + 1)) / 2 + ((x + (y + 1) % 2) / 2) % (Nx / 2)) % nv; + for (unsigned y = 0; y < Ny; y++) { + for (unsigned x = 0; x < Nx; x++) { + unsigned v1 = (Nx * y) / 2 + ((x + y % 2) / 2) % (Nx / 2); + unsigned v2 = ((Nx * (y + 1)) / 2 + ((x + (y + 1) % 2) / 2) % (Nx / 2)) % nv; bool crossed_x = x == Nx - 1; bool crossed_y = y == Ny - 1; edges.push_back({{v1, v2}, {0.5 + (double)x, 0.5 + (double)y}, {crossed_x, crossed_y}}); - unsigned int dv1 = (Nx * y) / 2 + ((x + (y + 1) % 2) / 2) % (Nx / 2); - unsigned int dv2 = ((Nx * (y + 1)) / 2 + ((x + y % 2) / 2) % (Nx / 2)) % nv; + unsigned dv1 = (Nx * y) / 2 + ((x + (y + 1) % 2) / 2) % (Nx / 2); + unsigned dv2 = ((Nx * (y + 1)) / 2 + ((x + y % 2) / 2) % (Nx / 2)) % nv; dual_edges.push_back({{dv1, dv2}, {0.5 + (double)x, 0.5 + (double)y}, {crossed_x, crossed_y}}); } @@ -93,21 +93,21 @@ class triangleException: public std::exception } } triex; -unsigned int get_triangle_signature(unsigned int j1, unsigned int j2, unsigned int j3) { - // this yucky function takes three unsigned integers representing the +unsigned get_triangle_signature(unsigned j1, unsigned j2, unsigned j3) { + // this yucky function takes three unsignedegers representing the // location in the nine periodic copies of each corner of a delauney triangle - // and returns a signature for that triangle, which is an unsigned integer + // and returns a signature for that triangle, which is an unsignedeger // that uniquely labels the way the triangle crosses boundaries of the // copies. This allows us to differentiate delauney triangles with identical // vertices but which should be identified with different faces - unsigned int x1 = j1 % 3; - unsigned int y1 = j1 / 3; + unsigned x1 = j1 % 3; + unsigned y1 = j1 / 3; - unsigned int x2 = j2 % 3; - unsigned int y2 = j2 / 3; + unsigned x2 = j2 % 3; + unsigned y2 = j2 / 3; - unsigned int x3 = j3 % 3; - unsigned int y3 = j3 / 3; + unsigned x3 = j3 % 3; + unsigned y3 = j3 / 3; if ((j1 == j2) && (j2 == j3)) { return 0; @@ -146,9 +146,9 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) { // randomly choose N to be floor(Lx * Ly / 2) or ceil(Lx * Ly / 2) with // probability proportional to the distance from each std::uniform_real_distribution d(0.0, 1.0); - unsigned int N = round(Lx * Ly / 2 + d(rng) - 0.5); + unsigned N = round(Lx * Ly / 2 + d(rng) - 0.5); - unsigned int nv = N; + unsigned nv = N; vertices.resize(nv); // the coordinates of the lattice, from which a delaunay triangulation @@ -164,7 +164,7 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) { jcv_rect bounds = {{-Lx, -Ly}, {2 * Lx, 2 * Ly}}; std::vector points(9 * nv); - for (unsigned int i = 0; i < nv; i++) { + for (unsigned i = 0; i < nv; i++) { const vertex& v = vertices[i]; points[9 * i + 0] = {v.r.x - L.x, v.r.y - L.y}; points[9 * i + 1] = {v.r.x + 0.0, v.r.y - L.y}; @@ -181,7 +181,7 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) { const jcv_site* sites = jcv_diagram_get_sites(&diagram); - std::unordered_map, unsigned int> known_vertices; + std::unordered_map, unsigned> known_vertices; for (int i = 0; i < diagram.numsites; i++) { const jcv_site* site = &sites[i]; @@ -189,8 +189,8 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) { // we only care about processing the cells of our original, central sites if (site->index % 9 == 4) { bool self_bonded = false; - unsigned int i1 = (unsigned int)(site->index / 9); - unsigned int j1 = (unsigned int)(site->index % 9); + unsigned i1 = (unsigned)(site->index / 9); + unsigned j1 = (unsigned)(site->index % 9); const jcv_graphedge* e = site->edges; const jcv_graphedge* ep = site->edges; while (ep->next) { @@ -205,27 +205,27 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) { if (neighbor == NULL) { throw clippingex; } - unsigned int i2 = (unsigned int)(neighbor->index / 9); - unsigned int j2 = (unsigned int)(neighbor->index % 9); - unsigned int x2 = j2 % 3; - unsigned int y2 = j2 / 3; + unsigned i2 = (unsigned)(neighbor->index / 9); + unsigned j2 = (unsigned)(neighbor->index % 9); + unsigned x2 = j2 % 3; + unsigned y2 = j2 / 3; vertices[i1].polygon.push_back({e->pos[0].x, e->pos[0].y}); if (ep->neighbor == NULL) { throw clippingex; } - unsigned int i3p = (unsigned int)(ep->neighbor->index / 9); - unsigned int j3p = (unsigned int)(ep->neighbor->index % 9); + unsigned i3p = (unsigned)(ep->neighbor->index / 9); + unsigned j3p = (unsigned)(ep->neighbor->index % 9); - unsigned int sig1 = get_triangle_signature(j1, j2, j3p); + unsigned sig1 = get_triangle_signature(j1, j2, j3p); - std::array t1 = {i1, i2, i3p, sig1}; + std::array t1 = {i1, i2, i3p, sig1}; std::sort(t1.begin(), t1.begin() + 3); auto it1 = known_vertices.find(t1); - unsigned int vi1; + unsigned vi1; if (it1 == known_vertices.end()) { vi1 = dual_vertices.size(); @@ -259,17 +259,17 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) { throw clippingex; } - unsigned int i3n = (unsigned int)(en->neighbor->index / 9); - unsigned int j3n = (unsigned int)(en->neighbor->index % 9); + unsigned i3n = (unsigned)(en->neighbor->index / 9); + unsigned j3n = (unsigned)(en->neighbor->index % 9); - unsigned int sig2 = get_triangle_signature(j1, j2, j3n); + unsigned sig2 = get_triangle_signature(j1, j2, j3n); - std::array t2 = {i1, i2, i3n, sig2}; + std::array t2 = {i1, i2, i3n, sig2}; std::sort(t2.begin(), t2.begin() + 3); auto it2 = known_vertices.find(t2); - unsigned int vi2; + unsigned vi2; if (it2 == known_vertices.end()) { vi2 = dual_vertices.size(); @@ -279,8 +279,8 @@ graph::graph(double Lx, double Ly, std::mt19937& rng) { vi2 = it2->second; } - bool dcrossed_x = (unsigned int)floor(e->pos[0].x / L.x) != (unsigned int)floor(e->pos[1].x / L.x); - bool dcrossed_y = (unsigned int)floor(e->pos[0].y / L.y) != (unsigned int)floor(e->pos[1].y / L.y); + bool dcrossed_x = (unsigned)floor(e->pos[0].x / L.x) != (unsigned)floor(e->pos[1].x / L.x); + bool dcrossed_y = (unsigned)floor(e->pos[0].y / L.y) != (unsigned)floor(e->pos[1].y / L.y); dual_edges.push_back({{vi1, vi2}, {mod((e->pos[0].x + e->pos[1].x) / 2, L.x), diff --git a/lib/src/network.cpp b/lib/src/network.cpp index 3812f43..027946a 100644 --- a/lib/src/network.cpp +++ b/lib/src/network.cpp @@ -3,7 +3,7 @@ network::network(const graph& G, cholmod_common *c) : c(c), G(G), fuses(G.edges.size(), false), thresholds(G.edges.size(), 1) { b = CHOL_F(zeros)(G.vertices.size(), 1, CHOLMOD_REAL, c); - for (unsigned int i = 0; i < G.edges.size(); i++) { + for (unsigned i = 0; i < G.edges.size(); i++) { double v0y = G.vertices[G.edges[i].v[0]].r.y; double v1y = G.vertices[G.edges[i].v[1]].r.y; @@ -15,29 +15,29 @@ network::network(const graph& G, cholmod_common *c) : c(c), G(G), fuses(G.edges. } } - unsigned int nnz = G.vertices.size() + G.edges.size(); + unsigned nnz = G.vertices.size() + G.edges.size(); cholmod_triplet *t = CHOL_F(allocate_triplet)(G.vertices.size(), G.vertices.size(), nnz, 1, CHOLMOD_REAL, c); - for (unsigned int i = 0; i < G.vertices.size(); i++) { + for (unsigned i = 0; i < G.vertices.size(); i++) { ((CHOL_INT *)t->i)[i] = i; ((CHOL_INT *)t->j)[i] = i; ((double *)t->x)[i] = 0.0; } - unsigned int terms = G.vertices.size(); + unsigned terms = G.vertices.size(); - std::unordered_map, unsigned int> known_edges; + std::unordered_map, unsigned> known_edges; - for (unsigned int i = 0; i < G.edges.size(); i++) { - unsigned int v0 = G.edges[i].v[0]; - unsigned int v1 = G.edges[i].v[1]; + for (unsigned i = 0; i < G.edges.size(); i++) { + unsigned v0 = G.edges[i].v[0]; + unsigned v1 = G.edges[i].v[1]; ((double *)t->x)[v0]++; ((double *)t->x)[v1]++; - unsigned int s0 = v0 < v1 ? v0 : v1; - unsigned int s1 = v0 < v1 ? v1 : v0; + unsigned s0 = v0 < v1 ? v0 : v1; + unsigned s1 = v0 < v1 ? v1 : v0; auto it = known_edges.find({s0, s1}); @@ -67,7 +67,7 @@ network::network(const graph& G, cholmod_common *c) : c(c), G(G), fuses(G.edges. t->nnz = 2 * G.edges.size(); - for (unsigned int i = 0; i < G.edges.size(); i++) { + for (unsigned i = 0; i < G.edges.size(); i++) { ((CHOL_INT *)t->i)[2 * i] = i; ((CHOL_INT *)t->j)[2 * i] = G.edges[i].v[0]; ((double *)t->x)[2 * i] = 1.0; @@ -106,16 +106,16 @@ void network::set_thresholds(double beta, std::mt19937& rng) { } } -void network::break_edge(unsigned int e, bool unbreak) { +void network::break_edge(unsigned e, bool unbreak) { fuses[e] = !unbreak; - unsigned int v0 = G.edges[e].v[0]; - unsigned int v1 = G.edges[e].v[1]; + unsigned v0 = G.edges[e].v[0]; + unsigned v1 = G.edges[e].v[1]; - unsigned int n = factor->n; + unsigned n = factor->n; cholmod_sparse *update_mat = CHOL_F(allocate_sparse)(n, n, 2, true, true, 0, CHOLMOD_REAL, c); - unsigned int s1, s2; + unsigned s1, s2; s1 = v0 < v1 ? v0 : v1; s2 = v0 < v1 ? v1 : v0; @@ -123,11 +123,11 @@ void network::break_edge(unsigned int e, bool unbreak) { CHOL_INT *ii = (CHOL_INT *)update_mat->i; double *xx = (double *)update_mat->x; - for (unsigned int i = 0; i <= s1; i++) { + for (unsigned i = 0; i <= s1; i++) { pp[i] = 0; } - for (unsigned int i = s1 + 1; i <= n; i++) { + for (unsigned i = s1 + 1; i <= n; i++) { pp[i] = 2; } @@ -210,10 +210,10 @@ void network::fracture(hooks& m, double cutoff) { break; } - unsigned int max_pos = UINT_MAX; + unsigned max_pos = UINT_MAX; long double max_val = std::numeric_limits::lowest(); - for (unsigned int i = 0; i < G.edges.size(); i++) { + for (unsigned i = 0; i < G.edges.size(); i++) { if (!fuses[i] && fabs(ci.currents[i]) > cutoff) { long double val = logl(fabs(ci.currents[i])) - thresholds[i]; if (val > max_val) { -- cgit v1.2.3-70-g09d2