KASKADE 7 development version
iobase.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) 2009-2018 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 IOBASE_HH
14#define IOBASE_HH
15
16#include <string>
17
18#include <boost/fusion/include/for_each.hpp>
19#include <boost/fusion/include/zip_view.hpp>
20#include <boost/fusion/include/vector.hpp>
21
36//---------------------------------------------------------------------
37//---------------------------------------------------------------------
38
39namespace Kaskade
40{
41 struct UnaryTrue {
42 template <class T>
43 bool operator()(T const&) const { return true; }
44 };
45
46
50 namespace IoDetail {
51
52
53 template <class GridView,
54 class Writer,
55 class Filter,
56 class RAIter>
57 struct AddDataTo {};
58
59
60 } // End of namespace IoDetail
76 struct IoOptions
77 {
83 {
87 binary
88 };
89
94 {
111 };
112
113 enum Info
114 {
116 };
117
121 IoOptions() = default;
122
129 IoOptions& setOrder(int ord) { order = ord; return *this; }
130
137 IoOptions& setOutputType(OutputType out) { outputType = out; return *this; }
138
142 IoOptions& setPrecision(int pre) { precision = pre; return *this; }
143
147 IoOptions& setDataMode(DataMode mode) { dataMode = mode; return *this; }
148
152 int precision = 6;
153 int order = 1;
154 };
155
157 //---------------------------------------------------------------------
158
168 std::string paddedString(int n, int places=3);
169
170 //---------------------------------------------------------------------
171
186 template <class GridView,
187 class Writer,
188 class VariableSet,
189 class Filter,
190 class Options>
191 void writePartialFile(GridView const& gridView,
192 Writer& writer,
193 VariableSet const& vars,
194 std::string const& filename,
195 Filter const& filter,
196 Options const& options)
197 {
198 using namespace boost::fusion;
199
200 // Bug in boost::fusion? The following line does not work!
201 // for_each(zip(description.variables,vars.data),AddDataTo<VTKWriter>(writer));
202
203 typedef vector<typename VariableSet::Descriptions::Variables const&,
204 typename VariableSet::Functions const&> ZipVector;
205 zip_view<ZipVector> zipView(ZipVector(typename VariableSet::Descriptions::Variables(),vars.data));
206 for_each(zipView,IoDetail::AddDataTo<GridView,Writer,Filter,std::string const*>(gridView,writer,filter,&vars.descriptions.names[0]));
207
208 writer.write(filename.c_str(),options);
209 }
210
211} // namespace Kaskade
212
213#endif
A class for storing a heterogeneous collection of FunctionSpaceElement s.
Definition: variables.hh:341
VSDescriptions::RepresentationData Functions
boost::fusion::vector of data elements (of type FunctionSpaceElement)
Definition: variables.hh:347
Descriptions const & descriptions
Descriptions of variable set, of type VariableSetDescription (lots of useful infos)
Definition: variables.hh:510
std::string paddedString(int n, int places=3)
creates a zero-padded string representation of the given number
void writePartialFile(GridView const &gridView, Writer &writer, VariableSet const &vars, std::string const &filename, Filter const &filter, Options const &options)
Definition: iobase.hh:191
IoOptions ioOptions_default
options for VTK/AMIRA output
Definition: iobase.hh:77
DataMode dataMode
Definition: iobase.hh:150
OutputType
Determines text or binary output format. Currently this is only used by VTK output.
Definition: iobase.hh:83
OutputType outputType
Definition: iobase.hh:149
IoOptions()=default
Default constructor.
IoOptions & setOutputType(OutputType out)
Sets the output type to either ascii or binary.
Definition: iobase.hh:137
IoOptions & setPrecision(int pre)
Sets the number of decimal digits to be written for floating point numbers.
Definition: iobase.hh:142
IoOptions & setOrder(int ord)
Sets the polynomial order of output.
Definition: iobase.hh:129
DataMode
The data mode determines the continuity structure of the output.
Definition: iobase.hh:94
IoOptions & setDataMode(DataMode mode)
Sets the data mode (conforming or nonconforming).
Definition: iobase.hh:147
bool operator()(T const &) const
Definition: iobase.hh:43