TBTK
FileParser.h
Go to the documentation of this file.
1 /* Copyright 2016 Kristofer Bj√∂rnson and Andreas Theiler
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
24 #ifndef COM_DAFER45_TBTK_FILE_PARSER
25 #define COM_DAFER45_TBTK_FILE_PARSER
26 
27 #include "TBTK/Model.h"
28 #include "TBTK/ParameterSet.h"
29 
30 #include <string>
31 #include <fstream>
32 #include <sstream>
33 #include <iostream>
34 
35 namespace TBTK{
36 
39 class FileParser{
40 public:
42  enum class AmplitudeMode{
43  ALL,
44  ALL_EXCEPT_HC,
45  UNIT_CELL,
46  UNIT_CELL_EXCEPT_HC
47  };
48 
50  static void writeModel(
51  Model *model,
52  std::string fileName,
53  AmplitudeMode amplitudeMode,
54  std::string description
55  );
56 
58  static Model* readModel(std::string fileName);
59 
61  static void writeParameterSet(
62  const ParameterSet &parameterSet,
63  std::string fileName
64  );
65 
67  static ParameterSet readParameterSet(std::string fileName);
68 private:
70  static void openOutput(std::string fileName);
71 
73  static void closeOutput();
74 
76  static void readInput(std::string fileName);
77 
79  static void writeLineBreaks(int numLineBreaks);
80 
82  static void writeTabs(int numTabs);
83 
85  static void write(std::complex<double> value);
86 
88  static void write(const Index &index);
89 
91  static void writeCoordinates(
92  const double *coordinates,
93  int numCoordinates
94  );
95 
97  static void writeSpecifiers(const int *specifiers, int numSpecifiers);
98 
100  static void writeDescription(std::string description);
101 
103  static void writeAmplitudes(Model *model, AmplitudeMode amplitudeMode);
104 
106  static void writeGeometry(Model *model);
107 
109  static void removeComments();
110 
112  static void removeInitialWhiteSpaces();
113 
115  static int readParameter(
116  std::string parameterName,
117  std::string parentStructure
118  );
119 
121  static void readAmplitudes(Model *model);
122 
124  static void readGeometry(Model *model);
125 
127  static HoppingAmplitude* readHoppingAmplitude();
128 
130  static Index* readIndex();
131 
133  static void readCoordinates(
134  std::vector<double> *coordinates,
135  int dimensions
136  );
137 
139  static void readSpecifiers(
140  std::vector<int> *specifiers,
141  int numSpecifiers
142  );
143 
145  static bool readComplex(std::complex<double> *c);
146 
148  static bool readDouble(double *d, char endChar = ' ');
149 
151  static bool readInt(int *i, char endChar = ' ');
152 
154  static std::ofstream fout;
155 
157  static std::stringstream ssin;
158 };
159 
160 }; //End of namespace TBTK
161 
162 #endif
Definition: FileParser.h:39
Container of Model related information.
static void writeModel(Model *model, std::string fileName, AmplitudeMode amplitudeMode, std::string description)
Set of parameters.
AmplitudeMode
Definition: FileParser.h:42
static Model * readModel(std::string fileName)
Hopping amplitude from state &#39;from&#39; to state &#39;to&#39;.
Definition: HoppingAmplitude.h:49
Flexible physical index.
Definition: Index.h:70
Definition: ModelFactory.h:35
Definition: ParameterSet.h:34
static ParameterSet readParameterSet(std::string fileName)
static void writeParameterSet(const ParameterSet &parameterSet, std::string fileName)
Container of Model related information.
Definition: Model.h:52