add KSpace style zero to KSPACE and zero2 as plugin demo
This commit is contained in:
@ -94,6 +94,10 @@ add_library(zero2plugin MODULE zero2plugin.cpp pair_zero2.cpp bond_zero2.cpp
|
||||
angle_zero2.cpp dihedral_zero2.cpp improper_zero2.cpp)
|
||||
target_link_libraries(zero2plugin PRIVATE lammps)
|
||||
|
||||
add_library(kspaceplugin MODULE kspaceplugin.cpp kspace_zero2.cpp)
|
||||
target_include_directories(kspaceplugin PRIVATE "${LAMMPS_HEADER_DIR}/KSPACE")
|
||||
target_link_libraries(kspaceplugin PRIVATE lammps)
|
||||
|
||||
set_target_properties(morse2plugin nve2plugin helloplugin zero2plugin PROPERTIES PREFIX "" SUFFIX ".so")
|
||||
|
||||
# MacOS seems to need this
|
||||
|
||||
117
examples/plugins/kspace_zero2.cpp
Normal file
117
examples/plugins/kspace_zero2.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS development team: developers@lammps.org
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Axel Kohlmeyer (Temple U)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "kspace_zero2.h"
|
||||
|
||||
#include "atom.h"
|
||||
#include "comm.h"
|
||||
#include "domain.h"
|
||||
#include "error.h"
|
||||
#include "force.h"
|
||||
#include "pair.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
KSpaceZero2::KSpaceZero2(LAMMPS *lmp) : KSpace(lmp)
|
||||
{
|
||||
ewaldflag = 1;
|
||||
pppmflag = 1;
|
||||
msmflag = 1;
|
||||
dispersionflag = 1;
|
||||
tip4pflag = 1;
|
||||
dipoleflag = 1;
|
||||
spinflag = 1;
|
||||
}
|
||||
|
||||
KSpaceZero2::~KSpaceZero2()
|
||||
{
|
||||
fprintf(stderr, "In destructor for KSpace zero2. This = %p\n", this);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void KSpaceZero2::settings(int narg, char **arg)
|
||||
{
|
||||
if (narg != 1) error->all(FLERR, "Illegal kspace_style {} command", force->kspace_style);
|
||||
|
||||
accuracy_relative = fabs(utils::numeric(FLERR, arg[0], false, lmp));
|
||||
if (accuracy_relative > 1.0)
|
||||
error->all(FLERR, "Invalid relative accuracy {:g} for kspace_style {}", accuracy_relative,
|
||||
force->kspace_style);
|
||||
if ((narg != 0) && (narg != 1)) error->all(FLERR, "Illegal kspace_style command");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void KSpaceZero2::init()
|
||||
{
|
||||
if (comm->me == 0) utils::logmesg(lmp, "Dummy KSpace initialization ...\n");
|
||||
|
||||
// error checks
|
||||
|
||||
if (force->pair == nullptr) error->all(FLERR, "KSpace solver requires a pair style");
|
||||
if (!atom->q_flag) error->all(FLERR, "KSpace style zero2 requires atom attribute q");
|
||||
|
||||
// compute two charge force
|
||||
|
||||
two_charge();
|
||||
|
||||
int itmp;
|
||||
auto p_cutoff = (double *) force->pair->extract("cut_coul", itmp);
|
||||
if (p_cutoff == nullptr) error->all(FLERR, "KSpace style is incompatible with Pair style");
|
||||
double cutoff = *p_cutoff;
|
||||
|
||||
qsum_qsq();
|
||||
|
||||
accuracy = accuracy_relative * two_charge_force;
|
||||
|
||||
// make initial g_ewald estimate
|
||||
// based on desired accuracy and real space cutoff
|
||||
// fluid-occupied volume used to estimate real-space error
|
||||
// zprd used rather than zprd_slab
|
||||
|
||||
if (!gewaldflag) {
|
||||
if (accuracy <= 0.0) error->all(FLERR, "KSpace accuracy must be > 0");
|
||||
if (q2 == 0.0) error->all(FLERR, "Must use 'kspace_modify gewald' for uncharged system");
|
||||
g_ewald = accuracy * sqrt(atom->natoms * cutoff * domain->xprd * domain->yprd * domain->zprd) /
|
||||
(2.0 * q2);
|
||||
if (g_ewald >= 1.0)
|
||||
g_ewald = (1.35 - 0.15 * log(accuracy)) / cutoff;
|
||||
else
|
||||
g_ewald = sqrt(-log(g_ewald)) / cutoff;
|
||||
}
|
||||
|
||||
if (comm->me == 0) std::string mesg = fmt::format(" G vector (1/distance) = {:.8g}\n", g_ewald);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void KSpaceZero2::setup()
|
||||
{
|
||||
if (comm->me == 0) utils::logmesg(lmp, "Dummy KSpace setup\n");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void KSpaceZero2::compute(int eflag, int vflag)
|
||||
{
|
||||
ev_init(eflag, vflag);
|
||||
}
|
||||
33
examples/plugins/kspace_zero2.h
Normal file
33
examples/plugins/kspace_zero2.h
Normal file
@ -0,0 +1,33 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/ Sandia National Laboratories
|
||||
LAMMPS development team: developers@lammps.org
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef LMP_KSPACE_ZERO2_H
|
||||
#define LMP_KSPACE_ZERO2_H
|
||||
|
||||
#include "kspace.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class KSpaceZero2 : public KSpace {
|
||||
public:
|
||||
KSpaceZero2(class LAMMPS *);
|
||||
~KSpaceZero2() override;
|
||||
|
||||
void init() override;
|
||||
void setup() override;
|
||||
void settings(int, char **) override;
|
||||
|
||||
void compute(int, int) override;
|
||||
};
|
||||
} // namespace LAMMPS_NS
|
||||
#endif
|
||||
35
examples/plugins/kspaceplugin.cpp
Normal file
35
examples/plugins/kspaceplugin.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
|
||||
#include "lammpsplugin.h"
|
||||
|
||||
#include "comm.h"
|
||||
#include "command.h"
|
||||
#include "error.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "kspace_zero2.h"
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
static KSpace *zero2creator(LAMMPS *lmp)
|
||||
{
|
||||
KSpace *ptr = (KSpace *) new KSpaceZero2(lmp);
|
||||
fprintf(stderr, "Created zero2 instance at %p\n", ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
extern "C" void lammpsplugin_init(void *lmp, void *handle, void *regfunc)
|
||||
{
|
||||
lammpsplugin_t plugin;
|
||||
lammpsplugin_regfunc register_plugin = (lammpsplugin_regfunc) regfunc;
|
||||
|
||||
plugin.version = LAMMPS_VERSION;
|
||||
plugin.style = "kspace";
|
||||
plugin.name = "zero2";
|
||||
plugin.info = "zero2 KSpace style v1.0";
|
||||
plugin.author = "Axel Kohlmeyer (akohlmey@gmail.com)";
|
||||
plugin.creator.v1 = (lammpsplugin_factory1 *) &zero2creator;
|
||||
plugin.handle = handle;
|
||||
(*register_plugin)(&plugin, lmp);
|
||||
}
|
||||
117
src/KSPACE/kspace_zero.cpp
Normal file
117
src/KSPACE/kspace_zero.cpp
Normal file
@ -0,0 +1,117 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/, Sandia National Laboratories
|
||||
LAMMPS development team: developers@lammps.org
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
Contributing author: Axel Kohlmeyer (Temple U)
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "kspace_zero.h"
|
||||
|
||||
#include "atom.h"
|
||||
#include "comm.h"
|
||||
#include "domain.h"
|
||||
#include "error.h"
|
||||
#include "force.h"
|
||||
#include "pair.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using namespace LAMMPS_NS;
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
KSpaceZero::KSpaceZero(LAMMPS *lmp) : KSpace(lmp)
|
||||
{
|
||||
ewaldflag = 1;
|
||||
pppmflag = 1;
|
||||
msmflag = 1;
|
||||
dispersionflag = 1;
|
||||
tip4pflag = 1;
|
||||
dipoleflag = 1;
|
||||
spinflag = 1;
|
||||
}
|
||||
|
||||
KSpaceZero::~KSpaceZero()
|
||||
{
|
||||
fprintf(stderr, "In destructor for KSpace zero. This = %p\n", this);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void KSpaceZero::settings(int narg, char **arg)
|
||||
{
|
||||
if (narg != 1) error->all(FLERR, "Illegal kspace_style {} command", force->kspace_style);
|
||||
|
||||
accuracy_relative = fabs(utils::numeric(FLERR, arg[0], false, lmp));
|
||||
if (accuracy_relative > 1.0)
|
||||
error->all(FLERR, "Invalid relative accuracy {:g} for kspace_style {}", accuracy_relative,
|
||||
force->kspace_style);
|
||||
if ((narg != 0) && (narg != 1)) error->all(FLERR, "Illegal kspace_style command");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void KSpaceZero::init()
|
||||
{
|
||||
if (comm->me == 0) utils::logmesg(lmp, "Dummy KSpace initialization ...\n");
|
||||
|
||||
// error checks
|
||||
|
||||
if (force->pair == nullptr) error->all(FLERR, "KSpace solver requires a pair style");
|
||||
if (!atom->q_flag) error->all(FLERR, "KSpace style zero requires atom attribute q");
|
||||
|
||||
// compute two charge force
|
||||
|
||||
two_charge();
|
||||
|
||||
int itmp;
|
||||
auto p_cutoff = (double *) force->pair->extract("cut_coul", itmp);
|
||||
if (p_cutoff == nullptr) error->all(FLERR, "KSpace style is incompatible with Pair style");
|
||||
double cutoff = *p_cutoff;
|
||||
|
||||
qsum_qsq();
|
||||
|
||||
accuracy = accuracy_relative * two_charge_force;
|
||||
|
||||
// make initial g_ewald estimate
|
||||
// based on desired accuracy and real space cutoff
|
||||
// fluid-occupied volume used to estimate real-space error
|
||||
// zprd used rather than zprd_slab
|
||||
|
||||
if (!gewaldflag) {
|
||||
if (accuracy <= 0.0) error->all(FLERR, "KSpace accuracy must be > 0");
|
||||
if (q2 == 0.0) error->all(FLERR, "Must use 'kspace_modify gewald' for uncharged system");
|
||||
g_ewald = accuracy * sqrt(atom->natoms * cutoff * domain->xprd * domain->yprd * domain->zprd) /
|
||||
(2.0 * q2);
|
||||
if (g_ewald >= 1.0)
|
||||
g_ewald = (1.35 - 0.15 * log(accuracy)) / cutoff;
|
||||
else
|
||||
g_ewald = sqrt(-log(g_ewald)) / cutoff;
|
||||
}
|
||||
|
||||
if (comm->me == 0) std::string mesg = fmt::format(" G vector (1/distance) = {:.8g}\n", g_ewald);
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void KSpaceZero::setup()
|
||||
{
|
||||
if (comm->me == 0) utils::logmesg(lmp, "Dummy KSpace setup\n");
|
||||
}
|
||||
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
void KSpaceZero::compute(int eflag, int vflag)
|
||||
{
|
||||
ev_init(eflag, vflag);
|
||||
}
|
||||
40
src/KSPACE/kspace_zero.h
Normal file
40
src/KSPACE/kspace_zero.h
Normal file
@ -0,0 +1,40 @@
|
||||
/* -*- c++ -*- ----------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://www.lammps.org/ Sandia National Laboratories
|
||||
LAMMPS development team: developers@lammps.org
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef KSPACE_CLASS
|
||||
// clang-format off
|
||||
KSpaceStyle(zero,KSpaceZero);
|
||||
// clang-format on
|
||||
#else
|
||||
|
||||
#ifndef LMP_KSPACE_ZERO_H
|
||||
#define LMP_KSPACE_ZERO_H
|
||||
|
||||
#include "kspace.h"
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
|
||||
class KSpaceZero : public KSpace {
|
||||
public:
|
||||
KSpaceZero(class LAMMPS *);
|
||||
~KSpaceZero() override;
|
||||
|
||||
void init() override;
|
||||
void setup() override;
|
||||
void settings(int, char **) override;
|
||||
|
||||
void compute(int, int) override;
|
||||
};
|
||||
} // namespace LAMMPS_NS
|
||||
#endif
|
||||
#endif
|
||||
Reference in New Issue
Block a user