Majoranapp
A C++ library for studying MZM in non-interacting systems
ModelSelector.hpp
Go to the documentation of this file.
1 #ifndef PARSERS_MODELSELECTOR_HPP
2 #define PARSERS_MODELSELECTOR_HPP
3 
4 #include <string>
5 #include <vector>
6 
7 #include "../Factory.hpp"
8 #include "../Misc.hpp"
9 #include "../QuantumSystem.hpp"
10 #include "../QuantumSystem/Parameters.hpp"
11 #include "../QuantumSystem/Dimensions.hpp"
12 #include "../VectorViewer.hpp"
13 
18 {
19  friend class InputScriptParser;
20 
21 private:
22  static std::string selectedModel;
23  static std::string selectedMatrixType;
24  static std::vector<std::string> supportedModels;
25 
26  template<class T1, class T2>
27  static auto GetHamiltonian(QuantumSystem &quantumSystem)
28  {
29  VectorViewer::View = &T1::View;
30  return Factory<T1>::template Generate<T2>(quantumSystem);
31  }
32 
33 public:
34  template <class T>
35  static auto SelectModel(QuantumSystem &quantumSystem)
36  {
37  // TODO:
38  // - add ::name to models,
39  // - automate te viewer selector -> templetize the switch
40  switch (str2int(selectedModel.c_str()))
41  {
42  // Spinfull cases
44  return GetHamiltonian<SpinfullUniform3D,T>(quantumSystem);
46  return GetHamiltonian<SpinfullUniform2D,T>(quantumSystem);
48  return GetHamiltonian<SpinfullUniformChain,T>(quantumSystem);
50  return GetHamiltonian<SpinfullUserDefined,T>(quantumSystem);
51 
52  // Spinless cases
54  return GetHamiltonian<SpinlessUniform2D,T>(quantumSystem);
56  return GetHamiltonian<SpinlessUniformChain,T>(quantumSystem);
58  return GetHamiltonian<SpinlessUserDefined,T>(quantumSystem);
59 
60  default:
61  Info::Warning("Warning, unrecognized model and/or matrix type: ", ModelSelector::GetSelected());
62  Info::Warning("Running with default: ", "SpinfullUniformChain @ " + selectedMatrixType);
63  return GetHamiltonian<SpinfullUniformChain,T>(quantumSystem);
64  }
65  }
66 
67  static bool SparseSelected()
68  {
69  return selectedMatrixType == "sparse";
70  }
71 
72  static bool DenseSelected()
73  {
74  return selectedMatrixType == "dense";
75  }
76 
83  static auto SelectSparse(QuantumSystem &quantumSystem)
84  {
85  return SelectModel<arma::sp_mat>(quantumSystem);
86  }
87 
94  static auto SelectDense(QuantumSystem &quantumSystem)
95  {
96  return SelectModel<arma::mat>(quantumSystem);
97  }
98 
104  static std::string GetSelected()
105  {
106  return selectedModel + " @ " + selectedMatrixType;
107  }
108 };
109 
110 std::string ModelSelector::selectedModel{""};
111 std::string ModelSelector::selectedMatrixType{""};
112 
113 #endif
static bool SparseSelected()
Definition: ModelSelector.hpp:67
selecting model through name
Definition: ModelSelector.hpp:17
class which produces stuff
Definition: Factory.hpp:27
static constexpr char name[]
Definition: SpinfullUniform2D.hpp:94
constexpr unsigned int str2int(const char *str, int h=0)
converting c_str() into constexpr int, which can be used in switch statement
Definition: Misc.hpp:19
static auto SelectDense(QuantumSystem &quantumSystem)
arma::mat template specialization
Definition: ModelSelector.hpp:94
static constexpr char name[]
Definition: SpinfullUniform3D.hpp:116
static std::string selectedMatrixType
Definition: ModelSelector.hpp:23
static std::string GetSelected()
Get the Selected object.
Definition: ModelSelector.hpp:104
static constexpr char name[]
Definition: SpinlessUniformChain.hpp:56
static auto SelectModel(QuantumSystem &quantumSystem)
Definition: ModelSelector.hpp:35
Parsing JSON input script.
Definition: InputScriptParser.hpp:24
static auto SelectSparse(QuantumSystem &quantumSystem)
arma::sp_mat template specialization
Definition: ModelSelector.hpp:83
static bool DenseSelected()
Definition: ModelSelector.hpp:72
static constexpr char name[]
Definition: SpinfullUniformChain.hpp:61
static auto GetHamiltonian(QuantumSystem &quantumSystem)
Definition: ModelSelector.hpp:27
static std::string selectedModel
Definition: ModelSelector.hpp:22
class containing all information about quantum system, which is needed for hamiltonian construction ...
Definition: QuantumSystem.hpp:12
static constexpr char name[]
Definition: SpinlessUniform2D.hpp:78
static ViewerFunction View
Definition: VectorViewer.hpp:22
static constexpr char name[]
Definition: SpinlessUserDefined.hpp:41
static std::vector< std::string > supportedModels
Definition: ModelSelector.hpp:24
static constexpr char name[]
Definition: SpinfullUserDefined.hpp:41
static void Warning(std::string text, std::string note="")
Warning sent to std::cout.
Definition: Basics.hpp:102