[Dune] Exporting displacement field to VTK

Simon Praetorius simon.praetorius at tu-dresden.de
Tue Apr 14 10:50:49 CEST 2020


Dear Thomas,


Timo already wrotes, that it is not directly possible to pass this vector. The reason is, that the writer may need to generate additional vertices in the output (e.g. when using subsampling) that are not stored in the vector. Also, the numbering of the vector entries needs to be provided. Is each FieldVector in each BlockVector component a vector-entry on each grid vertex, or does it represent more than that (e.g. for higher-order lagrange elements the data in the additional lagrange nodes)


So, you need to provide an interpretation of your vector to the writer. This interpretation can be in form of the mentioned VTKFunction or an interpretation in the form of a discrete function, associating your vector with a function-space basis. Using dune-functions bases, this is easily possible by creating a `discreteGlobalBasisFunction`:


```c++

using namespace Dune::Functions::BasisFactory;

const int dow = GridView::dimensionworld;

auto basis = makeBasis(gv, power<dow>(lagrange<1>(), blockedInterleaved()));

auto xh = Functions::makeDiscreteGlobalBasisFunction<FieldVector<double,dow>>(basis, x);


Dune::VTKWriter<GridView> vtkWriter(gv);
vtkWriter.addVertexData(xh, "solution", dow);

```


The argument `blockedInterleaved()` tells the basis to sort the entries/indices in a `BlockVector<FieldVector<double,dow>>`-like fashion. Typically, if you work with dune-functions, the basis is already created and associated to your solution vector. So, you just need to create your discrete function and pass it to the VTKWriter.


I hope, there are no typos in the code above. See also the examples in the dune-functions code base, e.g. the stokes-example that also writes vector data to a vtu file.


Best,
Simon


Dr. Simon Praetorius
Institut für Wissenschaftliches Rechnen
Fakultät Mathematik
Technische Universität Dresden
Tel.: TUD-34432
Mail: simon.praetorius at tu-dresden.de<mailto:simon.praetorius at tu-dresden.de>
Web: www.math.tu-dresden.de/~spraetor<http://www.math.tu-dresden.de/~spraetor>
________________________________
Von: Dune <dune-bounces at lists.dune-project.org> im Auftrag von Timo Koch <timo.koch at iws.uni-stuttgart.de>
Gesendet: Dienstag, 14. April 2020 10:36
An: dune at lists.dune-project.org
Betreff: Re: [Dune] Exporting displacement field to VTK

Dear Thomas,

AFAIK the default implementation expects a flat vector, i.e. the entries can’t be blocked into a FieldVector<double,3>.

You can pass a custom VTKFunction instead that knows how to handle the nested type.
For example there is a possible implementation in Dumux (https://git.iws.uni-stuttgart.de/dumux-repositories/dumux/-/blob/master/dumux/io/vtkfunction.hh)
I don’t know if that’s too complicated for your needs.

There might be a solution with dune-functions. I’m not sure...

Best wishes,
Timo

--
_________________________________________________

Timo Koch                                      phone: +49 711 685 64676
IWS, Universität Stuttgart                  fax:   +49 711 685 60430
Pfaffenwaldring 61         email: timo.koch at iws.uni-stuttgart.de<mailto:timo.koch at iws.uni-stuttgart.de>
D-70569 Stuttgart             url: www.iws.uni-stuttgart.de/en/lh2/<http://www.iws.uni-stuttgart.de/en/lh2/>
_________________________________________________

On 14. Apr 2020, at 10:14, HELFER Thomas 202608 <thomas.helfer at cea.fr<mailto:thomas.helfer at cea.fr>> wrote:

Dear all,

I have written a small elastic example. However, I wish to export my displacement field to VTK,
However, the following call to `addVertexData` fails (error message below):

Dune::VTKWriter<GridView> vtkWriter(gv);
vtkWriter.addVertexData(x, "solution", 3);

where x is an instance of Dune::BlockVector<Dune::FieldVector<double, dime>>. The third parameter
of the method is probably not relevant here.

I would be grateful if someone could tell what I missed.

Regards,

Thomas Helfer

[ 75%] Building CXX object src/CMakeFiles/dune-mgis-elasticity-test.dir/dune-mgis-elasticity-test.cc.o
In file included from /home/th202608/codes/dune/2.7/install/include/dune/grid/io/file/vtk/vtkwriter.hh:29,
                from /home/th202608/codes/dune/2.7/tests/dune-mgis/src/dune-mgis-elasticity-test.cc:24<http://dune-mgis-elasticity-test.cc:24>:
/home/th202608/codes/dune/2.7/install/include/dune/grid/io/file/vtk/function.hh: In instantiation of 'double Dune::P1VTKFunction<GV, V>::evaluate(int, const Entity&, const Dune::FieldVector<typename Dune::VTKFunction<GV>::ctype, #'using_decl' not supported by dump_expr#<expression error> >&) const [with GV = Dune::GridView<Dune::DefaultLeafGridViewTraits<const Dune::YaspGrid<3> > >; V = Dune::BlockVector<Dune::FieldVector<double, 3> >; Dune::P1VTKFunction<GV, V>::Entity = Dune::Entity<0, 3, const Dune::YaspGrid<3>, Dune::YaspEntity>; Dune::P1VTKFunction<GV, V>::Base = Dune::VTKFunction<Dune::GridView<Dune::DefaultLeafGridViewTraits<const Dune::YaspGrid<3> > > >; typename Dune::VTKFunction<GV>::ctype = double]':
/home/th202608/codes/dune/2.7/install/include/dune/grid/io/file/vtk/function.hh:235:12:   required from here
/home/th202608/codes/dune/2.7/install/include/dune/grid/io/file/vtk/function.hh:243:25: error: use of deleted function 'Dune::FieldVector<K, 1>& Dune::FieldVector<K, 1>::operator=(const Dune::FieldVector<T, N>&) [with T = double; int N = 3; K = double]'
 243 |         cornerValues[i] = v[mapper.subIndex(e,i,dim)*ncomps_+mycomp_];
     |         ~~~~~~~~~~~~~~~~^~~~
In file included from /home/th202608/codes/dune/2.7/install/include/dune/grid/common/grid.hh:15,
                from /home/th202608/codes/dune/2.7/install/include/dune/grid/yaspgrid.hh:20,
                from /home/th202608/codes/dune/2.7/tests/dune-mgis/src/dune-mgis-elasticity-test.cc:14<http://dune-mgis-elasticity-test.cc:14>:
/home/th202608/codes/dune/2.7/install/include/dune/common/fvector.hh:352:18: note: declared here
 352 |     FieldVector& operator=(const FieldVector<T, N>&) = delete;

_______________________________________________
Dune mailing list
Dune at lists.dune-project.org<mailto:Dune at lists.dune-project.org>
https://lists.dune-project.org/mailman/listinfo/dune

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20200414/04dacf1f/attachment.htm>


More information about the Dune mailing list