Skip to content

Commit

Permalink
rename plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
amlucas committed Nov 30, 2022
1 parent 50f2227 commit 002ff0a
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 43 deletions.
10 changes: 5 additions & 5 deletions docs/source/mmirheo/Plugins/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ def createAddFourRollMillForce():
"""
pass

def createAddPressureGradient():
r"""createAddPressureGradient(state: MirState, name: str, pv: ParticleVectors.ParticleVector, pressure_field: Callable[[real3], float], h: real3) -> Tuple[Plugins.SimulationPlugin, Plugins.PostprocessPlugin]
def createAddPotentialForce():
r"""createAddPotentialForce(state: MirState, name: str, pv: ParticleVectors.ParticleVector, potential_field: Callable[[real3], float], h: real3) -> Tuple[Plugins.SimulationPlugin, Plugins.PostprocessPlugin]
Add a force :math:`\mathbf{F}_{extra}` to each particle of a specific PV every time-step.
The force is the negative pressure gradient at the particle position, where the pressure is a provided field.
The force is the negative gradient of a potential field at the particle position.
Args:
name: name of the plugin
pv: :any:`ParticleVector` that we'll work with
pressure_field: pressure field
h: grid spacing used to discretize the pressure gradient
potential_field: potential field
h: grid spacing used to discretize the potential field
"""
Expand Down
10 changes: 5 additions & 5 deletions src/mirheo/bindings/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ void exportPlugins(py::module& m)
force: extra force
)");

m.def("__createAddPressureGradient", &plugin_factory::createAddPressureGradientPlugin,
"compute_task"_a, "state"_a, "name"_a, "pv"_a, "pressure_field"_a, "h"_a, R"(
m.def("__createAddPotentialForce", &plugin_factory::createAddPotentialForcePlugin,
"compute_task"_a, "state"_a, "name"_a, "pv"_a, "potential_field"_a, "h"_a, R"(
Add a force :math:`\mathbf{F}_{extra}` to each particle of a specific PV every time-step.
The force is the negative pressure gradient at the particle position, where the pressure is a provided field.
The force is the negative gradient of a potential field at the particle position.
Args:
name: name of the plugin
pv: :any:`ParticleVector` that we'll work with
pressure_field: pressure field
h: grid spacing used to discretize the pressure gradient
potential_field: potential field
h: grid spacing used to discretize the potential field
)");

m.def("__createAddReversePoiseuilleForce", &plugin_factory::createAddReversePoiseuilleForcePlugin,
Expand Down
2 changes: 1 addition & 1 deletion src/mirheo/plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(sources_cpp

set(sources_cu
add_force.cu
add_pressure_gradient.cu
add_potential_force.cu
add_reverse_poiseuille_force.cu
add_sinusoidal_force.cu
add_torque.cu
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2022 ETH Zurich. All Rights Reserved.
#include "add_pressure_gradient.h"
#include "add_potential_force.h"

#include <mirheo/core/field/from_function.h>
#include <mirheo/core/field/utils.h>
Expand All @@ -12,7 +12,7 @@
namespace mirheo {
namespace add_pressure_gradients_kernels {

__global__ void addPressureGradient(PVview view, ScalarFieldDeviceHandler pressureField)
__global__ void addPotentialForce(PVview view, ScalarFieldDeviceHandler potentialField)
{
const int i = blockIdx.x * blockDim.x + threadIdx.x;

Expand All @@ -22,7 +22,7 @@ __global__ void addPressureGradient(PVview view, ScalarFieldDeviceHandler pressu
const real3 r = Real3_int(view.readPosition(i)).v;

constexpr real h = 0.05_r;
const real3 grad = computeGradient(pressureField, r, h);
const real3 grad = computeGradient(potentialField, r, h);

view.forces[i] += make_real4(-grad, 0.0_r);
}
Expand All @@ -31,35 +31,35 @@ __global__ void addPressureGradient(PVview view, ScalarFieldDeviceHandler pressu

constexpr real3 defaultMargin {5.0_r, 5.0_r, 5.0_r};

AddPressureGradientPlugin::AddPressureGradientPlugin(const MirState *state,
const std::string& name,
const std::string& pvName,
PressureField pressureField,
real3 gridSpacing)
AddPotentialForcePlugin::AddPotentialForcePlugin(const MirState *state,
const std::string& name,
const std::string& pvName,
PotentialField potentialField,
real3 gridSpacing)
: SimulationPlugin(state, name)
, pvName_(pvName)
, pressureField_(std::make_unique<ScalarFieldFromFunction>
(state, name+"_field", pressureField, gridSpacing, defaultMargin))
, potentialField_(std::make_unique<ScalarFieldFromFunction>
(state, name+"_field", potentialField, gridSpacing, defaultMargin))
{}

void AddPressureGradientPlugin::setup(Simulation *simulation, const MPI_Comm& comm, const MPI_Comm& interComm)
void AddPotentialForcePlugin::setup(Simulation *simulation, const MPI_Comm& comm, const MPI_Comm& interComm)
{
SimulationPlugin::setup(simulation, comm, interComm);

pv_ = simulation->getPVbyNameOrDie(pvName_);

pressureField_->setup(comm);
potentialField_->setup(comm);
}

void AddPressureGradientPlugin::beforeForces(cudaStream_t stream)
void AddPotentialForcePlugin::beforeForces(cudaStream_t stream)
{
PVview view(pv_, pv_->local());
const int nthreads = 128;

SAFE_KERNEL_LAUNCH(
add_pressure_gradients_kernels::addPressureGradient,
add_pressure_gradients_kernels::addPotentialForce,
getNblocks(view.size, nthreads), nthreads, 0, stream,
view, pressureField_->handler() );
view, potentialField_->handler() );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ class ParticleVector;
class ScalarField;

/** Add a force to every particle of a given ParticleVector at every time step.
The force is the derivative of a provided scalar field at the particle's position.
The force is the negative gradient of a provided scalar field at the particle's position.
The force is added at the beforeForce() stage.
*/
class AddPressureGradientPlugin : public SimulationPlugin
class AddPotentialForcePlugin : public SimulationPlugin
{
public:
/// functor that describes a pressure field on the CPU.
using PressureField = std::function<real(real3)>;
using PotentialField = std::function<real(real3)>;

/** Create a AddPressureGradientPlugin object.
/** Create a AddPotentialForcePlugin object.
\param [in] state The global state of the simulation.
\param [in] name The name of the plugin.
\param [in] pvName The name of the ParticleVector to which the force should be applied.
\param [in] pressureField The pressure scalar field.
\param [in] gridSpacing The grid spacing used to discretize \p pressureField.
\param [in] potentialField The potential scalar field.
\param [in] gridSpacing The grid spacing used to discretize \p potentialField.
*/
AddPressureGradientPlugin(const MirState *state, const std::string& name,
const std::string& pvName,
PressureField pressureField,
real3 gridSpacing);
AddPotentialForcePlugin(const MirState *state, const std::string& name,
const std::string& pvName,
PotentialField potentialField,
real3 gridSpacing);

void setup(Simulation *simulation, const MPI_Comm& comm, const MPI_Comm& interComm) override;
void beforeForces(cudaStream_t stream) override;
Expand All @@ -41,7 +41,7 @@ class AddPressureGradientPlugin : public SimulationPlugin
private:
std::string pvName_;
ParticleVector *pv_ {nullptr};
std::unique_ptr<ScalarField> pressureField_; /// the pressure field
std::unique_ptr<ScalarField> potentialField_; /// the potential field
};

} // namespace mirheo
8 changes: 4 additions & 4 deletions src/mirheo/plugins/factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "factory.h"

#include "add_force.h"
#include "add_pressure_gradient.h"
#include "add_potential_force.h"
#include "add_reverse_poiseuille_force.h"
#include "add_sinusoidal_force.h"
#include "add_torque.h"
Expand Down Expand Up @@ -74,11 +74,11 @@ PairPlugin createAddForcePlugin(bool computeTask, const MirState *state, std::st
return { simPl, nullptr };
}

PairPlugin createAddPressureGradientPlugin(bool computeTask, const MirState *state, std::string name,
ParticleVector *pv, std::function<real(real3)> pressureField, real3 gridSpacing)
PairPlugin createAddPotentialForcePlugin(bool computeTask, const MirState *state, std::string name,
ParticleVector *pv, std::function<real(real3)> potentialField, real3 gridSpacing)
{
auto simPl = computeTask
? std::make_shared<AddPressureGradientPlugin> (state, name, pv->getName(), std::move(pressureField), gridSpacing)
? std::make_shared<AddPotentialForcePlugin> (state, name, pv->getName(), std::move(potentialField), gridSpacing)
: nullptr;
return { simPl, nullptr };
}
Expand Down
4 changes: 2 additions & 2 deletions src/mirheo/plugins/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ PairPlugin createAddFourRollMillForcePlugin(bool computeTask, const MirState *st

PairPlugin createAddForcePlugin(bool computeTask, const MirState *state, std::string name, ParticleVector *pv, real3 force);

PairPlugin createAddPressureGradientPlugin(bool computeTask, const MirState *state, std::string name,
ParticleVector *pv, std::function<real(real3)> pressureField, real3 gridSpacing);
PairPlugin createAddPotentialForcePlugin(bool computeTask, const MirState *state, std::string name,
ParticleVector *pv, std::function<real(real3)> potentialField, real3 gridSpacing);

PairPlugin createAddReversePoiseuilleForcePlugin(bool computeTask, const MirState *state, std::string name, ParticleVector *pv,
real3 force, char flipDirection);
Expand Down

0 comments on commit 002ff0a

Please sign in to comment.