Class to write particle data to a .vtu file.
More...
#include <VTUWriter.h>
Class to write particle data to a .vtu file.
Definition at line 10 of file VTUWriter.h.
◆ initializeOutput()
VTKFile_t VTUWriter::initializeOutput |
( |
int |
numParticles | ) |
|
|
staticprivate |
Creates a VTKFile_t object with the given number of particles.
- Parameters
-
numParticles | Number of particles to be plotted |
- Returns
- VTUFile_t object with the given number of particles
Definition at line 7 of file VTUWriter.cpp.
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);
◆ plotParticle()
void VTUWriter::plotParticle |
( |
VTKFile_t & |
file, |
|
|
const Particle & |
p |
|
) |
| |
|
staticprivate |
Writes a given particle to the given VTKFile_t object.
- Parameters
-
file | VTUFile_t object to write to |
p | Particle to be written |
Definition at line 41 of file VTUWriter.cpp.
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]);
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.
◆ writeFile()
const std::filesystem::path VTUWriter::writeFile |
( |
const SimulationParams & |
params, |
|
|
size_t |
iteration, |
|
|
const std::vector< Particle > & |
particles |
|
) |
| const |
|
overridevirtual |
Writes the data of the given ParticleContainer to a .vtu file.
- Parameters
-
params | SimulationParams object which provides the output directory path |
iteration | The current iteration number |
particles | A vector of particles to write to the file |
- Returns
- The path to the written file
Implements FileWriter.
Definition at line 67 of file VTUWriter.cpp.
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.
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.
The documentation for this class was generated from the following files: