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

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

#include <prof.hpp>

Inheritance diagram for ParticlesLoader::Prof:
Collaboration diagram for ParticlesLoader::Prof:

Public Member Functions

std::pair< double, Particlesload (const fs::path &path, double defaultDensity) override
 Load particles.
 
 ~Prof () override
 
 Prof ()
 
- 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 prof file format, please refer to the Profile.

Definition at line 11 of file prof.hpp.

Constructor & Destructor Documentation

◆ ~Prof()

Prof::~Prof ( )
override

Definition at line 42 of file prof.cpp.

42 {
43}

◆ Prof()

Prof::Prof ( )

Definition at line 10 of file prof.cpp.

10 {
11}

Member Function Documentation

◆ load()

std::pair< double, Particles > Prof::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 13 of file prof.cpp.

13 {
14 std::ifstream ifs;
15 ifs.open(path);
16 if (ifs.fail()) {
17 cerr << "cannot read prof file: " << fs::absolute(path) << endl;
18 std::exit(-1);
19 }
20
21 Particles particles;
22 double startTime = NAN;
23 int particleSize = 0;
24 ifs >> startTime;
25 ifs >> particleSize;
26 for (int i = 0; i < particleSize; i++) {
27 int type_int = 0;
28 ParticleType type;
29 Eigen::Vector3d pos, vel;
30
31 ifs >> type_int;
32 ifs >> pos.x() >> pos.y() >> pos.z();
33 ifs >> vel.x() >> vel.y() >> vel.z();
34
35 type = static_cast<ParticleType>(type_int);
36 particles.add(Particle(particles.size(), type, pos, vel, defaultDensity));
37 }
38
39 return {startTime, particles};
40}
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: