dune-grid
2.11
Toggle main menu visibility
Loading...
Searching...
No Matches
dune
grid
io
file
gnuplot
gnuplot.cc
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root
2
// SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception
3
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
4
// vi: set et ts=4 sw=2 sts=2:
9
10
#include "
../gnuplot.hh
"
11
12
namespace
Dune
{
13
17
template
<
class
Gr
id
View>
18
void
19
GnuplotWriter<GridView>::write
(
const
std::string& filename)
const
20
{
21
// open file
22
std::ofstream file(filename.c_str());
23
// write all column names
24
file <<
"# coord\t"
;
25
for
(
size_t
i=0; i<_names.size(); i++)
26
file << _names[i] <<
"\t"
;
27
file <<
"\n"
;
28
29
if
(dimworld==1) {
30
#if !NDEBUG
31
int
counter = 0;
32
#endif
33
typedef
typename
GridView::template Codim<0>::Iterator CellIterator;
34
CellIterator it = _gv.template begin<0>();
35
CellIterator end = _gv.template end<0>();
36
for
(; it != end; ++it)
37
{
38
int
i = _is.index(*it);
39
// check that the elements are numbered consecutively
40
assert (i == counter++);
41
// calc positions
42
assert(it->geometry().corners() == 2);
43
const
FieldVector<ctype,dimworld>& left = it->geometry().corner(0);
44
const
FieldVector<ctype,dimworld>& right = it->geometry().corner(1);
45
assert(left[0] < right[0]);
46
// write gnuplot rows for left & right vertex
47
writeRow(file, left, _data[2*i]);
48
writeRow(file, right, _data[2*i+1]);
49
}
50
51
}
else
{
52
53
typedef
typename
GridView::template Codim<dimworld>::Iterator VertexIterator;
54
VertexIterator it = _gv.template begin<dimworld>();
55
VertexIterator end = _gv.template end<dimworld>();
56
for
(; it != end; ++it) {
57
58
// write gnuplot rows for vertex
59
writeRow(file, it->geometry().corner(0), _data[_is.index(*it)]);
60
61
}
62
63
}
64
65
}
66
67
template
<
class
Gr
id
View>
68
void
69
GnuplotWriter<GridView>::writeRow(std::ostream & file,
70
const
FieldVector<ctype,dimworld>& position,
71
const
std::vector<float> & data)
const
72
{
73
assert (data.size() == _names.size());
74
// write position
75
file << position <<
"\t"
;
76
// write all data columns
77
for
(
size_t
j=0; j<data.size(); j++)
78
file << data[j] <<
"\t"
;
79
file <<
"\n"
;
80
}
81
87
template
<
class
Gr
id
View>
88
template
<
class
DataContainer>
89
void
90
GnuplotWriter<GridView>::addData(DataType t,
const
DataContainer& data,
const
std::string & name)
91
{
92
assert((t == cellData && _is.size(0) == data.size())
93
|| (t == vertexData && _is.size(
GridView::dimension
) == data.size()) );
94
_names.push_back(name);
95
96
// copy data to new container
97
98
if
(dimworld==1) {
99
100
// data is transformed to nonconforming vertex data
101
int
c = 0;
102
int
shift = (t==vertexData ? 1 : 0);
103
for
(
size_t
i=0; i<_is.size(0); i++)
104
{
105
_data[c++].push_back(data[i]);
106
_data[c++].push_back(data[i+shift]);
107
};
108
109
}
else
{
110
111
// 2d: only vertex data is allowed
112
for
(
size_t
i=0; i<_is.size(dimworld); i++)
113
_data[i].push_back(data[i]);
114
115
}
116
117
}
118
119
}
gnuplot.hh
Provides gnuplot output for 1D Grids.
Dune::GridView::dimension
static constexpr int dimension
The dimension of the grid.
Definition
common/gridview.hh:134
Dune
Include standard header files.
Definition
agrid.hh:60
Dune::GnuplotWriter::write
void write(const std::string &filename) const
Write Gnuplot file to disk.
Definition
gnuplot.cc:19
Generated by
1.17.0