Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion hoomd-manifold/src/sphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<const N: usize> Spherical<N> {
#[inline]
#[must_use]
pub fn from_cartesian_coordinates(point: Cartesian<N>) -> Spherical<N> {
let rad = point.norm();
let rad = point.norm_squared();
assert_relative_eq!(rad, 1.0_f64, epsilon = 1e-6);
Spherical { point }
}
Expand Down
55 changes: 54 additions & 1 deletion hoomd-mc/src/hypercuboid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use serde_with::serde_as;
use std::array;

use hoomd_geometry::shape::Hypercuboid;
use hoomd_microstate::boundary::{Closed, Periodic};
use hoomd_manifold::Spherical;
use hoomd_microstate::boundary::{Closed, OpenSpherical, Periodic};
use hoomd_utility::valid::PositiveReal;
use hoomd_vector::Cartesian;

Expand Down Expand Up @@ -136,6 +137,26 @@ impl<const N: usize> Checkerboard<Cartesian<N>> for HypercuboidCheckerboard<N> {
}
}

impl<const N: usize> Checkerboard<Spherical<N>> for HypercuboidCheckerboard<N> {
#[inline]
fn point_to_space_index(&self, point: &Spherical<N>) -> Option<usize> {
<Self as Checkerboard<Cartesian<N>>>::point_to_space_index(
self,
&Cartesian::from(*point.coordinates()),
)
}

#[inline]
fn space_indices_by_color(&self) -> &[Vec<usize>] {
<Self as Checkerboard<Cartesian<N>>>::space_indices_by_color(self)
}

#[inline]
fn num_spaces(&self) -> usize {
<Self as Checkerboard<Cartesian<N>>>::num_spaces(self)
}
}

impl<const N: usize> HypercuboidCheckerboard<N> {
/// Collapse a multi-dimensional index to a single value in `[0, num_spaces]`.
#[inline]
Expand Down Expand Up @@ -366,6 +387,38 @@ impl<const N: usize> Cover<Cartesian<N>> for Periodic<Hypercuboid<N>> {
}
}

impl<const N: usize> Cover<Spherical<N>> for OpenSpherical<N> {
type Checkerboard = HypercuboidCheckerboard<N>;
#[inline]
fn cover<R: Rng + ?Sized>(
&self,
rng: &mut R,
interaction_range: PositiveReal,
) -> Self::Checkerboard {
HypercuboidCheckerboard::new(
rng,
interaction_range,
[2.0.try_into().expect("hard-coded positive number"); N],
[false; N],
)
}

#[inline]
fn cover_into<R: Rng + ?Sized>(
&self,
checkerboard: &mut Self::Checkerboard,
rng: &mut R,
interaction_range: PositiveReal,
) {
checkerboard.update(
rng,
interaction_range,
[2.0.try_into().expect("hard-coded positive number"); N],
[false; N],
);
}
}

#[cfg(test)]
mod tests {
use assert2::{assert, check};
Expand Down
2 changes: 2 additions & 0 deletions hoomd-microstate/src/boundary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ use thiserror::Error;

mod closed;
mod open;
mod open_spherical;
mod periodic;

pub use closed::Closed;
pub use open::Open;
pub use open_spherical::OpenSpherical;
pub use periodic::Periodic;

/// Enumerate possible sources of error in fallible boundary methods.
Expand Down
60 changes: 60 additions & 0 deletions hoomd-microstate/src/boundary/open_spherical.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright (c) 2024-2026 The Regents of the University of Michigan.
// Part of hoomd-rs, released under the BSD 3-Clause License.

//! Implement `OpenSpherical`

use arrayvec::ArrayVec;
use serde::{Deserialize, Serialize};

use super::{Error, GenerateGhosts, MAX_GHOSTS, Wrap};
use crate::property::Position;
use hoomd_manifold::Spherical;

/// [`OpenSpherical<N>`] implements a hypercubic box enclosing a unit-radius
/// $`(N-1)`$-sphere. Use `OpenSpherical` alongside [`SphericalVecCell`] to
/// implement [`ParallelSweep`] for [`Spherical`] bodies. `OpenSpherical` is
/// otherwise functionally identical to using [`Open`] for [`Spherical`]
/// simulations.
///
/// # Example
/// ```
/// use hoomd_microstate::boundary::OpenSpherical;
///
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
/// let closed_spherical: OpenSpherical<3> = OpenSpherical {};
/// # Ok(())
/// # }
/// ```
///
/// Similar to [`Open`], `OpenSpherical` does not wrap bodies and sites,
/// nor does it generate ghost sites.
///
/// [`SphericalVecCell`]: hoomd_spatial::SphericalVecCell;
/// [`ParallelSweep`]: hoomd_mc::ParallelSweep;
/// [`Spherical`]: hoomd_manifold::Spherical;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct OpenSpherical<const N: usize> {}

impl<BS, const N: usize> Wrap<BS> for OpenSpherical<N>
where
BS: Position<Position = Spherical<N>>,
{
#[inline]
fn wrap(&self, properties: BS) -> Result<BS, Error> {
Ok(properties)
}
}

impl<S, const N: usize> GenerateGhosts<S> for OpenSpherical<N>
where
S: Default,
{
#[inline]
fn maximum_interaction_range(&self) -> f64 {
std::f64::consts::PI
}
#[inline]
fn generate_ghosts(&self, _site_properties: &S) -> ArrayVec<S, MAX_GHOSTS> {
ArrayVec::new()
}
}
2 changes: 2 additions & 0 deletions hoomd-spatial/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ rustc-hash.workspace = true
serde.workspace = true
serde_with.workspace = true

hoomd-manifold.workspace = true
hoomd-vector.workspace = true
hoomd-utility.workspace = true

[dev-dependencies]
approxim.workspace = true
assert2.workspace = true
rand.workspace = true
rstest.workspace = true
2 changes: 2 additions & 0 deletions hoomd-spatial/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ use hoomd_utility::valid::PositiveReal;

mod all_pairs;
mod hash_cell;
mod spherical_vec_cell;
mod vec_cell;

pub use all_pairs::AllPairs;
pub use hash_cell::{HashCell, HashCellBuilder};
pub use spherical_vec_cell::{SphericalVecCell, SphericalVecCellBuilder};
pub use vec_cell::{VecCell, VecCellBuilder};

/// Allow incremental updates to points in the spatial data.
Expand Down
Loading