-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathvtk.cpp
121 lines (99 loc) · 4.36 KB
/
vtk.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//------------------------------------------------------------------------------
//
// This file is part of the VAMPIRE open source package under the
// Free BSD licence (see licence file for details).
//
// (c) Richard F L Evans 2019. All rights reserved.
//
// Email: [email protected]
//
//------------------------------------------------------------------------------
//
// C++ standard library headers
#include <cmath>
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
// program header
#include "vdc.hpp"
namespace vdc{
//------------------------------------------------------------------------------
// Function to output spins-XXXX.vtu files compatible with paraview
//------------------------------------------------------------------------------
void output_vtk_file(unsigned int spin_file_id){
// Set VTK file name
std::stringstream vtk_file_sstr;
vtk_file_sstr << "spins-";
vtk_file_sstr << std::setfill('0') << std::setw(8) << spin_file_id;
vtk_file_sstr << ".vtu";
std::string vtk_file = vtk_file_sstr.str();
// open vtk file
std::ofstream vtkfile;
vtkfile.open(vtk_file.c_str());
// output informative message to user
if(vdc::verbose) std::cout << " Writing VTK file " << vtk_file << "..." << std::flush;
const double scx = vdc::system_centre[0];
const double scy = vdc::system_centre[1];
const double scz = vdc::system_centre[2];
vtkfile << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" << std::endl;
vtkfile << "<UnstructuredGrid>" << std::endl;
vtkfile << " <Piece NumberOfPoints=\"" << vdc::sliced_atoms_list.size() << "\" NumberOfCells=\"0\">" << std::endl;
vtkfile << " <Points>" << std::endl;
vtkfile << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl;
for(int i=0; i < vdc::sliced_atoms_list.size(); i++){
// get atom ID
unsigned int atom = vdc::sliced_atoms_list[i];
vtkfile << " " << coordinates[3*atom+0]-scx << " " << coordinates[3*atom+1]-scy << " " << coordinates[3*atom+2]-scz << std::endl;
}
vtkfile << " </DataArray>" << std::endl;
vtkfile << " </Points>" << std::endl;
vtkfile << " <PointData Vectors=\"vector\">" << std::endl;
vtkfile << " <DataArray type=\"Float32\" Name=\"spin\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl;
for(int i=0; i < vdc::atoms_list.size(); i++){
// get atom ID
unsigned int atom = vdc::atoms_list[i];
vtkfile << spins[3*atom+0] << " " << spins[3*atom+1] << " " << spins[3*atom+2] << " ";
}
vtkfile << std::endl;
vtkfile << " </DataArray>" << std::endl;
vtkfile << " <DataArray type=\"Float32\" Name=\"moment\" format=\"ascii\">" << std::endl;
for(int i=0; i < vdc::sliced_atoms_list.size(); i++){
// get atom ID
unsigned int atom = vdc::sliced_atoms_list[i];
// get atom type
int type_id = vdc::type[atom];
const double moment = materials[type_id].moment;
vtkfile << moment << " ";
}
vtkfile << std::endl;
vtkfile << " </DataArray>" << std::endl;
vtkfile << " <DataArray type=\"Int32\" Name=\"ID\" format=\"ascii\">" << std::endl;
for(int i=0; i < vdc::sliced_atoms_list.size(); i++){
// get atom ID
unsigned int atom = vdc::sliced_atoms_list[i];
// get atom type
int type_id = vdc::type[atom];
vtkfile << type_id << " ";
}
vtkfile << std::endl;
vtkfile << " </DataArray>" << std::endl;
vtkfile << " </PointData>" << std::endl;
vtkfile << " <Cells>" << std::endl;
vtkfile << " <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << std::endl;
vtkfile << " </DataArray>" << std::endl;
vtkfile << " <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << std::endl;
vtkfile << " </DataArray>" << std::endl;
vtkfile << " <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">" << std::endl;
vtkfile << " </DataArray>" << std::endl;
vtkfile << " </Cells>" << std::endl;
vtkfile << " </Piece>" << std::endl;
vtkfile << "</UnstructuredGrid>" << std::endl;
vtkfile << "</VTKFile>" << std::endl;
// output informative message to user
if(vdc::verbose) std::cout << "done!" << std::endl;
return;
}
} // end of namespace vdc