Skip to content

Commit 543c924

Browse files
authored
Merge pull request #69 from stochasticHydroTools/deterministic_drift
Deterministic thermal drift tests
2 parents c871026 + eb3090c commit 543c924

8 files changed

Lines changed: 181 additions & 145 deletions

File tree

include/MobilityInterface/random_finite_differences.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ template <typename Mdot>
3131
void random_finite_differences(Mdot mdot, device_span<const real> positions,
3232
device_span<real> ilinear,
3333
device_span<real> iangular, uint seed,
34-
real prefactor = 1) {
35-
constexpr real delta = 1e-3;
34+
const real delta, real prefactor = 1) {
3635
const uint N = ilinear.size() / 3;
3736
using device_vector =
3837
thrust::device_vector<real, allocator::thrust_cached_allocator<real>>;

solvers/DPStokes/extra/uammd_interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct PyParameters {
3131
real zmin, zmax;
3232
// Tolerance will be ignored in DP mode, TP will use only tolerance and nxy/nz
3333
real tolerance = 1e-5;
34+
real delta = 1e-3; // RFD step size
3435
real w, w_d;
3536
real hydrodynamicRadius = -1;
3637
real3 beta = {-1.0, -1.0, -1.0};

solvers/DPStokes/mobility.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,9 @@ class DPStokes : public libmobility::Mobility {
222222
uint seed = rng();
223223
device_vector thermal_drift_m(ilinear.size(), 0);
224224
device_vector thermal_drift_d(iangular.size(), 0);
225-
libmobility::random_finite_differences(mdot, original_pos, thermal_drift_m,
226-
thermal_drift_d, seed, prefactor);
225+
libmobility::random_finite_differences(
226+
mdot, original_pos, thermal_drift_m, thermal_drift_d, seed,
227+
this->dppar.delta * this->dppar.hydrodynamicRadius, prefactor);
227228
this->setPositions(original_pos);
228229
thrust::transform(thrust::cuda::par, thermal_drift_m.begin(),
229230
thermal_drift_m.end(), linear.begin(), linear.begin(),

solvers/DPStokes/python_wrapper.cu

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ zmax : float
2222
The maximum value of the z coordinate. This is the position of the top wall if the Z periodicity is `two_walls`.
2323
allowChangingBoxSize : bool
2424
Whether the periodic extents Lx & Ly can be modified during parameter selection. Default: false.
25+
delta : float
26+
The finite difference step size for random finite differences. Specified in units of hydrodynamicRadius. Default is 1e-3.
2527
)pbdoc";
2628

2729
static const char *docstring = R"pbdoc(
@@ -35,18 +37,20 @@ The periodicity must be set to `periodic` in the X and Y directions. The Z perio
3537
)pbdoc";
3638

3739
MOBILITY_PYTHONIFY_WITH_EXTRA_CODE(
38-
DPStokes, solver.def(
39-
"setParameters",
40-
[](DPStokes &self, real Lx, real Ly, real zmin, real zmax,
41-
bool allowChangingBoxSize) {
42-
DPStokesParameters params;
43-
params.Lx = Lx;
44-
params.Ly = Ly;
45-
params.zmin = zmin;
46-
params.zmax = zmax;
47-
params.allowChangingBoxSize = allowChangingBoxSize;
48-
self.setParametersDPStokes(params);
49-
},
50-
"Lx"_a, "Ly"_a, "zmin"_a, "zmax"_a,
51-
"allowChangingBoxSize"_a = false, setparameters_docstring);
40+
DPStokes,
41+
solver.def(
42+
"setParameters",
43+
[](DPStokes &self, real Lx, real Ly, real zmin, real zmax,
44+
bool allowChangingBoxSize, real delta) {
45+
DPStokesParameters params;
46+
params.Lx = Lx;
47+
params.Ly = Ly;
48+
params.zmin = zmin;
49+
params.zmax = zmax;
50+
params.allowChangingBoxSize = allowChangingBoxSize;
51+
params.delta = delta;
52+
self.setParametersDPStokes(params);
53+
},
54+
"Lx"_a, "Ly"_a, "zmin"_a, "zmax"_a, "allowChangingBoxSize"_a = false,
55+
"delta"_a = 1e-3, setparameters_docstring);
5256
, docstring);

solvers/NBody/mobility.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class NBody : public libmobility::Mobility {
2828
nbody_rpy::algorithm algorithm = nbody_rpy::algorithm::advise;
2929

3030
real wallHeight; // location of the wall in z
31+
real delta; // finite difference step size for random finite differences
3132

3233
// Batched functionality configuration
3334
int Nbatch = -1;
@@ -53,6 +54,7 @@ class NBody : public libmobility::Mobility {
5354
int Nbatch = -1;
5455
int NperBatch = -1;
5556
std::optional<real> wallHeight = std::nullopt;
57+
real delta = 1e-3; // in units of particle radius
5658
};
5759
/**
5860
* @brief Sets the parameters for the N-body computation
@@ -94,6 +96,7 @@ class NBody : public libmobility::Mobility {
9496
"you want to use a wall, set periodicityZ to single_wall in the "
9597
"configuration.");
9698
}
99+
this->delta = par.delta;
97100
}
98101

99102
void initialize(Parameters ipar) override {
@@ -195,8 +198,9 @@ class NBody : public libmobility::Mobility {
195198
device_vector thermal_drift_m(ilinear.size(), 0);
196199
device_vector thermal_drift_d(iangular.size(), 0);
197200

198-
libmobility::random_finite_differences(mdot, original_pos, thermal_drift_m,
199-
thermal_drift_d, seed, prefactor);
201+
libmobility::random_finite_differences(
202+
mdot, original_pos, thermal_drift_m, thermal_drift_d, seed,
203+
this->delta * this->hydrodynamicRadius, prefactor);
200204
device_adapter<real> linear(ilinear, device::cuda);
201205
this->setPositions(original_pos);
202206
thrust::transform(thrust::cuda::par, thermal_drift_m.begin(),

solvers/NBody/python_wrapper.cu

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55
#include <nanobind/stl/optional.h>
66

77
static const char *docstringSetParameters = R"pbdoc(
8-
Set the parameters for the NBody solver.
8+
Set the parameters for the NBody solver.
99
10-
Parameters
11-
----------
12-
algorithm : str
13-
The algorithm to use. Options are "naive", "fast", "block" and "advise". Default is "advise".
14-
NBatch : int
15-
The number of batches to use. If -1 (default), the number of batches is automatically determined.
16-
NperBatch : int
17-
The number of particles per batch. If -1 (default), the number of particles per batch is automatically determined.
18-
wallHeight : float
19-
The height of the wall. Only valid if periodicityZ is single_wall.
20-
)pbdoc";
10+
Parameters
11+
----------
12+
algorithm : str
13+
The algorithm to use. Options are "naive", "fast", "block" and "advise". Default is "advise".
14+
NBatch : int
15+
The number of batches to use. If -1 (default), the number of batches is automatically determined.
16+
NperBatch : int
17+
The number of particles per batch. If -1 (default), the number of particles per batch is automatically determined.
18+
wallHeight : float
19+
The height of the wall. Only valid if periodicityZ is single_wall.
20+
delta : float
21+
The finite difference step size for random finite differences. Specified in units of hydrodynamicRadius. Default is 1e-3.
22+
)pbdoc";
2123

2224
static const char *docstring = R"pbdoc(
2325
This module computes hydrodynamic interactions using an :math:`O(N^2)` algorithm.
@@ -50,10 +52,10 @@ MOBILITY_PYTHONIFY_WITH_EXTRA_CODE(
5052
solver.def(
5153
"setParameters",
5254
[](NBody &myself, std::string algo, int NBatch, int NperBatch,
53-
std::optional<real> wallHeight) {
55+
std::optional<real> wallHeight, real delta) {
5456
myself.setParametersNBody({nbody_rpy::string2NBodyAlgorithm(algo),
55-
NBatch, NperBatch, wallHeight});
57+
NBatch, NperBatch, wallHeight, delta});
5658
},
5759
docstringSetParameters, "algorithm"_a = "advise", "Nbatch"_a = -1,
58-
"NperBatch"_a = -1, "wallHeight"_a = std::nullopt);
60+
"NperBatch"_a = -1, "wallHeight"_a = std::nullopt, "delta"_a = 1e-3);
5961
, docstring);

0 commit comments

Comments
 (0)