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

Setup initial values for domain from function

0 votes

Hi,

I'm trying to set inital values for the domain I'm working on.

For example when I try to solve the diffusion-PDE there might be some different concentrations in the area before the diffusion.

I tried o set them with

//setup FunctionSpace, Linear and Bilinear Form

dolfin::Function u(V); //V is my FunctionSpace

u.interpolate(initial);

//setup Boundary Condition and compute Solution

Where as initial is a class, derived from dolfin::Expression, providing the function for initial values.

I don't get an error-message but changing this initial function for test-cases doesnt change anything to the solution at all.

Have you any ideas or hints, how to solve this Problem/work around?

asked Jun 23, 2016 by Pama328 FEniCS Novice (480 points)
retagged Jun 23, 2016 by Pama328

3 Answers

0 votes
 
Best answer

[Continuing from a previous discussion in the comments]

There is no meaning in doing this. What do you expect that to matter? How is this datum supposed to influence anything? There is no sign of an "initial value" for the solution anywhere in the equation.

answered Jul 3, 2016 by Massimiliano Leoni FEniCS User (1,760 points)
selected Jul 3, 2016 by Pama328
0 votes

Can you show some more code?

answered Jun 24, 2016 by Massimiliano Leoni FEniCS User (1,760 points)

I added some more code in an other answer

0 votes

here is the more detailed code:
without setting the initial values (the part next to the TODO) everything is working fine,but changing the eval-Function of the initial class doesnt change anything.

//Setup constants 

const int dim = 2;
        Poisson::Initial initial;
        dolfin::Constant dirichlet(0.0);

        dolfin::FunctionSpace fSpace();

auto mesh = std::make_shared<dolfin::UnitSquareMesh(32, 32)>();

DimensionWrapper<dim> dimensionWrapper;

        //Setup FunctionSpace, Linear and BilinearForm (based on dim)
        auto V = std::make_shared<decltype(dimensionWrapper.FunctionSpace(mesh))>(dimensionWrapper.FunctionSpace(mesh));
        auto a = dimensionWrapper.BilinearForm(V,V);
        auto L = dimensionWrapper.LinearForm(V);

        //setup solution
        dolfin::Function u(V);

        //TODO: implement initial values (not working yet)
        u.interpolate(initial);

        //Define boundary condition
        auto u0 = std::make_shared<dolfin::Constant>(dirichletBoundary);
        auto boundary = std::make_shared<DirichletBoundary>();
        dolfin::DirichletBC bc(V, u0, boundary);


        //Set Boundary Condition for Problem
        Source f;
        dUdN g;
        L.g = g;
        L.f = f;

        //Compute solution
        dolfin::solve(a == L, u, bc);

The initial class is defined as :

 class Initial : public dolfin::Expression {
        void eval(dolfin::Array<double> &values, const dolfin::Array<double> &x) const{
            values[0] = 1;
        }
    };

I hope, my question is now clear and you might be able to help me.

answered Jun 28, 2016 by Pama328 FEniCS Novice (480 points)

Whatever is in u is cleared when you call solve. Your variational forms should have a coefficient uOld or similar that stores the initial condition [and then the previous-time-step solution for subsequent time steps].
This does not look like an evolutionary problem at all :S

Unfortunately there is nothing like this. I tired to run along the Poisson-demo and used this UFL-code:

#Define Poisson PDE in 2D:

element = FiniteElement("Lagrange", triangle, 1)

u = TrialFunction(element)
v = TestFunction(element)
f = Coefficient(element)
g = Coefficient(element)

a = inner(grad(u), grad(v))*dx
L = f*v*dx + g*v*ds

I changed the triangle to tetrahedron and for being able to solve the Poisson-equation in 3D to.

I looked a lot at the other demos and found something like this in the Cahn-Hillard-example

But I don't know how to apply this onto the Poisson-Equation to set initial values.

Listen, you need an evolutionary [= time-dependent] problem to have an initial condition. This means that your PDE must have the symbol \(\frac{\partial}{\partial t}\) somewhere in it.

Isn't it that what you are looking for is the initial guess for the linear system solver?

Ok, thanks and if I have a non-evolutionary equation (let's say the Poisson-equation) there is no option for setting initial values (= values at the domain before solving the equation)

There is no meaning in doing this. What do you expect that to matter? How is this datum supposed to influence anything? There is no sign of an "initial value" for the solution anywhere in the equation.

Okay, thanks a lot. It seems I missunderstood something in class.

If you add this as an own answer, I'll mark it as best answer.

Sure! I don't really care about points but at least it will stay sticky for whoever comes later on.

If you need any clarification on the topic, just go ahead.

Thanks a lot. I'm going to read the book I got from my professor and If something is still unclear I'd ask you again

...