← Back to team overview

dolfin team mailing list archive

Re: Collect function data in subclass to prepare for user-defined functions.

 

On Mon, Feb 14, 2005 at 03:19:06PM +0100, dolfin@xxxxxxxxxx wrote:
> Commit from logg (2005-02-14 15:19 CET)
> ----------------
> 
> Collect function data in subclass to prepare for user-defined functions.
> 
>   dolfin  src/kernel/function/NewFunction.cpp       1.6
>   dolfin  src/kernel/function/dolfin/NewFunction.h  1.5
> 
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/cgi-bin/mailman/listinfo/dolfin-dev

I'm thinking about how to enable user-defined functions, but I don't
have a clear solution.

The idea right now seems to be to subclass NewFunction, a la:

// Source term
// Example using NewFunction

class F : public NewFunction
{
public:
  F(const Mesh& mesh, const NewFiniteElement& element, NewVector& x) :
    NewFunction(mesh, element, x)
  {
  }
  virtual real operator()(const Point& p)
  {
    real pi = DOLFIN_PI;
    return 14.0 * pi*pi * sin(pi*p.x) * sin(2.0*pi*p.y) * sin(3.0*pi*p.z);
  }
};

We could have a separate constructor when an expression is given, and
then project the given expression.

I think this is a bit ugly though, it seems unnecessarily complex.

Another solution would be to separate the expression out into a
functor (function class), and the example would be:

class F : Expression
{
  virtual real operator()(const Point& p)
  {
    real pi = DOLFIN_PI;
    return 14.0 * pi*pi * sin(pi*p.x) * sin(2.0*pi*p.y) * sin(3.0*pi*p.z);
  }
}

then:

int main()
{
  ...

  F fexpression;
  NewFunction f(mesh, element, fexpression);
  
  ..
}

This seems much more natural. When we have a function given by the
values of its degrees of freedom, we pass a vector with the dofs to
NewFunction. When we have a function given by an expression, we pass
the expression to NewFunction and it projects it and stores it as
values of the dofs. However, we would need to introduce a new class:
Expression. What do you think?

  Johan



Follow ups

References