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
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
53 #pragma warning( push )
54 #pragma warning( disable : 4244 )
57 #include <boost/python.hpp>
58 using namespace boost::python
;
67 \brief Contains code for the Compute class
70 /*! \param sysdef SystemDefinition this compute will act on. Must not be NULL.
71 \post The Compute is constructed with the given particle data and a NULL profiler.
73 Compute::Compute(boost::shared_ptr
<SystemDefinition
> sysdef
) : m_sysdef(sysdef
), m_pdata(m_sysdef
->getParticleData()),
74 exec_conf(m_pdata
->getExecConf()), m_force_compute(false), m_last_computed(0), m_first_compute(true)
79 m_exec_conf
= exec_conf
;
82 /*! \param num_iters Number of iterations to average for the benchmark
83 \returns Milliseconds of execution time per calculation
84 Derived classes can optionally implement this method. */
85 double Compute::benchmark(unsigned int num_iters
)
87 m_exec_conf
->msg
->error() << "This compute doesn't support benchmarking" << endl
;
88 throw runtime_error("Error benchmarking compute");
92 /*! It is useful for the user to know where computation time is spent, so all Computes
93 should profile themselves. This method sets the profiler for them to use.
94 This method does not need to be called, as Computes will not profile themselves
96 \param prof Pointer to a profiler for the compute to use. Set to NULL
97 (boost::shared_ptr<Profiler>()) to stop the
98 analyzer from profiling itself.
99 \note Derived classes MUST check if m_prof is set before calling any profiler methods.
101 void Compute::setProfiler(boost::shared_ptr
<Profiler
> prof
)
106 /*! \param timestep Current time step
107 \returns true if computations should be performed, false if they have already been done
109 \note This method is designed to only be called once per call to compute() like so:
111 void SomeClass::compute(unsgned int timestep)
113 if (!shouldCompute(timestep))
119 bool Compute::shouldCompute(unsigned int timestep
)
121 // handle case where no computation has been performed yet
124 m_first_compute
= false;
125 m_last_computed
= timestep
;
129 // Update if computation is enforced, but leave m_last_computed unchanged
130 // (such that after a forced compute(), still a regular compute() is possible)
133 m_force_compute
= false;
137 // otherwise, we update if the last computed timestep is less than the current
138 if (m_last_computed
!= timestep
)
140 m_last_computed
= timestep
;
145 // failing the above, we perform no computation
149 void Compute::forceCompute(unsigned int timestep
)
151 m_force_compute
= true;
156 //! Wrapper class for handling virtual methods of Compute in python
157 class ComputeWrap
: public Compute
, public wrapper
<Compute
>
161 /*! \param sysdef Particle data to pass on to the base class */
162 ComputeWrap(boost::shared_ptr
<SystemDefinition
> sysdef
) : Compute(sysdef
)
166 //! Calls overidden Compute::compute()
167 /*! \param timestep Parameter to pass on to the base class method */
168 void compute(unsigned int timestep
)
170 this->get_override("compute")(timestep
);
173 //! Calls overidden Compute::compute()
174 /*! \param num_iters Parameter to pass on to the base class method */
175 double benchmark(unsigned int num_iters
)
177 if (override f
= this->get_override("benchmark"))
180 return Compute::benchmark(num_iters
);
183 //! Calls overridden Compute::printStats()
186 if (override f
= this->get_override("printStats"))
189 Compute::printStats();
192 //! Default implementation of Compute::printStats()
193 void default_printStats()
195 this->Compute::printStats();
198 // A decision has been made to not currently support deriving new compute classes in python
199 // thus, the internal methods of Compute that are only needed for that purpose do not need to be
200 // exported, only the public interface
202 // Calls overridden Compute::shouldCompute()
203 /* \param timestep Parameter to pass on to the base class method */
204 /*bool shouldCompute(unsigned int timestep)
206 if (override f = this->get_override("shouldCompute"))
209 return Compute::shouldCompute(timestep);
212 // Default implementation of Compute::shouldCompute()
213 /* \param timestep Parameter to pass on to the base class method */
214 /*bool default_shouldCompute(unsigned int timestep)
216 return this->Compute::shouldCompute(timestep);
219 // The python export needs to be a friend to export protected members
220 friend void export_Compute();*/
223 void export_Compute()
225 class_
<ComputeWrap
, boost::shared_ptr
<ComputeWrap
>, boost::noncopyable
>("Compute", init
< boost::shared_ptr
<SystemDefinition
> >())
226 .def("compute", pure_virtual(&Compute::compute
))
227 .def("benchmark", pure_virtual(&Compute::benchmark
))
228 .def("printStats", &Compute::printStats
, &ComputeWrap::default_printStats
)
229 .def("setProfiler", &Compute::setProfiler
)
234 #pragma warning( pop )