Skip to content

Commit c908a50

Browse files
committed
Fixed VTK output
1 parent c273fe9 commit c908a50

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

src/VTK.cpp

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,53 @@ void VTK::Write(
7979
const int precision,
8080
const int resolution)
8181
{
82+
const long int Nx = get_Nx(resolution, locSettings);
83+
const long int Ny = get_Ny(resolution, locSettings);
84+
const long int Nz = get_Nz(resolution, locSettings);
85+
86+
#ifndef MPI_PARALLEL
87+
ofstream vtk_file(Filename.c_str());
88+
VTK::WriteHeader(vtk_file, Nx, Ny, Nz);
89+
{
90+
WritePointData(vtk_file,ListOfFields,Nx,Ny,Nz,precision);
91+
}
92+
VTK::WriteEndPointData(vtk_file);
93+
VTK::WriteCoordinates(vtk_file, locSettings, resolution);
94+
VTK::CloseFile(vtk_file);
95+
#else
96+
std::stringstream buffer;
97+
std::stringstream hbuffer;
98+
std::stringstream tbuffer;
99+
100+
const long int TotalNx = get_TotalNx(resolution, locSettings);
101+
const long int TotalNy = get_TotalNy(resolution, locSettings);
102+
const long int TotalNz = get_TotalNz(resolution, locSettings);
103+
const long int OffsetX = get_OffsetX(resolution, locSettings);
104+
const long int OffsetY = get_OffsetY(resolution, locSettings);
105+
const long int OffsetZ = get_OffsetZ(resolution, locSettings);
106+
107+
buffer << "<Piece Extent=\""
108+
<< OffsetX << " " << Nx-1 + OffsetX << " "
109+
<< OffsetY << " " << Ny-1 + OffsetY << " "
110+
<< OffsetZ << " " << Nz-1 + OffsetZ << "\">\n";
111+
{
112+
WritePointData(buffer,ListOfFields,Nx,Ny,Nz,precision);
113+
}
114+
VTK::WriteEndPointData(buffer);
115+
VTK::WriteCoordinates(buffer, locSettings, resolution);
116+
buffer << "</Piece>\n";
117+
118+
hbuffer << "<?xml version= \"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
119+
hbuffer << "<VTKFile type=\"StructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
120+
hbuffer << "<StructuredGrid WholeExtent=\""
121+
<< 0 << " " << TotalNx-1 << " "
122+
<< 0 << " " << TotalNy-1 << " "
123+
<< 0 << " " << TotalNz-1 << "\"> \n";
124+
tbuffer << "</StructuredGrid> \n";
125+
tbuffer << "</VTKFile> \n";
126+
127+
op_mpi_write_vtk(Filename, buffer, hbuffer, tbuffer);
128+
#endif
82129
}
83130

84131
void VTK::WriteCompressed(
@@ -144,6 +191,53 @@ void VTK::WriteDistorted(
144191
const int precision,
145192
const int resolution)
146193
{
194+
const long int Nx = get_Nx(resolution, locSettings);
195+
const long int Ny = get_Ny(resolution, locSettings);
196+
const long int Nz = get_Nz(resolution, locSettings);
197+
198+
#ifndef MPI_PARALLEL
199+
ofstream vtk_file(Filename.c_str());
200+
VTK::WriteHeader(vtk_file, Nx, Ny, Nz);
201+
{
202+
WritePointData(vtk_file,ListOfFields,Nx,Ny,Nz,precision);
203+
}
204+
VTK::WriteEndPointData(vtk_file);
205+
VTK::WriteCoordinatesDistorted(vtk_file,EP,locSettings,resolution);
206+
VTK::CloseFile(vtk_file);
207+
#else
208+
std::stringstream buffer;
209+
std::stringstream hbuffer;
210+
std::stringstream tbuffer;
211+
212+
const long int TotalNx = get_TotalNx(resolution, locSettings);
213+
const long int TotalNy = get_TotalNy(resolution, locSettings);
214+
const long int TotalNz = get_TotalNz(resolution, locSettings);
215+
const long int OffsetX = get_OffsetX(resolution, locSettings);
216+
const long int OffsetY = get_OffsetY(resolution, locSettings);
217+
const long int OffsetZ = get_OffsetZ(resolution, locSettings);
218+
219+
buffer << "<Piece Extent=\""
220+
<< OffsetX << " " << Nx-1 + OffsetX << " "
221+
<< OffsetY << " " << Ny-1 + OffsetY << " "
222+
<< OffsetZ << " " << Nz-1 + OffsetZ << "\">\n";
223+
{
224+
WritePointData(buffer,ListOfFields,Nx,Ny,Nz,precision);
225+
}
226+
VTK::WriteEndPointData(buffer);
227+
VTK::WriteCoordinatesDistorted(buffer,EP,locSettings,resolution);
228+
buffer << "</Piece>\n";
229+
230+
hbuffer << "<?xml version= \"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
231+
hbuffer << "<VTKFile type=\"StructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
232+
hbuffer << "<StructuredGrid WholeExtent=\""
233+
<< 0 << " " << TotalNx-1 << " "
234+
<< 0 << " " << TotalNy-1 << " "
235+
<< 0 << " " << TotalNz-1 << "\"> \n";
236+
tbuffer << "</StructuredGrid> \n";
237+
tbuffer << "</VTKFile> \n";
238+
239+
op_mpi_write_vtk(Filename, buffer, hbuffer, tbuffer);
240+
#endif
147241
}
148242

149243
void VTK::WriteDistortedCompressed(

0 commit comments

Comments
 (0)