| 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 |   //!> grant operator access to private functions
 | 
|---|
| 40 |   friend std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential);
 | 
|---|
| 41 |   //!> grant operator access to private functions
 | 
|---|
| 42 |   friend std::istream& operator>>(std::istream &ost, SerializablePotential &potential);
 | 
|---|
| 43 | 
 | 
|---|
| 44 | public:
 | 
|---|
| 45 |   //!> typedef for particle designation
 | 
|---|
| 46 |   typedef int ParticleType_t;
 | 
|---|
| 47 |   //!> typedef for a vector of particle designations
 | 
|---|
| 48 |   typedef std::vector<ParticleType_t> ParticleTypes_t;
 | 
|---|
| 49 |   //!> typedef for a vector of parameter names
 | 
|---|
| 50 |   typedef std::vector<std::string> ParameterNames_t;
 | 
|---|
| 51 |   //!> typedef for a single parameter degree of freedom of the function
 | 
|---|
| 52 |   typedef double parameter_t;
 | 
|---|
| 53 |   //!> typedef for the whole set of parameters of the function
 | 
|---|
| 54 |   typedef std::vector<parameter_t> parameters_t;
 | 
|---|
| 55 | 
 | 
|---|
| 56 | public:
 | 
|---|
| 57 |   SerializablePotential(const ParticleTypes_t &_ParticleTypes) :
 | 
|---|
| 58 |     ParticleTypes(_ParticleTypes)
 | 
|---|
| 59 |   {}
 | 
|---|
| 60 |   ~SerializablePotential() {}
 | 
|---|
| 61 | 
 | 
|---|
| 62 |   /** Return the token name of this specific potential.
 | 
|---|
| 63 |    *
 | 
|---|
| 64 |    * \return token name of the potential
 | 
|---|
| 65 |    */
 | 
|---|
| 66 |   virtual const std::string& getToken() const=0;
 | 
|---|
| 67 | 
 | 
|---|
| 68 |   /** Return the name of this specific potential.
 | 
|---|
| 69 |    *
 | 
|---|
| 70 |    * This is required for storage in a Registry. The name is the token name
 | 
|---|
| 71 |    * followed by "_" and the particle types to make it unique.
 | 
|---|
| 72 |    *
 | 
|---|
| 73 |    * \return name of the potential
 | 
|---|
| 74 |    */
 | 
|---|
| 75 |   const std::string getName() const;
 | 
|---|
| 76 | 
 | 
|---|
| 77 | 
 | 
|---|
| 78 |   /** Getter for the parameters of this model function.
 | 
|---|
| 79 |    *
 | 
|---|
| 80 |    * \return current set of parameters of the model function
 | 
|---|
| 81 |    */
 | 
|---|
| 82 |   virtual parameters_t getParameters() const=0;
 | 
|---|
| 83 | 
 | 
|---|
| 84 |   /** Getter for the number of parameters of this model function.
 | 
|---|
| 85 |    *
 | 
|---|
| 86 |    * \return number of parameters
 | 
|---|
| 87 |    */
 | 
|---|
| 88 |   virtual size_t getParameterDimension() const=0;
 | 
|---|
| 89 | 
 | 
|---|
| 90 |   /** Returns a vector of particle designations.
 | 
|---|
| 91 |    *
 | 
|---|
| 92 |    * These designations denote the particle types for which this potential
 | 
|---|
| 93 |    * has been parametrized.
 | 
|---|
| 94 |    *
 | 
|---|
| 95 |    * \return vector of particle type
 | 
|---|
| 96 |    */
 | 
|---|
| 97 |   const ParticleTypes_t& getParticleTypes() const
 | 
|---|
| 98 |   { return ParticleTypes; }
 | 
|---|
| 99 | 
 | 
|---|
| 100 |   /** Returns a vector of parameter names.
 | 
|---|
| 101 |    *
 | 
|---|
| 102 |    * This is required from the specific implementation
 | 
|---|
| 103 |    *
 | 
|---|
| 104 |    * \return vector of strings containing parameter names
 | 
|---|
| 105 |    */
 | 
|---|
| 106 |   virtual const ParameterNames_t& getParameterNames() const=0;
 | 
|---|
| 107 | 
 | 
|---|
| 108 |   /** Returns the index associated to a specific parameter \a _name.
 | 
|---|
| 109 |    *
 | 
|---|
| 110 |    * \param _name parameter name to look up index for
 | 
|---|
| 111 |    * \return index to the given \a _name or (size_t)-1 if none found
 | 
|---|
| 112 |    */
 | 
|---|
| 113 |   const size_t getParameterIndex(const std::string &_name) const;
 | 
|---|
| 114 | 
 | 
|---|
| 115 | protected:
 | 
|---|
| 116 | 
 | 
|---|
| 117 |   /** Setter for the parameters of the model function.
 | 
|---|
| 118 |    *
 | 
|---|
| 119 |    * \param params set of parameters to set
 | 
|---|
| 120 |    */
 | 
|---|
| 121 |   virtual void setParameters(const parameters_t ¶ms)=0;
 | 
|---|
| 122 | 
 | 
|---|
| 123 |   /** Setter for a given particle type.
 | 
|---|
| 124 |    *
 | 
|---|
| 125 |    * \param index index of type to set
 | 
|---|
| 126 |    * \param _designation type to set to
 | 
|---|
| 127 |    */
 | 
|---|
| 128 |   void setParticleType(const size_t index, const ParticleType_t& _designation)
 | 
|---|
| 129 |   {
 | 
|---|
| 130 |     const_cast<ParticleTypes_t &>(ParticleTypes).resize(index);
 | 
|---|
| 131 |     const_cast<ParticleTypes_t &>(ParticleTypes)[index] = _designation;
 | 
|---|
| 132 |   }
 | 
|---|
| 133 | 
 | 
|---|
| 134 | private:
 | 
|---|
| 135 | 
 | 
|---|
| 136 |   //!> static definition of the particle types for this potential
 | 
|---|
| 137 |   const ParticleTypes_t ParticleTypes;
 | 
|---|
| 138 | };
 | 
|---|
| 139 | 
 | 
|---|
| 140 | /** Output operations stores .potentials line containing these parameters
 | 
|---|
| 141 |  * coefficients and designations.
 | 
|---|
| 142 |  *
 | 
|---|
| 143 |  * \param ost output stream to print to
 | 
|---|
| 144 |  * \param potential potential whose coefficients to print
 | 
|---|
| 145 |  * \return output stream for concatenation
 | 
|---|
| 146 |  */
 | 
|---|
| 147 | std::ostream& operator<<(std::ostream &ost, const SerializablePotential &potential);
 | 
|---|
| 148 | 
 | 
|---|
| 149 | /** Input operation parses coefficients from a given line of a .potentials
 | 
|---|
| 150 |  * file.
 | 
|---|
| 151 |  *
 | 
|---|
| 152 |  * \param ist input stream to parse from
 | 
|---|
| 153 |  * \param potential potential to set
 | 
|---|
| 154 |  * \return input stream for concatenation
 | 
|---|
| 155 |  */
 | 
|---|
| 156 | std::istream& operator>>(std::istream &ist, SerializablePotential &potential);
 | 
|---|
| 157 | 
 | 
|---|
| 158 | 
 | 
|---|
| 159 | #endif /* SERIALIZABLEPOTENTIAL_HPP_ */
 | 
|---|