blob: 9291fdd09240508b1f0be847ecf97601077a10b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include "fluid_buffer.h"
#include <fstream>
FluidBuffer::FluidBuffer(std::size_t dimX, std::size_t dimY):
dim_x_(dimX),
dim_y_(dimY),
density_(new Density[dimX*dimY]),
velocity_(new Velocity[dimX*dimY]) { }
std::size_t FluidBuffer::dimX() const {
return dim_x_;
}
std::size_t FluidBuffer::dimY() const {
return dim_y_;
}
Density& FluidBuffer::density(std::size_t x, std::size_t y) {
return density_[y*dim_x_ + x];
}
Density& FluidBuffer::density(Vector<std::size_t> pos) {
return density(pos[0], pos[1]);
}
Velocity& FluidBuffer::velocity(std::size_t x, std::size_t y) {
return velocity_[y*dim_x_ + x];
}
Velocity& FluidBuffer::velocity(Vector<std::size_t> pos) {
return velocity(pos[0], pos[1]);
}
void FluidBuffer::writeAsVTK(const std::filesystem::path& path) {
std::filesystem::create_directories(path.parent_path());
std::ofstream fout;
fout.open(path.c_str());
fout << "# vtk DataFile Version 3.0\n";
fout << "lbm_output\n";
fout << "ASCII\n";
fout << "DATASET RECTILINEAR_GRID\n";
fout << "DIMENSIONS " << dimX() << " " << dimY() << " 1" << "\n";
fout << "X_COORDINATES " << dimX() << " float\n";
for( std::size_t x = 0; x < dimX(); ++x ) {
fout << x << " ";
}
fout << "\nY_COORDINATES " << dimY() << " float\n";
for( std::size_t y = 0; y < dimY(); ++y ) {
fout << y << " ";
}
fout << "\nZ_COORDINATES " << 1 << " float\n";
fout << 0 << "\n";
fout << "POINT_DATA " << dimX() * dimY() << "\n";
fout << "VECTORS velocity float\n";
for ( std::size_t y = 0; y < dimY(); ++y ) {
for ( std::size_t x = 0; x < dimX(); ++x ) {
fout << velocity(x,y)[0] << " " << velocity(x,y)[1] << " 0\n";
}
}
fout << "SCALARS density float 1\n";
fout << "LOOKUP_TABLE default\n";
for ( std::size_t y = 0; y < dimY(); ++y ) {
for ( std::size_t x = 0; x < dimX(); ++x ) {
fout << density(x,y) << "\n";
}
}
fout.close();
}
|