TBTK
Need a break? Support the development by playing Polarity Puzzles
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  const std::vector<double> &coordinates/*,
94  int numCoordinates*/
95  );
96 
98 // static void writeSpecifiers(const int *specifiers, int numSpecifiers);
99  static void writeSpecifiers(const std::vector<int> &specifiers);
100 
102  static void writeDescription(std::string description);
103 
105  static void writeAmplitudes(Model *model, AmplitudeMode amplitudeMode);
106 
108  static void writeGeometry(Model *model);
109 
111  static void removeComments();
112 
114  static void removeInitialWhiteSpaces();
115 
117  static int readParameter(
118  std::string parameterName,
119  std::string parentStructure
120  );
121 
123  static void readAmplitudes(Model *model);
124 
126  static void readGeometry(Model *model);
127 
129  static HoppingAmplitude* readHoppingAmplitude();
130 
132  static Index* readIndex();
133 
135  static void readCoordinates(
136  std::vector<double> *coordinates,
137  int dimensions
138  );
139 
141  static void readSpecifiers(
142  std::vector<int> *specifiers,
143  int numSpecifiers
144  );
145 
147  static bool readComplex(std::complex<double> *c);
148 
150  static bool readDouble(double *d, char endChar = ' ');
151 
153  static bool readInt(int *i, char endChar = ' ');
154 
156  static std::ofstream fout;
157 
159  static std::stringstream ssin;
160 };
161 
162 }; //End of namespace TBTK
163 
164 #endif
TBTK::Model
Container of Model related information.
Definition: Model.h:57
Model.h
Container of Model related information.
TBTK::ParameterSet
Definition: ParameterSet.h:34
TBTK::FileParser
Definition: FileParser.h:39
TBTK::FileParser::readParameterSet
static ParameterSet readParameterSet(std::string fileName)
TBTK::FileParser::writeParameterSet
static void writeParameterSet(const ParameterSet &parameterSet, std::string fileName)
TBTK::FileParser::readModel
static Model * readModel(std::string fileName)
TBTK::HoppingAmplitude
Hopping amplitude from state 'from' to state 'to'.
Definition: HoppingAmplitude.h:53
TBTK::FileParser::AmplitudeMode
AmplitudeMode
Definition: FileParser.h:42
ParameterSet.h
Set of parameters.
TBTK::FileParser::writeModel
static void writeModel(Model *model, std::string fileName, AmplitudeMode amplitudeMode, std::string description)
TBTK::Index
Physical index.
Definition: Index.h:44