Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add biased voronoi cells feature #593

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
344d6de
add container_periodic_poly function
yuanzhou0827 Mar 6, 2020
6d85975
make header files consistently
yuanzhou0827 Mar 6, 2020
5969de0
revert to the original for testing
yuanzhou0827 Mar 6, 2020
618d3e1
only polydisperse
yuanzhou0827 Mar 7, 2020
40e899c
unsigned is not applied double or float.
yuanzhou0827 Mar 7, 2020
ef32aef
reduce the if_else loops
yuanzhou0827 Mar 7, 2020
e80cea0
default values can only be set in header file, and give the container…
yuanzhou0827 Mar 7, 2020
f5a8687
the way for a point to call a function is ->
yuanzhou0827 Mar 7, 2020
133ff92
use container_periodic_poly only
yuanzhou0827 Mar 8, 2020
fb13e75
add container_periodic_poly function
yuanzhou0827 Mar 6, 2020
c78a6c1
make header files consistently
yuanzhou0827 Mar 6, 2020
71feecd
revert to the original for testing
yuanzhou0827 Mar 6, 2020
9228ab4
only polydisperse
yuanzhou0827 Mar 7, 2020
a4b1323
unsigned is not applied double or float.
yuanzhou0827 Mar 7, 2020
db1a753
reduce the if_else loops
yuanzhou0827 Mar 7, 2020
3c9523b
default values can only be set in header file, and give the container…
yuanzhou0827 Mar 7, 2020
785f4e6
the way for a point to call a function is ->
yuanzhou0827 Mar 7, 2020
689665b
use container_periodic_poly only
yuanzhou0827 Mar 8, 2020
370158a
Intermediate commit with fixes
yuanzhou0827 Mar 12, 2020
98009ba
Merge branch 'bias_vor' of https://github.com/glotzerlab/freud into b…
yuanzhou0827 Mar 16, 2020
ab3f73f
resolve the variable type problem
yuanzhou0827 Mar 18, 2020
0ce8d91
wrap long lines
yuanzhou0827 Mar 18, 2020
cd65474
variable type
yuanzhou0827 Mar 18, 2020
f17ab2a
variable type correction
yuanzhou0827 Mar 19, 2020
d1de530
finalize the format
yuanzhou0827 Mar 19, 2020
56458a8
flake8 formatted
yuanzhou0827 Mar 19, 2020
376ff30
docstring added
yuanzhou0827 Mar 19, 2020
030d95f
Merge remote-tracking branch 'origin/master' into bias_vor
bdice Nov 6, 2020
e165531
Apply suggestions from code review
bdice Nov 6, 2020
75a6551
Apply suggestions from code review
bdice Nov 6, 2020
2fb9d47
Use nullptr.
bdice Nov 6, 2020
affde15
Update comments and clang-format.
bdice Nov 6, 2020
c1d032a
Merge branch 'master' into bias_vor
bdice Nov 21, 2021
ddf0e9e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2021
d4e5e6c
Merge branch 'master' into bias_vor
yuanzhou0827 Jan 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions cpp/locality/Voronoi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,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 double* radii)
{
const auto box = nq->getBox();
const auto n_points = nq->getNPoints();
Expand All @@ -39,13 +39,18 @@ void Voronoi::compute(const freud::locality::NeighborQuery* nq)
const int voro_blocks_y = int(box.getLy() * block_scale + 1);
const int voro_blocks_z = int(box.getLz() * block_scale + 1);

voro::container_periodic container(v1.x, v2.x, v2.y, v3.x, v3.y, v3.z, voro_blocks_x, voro_blocks_y,
voro_blocks_z, 3);
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);

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<double> query_point((*nq)[query_point_id]);
yuanzhou0827 marked this conversation as resolved.
Show resolved Hide resolved
container.put(query_point_id, query_point.x, query_point.y, query_point.z);
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;
Expand Down
2 changes: 1 addition & 1 deletion cpp/locality/Voronoi.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Voronoi
// default constructor
Voronoi() : m_neighbor_list(std::make_shared<NeighborList>()) {}

void compute(const freud::locality::NeighborQuery* nq);
void compute(const freud::locality::NeighborQuery* nq, const double* radii = nullptr);

std::shared_ptr<NeighborList> getNeighborList() const
{
Expand Down
3 changes: 2 additions & 1 deletion freud/_locality.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,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
15 changes: 13 additions & 2 deletions freud/locality.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1162,17 +1162,28 @@ cdef class Voronoi(_Compute):
def __dealloc__(self):
del self.thisptr

def compute(self, system):
def compute(self, system, radii=None):
r"""Compute Voronoi diagram.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to add a longer description of Voronoi diagrams and how this feature works. I think it might go best in the class docstring. It should include external links, formulas/equations, and descriptions of why someone would want to use this feature. It's important to include the several names for this feature so that it can be found via Google / documentation search. Please verify what type of weighted Voronoi diagram we are computing (additively weighted, multiplicatively weighted, or something else?), and cite whatever references you can find. You may need to refer to the voro++ documentation.

Args:
system:
Any object that is a valid argument to
:class:`freud.locality.NeighborQuery.from_system`.
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.thisptr.compute(nq.get_ptr())
self._box = nq.box
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
Expand Down