Defining real part of complex equation using Expression() in FEniCS

Hi,
I want to impose the real part of a complex velocity expression at an inlet of my geometry. But, I am not sure how to do that.

For example,
v_{in} = \Re [y(1-y)e^{it}]

Though the above equation is simple, I have a very complicated ‘complex’ equation.
I want something like this:

v_in = Expression("x[1]*(1-x[1])*exp(1j*t)",t=0.0, degree=2)
v_in = v_in.real

Please tell me how to do it.
Thank you,

Legacy dolfin doesn’t really have complex support.
You can use sympy for this though:

from dolfin import *


mesh = UnitSquareMesh(10, 10)

import sympy

x, y, t = sympy.symbols("x[0], x[1] t", real=True)

v_in = y * (1 - y) * sympy.exp(1j * t)
v_real, _ = v_in.as_real_imag()


expr = Expression(str(v_real), degree=2, t=0.0)

print(assemble(expr * dx(domain=mesh)))

expr.t = 2
print(assemble(expr * dx(domain=mesh)))
1 Like

Thank you very much, Dokken! :slight_smile: