HPhi++  3.1.0
input.cpp
Go to the documentation of this file.
1 /* HPhi - Quantum Lattice Model Simulator */
2 /* Copyright (C) 2015 The University of Tokyo */
3 
4 /* This program is free software: you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation, either version 3 of the License, or */
7 /* (at your option) any later version. */
8 
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13 
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 #include "input.hpp"
17 #include "FileIO.hpp"
18 #include "wrapperMPI.hpp"
19 
20 int inputHam(struct BindStruct *X){
21  //Input Ham
22  long int i=0;
23  long int ham_i=0;
24  long int ham_j=0;
25  long int imax = X->Check.idim_max;
26  long int ihermite=0;
27  long int itmp;
28  double dHam_re, dHam_im;
29  char ctmp[256], ctmp2[256];
30 
31  FILE *fp;
32  char sdt[D_FileNameMax];
33 
34  sprintf(sdt,"%s_Ham.dat", X->Def.CDataFileHead);
35  if(childfopenMPI(sdt,"r",&fp)!=0){
36  return -1;
37  }
38 
39  //skip: header
40  fgetsMPI(ctmp, sizeof(ctmp) / sizeof(char), fp);
41  //skip: read imax, imax, ihermite
42  fgetsMPI(ctmp, sizeof(ctmp) / sizeof(char), fp);
43  sscanf(ctmp, "%ld %ld %ld\n", &itmp, &itmp, &ihermite);
44  if(itmp != imax){
45  fprintf(stdoutMPI, "Error: The dimension of input Hamiltonian is wrong: input=%ld, idim=%ld.\n", itmp, imax);
46  return -1;
47  }
48  for(i=1; i<= ihermite; i++){
49  fgetsMPI(ctmp2, sizeof(ctmp2) / sizeof(char), fp);
50  sscanf(ctmp2, "%ld %ld %lf %lf\n",
51  &ham_i, &ham_j, &dHam_re, &dHam_im);
52  v0[ham_i][ham_j]=dHam_re+I*dHam_im;
53  v0[ham_j][ham_i]=conj(v0[ham_i][ham_j]);
54  }
55  fclose(fp);
56  return 0;
57 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.cpp:75
std::complex< double > ** v0
Definition: global.cpp:20
std::complex< double > I(0.0, 1.0)
int inputHam(struct BindStruct *X)
Definition: input.cpp:20
Bind.
Definition: struct.hpp:394
char * fgetsMPI(char *InputString, int maxcount, FILE *fp)
MPI file I/O (get a line, fgets) wrapper. Only the root node (myrank = 0) reads and broadcast string...
Definition: wrapperMPI.cpp:122
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green&#39;s function.
Definition: struct.hpp:42
long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.hpp:305
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.cpp:27