Welcome to the Bug Tracking System for the DUNE project.
Due to increasing spam attacks, we had to disable the feature of anonymous bug reports. You will have to register before you are able to report a new bug.
In case you experience any problems, let us know at http://www.dune-project.org/mailinglists.html .
| Tasklist |

FS#658 - Cannot get GeometryGrid with DiscreteCoordFunction to work

Attached to Project: Dune
Opened by Oliver Sander (sander) - Wednesday, 11 November 2009, 16:23 GMT+2
Last edited by Martin Nolte (nolte) - Wednesday, 21 April 2010, 08:26 GMT+2
Task Type Bug Report
Category Dune Core Modules → Grid
Status New
Assigned To No-one
Operating System Unspecified / All
Severity Low
Priority Normal
Reported Version 1.2
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No

Details

I am not sure whether this is a bug or whether I am not understanding the GeometryGrid documentation right.
I am trying to deform a grid with a vector given the new position for each vertex. In the documentation it says that the deformation function must derive from either AnalyticalCoordFunction or from DiscreteCoordFunction. Well, my function is not analytic, so I try the second one. No example code is given but I try my best and produce the following deformation function

template <class GridView>
class DeformationFunction
: public Dune :: DiscreteCoordFunction< double, dim, DeformationFunction<GridView> >
{
typedef DeformationFunction<GridView> This;
typedef Dune :: DiscreteCoordFunction< double, dim, This > Base;

public:

DeformationFunction(const GridView& gridView,
const double* deformedPosition)
: gridView_(gridView),
deformedPosition_(deformedPosition)
{}

template< class HostEntity >
void evaluate ( const HostEntity &hostEntity, unsigned int corner,
Dune::FieldVector<double,dim> &y ) const
{

const typename GridView::IndexSet& indexSet = gridView_.indexSet();

int idx = indexSet.subIndex(hostEntity, corner,dim);

for (int i=0; i<dim; i++)
y[i] = deformedPosition_[idx*dim + i];
}

private:

GridView gridView_;

const double* deformedPosition_;

};


Unfortunately, the code won't compile if I ask for a vertex position directly

std::cout << deformedGrid.leafbegin<dim>()->geometry().corner(0);

because then HostEntity apparently is a Codim<dim> entity for which subIndex is not declared. On the other hand, if I only query elements I can compile this, and the 'corner' parameter really takes on different values. That means the 'corner' parameter is not superfluous and I cannot use 'index' instead of 'subIndex'. I tried to read and understand the code, but it is completely undocumented...

Full testcase attached, thank you for your help.
This task depends upon

Comment by Oliver Sander (sander) - Wednesday, 11 November 2009, 16:27 GMT+2
I have spend a bit of time with the dune-grid -> modules -> GeometryGrid documentation. It has been helpful, but the section on 'Usage' is completely incomprehensible.
Comment by Oliver Sander (sander) - Wednesday, 11 November 2009, 16:31 GMT+2
... whoops, wrong button. I was going to finish with a friendly 'could you please reformulate it a bit to make it more readable?'

Thanks,
Oliver
Comment by Martin Nolte (nolte) - Wednesday, 11 November 2009, 16:39 GMT+2
First of all, you're probably right that the documentation should be improved by 2 simple examples and I'll try to come up with them as soon as possible...

As to your problem: You're completely right, the subIndex method is what you intend, yet it cannot be called for arbitrary entities. There are 2 workarounds that I know of:
a) Use AlbertaGrid as host grid (it supports the method subIndex for all codimension entities -- if I didn't forget to commit this).
b) Try using YaspGrid or UGGrid (they only provide elements and vertices) and specialize the method for the 2 types of entities that might appear.

Actually this problem is what I meant when I asked for the extended subIndex method on the December 2008 developer meeting in Heidelberg.

You can also take a look at the CachedCoordFunction (which wraps an analytical function into a discrete one by caching the corner values).

I hope this helps you understand a bit better. As I said, demo implementations will follow as soon as possible.

Yours,

Martin

I hope this helps you understand the possibilities a bit better.
Comment by Oliver Sander (sander) - Wednesday, 11 November 2009, 16:45 GMT+2
Hi Martin!
Thanks for the quick reply. I know that a) is no use, because my actual code uses Alberta. I just switched to SGrid for a concise test case. The problem is that you need to go through the interface class, which has subIndex only for codim==0. b) specializing sounds more feasible. I am only using vertices and elements anyways.

An example for CachedCoordFunction would be highly appreciated to, even though it will not help in my current problem (my deformation really is vertex-based).
Comment by Martin Nolte (nolte) - Wednesday, 11 November 2009, 17:16 GMT+2
Hi Oli,

I still have a question: how do store vertex data on an index set, anyway? As far as I see it, you need to index the entire hierarchy. So, if you are using AlbertaGrid and want a simple fix for this problem, use the hierarchic index set (I know it is not standard, but it does both, support your method -- no interface in the way -- and indexes the entire hierarchy). Some holes should not be your problem :-). At least, this is how the CacheCoordFunction does it.

Note: Using level indices for all levels on an AlbertaGrid is currently not a good idea (you will store a vector of the size of the hierarchic index set for each level).

By the way, using IdSets won't help either, since the subId-method you'd need is missing, too (even in AlbertaGrid). To be honest, I don't even know how to write a good example without restricting myself to AlbertaGrid due to this problem.

Do we need to discuss this on the meeting in November? Or can we simply agree that the "extended" sudIndex / subId methods are added to the interface?

Martin
Comment by Martin Nolte (nolte) - Wednesday, 21 April 2010, 08:26 GMT+2
Since noone seems interested at the moment, I will lower severity.
Comment by Martin Nolte (nolte) - Wednesday, 21 April 2010, 08:45 GMT+2
Alberta now also supports the subId method for arbitrary entities, i.e.,

template< int codim >
subId( Codim< codim >::Entity &e, int i, unsigned int subcodim ) const;

Currently, it is not tunnelled through the interface, though.
Comment by Martin Nolte (nolte) - Wednesday, 21 April 2010, 09:28 GMT+2
I provided a patch that adds the subIndex / subId method for arbitrary entities to the interface. So we can do some more testing...

Loading...