00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "QCTools.hpp"
00021
00022 void readGlobalDensityFromAsciiFile(const std::string &fileName, QCSymMatrix &D ){
00023 QC_TRACE_INIT("BEGIN QCTools readGlobalDensityFromAsciiFile ") ;
00024
00025 std::ifstream data ;
00026 std::string type;
00027
00028 data.open(fileName.c_str());
00029 if (!data){
00030 std::cerr << "Error to open density Matrix in File " << fileName <<std::endl;
00031 exit(EXIT_FAILURE) ;
00032 }
00033
00034 data >> type ;
00035 if (type == "SEQ"){
00036 readGlobalDensityFromAsciiFileSEQ(data, D);
00037 }
00038 else if (type == "BASIC-SHARED"){
00039 readGlobalDensityFromAsciiFileSHARED(data, D);
00040 }
00041 else if (type == "BASIC-PARA"){
00042 readGlobalDensityFromAsciiFilePARA(data, D);
00043 }
00044 else {
00045 std::cerr << "Bad type of file (" << type << ") must be SEQ, BASIC-SHARED BASIC-PARA for ascii files."<<std::endl;
00046 exit (EXIT_FAILURE) ;
00047 }
00048 data.close();
00049 QC_TRACE_INIT("END QCTools readGlobalDensityFromAsciiFile") ;
00050
00051 }
00052 void readGlobalDensityFromAsciiFileSEQ(std::ifstream &data , QCSymMatrix &D ){
00053
00054 QC_TRACE_INIT("BEGIN QCTools readGlobalDensityFromAsciiFileSEQ ") ;
00055 int dim = 0, nbelement = 0;
00056 data >> dim >> nbelement;
00057 if ( dim != D.getDim() ){
00058 std::cerr << "Bad dimension of the density Matrix in File " << std::endl
00059 << " Dimension in File : " << dim <<" Dimension given by the model" << D.getDim() <<std::endl ;
00060 exit (EXIT_FAILURE) ;
00061 }
00062 int i, j ;
00063 QCFloat val ;
00064 for (int k = 0; k < nbelement ; ++k) {
00065 data >> i >> j >>val ;
00066 if (i < j ){
00067 std::cerr <<" Error we must read a Symetric Matrix " <<std::endl ;
00068 exit(EXIT_FAILURE) ;
00069 }
00070 D[i][j] = val ;
00071 }
00072 QC_TRACE_INIT("END QCTools readGlobalDensityFromFileAsciiSEQ ");
00073 }
00074 void readGlobalDensityFromAsciiFileSHARED(std::ifstream &data , QCSymMatrix &D ){
00075
00076 QC_TRACE_INIT("BEGIN QCTools readGlobalDensityFromAsciiFileSHARED ") ;
00077
00078 int numberOfSD, iloc, jloc, iglob, jglob, flag, nsd, nbElements,dim, bidon;
00079 std::string type ;
00080 data >> numberOfSD ;
00081 std::cout << "numberOfSD : "<<numberOfSD<<" " << D.getDim() <<std::endl;
00082 QCFloat val;
00083
00084 for (int k = 0 ; k < numberOfSD; ++k) {
00085 data >> type >> nsd >> bidon >> dim >> nbElements ;
00086 for (int e = 0; e < nbElements ; ++e ){
00087 data >> iloc >> jloc >> iglob >> jglob >> flag >>val ;
00088 if(flag == 0){ continue; }
00089 if (iglob < jglob ){
00090 D[jglob][iglob] = val ;
00091 }
00092 else {
00093 D[iglob][jglob] = val ;
00094 }
00095 }
00096 }
00097 QC_TRACE_INIT("END QCTools readGlobalDensityFromFileAsciiSHARED")
00098 }
00099 void readGlobalDensityFromAsciiFilePARA(std::ifstream &data , QCSymMatrix &D ){
00100
00101 QC_TRACE_INIT("BEGIN QCTools readGlobalDensityFromAsciiFilePARA ") ;
00102
00103 std::string fileName("") ;
00104 std::ifstream dataD ;
00105 int numberOfProc,numberOfSD ;
00106
00107 data >> numberOfProc >> numberOfSD ;
00108 std::cout << "numberOfProc : "<<numberOfProc <<" numberOfSD : "<<numberOfSD<<std::endl;
00109 for (int p = 0 ; p < numberOfProc; ++p) {
00110 data >> fileName ;
00111 dataD.open(fileName.c_str());
00112 std::cout << "Read in File "<< fileName <<std::endl;
00113 if (!dataD){
00114 std::cerr << "Error to open density Matrix in File " << fileName <<std::endl;
00115 exit(EXIT_FAILURE) ;
00116 }
00117 std::string type ;
00118 dataD >> type ;
00119 if (type != "BASIC-SHARED"){
00120 std::cerr << "Error in density Matrix in File " << fileName <<std::endl;
00121 std::cerr << "Bad type of file (" << type
00122 << ") must be BASIC-SHARED for ascii files."<<std::endl;
00123 exit (EXIT_FAILURE) ;
00124 }
00125 readGlobalDensityFromAsciiFileSHARED(dataD,D);
00126 dataD.close() ;
00127 }
00128 QC_TRACE_INIT("END QCTools readGlobalDensityFromFileAsciiPARA")
00129 }