<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none"><!--P{margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr" style="font-size:12pt;color:#000000;background-color:#FFFFFF;font-family:Calibri,Arial,Helvetica,sans-serif;">
<p>Dear Thomas,</p>
<p><br>
</p>
<p>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)</p>
<p><br>
</p>
<p>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`:</p>
<p><br>
</p>
<p>```c++</p>
<p>using namespace Dune::Functions::BasisFactory;</p>
<p>const int dow = GridView::dimensionworld;<br>
</p>
<p>auto basis = makeBasis(gv, power<dow>(lagrange<1>(), blockedInterleaved()));</p>
<p>auto xh = Functions::makeDiscreteGlobalBasisFunction<FieldVector<double,dow>>(basis, x);</p>
<p><br>
</p>
<p>Dune::VTKWriter<GridView> vtkWriter(gv);<br class="">
vtkWriter.addVertexData(xh, "solution", dow);<br>
</p>
<p>```<br>
</p>
<p><br>
</p>
<p>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.</p>
<p><br>
</p>
<p>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.</p>
<p><br>
</p>
<p>Best,<br>
Simon<br>
</p>
<p><br>
</p>
<div id="Signature">
<div name="divtagdefaultwrapper" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
Dr. Simon Praetorius <br>
Institut für Wissenschaftliches Rechnen <br>
Fakultät Mathematik <br>
Technische Universität Dresden <br>
Tel.: TUD-34432 <br>
Mail: <a class="moz-txt-link-abbreviated" href="mailto:simon.praetorius@tu-dresden.de" id="NoLP">
simon.praetorius@tu-dresden.de</a><br>
Web: <a class="moz-txt-link-abbreviated" href="http://www.math.tu-dresden.de/~spraetor" id="NoLP">
www.math.tu-dresden.de/~spraetor</a></div>
</div>
<div style="word-wrap:break-word; line-break:after-white-space">
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>Von:</b> Dune <dune-bounces@lists.dune-project.org> im Auftrag von Timo Koch <timo.koch@iws.uni-stuttgart.de><br>
<b>Gesendet:</b> Dienstag, 14. April 2020 10:36<br>
<b>An:</b> dune@lists.dune-project.org<br>
<b>Betreff:</b> Re: [Dune] Exporting displacement field to VTK</font>
<div> </div>
</div>
<div>Dear Thomas,
<div class=""><br class="">
</div>
<div class="">AFAIK the default implementation expects a flat vector, i.e. the entries can’t be blocked into a FieldVector<double,3>.</div>
<div class=""><br class="">
</div>
<div class="">You can pass a custom VTKFunction instead that knows how to handle the nested type.</div>
<div class="">For example there is a possible implementation in Dumux (<a href="https://git.iws.uni-stuttgart.de/dumux-repositories/dumux/-/blob/master/dumux/io/vtkfunction.hh" class="">https://git.iws.uni-stuttgart.de/dumux-repositories/dumux/-/blob/master/dumux/io/vtkfunction.hh</a>)</div>
<div class="">I don’t know if that’s too complicated for your needs.</div>
<div class=""><br class="">
</div>
<div class="">There might be a solution with dune-functions. I’m not sure...</div>
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class="">Timo</div>
<div class=""><br class="">
<div class="">
<div style="color:rgb(0,0,0); font-family:Helvetica; font-size:12px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; text-decoration:none">
-- <br class="">
_________________________________________________</div>
<div style="color:rgb(0,0,0); font-family:Helvetica; font-size:12px; font-style:normal; font-weight:normal; letter-spacing:normal; orphans:auto; text-align:start; text-indent:0px; text-transform:none; white-space:normal; widows:auto; word-spacing:0px; text-decoration:none">
<br class="">
Timo Koch phone: +49 711 685 64676<br class="">
IWS, Universität Stuttgart fax: +49 711 685 60430<br class="">
Pfaffenwaldring 61 <a href="mailto:timo.koch@iws.uni-stuttgart.de" class="">
email: timo.koch@iws.uni-stuttgart.de</a><br class="">
D-70569 Stuttgart url: <a href="http://www.iws.uni-stuttgart.de/en/lh2/" class="">www.iws.uni-stuttgart.de/en/lh2/</a><br class="">
_________________________________________________</div>
</div>
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 14. Apr 2020, at 10:14, HELFER Thomas 202608 <<a href="mailto:thomas.helfer@cea.fr" class="">thomas.helfer@cea.fr</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">Dear all,<br class="">
<br class="">
I have written a small elastic example. However, I wish to export my displacement field to VTK,
<br class="">
However, the following call to `addVertexData` fails (error message below):<br class="">
<br class="">
Dune::VTKWriter<GridView> vtkWriter(gv);<br class="">
vtkWriter.addVertexData(x, "solution", 3);<br class="">
<br class="">
where x is an instance of Dune::BlockVector<Dune::FieldVector<double, dime>>. The third parameter<br class="">
of the method is probably not relevant here.<br class="">
<br class="">
I would be grateful if someone could tell what I missed.<br class="">
<br class="">
Regards,<br class="">
<br class="">
Thomas Helfer<br class="">
<br class="">
[ 75%] Building CXX object src/CMakeFiles/dune-mgis-elasticity-test.dir/dune-mgis-elasticity-test.cc.o<br class="">
In file included from /home/th202608/codes/dune/2.7/install/include/dune/grid/io/file/vtk/vtkwriter.hh:29,<br class="">
from /home/th202608/codes/dune/2.7/tests/dune-mgis/src/<a href="http://dune-mgis-elasticity-test.cc:24" class="">dune-mgis-elasticity-test.cc:24</a>:<br class="">
/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]':<br class="">
/home/th202608/codes/dune/2.7/install/include/dune/grid/io/file/vtk/function.hh:235:12: required from here<br class="">
/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]'<br class="">
243 | cornerValues[i] = v[mapper.subIndex(e,i,dim)*ncomps_+mycomp_];<br class="">
| ~~~~~~~~~~~~~~~~^~~~<br class="">
In file included from /home/th202608/codes/dune/2.7/install/include/dune/grid/common/grid.hh:15,<br class="">
from /home/th202608/codes/dune/2.7/install/include/dune/grid/yaspgrid.hh:20,<br class="">
from /home/th202608/codes/dune/2.7/tests/dune-mgis/src/<a href="http://dune-mgis-elasticity-test.cc:14" class="">dune-mgis-elasticity-test.cc:14</a>:<br class="">
/home/th202608/codes/dune/2.7/install/include/dune/common/fvector.hh:352:18: note: declared here<br class="">
352 | FieldVector& operator=(const FieldVector<T, N>&) = delete;<br class="">
<br class="">
_______________________________________________<br class="">
Dune mailing list<br class="">
<a href="mailto:Dune@lists.dune-project.org" class="">Dune@lists.dune-project.org</a><br class="">
https://lists.dune-project.org/mailman/listinfo/dune</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</div>
</div>
</body>
</html>