From e7dc50d44762a90a1ded2992fa91b29547650322 Mon Sep 17 00:00:00 2001 From: Ryker Fish Date: Thu, 11 Sep 2025 11:25:36 -0600 Subject: [PATCH 1/4] feat: made nbody work in the no-wall case without calling setParams --- solvers/NBody/mobility.h | 7 +++++-- tests/test_initialization.py | 11 +++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/solvers/NBody/mobility.h b/solvers/NBody/mobility.h index e4f1bfa..8f15f20 100644 --- a/solvers/NBody/mobility.h +++ b/solvers/NBody/mobility.h @@ -30,8 +30,8 @@ class NBody : public libmobility::Mobility { real wallHeight; // location of the wall in z // Batched functionality configuration - int Nbatch; - int NperBatch; + int Nbatch = -1; + int NperBatch = -1; std::mt19937 rng; @@ -118,6 +118,9 @@ class NBody : public libmobility::Mobility { const auto numberParticles = this->getNumberParticles(); int i_Nbatch = (this->Nbatch < 0) ? 1 : this->Nbatch; int i_NperBatch = (this->NperBatch < 0) ? numberParticles : this->NperBatch; + std::cout << "i_nbatch: " << i_Nbatch << " i_nper: " << i_NperBatch << std::endl; + std::cout << "obj nbatch: " << this->NperBatch << "obj nper: " << i_NperBatch << std::endl; + std::cout << "npart: " << numberParticles << std::endl; if (i_NperBatch * i_Nbatch != numberParticles) throw std::runtime_error("[Mobility] Invalid batch parameters for NBody. " "If in doubt, use the defaults."); diff --git a/tests/test_initialization.py b/tests/test_initialization.py index 93a7b12..ce544c4 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -61,6 +61,17 @@ def test_nbody_default_parameters(): positions = np.random.rand(10, 3) solver.setPositions(positions) +# NBody should use default alg and all particles in one batch if no params set +def test_nbody_no_params(): + solver = NBody("open", "open", "open") + solver.initialize( + viscosity=1.0, + hydrodynamicRadius=1.5, + ) + positions = np.random.rand(10, 3) + solver.setPositions(positions) + mf, _ = solver.Mdot(positions) + @pytest.mark.parametrize( ("NBatch", "NperBatch", "numberParticles"), From 6395732190ab850f7f010ae4e6c5db63568e2002 Mon Sep 17 00:00:00 2001 From: Ryker Fish Date: Thu, 11 Sep 2025 11:55:44 -0600 Subject: [PATCH 2/4] feat: made it possible to initialize PSE without specifying shear strain, in which case it gets set to 0. --- solvers/PSE/mobility.h | 6 ++++-- solvers/PSE/python_wrapper.cu | 16 ++++++++-------- tests/test_initialization.py | 5 +++++ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/solvers/PSE/mobility.h b/solvers/PSE/mobility.h index 02e8749..aba0601 100644 --- a/solvers/PSE/mobility.h +++ b/solvers/PSE/mobility.h @@ -4,6 +4,7 @@ #include "extra/uammd_interface.h" #include #include +#include #include #include @@ -50,7 +51,8 @@ class PSE : public libmobility::Mobility { } struct PSEParameters { - real psi, Lx, Ly, Lz, shearStrain; + real psi, Lx, Ly, Lz; + std::optional shearStrain = std::nullopt; }; void setParametersPSE(PSEParameters i_par) { @@ -58,7 +60,7 @@ class PSE : public libmobility::Mobility { psepar.Lx = i_par.Lx; psepar.Ly = i_par.Ly; psepar.Lz = i_par.Lz; - psepar.shearStrain = i_par.shearStrain; + psepar.shearStrain = i_par.shearStrain ? i_par.shearStrain.value() : 0.0; } void setPositions(device_span ipositions) override { diff --git a/solvers/PSE/python_wrapper.cu b/solvers/PSE/python_wrapper.cu index 7922373..0bc0342 100644 --- a/solvers/PSE/python_wrapper.cu +++ b/solvers/PSE/python_wrapper.cu @@ -31,12 +31,12 @@ This module will only accept periodic boundary conditions in the three direction )pbdoc"; MOBILITY_PYTHONIFY_WITH_EXTRA_CODE( - PSE, - solver.def( - "setParameters", - [](PSE &self, real psi, real Lx, real Ly, real Lz, real shearStrain) { - self.setParametersPSE({psi, Lx, Ly, Lz, shearStrain}); - }, - docstringSetParameters, "psi"_a, "Lx"_a, "Ly"_a, "Lz"_a, - "shearStrain"_a); + PSE, solver.def( + "setParameters", + [](PSE &self, real psi, real Lx, real Ly, real Lz, + std::optional shearStrain) { + self.setParametersPSE({psi, Lx, Ly, Lz, shearStrain}); + }, + docstringSetParameters, "psi"_a, "Lx"_a, "Ly"_a, "Lz"_a, + "shearStrain"_a = std::nullopt); , docstring); diff --git a/tests/test_initialization.py b/tests/test_initialization.py index ce544c4..0b5b57d 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -61,6 +61,11 @@ def test_nbody_default_parameters(): positions = np.random.rand(10, 3) solver.setPositions(positions) +def test_pse_no_shear(): + solver = PSE("periodic", "periodic", "periodic") + solver.setParameters(psi=1.0, Lx=10.0, Ly=10.0, Lz=10.0) + solver.initialize(hydrodynamicRadius=1.0, viscosity=1.0) + # NBody should use default alg and all particles in one batch if no params set def test_nbody_no_params(): solver = NBody("open", "open", "open") From 94901e6e1ecba96103da96276b1adf09f9984f3c Mon Sep 17 00:00:00 2001 From: Ryker Fish Date: Thu, 11 Sep 2025 11:59:58 -0600 Subject: [PATCH 3/4] format --- tests/test_initialization.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_initialization.py b/tests/test_initialization.py index 0b5b57d..d82b77e 100644 --- a/tests/test_initialization.py +++ b/tests/test_initialization.py @@ -61,11 +61,13 @@ def test_nbody_default_parameters(): positions = np.random.rand(10, 3) solver.setPositions(positions) + def test_pse_no_shear(): solver = PSE("periodic", "periodic", "periodic") solver.setParameters(psi=1.0, Lx=10.0, Ly=10.0, Lz=10.0) solver.initialize(hydrodynamicRadius=1.0, viscosity=1.0) + # NBody should use default alg and all particles in one batch if no params set def test_nbody_no_params(): solver = NBody("open", "open", "open") From 9bc5a1441b33bdb634fe0873fa26126e9cbcfdab Mon Sep 17 00:00:00 2001 From: Ryker Fish Date: Thu, 11 Sep 2025 12:00:41 -0600 Subject: [PATCH 4/4] format --- solvers/NBody/mobility.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/solvers/NBody/mobility.h b/solvers/NBody/mobility.h index 8f15f20..6ead265 100644 --- a/solvers/NBody/mobility.h +++ b/solvers/NBody/mobility.h @@ -118,9 +118,6 @@ class NBody : public libmobility::Mobility { const auto numberParticles = this->getNumberParticles(); int i_Nbatch = (this->Nbatch < 0) ? 1 : this->Nbatch; int i_NperBatch = (this->NperBatch < 0) ? numberParticles : this->NperBatch; - std::cout << "i_nbatch: " << i_Nbatch << " i_nper: " << i_NperBatch << std::endl; - std::cout << "obj nbatch: " << this->NperBatch << "obj nper: " << i_NperBatch << std::endl; - std::cout << "npart: " << numberParticles << std::endl; if (i_NperBatch * i_Nbatch != numberParticles) throw std::runtime_error("[Mobility] Invalid batch parameters for NBody. " "If in doubt, use the defaults.");