← Back to team overview

dolfin team mailing list archive

Re: MeshFunction::get(..)

 

On Thu, Oct 08, 2009 at 02:00:02PM +0200, Johan Hake wrote:
> On Thursday 08 October 2009 13:56:38 Anders Logg wrote:
> > On Thu, Oct 08, 2009 at 01:22:23PM +0200, Johan Hake wrote:
> > > On Tuesday 29 September 2009 15:15:12 Anders Logg wrote:
> > > > On Tue, Sep 29, 2009 at 03:07:33PM +0200, Johan Hake wrote:
> > > > > On Tuesday 29 September 2009 14:06:20 Garth N. Wells wrote:
> > > > > > Anders Logg wrote:
> > > > > > > On Tue, Sep 29, 2009 at 01:01:35PM +0100, Garth N. Wells wrote:
> > > > > > >> Anders Logg wrote:
> > > > > > >>> On Tue, Sep 29, 2009 at 12:42:54PM +0100, Garth N. Wells wrote:
> > > > > > >>>> Anders Logg wrote:
> > > > > > >>>>> On Tue, Sep 29, 2009 at 07:39:01AM +0100, Garth N. Wells
> wrote:
> > > > > > >>>>>> Is there a reason why the MeshFunction.get(..) functions
> > > > > > >>>>>> return by value rather then reference, e.g. it is currently
> > > > > > >>>>>>
> > > > > > >>>>>>      inline T get(const MeshEntity& entity) const
> > > > > > >>>>>>
> > > > > > >>>>>> rather than
> > > > > > >>>>>>
> > > > > > >>>>>>      inline T& get(const MeshEntity& entity) const
> > > > > > >>>>>>
> > > > > > >>>>>> Garth
> > > > > > >>>>>
> > > > > > >>>>> Yes, we have a set() function for setting the values.
> > > > > > >>>>
> > > > > > >>>> I know, but I would like to get a reference rather than
> > > > > > >>>> copying data
> > > > > > >>>>
> > > > > > >>>>     unsigned int index = 3;
> > > > > > >>>>     const std::vector<double>& vec =  mesh_function.get(index)
> > > > > > >>>>
> > > > > > >>>> I can do this when I have the MeshEntitiy, but not when using
> > > > > > >>>> the index.
> > > > > > >>>
> > > > > > >>> Does it work if you do
> > > > > > >>>
> > > > > > >>>   &vec[0] = mesh_function.values();
> > > > > > >>
> > > > > > >> Probably, bit it's not what I want. I have a std::vector
> > > > > > >> attached to mesh entities (MeshFunction<std::vector<double> >).
> > > > > > >> I want a reference to the std::vector attached to a particular
> > > > > > >> entity
> > > > > > >>
> > > > > > >>    std::vector<double> vec& =  mesh_function(my_entity);
> > > > > > >>
> > > > > > >> is fine, but
> > > > > > >>
> > > > > > >>    std::vector<double> vec& =  mesh_function.get(my_index);
> > > > > > >>
> > > > > > >> is not.
> > > > > > >
> > > > > > > What if you just add operator[] for uint?
> > > > > > >
> > > > > > >> Back to my question: Is there a reason why MeshFunction::get
> > > > > > >> returns by value and not by reference?
> > > > > > >
> > > > > > > There might be a reason. I think we introduced get/set for use in
> > > > > > > the Python interface. Perhaps Johan remembers?
> > > > >
> > > > > Well, this was before my time ;)
> > > > >
> > > > > But I see that get is used to overload the __call__ method in Python.
> > > > > I am quite sure this can be done in a nicer way. We probably had
> > > > > difficulties with extending the MeshFunctions as these are templated
> > > > > classes. We know how to do this now.
> > > > >
> > > > > I am not sure why we return by value, but it might have something to
> > > > > do with memory management in Python. However these things could be
> > > > > handled in the wrapper layer anyway.
> > > > >
> > > > > I suggest we define the C++ interface as we want it to be, then I am
> > > > > quite sure I can mimic this in Python. (starting to get bald I think
> > > > > ;))
> > > > >
> > > > > So whats the logic here. Should
> > > > >
> > > > >   &T operator()
> > > > >
> > > > > be used when we have the entity, and maybe
> > > > >
> > > > >   &T operator[]
> > > > >
> > > > > when we have the index, or should one of the operators be used for
> > > > > both cases?
> > > >
> > > > I think it would be safe to overload operator[].
> > >
> > > Do we still want to make this transition? I have started it but it
> > > requires quite a lot of changes...
> > >
> > > Johan
> >
> > I guess it would be nice to have. Why does it require many changes?
> > It's just adding a new function (at least in C++).
>
> Already done, but mf->get is used quite a lot in the library. This is a really
> no brainer, I just wanted to be sure.

ok, that's "easy" to fix. So just go ahead.

--
Anders

Attachment: signature.asc
Description: Digital signature


References