From 344d6de9b813aa77fb7778898370b5f7f0952c4c Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 17:49:43 -0500 Subject: [PATCH 01/31] add container_periodic_poly function --- cpp/locality/Voronoi.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index b3189f9b7..19d9f7828 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq) +void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,15 +44,25 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq) int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); + if (radii!=NULL){ + voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + } else { + voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + } for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - container.put(query_point_id, query_point.x, query_point.y, query_point.z); + if (radii!=NULL){ + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + } else{ + container.put(query_point_id, query_point.x, query_point.y, query_point.z); + } } voro::voronoicell_neighbor cell; From 6d8597551a9e5865cff1e224723cbc02dec36450 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 18:09:36 -0500 Subject: [PATCH 02/31] make header files consistently --- cpp/locality/Voronoi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/locality/Voronoi.h b/cpp/locality/Voronoi.h index 77f97b82e..d62efe4a3 100644 --- a/cpp/locality/Voronoi.h +++ b/cpp/locality/Voronoi.h @@ -19,7 +19,7 @@ class Voronoi // default constructor Voronoi() : m_neighbor_list(std::make_shared()) {} - void compute(const freud::locality::NeighborQuery* nq); + void compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL); std::shared_ptr getNeighborList() const { From 5969de0cc4a2d948ba1bf43f46ca990af358c999 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 18:35:09 -0500 Subject: [PATCH 03/31] revert to the original for testing --- cpp/locality/Voronoi.cc | 18 ++++-------------- cpp/locality/Voronoi.h | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index 19d9f7828..faf2f220d 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL) +void Voronoi::compute(const freud::locality::NeighborQuery* nq) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,27 +44,17 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned d int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - if (radii!=NULL){ - voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, - boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, - voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - } else { - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - } for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - if (radii!=NULL){ - container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); - } else{ - container.put(query_point_id, query_point.x, query_point.y, query_point.z); - } + container.put(query_point_id, query_point.x, query_point.y, query_point.z); } - + voro::voronoicell_neighbor cell; voro::c_loop_all_periodic voronoi_loop(container); std::vector face_areas; diff --git a/cpp/locality/Voronoi.h b/cpp/locality/Voronoi.h index d62efe4a3..77f97b82e 100644 --- a/cpp/locality/Voronoi.h +++ b/cpp/locality/Voronoi.h @@ -19,7 +19,7 @@ class Voronoi // default constructor Voronoi() : m_neighbor_list(std::make_shared()) {} - void compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL); + void compute(const freud::locality::NeighborQuery* nq); std::shared_ptr getNeighborList() const { From 618d3e1333884a7a86e7fec6d2ddab9cb85e40f8 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 19:05:14 -0500 Subject: [PATCH 04/31] only polydisperse --- cpp/locality/Voronoi.cc | 26 ++++++++++++++++++-------- cpp/locality/Voronoi.h | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index faf2f220d..145066cbd 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq) +void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,17 +44,27 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq) int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, - boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, - voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - + if (radii != NULL){ + voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + } + /*else{ + voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + } +*/ for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - container.put(query_point_id, query_point.x, query_point.y, query_point.z); + if (radii != NULL){ + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + } /*else { + container.put(query_point_id, query_point.x, query_point.y, query_point.z); + }*/ } - + voro::voronoicell_neighbor cell; voro::c_loop_all_periodic voronoi_loop(container); std::vector face_areas; diff --git a/cpp/locality/Voronoi.h b/cpp/locality/Voronoi.h index 77f97b82e..d62efe4a3 100644 --- a/cpp/locality/Voronoi.h +++ b/cpp/locality/Voronoi.h @@ -19,7 +19,7 @@ class Voronoi // default constructor Voronoi() : m_neighbor_list(std::make_shared()) {} - void compute(const freud::locality::NeighborQuery* nq); + void compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL); std::shared_ptr getNeighborList() const { From 40e899c74b5c2b3826d99baf73b9b484db1d7161 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 19:15:50 -0500 Subject: [PATCH 05/31] unsigned is not applied double or float. --- cpp/locality/Voronoi.cc | 25 +++++++++++++++---------- cpp/locality/Voronoi.h | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index 145066cbd..a5e6cd383 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL) +void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* radii = NULL) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,25 +44,30 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned d int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - if (radii != NULL){ - voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + if (radii != NULL) + { + voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); } - /*else{ - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + else + { + voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); } -*/ + for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - if (radii != NULL){ - container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); - } /*else { + if (radii != NULL) + { + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + } + else + { container.put(query_point_id, query_point.x, query_point.y, query_point.z); - }*/ + } } voro::voronoicell_neighbor cell; diff --git a/cpp/locality/Voronoi.h b/cpp/locality/Voronoi.h index d62efe4a3..80c741cfc 100644 --- a/cpp/locality/Voronoi.h +++ b/cpp/locality/Voronoi.h @@ -19,7 +19,7 @@ class Voronoi // default constructor Voronoi() : m_neighbor_list(std::make_shared()) {} - void compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL); + void compute(const freud::locality::NeighborQuery* nq, const double* radii = NULL); std::shared_ptr getNeighborList() const { From ef32aefd44c306d7a9613d63856af9c48d6e9ba3 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 19:39:03 -0500 Subject: [PATCH 06/31] reduce the if_else loops --- cpp/locality/Voronoi.cc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index a5e6cd383..a63bb7c9b 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -49,24 +49,21 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) + { + vec3 query_point((*nq)[query_point_id]); + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + } } else { voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - } - - for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) - { - vec3 query_point((*nq)[query_point_id]); - if (radii != NULL) - { - container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); - } - else + for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { - container.put(query_point_id, query_point.x, query_point.y, query_point.z); + vec3 query_point((*nq)[query_point_id]); + container.put(query_point_id, query_point.x, query_point.y, query_point.z); } } From e80cea0c1c73013f00fb522edb326c8848ed9eb6 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 20:12:33 -0500 Subject: [PATCH 07/31] default values can only be set in header file, and give the container a point which global exists --- cpp/locality/Voronoi.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index a63bb7c9b..0fff0f738 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* radii = NULL) +void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* radii) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,9 +44,12 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); + + voro::container_periodic_base *container; + if (radii != NULL) { - voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + container = new voro::container_periodic_poly(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) @@ -57,7 +60,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra } else { - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + container = new voro::container_periodic(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) @@ -68,7 +71,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra } voro::voronoicell_neighbor cell; - voro::c_loop_all_periodic voronoi_loop(container); + voro::c_loop_all_periodic voronoi_loop(*container); std::vector face_areas; std::vector face_vertices; std::vector neighbors; @@ -80,7 +83,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra { do { - container.compute_cell(cell, voronoi_loop); + container->compute_cell(cell, voronoi_loop); // Get id and position of current particle const int query_point_id(voronoi_loop.pid()); @@ -191,6 +194,8 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra m_neighbor_list->getWeights()[bond] = bonds[bond].weight; } }); + + delete container; } }; }; // end namespace freud::locality From f5a86878ca70481d53c3ee68a2b3d4772f3adfa5 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 20:20:34 -0500 Subject: [PATCH 08/31] the way for a point to call a function is -> --- cpp/locality/Voronoi.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index 0fff0f738..e13c54fef 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -55,7 +55,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + container->put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); } } else @@ -66,7 +66,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - container.put(query_point_id, query_point.x, query_point.y, query_point.z); + container->put(query_point_id, query_point.x, query_point.y, query_point.z); } } From 133ff9279450f5cc1af96eba121648d7f48a139f Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Sat, 7 Mar 2020 19:47:30 -0500 Subject: [PATCH 09/31] use container_periodic_poly only --- cpp/locality/Voronoi.cc | 59 +++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index e13c54fef..53ea482ed 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -40,38 +40,51 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra // having to create a pre_container. This saves time because the // pre_container cannot be used to set up container_periodic (only // non-periodic containers are compatible). + // Also, we enable the weighted voronoi diagram if the weights of different + // points are provided; otherwise, the default is unbiased voronoi shapes + // calculations. float block_scale = std::pow(n_points / (voro::optimal_particles * box.getVolume()), 1.0 / 3.0); int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - voro::container_periodic_base *container; - - if (radii != NULL) - { - container = new voro::container_periodic_poly(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + // voro::container_periodic_poly *container; + voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) - { - vec3 query_point((*nq)[query_point_id]); - container->put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); - } - } - else + for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { - container = new voro::container_periodic(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, - boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, - voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) - { - vec3 query_point((*nq)[query_point_id]); - container->put(query_point_id, query_point.x, query_point.y, query_point.z); + vec3 query_point((*nq)[query_point_id]); + double radius = (radii != NULL) ? radii[query_point_id] : 0.0; + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radius); } - } + + // if (radii != NULL) + // { + // container = new voro::container_periodic_poly(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + // boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + // voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + // voro::container_periodic_poly* container_poly(dynamic_cast(container)); + // for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) + // { + // vec3 query_point((*nq)[query_point_id]); + // container_poly->put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + // } + // } + // else + // { + // container = new voro::container_periodic(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + // boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + // voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + // for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) + // { + // vec3 query_point((*nq)[query_point_id]); + // container->put(query_point_id, query_point.x, query_point.y, query_point.z); + // } + // } voro::voronoicell_neighbor cell; - voro::c_loop_all_periodic voronoi_loop(*container); + voro::c_loop_all_periodic voronoi_loop(container); std::vector face_areas; std::vector face_vertices; std::vector neighbors; @@ -83,7 +96,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra { do { - container->compute_cell(cell, voronoi_loop); + container.compute_cell(cell, voronoi_loop); // Get id and position of current particle const int query_point_id(voronoi_loop.pid()); @@ -195,7 +208,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra } }); - delete container; + // delete container; } }; }; // end namespace freud::locality From fb13e75255ee5c12c6fd651ea70f5f319a2bf7a4 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 17:49:43 -0500 Subject: [PATCH 10/31] add container_periodic_poly function --- cpp/locality/Voronoi.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index b3189f9b7..19d9f7828 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq) +void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,15 +44,25 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq) int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); + if (radii!=NULL){ + voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + } else { + voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + } for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - container.put(query_point_id, query_point.x, query_point.y, query_point.z); + if (radii!=NULL){ + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + } else{ + container.put(query_point_id, query_point.x, query_point.y, query_point.z); + } } voro::voronoicell_neighbor cell; From c78a6c10ddacd57cead286e3cb5c4ca8975cb192 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 18:09:36 -0500 Subject: [PATCH 11/31] make header files consistently --- cpp/locality/Voronoi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/locality/Voronoi.h b/cpp/locality/Voronoi.h index 77f97b82e..d62efe4a3 100644 --- a/cpp/locality/Voronoi.h +++ b/cpp/locality/Voronoi.h @@ -19,7 +19,7 @@ class Voronoi // default constructor Voronoi() : m_neighbor_list(std::make_shared()) {} - void compute(const freud::locality::NeighborQuery* nq); + void compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL); std::shared_ptr getNeighborList() const { From 71feecdffc144c50f4f4799da77549cdbbae41da Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 18:35:09 -0500 Subject: [PATCH 12/31] revert to the original for testing --- cpp/locality/Voronoi.cc | 18 ++++-------------- cpp/locality/Voronoi.h | 2 +- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index 19d9f7828..faf2f220d 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL) +void Voronoi::compute(const freud::locality::NeighborQuery* nq) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,27 +44,17 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned d int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - if (radii!=NULL){ - voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, - boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, - voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - } else { - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - } for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - if (radii!=NULL){ - container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); - } else{ - container.put(query_point_id, query_point.x, query_point.y, query_point.z); - } + container.put(query_point_id, query_point.x, query_point.y, query_point.z); } - + voro::voronoicell_neighbor cell; voro::c_loop_all_periodic voronoi_loop(container); std::vector face_areas; diff --git a/cpp/locality/Voronoi.h b/cpp/locality/Voronoi.h index d62efe4a3..77f97b82e 100644 --- a/cpp/locality/Voronoi.h +++ b/cpp/locality/Voronoi.h @@ -19,7 +19,7 @@ class Voronoi // default constructor Voronoi() : m_neighbor_list(std::make_shared()) {} - void compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL); + void compute(const freud::locality::NeighborQuery* nq); std::shared_ptr getNeighborList() const { From 9228ab474542749f6dbcee3df9980f7911f6a322 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 19:05:14 -0500 Subject: [PATCH 13/31] only polydisperse --- cpp/locality/Voronoi.cc | 26 ++++++++++++++++++-------- cpp/locality/Voronoi.h | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index faf2f220d..145066cbd 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq) +void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,17 +44,27 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq) int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, - boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, - voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - + if (radii != NULL){ + voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + } + /*else{ + voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + } +*/ for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - container.put(query_point_id, query_point.x, query_point.y, query_point.z); + if (radii != NULL){ + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + } /*else { + container.put(query_point_id, query_point.x, query_point.y, query_point.z); + }*/ } - + voro::voronoicell_neighbor cell; voro::c_loop_all_periodic voronoi_loop(container); std::vector face_areas; diff --git a/cpp/locality/Voronoi.h b/cpp/locality/Voronoi.h index 77f97b82e..d62efe4a3 100644 --- a/cpp/locality/Voronoi.h +++ b/cpp/locality/Voronoi.h @@ -19,7 +19,7 @@ class Voronoi // default constructor Voronoi() : m_neighbor_list(std::make_shared()) {} - void compute(const freud::locality::NeighborQuery* nq); + void compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL); std::shared_ptr getNeighborList() const { From a4b132314be496ad2343ded15c7bcbb78d15eb63 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 19:15:50 -0500 Subject: [PATCH 14/31] unsigned is not applied double or float. --- cpp/locality/Voronoi.cc | 25 +++++++++++++++---------- cpp/locality/Voronoi.h | 2 +- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index 145066cbd..a5e6cd383 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL) +void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* radii = NULL) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,25 +44,30 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const unsigned d int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - if (radii != NULL){ - voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + if (radii != NULL) + { + voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); } - /*else{ - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + else + { + voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); } -*/ + for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - if (radii != NULL){ - container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); - } /*else { + if (radii != NULL) + { + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + } + else + { container.put(query_point_id, query_point.x, query_point.y, query_point.z); - }*/ + } } voro::voronoicell_neighbor cell; diff --git a/cpp/locality/Voronoi.h b/cpp/locality/Voronoi.h index d62efe4a3..80c741cfc 100644 --- a/cpp/locality/Voronoi.h +++ b/cpp/locality/Voronoi.h @@ -19,7 +19,7 @@ class Voronoi // default constructor Voronoi() : m_neighbor_list(std::make_shared()) {} - void compute(const freud::locality::NeighborQuery* nq, const unsigned double* radii = NULL); + void compute(const freud::locality::NeighborQuery* nq, const double* radii = NULL); std::shared_ptr getNeighborList() const { From db1a753e4ab4414188b4f139e1562477878ac376 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 19:39:03 -0500 Subject: [PATCH 15/31] reduce the if_else loops --- cpp/locality/Voronoi.cc | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index a5e6cd383..a63bb7c9b 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -49,24 +49,21 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) + { + vec3 query_point((*nq)[query_point_id]); + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + } } else { voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - } - - for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) - { - vec3 query_point((*nq)[query_point_id]); - if (radii != NULL) - { - container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); - } - else + for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { - container.put(query_point_id, query_point.x, query_point.y, query_point.z); + vec3 query_point((*nq)[query_point_id]); + container.put(query_point_id, query_point.x, query_point.y, query_point.z); } } From 3c9523b96caa882b36bf9f1c84ee5c53bef960cb Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 20:12:33 -0500 Subject: [PATCH 16/31] default values can only be set in header file, and give the container a point which global exists --- cpp/locality/Voronoi.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index a63bb7c9b..0fff0f738 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -15,7 +15,7 @@ namespace freud { namespace locality { // Voronoi calculations should be kept in double precision. -void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* radii = NULL) +void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* radii) { auto box = nq->getBox(); auto n_points = nq->getNPoints(); @@ -44,9 +44,12 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); + + voro::container_periodic_base *container; + if (radii != NULL) { - voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + container = new voro::container_periodic_poly(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) @@ -57,7 +60,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra } else { - voro::container_periodic container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + container = new voro::container_periodic(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) @@ -68,7 +71,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra } voro::voronoicell_neighbor cell; - voro::c_loop_all_periodic voronoi_loop(container); + voro::c_loop_all_periodic voronoi_loop(*container); std::vector face_areas; std::vector face_vertices; std::vector neighbors; @@ -80,7 +83,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra { do { - container.compute_cell(cell, voronoi_loop); + container->compute_cell(cell, voronoi_loop); // Get id and position of current particle const int query_point_id(voronoi_loop.pid()); @@ -191,6 +194,8 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra m_neighbor_list->getWeights()[bond] = bonds[bond].weight; } }); + + delete container; } }; }; // end namespace freud::locality From 785f4e6dd52340e50e95340f79050aae31d78080 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Fri, 6 Mar 2020 20:20:34 -0500 Subject: [PATCH 17/31] the way for a point to call a function is -> --- cpp/locality/Voronoi.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index 0fff0f738..e13c54fef 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -55,7 +55,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - container.put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + container->put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); } } else @@ -66,7 +66,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - container.put(query_point_id, query_point.x, query_point.y, query_point.z); + container->put(query_point_id, query_point.x, query_point.y, query_point.z); } } From 689665b249a5c47cbd08b86ec39f548841c29985 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Sat, 7 Mar 2020 19:47:30 -0500 Subject: [PATCH 18/31] use container_periodic_poly only --- cpp/locality/Voronoi.cc | 59 +++++++++++++++++++++++++---------------- 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index e13c54fef..53ea482ed 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -40,38 +40,51 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra // having to create a pre_container. This saves time because the // pre_container cannot be used to set up container_periodic (only // non-periodic containers are compatible). + // Also, we enable the weighted voronoi diagram if the weights of different + // points are provided; otherwise, the default is unbiased voronoi shapes + // calculations. float block_scale = std::pow(n_points / (voro::optimal_particles * box.getVolume()), 1.0 / 3.0); int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - voro::container_periodic_base *container; - - if (radii != NULL) - { - container = new voro::container_periodic_poly(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + // voro::container_periodic_poly *container; + voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) - { - vec3 query_point((*nq)[query_point_id]); - container->put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); - } - } - else + for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { - container = new voro::container_periodic(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, - boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, - voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) - { - vec3 query_point((*nq)[query_point_id]); - container->put(query_point_id, query_point.x, query_point.y, query_point.z); + vec3 query_point((*nq)[query_point_id]); + double radius = (radii != NULL) ? radii[query_point_id] : 0.0; + container.put(query_point_id, query_point.x, query_point.y, query_point.z, radius); } - } + + // if (radii != NULL) + // { + // container = new voro::container_periodic_poly(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + // boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + // voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + // voro::container_periodic_poly* container_poly(dynamic_cast(container)); + // for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) + // { + // vec3 query_point((*nq)[query_point_id]); + // container_poly->put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); + // } + // } + // else + // { + // container = new voro::container_periodic(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, + // boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, + // voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + // for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) + // { + // vec3 query_point((*nq)[query_point_id]); + // container->put(query_point_id, query_point.x, query_point.y, query_point.z); + // } + // } voro::voronoicell_neighbor cell; - voro::c_loop_all_periodic voronoi_loop(*container); + voro::c_loop_all_periodic voronoi_loop(container); std::vector face_areas; std::vector face_vertices; std::vector neighbors; @@ -83,7 +96,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra { do { - container->compute_cell(cell, voronoi_loop); + container.compute_cell(cell, voronoi_loop); // Get id and position of current particle const int query_point_id(voronoi_loop.pid()); @@ -195,7 +208,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra } }); - delete container; + // delete container; } }; }; // end namespace freud::locality From 370158aafd5d25e915763cb64cf793ca3a03ca6a Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Thu, 12 Mar 2020 11:48:55 -0400 Subject: [PATCH 19/31] Intermediate commit with fixes --- freud/_locality.pxd | 3 ++- freud/locality.pxd | 1 + freud/locality.pyx | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/freud/_locality.pxd b/freud/_locality.pxd index 78ed7ba17..d54a12cd3 100644 --- a/freud/_locality.pxd +++ b/freud/_locality.pxd @@ -135,7 +135,8 @@ cdef extern from "PeriodicBuffer.h" namespace "freud::locality": cdef extern from "Voronoi.h" namespace "freud::locality": cdef cppclass Voronoi: Voronoi() - void compute(const NeighborQuery*) nogil except + + void compute(const NeighborQuery*, + const double*) nogil except + vector[vector[vec3[double]]] getPolytopes() const const freud.util.ManagedArray[double] &getVolumes() const shared_ptr[NeighborList] getNeighborList() const diff --git a/freud/locality.pxd b/freud/locality.pxd index ef4b0e6d8..5dda697b1 100644 --- a/freud/locality.pxd +++ b/freud/locality.pxd @@ -78,3 +78,4 @@ cdef class Voronoi(_Compute): cdef freud._locality.Voronoi * thisptr cdef NeighborList _nlist cdef freud.box.Box _box + cdef double radii diff --git a/freud/locality.pyx b/freud/locality.pyx index df1e3028f..849b17c8f 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1120,7 +1120,7 @@ cdef class Voronoi(_Compute): def __dealloc__(self): del self.thisptr - def compute(self, system): + def compute(self, system, radii=None): R"""Compute Voronoi diagram. Args: @@ -1129,8 +1129,10 @@ cdef class Voronoi(_Compute): :class:`freud.locality.NeighborQuery.from_system`. """ cdef NeighborQuery nq = NeighborQuery.from_system(system) - self.thisptr.compute(nq.get_ptr()) self._box = nq.box + radii = self.radii if radii is not None else np.zeros(nq.positions.shape[0]) + cdef np.float32_t[::1] l_radii = radii + self.thisptr.compute(nq.get_ptr(), &l_radii[0]) return self @_Compute._computed_property From ab3f73f1c36bac7fd19d69a941e2e8a5377215ff Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Wed, 18 Mar 2020 19:03:43 -0400 Subject: [PATCH 20/31] resolve the variable type problem --- freud/locality.pyx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index 849b17c8f..d3f44508e 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1130,9 +1130,9 @@ cdef class Voronoi(_Compute): """ cdef NeighborQuery nq = NeighborQuery.from_system(system) self._box = nq.box - radii = self.radii if radii is not None else np.zeros(nq.positions.shape[0]) - cdef np.float32_t[::1] l_radii = radii - self.thisptr.compute(nq.get_ptr(), &l_radii[0]) + radii = self.radii if radii is not None else np.zeros(nq.positions.shape[0], dtype=np.float32) + cdef double[::1] l_radii = radii + self.thisptr.compute(nq.get_ptr(), &l_radii[0]) return self @_Compute._computed_property From 0ce8d91cd10ff03efdae044c74f51a54e9c1266c Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Wed, 18 Mar 2020 19:11:02 -0400 Subject: [PATCH 21/31] wrap long lines --- freud/locality.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index d3f44508e..0edce5c86 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1130,7 +1130,8 @@ cdef class Voronoi(_Compute): """ cdef NeighborQuery nq = NeighborQuery.from_system(system) self._box = nq.box - radii = self.radii if radii is not None else np.zeros(nq.positions.shape[0], dtype=np.float32) + radii = self.radii if radii is not None \ + else np.zeros(nq.positions.shape[0], dtype=double) cdef double[::1] l_radii = radii self.thisptr.compute(nq.get_ptr(), &l_radii[0]) return self From cd65474b28dc0f3265458efe5ed9619494ca5700 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Wed, 18 Mar 2020 19:39:54 -0400 Subject: [PATCH 22/31] variable type --- freud/locality.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index 0edce5c86..14acf28a6 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1130,8 +1130,8 @@ cdef class Voronoi(_Compute): """ cdef NeighborQuery nq = NeighborQuery.from_system(system) self._box = nq.box - radii = self.radii if radii is not None \ - else np.zeros(nq.positions.shape[0], dtype=double) + radii = self.radii if radii is not None\ + else np.zeros(nq.positions.shape[0], dtype=np.float32) cdef double[::1] l_radii = radii self.thisptr.compute(nq.get_ptr(), &l_radii[0]) return self From f17ab2a5ba24b9381d366f92f8f6b85b4ab31772 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Wed, 18 Mar 2020 21:49:56 -0400 Subject: [PATCH 23/31] variable type correction --- freud/locality.pyx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index 14acf28a6..3b171e4c6 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1131,7 +1131,7 @@ cdef class Voronoi(_Compute): cdef NeighborQuery nq = NeighborQuery.from_system(system) self._box = nq.box radii = self.radii if radii is not None\ - else np.zeros(nq.positions.shape[0], dtype=np.float32) + else np.zeros(nq.points.shape[0], dtype = np.float64) cdef double[::1] l_radii = radii self.thisptr.compute(nq.get_ptr(), &l_radii[0]) return self From d1de530d85265de5e37fcf843769a1ceff8fe221 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Wed, 18 Mar 2020 23:01:45 -0400 Subject: [PATCH 24/31] finalize the format --- cpp/locality/Voronoi.cc | 29 +---------------------------- freud/locality.pxd | 1 - freud/locality.pyx | 8 +++++--- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index 53ea482ed..824fa8de7 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -40,7 +40,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra // having to create a pre_container. This saves time because the // pre_container cannot be used to set up container_periodic (only // non-periodic containers are compatible). - // Also, we enable the weighted voronoi diagram if the weights of different + // Also, we enable the weighted voronoi diagram if the sizes of different // points are provided; otherwise, the default is unbiased voronoi shapes // calculations. float block_scale = std::pow(n_points / (voro::optimal_particles * box.getVolume()), 1.0 / 3.0); @@ -48,7 +48,6 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - // voro::container_periodic_poly *container; voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); @@ -59,30 +58,6 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra container.put(query_point_id, query_point.x, query_point.y, query_point.z, radius); } - // if (radii != NULL) - // { - // container = new voro::container_periodic_poly(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, - // boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, - // voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - // voro::container_periodic_poly* container_poly(dynamic_cast(container)); - // for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) - // { - // vec3 query_point((*nq)[query_point_id]); - // container_poly->put(query_point_id, query_point.x, query_point.y, query_point.z, radii[query_point_id]); - // } - // } - // else - // { - // container = new voro::container_periodic(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, - // boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, - // voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); - // for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) - // { - // vec3 query_point((*nq)[query_point_id]); - // container->put(query_point_id, query_point.x, query_point.y, query_point.z); - // } - // } - voro::voronoicell_neighbor cell; voro::c_loop_all_periodic voronoi_loop(container); std::vector face_areas; @@ -207,8 +182,6 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra m_neighbor_list->getWeights()[bond] = bonds[bond].weight; } }); - - // delete container; } }; }; // end namespace freud::locality diff --git a/freud/locality.pxd b/freud/locality.pxd index 5dda697b1..ef4b0e6d8 100644 --- a/freud/locality.pxd +++ b/freud/locality.pxd @@ -78,4 +78,3 @@ cdef class Voronoi(_Compute): cdef freud._locality.Voronoi * thisptr cdef NeighborList _nlist cdef freud.box.Box _box - cdef double radii diff --git a/freud/locality.pyx b/freud/locality.pyx index 3b171e4c6..a3de248c8 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1130,10 +1130,12 @@ cdef class Voronoi(_Compute): """ cdef NeighborQuery nq = NeighborQuery.from_system(system) self._box = nq.box - radii = self.radii if radii is not None\ - else np.zeros(nq.points.shape[0], dtype = np.float64) + if radii is None: + radii = np.zeros(len(nq.points), dtype=np.float64) + radii = freud.util._convert_array(radii, shape=(len(nq.points),), \ + dtype=np.float64) cdef double[::1] l_radii = radii - self.thisptr.compute(nq.get_ptr(), &l_radii[0]) + self.thisptr.compute(nq.get_ptr(), &l_radii[0]) return self @_Compute._computed_property From 56458a8e02275df5a74bf109390037b129adb756 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Wed, 18 Mar 2020 23:49:07 -0400 Subject: [PATCH 25/31] flake8 formatted --- freud/locality.pyx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index a3de248c8..63ddb3905 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1132,8 +1132,10 @@ cdef class Voronoi(_Compute): self._box = nq.box if radii is None: radii = np.zeros(len(nq.points), dtype=np.float64) - radii = freud.util._convert_array(radii, shape=(len(nq.points),), \ - dtype=np.float64) + radii = freud.util._convert_array( + radii, + shape=(len(nq.points),), + dtype=np.float64) cdef double[::1] l_radii = radii self.thisptr.compute(nq.get_ptr(), &l_radii[0]) return self From 376ff30ab62213cbd02321c66f196bbb01eaa554 Mon Sep 17 00:00:00 2001 From: yuanzhou Date: Thu, 19 Mar 2020 13:25:14 -0400 Subject: [PATCH 26/31] docstring added --- freud/locality.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/freud/locality.pyx b/freud/locality.pyx index 63ddb3905..c68727129 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1127,6 +1127,10 @@ cdef class Voronoi(_Compute): system: Any object that is a valid argument to :class:`freud.locality.NeighborQuery.from_system`. + radii: + A list of :class:`numpy.ndarray` defining radii of points in + the system. (Default value = :code:`None`, meaning unbiased + Voronoi diagram.) """ cdef NeighborQuery nq = NeighborQuery.from_system(system) self._box = nq.box From e1655316dc3db53e0ed7e0a7ddef025892ceb40e Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 6 Nov 2020 15:08:44 -0600 Subject: [PATCH 27/31] Apply suggestions from code review --- freud/locality.pyx | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index 3ef558b64..baf3c63f5 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1168,14 +1168,13 @@ cdef class Voronoi(_Compute): """ cdef NeighborQuery nq = NeighborQuery.from_system(system) self._box = nq.box - if radii is None: - radii = np.zeros(len(nq.points), dtype=np.float64) - radii = freud.util._convert_array( - radii, - shape=(len(nq.points),), - dtype=np.float64) - cdef double[::1] l_radii = radii - self.thisptr.compute(nq.get_ptr(), &l_radii[0]) + cdef double* l_radii_ptr = NULL + cdef double[::1] l_radii + if radii is not None: + l_radii = freud.util._convert_array( + radii, shape=(len(nq.points),), dtype=np.float64) + l_radii_ptr = &l_radii[0] + self.thisptr.compute(nq.get_ptr(), l_radii_ptr) return self @_Compute._computed_property From 75a655152833e963b5feb2e0f85e08c2e8df81ff Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 6 Nov 2020 15:08:56 -0600 Subject: [PATCH 28/31] Apply suggestions from code review --- freud/locality.pyx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/freud/locality.pyx b/freud/locality.pyx index baf3c63f5..e6e7d7525 100644 --- a/freud/locality.pyx +++ b/freud/locality.pyx @@ -1161,10 +1161,11 @@ cdef class Voronoi(_Compute): system: Any object that is a valid argument to :class:`freud.locality.NeighborQuery.from_system`. - radii: - A list of :class:`numpy.ndarray` defining radii of points in - the system. (Default value = :code:`None`, meaning unbiased - Voronoi diagram.) + radii ((:math:`N_{points}`) :class:`numpy.ndarray`): + An array of radii for each point in the system. If provided, + the power diagram (also called the radical Voronoi + tessellation) will be computed (Default value = :code:`None`, + which gives the Voronoi diagram). """ cdef NeighborQuery nq = NeighborQuery.from_system(system) self._box = nq.box From 2fb9d47cd493eb553ceabc3cab6ae204f7a093e5 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 6 Nov 2020 15:09:30 -0600 Subject: [PATCH 29/31] Use nullptr. --- cpp/locality/Voronoi.cc | 2 +- cpp/locality/Voronoi.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index 0008642d1..050a9150e 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -54,7 +54,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { vec3 query_point((*nq)[query_point_id]); - double radius = (radii != NULL) ? radii[query_point_id] : 0.0; + double radius = (radii != nullptr) ? radii[query_point_id] : 0.0; container.put(query_point_id, query_point.x, query_point.y, query_point.z, radius); } diff --git a/cpp/locality/Voronoi.h b/cpp/locality/Voronoi.h index 8c3e6f5af..533fa39fa 100644 --- a/cpp/locality/Voronoi.h +++ b/cpp/locality/Voronoi.h @@ -19,7 +19,7 @@ class Voronoi // default constructor Voronoi() : m_neighbor_list(std::make_shared()) {} - void compute(const freud::locality::NeighborQuery* nq, const double* radii = NULL); + void compute(const freud::locality::NeighborQuery* nq, const double* radii = nullptr); std::shared_ptr getNeighborList() const { From affde157fa5f720dca3e7f643360c9ac51064e8c Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Fri, 6 Nov 2020 15:14:02 -0600 Subject: [PATCH 30/31] Update comments and clang-format. --- cpp/locality/Voronoi.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index 050a9150e..0c82da943 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -40,23 +40,24 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra // having to create a pre_container. This saves time because the // pre_container cannot be used to set up container_periodic (only // non-periodic containers are compatible). - // Also, we enable the weighted voronoi diagram if the sizes of different - // points are provided; otherwise, the default is unbiased voronoi shapes - // calculations. float block_scale = std::pow(n_points / (voro::optimal_particles * box.getVolume()), 1.0 / 3.0); int voro_blocks_x = int(box.getLx() * block_scale + 1); int voro_blocks_y = int(box.getLy() * block_scale + 1); int voro_blocks_z = int(box.getLz() * block_scale + 1); - voro::container_periodic_poly container(boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, - boxLatticeVectors[2].x, boxLatticeVectors[2].y, boxLatticeVectors[2].z, - voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); + voro::container_periodic_poly container( + boxLatticeVectors[0].x, boxLatticeVectors[1].x, boxLatticeVectors[1].y, boxLatticeVectors[2].x, + boxLatticeVectors[2].y, boxLatticeVectors[2].z, voro_blocks_x, voro_blocks_y, voro_blocks_z, 3); for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) { + // If an array of radii is provided, those radii are used to compute + // the power diagram (also called the radical Voronoi tessellation). If + // a nullptr is provided, then the points are assumed to have zero + // radius. vec3 query_point((*nq)[query_point_id]); double radius = (radii != nullptr) ? radii[query_point_id] : 0.0; container.put(query_point_id, query_point.x, query_point.y, query_point.z, radius); - } + } voro::voronoicell_neighbor cell; voro::c_loop_all_periodic voronoi_loop(container); From ddf0e9e0a335659e581906edbce3a8362b429d65 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 21 Nov 2021 20:35:09 +0000 Subject: [PATCH 31/31] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- cpp/locality/Voronoi.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cpp/locality/Voronoi.cc b/cpp/locality/Voronoi.cc index e2d4846bd..35e58c733 100644 --- a/cpp/locality/Voronoi.cc +++ b/cpp/locality/Voronoi.cc @@ -40,7 +40,7 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq, const double* ra const int voro_blocks_z = int(box.getLz() * block_scale + 1); voro::container_periodic_poly container(v1.x, v2.x, v2.y, v3.x, v3.y, v3.z, voro_blocks_x, voro_blocks_y, - voro_blocks_z, 3); + voro_blocks_z, 3); for (size_t query_point_id = 0; query_point_id < n_points; query_point_id++) {