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

Assigning tensor-valued function

0 votes

Hi, I wonder how can I properly assign tensor-valued function to another tensor function (with different shape). Here is the minimal code

from dolfin import *

dim = 2
N   = 10

mesh = UnitSquareMesh(5,5)

W = TensorFunctionSpace(mesh, 'DG', 1, shape=(dim,dim))
WW = TensorFunctionSpace(mesh, 'DG', 1, shape=(dim,dim,N))

Bs = Function(W)
B = Function(WW)

Bs = interpolate(Expression((("0", "1"), 
                             ("3", "4"))), W)
assign(B.sub(???), Bs)

In particular, I would like to have something like the following assigment:

assign(B.sub(:,:,0), Bs(:,:))

My question is - is this a correct way? If so, then what should I insert instead of '???' ? If not, what is the right way?

Thanks a lot :)

asked May 27, 2015 by Ianx86 FEniCS User (1,050 points)

1 Answer

+1 vote
 
Best answer

You can use it like this:

  K = 0
  assign([B.sub(K+i*N) for i in range(dim*dim)], Bs)
  print assemble((B[:,:,K]-Bs)**2*dx) # Zero
answered May 27, 2015 by Øyvind Evju FEniCS Expert (17,700 points)
selected May 27, 2015 by Ianx86

It's working and I can see how. Thanks a lot for quick answer.

...