void io::VtkWriter::writeTimeStep(
		const Float2D &i_h,
        const Float2D &i_hu,
        const Float2D &i_hv,
        float i_time)
{
	std::ofstream vtkFile(generateFileName().c_str());
	assert(vtkFile.good());

	// VTK HEADER
	vtkFile << "<?xml version=\"1.0\"?>" << std::endl
			<< "<VTKFile type=\"StructuredGrid\">" << std::endl
			<< "<StructuredGrid WholeExtent=\"" << offsetX << " " << offsetX+nX
				<< " " << offsetY << " " << offsetY+nY << " 0 0\">" << std::endl
	        << "<Piece Extent=\"" << offsetX << " " << offsetX+nX
	        	<< " " << offsetY << " " << offsetY+nY << " 0 0\">" << std::endl;

	vtkFile << "<Points>" << std::endl
			<< "<DataArray NumberOfComponents=\"3\" type=\"Float32\" format=\"ascii\">" << std::endl;

	//GITTER PUNKTE
	for (int j=0; j < nX+1; j++)
	      for (int i=0; i < nX+1; i++)
	    	  vtkFile << (offsetX+i)*dX << " " << (offsetY+j)*dY <<" 0" << std::endl;

	vtkFile << "</DataArray>" << std::endl
			<< "</Points>" << std::endl;

	vtkFile << "<CellData>" << std::endl;

	// Water surface height (h+b)
	vtkFile << "<DataArray Name=\"H\" type=\"Float32\" format=\"ascii\">" << std::endl;
	for (int j=1; j < nY+1; j++)
		for (int i=1; i < nX+1; i++)
			vtkFile << i_h[i][j]+b[i][j] << std::endl;
	vtkFile << "</DataArray>" << std::endl;

	// Velocities
	vtkFile << "<DataArray Name=\"U\" type=\"Float32\" format=\"ascii\">" << std::endl;
	for (int j=1; j < nY+1; j++)
		for (int i=1; i < nX+1; i++)
			vtkFile << ((i_h[i][j]>0) ? i_hu[i][j]/i_h[i][j] : 0.0 ) << std::endl;
	vtkFile << "</DataArray>" << std::endl;

	vtkFile << "<DataArray Name=\"V\" type=\"Float32\" format=\"ascii\">" << std::endl;
	for (int j=1; j < nY+1; j++)
		for (int i=1; i<nX+1; i++)
			vtkFile << ((i_h[i][j]>0) ? i_hv[i][j]/i_h[i][j] : 0.0 ) << std::endl;
	vtkFile << "</DataArray>" << std::endl;

	// Bathymetry
	vtkFile << "<DataArray Name=\"B\" type=\"Float32\" format=\"ascii\">" << std::endl;
	for (int j=1; j<nY+1; j++)
		for (int i=1; i<nX+1; i++)
			vtkFile << b[i][j] << std::endl;
	vtkFile << "</DataArray>" << std::endl;

	vtkFile << "</CellData>" << std::endl
			<< "</Piece>" << std::endl;

	vtkFile << "</StructuredGrid>" << std::endl
			<< "</VTKFile>" << std::endl;

	// Increament time step
	timeStep++;
}
Beispiel #2
0
void io::VtkWriter::writeTimeStep(
		const Float2D &i_h,
        const Float2D &i_hu,
        const Float2D &i_hv,
        float i_time)
{
	std::ofstream vtkFile(generateFileName().c_str());
	assert(vtkFile.good());

	//Grid wrapper for each grid
	CoarseGridWrapper gridWrapperH(i_h, boundarySize, nX, nY, coarseness);
	CoarseGridWrapper gridWrapperHu(i_hu, boundarySize, nX, nY, coarseness);
	CoarseGridWrapper gridWrapperHv(i_hv, boundarySize, nX, nY, coarseness);
	CoarseGridWrapper gridWrapperB(b, boundarySize, nX, nY, coarseness);

	// VTK header
	vtkFile << "<?xml version=\"1.0\"?>" << std::endl
			<< "<VTKFile type=\"StructuredGrid\">" << std::endl
			<< "<StructuredGrid WholeExtent=\"" << offsetX << " " << offsetX+coarseX
				<< " " << offsetY << " " << offsetY+coarseY << " 0 0\">" << std::endl
	        << "<Piece Extent=\"" << offsetX << " " << offsetX+coarseX
	        	<< " " << offsetY << " " << offsetY+coarseY << " 0 0\">" << std::endl;

	vtkFile << "<Points>" << std::endl
			<< "<DataArray NumberOfComponents=\"3\" type=\"Float32\" format=\"ascii\">" << std::endl;

	//Grid points
	for (unsigned int j=0; j < coarseX+1; j++)
        for (unsigned int i=0; i < coarseY+1; i++)
            vtkFile << (offsetX+i)*((dX * float(nX)) / float(coarseX))
                << " " << (offsetY+j)*((dY * float(nY)) / float(coarseY))
                << " 0" << std::endl;
    
	vtkFile << "</DataArray>" << std::endl
			<< "</Points>" << std::endl;

	vtkFile << "<CellData>" << std::endl;

	// Water surface height h
	vtkFile << "<DataArray Name=\"h\" type=\"Float32\" format=\"ascii\">" << std::endl;
	for (unsigned int j=0; j < coarseY; j++)
		for (unsigned int i=0; i < coarseX+0; i++)
			vtkFile << gridWrapperH.getElem(i, j) << std::endl;
	vtkFile << "</DataArray>" << std::endl;

	// Momentums
	vtkFile << "<DataArray Name=\"hu\" type=\"Float32\" format=\"ascii\">" << std::endl;
	for (unsigned int j=0; j < coarseY; j++)
		for (unsigned int i=0; i < coarseX; i++)
			vtkFile << gridWrapperHu.getElem(i, j) << std::endl;
	vtkFile << "</DataArray>" << std::endl;

	vtkFile << "<DataArray Name=\"hv\" type=\"Float32\" format=\"ascii\">" << std::endl;
	for (unsigned int j=0; j < coarseY; j++)
		for (unsigned int i=0; i<coarseX; i++)
			vtkFile << gridWrapperHv.getElem(i, j) << std::endl;
	vtkFile << "</DataArray>" << std::endl;

	// Bathymetry
	vtkFile << "<DataArray Name=\"b\" type=\"Float32\" format=\"ascii\">" << std::endl;
	for (unsigned int j=0; j<coarseY; j++)
		for (unsigned int i=0; i<coarseX; i++)
			vtkFile << gridWrapperB.getElem(i, j) << std::endl;
	vtkFile << "</DataArray>" << std::endl;

	vtkFile << "</CellData>" << std::endl
			<< "</Piece>" << std::endl;

	vtkFile << "</StructuredGrid>" << std::endl
			<< "</VTKFile>" << std::endl;

	// Increament time step
	timeStep++;
}