mirror of
https://git.gfz-potsdam.de/naaice/tug.git
synced 2025-12-13 09:28:23 +01:00
add csv2matrix function
This commit is contained in:
parent
695b80beaf
commit
33fd35a65a
28
examples/csv2eigen.hpp
Normal file
28
examples/csv2eigen.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
#include <Eigen/Core>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
using namespace Eigen;
|
||||
|
||||
inline MatrixXd CSV2Eigen(string file2Convert){
|
||||
|
||||
vector<double> matrixEntries;
|
||||
|
||||
ifstream matrixDataFile(file2Convert);
|
||||
|
||||
string matrixRowString;
|
||||
string matrixEntry;
|
||||
int matrixRowNumber = 0;
|
||||
|
||||
while(getline(matrixDataFile, matrixRowString)){
|
||||
stringstream matrixRowStringStream(matrixRowString);
|
||||
while(getline(matrixRowStringStream, matrixEntry, ' ')){
|
||||
matrixEntries.push_back(stod(matrixEntry));
|
||||
}
|
||||
matrixRowNumber++;
|
||||
}
|
||||
|
||||
return Map<Matrix<double, Dynamic, Dynamic, RowMajor>>(matrixEntries.data(), matrixRowNumber, matrixEntries.size() / matrixRowNumber);
|
||||
|
||||
}
|
||||
@ -1,4 +1,6 @@
|
||||
#include <tug/Simulation.hpp>
|
||||
#include "csv2eigen.hpp"
|
||||
#include "Eigen/Core"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int row = 11;
|
||||
@ -42,8 +44,14 @@ int main(int argc, char *argv[]) {
|
||||
Simulation sim = Simulation(grid, bc, FTCS_APPROACH);
|
||||
//sim.setTimestep(0.001);
|
||||
sim.setIterations(2);
|
||||
sim.setOutputCSV(CSV_OUTPUT_VERBOSE);
|
||||
sim.setOutputCSV(CSV_OUTPUT_ON);
|
||||
|
||||
MatrixXd mymatrix = CSV2Eigen("/Users/hannessigner/Documents/tug/build/examples/FTCS_11_11_2-1.csv");
|
||||
|
||||
cout << "Matrix start:" << endl;
|
||||
cout << mymatrix << endl;
|
||||
|
||||
//bool r = grid.isApprox(mymatrix);
|
||||
|
||||
// RUN
|
||||
sim.run();
|
||||
|
||||
@ -152,7 +152,7 @@ void Simulation::run() {
|
||||
}
|
||||
if (this->csv_output > CSV_OUTPUT_OFF) {
|
||||
filename = createCSVfile();
|
||||
printConcentrationsCSV(filename);
|
||||
// printConcentrationsCSV(filename);
|
||||
}
|
||||
|
||||
if (approach == FTCS_APPROACH) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user