3 #include <spdlog/fmt/bundled/core.h>
8 VTKFile_t vtu_file(
"UnstructuredGrid");
12 DataArray_t mass(type::Float32,
"mass", 1);
13 DataArray_t velocity(type::Float32,
"velocity", 3);
14 DataArray_t forces(type::Float32,
"force", 3);
15 DataArray_t type(type::Int32,
"type", 1);
17 point_data.DataArray().push_back(mass);
18 point_data.DataArray().push_back(velocity);
19 point_data.DataArray().push_back(forces);
20 point_data.DataArray().push_back(type);
26 DataArray_t point_coordinates(type::Float32,
"points", 3);
27 points.DataArray().push_back(point_coordinates);
31 DataArray_t cells_data(type::Float32,
"types", 0);
32 cells.DataArray().push_back(cells_data);
34 PieceUnstructuredGrid_t piece(point_data, cell_data, points, cells, numParticles, 0);
35 UnstructuredGrid_t unstructured_grid(piece);
36 vtu_file.UnstructuredGrid(unstructured_grid);
42 PointData::DataArray_sequence& point_data_sequence = vtuFile.UnstructuredGrid()->Piece().PointData().DataArray();
43 PointData::DataArray_iterator data_iterator = point_data_sequence.begin();
45 data_iterator->push_back(p.
getM());
48 data_iterator->push_back(p.
getV()[0]);
49 data_iterator->push_back(p.
getV()[1]);
50 data_iterator->push_back(p.
getV()[2]);
53 data_iterator->push_back(p.
getF()[0]);
54 data_iterator->push_back(p.
getF()[1]);
55 data_iterator->push_back(p.
getF()[2]);
58 data_iterator->push_back(p.
getType());
60 Points::DataArray_sequence& points_sequence = vtuFile.UnstructuredGrid()->Piece().Points().DataArray();
61 Points::DataArray_iterator points_iterator = points_sequence.begin();
62 points_iterator->push_back(p.
getX()[0]);
63 points_iterator->push_back(p.
getX()[1]);
64 points_iterator->push_back(p.
getX()[2]);
68 const std::vector<Particle>& particles)
const {
69 auto file_name = params.
output_dir_path / fmt::format(
"MD_VTU_{:08d}.vtu", iteration);
73 for (
const Particle& particle : particles) {
77 std::ofstream file(file_name);
78 VTKFile(file, vtu_file);
Class to represent a particle.
const std::array< double, 3 > & getV() const
Gets the velocity of the particle.
int getType() const
Gets the type of the particle.
const std::array< double, 3 > & getX() const
Gets the position of the particle.
double getM() const
Gets the mass of the particle.
const std::array< double, 3 > & getF() const
Gets the total force of the particle.
Contains all parameters needed to run a simulation.
std::filesystem::path output_dir_path
Path to the directory in which to save the simulation output.
static void plotParticle(VTKFile_t &file, const Particle &p)
Writes a given particle to the given VTKFile_t object.
static VTKFile_t initializeOutput(int numParticles)
Creates a VTKFile_t object with the given number of particles.
const std::filesystem::path writeFile(const SimulationParams ¶ms, size_t iteration, const std::vector< Particle > &particles) const override
Writes the data of the given ParticleContainer to a .vtu file.