← Back to team overview

dolfin team mailing list archive

Re: Evaluate discrete function on cells

 

Dag Lindbo wrote:
Hello all,

I saw that there is a convenient way to evaluate a DiscreteFunction at all vertices of its mesh, i.e. u.evaluate( val ). Is there a convenient way to evaluate a function on each cell (e.g. on the mid-point of each triangle)?

If not, I would really appreciate some suggestions how to go about. Is the more general function

interpolate(real* coefficients,const ufc::cell& cell,
	    const ufc::finite_element& finite_element)

the way to go? How do I evaluate the sum of basis functions in a point if I know the coefficients?
I have been playing with a similar functionality in my own project, where I need to evaluate some field on a cell. What I ended up doing is adding two methods to the Function class, specifically for DiscreteFunctions, that return the local data, uint* dofs (which are the coefficients) and the DofMap* dof_map. Then I can iterate over cells and evaluate the coefficients on each cell however I want. So my loop looks something like:

(say field is a DiscreteFunction)
 for (; !cell.end(); ++cell) {
   ufc_cell.update(*cell);
   dof_map->tabulate_dofs(dofs, ufc_cell);
field.vector().get(array, dof_map->local_dimension(), dofs);

   ...do something with array...
 }

There is probably a better way to do this, and I'd like to hear it, too. Otherwise I can submit my own changes.

Jake
Thanks!
/Dag Lindbo
_______________________________________________
DOLFIN-dev mailing list
DOLFIN-dev@xxxxxxxxxx
http://www.fenics.org/mailman/listinfo/dolfin-dev





Follow ups

References