division in forms

Asked by Neilen Marais

Is it possible to do division in forms?

I have the following form:

(dot(curl(v), curl(u)))/mu_r*dx

where mu_r is a FunctionSpace(mesh, 'DG', 0) function. The form works fine if I multiply by mu_r, but I cannot divide!

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Marie Rognes (meg-simula) said :
#1

Yes, it is possible to do division by a Function in forms.

Could you please provide a minimal running example and tell us what error you get?

Revision history for this message
Neilen Marais (neilenmarais) said :
#2

It seems to be related to the

 from __future__ import division

statement. The following doesn't work:

from __future__ import division

import dolfin as dol
from dolfin import dot, curl, inner, dx

# Define mesh
mesh = dol.UnitCube(1,1,1)
material_func_space = dol.FunctionSpace(mesh, 'DG', 0)
mu_r = dol.Function(material_func_space)
mu_r.vector()[:] = 1.

# Define function space
order = 3
V = dol.FunctionSpace(mesh, "Nedelec 1st kind H(curl)", order)

# Define basis and bilinear form
u = dol.TrialFunction(V)
v = dol.TestFunction(V)

s = dot(curl(v), curl(u))/mu_r*dx # Stiffness form

But if you comment out the from __future__ statement it does work.

Revision history for this message
Martin Sandve Alnæs (martinal) said :
#3

On 12 April 2011 11:53, Neilen Marais
<email address hidden>wrote:

> Question #152508 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/152508
>
> Neilen Marais posted a new comment:
> It seems to be related to the
>
> from __future__ import division
>
> statement. The following doesn't work:
>
> from __future__ import division
>
> import dolfin as dol
> from dolfin import dot, curl, inner, dx
>
> # Define mesh
> mesh = dol.UnitCube(1,1,1)
> material_func_space = dol.FunctionSpace(mesh, 'DG', 0)
> mu_r = dol.Function(material_func_space)
> mu_r.vector()[:] = 1.
>
>
> # Define function space
> order = 3
> V = dol.FunctionSpace(mesh, "Nedelec 1st kind H(curl)", order)
>
> # Define basis and bilinear form
> u = dol.TrialFunction(V)
> v = dol.TestFunction(V)
>
> s = dot(curl(v), curl(u))/mu_r*dx # Stiffness form
>
>
> But if you comment out the from __future__ statement it does work.

I have commited a fix for this in the development version of UFL. When
future division is enabled, __div__ is replaced with __truediv__ and
__floordiv__. UFL now handles __div__ and __truediv__ the same way, and
throws an error on __floordiv__ which is not supported.

For future bug reports, pasting the error you get instead of "it doesn't
work" is appreciated.

Martin

Can you help with this problem?

Provide an answer of your own, or ask Neilen Marais for more information if necessary.

To post a message you must log in.