Function evaluation in a cell

Asked by Allan Leal

Hello,

I want to evaluate an instance of a Function class inside a cell. The documentation shows the following overloads for the Function.eval method:

eval(values, x)
eval(values, x, dolfin_cell, ufc_cell)

The dolfin_cell can be easily determined from a mesh by doing:

dolfin_cell = Cell(mesh, index_cell)

But I have no idea of how to get an instance of the ufc::cell class so that I can cell-evaluate the function.

Thanks in advance.

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Garth Wells (garth-wells) said :
#1

On 13 January 2012 16:00, Allan Leal
<email address hidden> wrote:
> New question #184620 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Hello,
>
> I want to evaluate an instance of a Function class inside a cell. The documentation shows the following overloads for the Function.eval method:
>
> eval(values, x)
> eval(values, x, dolfin_cell, ufc_cell)
>
> The dolfin_cell can be easily determined from a mesh by doing:
>
> dolfin_cell = Cell(mesh, index_cell)
>
> But I have no idea of how to get an instance of the ufc::cell class so that I can cell-evaluate the function.
>

It may not be exposed in the Python interface yet, but UFCCell is a
sub-class of ufc::cell:

    dolfin_cell = Cell(mesh, index_cell)
    ufc_cell = UFCCell(dolfin_cell)

If UFCCell is not exposed, we can add it easily.

If you're inside a loop, it it possible to update the UFCCell object
rather than re-creating it.

Garth

> Thanks in advance.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Mikael Mortensen (mikael-mortensen) said :
#2

You can do

import ufc
ufccell = ufc.cell()

I use it in a probe class that computes eval efficiently when it needs to
be recomputed several times for the same cell. See Probe.py in folder
cbc/cfd/tools of the CBC.PDESys project in launchpad.

Mikael

On Friday, 13 January 2012, Garth Wells <
<email address hidden>> wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Status: Open => Answered
>
> Garth Wells proposed the following answer:
> On 13 January 2012 16:00, Allan Leal
> <email address hidden> wrote:
>> New question #184620 on DOLFIN:
>> https://answers.launchpad.net/dolfin/+question/184620
>>
>> Hello,
>>
>> I want to evaluate an instance of a Function class inside a cell. The
documentation shows the following overloads for the Function.eval method:
>>
>> eval(values, x)
>> eval(values, x, dolfin_cell, ufc_cell)
>>
>> The dolfin_cell can be easily determined from a mesh by doing:
>>
>> dolfin_cell = Cell(mesh, index_cell)
>>
>> But I have no idea of how to get an instance of the ufc::cell class so
that I can cell-evaluate the function.
>>
>
> It may not be exposed in the Python interface yet, but UFCCell is a
> sub-class of ufc::cell:
>
> dolfin_cell = Cell(mesh, index_cell)
> ufc_cell = UFCCell(dolfin_cell)
>
> If UFCCell is not exposed, we can add it easily.
>
> If you're inside a loop, it it possible to update the UFCCell object
> rather than re-creating it.
>
> Garth
>
>> Thanks in advance.
>>
>> --
>> You received this question notification because you are a member of
>> DOLFIN Team, which is an answer contact for DOLFIN.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Revision history for this message
Allan Leal (allanleal) said :
#3

@Garth

UFCCell is not define in my FEniCS installation. How can I add it?

@ Mikael

The function ufc.cell accepts no argument (except self), so how does it work? I could not manage to get the following code working:

from dolfin import *
from numpy import *
import ufc

mesh = UnitSquare(1,1)
DG1 = FunctionSpace(mesh, 'DG', 1)

u = Function(DG1)
...
dolfin_cell = Cell(mesh, 0)
ufc_cell = ufc.cell() # empty ufc::cell???

u.eval(values, x, dolfin_cell, ufc_cell)

Revision history for this message
Allan Leal (allanleal) said :
#4

@ Garth,

I could find dolfin/fem/UFCCell.h

Are there plans to generate a python wrapper for this class? Is there an alternative for solving my problem?

I need to evaluate the function in a cell, because the function space is DG and the evaluations are on the edges (where u is discontinuous).

Revision history for this message
Johan Hake (johan-hake) said :
#5

On Friday January 13 2012 20:05:52 Allan Leal wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Allan Leal gave more information on the question:
> @ Garth,
>
> I could find dolfin/fem/UFCCell.h
>
> Are there plans to generate a python wrapper for this class?

It should be pretty easy to expose. I can add it to trunk, not the 1.0 branch,
but at the moment I do not have a buildbot up and running with trunk so I
cannot test any changes...

I have added Blueprint for this:

  https://blueprints.launchpad.net/dolfin/+spec/expose-ufccell-to-python

> Is there an alternative for solving my problem?

Not sure.

Johan

> I need to evaluate the function in a cell, because the function space is
> DG and the evaluations are on the edges (where u is discontinuous).

Revision history for this message
Mikael Mortensen (mikael-mortensen) said :
#6

On 13 January 2012 19:41, Allan Leal <email address hidden>
wrote:
>
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Status: Answered => Open
>
> Allan Leal is still having a problem:
> @Garth
>
> UFCCell is not define in my FEniCS installation. How can I add it?
>
> @ Mikael
>
> The function ufc.cell accepts no argument (except self), so how does it
> work? I could not manage to get the following code working:
>
> from dolfin import *
> from numpy import *
> import ufc
>
> mesh = UnitSquare(1,1)
> DG1 = FunctionSpace(mesh, 'DG', 1)
>
> u = Function(DG1)
> ...
> dolfin_cell = Cell(mesh, 0)
> ufc_cell = ufc.cell() # empty ufc::cell???
>
> u.eval(values, x, dolfin_cell, ufc_cell)

It seems like this crashes in element.evaluate_basis inside eval. Perhaps
you need to submit a bug report on this? Or wait for the UFCCell wrap?

You can set the index of the ufc_cell like ufc_cell.index = 0, but I think
you also need to set the ufc_cell.mesh_identifier to mesh.id() to get past
line 432 in UFCCell.h. I noticed that it actually works if I change the
last argument of element.evaluate_basis in eval (line 384) from

element.evaluate_basis(i, &basis[0], &x[0], ufc_cell);

to

element.evaluate_basis(i, &basis[0], &x[0], dolfin_cell);

I guess i have to dig deeper when i can find the time. Anybody else know
why? Other functions like restrict work with the ufc_cell argument.

M

>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Allan Leal (allanleal) said :
#7

Why not hide the requirement of a ufc::cell instance from Dolfin users?

If a UFCCell object can be instantiated from a Cell, e.g.,:

    dolfin_cell = Cell(mesh, index_cell)
    ufc_cell = UFCCell(dolfin_cell)

then why the interface of Function.eval isn't as follows:

    eval(values, x, dolfin_cell) ?

Also, why not provide the following interface:

     values = eval(x, dolfin_cell) ?

Is there a better place to suggest this?

Revision history for this message
Anders Logg (logg) said :
#8

On Sat, Jan 14, 2012 at 04:10:56PM -0000, Allan Leal wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Allan Leal posted a new comment:
> Why not hide the requirement of a ufc::cell instance from Dolfin users?
>
> If a UFCCell object can be instantiated from a Cell, e.g.,:
>
> dolfin_cell = Cell(mesh, index_cell)
> ufc_cell = UFCCell(dolfin_cell)
>
> then why the interface of Function.eval isn't as follows:
>
> eval(values, x, dolfin_cell) ?

I think we should add this. A user should not need to create a
UFCCell.

> Also, why not provide the following interface:
>
> values = eval(x, dolfin_cell) ?
>
> Is there a better place to suggest this?

The mailing list.

--
Anders

Revision history for this message
Garth Wells (garth-wells) said :
#9

On 15 January 2012 00:45, Anders Logg
<email address hidden> wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Anders Logg proposed the following answer:
> On Sat, Jan 14, 2012 at 04:10:56PM -0000, Allan Leal wrote:
>> Question #184620 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/184620
>>
>> Allan Leal posted a new comment:
>> Why not hide the requirement of a ufc::cell instance from Dolfin users?
>>
>> If a UFCCell object can be instantiated from a Cell, e.g.,:
>>
>>     dolfin_cell = Cell(mesh, index_cell)
>>     ufc_cell = UFCCell(dolfin_cell)
>>
>> then why the interface of Function.eval isn't as follows:
>>
>>     eval(values, x, dolfin_cell) ?
>
> I think we should add this. A user should not need to create a
> UFCCell.
>

I'm not convinced.

Creating a UFCCell (which is necessary to support UFC) is expensive
in that it allocates memory. By supplying an interface which does not
require a a UFCCell but does create one in the background hides an
expensive operation for repeated calls. The functionality in question
is rather low-level, which is why I'm not fussed if a user takes
control of creating (and updating) the UFCCell.

Garth

>> Also, why not provide the following interface:
>>
>>      values = eval(x, dolfin_cell) ?
>>
>> Is there a better place to suggest this?
>
> The mailing list.
>
> --
> Anders
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Allan Leal (allanleal) said :
#10

Reading the definition of UFCCell, it indeed has some memory allocations. So, the following code is more efficient:

ufc_cell = UFCCell(Cell(mesh, 0))

for cell_id in range(num_cells):
    dolfin_cell = Cell(mesh, cell_id)
    ufc_cell.update(dolfin_cell)
    ....
    u.eval(values, x, dolfin_cell, ufc_cell)

A solution to the problem Garth pointed out would be the encapsulation of this creation and update by defining a new class (e.g., FunctionCell) that stores internally a ufc_cell:

class FunctionCell:
    def __init__(mesh, u):
        self.u = u
        self.mesh = mesh
        self.ufc_cell = UFCCell(Cell(mesh, 0))
        ....
    def __call__(x, cell_id, values=None):
        dolfin_cell = Cell(self.mesh, cell_id)
        self.ufc_cell.update(dolfin_cell)
        ...
        if values == None:
             # then, allocate memory for 'values'
        ...
        self.u.eval(values, x, dolfin_cell, self.ufc_cell)
        return values

Now, FunctionCell is an adequate and efficient function for evaluation inside cells. An example of its use would be:

u = Function(U)
ucell = FunctionCell(mesh, u)
for cell_id in range(num_cells):
     x = # a point inside the current cell
     val = ucell(x, cell_id)

I think Dolfin should provide clean and intuitive interfaces as much as possible. This is one of its differentials with respect to other FEM/CFD libraries. The above approach seems to hide some details that the user does not need to know.

Allan

Revision history for this message
Johan Hake (johan-hake) said :
#11

On Saturday January 14 2012 11:30:54 Mikael Mortensen wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Mikael Mortensen proposed the following answer:
> On 13 January 2012 19:41, Allan Leal <email address hidden>
>
> wrote:
> > Question #184620 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/184620
> >
> > Status: Answered => Open
> >
> > Allan Leal is still having a problem:
> > @Garth
> >
> > UFCCell is not define in my FEniCS installation. How can I add it?
> >
> > @ Mikael
> >
> > The function ufc.cell accepts no argument (except self), so how does it
> > work? I could not manage to get the following code working:
> >
> > from dolfin import *
> > from numpy import *
> > import ufc
> >
> > mesh = UnitSquare(1,1)
> > DG1 = FunctionSpace(mesh, 'DG', 1)
> >
> > u = Function(DG1)
> > ...
> > dolfin_cell = Cell(mesh, 0)
> > ufc_cell = ufc.cell() # empty ufc::cell???
> >
> > u.eval(values, x, dolfin_cell, ufc_cell)
>
> It seems like this crashes in element.evaluate_basis inside eval. Perhaps
> you need to submit a bug report on this? Or wait for the UFCCell wrap?

ufc.cell should not be instantiated by itself. There are no memory allocated
for in particular entity_indices and coordinates. One should not instantiate
ufc.cell from Python.

> You can set the index of the ufc_cell like ufc_cell.index = 0, but I think
> you also need to set the ufc_cell.mesh_identifier to mesh.id() to get past
> line 432 in UFCCell.h. I noticed that it actually works if I change the
> last argument of element.evaluate_basis in eval (line 384) from
>
> element.evaluate_basis(i, &basis[0], &x[0], ufc_cell);
>
> to
>
> element.evaluate_basis(i, &basis[0], &x[0], dolfin_cell);
>
> I guess i have to dig deeper when i can find the time. Anybody else know
> why? Other functions like restrict work with the ufc_cell argument.

Is that by pure luck?

Johan

> M
>
> > --
> > You received this question notification because you are a member of
> > DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Anders Logg (logg) said :
#12

On Sun, Jan 15, 2012 at 10:10:59AM -0000, Garth Wells wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Garth Wells proposed the following answer:
> On 15 January 2012 00:45, Anders Logg
> <email address hidden> wrote:
> > Question #184620 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/184620
> >
> > Anders Logg proposed the following answer:
> > On Sat, Jan 14, 2012 at 04:10:56PM -0000, Allan Leal wrote:
> >> Question #184620 on DOLFIN changed:
> >> https://answers.launchpad.net/dolfin/+question/184620
> >>
> >> Allan Leal posted a new comment:
> >> Why not hide the requirement of a ufc::cell instance from Dolfin users?
> >>
> >> If a UFCCell object can be instantiated from a Cell, e.g.,:
> >>
> >>     dolfin_cell = Cell(mesh, index_cell)
> >>     ufc_cell = UFCCell(dolfin_cell)
> >>
> >> then why the interface of Function.eval isn't as follows:
> >>
> >>     eval(values, x, dolfin_cell) ?
> >
> > I think we should add this. A user should not need to create a
> > UFCCell.
> >
>
> I'm not convinced.
>
> Creating a UFCCell (which is necessary to support UFC) is expensive
> in that it allocates memory. By supplying an interface which does not
> require a a UFCCell but does create one in the background hides an
> expensive operation for repeated calls. The functionality in question
> is rather low-level, which is why I'm not fussed if a user takes
> control of creating (and updating) the UFCCell.

This is for the Python interface so it might actually be the case that
a dolfin::Cell interface is more efficient than a UFCCell interface,
since it would involve creating the UFCCell wrapper in Python, instead
of an extra Python call to update the UFCCell data.

Anyway, since this will be accessed from a loop in Python, I don't
think the efficiency is much of an issue. Having a dolfin::Cell
interface would be much more convenient.

--
Anders

> Garth
>
>
> >> Also, why not provide the following interface:
> >>
> >>      values = eval(x, dolfin_cell) ?
> >>
> >> Is there a better place to suggest this?
> >
> > The mailing list.
> >
> >
>

Revision history for this message
Johan Hake (johan-hake) said :
#13

On Sunday January 15 2012 11:10:58 Garth Wells wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Garth Wells proposed the following answer:
> On 15 January 2012 00:45, Anders Logg
>
> <email address hidden> wrote:
> > Question #184620 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/184620
> >
> > Anders Logg proposed the following answer:
> >
> > On Sat, Jan 14, 2012 at 04:10:56PM -0000, Allan Leal wrote:
> >> Question #184620 on DOLFIN changed:
> >> https://answers.launchpad.net/dolfin/+question/184620
> >>
> >> Allan Leal posted a new comment:
> >> Why not hide the requirement of a ufc::cell instance from Dolfin users?
> >>
> >> If a UFCCell object can be instantiated from a Cell, e.g.,:
> >>
> >> dolfin_cell = Cell(mesh, index_cell)
> >> ufc_cell = UFCCell(dolfin_cell)
> >>
> >> then why the interface of Function.eval isn't as follows:
> >>
> >> eval(values, x, dolfin_cell) ?
> >
> > I think we should add this. A user should not need to create a
> > UFCCell.

+

> I'm not convinced.
>
> Creating a UFCCell (which is necessary to support UFC) is expensive
> in that it allocates memory. By supplying an interface which does not
> require a a UFCCell but does create one in the background hides an
> expensive operation for repeated calls. The functionality in question
> is rather low-level, which is why I'm not fussed if a user takes
> control of creating (and updating) the UFCCell.

One could create a default private UFCCell in the constructor of Function.
Then inside

  Function::eval(values, x, dolfin_cell)
  {
     _ufc_cell.update(dolfin_cell);
     eval(values, x, _ufc_cell);
  }

> >> Also, why not provide the following interface:
> >>
> >> values = eval(x, dolfin_cell) ?

There are already a quite nice interface of implicit evaluation of a Function
using the __call__ method in Python.

  values = u(x)
  values = u(0, 0, .5)

aso, but there are no logic for passing a dolfin::Cell. That needs an
interface as suggested above.

Johan

> >> Is there a better place to suggest this?
> >
> > The mailing list.
> >
> > --
> > Anders
> >
> > --
> > You received this question notification because you are a member of
> > DOLFIN Team, which is an answer contact for DOLFIN.

Revision history for this message
Anders Logg (logg) said :
#14

On Sun, Jan 15, 2012 at 08:11:04PM -0000, Johan Hake wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Johan Hake proposed the following answer:
> On Sunday January 15 2012 11:10:58 Garth Wells wrote:
> > Question #184620 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/184620
> >
> > Garth Wells proposed the following answer:
> > On 15 January 2012 00:45, Anders Logg
> >
> > <email address hidden> wrote:
> > > Question #184620 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/184620
> > >
> > > Anders Logg proposed the following answer:
> > >
> > > On Sat, Jan 14, 2012 at 04:10:56PM -0000, Allan Leal wrote:
> > >> Question #184620 on DOLFIN changed:
> > >> https://answers.launchpad.net/dolfin/+question/184620
> > >>
> > >> Allan Leal posted a new comment:
> > >> Why not hide the requirement of a ufc::cell instance from Dolfin users?
> > >>
> > >> If a UFCCell object can be instantiated from a Cell, e.g.,:
> > >>
> > >> dolfin_cell = Cell(mesh, index_cell)
> > >> ufc_cell = UFCCell(dolfin_cell)
> > >>
> > >> then why the interface of Function.eval isn't as follows:
> > >>
> > >> eval(values, x, dolfin_cell) ?
> > >
> > > I think we should add this. A user should not need to create a
> > > UFCCell.
>
> +
>
> > I'm not convinced.
> >
> > Creating a UFCCell (which is necessary to support UFC) is expensive
> > in that it allocates memory. By supplying an interface which does not
> > require a a UFCCell but does create one in the background hides an
> > expensive operation for repeated calls. The functionality in question
> > is rather low-level, which is why I'm not fussed if a user takes
> > control of creating (and updating) the UFCCell.
>
> One could create a default private UFCCell in the constructor of Function.
> Then inside
>
> Function::eval(values, x, dolfin_cell)
> {
> _ufc_cell.update(dolfin_cell);
> eval(values, x, _ufc_cell);
> }

I think that sounds like a good solution.

--
Anders

> > >> Also, why not provide the following interface:
> > >>
> > >> values = eval(x, dolfin_cell) ?
>
> There are already a quite nice interface of implicit evaluation of a Function
> using the __call__ method in Python.
>
> values = u(x)
> values = u(0, 0, .5)
>
> aso, but there are no logic for passing a dolfin::Cell. That needs an
> interface as suggested above.
>
> Johan
>
> > >> Is there a better place to suggest this?
> > >
> > > The mailing list.
> > >
>

Revision history for this message
Johan Hake (johan-hake) said :
#15

On Sunday January 15 2012 21:30:55 Anders Logg wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Anders Logg proposed the following answer:
>
> On Sun, Jan 15, 2012 at 08:11:04PM -0000, Johan Hake wrote:
> > Question #184620 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/184620
> >
> > Johan Hake proposed the following answer:
> >
> > On Sunday January 15 2012 11:10:58 Garth Wells wrote:
> > > Question #184620 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/184620
> > >
> > > Garth Wells proposed the following answer:
> > > On 15 January 2012 00:45, Anders Logg
> > >
> > > <email address hidden> wrote:
> > > > Question #184620 on DOLFIN changed:
> > > > https://answers.launchpad.net/dolfin/+question/184620
> > > >
> > > > Anders Logg proposed the following answer:
> > > >
> > > > On Sat, Jan 14, 2012 at 04:10:56PM -0000, Allan Leal wrote:
> > > >> Question #184620 on DOLFIN changed:
> > > >> https://answers.launchpad.net/dolfin/+question/184620
> > > >>
> > > >> Allan Leal posted a new comment:
> > > >> Why not hide the requirement of a ufc::cell instance from Dolfin
> > > >> users?
> > > >>
> > > >> If a UFCCell object can be instantiated from a Cell, e.g.,:
> > > >> dolfin_cell = Cell(mesh, index_cell)
> > > >> ufc_cell = UFCCell(dolfin_cell)
> > > >>
> > > >> then why the interface of Function.eval isn't as follows:
> > > >> eval(values, x, dolfin_cell) ?
> > > >
> > > > I think we should add this. A user should not need to create a
> > > > UFCCell.
> >
> > +
> >
> > > I'm not convinced.
> > >
> > > Creating a UFCCell (which is necessary to support UFC) is expensive
> > > in that it allocates memory. By supplying an interface which does not
> > > require a a UFCCell but does create one in the background hides an
> > > expensive operation for repeated calls. The functionality in question
> > > is rather low-level, which is why I'm not fussed if a user takes
> > > control of creating (and updating) the UFCCell.
> >
> > One could create a default private UFCCell in the constructor of
> > Function. Then inside
> >
> > Function::eval(values, x, dolfin_cell)
> > {
> >
> > _ufc_cell.update(dolfin_cell);
> > eval(values, x, _ufc_cell);
> >
> > }
>
> I think that sounds like a good solution.

Is this something that should be backported?

It isn't that big of a change... Also one does not have to wrap UFCCell with
this interface.

Johan

> --
> Anders
>
> > > >> Also, why not provide the following interface:
> > > >> values = eval(x, dolfin_cell) ?
> >
> > There are already a quite nice interface of implicit evaluation of a
> > Function using the __call__ method in Python.
> >
> > values = u(x)
> > values = u(0, 0, .5)
> >
> > aso, but there are no logic for passing a dolfin::Cell. That needs an
> > interface as suggested above.
> >
> > Johan
> >
> > > >> Is there a better place to suggest this?
> > > >
> > > > The mailing list.

Revision history for this message
Anders Logg (logg) said :
#16

On Sun, Jan 15, 2012 at 09:01:01PM -0000, Johan Hake wrote:
> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Johan Hake proposed the following answer:
> On Sunday January 15 2012 21:30:55 Anders Logg wrote:
> > Question #184620 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/184620
> >
> > Anders Logg proposed the following answer:
> >
> > On Sun, Jan 15, 2012 at 08:11:04PM -0000, Johan Hake wrote:
> > > Question #184620 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/184620
> > >
> > > Johan Hake proposed the following answer:
> > >
> > > On Sunday January 15 2012 11:10:58 Garth Wells wrote:
> > > > Question #184620 on DOLFIN changed:
> > > > https://answers.launchpad.net/dolfin/+question/184620
> > > >
> > > > Garth Wells proposed the following answer:
> > > > On 15 January 2012 00:45, Anders Logg
> > > >
> > > > <email address hidden> wrote:
> > > > > Question #184620 on DOLFIN changed:
> > > > > https://answers.launchpad.net/dolfin/+question/184620
> > > > >
> > > > > Anders Logg proposed the following answer:
> > > > >
> > > > > On Sat, Jan 14, 2012 at 04:10:56PM -0000, Allan Leal wrote:
> > > > >> Question #184620 on DOLFIN changed:
> > > > >> https://answers.launchpad.net/dolfin/+question/184620
> > > > >>
> > > > >> Allan Leal posted a new comment:
> > > > >> Why not hide the requirement of a ufc::cell instance from Dolfin
> > > > >> users?
> > > > >>
> > > > >> If a UFCCell object can be instantiated from a Cell, e.g.,:
> > > > >> dolfin_cell = Cell(mesh, index_cell)
> > > > >> ufc_cell = UFCCell(dolfin_cell)
> > > > >>
> > > > >> then why the interface of Function.eval isn't as follows:
> > > > >> eval(values, x, dolfin_cell) ?
> > > > >
> > > > > I think we should add this. A user should not need to create a
> > > > > UFCCell.
> > >
> > > +
> > >
> > > > I'm not convinced.
> > > >
> > > > Creating a UFCCell (which is necessary to support UFC) is expensive
> > > > in that it allocates memory. By supplying an interface which does not
> > > > require a a UFCCell but does create one in the background hides an
> > > > expensive operation for repeated calls. The functionality in question
> > > > is rather low-level, which is why I'm not fussed if a user takes
> > > > control of creating (and updating) the UFCCell.
> > >
> > > One could create a default private UFCCell in the constructor of
> > > Function. Then inside
> > >
> > > Function::eval(values, x, dolfin_cell)
> > > {
> > >
> > > _ufc_cell.update(dolfin_cell);
> > > eval(values, x, _ufc_cell);
> > >
> > > }
> >
> > I think that sounds like a good solution.
>
> Is this something that should be backported?
>
> It isn't that big of a change... Also one does not have to wrap UFCCell with
> this interface.

My first instinct is no, we shouldn't change the interface in 1.0 (not
even backwards compatible improvements).

But I have no serious objections if there are other opinions.

--
Anders

Revision history for this message
Mikael Mortensen (mikael-mortensen) said :
#17

On 15 January 2012 21:01, Johan Hake
<email address hidden>wrote:

> Question #184620 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/184620
>
> Johan Hake proposed the following answer:
> On Saturday January 14 2012 11:30:54 Mikael Mortensen wrote:
> > Question #184620 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/184620
> >
> > Mikael Mortensen proposed the following answer:
> > On 13 January 2012 19:41, Allan Leal <
> <email address hidden>>
> >
> > wrote:
> > > Question #184620 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/184620
> > >
> > > Status: Answered => Open
> > >
> > > Allan Leal is still having a problem:
> > > @Garth
> > >
> > > UFCCell is not define in my FEniCS installation. How can I add it?
> > >
> > > @ Mikael
> > >
> > > The function ufc.cell accepts no argument (except self), so how does it
> > > work? I could not manage to get the following code working:
> > >
> > > from dolfin import *
> > > from numpy import *
> > > import ufc
> > >
> > > mesh = UnitSquare(1,1)
> > > DG1 = FunctionSpace(mesh, 'DG', 1)
> > >
> > > u = Function(DG1)
> > > ...
> > > dolfin_cell = Cell(mesh, 0)
> > > ufc_cell = ufc.cell() # empty ufc::cell???
> > >
> > > u.eval(values, x, dolfin_cell, ufc_cell)
> >
> > It seems like this crashes in element.evaluate_basis inside eval. Perhaps
> > you need to submit a bug report on this? Or wait for the UFCCell wrap?
>
> ufc.cell should not be instantiated by itself. There are no memory
> allocated
> for in particular entity_indices and coordinates. One should not
> instantiate
> ufc.cell from Python.
>
> > You can set the index of the ufc_cell like ufc_cell.index = 0, but I
> think
> > you also need to set the ufc_cell.mesh_identifier to mesh.id() to get
> past
> > line 432 in UFCCell.h. I noticed that it actually works if I change the
> > last argument of element.evaluate_basis in eval (line 384) from
> >
> > element.evaluate_basis(i, &basis[0], &x[0], ufc_cell);
> >
> > to
> >
> > element.evaluate_basis(i, &basis[0], &x[0], dolfin_cell);
> >
> > I guess i have to dig deeper when i can find the time. Anybody else know
> > why? Other functions like restrict work with the ufc_cell argument.
>
> Is that by pure luck?
>

It worked so I didn't really care:-) (Looks like ufc_cell wasn't used by
restrict which is why it worked for me.)

M

>
> Johan
>
> > M
> >
> > > --
> > > You received this question notification because you are a member of
> > > DOLFIN Team, which is an answer contact for DOLFIN.
>
> --
> You received this question notification because you are a member of
> DOLFIN Team, which is an answer contact for DOLFIN.
>

Can you help with this problem?

Provide an answer of your own, or ask Allan Leal for more information if necessary.

To post a message you must log in.