MPS-Basic
Loading...
Searching...
No Matches
csv.cpp
Go to the documentation of this file.
1#include "csv.hpp"
2
3#include "../particles.hpp"
4
5#include <Eigen/Dense>
6#include <csv.h>
7#include <fstream>
8#include <iostream>
9#include <string>
10
12using std::cerr;
13using std::endl;
14
16}
17
18std::pair<double, Particles> Csv::load(const fs::path& path, double defaultDensity) {
19 io::CSVReader<9> in(path.string());
20 double startTime = std::stod(in.next_line());
21 double numParticles = std::stod(in.next_line());
22
23 in.read_header(io::ignore_missing_column, "type", "fluidType", "x", "y", "z", "vx", "vy", "vz", "density");
24 int type;
25 int fluidType = 0;
26 double x, y, z, vx, vy, vz;
27 double density = -1.0;
28 Particles particles;
29 while (in.read_row(type, fluidType, x, y, z, vx, vy, vz, density)) {
30 Eigen::Vector3d pos(x, y, z);
31 Eigen::Vector3d vel(vx, vy, vz);
32 if (density < 0) {
33 density = defaultDensity;
34 }
35 particles.add(Particle(particles.size(), static_cast<ParticleType>(type), pos, vel, density, fluidType));
36 }
37
38 return std::make_pair(startTime, particles);
39}
40
42}
Class for particle in MPS method.
Definition particle.hpp:47
Class for loading particles from a prof file.
Definition csv.hpp:11
~Csv() override
Definition csv.cpp:41
std::pair< double, Particles > load(const fs::path &path, double defaultDensity) override
Load particles.
Definition csv.cpp:18
A collection of particles.
Definition particles.hpp:10
int size() const
Get the number of particles.
Definition particles.cpp:21
void add(const Particle &particle)
Add a particle to the collection.
Definition particles.cpp:25
ParticleType
Enum class for particle type.
Definition particle.hpp:11