[Dune] Returning Geometries As Objects
Martin Nolte
nolte at mathematik.uni-freiburg.de
Mon Feb 20 15:29:57 CET 2012
Dear grid implementors,
there is a pitfall when starting to actually return geometries as objects (as
this is, for example, done in IdentityGrid in the dune-grid-dev-howto: One
easily forgets that, for the transition period, the Dune::Geometry facade can
either store a reference or the object. To select the correct behavior, you
have to specialize the "StoreGeometryReference" facade option (and set v = false).
To simplify the first part of the transition, which you will all have gone
through by now, the default value for "StoreGeometryReference" is true, i.e.,
the Dune::Geometry facade stores a reference to the geometry it is passed.
Unfortunately, the compiler does not warn about returning a reference to a
temporary, if you forget to specialize the facade class. This will ususally
lead to unpredictable behavior. Fortunately, in my experience, the grid tests
always fail in this situation with an unpredictable error, e.g., local(
global( x ) ) != x.
I hope, this piece of information helps debugging these realy nasty memory errors.
Best,
Martin
On 02/15/2012 03:03 PM, Carsten Gräser wrote:
> Dear 3rd party grid implementors,
>
> this is a warning about a small pitfall with the
> new geometry behavior in dune-grid:
>
> Even if you want to use (for a transition) the possibility
> to still store references to geometries according to the
> temporary default behavior of the new Geometry interface
> class you have to adapt your grid.
>
> The reason is that until now you had to store a Geometry<GeometryImpl>
> (or maybe a Makeable...<...>) yourself in the Entity. Now you have
> to store only the plain GeometryImpl. Using your old implementation
> you may end up storing a Geometry<GeometryImpl> which itself stores
> a reference to a no longer existing temporary GeometryImpl
>
> You may want to look at the merge commit r7869 as reference for the
> neccessary changes.
>
> The reason for warning about this seemingly obvious fact is,
> that I just realized that an unmodified grid implementation
> might surprisingly still compile and run with the modified grid
> interface.
>
> Best,
> Carsten
>
> _______________________________________________
> 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