File: kspace_zero2.cpp

package info (click to toggle)
lammps 20251210%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 465,808 kB
  • sloc: cpp: 1,031,565; python: 26,771; ansic: 8,808; f90: 7,302; sh: 5,316; perl: 4,171; fortran: 2,442; xml: 1,613; makefile: 1,119; objc: 238; lisp: 188; yacc: 58; csh: 16; awk: 14; tcl: 6; javascript: 2
file content (112 lines) | stat: -rw-r--r-- 3,589 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/* ----------------------------------------------------------------------
   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;
}

/* ---------------------------------------------------------------------- */

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) utils::logmesg(lmp, "  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);
}