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

Adding virial support #10

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
3 changes: 3 additions & 0 deletions dlext/include/FixDLExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace dlext

using TimeStep = bigint; // bigint depends on how LAMMPS was built
using DLExtCallback = std::function<void(TimeStep)>;
using DLExtSetVirial = std::function<void(double*)>;

// } // Aliases

Expand All @@ -39,9 +40,11 @@ class DEFAULT_VISIBILITY FixDLExt : public Fix {
int setmask() override;
void post_force(int) override;
void set_callback(DLExtCallback& cb);
void set_virial_callback(DLExtSetVirial& cb);

private:
DLExtCallback callback = [](TimeStep) { };
DLExtSetVirial setVirial = [](double*) { };
};

void register_FixDLExt(LAMMPS* lmp);
Expand Down
18 changes: 17 additions & 1 deletion dlext/src/FixDLExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ FixDLExt::FixDLExt(LAMMPS* lmp, int narg, char** arg)
if (atom->map_style != Atom::MAP_ARRAY)
error->all(FLERR, "Fix dlext requires to map atoms as arrays");

// signal that this fix contributes to the global virial
virial_global_flag = 1;
thermo_virial = 1;

kokkosable = has_kokkos_cuda_enabled(lmp);
atomKK = dynamic_cast<AtomKokkos*>(atom);
execution_space = (on_host || !kokkosable) ? kOnHost : kOnDevice;
Expand All @@ -40,9 +44,21 @@ FixDLExt::FixDLExt(LAMMPS* lmp, int narg, char** arg)
}

int FixDLExt::setmask() { return FixConst::POST_FORCE; }
void FixDLExt::post_force(int) { callback(update->ntimestep); }
void FixDLExt::post_force(int vflag)
{
// virial setup
v_init(vflag);

// invoke callback
callback(update->ntimestep);

// put the virial from the bias into this fix's member variable virial[6] (see fix.h)
setVirial(virial);
pabloferz marked this conversation as resolved.
Show resolved Hide resolved
}
void FixDLExt::set_callback(DLExtCallback& cb) { callback = cb; }

void FixDLExt::set_virial_callback(DLExtSetVirial& cb) { setVirial = cb; }

void register_FixDLExt(LAMMPS* lmp)
{
auto fix_map = lmp->modify->fix_map;
Expand Down
1 change: 1 addition & 0 deletions python/lammps_dlext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ void export_FixDLExt(py::module& m)
return static_cast<FixDLExt*>(fix);
}))
.def("set_callback", &FixDLExt::set_callback)
.def("set_virial_callback", &FixDLExt::set_virial_callback)
;
}

Expand Down