22// it under the terms of the GNU General Public License as published by
33// the Free Software Foundation, either version 3 of the License, or
44// (at your option) any later version.
5-
65// This program is distributed in the hope that it will be useful,
76// but WITHOUT ANY WARRANTY; without even the implied warranty of
87// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
98// GNU General Public License for more details.
109
11- // You should have received a copy of the GNU General Public License
12- // along with this program. If not, see <http://www.gnu.org/licenses/>.
13-
1410#pragma once
1511#include < vector>
1612#include < string>
1713#include < fstream>
18- #include " ../ struct/particle.h"
14+ #include " struct/particle.h"
1915
20- inline void SaveVTU (const std::vector<Particle>& p, const std::string& filename)
16+ /* *
17+ * @brief Saves the SoA Particle database to a VTU (XML) file.
18+ * This is the modern VTK format preferred by newer versions of ParaView.
19+ */
20+ inline void SaveVTU (const Particle& p, const std::string& filename)
2121{
2222 std::ofstream out (filename);
2323 if (!out) return ;
2424
25- const size_t N = p.size ();
25+ const size_t N = p.size (); // Total particles in the database
2626
2727 out << " <?xml version=\" 1.0\" ?>\n " ;
2828 out << " <VTKFile type=\" UnstructuredGrid\" version=\" 0.1\" byte_order=\" LittleEndian\" >\n " ;
2929 out << " <UnstructuredGrid>\n " ;
3030 out << " <Piece NumberOfPoints=\" " << N
3131 << " \" NumberOfCells=\" " << N << " \" >\n " ;
3232
33- // --- POINTS ---
33+ // --- POINTS (Coordinates) ---
3434 out << " <Points>\n " ;
3535 out << " <DataArray type=\" Float32\" NumberOfComponents=\" 3\" format=\" ascii\" >\n " ;
36- for (const auto & a : p )
37- out << a. x << " " << a. y << " " << a. z << " " ;
36+ for (size_t i = 0 ; i < N; i++ )
37+ out << p. x [i] << " " << p. y [i] << " " << p. z [i] << " " ;
3838 out << " \n </DataArray>\n </Points>\n " ;
3939
40- // --- CELLS ---
40+ // --- CELLS (Topology) ---
4141 out << " <Cells>\n " ;
4242 out << " <DataArray type=\" Int32\" Name=\" connectivity\" format=\" ascii\" >\n " ;
4343 for (size_t i = 0 ; i < N; i++) out << i << " " ;
@@ -51,25 +51,25 @@ inline void SaveVTU(const std::vector<Particle>& p, const std::string& filename)
5151 for (size_t i = 0 ; i < N; i++) out << " 1 " ; // 1 = VTK_VERTEX
5252 out << " \n </DataArray>\n </Cells>\n " ;
5353
54- // --- POINT DATA ---
54+ // --- POINT DATA (Attributes) ---
5555 out << " <PointData>\n " ;
5656
57- // Dark Matter Type (0 = Star, 1 = DM)
57+ // Particle Type (0 = Star, 1 = DM)
5858 out << " <DataArray type=\" Int32\" Name=\" type\" format=\" ascii\" >\n " ;
59- for (const auto & a : p )
60- out << a .type << " " ;
59+ for (size_t i = 0 ; i < N; i++ )
60+ out << p .type [i] << " " ;
6161 out << " \n </DataArray>\n " ;
6262
6363 // Velocity
6464 out << " <DataArray type=\" Float32\" Name=\" velocity\" NumberOfComponents=\" 3\" format=\" ascii\" >\n " ;
65- for (const auto & a : p )
66- out << a .vx << " " << a .vy << " " << a .vz << " " ;
65+ for (size_t i = 0 ; i < N; i++ )
66+ out << p .vx [i] << " " << p .vy [i] << " " << p .vz [i] << " " ;
6767 out << " \n </DataArray>\n " ;
6868
6969 // Mass
7070 out << " <DataArray type=\" Float32\" Name=\" mass\" format=\" ascii\" >\n " ;
71- for (const auto & a : p )
72- out << a. m << " " ;
71+ for (size_t i = 0 ; i < N; i++ )
72+ out << p. m [i] << " " ;
7373 out << " \n </DataArray>\n " ;
7474
7575 out << " </PointData>\n </Piece>\n </UnstructuredGrid>\n </VTKFile>\n " ;
0 commit comments