Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/MpqcParser_Parameters.hpp

    rc1db05 r7f570c  
    1414#endif
    1515
    16 #include <iosfwd>
    1716#include <list>
    18 #include <typeinfo>
     17#include <map>
    1918#include <vector>
    2019
    2120#include "CodePatterns/Clone.hpp"
    2221#include "CodePatterns/Log.hpp"
    23 #include "CodePatterns/Verbose.hpp"
    24 
    25 #include <boost/any.hpp>
    2622
    2723#include "Parser/FormatParser_Parameters.hpp"
     24
     25#include "Parser/Parameters/ContinuousParameter.hpp"
     26
     27// specialization for bool (we want "yes/no" not "1/0")
     28template <> const std::string ContinuousValue<bool>::get() const;
     29template <> void ContinuousValue<bool>::set(const std::string _value);
    2830
    2931class MpqcParser;
     
    4244  MpqcParser_Parameters();
    4345
    44   /** Copy Constructor of MpqcParser_Parameters.
    45    *
    46    * @param state ref to instance to copy
    47    */
    48   MpqcParser_Parameters(const MpqcParser_Parameters & state);
    49 
    5046  /** Destructor of MpqcParser_Parameters.
    5147   *
    5248   */
    5349  virtual ~MpqcParser_Parameters();
     50
     51  /** Enumeration of all known Parameters to allow placing them in vectors, maps.
     52   *
     53   */
     54  enum Parameters {
     55    hessianParam,    //!< HessianParam, whether hessian should be calculated or not
     56    savestateParam,  //!< savestateParam, whether intermediate/final states (wave function) should be stored
     57    do_gradientParam,//!< do_gradientParam, whether a gradient should be calculated
     58    maxiterParam,    //!< maxiterParam, number of maximum iterations for CG
     59    memoryParam,     //!< memoryParam, maximum amount of memory to use
     60    stdapproxParam,  //!< stdapproxParam, standard approximation in MBPT2 R12
     61    nfzcParam,       //!< nfzcParam, nfzc parameter in MBPT2 R12
     62    basisParam,      //!< basisParam, basis set to use
     63    aux_basisParam,  //!< aux_basisParam, auxiliary baseis set to use in MBPT2 R12
     64    integrationParam,//!< integrationParam, integration method to use in MBPT2 R12
     65    theoryParam,     //!< theoryParam, level of theory to use
     66    unknownParam};   //!< unknownParam, designates an unknown parameter
    5467
    5568  /** Enumeration of all known theories.
     
    7285  };
    7386
    74   /** Enumeration of all known Parameters to allow placing them in vectors, maps.
    75    *
    76    */
    77   enum Parameters {
    78     hessianParam,    //!< HessianParam, whether hessian should be calculated or not
    79     savestateParam,  //!< savestateParam, whether intermediate/final states (wave function) should be stored
    80     do_gradientParam,//!< do_gradientParam, whether a gradient should be calculated
    81     maxiterParam,    //!< maxiterParam, number of maximum iterations for CG
    82     memoryParam,     //!< memoryParam, maximum amount of memory to use
    83     stdapproxParam,  //!< stdapproxParam, standard approximation in MBPT2 R12
    84     nfzcParam,       //!< nfzcParam, nfzc parameter in MBPT2 R12
    85     basisParam,      //!< basisParam, basis set to use
    86     aux_basisParam,  //!< aux_basisParam, auxiliary baseis set to use in MBPT2 R12
    87     integrationParam,//!< integrationParam, integration method to use in MBPT2 R12
    88     theoryParam,     //!< theoryParam, level of theory to use
    89     unknownParam};   //!< unknownParam, designates an unknown parameter
     87  // enum to string getters
     88  const std::string getParameter(const enum Parameters param) const;
     89  void setParameter(const enum Parameters param, const std::string &);
     90  const std::string &getParameterName(const enum Parameters param) const;
     91  const std::string &getTheoryName(const enum Theory theory) const;
     92  const std::string &getIntegrationMethodName(const enum IntegrationMethod integration) const;
     93
     94private:
     95
     96
     97  //!> vector with all available theories in same order as enum Theory.
     98  std::vector<std::string> ValidTheories;
     99
     100  //!> vector with all available integration methods in same order as enum IntegrationMethod.
     101  std::vector<std::string> ValidIntegrationMethods;
    90102
    91103  bool checkWorldElementsAgainstCurrentBasis() const;
    92104
    93   /** Sets the desired level of solving theory to use.
    94    *
    95    * \param _theory shorthand of the theory
    96    */
    97   void setTheory(enum Theory _theory);
    98 
    99   /** Sets the desired level of solving integration to use.
    100    *
    101    * \param _integration shorthand of the integration
    102    */
    103   void setIntegration(enum IntegrationMethod _integration);
    104 
    105   /** Getter for integration method in params.
    106    *
    107    * @return enumeration index of IntegrationMethod.
    108    */
    109   enum IntegrationMethod getIntegration() const;
    110 
    111   /** Getter for current Theory in params.
    112    *
    113    * @return enumeration index of Theory
    114    */
    115   enum Theory getTheory() const;
    116 
    117   /** Getter for a parameter in params as a string.
    118    *
    119    * @param _param enumeration index of desired Parameter
    120    * @return string value
    121    */
    122   std::string getString(enum Parameters _param) const;
    123 
    124   /** Getter for integer value of desired Parameter in params.
    125    *
    126    * Only if type in params matches int!
    127    *
    128    * @param _param enumeration index in Parameter
    129    * @return integer value of parameter
    130    */
    131   int getInt(enum Parameters _param) const;
    132 
    133   /** Getter for double value of desired Parameter in params.
    134    *
    135    * Only if type in params matches double!
    136    *
    137    * @param _param enumeration index in Parameter
    138    * @return double value of parameter
    139    */
    140   double getDouble(enum Parameters _param) const;
    141 
    142   /** Getter for bool value of desired Parameter in params.
    143    *
    144    * Only if type in params matches bool!
    145    *
    146    * @param _param enumeration index in Parameter
    147    * @return bool value of parameter
    148    */
    149   bool getBool(enum Parameters _param) const;
    150 
    151   /** Setter for a desired value of its type is known.
    152    *
    153    * We check whether given type matches present type in params.
    154    *
    155    * @param _param enumeration index of Parameter
    156    * @param _desired desired value to set to
    157    * @return true - type match, value set, false - type mismatch
    158    */
    159   template <class T> bool setter(enum Parameters _param, T _desired) {
    160     if (typeid(T) == params[_param].type()) {
    161       params[_param] = _desired;
    162       return true;
    163     } else
    164       return false;
    165   }
    166 
    167   /** Sets a desired value in the params from a string.
    168    *
    169    * This is due to strict typing of C++ very ugly and boost::any does not make
    170    * it any better because it offers to functions to use values directly from
    171    * stringstream. Probably, because value is unknown to is as well and hence
    172    * the author could not implement it beautifully, so he dropped it altogether.
    173    * Grrr ....
    174    *
    175    * @param _param param to set
    176    * @param _desired stringstream containing value as next argument
    177    * @return true - type ok, false - unknown type in params.
    178    */
    179   bool setter(enum Parameters _param, std::stringstream& _desired);
    180 
    181   /** Grants access to ParamLookup.
    182    *
    183    *  Does not check for unknown parameter.
    184    *
    185    * @param _name name of parameter
    186    * @return enumeration index of Parameters
    187    */
    188   enum Parameters getParam(std::string _name) const;
    189 
    190   /** Checker whether parameter with name is known.
    191    *
    192    * @param _name
    193    * @return true - parameter known, false - parameter unknown
    194    */
    195   bool haveParam(std::string _name) const;
    196 
    197   /** Creates a clone of the class.
    198    *
    199    * @return
    200    */
    201   FormatParser_Parameters* clone() const;
    202 
    203   /** Applies a before returned undo state.
    204    *
    205    * @param undo state to set
    206    */
    207   void makeClone(const FormatParser_Parameters & _state);
    208 
    209   /** Set the internal parameters to the one's from the given \a state.
    210    *
    211    * @param state set of parameters
    212    */
    213   void copyParameters(const MpqcParser_Parameters & state);
    214 
    215 private:
    216105  /** Global initialization in cstor.
    217106   *
     
    224113  void initBasis();
    225114
    226   /** Initializes params.
    227    * Sets the type and the associated enumeration index.
    228    */
    229   void initParameters();
     115  //!> vector with all parameter names in same order as enum Parameters
     116  std::vector<std::string> ParamNames;
    230117
    231   /** Internal function used by initParameters() to add parameters to params.
    232    *
    233    * @param _enum enumeration index to set
    234    * @param _p (default) value to set with certain type
    235    */
    236   template <class T> void appendParameter(enum Parameters _enum, T _p) {
    237     boost::any _p_value = _p;
    238     params[_enum] = _p_value;
    239   }
     118  //!> typedef for the list of all available basis sets
     119  typedef std::map<std::string, std::list<std::string> > BasisMapType;
    240120
    241   // all internal typedefs for lists below
    242   typedef std::map<std::string, std::list<std::string> > BasisMapType;
    243   typedef std::map<enum Theory, std::string> TheoryNamesType;
    244   typedef std::map<std::string, enum Theory> TheoryLookupType;
    245   typedef std::map<enum IntegrationMethod, std::string> IntegrationNamesType;
    246   typedef std::map<std::string, enum IntegrationMethod> IntegrationLookupType;
    247   typedef std::map<enum Parameters, std::string> ParamNamesType;
    248   typedef std::map<std::string, enum Parameters> ParamLookupType;
    249   typedef std::map<enum Parameters, boost::any> parameterlist;
    250 
    251   //!> boost::any container for all the parameters
    252   parameterlist params;
    253 
    254   // maps from names to enumerations
    255 
    256   //!> contains basis and all elements the basis knows about
     121  //!> list of all basis along with their present element parametrization
    257122  BasisMapType BasisList;
    258   //!> contains the name of a theory as string
    259   TheoryNamesType TheoryNames;
    260   //!> contains a lookup from theory name to enumeration index
    261   TheoryLookupType TheoryLookup;
    262   //!> contains the name of an integration method as string
    263   IntegrationNamesType IntegrationNames;
    264   //!> contains a lookup from integration method name to enumeration index
    265   IntegrationLookupType IntegrationLookup;
    266   //!> contains the name of a parameter
    267   ParamNamesType ParamNames;
    268   //!> contains a lookup from parameter name to enumeration index
    269   ParamLookupType ParamLookup;
    270123};
    271124
    272 /** Output operator for the contents of MpqcParser_Parameters::params.
    273  *
    274  * @param ost output stream
    275  * @param params reference to MpqcParser_Parameters containing params.
    276  * @return reference to output stream for concatenation
    277  */
    278 std::ostream & operator << (std::ostream& ost, const MpqcParser_Parameters &params);
    279 
    280 /** Input operator for a list of parameters to place into \a params.
    281  *
    282  * @param ist input stream
    283  * @param params parameters to parse into
    284  * @return input stream for concatenation
    285  */
    286 std::istream & operator >> (std::istream& ist, MpqcParser_Parameters &params);
    287 
    288125#endif /* MPQCPARSER_PARAMETERS_HPP_ */
Note: See TracChangeset for help on using the changeset viewer.