Introduce SimulatorBuilder
[gromacs.git] / src / gromacs / mdtypes / iforceprovider.h
blobdda2fbee0ea2d27a140a2a6d31d948c1726c6ab2
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by
5 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
6 * and including many others, as listed in the AUTHORS file in the
7 * top-level source directory and at http://www.gromacs.org.
9 * GROMACS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1
12 * of the License, or (at your option) any later version.
14 * GROMACS is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with GROMACS; if not, see
21 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 * If you want to redistribute modifications to GROMACS, please
25 * consider that scientific software is very special. Version
26 * control is crucial - bugs must be traceable. We will be happy to
27 * consider code for inclusion in the official distribution, but
28 * derived work must not be called official GROMACS. Details are found
29 * in the README & COPYING files - if they are missing, get the
30 * official version at http://www.gromacs.org.
32 * To help us fund GROMACS development, we humbly ask that you cite
33 * the research papers on the package. Check out http://www.gromacs.org.
35 /*! \libinternal \file
36 * \brief
37 * Declares gmx::IForceProvider and ForceProviders.
39 * See \ref page_mdmodules for an overview of this and associated interfaces.
41 * \author Teemu Murtola <teemu.murtola@gmail.com>
42 * \author Carsten Kutzner <ckutzne@gwdg.de>
43 * \inlibraryapi
44 * \ingroup module_mdtypes
46 #ifndef GMX_MDTYPES_IFORCEPROVIDER_H
47 #define GMX_MDTYPES_IFORCEPROVIDER_H
49 #include "gromacs/math/vec.h"
50 #include "gromacs/utility/arrayref.h"
51 #include "gromacs/utility/classhelpers.h"
52 #include "gromacs/utility/gmxassert.h"
54 struct gmx_enerdata_t;
55 struct t_commrec;
56 struct t_forcerec;
57 struct t_mdatoms;
59 namespace gmx
62 template <typename T>
63 class ArrayRef;
64 class ForceWithVirial;
67 /*! \libinternal \brief
68 * Helper struct that bundles data for passing it over to the force providers
70 * This is a short-lived container that bundles up all necessary input data for the
71 * force providers. Its only purpose is to allow calling forceProviders->calculateForces()
72 * with just two arguments, one being the container for the input data,
73 * the other the container for the output data.
75 * Both ForceProviderInput as well as ForceProviderOutput only package existing
76 * data structs together for handing it over to calculateForces(). Apart from the
77 * POD entries they own nothing.
79 class ForceProviderInput
81 public:
82 /*! \brief Constructor assembles all necessary force provider input data
84 * \param[in] x Atomic positions
85 * \param[in] cr Communication record structure
86 * \param[in] box The simulation box
87 * \param[in] time The current time in the simulation
88 * \param[in] mdatoms The atomic data
90 ForceProviderInput(ArrayRef<const RVec> x,
91 const t_mdatoms &mdatoms,
92 double time,
93 const matrix box,
94 const t_commrec &cr)
95 : x_(x), mdatoms_(mdatoms), t_(time), cr_(cr)
97 copy_mat(box, box_);
100 ArrayRef<const RVec> x_; //!< The atomic positions
101 const t_mdatoms &mdatoms_; //!< Atomic data
102 double t_; //!< The current time in the simulation
103 matrix box_ = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}; //!< The simulation box
104 const t_commrec &cr_; //!< Communication record structure
107 /*! \brief Take pointer, check if valid, return reference
109 template <class T> T &makeRefFromPointer(T *ptr)
111 GMX_ASSERT(ptr != nullptr, "got null pointer");
112 return *ptr;
115 /*! \libinternal \brief
116 * Helper struct bundling the output data of a force provider
118 * Same as for the ForceProviderInput class, but these variables can be written as well.
120 class ForceProviderOutput
122 public:
123 /*! \brief Constructor assembles all necessary force provider output data
125 * \param[in,out] forceWithVirial Container for force and virial
126 * \param[in,out] enerd Structure containing energy data
128 ForceProviderOutput(ForceWithVirial *forceWithVirial,
129 gmx_enerdata_t *enerd)
130 : forceWithVirial_(makeRefFromPointer(forceWithVirial)), enerd_(makeRefFromPointer(enerd))
134 ForceWithVirial &forceWithVirial_; //!< Container for force and virial
135 gmx_enerdata_t &enerd_; //!< Structure containing energy data
139 /*! \libinternal \brief
140 * Interface for a component that provides forces during MD.
142 * Modules implementing IMDModule generally implement this internally, and use
143 * IMDModule::initForceProviders() to register their implementation in
144 * ForceProviders.
146 * The interface most likely requires additional generalization for use in
147 * other modules than the current electric field implementation.
149 * The forces that are produced by force providers are not taken into account
150 * in the calculation of the virial. When applicable, the provider should
151 * compute its own virial contribution.
153 * \inlibraryapi
154 * \ingroup module_mdtypes
156 class IForceProvider
158 public:
159 /*! \brief
160 * Computes forces.
162 * \param[in] forceProviderInput struct that collects input data for the force providers
163 * \param[in,out] forceProviderOutput struct that collects output data of the force providers
165 virtual void calculateForces(const ForceProviderInput &forceProviderInput,
166 ForceProviderOutput *forceProviderOutput) = 0;
168 protected:
169 ~IForceProvider() {}
172 } // namespace gmx
174 /*! \libinternal \brief
175 * Evaluates forces from a collection of gmx::IForceProvider.
177 * This class is a `struct` outside the `gmx` namespace to make it possible to
178 * forward-declare it in forcerec.h, which still needs to compile when included
179 * from the C group kernels.
181 * \inlibraryapi
182 * \ingroup module_mdtypes
184 struct ForceProviders
186 public:
187 ForceProviders();
188 ~ForceProviders();
190 /*! \brief
191 * Adds a provider.
193 void addForceProvider(gmx::IForceProvider *provider);
195 //! Whether there are modules added.
196 bool hasForceProvider() const;
198 //! Computes forces.
199 void calculateForces(const gmx::ForceProviderInput &forceProviderInput,
200 gmx::ForceProviderOutput *forceProviderOutput) const;
202 private:
203 class Impl;
205 gmx::PrivateImplPointer<Impl> impl_;
208 #endif