20#include "dune/grid/common/grid.hh"
21#include "dune/common/fmatrix.hh"
47 template<
class Function>
51 typedef typename Function::Space
Space;
52 typedef typename Space::Grid
Grid;
70 lowerbound(lb), upperbound(ub), step(st), scalar(dataIsScalar)
74 step[i]=(upperbound[i]-lowerbound[i])/(size[i]-1);
82 std::ofstream out(name.c_str());
84 throw FileIOException(
"Failed to open file for writing.",name,__FILE__,__LINE__);
86 out <<
"<VTKFile type=\"RectilinearGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n"
87 <<
" <RectilinearGrid WholeExtent=\"";
88 for (
int i=0; i<
spaceDim; ++i) out <<
"0 " << size[i]-1 <<
' ';
89 for (
int i=
spaceDim; i<3; ++i) out <<
"0 0 ";
91 <<
" <Piece Extent=\"";
92 for (
int i=0; i<
spaceDim; ++i) out <<
"0 " << size[i]-1 <<
' ';
93 for (
int i=
spaceDim; i<3; ++i) out <<
"0 0 ";
99 <<
" <DataArray type=\"Float32\" format=\"ascii\" Name=\"u\" NumberOfComponents=\"" << vtkComponents <<
"\">\n";
102 for(
int i=0; i<data.size(); ++i) {
104 out <<
static_cast<float>(data[i][j]) <<
' ';
111 out <<
" </DataArray>\n"
113 <<
" <Coordinates>\n";
115 for (
int i=0; i<3; ++i)
117 out <<
" <DataArray type=\"Float32\" format=\"ascii\" NumberOfComponents=\"1\" Name=\"" << (i==0?
'x': i==1?
'y':
'z') <<
"\">\n ";
119 for (
int j=0; j<size[i]; ++j)
120 out << lowerbound[i] + j*step[i] <<
' ';
124 <<
" </DataArray>\n";
127 out <<
" </Coordinates>\n"
129 <<
" </RectilinearGrid>\n"
139 size[i]=(
int)floor((upperbound[i]-lowerbound[i])/step[i])+1;
147 ShapeFunctionCache<Grid,typename Function::Scalar> sfCache;
151 for(
int i=0; i<
spaceDim; i++) datasize *= size[i];
152 data.resize(datasize);
153 for(
int i=0; i<datasize; ++i) data[i] = 0.0;
154 typename Space::Evaluator fkt(fu.space(),&sfCache);
155 typedef typename Grid::template Codim<0>::Entity
Cell;
157 for (
auto ci=fu.space().gridView().template begin<0>(); ci!=fu.space().gridView().template end<0>(); ++ci)
161 getIndexRange<Cell, Grid::dimension>(lrange,urange,*ci);
162 scanLocally<Cell, Grid::dimension>(fu, fkt, data,*ci,lrange,urange,at,
spaceDim);
167 template<
class Entity,
int spaceDim>
173 for(
int i=0; i<ci.geometry().corners(); i++)
175 auto x = ci.geometry().corner(i);
184 lower[i] =
std::max((
int)ceil((lr[i]-lowerbound[i])/step[i]), 0);
185 upper[i] =
std::min((
int)ceil((ur[i]-lowerbound[i])/step[i])+1,size[i]);
189 template<
int spaceDim>
194 x[i] = lowerbound[i]+step[i]*ind[i];
207 index += ind[i]*mult;
213 template<
class Entity,
int spaceDim>
214 void scanLocally(
Function const& fu,
215 typename Function::Space::Evaluator& fkt,
216 std::vector<typename Function::ValueType>& data,
225 for(at[dimnumber-1]=lrange[dimnumber-1]; at[dimnumber-1]<urange[dimnumber-1]; ++at[dimnumber-1])
226 scanLocally<Entity,spaceDim>(fu, fkt,data,ci,lrange,urange,at,dimnumber-1);
230 auto x = getCoord<spaceDim>(at);
231 auto xi = ci.geometry().local(x);
235 int dataInd = getDataIndex(at);
236 data[dataInd] = fu.
value(fkt);
244 std::vector<typename Function::ValueType> data;
265 template<
class Function>
277 scanEdges(fu,nEdgePoints);
284 std::ofstream out(name.c_str());
287 std::cout <<
"Error when opening file!" << std::endl;
290 out <<
"# vtk DataFile Version 2.0" <<std::endl;
291 out <<
"Scanned Data" <<std::endl;
292 out <<
"ASCII" <<std::endl;
293 out <<
"DATASET POLYDATA" << std::endl;
296 for(
int i=0; i<data.size(); ++i)
297 npoints+=data[i].size();
299 out <<
"POINTS " << npoints <<
" float" << std::endl;
300 for(
int i=0; i<data.size(); ++i)
301 for(
int k=0; k<data[i].size(); ++k)
302 out <<
static_cast<float>(data[i][k][0]) <<
" "
303 <<
static_cast<float>(data[i][k][1]) <<
" "
304 <<
static_cast<float>(data[i][k][2]) << std::endl;
305 out <<
"LINES " << data.size() <<
" " << data.size()+npoints << std::endl;
307 for(
int i=0; i<data.size(); ++i)
309 out << data[i].size();
310 for(
int k=0; k<data[i].size();++k)
317 out <<
"POINT_DATA " << npoints << std::endl;
319 out <<
"SCALARS data float 1" << std::endl;
320 out <<
"LOOKUP_TABLE default" << std::endl;
322 for(
int i=0; i<data.size(); ++i)
324 for(
int k=0; k<data[i].size();++k)
325 out <<
static_cast<float>(data[i][k][3]) <<
" ";
333 void scanEdges(
Function const& fu,
int nEdgePoints)
335 typedef typename Function::Space Space;
336 typedef typename Space::Grid Grid;
340 typename Space::Evaluator fkt(fu.space(),&sfCache);
341 typedef typename Space::IndexSet::template Codim<0>::template Partition<Dune::All_Partition>::Iterator CellIterator;
345 for (CellIterator ci=fu.space().indexSet().template begin<0,Dune::All_Partition>();
346 ci!=fu.space().indexSet().template end<0,Dune::All_Partition>(); ++ci)
349 Dune::ReferenceElement<typename Grid::ctype,Grid::dimension>
const&
350 r(Dune::ReferenceElements<typename Grid::ctype,Grid::dimension>::general(ci->type()));
351 for(
int i=0; i < r.size(Grid::dimension-1); ++i)
353 std::vector<Dune::FieldVector<typename Grid::ctype,4> > dcell;
354 for(
int k=0; k<nEdgePoints; k++)
356 onEdge[0]=k*1.0/(nEdgePoints-1);
359 v=ci->geometry().global(v);
362 for(
int j=0; j<Grid::dimension;++j) dt[j]=v[j];
366 data.push_back(dcell);
371 std::vector< std::vector<Dune::FieldVector<typename Function::Space::Grid::ctype,4> > > data;
Function is the interface for evaluatable functions .
static int const components
ValueType value(Cell const &cell, Dune::FieldVector< typename Cell::Geometry::ctype, Cell::dimension > const &localCoordinate) const
Class to scan functions along the edges of a computational grid.
EdgeScanner(Function const &fu, int nEdgePoints)
Scans Function fu along the edges of the computational grid.
void writeVTK(std::string name)
Print data in .vtk (Legacy) format. The extension ".vtk" is automatically appended.
An exception class for file IO errors.
This class caches values and derivatives of shape functions at quadrature points.
typename GridView::template Codim< 0 >::Entity Cell
The type of cells (entities of codimension 0) in the grid view.
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Dune::FieldVector< T, n > min(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise minimum.
LocalCoordinate::field_type checkInside(Dune::GeometryType const >, LocalCoordinate const &x)
Checks whether a point is inside or outside the reference element, and how much.