[Dune] question about addCellData

Gregor Corbin corbin at mathematik.uni-kl.de
Mon Feb 12 15:10:01 CET 2018


Hi,

as the error message already indicates, the writer expects a vector of
scalars of size num_cell * n_comp and then assumes that n_comp
consecutive vector elements belong to one cell.  I think you first need
to produce a "flat" vector of your data, like this:

n_comp = GridType::dimensionworld;

N = num_cell *ncomp ;

std::vector<double> velocity_flat(N);

for (size_t idx = 0; idx < num_cell; ++idx)

    for (size_t k = 0; k < n_comp; ++k)

        velocity_flat[idx*n_comp+k] = velocity[idx][k];


Then pass this to your VTK writer like this:

vtkwriter.addCellData(velocity_flat,"velocity",n_comp);

Not the most elegant version, but it works.

As an alternative, if you have PDELab, you could make a GridFunction
from your data and pass a pointer to the gridfunction too
addCellData.For this, you need to derive your function from
GridFunctionBase<...> and implement the memeber function

void evaluate(const Cell& c, const Dune::FieldVector<RF,dimension>&
xlocal, Dune::FieldVector<RF,n_comp>& y)

that evaluates your function at cell c, local coordinate xlocal and puts
the result into y.


Disclaimer: I am not a Dune developer, merely a user. So take everything
I say here with a grain of salt.

Regards,

Gregor Corbin

Am 12.02.2018 um 14:15 schrieb Ponomarev, Ilya:
> Good afternoon.
>
> I have structure
> std::vector<Dune::FieldVector<double ,GridType::dimensionworld>>
> velocity(num_cell);;
> num_cell is number of cells in my grid from the size of
> Dune::LeafMultipleCodimMultipleGeomTypeMapper<GridType,Dune::MCMGElementLayout>
> object.
> I store 3 components of speed in my structure.
>
> But I didn't catch, how I can visualize my speed with addCellData in
> object of Dune::VTKSequenceWriter class. Simple structure, like
> temperature or concentration, are visualized correctly, but structure
> with several components - not.
> I got an error:
>
> dune-grid/dune/grid/io/file/vtk/function.hh:123:47: error: cannot
> convert ‘const value_type {aka const Dune::FieldVector<double, 3>}’ to
> ‘double’ in return
>        return v[mapper.index(e)*ncomps_+mycomp_];
>
> Could you explain me, please, how that problem can be solved? 
>
> Best regards,
> Ilya Ponomarev.
>
>
> _______________________________________________
> Dune mailing list
> Dune at lists.dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20180212/4bea78e7/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x0686D386.asc
Type: application/pgp-keys
Size: 3116 bytes
Desc: not available
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20180212/4bea78e7/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20180212/4bea78e7/attachment.sig>


More information about the Dune mailing list