solving problem with vector valued function

Asked by Melanie Jahny

I'd like to solve the convection-equation for different kinds of (independent) concentration functions.
I'd like to solve the concection-diffusion problem for several concentrations.
I'd like to set the number of different concentration function as a variable m.
How do I have to define the concentration functions conc[i] (i <= m) ?
Can I define them as a vector?

For one concentration I defined
Q = FunctionSpace(mesh, "CG", 1)
conc = TrialFunction(Q)

I tried VectorFunctionSpace, but it sets the size of the vector equal the mesh-dimension.
Further, how do I have to change the bilinarform for several concentrations?
F = eta*(conc-conc_prev)*dx + dt*(eta*dot(velocity, grad(conc))*dx + Diff_const*dot(grad(eta), grad(conc)*dx)

with eta = TestFunction(Q) and conc_prev the concentration from previous time step.

Is it possible to solve this problem by a for-loop over the number of concentration functions?
How will the boundary value definition change? (I have Neumann-boundary values on a small part of the mesh)?

I hope anyone can help me! Thanks!

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Johan Hake
Solved:
Last query:
Last reply:
Revision history for this message
Johan Hake (johan-hake) said :
#1

Melanie!

You can use a MixedFunctionSpace.

  from dolfin import *
  mesh = UnitCube(10,10,10)

  dt = 1.0
  N = 4 # Number of diffusive ligands
  Ds = range(1, N+2) # Diffusion constants
  V = MixedFunctionSpace([FunctionSpace(mesh, "CG", 1)]*N)
  u = Function(V); u0 = Function(V)
  v = TestFunction(V)

  F = reduce(lambda x, y:x+y, \
      (((u[i]-u0[i])*v[i]/dt+\
      Ds[i]*inner(grad(u[i]), grad(v[i])))*dx for i in xrange(N)))

  dF = derivative(F, u)

  problem = VariationalProblem(F, dF)

- This is pretty compact and should for clarity be expanded
- I have not added any Neumann conditions, neither the advective term
- Also note that eventhough F is linear I have stated the problem as
  a nonlinear one

Johan

On Tuesday February 15 2011 08:37:28 Melanie Jahny wrote:
> New question #145492 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/145492
>
> I'd like to solve the convection-equation for different kinds of
> (independent) concentration functions. I'd like to solve the
> concection-diffusion problem for several concentrations. I'd like to set
> the number of different concentration function as a variable m. How do I
> have to define the concentration functions conc[i] (i <= m) ? Can I define
> them as a vector?
>
> For one concentration I defined
> Q = FunctionSpace(mesh, "CG", 1)
> conc = TrialFunction(Q)
>
> I tried VectorFunctionSpace, but it sets the size of the vector equal the
> mesh-dimension. Further, how do I have to change the bilinarform for
> several concentrations? F = eta*(conc-conc_prev)*dx +
> dt*(eta*dot(velocity, grad(conc))*dx + Diff_const*dot(grad(eta),
> grad(conc)*dx)
>
> with eta = TestFunction(Q) and conc_prev the concentration from previous
> time step.
>
> Is it possible to solve this problem by a for-loop over the number of
> concentration functions? How will the boundary value definition change? (I
> have Neumann-boundary values on a small part of the mesh)?
>
> I hope anyone can help me! Thanks!

Revision history for this message
Melanie Jahny (melanie-jahny) said :
#2

Thank you so much Johan for helping me with my problem.
I tried the code you*ve written and got the following error message after the last line:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/site-packages/dolfin/fem/variationalproblem.py", line 40, in __init__
    self.L = Form(L, form_compiler_parameters=form_compiler_parameters)
  File "/usr/local/lib/python2.6/site-packages/dolfin/fem/form.py", line 43, in __init__
    function_spaces)
  File "/usr/local/lib/python2.6/site-packages/dolfin/fem/form.py", line 64, in _extract_function_spaces
    if not isinstance(func.function_space(), cpp.FunctionSpace):
AttributeError: 'Argument' object has no attribute 'function_space'

Can you understand what this means?
Melanie

Revision history for this message
Johan Hake (johan-hake) said :
#3

What version are you using? I think you need the soon to be released
development version for that particular example.

But if you change:

    dF = derivative(F, u)

to:

    du = TrialFunction(V)
    dF = derivative(F, u, du)

I think you should be good. However I suspect the syntax of VariationalProblem
for nonlinear cases also has change. So the last line might still not work.
You need to check the docstring of VariationalProblem:

   >>> help(VariationalProblem)

to get it going.

Johan

On Wednesday February 16 2011 08:11:26 Melanie Jahny wrote:
> Question #145492 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/145492
>
> Status: Answered => Open
>
> Melanie Jahny is still having a problem:
> Thank you so much Johan for helping me with my problem.
> I tried the code you*ve written and got the following error message after
> the last line:
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File
> "/usr/local/lib/python2.6/site-packages/dolfin/fem/variationalproblem.py",
> line 40, in __init__ self.L = Form(L,
> form_compiler_parameters=form_compiler_parameters) File
> "/usr/local/lib/python2.6/site-packages/dolfin/fem/form.py", line 43, in
> __init__ function_spaces)
> File "/usr/local/lib/python2.6/site-packages/dolfin/fem/form.py", line
> 64, in _extract_function_spaces if not isinstance(func.function_space(),
> cpp.FunctionSpace):
> AttributeError: 'Argument' object has no attribute 'function_space'
>
>
> Can you understand what this means?
> Melanie

Revision history for this message
Melanie Jahny (melanie-jahny) said :
#4

Thank you for your quick answer!!!
I think I'm using the newest fenics version 0.9.4.
I tried the new code, and it works:
du = TrialFunction(V)
dF = derivative(F, u, du)

problem = VariationalProblem(F, dF)

But I cannot get the solution of the problem, I can neither call:
problem.solve(u)

nor

solver = NewtonSolver("lu")
solver.parameters["convergence_criterion"] = "incremental"
solver.parameters["relative_tolerance"] = 1e-6
solver.solve(problem, u.vector())

What can I do to get the solution???

Revision history for this message
Best Johan Hake (johan-hake) said :
#5

On Wednesday February 16 2011 09:37:25 Melanie Jahny wrote:
> Question #145492 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/145492
>
> Status: Answered => Open
>
> Melanie Jahny is still having a problem:
> Thank you for your quick answer!!!
> I think I'm using the newest fenics version 0.9.4.
> I tried the new code, and it works:
> du = TrialFunction(V)
> dF = derivative(F, u, du)
>
> problem = VariationalProblem(F, dF)
>
> But I cannot get the solution of the problem, I can neither call:
> problem.solve(u)

What do you get?

The solution to the stated problem lacks initial conditions and boundary
conditions. You need to give those before it can start to make sense. Also
your u includes the solution from all your ligands. To plot each solution take
a look in:

  demo/pde/mixed-poisson/python/demo.py

and other answers on the Question and answers at Launchpad.

> nor
>
> solver = NewtonSolver("lu")
> solver.parameters["convergence_criterion"] = "incremental"
> solver.parameters["relative_tolerance"] = 1e-6
> solver.solve(problem, u.vector())

Here problem is not a VariationalProbelm but an instance of a subclass of
NonlinearProblem. Look into:

  demo/pde/cahn-hilliard/python/demo.py

for details about how to use that.

Johan

> What can I do to get the solution???

Revision history for this message
Melanie Jahny (melanie-jahny) said :
#6

Thanks Johan Hake, that solved my question.