LCOV - code coverage report
Current view: top level - pairinteraction - State.hpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 10 10 100.0 %
Date: 2024-04-29 00:41:50 Functions: 6 12 50.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 STATE_H
      21             : #define STATE_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             : class MatrixElementCache;
      34             : 
      35             : ////////////////////////////////////////////////////////////////////
      36             : /// \brief One-atom state
      37             : /// This class implements a one-atom state. It can either be a
      38             : /// Rydberg state in the fine structure basis or an artificial state
      39             : /// specified by a label.
      40             : ////////////////////////////////////////////////////////////////////
      41             : 
      42             : class StateOne {
      43             : public:
      44        1409 :     StateOne() = default;
      45             :     explicit StateOne(std::string species, int n, int l, float j, float m);
      46             :     explicit StateOne(std::string label);
      47             : 
      48             :     // Methods for printing the state
      49             :     friend std::ostream &operator<<(std::ostream &out, const StateOne &state);
      50             :     std::string str() const;
      51             : 
      52             :     // Getters
      53             :     const int &getN() const;
      54             :     const int &getL() const;
      55             :     const float &getJ() const;
      56             :     const float &getM() const;
      57             :     const float &getS() const;
      58             :     const std::string &getSpecies() const;
      59             :     const std::string &getElement() const;
      60             :     double getEnergy() const;
      61             :     double getEnergy(MatrixElementCache &cache) const;
      62             :     double getNStar() const;
      63             :     double getNStar(MatrixElementCache &cache) const;
      64             :     const std::string &getLabel() const;
      65             :     bool isArtificial() const;
      66             :     bool isGeneralized() const;
      67             : 
      68             :     const size_t &getHash() const;
      69             : 
      70             :     StateOne getReflected() const;
      71             : 
      72             :     // Comparators
      73             :     bool operator==(StateOne const &rhs) const;
      74             :     bool operator^(StateOne const &rhs) const; // subset
      75             :     bool operator!=(StateOne const &rhs) const;
      76             :     bool operator<(StateOne const &rhs) const;
      77             :     bool operator<=(StateOne const &rhs) const;
      78             : 
      79             : private:
      80             :     // TODO make the variables constant (requires load_construct_data, see
      81             :     // https://stackoverflow.com/questions/50603180/serialization-of-class-with-const-members-using-boost)
      82             :     std::string species, element;
      83             :     int n, l;
      84             :     float j, m, s;
      85             :     size_t hashvalue;
      86             : 
      87             :     // Method for serialization
      88             :     friend class cereal::access;
      89             :     template <class Archive>
      90        1364 :     void serialize(Archive &ar, unsigned int /* version */) {
      91        1364 :         ar &species &element &n &l &j &m &s &hashvalue;
      92        1364 :     }
      93             : 
      94             :     // Utility methods
      95             :     void analyzeSpecies();
      96             :     void shouldBeArtificial(bool opinion) const;
      97             : };
      98             : 
      99             : ////////////////////////////////////////////////////////////////////
     100             : /// \brief Two-atom state
     101             : /// This class implements a two-atom state. It can either be a
     102             : /// Rydberg state in the fine structure basis or an artificial state
     103             : /// specified by a label.
     104             : ////////////////////////////////////////////////////////////////////
     105             : 
     106             : class StateTwo {
     107             : public:
     108         263 :     StateTwo() = default;
     109             :     explicit StateTwo(std::array<std::string, 2> species, std::array<int, 2> n,
     110             :                       std::array<int, 2> l, std::array<float, 2> j, std::array<float, 2> m);
     111             :     explicit StateTwo(std::array<std::string, 2> label); // TODO use &&label?
     112             :     explicit StateTwo(StateOne first_state, StateOne second_state);
     113             : 
     114             :     // Methods for printing the state
     115             :     friend std::ostream &operator<<(std::ostream &out, const StateTwo &state);
     116             :     std::string str() const;
     117             : 
     118             :     // Getters
     119             :     std::array<int, 2> getN() const;
     120             :     std::array<int, 2> getL() const;
     121             :     std::array<float, 2> getJ() const;
     122             :     std::array<float, 2> getM() const;
     123             :     std::array<float, 2> getS() const;
     124             :     std::array<std::string, 2> getSpecies() const;
     125             :     std::array<std::string, 2> getElement() const;
     126             :     double getEnergy() const;
     127             :     double getEnergy(MatrixElementCache &cache) const;
     128             :     std::array<double, 2> getNStar() const;
     129             :     std::array<double, 2> getNStar(MatrixElementCache &cache) const;
     130             :     double getLeRoyRadius(MatrixElementCache &cache) const;
     131             :     std::array<std::string, 2> getLabel() const;
     132             :     std::array<bool, 2> isArtificial() const;
     133             :     std::array<bool, 2> isGeneralized() const;
     134             : 
     135             :     const int &getN(int idx) const;
     136             :     const int &getL(int idx) const;
     137             :     const float &getJ(int idx) const;
     138             :     const float &getM(int idx) const;
     139             :     const float &getS(int idx) const;
     140             :     const std::string &getSpecies(int idx) const;
     141             :     const std::string &getElement(int idx) const;
     142             :     double getEnergy(int idx) const;
     143             :     double getEnergy(int idx, MatrixElementCache &cache) const;
     144             :     double getNStar(int idx) const;
     145             :     double getNStar(int idx, MatrixElementCache &cache) const;
     146             :     const std::string &getLabel(int idx) const;
     147             :     bool isArtificial(int idx) const;
     148             :     bool isGeneralized(int idx) const;
     149             : 
     150             :     const StateOne &getFirstState() const;
     151             :     const StateOne &getSecondState() const;
     152             : 
     153             :     const size_t &getHash() const;
     154             : 
     155             :     StateTwo getReflected() const;
     156             : 
     157             :     // Comparators
     158             :     bool operator==(StateTwo const &rhs) const;
     159             :     bool operator^(StateTwo const &rhs) const; // subset
     160             :     bool operator!=(StateTwo const &rhs) const;
     161             :     bool operator<(StateTwo const &rhs) const;
     162             :     bool operator<=(StateTwo const &rhs) const;
     163             : 
     164             : private:
     165             :     // TODO make the variables constant (requires load_construct_data, see
     166             :     // https://stackoverflow.com/questions/50603180/serialization-of-class-with-const-members-using-boost)
     167             :     std::array<StateOne, 2> state_array;
     168             :     size_t hashvalue;
     169             : 
     170             :     // Method for serialization
     171             :     friend class cereal::access;
     172             :     template <class Archive>
     173         262 :     void serialize(Archive &ar, unsigned int /* version */) {
     174         262 :         ar &state_array &hashvalue;
     175         262 :     }
     176             : };
     177             : 
     178             : ////////////////////////////////////////////////////////////////////
     179             : /// Hashers ////////////////////////////////////////////////////////
     180             : ////////////////////////////////////////////////////////////////////
     181             : 
     182             : #ifndef SWIG
     183             : 
     184             : namespace std {
     185             : 
     186             : template <>
     187             : struct hash<StateOne> {
     188       42844 :     size_t operator()(const StateOne &s) const { return s.getHash(); }
     189             : };
     190             : 
     191             : template <>
     192             : struct hash<StateTwo> {
     193     2231762 :     size_t operator()(const StateTwo &s) const { return s.getHash(); }
     194             : };
     195             : 
     196             : } // namespace std
     197             : #endif
     198             : 
     199             : #endif

Generated by: LCOV version 1.14