Commit f9dea432 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

[112-integrate-erlangen-2] added changes to plot

parent 35b7846e
Pipeline #168236 failed with stages
in 0 seconds
include_directories(${PROJECT_SOURCE_DIR}/src/shapes)
set(src
Plot.C
# Plot.C
geometry/Point.cpp
QuadratureInterval.cpp
QuadratureTriangle.cpp
......
......@@ -5,6 +5,7 @@
#include "utility/Config.hpp"
#include "parallel/Parallel.hpp"
#include "utility/M_IOFiles.hpp"
#include <iostream>
using namespace std;
......@@ -700,6 +701,151 @@ void Plot::vtk_vertexdata(const string &name, int k, bool deformed) {
vtk_scalar(out, k);
}
#if 1
void Plot::xml_header (ostream& out) {
out << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" << std::endl;
out << "<UnstructuredGrid>" << std::endl;
out << "<Piece NumberOfPoints=\"" << VD.size() << "\" NumberOfCells=\"" << C.size() <<"\">" << std::endl;
}
void Plot::vtk_xml_alldata(const char* name, const string components[], int k1, int k2, int k3, double t, int deformed) {
if (!PPM->master()) return;
string filename = string("data/vtk/") + name + string(".vtu");
M_ofstream out(filename.c_str());
xml_header(out);
out << "<PointData Scalars=\"scalars\">" << endl;
for (int j=0; j<k1; ++j) {
out << "<DataArray type=\"Float32\" Name=\"" << components[j] << "\" format=\"ascii\">" << std::endl;
for (plotdata p=plotdata(VD.begin()); p!=plotdata(VD.end()); ++p) {
if (abs(p[j]) < PlotTolerance) out << "0"<<endl;
else out << p[j]<<endl;
}
out << "</DataArray>" << endl;
}
for (int j=0; j<k2; ++j) {
out << "<DataArray type=\"Float32\" Name=\"" << components[k1+j] << "\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl;
for (plotdata p=plotdata(VD.begin()); p!=plotdata(VD.end()); ++p) {
if (abs(p[k1+M.dim()*j]) < PlotTolerance) out << "0";
else out << p[k1+M.dim()*j];
if (abs(p[k1+M.dim()*j+1]) < PlotTolerance) out << " 0";
else out << " "<<p[k1+M.dim()*j+1];
if (M.dim() == 2) out<<" 0"<<std::endl;
else {
if (abs(p[k1+M.dim()*j+2]) < PlotTolerance) out << " 0"<< std::endl;
else out << " "<<p[k1+M.dim()*j+2]<< std::endl;
}
}
out << "</DataArray>" << std::endl;
}
out << "</PointData>" << std::endl;
out << "<CellData Scalars=\"scalars\">" << std::endl;
for (int j=0; j<k3; ++j) {
out << "<DataArray type=\"Float32\" Name=\"" << components[k1+k2+j] << "\" format=\"ascii\">" << std::endl;
for (unsigned int i=0; i<CD.size(); ++i) {
if (abs(CD[i][j]) < PlotTolerance)
out << "0" << std::endl;
else
out << CD[i][j] << std::endl;
}
out << "</DataArray>" << std::endl;
}
out << "</CellData>" << std::endl;
vtk_xml_mesh(out, deformed);
xml_footer(out);
pvd_file(t, name);
}
void Plot::vtk_xml_mesh(std::ostream& out, bool deform) {
out << "<Points>" << endl;
out << "<DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << std::endl;
if (M.dim() == 2) Point_2d();
// { std::cerr << "Point 2D fehlt " << std::endl; std::cerr.flush(); exit(1);} //
for (plotdata p=plotdata(VD.begin()); p!=plotdata(VD.end()); ++p) {
if (deform) {
Point pp = p();
for (int i=0;i<M.dim(); ++i) pp[i] += p[i];
out <<pp;
}
// else out << p();
else
{
for( size_t i = 0; i < M.dim(); i++ )
out << p()[i] << " ";
}
if (M.dim() ==2) out <<" 0";
out<<endl;
}
out << "</DataArray>" << endl;
out << "</Points>" << endl;
out << "<Cells>" << endl;
out << "<DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">" << endl;
vector<int> offsets(C.size());
for (unsigned int i=0; i<C.size(); ++i, out << endl) {
offsets[i] = (i>0 ? offsets[i-1] : 0) + C[i].size();
switch (C[i].size()) {
case 3:
out << C[i][0] << " " << C[i][1] << " " << C[i][2];
break;
case 4:
if (M.dim() == 2)
out<<C[i][0]<<" "<<C[i][1]<<" "<<C[i][3]<<" "<< C[i][2];
else
out<<C[i][0]<<" "<<C[i][2]<<" "<<C[i][1]<<" "<< C[i][3];
break;
case 8:
out << C[i][0] << " " << C[i][1] << " " << C[i][3]
<< " " << C[i][2] << " " << C[i][4]
<< " " << C[i][5] << " " << C[i][7] << " " << C[i][6];
break;
}
}
out << "</DataArray>" << endl;
out << "<DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">" << endl;
for (unsigned int i=0; i<offsets.size(); ++i) {
out << offsets[i] << endl;
}
out << "</DataArray>" << endl;
out << "<DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">" << endl;
for (unsigned int i=0; i<C.size(); ++i, out << endl) {
switch (C[i].size()) {
case 3: out << "5";
break;
case 4:
if (M.dim() == 2) out<< "8";
else out<< "10";
break;
case 8: out << "11";
break;
}
}
out << "</DataArray>" << endl;
out << "</Cells>" << endl;
}
void Plot::xml_footer (std::ostream& out) {
out << "</Piece>" << endl;
out << "</UnstructuredGrid>" << endl;
out << "</VTKFile>" << endl;
}
void Plot::pvd_file (double t, const char* name) {
string filename = "data/vtk/" + pvd_name + ".pvd";
ofstream out2(filename.c_str(), ios::in | ios::out | ios::ate);
int size = out2.tellp();
out2.seekp(size-25);
out2 << "<DataSet timestep=\"" << t << "\" file=\"" << name << ".vtu" << "\"/>" << endl;
out2 << "</Collection>" << endl;
out2 << "</VTKFile>" << endl;
out2.close();
}
#endif
void Plot::vtk_2d_graph(const char *name, int k) {
if (!PPM->master()) return;
string filename = DataPathName + string("/vtk/") + name + string(".vtk");
......@@ -994,6 +1140,21 @@ Plot::Plot(const Mesh &m, int N, int K) : M(m), VD(M, N), C(M, VD),
config.get("vtkplot", vtkplot);
config.get("PlotTolerance", PlotTolerance);
SetDataPath();
#if 1
if (vtkplot) {
config.get("PVD_Name",pvd_name);
std::string filename = "data/vtk/" + pvd_name + ".pvd";
std::ofstream out(filename.c_str());
out << "<?xml version=\"1.0\"?>" << endl;
out << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">" << endl;
out << "<Collection>" << endl;
out << "</Collection>" << endl;
out << "</VTKFile>" << endl;
out.close();
}
#endif
}
......
......@@ -115,6 +115,11 @@ class Plot {
int vtkplot;
double PlotTolerance;
#if 1
std::string pvd_name;
#endif
void plotPoint(std::ostream &os, const Point &p) {
os << p[0];
for (int i = 1; i < SpaceDimension; ++i)
......@@ -223,6 +228,18 @@ public:
void vtk_vertexdata(const char *name, int k = 0, bool deformed = false);
#if 1
void xml_header (std::ostream& out);
void pvd_file (double t, const char* name);
void xml_footer (std::ostream& out);
void vtk_xml_mesh(std::ostream& out, bool deform);
void vtk_xml_alldata(const char* name, const std::string components[], int k1, int k2, int k3, double t, int deformed = 0);
#endif
void vtk_vertexdata(const string &name, int k = 0, bool deformed = false);
void vtk_stokes(const char *name, int deform = 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment