Use proper doxygen tags in modular simulator
[gromacs.git] / api / cpp / gmxapi / mdsignals.h
blobefe388cc6fca2d9c6515088e89fd4e48f9cabca6
1 /*
2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 2018,2019,2020, 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.
36 #ifndef GMXAPI_MDSIGNALS_IMPL_H
37 #define GMXAPI_MDSIGNALS_IMPL_H
39 /*! \file
40 * \brief Implementation details for gmxapi::Signal and related gmxapi::md infrastructure.
42 * \ingroup gmxapi_md
45 #include <atomic>
46 #include <functional>
47 #include <memory>
49 #include "gromacs/mdlib/simulationsignal.h"
50 #include "gromacs/mdlib/stophandler.h"
51 #include "gromacs/mdrun/runner.h"
53 // Public gmxapi headers.
54 #include "gmxapi/session.h"
55 #include "gmxapi/md/mdsignals.h"
57 // Internal gmxapi headers.
58 #include "session_impl.h"
60 namespace gmxapi
64 /*! \internal
65 * \brief The Signal Implementation interface.
67 * A SignalImpl concrete class must implement a `call()` method that issues the signal.
69 * \ingroup gmxapi_md
71 class Signal::SignalImpl
73 public:
74 //! Required functor behavior.
75 virtual void call() = 0;
77 //! May be subclassed.
78 virtual ~SignalImpl() = default;
81 /*!
82 * \brief Manage signal paths exposed through session resources to gmxapi operations.
84 * Manages signals for a single gmx::Mdrunner. Currently only supports a stop signal that
85 * is required to be issued by all registered possible issuers before the signal is sent to
86 * the associated runner. This is not what we want in the long run.
87 * \todo This class should handle signal inputs to operations that take signals as input (like
88 * Mdrunner) and \todo should allow multiple subscribers. For additional signal processing, such as
89 * boolean operations, additional operations should be inserted in a chain.
91 * SignalManager objects are created during Session launch and are owned exclusively by session
92 * implementation objects. If Session::isOpen() is true, the SignalManager should still be valid,
93 * but the intended use case is that SignalManager handles should be retrieved immediately before
94 * use by implementation code within the library with SessionImpl::getSignalManager().
96 * A SignalManager should be created for each signal consumer (each gmx::Mdrunner) in a Session.
97 * This occurs in the SessionImpl::create() function.
99 * \ingroup gmxapi_md
101 class SignalManager
103 public:
105 * \brief Set up a manager to mediate access to an upcoming MD stop handler.
107 * \param mdStopHandlerBuilder access to a builder that can be used during construction.
109 explicit SignalManager(gmx::StopHandlerBuilder* mdStopHandlerBuilder);
111 //! \cond
112 ~SignalManager();
113 //! \endcond
116 * \brief Add a name to the list of operations that will be using this signal.
118 void addSignaller(const std::string& name);
121 * \brief Allow a registered signaller to retrieve a functor.
123 * \param name Registered signal issuer.
124 * \param signal type of signal the client would like to issue.
125 * \return Generic Signal object.
127 * \throws gmxapi::ProtocolError if named signaller was not previously registered.
129 Signal getSignal(const std::string& name, md::signals signal);
132 * \brief Signal operation that issues only when all sources have issued.
134 * Implemented as a member class that can access SignalManager's private members.
135 * \todo Decouple logical operations from SignalManager class definition.
137 class LogicalAND;
139 private:
140 //! Non-owning handle to the associated runner.
141 gmx::Mdrunner* runner_;
145 * \brief State of the stop condition to be returned by the registered MD signaller.
147 * Ownership is shared by the function objects in the StopConditionHandler
148 * (owned by the simulator), which read the value, and the
149 * SessionImpl SignalManager, which mediates write access.
151 * The signal state is either gmx::StopSignal::noSignal or gmx::StopSignal::stopAtNextNSStep,
152 * so atomicity is not important, and we share the state across
153 * threads in a tMPI simulation.
155 std::shared_ptr<gmx::StopSignal> state_;
158 * \brief Track whether the signal has been issued by each registrant.
160 * \todo This is an implementation detail of LogicalAND that should not be here.
162 std::map<std::string, std::atomic_bool> called_;
166 } // end namespace gmxapi
168 #endif // GMXAPI_MDSIGNALS_IMPL_H