Enable parallel tests.
[hoomd-blue.git] / libhoomd / analyzers / IMDInterface.h
blob6cf2cfbcfc27a136b8f8a035158e317c8144f9b8
1 /*
2 Highly Optimized Object-oriented Many-particle Dynamics -- Blue Edition
3 (HOOMD-blue) Open Source Software License Copyright 2009-2014 The Regents of
4 the University of Michigan All rights reserved.
6 HOOMD-blue may contain modifications ("Contributions") provided, and to which
7 copyright is held, by various Contributors who have granted The Regents of the
8 University of Michigan the right to modify and/or distribute such Contributions.
10 You may redistribute, use, and create derivate works of HOOMD-blue, in source
11 and binary forms, provided you abide by the following conditions:
13 * Redistributions of source code must retain the above copyright notice, this
14 list of conditions, and the following disclaimer both in the code and
15 prominently in any materials provided with the distribution.
17 * Redistributions in binary form must reproduce the above copyright notice, this
18 list of conditions, and the following disclaimer in the documentation and/or
19 other materials provided with the distribution.
21 * All publications and presentations based on HOOMD-blue, including any reports
22 or published results obtained, in whole or in part, with HOOMD-blue, will
23 acknowledge its use according to the terms posted at the time of submission on:
24 http://codeblue.umich.edu/hoomd-blue/citations.html
26 * Any electronic documents citing HOOMD-Blue will link to the HOOMD-Blue website:
27 http://codeblue.umich.edu/hoomd-blue/
29 * Apart from the above required attributions, neither the name of the copyright
30 holder nor the names of HOOMD-blue's contributors may be used to endorse or
31 promote products derived from this software without specific prior written
32 permission.
34 Disclaimer
36 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS'' AND
37 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
38 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND/OR ANY
39 WARRANTIES THAT THIS SOFTWARE IS FREE OF INFRINGEMENT ARE DISCLAIMED.
41 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
42 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
43 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
45 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46 OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
47 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50 // Maintainer: joaander
52 /*! \file IMDInterface.h
53 \brief Declares the IMDInterface class
56 #ifdef NVCC
57 #error This header cannot be compiled by nvcc
58 #endif
60 #include <boost/shared_ptr.hpp>
62 #include "Analyzer.h"
63 #include "ConstForceCompute.h"
65 #ifndef __IMD_INTERFACE_H__
66 #define __IMD_INTERFACE_H__
68 //! Iterfaces with VMD through the IMD communcations port
69 /*! analyze() can be called very often. When not connected to
70 VMD, it will do nothing. After a connection has been established,
71 which can only happen during a call to analyze(), further calls will
72 transmit particle positions to VMD.
74 In its current implementation, only a barebones set of commands are
75 supported. The sending of any command that is not understood will
76 result in the socket closing the connection.
77 \ingroup analyzers
79 class IMDInterface : public Analyzer
81 public:
82 //! Constructor
83 IMDInterface(boost::shared_ptr<SystemDefinition> sysdef,
84 int port = 54321,
85 bool pause = false,
86 unsigned int rate=1,
87 boost::shared_ptr<ConstForceCompute> force = boost::shared_ptr<ConstForceCompute>(),
88 float force_scale=1.0);
90 //! Destructor
91 ~IMDInterface();
93 //! Handle connection requests and send current positions if connected
94 void analyze(unsigned int timestep);
95 private:
96 void *m_listen_sock; //!< Socket we are listening on
97 void *m_connected_sock; //!< Socket to transmit/receive data
98 float *m_tmp_coords; //!< Temporary holding location for coordinate data
100 bool m_active; //!< True if we have received a go command
101 bool m_paused; //!< True if we are paused
102 unsigned int m_trate; //!< Transmission rate
103 unsigned int m_count; //!< Count the number of times analyze() is called (used with trate)
105 bool m_is_initialized; //!< True if the interface has been initialized
106 int m_port; //!< Port to listen on
108 boost::shared_ptr<ConstForceCompute> m_force; //!< Force for applying IMD forces
109 float m_force_scale; //!< Factor by which to scale all IMD forces
111 //! Helper function that reads message headers and dispatches them to the relevant process functions
112 void dispatch();
113 //! Helper function to determine of messages are still available
114 bool messagesAvailable();
115 //! Process the IMD_DISCONNECT message
116 void processIMD_DISCONNECT();
117 //! Process the IMD_GO message
118 void processIMD_GO();
119 //! Process the IMD_KILL message
120 void processIMD_KILL();
121 //! Process the IMD_MDCOMM message
122 void processIMD_MDCOMM(unsigned int n);
123 //! Process the IMD_TRATE message
124 void processIMD_TRATE(int rate);
125 //! Process the IMD_PAUSE message
126 void processIMD_PAUSE();
127 //! Process the IMD_IOERROR message
128 void processIMD_IOERROR();
129 //! Process a dead connection
130 void processDeadConnection();
132 //! Helper function to establish a connection
133 void establishConnectionAttempt();
134 //! Helper function to send current data to VMD
135 void sendCoords(unsigned int timestep);
137 //! Initialize socket and internal state variables for communication
138 void initConnection();
141 //! Exports the IMDInterface class to python
142 void export_IMDInterface();
144 #endif