Skip to content

Commit

Permalink
Refactor flow fields (#78)
Browse files Browse the repository at this point in the history
* Update to flow fields

* Formatting changes

* Add cpp files for Parabolic and Constant flow class

* Revise parabolic flow coordinate system

* Fix pybind11 visbility

---------

Co-authored-by: Michael Howard <[email protected]>
  • Loading branch information
mayukh33 and mphoward authored Jun 5, 2024
1 parent 9b3aed1 commit 0b8575a
Show file tree
Hide file tree
Showing 12 changed files with 389 additions and 155 deletions.
2 changes: 2 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ignore = [

"__init__.py" = ["F401", # __init__.py import submodules for use by the package importer.
]
"*/pytest/*.py" = ["PLR2004", # allow "magic numbers" in tests
]

[lint.pydocstyle]
convention = "google"
Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ set(COMPONENT_NAME azplugins)

# TODO: List all host C++ source code files in _${COMPONENT_NAME}_sources.
set(_${COMPONENT_NAME}_sources
ConstantFlow.cc
GroupVelocityCompute.cc
module.cc
ParabolicFlow.cc
)

# TODO: List all GPU C++ source code files in _${COMPONENT_NAME}_cu_sources.
Expand All @@ -16,6 +18,7 @@ set(python_files
__init__.py
conftest.py
bond.py
flow.py
pair.py
)

Expand Down
34 changes: 34 additions & 0 deletions src/ConstantFlow.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) 2018-2020, Michael P. Howard
// Copyright (c) 2021-2024, Auburn University
// Part of azplugins, released under the BSD 3-Clause License.

#include "ConstantFlow.h"

namespace hoomd
{
namespace azplugins
{
namespace detail
{
void export_ConstantFlow(pybind11::module& m)
{
namespace py = pybind11;
py::class_<ConstantFlow, std::shared_ptr<ConstantFlow>>(m, "ConstantFlow")
.def(py::init<Scalar3>())
.def_property(
"velocity",
[](const ConstantFlow& U)
{
const auto field = U.getVelocity();
return pybind11::make_tuple(field.x, field.y, field.z);
},
[](ConstantFlow& U, const pybind11::tuple& field)
{
U.setVelocity(make_scalar3(pybind11::cast<Scalar>(field[0]),
pybind11::cast<Scalar>(field[1]),
pybind11::cast<Scalar>(field[2])));
});
}
} // end namespace detail
} // end namespace azplugins
} // end namespace hoomd
73 changes: 73 additions & 0 deletions src/ConstantFlow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) 2018-2020, Michael P. Howard
// Copyright (c) 2021-2024, Auburn University
// Part of azplugins, released under the BSD 3-Clause License.

#ifndef AZPLUGINS_CONSTANT_FLOW_H_
#define AZPLUGINS_CONSTANT_FLOW_H_

#ifndef __HIPCC__
#include <pybind11/pybind11.h>
#endif

#include "hoomd/HOOMDMath.h"

#ifndef __HIPCC__
#define HOSTDEVICE __host__ __device__
#else
#define HOSTDEVICE
#endif // __HIPCC__

#ifndef PYBIND11_EXPORT
#define PYBIND11_EXPORT __attribute__((visibility("default")))
#endif

namespace hoomd
{
namespace azplugins
{

//! Position-independent flow along a vector
class PYBIND11_EXPORT ConstantFlow
{
public:
//! Constructor
/*!
*\param U_ Flow field
*/
ConstantFlow(Scalar3 velocity)
{
setVelocity(velocity);
}

//! Evaluate the flow field
/*!
* \param r position to evaluate flow
*
* This is just a constant, independent of \a r.
*/
HOSTDEVICE Scalar3 operator()(const Scalar3& r) const
{
return U;
}

HOSTDEVICE Scalar3 getVelocity() const
{
return U;
}

HOSTDEVICE void setVelocity(const Scalar3& U_)
{
U = U_;
}

private:
Scalar3 U; //!< Flow field
};

} // namespace azplugins
} // namespace hoomd

#undef HOSTDEVICE
#undef PYBIND11_EXPORT

#endif // AZPLUGINS_CONSTANT_FLOW_H_
153 changes: 0 additions & 153 deletions src/FlowFields.h

This file was deleted.

25 changes: 25 additions & 0 deletions src/ParabolicFlow.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2018-2020, Michael P. Howard
// Copyright (c) 2021-2024, Auburn University
// Part of azplugins, released under the BSD 3-Clause License.

#include "ParabolicFlow.h"

namespace hoomd
{
namespace azplugins
{
namespace detail
{
void export_ParabolicFlow(pybind11::module& m)
{
namespace py = pybind11;
py::class_<ParabolicFlow, std::shared_ptr<ParabolicFlow>>(m, "ParabolicFlow")
.def(py::init<Scalar, Scalar>())
.def_property("mean_velocity",
&ParabolicFlow::getMeanVelocity,
&ParabolicFlow::setMeanVelocity)
.def_property("separation", &ParabolicFlow::getSeparation, &ParabolicFlow::setSeparation);
}
} // namespace detail
} // namespace azplugins
} // namespace hoomd
Loading

0 comments on commit 0b8575a

Please sign in to comment.