Mixed Element descriptions


370
views
0
9 months ago by
I have been meddling about with mixed elements and haven't been able to figure out if there is a functional difference between #1 and #2 below here?

E1 = FiniteElement(...)
E2 = FiniteElement(...)
E3 = FiniteElement(...)

# --- 1 ---
E = E1*E2*E3
# which is the same as
E = MixedElement(MixedElement(E1,E2),E3)
# and
E = MixedElement((E1,E2),E3)
# and produces:
# MixedElement(MixedElement(FiniteElement(...), FiniteElement(...)), FiniteElement(...))

# --- 2 ---
E = MixedElement(E1,E2,E3)
# which produces:
# MixedElement(FiniteElement(...), FiniteElement(...), FiniteElement(...))
​

In case they are functionally different, is it possible to flexibly generate mixed elements? Say I have a parameter d and want a mixed element of type
E = MixedElement(E1,E2,...<d times>..., E2,E3)​
# so that it takes the form
# MixedElement(FiniteElement(<E1 type>),FiniteElement(<E2 type>),...,FiniteElement(<E3 type>))
# with no mixed element in mixed element shenanigans
where E2 appears exactly d times. How would I do this?
Community: FEniCS Project
1
What, like this?

from fenics import *

E1 = FiniteElement("CG", interval, 1)
E2 = FiniteElement("CG", interval, 2)
E3 = FiniteElement("CG", interval, 3)

d  = 4

M = MixedElement([E1,E2]*d + [E2,E3])

print M
written 9 months ago by pf4d  
1
Hello,

In your first formulation, where you multiply finite elements to create a mixed element, you will always be dealing with tuples. That means, that your mixed function space will have a tuple, and inside it a tuple, and so on, as long as you have multiplication... By creating it with a list, as suggested on the answer by Adam you'll get the proper definition that you want...
written 9 months ago by Leonardo Hax Damiani  
1
Oh, I see!  In that case,

from fenics import *

E1 = FiniteElement("CG", interval, 1)
E2 = FiniteElement("CG", interval, 2)
E3 = FiniteElement("CG", interval, 3)

d  = 4

M = MixedElement([E1] + [E2]*d + [E3])

print M​
written 9 months ago by pf4d  
1
It seems that list addition and multiplication works like:
[1,2]*3 = [1,2,1,2,1,2]​
so there was no problem of nesting in your first code-snippet.
written 9 months ago by Bjørn Jensen  

2 Answers


3
9 months ago by
pf4d  

Use the list operations such as

[1,2]*3 = [1,2,1,2,1,2]​

like this :

from fenics import *

E1 = FiniteElement("CG", interval, 1)
E2 = FiniteElement("CG", interval, 2)
E3 = FiniteElement("CG", interval, 3)

d  = 4

M = MixedElement([E1,E2]*d + [E2,E3])

print M
2
9 months ago by
You can first create a list of your finite elements and then feed it to the MixedElement function:
E1 = FiniteElement(...)
E2 = FiniteElement(...)
E3 = FiniteElement(...)

element_list = [E1]

for i in range(d):
    element_list.append(E2)

element_list.append(E3)

E = MixedElement(element_list)
​
Please login to add an answer/comment or follow this question.

Similar posts:
Search »