Ejemplo n.º 1
0
void LoadSpMatrix(const char* filename, SpMatrix& m){
	
	int NbRow, NbCol;
	string      line;
	int        j0,k0;
	Cplx         val;
	
	// Ouverture fichier
	ifstream file; file.open(filename);
	if(!file.good()){
		cout << "LoadSpMatrix in loading.hpp: error opening the matrix file" << endl;
        cout << filename << endl;
		abort();}
	
	// Lecture nombre de lignes et de colonnes
	file >> NbRow; file >> NbCol;
	m.resize(NbRow,NbCol,NbRow*max(NbCol/10,10));

	// Lecture parametres
	int ndofperelt=GetNdofPerElt();
	
	int NbCoef=0;
	
	getline(file,line);
	getline(file,line);
	while(!file.eof()){
		
		// Lecture de la ligne
		istringstream iss(line);
		
		// Pour chaque ligne, stockage
		// du bloc d'interaction
		iss >> j0; j0 = ndofperelt*(j0-1);
		iss >> k0; k0 = ndofperelt*(k0-1);
		
		for(int j=0; j<ndofperelt; j++){
			for(int k=0; k<ndofperelt; k++){
				iss >> val;
				m.I_(NbCoef) = j0+j;
				m.J_(NbCoef) = k0+k;
				m.K_(NbCoef) = val;
				//m(j0+j,k0+k) = val;
				NbCoef++;
			}
		}
		getline(file,line);
	}
	
	file.close();
	
	m.resize(NbRow,NbCol,NbCoef);
}