dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #00333
Re: Collect function data in subclass to prepare for user-defined functions.
I understand your point. However, I just checked in some updates of
NewFunction that lets a user do
class MyFunction : NewFunctionExpression
{
real operator()(const Point& p)
{
return sin(p.x);
}
};
MyFunction f;
Could you take a look and see if you like the new/old solution?
It's not very complicated. The projection just checks if data is null
and in that case calls the user defined evaluation operator.
/Anders
On Mon, Feb 14, 2005 at 03:35:25PM +0100, Johan Jansson wrote:
> 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
>
> _______________________________________________
> DOLFIN-dev mailing list
> DOLFIN-dev@xxxxxxxxxx
> http://www.fenics.org/cgi-bin/mailman/listinfo/dolfin-dev
>
Follow ups
References