TBTK
FileWriter.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_WRITER
25 #define COM_DAFER45_TBTK_FILE_WRITER
26 
27 #include "TBTK/Model.h"
29 #include "TBTK/Geometry.h"
30 #include "TBTK/ParameterSet.h"
32 #include "TBTK/Property/DOS.h"
33 #include "TBTK/Property/Density.h"
35 #include "TBTK/Property/LDOS.h"
36 #include "TBTK/Property/SpectralFunction.h"
39 #include <fstream>
40 #include <stdio.h>
41 
42 namespace TBTK{
43 
51 class FileWriter{
52 public:
54  static void writeModel(
55  const Model &model,
56  std::string name = "Model",
57  std::string path = "/"
58  );
59 
61  static void writeHoppingAmplitudeSet(
62  const HoppingAmplitudeSet &hoppingAmplitudeSet,
63  std::string name = "HoppingAmplitudeSet",
64  std::string path = "/"
65  );
66 
67  static void writeGeometry(
68  const Geometry &geometry,
69  std::string name = "Geometry",
70  std::string path = "/"
71  );
72 
73  static void writeIndexTree(
74  const IndexTree &indexTree,
75  std::string name = "IndexTree",
76  std::string path = "/"
77  );
78 
80  static void writeEigenValues(
81  const Property::EigenValues &ev,
82  std::string name = "EigenValues",
83  std::string path = "/"
84  );
85 
87  static void writeWaveFunctions(
88  const Property::WaveFunctions &waveFunctions,
89  std::string name = "WaveFunctions",
90  std::string path = "/"
91  );
92 
94  static void writeDOS(
95  const Property::DOS &dos,
96  std::string name = "DOS",
97  std::string path = "/"
98  );
99 
101  static void writeDensity(
102  const Property::Density &density,
103  std::string name = "Density",
104  std::string path = "/"
105  );
106 
108  static void writeMagnetization(
109  const Property::Magnetization &magnetization,
110  std::string name = "Magnetization",
111  std::string path = "/"
112  );
113 
115  static void writeLDOS(
116  const Property::LDOS &ldos,
117  std::string name = "LDOS",
118  std::string path = "/"
119  );
120 
122  static void writeSpectralFunction(
123  const Property::SpectralFunction &spectralFunction,
124  std::string name = "SpectralFunction",
125  std::string path = "/"
126  );
127 
129  static void writeSpinPolarizedLDOS(
130  const Property::SpinPolarizedLDOS &spinPolarizedLDOS,
131  std::string name = "SpinPolarizedLDOS",
132  std::string path = "/"
133  );
134 
136  static void write(
137  const int *data,
138  int rank,
139  const int *dims,
140  std::string name,
141  std::string path = "/"
142  );
143 
145  static void write(
146  const double *data,
147  int rank,
148  const int *dims,
149  std::string name,
150  std::string path = "/"
151  );
152 
155  static void write(
156  const std::complex<double> *data,
157  int rank,
158  const int *dims,
159  std::string name,
160  std::string path = "/"
161  );
162 
164  static void writeAttributes(
165  const int *attributes,
166  const std::string *attribute_names,
167  int num,
168  std::string name,
169  std::string path = "/"
170  );
171 
173  static void writeAttributes(
174  const double *attributes,
175  const std::string *attribute_names,
176  int num,
177  std::string name,
178  std::string path = "/"
179  );
180 
182  static void writeParameterSet(
183  const ParameterSet *parameterSet,
184  std::string name = "ParameterSet",
185  std::string path = "/"
186  );
187 
189  static void setFileName(std::string filename);
190 
193  static void clear();
194 
196  static bool exists();
197 private:
199  static bool isInitialized;
200 
202  static void init();
203 
205  static std::string filename;
206 };
207 
209  const Property::SpectralFunction &spectralFunction,
210  std::string name,
211  std::string path
212 ){
213  writeLDOS(spectralFunction, name, path);
214 }
215 
216 inline void FileWriter::setFileName(std::string filename){
217  FileWriter::filename = filename;
218  isInitialized = false;
219 }
220 
221 inline void FileWriter::clear(){
222  remove(filename.c_str());
223  isInitialized = false;
224 }
225 
226 }; //End of namespace TBTK
227 
228 #endif
229 
Property container for local density of states (LDOS).
Definition: LDOS.h:33
static void write(const int *data, int rank, const int *dims, std::string name, std::string path="/")
Property container for eigen values..
Definition: EigenValues.h:32
HoppingAmplitude container.
Definition: HoppingAmplitudeSet.h:49
Property container for magnetization.
Definition: Magnetization.h:35
Property container for spectral function.
Definition: SpectralFunction.h:32
Property container for eigen values.
Property container for local density of states (LDOS).
Container of Model related information.
static void writeEigenValues(const Property::EigenValues &ev, std::string name="EigenValues", std::string path="/")
static void writeSpinPolarizedLDOS(const Property::SpinPolarizedLDOS &spinPolarizedLDOS, std::string name="SpinPolarizedLDOS", std::string path="/")
static bool exists()
Set of parameters.
HoppingAmplitude container.
static void writeModel(const Model &model, std::string name="Model", std::string path="/")
static void writeMagnetization(const Property::Magnetization &magnetization, std::string name="Magnetization", std::string path="/")
Property container for spin-polarized local density of states (spin-polarized LDOS).
Property container for density.
static void writeLDOS(const Property::LDOS &ldos, std::string name="LDOS", std::string path="/")
static void setFileName(std::string filename)
Definition: FileWriter.h:216
Property container for magnetization.
Definition: FileWriter.h:51
static void writeAttributes(const int *attributes, const std::string *attribute_names, int num, std::string name, std::string path="/")
Data structure for mapping physical indices to a linear index.
Definition: IndexTree.h:34
Definition: ModelFactory.h:35
Definition: ParameterSet.h:34
Property container for wave function.
Definition: WaveFunctions.h:34
Property container for spin-polarized local density of states (spin-polarized LDOS).
Definition: SpinPolarizedLDOS.h:37
Property container for density.
Definition: Density.h:33
Property container for density of states (DOS).
static void writeSpectralFunction(const Property::SpectralFunction &spectralFunction, std::string name="SpectralFunction", std::string path="/")
Definition: FileWriter.h:208
Contains geometric information about a Model.
Definition: Geometry.h:35
static void clear()
Definition: FileWriter.h:221
static void writeDensity(const Property::Density &density, std::string name="Density", std::string path="/")
Property container for density of states (DOS).
Definition: DOS.h:32
static void writeDOS(const Property::DOS &dos, std::string name="DOS", std::string path="/")
static void writeParameterSet(const ParameterSet *parameterSet, std::string name="ParameterSet", std::string path="/")
Property container for wave functions.
Container of Model related information.
Definition: Model.h:52
Contains geometric inforamtion about a Model.
static void writeHoppingAmplitudeSet(const HoppingAmplitudeSet &hoppingAmplitudeSet, std::string name="HoppingAmplitudeSet", std::string path="/")
static void writeWaveFunctions(const Property::WaveFunctions &waveFunctions, std::string name="WaveFunctions", std::string path="/")