Skip to content

refactor blockvector bindings to allow for generic types

This MR adds the capability to add costum types into a BlockVector with Python bindings.

The new interface let you pass an entry of your type e.g. Dune::FieldVector<double,3>. If you also pass a size, then given type is copied to each entry. I decided to do this in such a way sicne this is the least suprise, if I pass a constructed Dune::FieldVector<double,3> v to the Python constructor BlockVector(v,5), I would expect it to be initialized with the given value v. But I can also remove this behavior.

vec = dune.common.FieldVector([1])
z2 = BlockVector(vec,5) # z2 is populates as ((1.0),(1.0),(1.0),(1.0),(1.0))

Then there is another option to simply passing the block size which mimics the original behavior and runts an object of type Dune::BlockVector<Dune::FieldVector<double,blockSize>>.

z = BlockVector(5,size)

where size is the size of the block vector.

A third variant is the construction of a BlockVector of your given type by string and a list of includes:

includes= ["dune/common/fvector.hh"]
z3 = BlockVector(("Dune::FieldVector<double,1>",includes),5)

which I found also convenient as an option.

There is also a lowercase blockVector function in the Python bindings, which create a Blockvector of a given size with entries Dune::FieldVector<double,1> but there is an optional argument blockSize, which creates entries of type Dune::FieldVector<double,blockSize>.

I dont know the reason for the lowercase function but I tried to not break existing code.

@carsten.graeser @andreas.dedner can you please have a look?

EDIT: Locally the tests passed for me but in the CI somehow the read_only_property two_norm is not available anymore. Somehow the detail::registerOneTensorInterface call is not done in the CI but only for me locally. I don't know the reason for this problem. Maybe someone can give me a hint?

EDIT 2: It also works locally with the environment given by the ci script. If I run the python test locally inside the docker container registry.dune-project.org/docker/ci/debian:11 with the toolchains gcc-9-17 and gcc-9-20 it works. But online it fails.

EDIT 3: I didn't really change anything but now the CI runs through...

Edited by Alexander Müller

Merge request reports

Loading