4 #ifndef DUNE_VTKWRITER_HH
5 #define DUNE_VTKWRITER_HH
17 #include <dune/common/exceptions.hh>
18 #include <dune/common/indent.hh>
19 #include <dune/common/iteratorfacades.hh>
20 #include <dune/common/path.hh>
21 #include <dune/common/shared_ptr.hh>
22 #include <dune/geometry/referenceelements.hh>
59 template<
class Gr
idView >
67 typedef typename GridView::template Codim< 0 >::Entity Cell;
68 typedef typename GridView::template Codim< n >::Entity Vertex;
76 typedef typename GridView::template Codim< 0 >
77 ::template Partition< VTK_Partition >::Iterator
79 typedef typename GridView::template Codim< n >
80 ::template Partition< VTK_Partition >::Iterator
88 switch( VTK_Partition )
93 default: DUNE_THROW(NotImplemented,
"Add check for this partition type");
120 return ReferenceElements<DT,n>::general((*this)->type()).
position(0,0);
126 return gridView_.template begin< 0, VTK_Partition >();
131 return gridView_.template end< 0, VTK_Partition >();
150 public ForwardIteratorFacade<VertexIterator, const Entity, const Entity&, int>
152 GridCellIterator git;
153 GridCellIterator gend;
159 std::vector<bool> visited;
169 const int numCorners = git->template count< n >();
170 if( cornerIndexDune == numCorners )
172 offset += numCorners;
176 while( (git != gend) && skipEntity( git->partitionType() ) )
182 const GridCellIterator & end,
185 git(x), gend(end), datamode(dm), cornerIndexDune(0),
186 vertexmapper(vm), visited(vm.size(), false),
190 visited[vertexmapper.
map(*git,cornerIndexDune,n)] =
true;
197 while(visited[vertexmapper.
map(*git,cornerIndexDune,n)])
200 if (git == gend)
return;
202 visited[vertexmapper.
map(*git,cornerIndexDune,n)] =
true;
211 return git == cit.git
212 && cornerIndexDune == cit.cornerIndexDune
213 && datamode == cit.datamode;
222 return cornerIndexDune;
227 return ReferenceElements<DT,n>::general(git->type())
235 gridView_.template end< 0, VTK_Partition >(),
236 datamode, *vertexmapper );
242 gridView_.template end< 0, VTK_Partition >(),
243 datamode, *vertexmapper );
262 public ForwardIteratorFacade<CornerIterator, const Entity, const Entity&, int>
264 GridCellIterator git;
265 GridCellIterator gend;
274 const std::vector<int> & number;
281 const GridCellIterator & end,
284 const std::vector<int> & num) :
285 git(x), gend(end), datamode(dm), cornerIndexVTK(0),
287 number(num), offset(0) {}
293 const int numCorners = git->template count< n >();
294 if( cornerIndexVTK == numCorners )
296 offset += numCorners;
300 while( (git != gend) && skipEntity( git->partitionType() ) )
306 return git == cit.git
307 && cornerIndexVTK == cit.cornerIndexVTK
308 && datamode == cit.datamode;
330 DUNE_THROW(IOError,
"VTKWriter: unsupported DataMode" << datamode);
338 gridView_.template end< 0, VTK_Partition >(),
339 datamode, *vertexmapper, number );
345 gridView_.template end< 0, VTK_Partition >(),
346 datamode, *vertexmapper, number );
398 void addCellData (
const V& v,
const std::string &name,
int ncomps = 1)
401 for (
int c=0; c<ncomps; ++c) {
402 std::stringstream compName;
405 compName <<
"[" << c <<
"]";
449 for (
int c=0; c<ncomps; ++c) {
450 std::stringstream compName;
453 compName <<
"[" << c <<
"]";
483 std::string
write (
const std::string &name,
515 std::string
pwrite (
const std::string & name,
const std::string & path,
const std::string & extendpath,
535 const std::string& path,
536 int commRank,
int commSize)
const
538 std::ostringstream s;
539 if(path.size() > 0) {
541 if(path[path.size()-1] !=
'/')
544 s <<
's' << std::setw(4) << std::setfill(
'0') << commSize <<
'-';
545 s <<
'p' << std::setw(4) << std::setfill(
'0') << commRank <<
'-';
566 const std::string& path,
569 std::ostringstream s;
570 if(path.size() > 0) {
572 if(path[path.size()-1] !=
'/')
575 s <<
's' << std::setw(4) << std::setfill(
'0') << commSize <<
'-';
598 const std::string& path)
const
600 static const std::string extension =
603 return concatPaths(path, name+extension);
621 std::string
write (
const std::string &name,
629 return pwrite(name,
"",
"", type, commRank, commSize);
639 file.exceptions(std::ios_base::badbit | std::ios_base::failbit |
640 std::ios_base::eofbit);
641 file.open( pieceName.c_str(), std::ios::binary );
642 if (! file.is_open())
643 DUNE_THROW(IOError,
"Could not write to piece file " << pieceName);
644 writeDataFile( file );
674 std::string
pwrite(
const std::string& name,
const std::string& path,
675 const std::string& extendpath,
684 file.exceptions(std::ios_base::badbit | std::ios_base::failbit |
685 std::ios_base::eofbit);
686 std::string piecepath = concatPaths(path, extendpath);
687 std::string relpiecepath = relativePath(path, piecepath);
692 file.open(fullname.c_str(),std::ios::binary);
693 if (! file.is_open())
694 DUNE_THROW(IOError,
"Could not write to piecefile file " << fullname);
703 file.open(fullname.c_str());
704 if (! file.is_open())
705 DUNE_THROW(IOError,
"Could not write to parallel file " << fullname);
706 writeParallelHeader(file,name,relpiecepath, commSize );
732 void writeParallelHeader(std::ostream& s,
const std::string& piecename,
733 const std::string& piecepath,
const int commSize)
747 if ((*it)->ncomps()==1)
749 scalars = (*it)->name();
755 if ((*it)->ncomps()>1)
757 vectors = (*it)->name();
760 writer.beginPointData(scalars, vectors);
765 unsigned writecomps = (*it)->ncomps();
766 if(writecomps == 2) writecomps = 3;
767 writer.addArray<
float>((*it)->name(), writecomps);
769 writer.endPointData();
776 if ((*it)->ncomps()==1)
778 scalars = (*it)->name();
784 if ((*it)->ncomps()>1)
786 vectors = (*it)->name();
789 writer.beginCellData(scalars, vectors);
792 unsigned writecomps = (*it)->ncomps();
793 if(writecomps == 2) writecomps = 3;
794 writer.addArray<
float>((*it)->name(), writecomps);
796 writer.endCellData();
799 writer.beginPoints();
800 writer.addArray<
float>(
"Coordinates", 3);
804 for(
int i = 0; i < commSize; ++i )
809 writer.addPiece(fullname);
816 void writeDataFile (std::ostream& s)
821 VTK::VTUWriter writer(s,
outputtype, fileType);
824 vertexmapper =
new VertexMapper(
gridView_ );
827 number.resize(vertexmapper->
size());
828 for (std::vector<int>::size_type i=0; i<number.size(); i++) number[i] = -1;
833 writeAllData(writer);
837 if(writer.beginAppended())
838 writeAllData(writer);
839 writer.endAppended();
841 delete vertexmapper; number.clear();
844 void writeAllData(VTK::VTUWriter& writer) {
869 DUNE_THROW(IOError,
"VTKWriter: unsupported OutputType" <<
outputtype);
877 return "UnstructuredGrid";
891 for (
int i=0; i<it->template count<n>(); ++i)
896 int alpha = vertexmapper->
map(*it,i,n);
898 number[alpha] = nvertices++;
914 std::string scalars =
"";
916 if ((*it)->ncomps()==1)
918 scalars = (*it)->name();
921 std::string vectors =
"";
923 if ((*it)->ncomps()>1)
925 vectors = (*it)->name();
934 unsigned writecomps = (*it)->ncomps();
935 if(writecomps == 2) writecomps = 3;
936 shared_ptr<VTK::DataArrayWriter<float> > p
939 if(!p->writeIsNoop())
942 for (
int j=0; j<(*it)->ncomps(); j++)
943 p->write((*it)->evaluate(j,*i,i.position()));
946 for (
unsigned j=(*it)->ncomps(); j < writecomps; ++j)
959 std::string scalars =
"";
961 if ((*it)->ncomps()==1)
963 scalars = (*it)->name();
966 std::string vectors =
"";
968 if ((*it)->ncomps()>1)
970 vectors = (*it)->name();
979 unsigned writecomps = (*it)->ncomps();
980 if(writecomps == 2) writecomps = 3;
981 shared_ptr<VTK::DataArrayWriter<float> > p
984 if(!p->writeIsNoop())
987 for (
int j=0; j<(*it)->ncomps(); j++)
988 p->write((*it)->evaluate(j,*vit,vit.position()));
991 for (
unsigned j=(*it)->ncomps(); j < writecomps; ++j)
1003 shared_ptr<VTK::DataArrayWriter<float> > p
1005 if(!p->writeIsNoop()) {
1010 for (
int j=0; j<
std::min(dimw,3); j++)
1011 p->write(vit->geometry().corner(vit.localindex())[j]);
1012 for (
int j=std::min(dimw,3); j<3; j++)
1029 shared_ptr<VTK::DataArrayWriter<int> > p1
1031 if(!p1->writeIsNoop())
1038 shared_ptr<VTK::DataArrayWriter<int> > p2
1040 if(!p2->writeIsNoop()) {
1044 offset += it->template count<n>();
1053 shared_ptr<VTK::DataArrayWriter<unsigned char> > p3
1055 if(!p3->writeIsNoop())
1082 std::vector<int> number;
Traits::IndexSet IndexSet
type of the index set
Definition: common/gridview.hh:70
const Entity & dereference() const
Definition: vtkwriter.hh:310
The dimension of the world the grid lives in.
Definition: common/gridview.hh:124
virtual void writeGridPoints(VTK::VTUWriter &writer)
write the positions of vertices
Definition: vtkwriter.hh:999
GridView gridView_
Definition: vtkwriter.hh:1072
PartitionIteratorType
Parameter to be used for the parallel level- and leaf iterators.
Definition: gridenums.hh:130
std::string write(const std::string &name, VTK::OutputType type, const int commRank, const int commSize)
write output (interface might change later)
Definition: vtkwriter.hh:621
std::string getFormatString() const
Definition: vtkwriter.hh:859
void increment()
Definition: vtkwriter.hh:288
CornerIterator(const GridCellIterator &x, const GridCellIterator &end, const VTK::DataMode &dm, const VertexMapper &vm, const std::vector< int > &num)
Definition: vtkwriter.hh:280
CornerIterator cornerBegin() const
Definition: vtkwriter.hh:335
Data array writers for the VTKWriter.
Writer for the ouput of grid functions in the vtk format.Writes arbitrary grid functions (living on c...
Definition: vtkwriter.hh:60
Output to the file is inline base64 binary.
Definition: common.hh:44
FileType
which type of VTK file to write
Definition: common.hh:290
Traits::Grid Grid
type of the grid
Definition: common/gridview.hh:67
VertexIterator vertexBegin() const
Definition: vtkwriter.hh:232
Implementation class for a multiple codim and multiple geometry type mapper.
Definition: mcmgmapper.hh:102
std::list< VTKFunctionPtr > celldata
Definition: vtkwriter.hh:1068
all entities
Definition: gridenums.hh:135
for .vtu files (UnstructuredGrid)
Definition: common.hh:294
The dimension of the grid.
Definition: common/gridview.hh:120
for .vtp files (PolyData)
Definition: common.hh:292
Grid::ctype ctype
type used for coordinates in grid
Definition: common/gridview.hh:117
void endCellData()
finish CellData section
Definition: vtuwriter.hh:218
A base class for grid functions with any return type and dimension.
Definition: function.hh:37
Common stuff for the VTKWriter.
void basicIncrement()
Definition: vtkwriter.hh:164
Take a vector and interpret it as cell data for the VTKWriter.
Definition: function.hh:87
Output to the file is in ascii.
Definition: common.hh:42
void increment()
Definition: vtkwriter.hh:192
void beginPoints()
start section for the point coordinates
Definition: vtuwriter.hh:236
int size() const
Return total number of entities in the entity set managed by the mapper.
Definition: mcmgmapper.hh:181
Functions for VTK output.
Iterate over the elements' corners.
Definition: vtkwriter.hh:261
virtual void writeCellData(VTK::VTUWriter &writer)
write cell data
Definition: vtkwriter.hh:909
const Entity & dereference() const
Definition: vtkwriter.hh:215
void clear()
clear list of registered functions
Definition: vtkwriter.hh:460
Iterate over the grid's vertices.
Definition: vtkwriter.hh:149
Mapper for multiple codim and multiple geometry types.
int localindex() const
index of vertex within the entity, in Dune-numbering
Definition: vtkwriter.hh:220
std::string getTypeString() const
Definition: vtkwriter.hh:872
CornerIterator cornerEnd() const
Definition: vtkwriter.hh:342
virtual void writeVertexData(VTK::VTUWriter &writer)
write vertex data
Definition: vtkwriter.hh:954
int ncells
Definition: vtkwriter.hh:1075
void addVertexData(const VTKFunctionPtr &p)
Add a grid function that lives on the vertices of the grid to the visualization.
Definition: vtkwriter.hh:425
CellIterator cellEnd() const
Definition: vtkwriter.hh:129
int ncorners
Definition: vtkwriter.hh:1077
virtual void writeGridCells(VTK::VTUWriter &writer)
write the connectivity array
Definition: vtkwriter.hh:1023
GeometryType geometryType(const Dune::GeometryType &t)
mapping from GeometryType to VTKGeometryType
Definition: common.hh:195
Iterator over the grids elements.
Definition: vtkwriter.hh:111
std::list< VTKFunctionPtr > vertexdata
Definition: vtkwriter.hh:1069
Output non-conforming data.
Definition: common.hh:78
void endPointData()
finish PointData section
Definition: vtuwriter.hh:180
Grid view abstract base classInterface class for a view on grids. Grids return two types of view...
Definition: common/gridview.hh:56
CellIterator(const GridCellIterator &x)
construct a CellIterator from the gridview's Iterator.
Definition: vtkwriter.hh:115
PartitionType
Attributes used in the generic overlap model.
Definition: gridenums.hh:24
shared_ptr< const VTKFunction > VTKFunctionPtr
Definition: vtkwriter.hh:100
Dump a .vtu/.vtp files contents to a stream.
Definition: pvtuwriter.hh:60
void addCellData(const VTKFunctionPtr &p)
Add a grid function that lives on the cells of the grid to the visualization.
Definition: vtkwriter.hh:367
CellIterator cellBegin() const
Definition: vtkwriter.hh:124
Ouput is to the file is appended raw binary.
Definition: common.hh:46
const FieldVector< DT, n > & position() const
position of vertex inside the entity
Definition: vtkwriter.hh:225
OutputType
How the bulk data should be stored in the file.
Definition: common.hh:40
void endCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:283
VTK::OutputType outputtype
Definition: vtkwriter.hh:1085
std::string getSerialPieceName(const std::string &name, const std::string &path) const
return name of a serial piece file
Definition: vtkwriter.hh:597
const FieldVector< DT, n > position() const
Definition: vtkwriter.hh:118
bool equals(const CornerIterator &cit) const
Definition: vtkwriter.hh:304
VertexIterator(const GridCellIterator &x, const GridCellIterator &end, const VTK::DataMode &dm, const VertexMapper &vm)
Definition: vtkwriter.hh:181
Output conforming data.
Definition: common.hh:70
interior and border entities
Definition: gridenums.hh:132
void addCellData(const V &v, const std::string &name, int ncomps=1)
Add a grid function (represented by container) that lives on the cells of the grid to the visualizati...
Definition: vtkwriter.hh:398
void beginCellData(const std::string &scalars="", const std::string &vectors="")
start CellData section
Definition: vtuwriter.hh:203
int id() const
Process-local consecutive zero-starting vertex id.
Definition: vtkwriter.hh:319
VTKWriter(const GridView &gridView, VTK::DataMode dm=VTK::conforming)
Construct a VTKWriter working on a specific GridView.
Definition: vtkwriter.hh:357
virtual void countEntities(int &nvertices, int &ncells, int &ncorners)
count the vertices, cells and corners
Definition: vtkwriter.hh:881
Dune::VTKFunction< GridView > VTKFunction
Definition: vtkwriter.hh:99
DataMode
Whether to produce conforming or non-conforming output.
Definition: common.hh:64
int renumber(const Dune::GeometryType &t, int i)
renumber VTK <-> Dune
Definition: common.hh:224
int map(const EntityType &e) const
Map entity to array index.
Definition: mcmgmapper.hh:153
Ouput is to the file is appended base64 binary.
Definition: common.hh:48
int nvertices
Definition: vtkwriter.hh:1076
std::string write(const std::string &name, VTK::OutputType type=VTK::ascii)
write output (interface might change later)
Definition: vtkwriter.hh:483
bool equals(const VertexIterator &cit) const
Definition: vtkwriter.hh:209
void addCellData(VTKFunction *p)
Add a grid function that lives on the cells of the grid to the visualization.
Definition: vtkwriter.hh:377
std::string getParallelHeaderName(const std::string &name, const std::string &path, int commSize) const
return name of a parallel header file
Definition: vtkwriter.hh:565
const CollectiveCommunication & comm() const
obtain collective communication object
Definition: common/gridview.hh:232
void beginCells()
start section for the grid cells/PolyData lines
Definition: vtuwriter.hh:272
void addVertexData(VTKFunction *p)
Add a grid function that lives on the vertices of the grid to the visualization.
Definition: vtkwriter.hh:416
Dump a .vtu/.vtp files contents to a stream.
Definition: vtuwriter.hh:96
std::string pwrite(const std::string &name, const std::string &path, const std::string &extendpath, VTK::OutputType type=VTK::ascii)
write output (interface might change later)
Definition: vtkwriter.hh:515
void endPoints()
finish section for the point coordinates
Definition: vtuwriter.hh:247
std::string getParallelPieceName(const std::string &name, const std::string &path, int commRank, int commSize) const
return name of a parallel piece file
Definition: vtkwriter.hh:534
void beginPointData(const std::string &scalars="", const std::string &vectors="")
start PointData section
Definition: vtuwriter.hh:165
VertexIterator vertexEnd() const
Definition: vtkwriter.hh:239
std::string pwrite(const std::string &name, const std::string &path, const std::string &extendpath, VTK::OutputType ot, const int commRank, const int commSize)
write output; interface might change later
Definition: vtkwriter.hh:674
virtual ~VTKWriter()
destructor
Definition: vtkwriter.hh:467
void addVertexData(const V &v, const std::string &name, int ncomps=1)
Add a grid function (represented by container) that lives on the vertices of the grid to the visualiz...
Definition: vtkwriter.hh:446
all interior entities
Definition: gridenums.hh:25
int min(const DofVectorPointer< int > &dofVector)
Definition: dofvector.hh:352
DataArrayWriter< T > * makeArrayWriter(const std::string &name, unsigned ncomps, unsigned nitems)
aquire a DataArrayWriter
Definition: vtuwriter.hh:379
Take a vector and interpret it as point data for the VTKWriter.
Definition: function.hh:190
std::list< VTKFunctionPtr >::const_iterator FunctionIterator
Definition: vtkwriter.hh:103