[Dune] Understanding grid.getRealImplementation() paradigm

Martin Nolte nolte at mathematik.uni-freiburg.de
Fri Dec 19 17:05:12 CET 2014


Hi Aleksejs,

this is an extremely well-guarded secret ;-). DUNE tries to force users into 
calling the interface methods only. To this end, the implementation of most 
grid objects (like entities) are enclosed in a facade class (like 
Dune::Entity) which simply containts the implementation and forwards all calls 
to it. Thus, only the interface methods are exposed to the user.

As a grid implementor, on the other hand, you want to access the public (or 
private) methods of your implementation. While there are different ideas how 
to gain this access, the method used by GeometryGrid the following. Each 
facade class is a friend of the corresponding GridDefaultImplementation. 
Therefore the method GridDefaultImplementation::getRealImplementation is 
allowed to access the private ethod impl on the facade. As your grid 
implementation is derived from GridDefaultImplementation, it may allow its 
friends (e.g., the index set implementation) to access this method, i.e., 
Grid::getRealImplementation.

If you need to access implementation-dependent methods on, e.g., the entity in 
your user code, there is a second way to the implementation: Configure DUNE 
with --enable-experimental-grid-extensions. This makes the method impl public, 
so you can call it from whereever you like. Unfortunately, this is not a real 
option for a grid developer, unless you want to force your users into using 
the experimental grid extensionsl.

Put in a nutshell: This trickery is necessary to protect our users from 
themselves.

Unfortunately, this trick is DUNE-specific and there is no reference on it in 
the literature. If you happen to know a simpler or more common way to keep 
users out of the implementation, I guess most DUNE developers will be happy to 
hear it. At least all grid developers suffer from this ugly code.

Best,

Martin

PS: We have had the discussion on making the impl method publicly available, 
but a majority of developers seems to like it better this way. Personally, I 
always enable the experimental grid extensions.

On 12/19/2014 03:52 PM, Aleksejs Fomins wrote:
> Dear Dune,
>
> I feel very confused about this feature of the Grid Implementation.
>
> Consider a method geometrygrid->indexsets->index(&entity)
>
> which does the following
>
> return Grid::getRealImplementation( entity ).index( hostIndexSet() );
>
> however, GeometryGrid does not have the method getRealImplementation(),
> except of the one inherited from GridDefaultImplementation. So where is
> the method eventually implemented?
>
> I would also appreciate a link to a book chapter or sth where I could
> read about this paradigm.
>
> Thank you,
> Aleksejs
>
>
>
> _______________________________________________
> Dune mailing list
> Dune at dune-project.org
> http://lists.dune-project.org/mailman/listinfo/dune
>

-- 
Dr. Martin Nolte <nolte at mathematik.uni-freiburg.de>

Universität Freiburg                                   phone: +49-761-203-5630
Abteilung für angewandte Mathematik                    fax:   +49-761-203-5632
Hermann-Herder-Straße 10
79104 Freiburg, Germany




More information about the Dune mailing list