3 * This source code is part of
7 * GROningen MAchine for Chemical Simulations
9 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
10 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
11 * Copyright (c) 2001-2009, The GROMACS development team,
12 * check out http://www.gromacs.org for more information.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * If you want to redistribute modifications, please consider that
20 * scientific software is very special. Version control is crucial -
21 * bugs must be traceable. We will be happy to consider code for
22 * inclusion in the official distribution, but derived work must not
23 * be called official GROMACS. Details are found in the README & COPYING
24 * files - if they are missing, get the official version at www.gromacs.org.
26 * To help us fund GROMACS development, we humbly ask that you cite
27 * the papers on the package - you can find them in the top README file.
29 * For more info, check our website at http://www.gromacs.org
33 * Declares gmx::TimeUnitManager.
35 * \author Teemu Murtola <teemu.murtola@cbr.su.se>
37 * \ingroup module_options
39 #ifndef GMX_OPTIONS_TIMEUNITMANAGER_H
40 #define GMX_OPTIONS_TIMEUNITMANAGER_H
42 #include "../utility/gmxassert.h"
50 * Time values for TimeUnitManager.
53 * Currently, this should match with the time_unit_t enum defined in oenv.h
54 * except that there is no NULL first item in this enum.
61 eTimeUnit_fs, //!< Femtoseconds.
62 eTimeUnit_ps, //!< Picoseconds.
63 eTimeUnit_ns, //!< Nanoseconds.
64 eTimeUnit_us, //!< Microseconds.
65 eTimeUnit_ms, //!< Milliseconds.
66 eTimeUnit_s //!< Seconds.
70 * Provides common functionality for time unit conversions.
72 * Methods/objects that need to deal with time units can either take a
73 * TimeUnitManager object, or they can take a TimeUnit value and construct a
74 * TimeUnitManager object internally.
76 * Default copy constructor and assignment are used: the copy is an independent
77 * object that is initialized with the same time unit as the original.
81 * Most of this class is independent of the options implementation.
82 * To ease reuse, it could be split such that the generic part is moved to the
83 * utility module, and only the options-specific parts left in the options
88 * \ingroup module_options
93 //! Creates a time unit manager with the default (ps) time unit.
95 //! Creates a time unit manager with the given time unit.
96 explicit TimeUnitManager(TimeUnit unit);
98 //! Returns the currently selected time unit.
99 TimeUnit timeUnit() const
101 GMX_ASSERT(timeUnit_ >= 0 && timeUnit_ <= eTimeUnit_s,
102 "Time unit index has become out-of-range");
103 return static_cast<TimeUnit>(timeUnit_);
105 //! Set a new time unit for the manager.
106 void setTimeUnit(TimeUnit unit);
108 //! Returns a string constant corresponding to the current time unit.
109 const char *timeUnitAsString() const;
111 //! Returns the scaling factor to convert times to ps.
112 double timeScaleFactor() const;
113 //! Returns the scaling factor to convert times from ps.
114 double inverseTimeScaleFactor() const;
117 * Adds a common option for selecting the time unit.
119 * \param[in,out] options Options to which the common option is added.
120 * \param[in] name Name of the option to add.
122 * Adds an enum option to \p options to select the time unit for this
125 void addTimeUnitOption(Options *options, const char *name);
127 * Scales user input values given to time options.
129 * \param[in,out] options Options in which to scale times.
131 * Scales each time option (see DoubleOption::timeValue()) in
132 * \p options such that any user-given values are interpreted as given
133 * in the time unit specified by this manager, and scaled to
134 * picoseconds. Programmatically given values (e.g., as default values
135 * for the options) are not scaled.
137 void scaleTimeOptions(Options *options) const;
141 * Currently set time unit for this manager.
143 * Type is int to make it possible to use it with
144 * StringOption::storeEnumIndex(), but it should always one of the
145 * allowed values for TimeUnit.