LCOV - code coverage report
Current view: top level - pairinteraction - StateOld.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 15 15 100.0 %
Date: 2024-04-29 00:41:50 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Copyright (c) 2016 Sebastian Weber, Henri Menke. All rights reserved.
       3             :  *
       4             :  * This file is part of the pairinteraction library.
       5             :  *
       6             :  * The pairinteraction library is free software: you can redistribute it and/or modify
       7             :  * it under the terms of the GNU Lesser General Public License as published by
       8             :  * the Free Software Foundation, either version 3 of the License, or
       9             :  * (at your option) any later version.
      10             :  *
      11             :  * The pairinteraction library is distributed in the hope that it will be useful,
      12             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :  * GNU Lesser General Public License for more details.
      15             :  *
      16             :  * You should have received a copy of the GNU Lesser General Public License
      17             :  * along with the pairinteraction library. If not, see <http://www.gnu.org/licenses/>.
      18             :  */
      19             : 
      20             : #ifndef STATEOLD_H
      21             : #define STATEOLD_H
      22             : 
      23             : #include "utils.hpp"
      24             : 
      25             : #include <array>
      26             : #include <cmath>
      27             : #include <iostream>
      28             : #include <string>
      29             : 
      30             : #include <cereal/types/array.hpp>
      31             : #include <cereal/types/string.hpp>
      32             : 
      33             : typedef uint32_t idx_t;
      34             : 
      35             : /** \brief %Base class for states
      36             :  *
      37             :  * This class is the base class for states specified in the fine structure basis.
      38             :  */
      39             : class StateOld {
      40             : public:
      41      432342 :     StateOld(idx_t idx) : idx(idx) {}
      42             :     idx_t idx;
      43             : };
      44             : 
      45             : /** \brief %One-atom Rydberg state
      46             :  *
      47             :  * This class implements a one-atom Rydberg state.
      48             :  */
      49             : class StateOneOld : public StateOld {
      50             : public:
      51             :     // These are public to allow direct access.  This violates the
      52             :     // open/closed principle and is a sign of code smell.
      53             :     std::string species, element;
      54             :     int n{0};
      55             :     int l{0};
      56             :     float j{0};
      57             :     float m{0};
      58             :     float s;
      59             : 
      60             :     StateOneOld();
      61             :     StateOneOld(std::string element, int n, int l, float j, float m);
      62             :     StateOneOld(idx_t idx, int n, int l, float j, float m);
      63             :     StateOneOld(int n, int l, float j, float m);
      64             : 
      65             :     friend std::ostream &operator<<(std::ostream &out, const StateOneOld &state);
      66             : 
      67             :     bool operator==(StateOneOld const & /*rhs*/) const;
      68             :     bool operator^(StateOneOld const & /*rhs*/) const; // subset
      69             :     bool operator!=(StateOneOld const & /*rhs*/) const;
      70             :     bool operator<(StateOneOld const & /*rhs*/) const;
      71             : 
      72             :     double getEnergy() const;
      73             :     double getNStar() const;
      74             : 
      75             :     std::string getSpecies() const;
      76             :     int getN() const;
      77             :     int getL() const;
      78             :     float getJ() const;
      79             :     float getM() const;
      80             : 
      81             : private:
      82             :     ////////////////////////////////////////////////////////////////////
      83             :     /// Utility methods ////////////////////////////////////////////////
      84             :     ////////////////////////////////////////////////////////////////////
      85             : 
      86             :     void analyzeSpecies();
      87             : 
      88             :     ////////////////////////////////////////////////////////////////////
      89             :     /// Method for serialization ///////////////////////////////////////
      90             :     ////////////////////////////////////////////////////////////////////
      91             : 
      92             :     friend class cereal::access;
      93             : 
      94             :     template <class Archive>
      95             :     void serialize(Archive &ar, unsigned int /* version */) {
      96             :         ar &CEREAL_NVP(species) & CEREAL_NVP(element) & CEREAL_NVP(s) & CEREAL_NVP(n) &
      97             :             CEREAL_NVP(l) & CEREAL_NVP(j) & CEREAL_NVP(m);
      98             :     }
      99             : };
     100             : 
     101             : /** \brief %Two-atom Rydberg state
     102             :  *
     103             :  * This class implements a two-atom Rydberg state.
     104             :  */
     105             : class StateTwoOld : public StateOld { // TODO define getters and setters, save a pair state as two
     106             :                                       // single atom states
     107             : public:
     108             :     // These are public to allow direct access.  This violates the
     109             :     // open/closed principle and is a sign of code smell.
     110             :     std::array<std::string, 2> species, element;
     111             :     std::array<int, 2> n, l;
     112             :     std::array<float, 2> j, m, s;
     113             : 
     114             :     StateTwoOld();
     115             :     StateTwoOld(std::array<std::string, 2> element, std::array<int, 2> n, std::array<int, 2> l,
     116             :                 std::array<float, 2> j, std::array<float, 2> m);
     117             :     StateTwoOld(const StateOneOld &s1, const StateOneOld &s2);
     118             :     StateTwoOld(idx_t idx, std::array<int, 2> n, std::array<int, 2> l, std::array<float, 2> j,
     119             :                 std::array<float, 2> m);
     120             :     StateTwoOld(std::array<int, 2> n, std::array<int, 2> l, std::array<float, 2> j,
     121             :                 std::array<float, 2> m);
     122             :     StateTwoOld(idx_t idx, const StateOneOld &a, const StateOneOld &b);
     123             : 
     124             :     StateOneOld getFirstState() const;
     125             :     StateOneOld getSecondState() const;
     126             :     void setFirstState(StateOneOld const & /*s*/);
     127             :     void setSecondState(StateOneOld const & /*s*/);
     128             : 
     129             :     StateOneOld first() const;
     130             :     StateOneOld second() const;
     131             : 
     132             :     friend std::ostream &operator<<(std::ostream &out, const StateTwoOld &state);
     133             : 
     134             :     bool operator==(StateTwoOld const & /*rhs*/) const;
     135             :     bool operator^(StateTwoOld const & /*rhs*/) const; // subset
     136             :     bool operator!=(StateTwoOld const & /*rhs*/) const;
     137             :     bool operator<(StateTwoOld const & /*rhs*/) const;
     138             : 
     139             :     StateTwoOld order();
     140             : 
     141             :     double getEnergy() const;
     142             :     std::array<double, 2> getNStar() const;
     143             : 
     144             :     std::array<std::string, 2> getSpecies() const;
     145             :     std::array<int, 2> getN() const;
     146             :     std::array<int, 2> getL() const;
     147             :     std::array<float, 2> getJ() const;
     148             :     std::array<float, 2> getM() const;
     149             : 
     150             : private:
     151             :     ////////////////////////////////////////////////////////////////////
     152             :     /// Utility methods ////////////////////////////////////////////////
     153             :     ////////////////////////////////////////////////////////////////////
     154             : 
     155             :     void analyzeSpecies();
     156             : 
     157             :     ////////////////////////////////////////////////////////////////////
     158             :     /// Method for serialization ///////////////////////////////////////
     159             :     ////////////////////////////////////////////////////////////////////
     160             : 
     161             :     friend class cereal::access;
     162             : 
     163             :     template <class Archive>
     164             :     void serialize(Archive &ar, unsigned int /* version */) {
     165             :         ar &CEREAL_NVP(species) & CEREAL_NVP(element) & CEREAL_NVP(s) & CEREAL_NVP(n) &
     166             :             CEREAL_NVP(l) & CEREAL_NVP(j) & CEREAL_NVP(m);
     167             :     }
     168             : };
     169             : 
     170             : #ifndef SWIG
     171             : namespace std {
     172             : 
     173             : template <>
     174             : struct hash<StateOneOld> {
     175      102074 :     size_t operator()(const StateOneOld &s) const {
     176      102074 :         std::size_t seed = 0;
     177      102074 :         utils::hash_combine(seed, s.n);
     178      102074 :         utils::hash_combine(seed, s.l);
     179      102074 :         utils::hash_combine(seed, s.j);
     180      102074 :         utils::hash_combine(seed, s.m);
     181      102074 :         return seed;
     182             :     }
     183             : };
     184             : 
     185             : template <>
     186             : struct hash<StateTwoOld> {
     187      118316 :     size_t operator()(const StateTwoOld &s) const {
     188      118316 :         std::size_t seed = 0;
     189      118316 :         utils::hash_combine(seed, s.n);
     190      118316 :         utils::hash_combine(seed, s.l);
     191      118316 :         utils::hash_combine(seed, s.j);
     192      118316 :         utils::hash_combine(seed, s.m);
     193      118316 :         return seed;
     194             :     }
     195             : };
     196             : 
     197             : } // namespace std
     198             : #endif
     199             : 
     200             : #endif

Generated by: LCOV version 1.14