MPS-Basic
Loading...
Searching...
No Matches
ParticlesLoader::Csv Class Reference

Class for loading particles from a prof file. More...

#include <csv.hpp>

Inheritance diagram for ParticlesLoader::Csv:
Collaboration diagram for ParticlesLoader::Csv:

Public Member Functions

std::pair< double, Particlesload (const fs::path &path, double defaultDensity) override
 Load particles.
 
 ~Csv () override
 
 Csv ()
 
- Public Member Functions inherited from ParticlesLoader::Interface
virtual ~Interface ()=default
 

Detailed Description

Class for loading particles from a prof file.

For more details on the csv file format, please refer to the CSV.

Definition at line 11 of file csv.hpp.

Constructor & Destructor Documentation

◆ ~Csv()

Csv::~Csv ( )
override

Definition at line 41 of file csv.cpp.

41 {
42}

◆ Csv()

Csv::Csv ( )

Definition at line 15 of file csv.cpp.

15 {
16}

Member Function Documentation

◆ load()

std::pair< double, Particles > Csv::load ( const fs::path & path,
double defaultDensity )
overridevirtual

Load particles.

Parameters
pathPath to the particles file
defaultDensityDefault density of particles
Returns
Pair of simulation start time and particles

Implements ParticlesLoader::Interface.

Definition at line 18 of file csv.cpp.

18 {
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}
Class for particle in MPS method.
Definition particle.hpp:47
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
Here is the call graph for this function:

The documentation for this class was generated from the following files: