Initializing a function with two sub-functions

Asked by jhameed2@illinois.edu on 2010-05-17

Hello,

Is there a nice way to initialize a mixed element function with two of its sub-functions. Specifically,

element = FiniteElement("Lagrange", tetrahedron, 1)
vecElement = element + element
u = Coefficient(vecElement)

Now, in the code, I want to do this:

u[0] = func1
u[1] = func2

where func1 and func2 are functions of "element". I want to do this to initialize u in a newton solver. The above code doesnt copy the values to u's sub-functions. Another way of framing my question could be, given two subfunctions, how do I combine them into a mixed-function?

I can think of some workarounds, e.g. initializing the function "u" as a vector function using an Expression class, but thats not as clean a solution as I would like. I would like to initialize u, given two input functions which are scalar.

Thanks,
-Jehanzeb

Question information

Language:
English Edit question
Status:
Answered
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Last query:
2010-05-17
Last reply:
2011-03-31
Patrick Riesen (priesen) said : #1

<email address hidden> wrote:
> New question #111370 on DOLFIN:
> https://answers.launchpad.net/dolfin/+question/111370
>
> Hello,
>
> Is there a nice way to initialize a mixed element function with two of its sub-functions. Specifically,
>
> element = FiniteElement("Lagrange", tetrahedron, 1)
> vecElement = element + element
> u = Coefficient(vecElement)
>
> Now, in the code, I want to do this:
>
> u[0] = func1
> u[1] = func2

you can extract the sub-dofmaps of u corresponding to u[0] and u[1] and
then in a cell iteration loop place the values of func1 and func2 into
u[0] and u[1] using subdofmap.tabulate_dofs() and func1.vector().get() /
u.vector().set() i guess ...

patrick

>
> where func1 and func2 are functions of "element". I want to do this to initialize u in a newton solver. The above code doesnt copy the values to u's sub-functions. Another way of framing my question could be, given two subfunctions, how do I combine them into a mixed-function?
>
> I can think of some workarounds, e.g. initializing the function "u" as a vector function using an Expression class, but thats not as clean a solution as I would like. I would like to initialize u, given two input functions which are scalar.
>
> Thanks,
> -Jehanzeb
>

Thanks. That might work, but is not a very clean way. I have a different representation which side steps this issue, so this is not a deal breaker for me, but I would think this should be easy to do.

Chaffra Affouda (chaffra) said : #3

I have a related problem. Let's say I have

m = UnitInterval(100)
Q = FunctionSpace(n, 'CG',1)
u0 = Function(Q)

W = MixedFunctionSpace([Q,Q,Q])
u_func = Function(W)
I want to do:

u_func[0].assign(u0) but I get
AttributeError: 'Indexed' object has no attribute 'assign'

How do I do this?
Thanks, Chaffra

Chaffra Affouda (chaffra) said : #4

Never mind. I have got it. I have to use split

Can you help with this problem?

Provide an answer of your own, or ask jhameed2@illinois.edu for more information if necessary.

To post a message you must log in.