Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mesh area conservation #1795

Merged
merged 106 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
e743a53
Added area conservation potential of mesh structure. pytest not start…
syjlee Jan 19, 2022
63f24f6
fix invalid second loop and keep only single loop which calculates bo…
syjlee Jan 19, 2022
6f7cec1
add comments on the variable At which is A0 divided by Nt
syjlee Jan 19, 2022
6035adf
fixes missing lines to connect area conservation in python to cpp
syjlee Jan 20, 2022
b6ab04d
Merge branch 'mesh-data-structure' into mesh_area_conservation
syjlee Jan 21, 2022
f88f2c1
fixes len_key in area_conservation.py
syjlee Jan 21, 2022
febeca0
fixes mistakes in computeForces and add get method for area
syjlee Jan 21, 2022
670858f
add three statepoints for area conservation in test_meshbond file of …
syjlee Jan 24, 2022
0b9a747
implement GPU code
syjlee Jan 26, 2022
0bedd84
Merge branch 'mesh-data-structure' into mesh_area_conservation
syjlee Jan 26, 2022
4aea9cc
fixes pytest values and remove unnecessary loop for getArea
syjlee Jan 26, 2022
e675003
remove a space
syjlee Jan 26, 2022
4131ec1
temporarily removed m_area in GPU
syjlee Jan 28, 2022
f9914bb
simplify Area conservation
Jan 28, 2022
5362300
Clean up Area conservation GPU code
Jan 28, 2022
dce6ebe
Merge branch 'mesh_area_conservation' of https://github.com/glotzerla…
Jan 28, 2022
57c417a
simplify GPU code
Jan 29, 2022
0654f73
fix GPU anc CPU code for area conservation
Jan 29, 2022
294e63f
set up area getter for GPU
Jan 30, 2022
64f5f33
fix minor bugs in Area conservation getter
Jan 30, 2022
ce6de06
pytest for Area getter
Jan 30, 2022
813ac7a
rename AreaConservation to TriangleAreaConservation
Feb 18, 2022
9ca84cf
add whole Area conservation
Feb 18, 2022
65ff0c0
fix minor bugs in GPU calculations
Feb 18, 2022
e14e7b5
Merge branch 'mesh-data-structure' into mesh_area_conservation
Apr 19, 2022
879ce08
Merge branch 'trunk-minor' into mesh_area_conservation
May 12, 2022
cb4be87
remove debug printf line
May 12, 2022
91159ba
Merge branch 'mesh_rewrite' into mesh_area_conservation
Dec 31, 2022
c8701ed
update Area conservation
Dec 31, 2022
9d3ce91
update headers
Dec 31, 2022
444fcad
fix Autotuner
Dec 31, 2022
fec55b9
add sphinx filees for docs
Dec 31, 2022
49cd19d
update CPU to per type area calculations
Jan 10, 2023
f7e941e
update GPU code
Jan 10, 2023
1b03799
update TriangleArea conservation
Jan 10, 2023
2afc58e
update pytests
Jan 10, 2023
d05d51d
fixed GPU errors
Jan 10, 2023
e1ddca7
Merge branch 'mesh_rewrite' into mesh_area_conservation
Jan 12, 2023
d2e12de
update GPU area code
Jan 12, 2023
b932d38
Merge branch 'mesh_rewrite' into mesh_area_conservation
Feb 2, 2023
2533c1c
improve area calculation code
Feb 2, 2023
f815225
Merge branch 'mesh_rewrite' into mesh_area_conservation
Feb 21, 2023
14709d7
make Area calculation MPI ready
Feb 28, 2023
7ab9988
make TriangleArea ready for MPI
Feb 28, 2023
6cc0939
fix some issues with MPI
Feb 28, 2023
7b319a8
change getN to getNGlobal for accurate Area conservation in MPI
Mar 2, 2023
e850389
Merge branch 'mesh_rewrite' into mesh_area_conservation
Mar 2, 2023
3499ff9
Merge branch 'mesh_rewrite' into mesh_area_conservation
Mar 2, 2023
bf42625
Merge branch 'trunk-major' into mesh_area_conservation
Mar 9, 2023
dc514ab
free memory in area calculation
Mar 17, 2023
d014bba
fix Area calculations for MPI
Mar 17, 2023
7b4281c
fix typo
Mar 17, 2023
dfda587
fix doube declartion
Mar 17, 2023
c823497
fix typo
Mar 17, 2023
90157bf
fix cuda issue for large systems
Mar 21, 2023
1ade840
improve TriangleArea class
Mar 21, 2023
7b6a5ed
update pytests
Mar 21, 2023
47ccfd4
Merge branch 'trunk-major' into mesh_area_conservation
Apr 7, 2023
54c44eb
Merge branch 'trunk-minor' into mesh_area_conservation
Jul 19, 2023
374eacb
change "alpha" to "default_gamma" in pytests
Jul 19, 2023
ce020bc
Merge branch 'trunk-patch' into mesh_area_conservation
Sep 27, 2023
59a357d
rewrite Trainagle area for virials
Sep 27, 2023
1d47538
rewrite AReaConservation to calculate virials
Sep 27, 2023
7be891e
fix energy calculation
Sep 27, 2023
1c7fc52
implement ignore_type option in area conservation
Sep 27, 2023
27467b5
add pytest
Sep 27, 2023
4a79732
Merge branch 'trunk-patch' into mesh_area_conservation
Sep 27, 2023
362d687
fix energy when ignore_type
Sep 29, 2023
4318879
Merge branch 'trunk-patch' into mesh_area_conservation
Oct 6, 2023
2b661b7
Merge branch 'trunk-patch' into mesh_area_conservation
Jan 15, 2024
fd38493
Merge branch 'trunk-patch' into mesh_area_conservation
Mar 25, 2024
5d88bd1
improve docs
Mar 25, 2024
cb9ee93
improve more docs
Mar 25, 2024
adef759
update comments in TriangleAreaConservationMeshForceCompute
Mar 25, 2024
19fb814
tidy up comments
Mar 25, 2024
1762646
Merge branch 'trunk-patch' into mesh_area_conservation
May 31, 2024
3e68531
minor fixes to documentation and comments
May 31, 2024
ca0629b
add conservation class description
May 31, 2024
92596f4
Merge branch 'trunk-patch' into mesh_area_conservation
May 31, 2024
bcb1044
remove commented out code
Jun 1, 2024
854e8fa
Merge branch 'trunk-minor' into mesh_area_conservation
Jun 1, 2024
321aa99
Merge branch 'trunk-minor' into mesh_area_conservation
joaander Jun 3, 2024
9b620fa
Merge branch 'trunk-minor' into mesh_area_conservation
Oct 8, 2024
d1cc446
improving docs
Oct 8, 2024
f3c7fdf
combine params
Oct 8, 2024
67e1b87
update struct
Oct 8, 2024
01b01dd
remove unnecesarry code
Oct 8, 2024
ee5c37d
improve Area code
Oct 8, 2024
de90ec7
fix docstrings
Oct 9, 2024
7af7715
fix docstring
Oct 9, 2024
1e6438d
fix docstring
Oct 9, 2024
1ae51e1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
447a861
reduce lines
Oct 9, 2024
cdb0fc6
Merge branch 'mesh_area_conservation' of https://github.com/glotzerla…
Oct 9, 2024
5a15461
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
5380016
combine triangle_area_parameter and area_parameter
Oct 9, 2024
45b4724
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 9, 2024
a94f1d3
combine m_area and m_area_GPU
Oct 16, 2024
9e336b5
combine m_area and m_area_GPU everywhere
Oct 16, 2024
514f461
Merge branch 'trunk-minor' into mesh_area_conservation
Oct 16, 2024
ea3e03a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 16, 2024
ed10888
Merge branch 'trunk-minor' into mesh_area_conservation
Oct 23, 2024
61f33aa
add Josh's comments
Oct 23, 2024
65c7e81
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Oct 23, 2024
573a0c3
fix params
Oct 23, 2024
07cb3bf
Merge branch 'mesh_area_conservation' of https://github.com/glotzerla…
Oct 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
407 changes: 407 additions & 0 deletions hoomd/md/AreaConservationMeshForceCompute.cc

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions hoomd/md/AreaConservationMeshForceCompute.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright (c) 2009-2024 The Regents of the University of Michigan.
// Part of HOOMD-blue, released under the BSD 3-Clause License.

#include "hoomd/ForceCompute.h"
#include "hoomd/MeshDefinition.h"

#include <memory>

/*! \file AreaConservationMeshForceCompute.h
\brief Declares a class for computing area constraint forces
*/

#ifdef __HIPCC__
#error This header cannot be compiled by nvcc
#endif

#include <pybind11/pybind11.h>

#ifndef __AREACONSERVATIONMESHFORCECOMPUTE_H__
#define __AREACONSERVATIONMESHFORCECOMPUTE_H__

namespace hoomd
{
namespace md
{
struct area_conservation_params
{
Scalar k;
Scalar A0;

#ifndef __HIPCC__
area_conservation_params() : k(0), A0(0) { }

area_conservation_params(pybind11::dict params)
: k(params["k"].cast<Scalar>()), A0(params["A0"].cast<Scalar>())
{
}

pybind11::dict asDict()
{
pybind11::dict v;
v["k"] = k;
v["A0"] = A0;
return v;
}
#endif
}
#if HOOMD_LONGREAL_SIZE == 32
__attribute__((aligned(4)));
#else
__attribute__((aligned(8)));
#endif

//! Computes area constraint forces on the mesh
/*! Area constraint forces are computed on every particle in a mesh.

\ingroup computes
*/
class PYBIND11_EXPORT AreaConservationMeshForceCompute : public ForceCompute
{
public:
//! Constructs the compute
AreaConservationMeshForceCompute(std::shared_ptr<SystemDefinition> sysdef,
std::shared_ptr<MeshDefinition> meshdef,
bool ignore_type);

//! Destructor
virtual ~AreaConservationMeshForceCompute();

//! Set the parameters
virtual void setParams(unsigned int type, Scalar K, Scalar A0);

virtual void setParamsPython(std::string type, pybind11::dict params);

/// Get the parameters for a type
pybind11::dict getParams(std::string type);

virtual pybind11::array_t<Scalar> getArea()
{
ArrayHandle<Scalar> h_area(m_area, access_location::host, access_mode::read);
return pybind11::array(m_mesh_data->getMeshTriangleData()->getNTypes(), h_area.data);
};

#ifdef ENABLE_MPI
//! Get ghost particle fields requested by this pair potential
/*! \param timestep Current time step
*/
virtual CommFlags getRequestedCommFlags(uint64_t timestep)
{
CommFlags flags = CommFlags(0);
flags[comm_flag::tag] = 1;
flags |= ForceCompute::getRequestedCommFlags(timestep);
return flags;
}
#endif

protected:
GPUArray<Scalar2> m_params; //!< Parameters
GPUArray<Scalar> m_area; //!< memory space for area
//
std::shared_ptr<MeshDefinition> m_mesh_data; //!< Mesh data to use in computing energy
bool m_ignore_type; //! ignore type to calculate global area if true

//! Actually compute the forces
virtual void computeForces(uint64_t timestep);

//! compute areas
virtual void precomputeParameter();
};

namespace detail
{
//! Exports the AreaConservationMeshForceCompute class to python
void export_AreaConservationMeshForceCompute(pybind11::module& m);

} // end namespace detail
} // end namespace md
} // end namespace hoomd

#endif
209 changes: 209 additions & 0 deletions hoomd/md/AreaConservationMeshForceComputeGPU.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
// Copyright (c) 2009-2024 The Regents of the University of Michigan.
// Part of HOOMD-blue, released under the BSD 3-Clause License.

#include "AreaConservationMeshForceComputeGPU.h"

using namespace std;

/*! \file AreaConservationMeshForceComputeGPU.cc
\brief Contains code for the AreaConservationMeshForceComputeGPU class
*/

namespace hoomd
{
namespace md
{
/*! \param sysdef System to compute forces on
\param meshdef Mesh triangulation
\param ignore_type boolean whether to ignore types
\post Memory is allocated, and forces are zeroed.
*/
AreaConservationMeshForceComputeGPU::AreaConservationMeshForceComputeGPU(
std::shared_ptr<SystemDefinition> sysdef,
std::shared_ptr<MeshDefinition> meshdef,
bool ignore_type)
: AreaConservationMeshForceCompute(sysdef, meshdef, ignore_type)
{
if (!m_exec_conf->isCUDAEnabled())
{
m_exec_conf->msg->error() << "Creating a AreaConservationMeshForceComputeGPU with no GPU "
"in the execution configuration"
<< endl;
throw std::runtime_error("Error initializing AreaConservationMeshForceComputeGPU");
}

unsigned int NTypes = this->m_mesh_data->getMeshTriangleData()->getNTypes();

if (this->m_ignore_type)
NTypes = 1;

GPUArray<Scalar> sum(NTypes, m_exec_conf);
m_sum.swap(sum);

m_block_size = 256;
unsigned int group_size = m_pdata->getN();
m_num_blocks = group_size / m_block_size;
m_num_blocks += 1;
m_num_blocks *= NTypes;
GPUArray<Scalar> partial_sum(m_num_blocks, m_exec_conf);
m_partial_sum.swap(partial_sum);

m_tuner.reset(new Autotuner<1>({AutotunerBase::makeBlockSizeRange(m_exec_conf)},
m_exec_conf,
"aconstraint_force"));
m_autotuners.push_back(m_tuner);
}

/*! Actually perform the force computation
\param timestep Current time step
*/
void AreaConservationMeshForceComputeGPU::computeForces(uint64_t timestep)
{
precomputeParameter();

// access the particle data arrays
ArrayHandle<Scalar4> d_pos(m_pdata->getPositions(), access_location::device, access_mode::read);

BoxDim box = this->m_pdata->getGlobalBox();

const GPUArray<typename Angle::members_t>& gpu_meshtriangle_list
= this->m_mesh_data->getMeshTriangleData()->getGPUTable();
const Index2D& gpu_table_indexer
= this->m_mesh_data->getMeshTriangleData()->getGPUTableIndexer();

ArrayHandle<typename Angle::members_t> d_gpu_meshtrianglelist(gpu_meshtriangle_list,
access_location::device,
access_mode::read);
ArrayHandle<unsigned int> d_gpu_meshtriangle_pos_list(
m_mesh_data->getMeshTriangleData()->getGPUPosTable(),
access_location::device,
access_mode::read);
ArrayHandle<unsigned int> d_gpu_n_meshtriangle(
this->m_mesh_data->getMeshTriangleData()->getNGroupsArray(),
access_location::device,
access_mode::read);

ArrayHandle<unsigned int> d_pts(this->m_mesh_data->getPerTypeSize(),
access_location::device,
access_mode::read);

ArrayHandle<Scalar4> d_force(m_force, access_location::device, access_mode::overwrite);
ArrayHandle<Scalar> d_virial(m_virial, access_location::device, access_mode::overwrite);
ArrayHandle<Scalar2> d_params(m_params, access_location::device, access_mode::read);

ArrayHandle<Scalar> d_area(m_area, access_location::device, access_mode::read);

m_tuner->begin();
kernel::gpu_compute_area_constraint_force(d_force.data,
d_virial.data,
m_virial.getPitch(),
m_pdata->getN(),
d_pts.data,
this->m_mesh_data->getSize(),
d_pos.data,
box,
d_area.data,
d_gpu_meshtrianglelist.data,
d_gpu_meshtriangle_pos_list.data,
gpu_table_indexer,
d_gpu_n_meshtriangle.data,
d_params.data,
this->m_ignore_type,
m_tuner->getParam()[0]);

if (this->m_exec_conf->isCUDAErrorCheckingEnabled())
CHECK_CUDA_ERROR();
m_tuner->end();
}

/*! Actually perform the force computation
\param timestep Current time step
*/
void AreaConservationMeshForceComputeGPU::precomputeParameter()
{
// access the particle data arrays
ArrayHandle<Scalar4> d_pos(m_pdata->getPositions(), access_location::device, access_mode::read);

BoxDim box = this->m_pdata->getGlobalBox();

m_num_blocks = m_pdata->getN() / m_block_size + 1;

const GPUArray<typename Angle::members_t>& gpu_meshtriangle_list
= this->m_mesh_data->getMeshTriangleData()->getGPUTable();
const Index2D& gpu_table_indexer
= this->m_mesh_data->getMeshTriangleData()->getGPUTableIndexer();

ArrayHandle<typename Angle::members_t> d_gpu_meshtrianglelist(gpu_meshtriangle_list,
access_location::device,
access_mode::read);
ArrayHandle<unsigned int> d_gpu_meshtriangle_pos_list(
m_mesh_data->getMeshTriangleData()->getGPUPosTable(),
access_location::device,
access_mode::read);
ArrayHandle<unsigned int> d_gpu_n_meshtriangle(
this->m_mesh_data->getMeshTriangleData()->getNGroupsArray(),
access_location::device,
access_mode::read);

ArrayHandle<Scalar> d_partial_sumArea(m_partial_sum,
access_location::device,
access_mode::overwrite);
ArrayHandle<Scalar> d_sumArea(m_sum, access_location::device, access_mode::overwrite);

unsigned int NTypes = m_mesh_data->getMeshTriangleData()->getNTypes();

if (this->m_ignore_type)
NTypes = 1;

kernel::gpu_compute_area_constraint_area(d_sumArea.data,
d_partial_sumArea.data,
m_pdata->getN(),
NTypes,
d_pos.data,
box,
d_gpu_meshtrianglelist.data,
d_gpu_meshtriangle_pos_list.data,
gpu_table_indexer,
this->m_ignore_type,
d_gpu_n_meshtriangle.data,
m_block_size,
m_num_blocks);

if (this->m_exec_conf->isCUDAErrorCheckingEnabled())
{
CHECK_CUDA_ERROR();
}

ArrayHandle<Scalar> h_sumArea(m_sum, access_location::host, access_mode::read);
ArrayHandle<Scalar> h_area(m_area, access_location::host, access_mode::overwrite);
#ifdef ENABLE_MPI
if (m_sysdef->isDomainDecomposed())
{
MPI_Allreduce(MPI_IN_PLACE,
&h_sumArea.data[0],
NTypes,
MPI_HOOMD_SCALAR,
MPI_SUM,
m_exec_conf->getMPICommunicator());
}
#endif
for (unsigned int i = 0; i < NTypes; i++)
h_area.data[i] = h_sumArea.data[i];
}

namespace detail
{
void export_AreaConservationMeshForceComputeGPU(pybind11::module& m)
{
pybind11::class_<AreaConservationMeshForceComputeGPU,
AreaConservationMeshForceCompute,
std::shared_ptr<AreaConservationMeshForceComputeGPU>>(
m,
"AreaConservationMeshForceComputeGPU")
.def(pybind11::
init<std::shared_ptr<SystemDefinition>, std::shared_ptr<MeshDefinition>, bool>());
}

} // end namespace detail
} // end namespace md
} // end namespace hoomd
Loading