Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit ac2b405
Author: Ryker Fish <rfish@mines.edu>
Date:   Tue Jul 16 19:41:16 2024 -0600

    regenerated data w new defaults after verifying against old repository

commit 07b4794
Author: Ryker Fish <rfish@mines.edu>
Date:   Tue Jul 16 19:05:08 2024 -0600

    added parameter to initialize that sets whether the box size can get altered or not

commit 447e543
Author: Ryker Fish <rfish@mines.edu>
Date:   Tue Jul 16 18:22:27 2024 -0600

    added mode that preserves L

commit 74ec436
Author: Ryker Fish <rfish@mines.edu>
Date:   Tue Jul 16 17:23:24 2024 -0600

    checkpoint commit- adding functionality to have parameter select that modifies the box size and another version that preserves it

commit 1113390
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed Jul 10 14:59:33 2024 -0600

    the changes to DPStokes parameters seem to made the mobility matrix less symmetric

commit 800f634
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed Jul 10 14:56:08 2024 -0600

    had to change the ref file to use the right positions. nbody test working.

commit 830866e
Author: Ryker Fish <rfish@mines.edu>
Date:   Mon Jul 8 18:46:51 2024 -0600

    the two pair DPStokes tests are passing. currently having issues with the nbody test

commit 9b3a4d3
Author: Ryker Fish <rfish@mines.edu>
Date:   Fri Jun 28 14:19:28 2024 -0600

    self mobility tests done

commit c4f2664
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed Jun 12 15:31:55 2024 -0600

    larger safety factor near open boundary for dpstokes

commit 5da7450
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed Jun 12 12:15:33 2024 -0600

    modify how N gets rounded in all dimensions to be fft friendly

commit 51db36a
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed Jun 12 11:58:39 2024 -0600

    changed selection of grid parameters to not modify h. instead, modify the box size to make L/h an integer

commit 5127394
Author: Ryker Fish <rfish@mines.edu>
Date:   Thu Jun 6 14:07:01 2024 -0600

    changed test pass threshold

commit 4fb82bf
Author: Ryker Fish <rfish@mines.edu>
Date:   Thu Jun 6 13:42:52 2024 -0600

    regenerated all ref data using libmobility implementations in single precision

commit 4392903
Author: Ryker Fish <rfish@mines.edu>
Date:   Thu Jun 6 13:25:04 2024 -0600

    regenerated refs using gpu implementations from dpstokes library. tests are now passing if the same kernel parameters are used as the ref implementation

commit 1ce606a
Author: Ryker Fish <rfish@mines.edu>
Date:   Thu May 30 16:06:32 2024 -0600

    fixed bug in nbody wall correction that came from normalizing by a factor of 1/8pi in the original implementation instead of 1/6pi in the Swan paper.

commit edf78f5
Author: Ryker Fish <rfish@mines.edu>
Date:   Thu May 30 16:05:21 2024 -0600

    switched all tests to w=4 kernels, added nbody to pair mobility tests

commit c575ef2
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed May 29 15:11:48 2024 -0600

    change dpstokes to use w=4 kernel by default for forces

commit 070728b
Author: Ryker Fish <rfish@mines.edu>
Date:   Tue May 28 16:57:09 2024 -0600

    started pair mobility test

commit ca4e1c7
Author: Ryker Fish <rfish@mines.edu>
Date:   Sat May 18 12:19:26 2024 -0600

    combined self mobility tests into one function

commit e90e9e2
Author: Ryker Fish <rfish@mines.edu>
Date:   Fri May 17 20:45:24 2024 -0600

    bug fix in NBody with wall correction- test now passing. the fix uses the correct constants from the Swan correction paper- the previous implementation was using constants based on a self mobility constant of 1/(8*pi*eta*a) instead of 1/(6*pi*eta*a)

commit 98e2ae0
Author: Ryker Fish <rfish@mines.edu>
Date:   Fri May 17 15:37:25 2024 -0600

    changed dpstokes test to compare to dpstokes reference and added a not-working nbody test

commit 7aaa0b1
Merge: 79fe6a7 d6144a5
Author: Ryker <rfish@mines.edu>
Date:   Mon May 13 14:25:35 2024 -0600

    Merge pull request #18 from stochasticHydroTools/minor_test_edits

    Minor test edits

commit d6144a5
Author: Ryker Fish <rfish@mines.edu>
Date:   Thu May 9 15:40:00 2024 -0600

    removed test cases for small numbers of particles for the fluctuation dissipation test.

commit 0e368d4
Author: Ryker <rfish@mines.edu>
Date:   Thu May 9 14:37:44 2024 -0600

    Edit comment on nbody test

    Comment had the answer for the PSE test. Removed the periodic correction part

commit 79fe6a7
Author: Ryker Fish <rfish@mines.edu>
Date:   Thu May 9 12:47:42 2024 -0600

    now testing if mobility is 0 on the bottom wall

commit 3c5002e
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed May 8 19:02:35 2024 -0600

    possible correction to DPStokes code to add a buffer the top instead of the bottom when there is a wall

commit c66303c
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed May 8 18:27:40 2024 -0600

    selfmobility test working in comparison to refernce results for one and two wall cases

commit 70aa329
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed May 8 17:12:19 2024 -0600

    mobility doesn't go to zero at the wall unless this section is commented out.

commit fe2c964
Author: Ryker Fish <rfish@mines.edu>
Date:   Wed May 8 16:37:04 2024 -0600

    first pass at computing translational self mobility components for bottom wall scenario
  • Loading branch information
rykerfish committed Jul 18, 2024
1 parent 2720bac commit 1e3fafd
Show file tree
Hide file tree
Showing 16 changed files with 277 additions and 26 deletions.
30 changes: 30 additions & 0 deletions solvers/DPStokes/extra/poly_fits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <vector>

namespace dpstokes_polys{

double polyEval(std::vector<double> polyCoeffs, double x){

int order = polyCoeffs.size() - 1;
double accumulator = polyCoeffs[order];
double current_x = x;
for(int i = 1; i <= order; i++){
accumulator += polyCoeffs[order-i]*current_x;
current_x *= x;
}

return accumulator;
}

std::vector<double> cbetam_inv = {
4131643418.193291,
-10471683395.26777,
11833009228.6429,
-7851132955.882548,
3388121732.651829,
-994285251.2185925,
201183449.7086889,
-27776767.88241613,
2515647.646492857,
-136305.2970161326,
3445.959503226691};
}
1 change: 1 addition & 0 deletions solvers/DPStokes/extra/uammd_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ namespace uammd_dpstokes{
real alpha_d = -1;
//Can be either none, bottom, slit or periodic
std::string mode;
bool allowChangingBoxSize = false;
};

class DPStokesUAMMD;
Expand Down
56 changes: 46 additions & 10 deletions solvers/DPStokes/mobility.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define MOBILITY_SELFMOBILITY_H
#include <MobilityInterface/MobilityInterface.h>
#include"extra/uammd_interface.h"
#include"extra/poly_fits.h"
#include<vector>
#include<cmath>
#include<type_traits>
Expand Down Expand Up @@ -49,23 +50,58 @@ class DPStokes: public libmobility::Mobility{
this->lanczosTolerance = ipar.tolerance;
this->dppar.mode = this->wallmode;
this->dppar.hydrodynamicRadius = ipar.hydrodynamicRadius[0];
this->dppar.w = 6;
this->dppar.beta = 1.714*this->dppar.w;
real h = this->dppar.hydrodynamicRadius/1.554;
this->dppar.w = 4;
this->dppar.beta = 1.785*this->dppar.w;
real h = this->dppar.hydrodynamicRadius/1.205;
this->dppar.alpha = this->dppar.w/2.0;
this->dppar.tolerance = 1e-6;
this->dppar.nx = int(this->dppar.Lx/h + 0.5);
this->dppar.ny = int(this->dppar.Ly/h + 0.5);
// Add a buffer of w*h/2 when there is an open boundary

real N_real = this->dppar.Lx/h; // actual N given L and h
int N_up = ceil(N_real);
int N_down = floor(N_real);
int N;
// either N_up or N_down will be a multiple of 2. pick the even one for a more FFT friendly grid.
if(N_up % 2 == 0){
N = N_up;
}else{
N = N_down;
}

this->dppar.nx = N;
this->dppar.ny = N;

// note: only set up for square boxes
if(this->dppar.allowChangingBoxSize){ // adjust box size to suit h
this->dppar.Lx = N*h;
this->dppar.Ly = N*h;
} else{ // adjust h so that L/h is an integer
h = this->dppar.Lx/N;
double arg = this->dppar.hydrodynamicRadius/(this->dppar.w*h);
this->dppar.beta = dpstokes_polys::polyEval(dpstokes_polys::cbetam_inv, arg);
}

// Add a buffer of 1.5*w*h/2 when there is an open boundary
if(this->wallmode == "nowall"){
this->dppar.zmax += this->dppar.w*h/2;
this->dppar.zmin -= this->dppar.w*h/2;
this->dppar.zmax += 1.5*this->dppar.w*h/2;
this->dppar.zmin -= 1.5*this->dppar.w*h/2;
}
if(this->wallmode == "bottom"){
this->dppar.zmin -= this->dppar.w*h/2;
this->dppar.zmax += 1.5*this->dppar.w*h/2;
}
real Lz = this->dppar.zmax - this->dppar.zmin;
this->dppar.nz = M_PI*Lz/(h);
real H = Lz/2;
// sets chebyshev node spacing at its coarsest (in the middle) to be h
real nz_actual = M_PI/(asin(h/H)) + 1;

// pick nearby N such that 2(Nz-1) is FFT friendly
N_up = ceil(nz_actual);
N_down = floor(nz_actual);
if(N_up % 2 == 1){
this->dppar.nz = N_up;
} else {
this->dppar.nz = N_down;
}

dpstokes->initialize(dppar, this->numberParticles);
Mobility::initialize(ipar);
if(ipar.needsTorque) throw std::runtime_error("[DPStokes] Torque is not implemented");
Expand Down
7 changes: 5 additions & 2 deletions solvers/DPStokes/python_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ zmin : float
The minimum value of the z coordinate.
zmax : float
The maximum value of the z coordinate.
allowChangingBoxSize : bool
Whether the periodic extents Lx & Ly can be modified during parameter selection. Default: false.
)pbdoc";

MOBILITY_PYTHONIFY_WITH_EXTRA_CODE(DPStokes,
solver.def(
"setParameters",
[](DPStokes &self, real dt, real Lx,
real Ly, real zmin, real zmax) {
real Ly, real zmin, real zmax, bool allowChangingBoxSize) {
DPStokesParameters params;
params.dt = dt;
params.Lx = Lx;
params.Ly = Ly;
params.zmin = zmin;
params.zmax = zmax;
params.allowChangingBoxSize = allowChangingBoxSize;
self.setParametersDPStokes(params);
},
"dt"_a, "Lx"_a, "Ly"_a, "zmin"_a,
"zmax"_a);
"zmax"_a, "allowChangingBoxSize"_a = false);
, docstring);
16 changes: 8 additions & 8 deletions solvers/NBody/extra/hydrodynamicKernels.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ namespace nbody_rpy{
real invZi = real(1.0) / hj;
real invZi3 = invZi * invZi * invZi;
real invZi5 = invZi3 * invZi * invZi;
correction.x += -vj.x*(real(9.0)*invZi - real(2.0)*invZi3 + invZi5 ) / real(12.0);
correction.y += -vj.y*(real(9.0)*invZi - real(2.0)*invZi3 + invZi5 ) / real(12.0);
correction.z += -vj.z*(real(9.0)*invZi - real(4.0)*invZi3 + invZi5 ) / real(6.0);
correction.x += -vj.x*(real(9.0)*invZi - real(2.0)*invZi3 + invZi5 ) / real(16.0);
correction.y += -vj.y*(real(9.0)*invZi - real(2.0)*invZi3 + invZi5 ) / real(16.0);
correction.z += -vj.z*(real(9.0)*invZi - real(4.0)*invZi3 + invZi5 ) / real(8.0);
}
else{
real h_hat = hj / rij.z;
real invR = rsqrt(dot(rij, rij));
real3 e = rij*invR;
real invR3 = invR * invR * invR;
real invR5 = invR3 * invR * invR;
real fact1 = -(real(3.0)*(real(1.0)+real(2.0)*h_hat*(real(1.0)-h_hat)*e.z*e.z) * invR + real(2.0)*(real(1.0)-real(3.0)*e.z*e.z) * invR3 - real(2.0)*(real(1.0)-real(5.0)*e.z*e.z) * invR5) / real(3.0);
real fact2 = -(real(3.0)*(real(1.0)-real(6.0)*h_hat*(real(1.0)-h_hat)*e.z*e.z) * invR - real(6.0)*(real(1.0)-real(5.0)*e.z*e.z) * invR3 + real(10.0)*(real(1.0)-real(7.0)*e.z*e.z) * invR5) / real(3.0);
real fact3 = e.z * (real(3.0)*h_hat*(real(1.0)-real(6.0)*(real(1.0)-h_hat)*e.z*e.z) * invR - real(6.0)*(real(1.0)-real(5.0)*e.z*e.z) * invR3 + real(10.0)*(real(2.0)-real(7.0)*e.z*e.z) * invR5) * real(2.0) / real(3.0);
real fact4 = e.z * (real(3.0)*h_hat*invR - real(10.0)*invR5) * real(2.0) / real(3.0);
real fact5 = -(real(3.0)*h_hat*h_hat*e.z*e.z*invR + real(3.0)*e.z*e.z*invR3 + (real(2.0)-real(15.0)*e.z*e.z)*invR5) * real(4.0) / real(3.0);
real fact1 = -(real(3.0)*(real(1.0)+real(2.0)*h_hat*(real(1.0)-h_hat)*e.z*e.z) * invR + real(2.0)*(real(1.0)-real(3.0)*e.z*e.z) * invR3 - real(2.0)*(real(1.0)-real(5.0)*e.z*e.z) * invR5) / real(4.0);
real fact2 = -(real(3.0)*(real(1.0)-real(6.0)*h_hat*(real(1.0)-h_hat)*e.z*e.z) * invR - real(6.0)*(real(1.0)-real(5.0)*e.z*e.z) * invR3 + real(10.0)*(real(1.0)-real(7.0)*e.z*e.z) * invR5) / real(4.0);
real fact3 = e.z * (real(3.0)*h_hat*(real(1.0)-real(6.0)*(real(1.0)-h_hat)*e.z*e.z) * invR - real(6.0)*(real(1.0)-real(5.0)*e.z*e.z) * invR3 + real(10.0)*(real(2.0)-real(7.0)*e.z*e.z) * invR5) / real(2.0);
real fact4 = e.z * (real(3.0)*h_hat*invR - real(10.0)*invR5) / real(2.0);
real fact5 = -(real(3.0)*h_hat*h_hat*e.z*e.z*invR + real(3.0)*e.z*e.z*invR3 + (real(2.0)-real(15.0)*e.z*e.z)*invR5);
correction.x += (fact1 + fact2 * e.x*e.x)*vj.x;
correction.x += (fact2 * e.x*e.y)*vj.y;
correction.x += (fact2 * e.x*e.z + fact3 * e.x)*vj.z;
Expand Down
Binary file added tests/ref/pair_mobility_bw_ref_noimg.mat
Binary file not shown.
Binary file added tests/ref/pair_mobility_bw_w4.mat
Binary file not shown.
Binary file added tests/ref/pair_mobility_sc_w4.mat
Binary file not shown.
17 changes: 17 additions & 0 deletions tests/ref/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Some of this data is generated from the original DoublyPeriodicStokes repository as a correctness check. Some of this data was generated from this repository as a consistency check.

The reason we've regenerated data is that default parameter selection has been changed to fix the grid parameters to the values that best preserve the hydrodynamic radius. When data has been regenerated, consistency was checked by first matching the original DoublyPeriodicStokes repository by using their same parameters, then switching to the new parameter selection and regenerating.

Abbreviations:
bw- bottom wall
sc- slit channel

-------------- Files --------------
SELF:
self_mobility_bw_ref: from the DPStokes repository. Periodized NBody using kernels with wall corrections in double precision.
self_mobility_bw_ref_noimg.mat: from the DPStokes repository. NBody kernels with wall corrections in double precision, but without using periodized images.
self_mobility_bw_w4, self_mobility_sc_w4: generated from this repository in double precision with default parameters.

PAIR:
pair_mobility_bw_w4, pair_mobility_sc_w4: generated from this repository in double precision with default parameters.
pair_mobility_bw_ref_noimg: from the DPStokes repository. NBody kernels with wall corrections in double precision, but without using periodized images.
Binary file added tests/ref/self_mobility_bw_ref.mat
Binary file not shown.
Binary file added tests/ref/self_mobility_bw_ref_noimg.mat
Binary file not shown.
Binary file added tests/ref/self_mobility_bw_w4.mat
Binary file not shown.
Binary file added tests/ref/self_mobility_sc_w4.mat
Binary file not shown.
10 changes: 5 additions & 5 deletions tests/test_mobility_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def test_mobility_matrix_linear(
assert M.dtype == precision
sym = M - M.T
assert np.allclose(
sym, 0.0, rtol=0, atol=1e-7
), f"Mobility matrix is not symmetric within 1e-7, max diff: {np.max(np.abs(sym))}"
sym, 0.0, rtol=0, atol=5e-5
), f"Mobility matrix is not symmetric within 5e-5, max diff: {np.max(np.abs(sym))}"


@pytest.mark.parametrize(
Expand Down Expand Up @@ -79,8 +79,8 @@ def test_mobility_matrix_angular(
assert M.dtype == precision
sym = M - M.T
assert np.allclose(
sym, 0.0, rtol=0, atol=1e-7
), f"Mobility matrix is not symmetric within 1e-7, max diff: {np.max(np.abs(sym))}"
sym, 0.0, rtol=0, atol=5e-5
), f"Mobility matrix is not symmetric within 5e-5, max diff: {np.max(np.abs(sym))}"


def test_self_mobility_linear_selfmobility():
Expand Down Expand Up @@ -110,7 +110,7 @@ def test_self_mobility_linear_selfmobility():


def test_self_mobility_linear_nbody():
# Mobility should be just 1/(6\pi\eta R)*(1 - 2.83729748/L) for a single particle.
# Mobility should be just 1/(6\pi\eta R)
Solver = NBody
precision = np.float32 if Solver.precision == "float" else np.float64
solver = Solver("open", "open", "open")
Expand Down
164 changes: 164 additions & 0 deletions tests/test_wall_mobility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import pytest
import numpy as np
import scipy.interpolate
import scipy.io

from libMobility import DPStokes, NBody
from utils import compute_M

self_mobility_params = {
"DPStokes": {"dt": 1, "Lx": 76.8, "Ly": 76.8, "zmin": 0, "zmax": 19.2},
"NBody": {"algorithm": "advise"},
}

@pytest.mark.parametrize(
("Solver", "periodicity", "tol", "start_height", "ref_file"),
[
(DPStokes, ("periodic", "periodic", "single_wall"), 5e-3, 4, "self_mobility_bw_ref.mat"),
(DPStokes, ("periodic", "periodic", "single_wall"), 1e-6, 0, "self_mobility_bw_w4.mat"),
(DPStokes, ("periodic", "periodic", "two_walls"), 1e-6, 0, "self_mobility_sc_w4.mat"),
(NBody, ("open", "open", "single_wall"), 1e-6, 1, "self_mobility_bw_ref_noimg.mat")
],
)
def test_self_mobility(Solver, periodicity, tol, start_height, ref_file):
zmax = 19.2
xymax = 76.8
params = self_mobility_params[Solver.__name__]

ref_dir = "./ref/"
ref = scipy.io.loadmat(ref_dir + ref_file)
refM = ref['M']
refHeights = ref['heights'][0]

hydrodynamicRadius = 1.0
eta = 1/4/np.sqrt(np.pi)

precision = np.float32 if Solver.precision == "float" else np.float64

solver = Solver(*periodicity)
solver.setParameters(**params)
numberParticles = 1
solver.initialize(
temperature=0,
viscosity=eta,
hydrodynamicRadius=hydrodynamicRadius,
numberParticles=numberParticles,
)

start_ind = np.where(refHeights >= start_height)[0][0]
refHeights = refHeights[start_ind:]
nHeights = len(refHeights)

refM = refM[start_ind:]

normMat = np.ones((3*numberParticles, 3*numberParticles), dtype=precision)
diag_ind = np.diag_indices_from(normMat)
normMat[diag_ind] = 1/(6*np.pi*eta*hydrodynamicRadius) # only for diag elements as this is for self mobility

allM = np.zeros((nHeights, 3*numberParticles, 3*numberParticles), dtype=precision)
for i in range(0,nHeights):
positions = np.array([[xymax/2, xymax/2, refHeights[i]]], dtype=precision)
solver.setPositions(positions)

M = compute_M(solver, numberParticles)
M /= normMat
allM[i] = M

# uncomment to save datafile for test plots
# scipy.io.savemat('./temp/test_data/test_' + ref_file, {'M': allM, 'heights': refHeights})

diags = [np.diag(matrix) for matrix in allM]
ref_diags = [np.diag(matrix)[0:3] for matrix in refM] # only take diagonal elements from forces

diff = np.abs([(diag - ref_diag) for diag, ref_diag in zip(diags, ref_diags)])

avgErr = np.mean(diff)

assert avgErr < tol, f"Self mobility does not match reference. Average error: {avgErr}"

@pytest.mark.parametrize(
("Solver", "periodicity", "tol", "ref_file"),
[
(DPStokes, ("periodic", "periodic", "single_wall"), 1e-6, "pair_mobility_bw_w4.mat"),
(DPStokes, ("periodic", "periodic", "two_walls"), 1e-6, "pair_mobility_sc_w4.mat"),
(NBody, ("open", "open", "single_wall"), 1e-4, "pair_mobility_bw_ref_noimg.mat"),
],
)
def test_pair_mobility(Solver, periodicity, ref_file, tol):
zmax = 19.2
xymax = 76.8
params = self_mobility_params[Solver.__name__]

ref_dir = "./ref/"
ref = scipy.io.loadmat(ref_dir + ref_file)
refM = ref['M']
refHeights = ref['heights'].flatten()
nHeights = len(refHeights)

radH = 1.0 # hydrodynamic radius
eta = 1/4/np.sqrt(np.pi)

precision = np.float32 if Solver.precision == "float" else np.float64

solver = Solver(*periodicity)
solver.setParameters(**params)
numberParticles = 2
solver.initialize(
temperature=0,
viscosity=eta,
hydrodynamicRadius=radH,
numberParticles=numberParticles,
)

normMat = (1/(6*np.pi*eta))*np.ones((3*numberParticles, 3*numberParticles), dtype=precision)

seps = np.array([3 * radH, 4 * radH, 8 * radH])
nSeps = len(seps)

allM = np.zeros((nSeps, nHeights, 3*numberParticles, 3*numberParticles), dtype=precision)
for i in range(0,nSeps):
for k in range(0, nHeights):
xpos = xymax/2
positions = np.array([[xpos+seps[i]/2, xpos, refHeights[k]],
[xpos-seps[i]/2, xpos, refHeights[k]]], dtype=precision)
solver.setPositions(positions)

M = compute_M(solver, numberParticles)
M /= normMat
allM[i][k] = M

# uncomment to save datafile for test plots
# scipy.io.savemat('./temp/test_data/test_' + ref_file, {'M': allM, 'heights': refHeights})


indx, indy = 4, 1 ## xx
checkComponent(indx, indy, allM, refM, nSeps, tol)

indx, indy = 5, 2 # yy
checkComponent(indx, indy, allM, refM, nSeps, tol)

indx, indy = 6, 3 # zz
checkComponent(indx, indy, allM, refM, nSeps, tol)

indx, indy = 5, 1 # yx
checkComponent(indx, indy, allM, refM, nSeps, tol)

indx, indy = 3, 4 # zx
checkComponent(indx, indy, allM, refM, nSeps, tol)

indx, indy = 3, 5 # zy
checkComponent(indx, indy, allM, refM, nSeps, tol)

def checkComponent(indx, indy, allM, refM, nSeps, tol):

indx -= 1 # shift from matlab to python indexing
indy -= 1
for i in range(0, nSeps):

xx = allM[i, :, indx, indy]
xx_ref = refM[i, :, indx, indy]

relDiff = np.abs([np.linalg.norm(xx - xx_ref)/np.linalg.norm(xx_ref + 1e-6) for xx, xx_ref in zip(xx, xx_ref)])
avgErr = np.mean(relDiff)

assert avgErr < tol, f"Pair mobility does not match reference for component {indx+1}, {indy+1}. Average error: {avgErr}"
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
sane_parameters = {
"PSE": {"psi": 1.0, "Lx": 32, "Ly": 32, "Lz": 32, "shearStrain": 0.0},
"NBody": {"algorithm": "advise"},
"DPStokes": {"dt": 1, "Lx": 16, "Ly": 16, "zmin": -6, "zmax": 6},
"DPStokes": {"dt": 1, "Lx": 16, "Ly": 16, "zmin": -6, "zmax": 6, "allowChangingBoxSize": False},
"SelfMobility": {"parameter": 5.0},
}

Expand Down

0 comments on commit 1e3fafd

Please sign in to comment.