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

Interpolated Expression of dimension 4 to vector for following calculation

–1 vote

Hi everybody!!

I created a Mixed Function Space of dimension 4.

V_u = VectorElement("Lagrange", mesh.ufl_cell(), 1, 3)
V_theta = FiniteElement("Lagrange", mesh.ufl_cell(), 1)
V = FunctionSpace(mesh, V_u*V_theta)

(u, theta) = TrialFunctions(V)
(delta_u, delta_theta) = TestFunctions(V)

Then I interpolated the Expressions u_0, theta_0 and v_0 into this Mixed Function Space.

u_0 = Expression(("x[0]", "x[1]", "x[2]", "x[3]"), degree = 1)
u_n = interpolate(u_0, V)
theta_0 = Expression(("x[0]", "x[1]", "x[2]", "x[3]"), degree = 1)
theta_n = interpolate(theta_0, V)
v_0 = Constant((0.0, 0.0, 0.0, 0.0))
v_n = interpolate(v_0, V)

And this is the equation that has to be solved:

a = temp_0dtinner(beta(E, alpha), sym(grad(u)))delta_thetadx + dtc_Ethetadelta_thetadx + dtdtkappainner(grad(theta), grad(delta_theta))dx + dtdtinner(sym(grad(delta_u)), sigma(u, theta))dx + rohinner(delta_u, u)*dx

l = dtdtinner(r, delta_theta)dx + dtdtinner(q_p, delta_theta)ds(top) + dtdtinner(b, delta_u)dx + dtdtinner(t_p, delta_u)ds(top) + rohinner(delta_u, u_n)dx + dtrohinner(delta_u, v_n)dx + dtc_Einner(theta_n, delta_theta)dx + temp_0dtinner(beta(E, alpha), sym(grad(u_n)))delta_thetadx

The problem is, that u_n, theta_n and v_n is of dimension 4 because of the interpolation. So the inner product doesn't work with those factors because delta_u and delta_theta are vector-valued and I get a shape mismatch.

Can anybody please help me or has any idea how to get rid of this problem?

asked Jan 23, 2017 by Ulla FEniCS Novice (210 points)

1 Answer

+1 vote

First of all, please use the "coding" ability and do some formatting or it is very hard to help you. It should look like this (it's a copy from your post):

a = temp_0dtinner(beta(E, alpha), sym(grad(u)))delta_thetadx +\
      dtc_Ethetadelta_thetadx + dtdtkappainner(grad(theta), grad(delta_theta))dx +\
      dtdtinner(sym(grad(delta_u)), sigma(u, theta))dx + rohinner(delta_u, u)*dx

As you can see, even in "coding" format I can only imagine what you want to express in your weak form.

To the question:

  1. "that u_n, theta_n and v_n is of dimension 4 because of the interpolation"
    I disagree, they are of dimension 4 because of your expression:

    u_0 = Expression(("x[0]", "x[1]", "x[2]", "x[3]"), degree = 1)
    
  2. "because delta_u and delta_theta are vector-valued "
    I think in your implementation, delta_u is vector-valued and has dim=3, but delta_theta seems to be scalar-valued.

  3. Obviously, you get a shape mismatch - and thats good, because you made a mistake in implementing the weak form equation. You cannot compute the inner product of 2 vectors with different dimensions...

Solution: You can probably define a vector-valued and a scalar expression:

u_n_v = Expression(("x[0]", "x[1]", "x[2]"), degree = 1)
u_n_s = Expression(("x[3]"), degree = 1)

and use these two terms for the inner product computation, something like:

inner(delta_u, u_n_v)dx + inner(delta_theta, u_n_s)dx
answered Jan 24, 2017 by RR FEniCS User (3,330 points)
...