MPS-Basic
Loading...
Searching...
No Matches
prof.cpp
Go to the documentation of this file.
1#include "prof.hpp"
2
3#include <fstream>
4#include <iostream>
5
7using std::cerr;
8using std::endl;
9
11}
12
13std::pair<double, Particles> Prof::load(const fs::path& path, double defaultDensity) {
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}
41
Class for particle in MPS method.
Definition particle.hpp:47
Class for loading particles from a prof file.
Definition prof.hpp:11
std::pair< double, Particles > load(const fs::path &path, double defaultDensity) override
Load particles.
Definition prof.cpp:13
~Prof() override
Definition prof.cpp:42
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