Boundary conditions for complex-valued problem

Asked by Nico Schlömer

I would like to solve a complex-valued problem using FEniCS. I gather from several previous postings, that FEniCS unfortunately doesn't support complex values, and that one should formulate the problem in the product space W of real and imaginary part, e.g.,

PN = FunctionSpace(mesh, "Nedelec 2nd kind H(curl)", 1)
W = PN * PN

I'm now wondering how to specify boundary conditions in that product space. This

zero = Expression(("0.0", "0.0", "0.0"), degree=1)
bc = DirichletBC(W, zero, DirichletBoundary())

doesn't work since `zero` isn't a member of W, but fail to understand how `zero x zero` is defined.

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
Nico Schlömer (nschloe) said :
#1

Okay, I think I can do

zero = Constant(np.zeros(6))

to generate the appropriate boundary condition.

Another shape mismatch bites me however at the creation of the right hand side.

rhs = Constant(np.array([0.0, 0.0, 1.0, 0.0, 0.0, 1.0]))
PN = FunctionSpace(mesh, "Nedelec 2nd kind H(curl)", 1)
W = PN * PN
v0 = TestFunction(W)
vr = v0[0]
vi = v0[1]
L = -inner(rhs,vr)*dx - inner(rhs,vi)*dx

gives

Traceback (most recent call last):
  File "curlcurl.py", line 61, in <module>
    L = -inner(rhs,vr)*dx - inner(rhs,vi)*dx
  File "/usr/lib/python2.7/dist-packages/ufl/operators.py", line 119, in inner
    return Inner(a, b)
  File "/usr/lib/python2.7/dist-packages/ufl/tensoralgebra.py", line 183, in __new__
    ufl_assert(ash == bsh, "Shape mismatch.")
  File "/usr/lib/python2.7/dist-packages/ufl/assertions.py", line 37, in ufl_assert
    if not condition: error(*message)
  File "/usr/lib/python2.7/dist-packages/ufl/log.py", line 148, in error
    raise self._exception_type(self._format_raw(*message))
ufl.log.UFLException: Shape mismatch.

Indeed, when inspecting those elements in "/usr/lib/python2.7/dist-packages/ufl/operators.py, line 199":
w_0
(v_{-2})[0]

I suppose the element "rhs" has to be from the function space W, but so far I didn't tell FEniCS about it.

Revision history for this message
Patrick Farrell (pefarrell) said :
#2

Is this what you mean?

[P.S. It makes other people's lives much easier if you provide the entire working code, not just snippets]

from dolfin import *
import numpy as np

mesh = UnitCube(2, 2, 2)
PN = FunctionSpace(mesh, "Nedelec 2nd kind H(curl)", 1)
W = PN * PN

bc = DirichletBC(W, (0, 0, 0, 0, 0, 0), "on_boundary")

rhs = project(Constant([0.0, 0.0, 1.0, 0.0, 0.0, 1.0]), W)

v0 = TestFunction(W)
vr = v0[0]
vi = v0[1]
L = -inner(rhs[0],vr)*dx - inner(rhs[1],vi)*dx

Dolfin attempts to compile it, but FFC fails to compile it with some strange error:

ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h: In member function ‘virtual void ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c_cell_integral_0_0::tabulate_tensor(double*, const double* const*, const ufc::cell&) const’:
ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h:3878:68: error: ‘K_03’ was not declared in this scope
ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h:3878:80: error: ‘K_04’ was not declared in this scope
ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h:3878:92: error: ‘K_05’ was not declared in this scope
ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h:3879:73: error: ‘K_13’ was not declared in this scope
ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h:3879:85: error: ‘K_14’ was not declared in this scope
ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h:3879:97: error: ‘K_15’ was not declared in this scope
ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h:3880:73: error: ‘K_23’ was not declared in this scope
ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h:3880:85: error: ‘K_24’ was not declared in this scope
ffc_form_d3da548a0c93117cd1258de09c5635a1bb85305c.h:3880:97: error: ‘K_25’ was not declared in this scope

which looks like a bug to me.

Revision history for this message
Nico Schlömer (nschloe) said :
#3

This

rhs = project(Constant([0.0, 0.0, 1.0, 0.0, 0.0, 1.0]), W)

might be what I'm looking for indeed.
The compilation fails for me with the same error though.

Revision history for this message
Patrick Farrell (pefarrell) said :
#4

Yep, I think you should report a bug.

Revision history for this message
Marie Rognes (meg-simula) said :
#5

Yes, please report the bug. Here is a simpler case that reproduces the same issue (the problem starts in the project step):

mesh = UnitCube(2, 2, 2)
PN = FunctionSpace(mesh, "Nedelec 2nd kind H(curl)", 1)
W = PN * PN
v = TestFunction(W)
c = Function(W)
L = inner(c, v)*dx
b = assemble(L)

As a temporary fix, you can try explicitly using the quadrature representation: add this

parameters["form_compiler"]["representation"] = "quadrature"

at the beginning of your script

Can you help with this problem?

Provide an answer of your own, or ask Nico Schlömer for more information if necessary.

To post a message you must log in.