This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

function/expression derivatives

+1 vote

I have a time-dependent problem

  1. dc/dt = d(uc)/dx + f

where d(uc)/dx is an convection term and f is a source/sink forcing. At each timestep, I first solve for u (it is the solution to a nonlinear PDE). I then solve solve for c^{t+1} using an LU solver (very similar to the advection-diffusion demo). The timestepper is basically controlled by two parameters: (i) the step size dt and (ii) \alpha such that \alpha=0 is backward Euler and \alpha=1 is forward Euler.

I'd like to use a fancier time-integration (specifically, one from Sundials). The integrator requires a method that evaluates the right hand side of (1). I was going to create and expression

class Concentration : public dolfin::Expression { 
public:
    Concentration(shared_ptr<dolfin:Function> u, shared_ptr<dolfin:Function> c) : dolfin::Expression(), u(u), c(c) {}

    void eval(dolfin::Array<double>& rhs, dolfin::Array<double> const& point) const {
        dolfin::Array<double> cx(1),dcdx(1),ux(1),dcxd(1);
        u->eval(ux, point);
        u->derivative(dudx, point);
        c->eval(cx, point);
        c->derivative(dcdx, point);

        rhs[0] = dudx[0]*cx[0]+ux[0]*dcdx[0] + f(point);
    }
private:
     shared_ptr<dolfin::Function> u;
     shared_ptr<dolfin::Function> c;
};

But I don't see any function like "derivative" --- does such a thing exist?

asked Feb 13, 2017 by davisad FEniCS Novice (470 points)
edited Feb 13, 2017 by davisad

1 Answer

0 votes

You should do it from the UFL side. Check the demo: undocumented/eval.

answered Feb 20, 2017 by str FEniCS User (1,600 points)
...