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

assemble_system

+1 vote

Hi,
This is a beginner question. I am solving an EM problem using N1curl elements. The weak form has imaginary term and so I split the equation into real and imaginary parts, and used mixed space formulation to solve coupled system. Broadly, the results looked right but it was slightly non-symmetrical. So I would like to try assemble_system(A,b,bcs) to make the coefficient matrix symmetric instead of using "solve(a == L, U, bcs)". I am having problem in passing parameters to solve() after assembling and split the final solution. Specifically, I am not sure how to pass the second parameter to solve() to store the solutions for a mixed function space. Any help ?

Here is the part of the code:

V = FunctionSpace(mesh, "Nedelec 1st kind H(curl)", 2)
Q = FunctionSpace(mesh, "Nedelec 1st kind H(curl)", 2)
combined_space = V * Q
....
#solve(a == L, Afield, bcs) # **this works but results were not symmetric**
A, b = assemble_system(a, L, bcs)
u = Function(combined_space)
U=u.vector() # **how do I write this for combined space**
solve(A,U,b)
Ur, Ui  = U.split(deepcopy=True)
asked Dec 3, 2013 by Arun FEniCS Novice (130 points)
edited Dec 4, 2013 by Arun

3 Answers

0 votes

Iff A, b are respectively bilinear and linear forms on combined_space then your code snippet is correct.

answered Dec 4, 2013 by Jan Blechta FEniCS Expert (51,420 points)

Thanks for the reply. But the above code throws this error when I try to split the solution after solve:

"AttributeError: 'GenericVector' object has no attribute 'split' 'GenericVector' object has no attribute 'split'".

The weak form (without any constants ) looks something like this:

J0 = Constant((0.0,0.0,1.0))
(Ur, Ui) = TrialFunctions(combined_space)
(T1, T2) = TestFunctions(combined_space)

a = inner(curl(T1),curl(Ur))*dx+inner(curl(T2),curl(Ui))*dx-inner(T1,Ur)*dx 
-inner(T2,Ui)*dx-inner(T1,Ui)*dx+inner(T2,Ur)*dx 

b = inner(J0,T1)*dx

Ah sorry, the last line

Ur, Ui  = U.split(deepcopy=True)

is not correct. You can split underlying Function not its Vector.

0 votes

Something like this?

V = FunctionSpace(mesh, "Nedelec 1st kind H(curl)", 2)
combined_space = V * V

J0     = Constant((0.0,0.0,1.0))
U      = TrialFunction(combined_space)
Ur, Ui = split(U)
T      = TestFunction(combined_space)
T1, T2 = split(T)


a = + inner(curl(T1),curl(Ur))*dx \
    + inner(curl(T2),curl(Ui))*dx \
    - inner(T1,Ur)*dx \
    - inner(T2,Ui)*dx \
    - inner(T1,Ui)*dx \
    + inner(T2,Ur)*dx 

L = inner(J0,T1)*dx

A, b = assemble_system(a, L, bcs)
U    = Function(combined_space).vector()
solve(A,U,b)

Ur, Ui = split(U)
answered Dec 5, 2013 by pf4d FEniCS User (2,970 points)
edited Dec 5, 2013 by pf4d
0 votes

Perhaps you can try just setting the solver_parameter (and not use assemble_system):

change:

solve(a == L, Afield, bcs) # **this works but results were not symmetric**

to

solve(a == L, Afield, bcs, solver_parameters = {"symmetric": True})
answered Dec 5, 2013 by stevenvdk FEniCS User (1,590 points)

Thanks for all the reply. This helps.

...