Remove forcerec and inputrec from ewald_LRcorrection
[alexxy/gromacs.git] / src / gromacs / ewald / ewald_utils.h
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5  * Copyright (c) 2001-2004, The GROMACS development team.
6  * Copyright (c) 2013,2014,2017,2019,2021, by the GROMACS development team, led by
7  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8  * and including many others, as listed in the AUTHORS file in the
9  * top-level source directory and at http://www.gromacs.org.
10  *
11  * GROMACS is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * as published by the Free Software Foundation; either version 2.1
14  * of the License, or (at your option) any later version.
15  *
16  * GROMACS is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with GROMACS; if not, see
23  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
25  *
26  * If you want to redistribute modifications to GROMACS, please
27  * consider that scientific software is very special. Version
28  * control is crucial - bugs must be traceable. We will be happy to
29  * consider code for inclusion in the official distribution, but
30  * derived work must not be called official GROMACS. Details are found
31  * in the README & COPYING files - if they are missing, get the
32  * official version at http://www.gromacs.org.
33  *
34  * To help us fund GROMACS development, we humbly ask that you cite
35  * the research papers on the package. Check out http://www.gromacs.org.
36  */
37 /*! \libinternal \file
38  *
39  * \brief Declares utility functions related to Ewald.
40  *
41  * \author Mark Abraham <mark.j.abraham@gmail.com>
42  * \author Szilárd Páll <pall.szilard@gmail.com>
43  *
44  * \inlibraryapi
45  * \ingroup module_ewald
46  */
47 #ifndef GMX_EWALD_UTILS_H
48 #define GMX_EWALD_UTILS_H
49
50 #include "gromacs/math/vec.h"
51 #include "gromacs/mdtypes/inputrec.h"
52 #include "gromacs/pbcutil/pbc.h"
53 #include "gromacs/utility/gmxassert.h"
54 #include "gromacs/utility/real.h"
55
56 /*! \brief Computes the Ewald splitting coefficient for Coulomb
57  *
58  * Returns a value of beta that satisfies rtol > erfc(beta * rc)
59  * (and is very close to equality). That value is used the same way in
60  * all Coulomb-based Ewald methods.
61  *
62  * \param[in] rc    Cutoff radius
63  * \param[in] rtol  Required maximum value of the short-ranged
64  *                  potential at the cutoff (ie. ewald-rtol)
65  * \return          The value of the splitting coefficient that
66  *                  produces the required dtol at rc.
67  */
68 real calc_ewaldcoeff_q(real rc, real rtol);
69
70 /*! \brief Computes the Ewald splitting coefficient for LJ
71  *
72  * Returns a value of beta that satisfies dtol > erfc(beta * rc) * (1
73  * + beta^2 * rc^2 + 0.5 * beta^4 * rc^4) (and is very close to
74  * equality), which is used in LJ-PME.
75  *
76  * \param[in] rc    Cutoff radius
77  * \param[in] rtol  Required maximum value of the short-ranged
78  *                  potential at the cutoff (ie. ewald-rtol-lj)
79  * \return          The value of the splitting coefficient that
80  *                  produces the required dtol at rc.
81  */
82 real calc_ewaldcoeff_lj(real rc, real rtol);
83
84
85 /*! \libinternal \brief Class to handle box scaling for Ewald and PME.
86  *
87  * At construction contents of inputrec determine whether scaling is necessary
88  * as well as the scaling factor used. Later, the scaleBox method can be used
89  * to apply the appropriate scaling (if needed) for Ewald-based methods.
90  *
91  */
92 class EwaldBoxZScaler
93 {
94
95 private:
96     bool scaleWithWalls_; /**< True if the simulation uses two walls and the box needs to be scaled in PME */
97     real scalingFactor_; /**< Box The scaling factor PME uses with walls */
98
99 public:
100     EwaldBoxZScaler() = delete;
101
102     /*! \brief Constructor that takes the input record to initialize Ewald box scaling appropriately. */
103     EwaldBoxZScaler(bool havePbcXY2Walls, real wallEwaldZfac)
104     {
105         if (havePbcXY2Walls)
106         {
107             scaleWithWalls_ = true;
108             scalingFactor_  = wallEwaldZfac;
109         }
110         else
111         {
112             scaleWithWalls_ = false;
113             scalingFactor_  = 1;
114         }
115     }
116
117     /*! \brief Copy and scale the box for PME.
118      *
119      * When PME is used with 2D periodicity and two walls, the
120      * copy of the \p box passed is scaled with the Z scaling factor.
121      *
122      * \param[in] box        The current box matrix
123      * \param[out] scaledBox Scaled copy of the box matrix.
124      */
125     void scaleBox(const matrix box, matrix scaledBox) const
126     {
127         GMX_ASSERT(box, "invalid source box pointer");
128         GMX_ASSERT(scaledBox, "invalid target box pointer");
129
130         copy_mat(box, scaledBox);
131         if (scaleWithWalls_)
132         {
133             svmul(scalingFactor_, scaledBox[ZZ], scaledBox[ZZ]);
134         }
135     }
136 };
137
138 #endif