Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
RaulPPelaez committed Apr 29, 2024
2 parents 2c41006 + 633d3a4 commit d9607dd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 15 deletions.
10 changes: 7 additions & 3 deletions cpp/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
For instance, a triply periodic algorithm will need at least a box size.
*/
#include "MobilityInterface/MobilityInterface.h"
#include"libMobility/solvers/NBody/mobility.h"
#include"libMobility/solvers/PSE/mobility.h"
#include"../solvers/NBody/mobility.h"
#include"../solvers/PSE/mobility.h"
#include <type_traits>
#include<vector>
#include<random>
Expand All @@ -24,9 +24,12 @@ template<class Solver>
auto initializeSolver(Parameters par){
std::shared_ptr<MobilityBase> solver;
if(std::is_same<Solver,NBody>::value){
solver = std::make_shared<NBody>(Configuration{.periodicityX = libmobility::periodicity_mode::open,
auto nbody = std::make_shared<NBody>(Configuration{.periodicityX = libmobility::periodicity_mode::open,
.periodicityY = libmobility::periodicity_mode::open,
.periodicityZ = libmobility::periodicity_mode::open});

nbody->setParametersNBody({nbody_rpy::algorithm::advise, 1,par.numberParticles});
solver = nbody;
}
if(std::is_same<Solver,PSE>::value){
auto pse = std::make_shared<PSE>(Configuration{.periodicityX = libmobility::periodicity_mode::periodic,
Expand All @@ -48,6 +51,7 @@ auto computeMFWithSolver(std::shared_ptr<MobilityBase> solver,
std::vector<scalar> &pos,
std::vector<scalar> &forces){
std::vector<scalar> result(pos.size(), 0);
solver->setPositions(pos.data());
solver->Mdot(forces.data(), result.data());
return result;
}
Expand Down
31 changes: 19 additions & 12 deletions python/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
'''
import numpy as np
import libMobility
#Each solver has its own help available, and libMobility itself offers information about the common interface.
#help(libMobility)
#help(libMobility.NBody)
#help(libMobility.PSE)
#help(...
# can also import modules individually by name, e.g.
# from libMobility import SelfMobility
# from libMobility import PSE
# ... etc

# Each solver has its own help available, and libMobility itself offers information about the common interface.
# help(libMobility)
# help(libMobility.NBody)
# help(libMobility.PSE)
# help(...


numberParticles = 3
#Each module can be compiled using a different precision, you can know which one with this
Expand All @@ -20,21 +26,22 @@

#Any solver can be used interchangeably, some of them need additional initialization via a "setParameters" function


nb = libMobility.SelfMobility(periodicityX='open',periodicityY='open',periodicityZ='open')
# to call with the alternate import, use the below
# nb = SelfMobility(periodicityX='open',periodicityY='open',periodicityZ='open')

#For NBody periodicityZ can also be single_wall
#nb = libMobility.NBody(periodicityX='open',periodicityY='open',periodicityZ='open')
#nb.setParametersNBody(algorithm="advise", Nbatch=-1, NperBatch=-1)
# For NBody periodicityZ can also be single_wall
# nb = libMobility.NBody(periodicityX='open',periodicityY='open',periodicityZ='open')
# nb.setParametersNBody(algorithm="advise", Nbatch=1, NperBatch=numberParticles)

#nb = libMobility.PSE(periodicityX='periodic',periodicityY='periodic',periodicityZ='periodic')
#nb.setParametersPSE(psi=1, Lx=128, Ly=128, Lz=128,shearStrain=0);
# nb = libMobility.PSE(periodicityX='periodic',periodicityY='periodic',periodicityZ='periodic')
# nb.setParametersPSE(psi=1, Lx=128, Ly=128, Lz=128,shearStrain=1)

nb.initialize(temperature=1.0, viscosity = 1/(6*np.pi),
hydrodynamicRadius = 1.0,
numberParticles = numberParticles)
nb.setPositions(pos)
#result = M*F

nb.Mdot(forces = force, result = result)
print(f"{numberParticles} particles located at ( X Y Z ): {pos}")
print("Forces:", force)
Expand Down
4 changes: 4 additions & 0 deletions solvers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ add_subdirectory(DPStokes)
add_subdirectory(PSE)
add_subdirectory(NBody)
add_subdirectory(SelfMobility)

set(INIT_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(INIT_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/path/to/installation/directory")
file(COPY "${INIT_SOURCE_DIR}/__init__.py" DESTINATION ${Python3_SITEARCH}/libMobility)
6 changes: 6 additions & 0 deletions solvers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .PSE import PSE
from .SelfMobility import SelfMobility
from .NBody import NBody
from .DPStokes import DPStokes

__all__ = ['PSE', 'SelfMobility', 'NBody', 'DPStokes']

0 comments on commit d9607dd

Please sign in to comment.