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.
49 // Maintainer: joaander
52 \brief Defines Variant and related classes
56 #pragma warning( push )
57 #pragma warning( disable : 4103 4244 )
64 #include <boost/python.hpp>
65 using namespace boost::python
;
68 VariantLinear::VariantLinear()
70 // initialize m_a and m_b to the end
75 /*! \param timestep Time step to set the value at
76 \param val Value to set at \a timestep
78 If a point at \a timestep has already been set, this overwrites it.
80 void VariantLinear::setPoint(unsigned int timestep
, double val
)
82 m_values
[timestep
] = val
;
85 /*! \param timestep Timestep to get the value at
86 \return Interpolated value
88 double VariantLinear::getValue(unsigned int timestep
)
90 // first transform the timestep by the offset
91 if (timestep
< m_offset
)
96 // handle the degenerate case that the variant is empty
99 cerr
<< endl
<< "***Error! No points specified to VariantLinear" << endl
<< endl
;
100 throw runtime_error("Error getting variant value");
103 // handle the degernate case that there is only one value in the variant
104 if (m_values
.size() == 1)
105 return m_values
.begin()->second
;
107 // handle beginning case
108 if (timestep
< m_values
.begin()->first
)
109 return m_values
.begin()->second
;
112 map
<unsigned int, double>::iterator last
= m_values
.end();
114 if (timestep
>= last
->first
)
117 // handle middle case
118 // check to see if the cache is still correct
119 bool cache_ok
= m_a
!= m_values
.end() && m_b
!= m_values
.end() && timestep
>= m_a
->first
&& timestep
< m_b
->first
;
122 // reload the cached iterators
123 m_a
= m_values
.upper_bound(timestep
);
127 assert(m_a
!= m_values
.end());
128 assert(m_b
!= m_values
.end());
132 unsigned int ta
= m_a
->first
;
133 unsigned int tb
= m_b
->first
;
136 double va
= m_a
->second
;
137 double vb
= m_b
->second
;
139 assert(timestep
>= ta
&& timestep
< tb
);
140 double f
= double((timestep
- ta
)) / double((tb
- ta
));
141 return (1.0 - f
) * va
+ f
* vb
;
144 void export_Variant()
146 class_
<Variant
, boost::shared_ptr
<Variant
> >("Variant", init
< >())
147 .def("getValue", &Variant::getValue
)
148 .def("setOffset", &Variant::setOffset
);
150 class_
<VariantConst
, boost::shared_ptr
<VariantConst
>, bases
<Variant
> >("VariantConst", init
< double >());
152 class_
<VariantLinear
, boost::shared_ptr
<VariantLinear
>, bases
<Variant
> >("VariantLinear", init
< >())
153 .def("setPoint", &VariantLinear::setPoint
);
157 #pragma warning( pop )