1 | /*
|
---|
2 | * SerializablePotential.hpp
|
---|
3 | *
|
---|
4 | * Created on: 23.11.2012
|
---|
5 | * Author: heber
|
---|
6 | */
|
---|
7 |
|
---|
8 | #ifndef SERIALIZABLEPOTENTIAL_HPP_
|
---|
9 | #define SERIALIZABLEPOTENTIAL_HPP_
|
---|
10 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #include <iosfwd>
|
---|
17 | #include <vector>
|
---|
18 |
|
---|
19 | /** SerializablePotential is a potential that can be parsed from and stored to
|
---|
20 | * a .potentials file.
|
---|
21 | *
|
---|
22 | * All required functionality for printing and parsing the set of parameters
|
---|
23 | * is set as virtual functions and have to be implemented specifically, e.g.
|
---|
24 | * -# ParameterNames: Should be static instance as are the same over each
|
---|
25 | * potential type despite although there may be more than one instance.
|
---|
26 | * \note If the parameter name is left empty, the value is neither printed
|
---|
27 | * nor parsed. This may be issued to skip internal parameters (e.g. offset).
|
---|
28 | * -# ParticleTypes: has been implemented here, as is different per instance.
|
---|
29 | *
|
---|
30 | * Specifically, what you need to do when inheriting is:
|
---|
31 | * -# implement getParameters() and setParameters()
|
---|
32 | * -# have some static const ParameterNames_t in your class and implement
|
---|
33 | * getParameterNames() as a getter for it (or any other way you prefer).
|
---|
34 | * The static instance can be easily initialized via boost::assign::list_of.
|
---|
35 | *
|
---|
36 | */
|
---|
37 | class SerializablePotential
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | //!> typedef for particle designation
|
---|
41 | typedef int ParticleType_t;
|
---|
42 | //!> typedef for a vector of particle designations
|
---|
43 | typedef std::vector<ParticleType_t> ParticleTypes_t;
|
---|
44 | //!> typedef for a vector of parameter names
|
---|
45 | typedef std::vector<std::string> ParameterNames_t;
|
---|
46 | //!> typedef for a single parameter degree of freedom of the function
|
---|
47 | typedef double parameter_t;
|
---|
48 | //!> typedef for the whole set of parameters of the function
|
---|
49 | typedef std::vector<parameter_t> parameters_t;
|
---|
50 |
|
---|
51 | public:
|
---|
52 | SerializablePotential(const ParticleTypes_t &_ParticleTypes) :
|
---|
53 | ParticleTypes(_ParticleTypes)
|
---|
54 | {}
|
---|
55 | virtual ~SerializablePotential() {}
|
---|
56 |
|
---|
57 | /** Return the token name of this specific potential.
|
---|
58 | *
|
---|
59 | * \return token name of the potential
|
---|
60 | */
|
---|
61 | virtual const std::string& getToken() const=0;
|
---|
62 |
|
---|
63 | /** Return the name of this specific potential.
|
---|
64 | *
|
---|
65 | * This is required for storage in a Registry. The name is the token name
|
---|
66 | * followed by "_" and the particle types to make it unique.
|
---|
67 | *
|
---|
68 | * \return name of the potential
|
---|
69 | */
|
---|
70 | const std::string getName() const;
|
---|
71 |
|
---|
72 |
|
---|
73 | /** Getter for the parameters of this model function.
|
---|
74 | *
|
---|
75 | * \return current set of parameters of the model function
|
---|
76 | */
|
---|
77 | virtual parameters_t getParameters() const=0;
|
---|
78 |
|
---|
79 | /** Getter for the number of parameters of this model function.
|
---|
80 | *
|
---|
81 | * \return number of parameters
|
---|
82 | */
|
---|
83 | virtual size_t getParameterDimension() const=0;
|
---|
84 |
|
---|
85 | /** Returns a vector of particle designations.
|
---|
86 | *
|
---|
87 | * These designations denote the particle types for which this potential
|
---|
88 | * has been parametrized.
|
---|
89 | *
|
---|
90 | * \return vector of particle type
|
---|
91 | */
|
---|
92 | const ParticleTypes_t& getParticleTypes() const
|
---|
93 | { return ParticleTypes; }
|
---|
94 |
|
---|
95 | /** Returns a vector of parameter names.
|
---|
96 | *
|
---|
97 | * This is required from the specific implementation
|
---|
98 | *
|
---|
99 | * \return vector of strings containing parameter names
|
---|
100 | */
|
---|
101 | virtual const ParameterNames_t& getParameterNames() const=0;
|
---|
102 |
|
---|
103 | /** Returns the index associated to a specific parameter \a _name.
|
---|
104 | *
|
---|
105 | * \param _name parameter name to look up index for
|
---|
106 | * \return index to the given \a _name or (size_t)-1 if none found
|
---|
107 | */
|
---|
108 | const size_t getParameterIndex(const std::string &_name) const;
|
---|
109 |
|
---|
110 | /** Print parameters to given stream \a ost.
|
---|
111 | *
|
---|
112 | * These are virtual functions to allow for overriding and hence
|
---|
113 | * changing the default behavior.
|
---|
114 | *
|
---|
115 | * @param ost stream to print to
|
---|
116 | */
|
---|
117 | virtual void stream_to(std::ostream &ost) const;
|
---|
118 |
|
---|
119 | /** Parse parameters from given stream \a ist.
|
---|
120 | *
|
---|
121 | * These are virtual functions to allow for overriding and hence
|
---|
122 | * changing the default behavior.
|
---|
123 | *
|
---|
124 | * @param ist stream to parse from
|
---|
125 | */
|
---|
126 | virtual void stream_from(std::istream &ist);
|
---|
127 |
|
---|
128 | protected:
|
---|
129 |
|
---|
130 | /** Setter for the parameters of the model function.
|
---|
131 | *
|
---|
132 | * \param params set of parameters to set
|
---|
133 | */
|
---|
134 | virtual void setParameters(const parameters_t ¶ms)=0;
|
---|
135 |
|
---|
136 | /** Setter for a given particle type.
|
---|
137 | *
|
---|
138 | * \param index index of type to set
|
---|
139 | * \param _designation type to set to
|
---|
140 | */
|
---|
141 | void setParticleType(const size_t index, const ParticleType_t& _designation)
|
---|
142 | {
|
---|
143 | if (ParticleTypes.size() <= index)
|
---|
144 | const_cast<ParticleTypes_t &>(ParticleTypes).resize(index+1);
|
---|
145 | const_cast<ParticleTypes_t &>(ParticleTypes)[index] = _designation;
|
---|
146 | }
|
---|
147 |
|
---|
148 | protected:
|
---|
149 | /** Default constructor for class EmpiricalPotential.
|
---|
150 | *
|
---|
151 | * Callable only by derived functions.
|
---|
152 | *
|
---|
153 | */
|
---|
154 | SerializablePotential();
|
---|
155 |
|
---|
156 | private:
|
---|
157 |
|
---|
158 | //!> static definition of the particle types for this potential
|
---|
159 | const ParticleTypes_t ParticleTypes;
|
---|
160 | };
|
---|
161 |
|
---|
162 | /** Output operations stores .potentials line containing these parameters
|
---|
163 | * coefficients and designations.
|
---|
164 | *
|
---|
165 | * \param ost output stream to print to
|
---|
166 | * \param potential potential whose coefficients to print
|
---|
167 | * \return output stream for concatenation
|
---|
168 | */
|
---|
169 | std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential);
|
---|
170 |
|
---|
171 | /** Input operation parses coefficients from a given line of a .potentials
|
---|
172 | * file.
|
---|
173 | *
|
---|
174 | * \param ist input stream to parse from
|
---|
175 | * \param potential potential to set
|
---|
176 | * \return input stream for concatenation
|
---|
177 | */
|
---|
178 | std::istream& operator>>(std::istream &ist, SerializablePotential &potential);
|
---|
179 |
|
---|
180 |
|
---|
181 | #endif /* SERIALIZABLEPOTENTIAL_HPP_ */
|
---|