KASKADE 7 development version
vtk.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2022 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef VTK_HH
14#define VTK_HH
15
17#include "io/iobase.hh"
18#include "io/vtkwriter.hh"
19#include "fem/variables.hh"
21
39//---------------------------------------------------------------------
40
41namespace Kaskade
42{
43
55 template <class Function>
56 void writeVTK(Function const& f, std::string const& filename, IoOptions options, std::string fname)
57 {
58 using namespace boost::fusion;
59
60 if (fname.empty())
61 fname = filename;
62
63 // Construct a variable set (trivially consisting of only one function) to be handed to the
64 // VTK writer.
65 auto vsDescription = makeVariableSetDescription(
66 makeSpaceList(&f.space()),
67 make_vector(Variable<SpaceIndex<0>,
69 auto fs = vsDescription.variableSet();
70 component<0>(fs) = f;
71
72 // write the VTK file
73 writeVTK(fs,filename,options);
74 }
75
76
77 //---------------------------------------------------------------------
78
88 {
89 public:
90 TimeSeriesVTKWriter(std::string const& basename, IoOptions options_= ioOptions_default)
91 : base(basename), pvd((basename+".pvd").c_str()), count(0), options(options_)
92 {
93 pvd << "<?xml version=\"1.0\"?>\n"
94 << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"" << VTKWriterDetail::vtkEndianness() << "\">\n"
95 << " <Collection>\n";
96 }
97
101 template <class VariableSet>
102 void add(double time, VariableSet const& vars)
103 {
104 auto fname = base+"-"+paddedString(count,4);
105 writeVTK(vars,fname,options);
106
107 pvd << " <DataSet timestep=\"" << time << "\" file=\"" << fname << ".vtu\" />\n";
108 ++count;
109 }
110
112 {
113 pvd << " </Collection>\n"
114 << "</VTKFile>\n";
115 }
116
117 private:
118 std::string base;
119 std::ofstream pvd;
120 int count;
121 IoOptions options;
122 };
123
124
125 //---------------------------------------------------------------------
126 //---------------------------------------------------------------------
127
128
129
130
131} // end namespace Kaskade
132//---------------------------------------------------------------------
133
134#endif
Function is the interface for evaluatable functions .
Definition: concepts.hh:324
void add(double time, VariableSet const &vars)
Adds frame with values given by vars at time time to the series.
Definition: vtk.hh:102
TimeSeriesVTKWriter(std::string const &basename, IoOptions options_=ioOptions_default)
Definition: vtk.hh:90
A class for storing a heterogeneous collection of FunctionSpaceElement s.
Definition: variables.hh:341
std::string paddedString(int n, int places=3)
creates a zero-padded string representation of the given number
void writeVTK(Function const &f, std::string const &filename, IoOptions options, std::string fname)
Writes a single finite element function to a VTK file.
Definition: vtk.hh:56
Output of mesh and solution for visualization software.
IoOptions ioOptions_default
Helper class for specifying the number of components of a variable.
Definition: variables.hh:100
options for VTK/AMIRA output
Definition: iobase.hh:77
Helper class for specifying the FE space index of a variable.
Definition: variables.hh:92
A class defining elementary information about a single variable.
Definition: variables.hh:128
Variables and their descriptions.