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

Use tensor from previous iteration

0 votes

Hi everyone,

I'm very new to fenics, and am trying to put together a stokes flow model using a maxwell material model. The constitutive law requires a time derivative of the stress tensor. It seems straightforward enough to use a first order finite difference of the tensor for time-stepping, but I'm having trouble saving the tensor value for use in the next time step.

I tried initializing the tensor to zero for the first iteration:

sig1 = Constant(0.0)*Identity(mesh.ufl_domain().geometric_dimension())

and then updating it during each time step with the new solution:

...
for t in range(n_steps):
    ...
    solve(A, U.vector(), b)

    u, p = U.split()
    sig1 = K*(sym(grad(u)) + sig1/(E*dt))
    ...

But that just extends the UFL representation to include the old sig1 value. After a few timesteps sig1 gets unreasonably huge and causes problems (of course).

Is there a way to project the tensor into the FE space, and store its numerical representation for use in the next time step, rather than its UFL form? I'm sure there's an obvious best practices (i.e. correct) way to deal with this, but I'm not sure what it is. Any tips would be appreciated.

Thanks in advance for your time!!

asked Nov 15, 2016 by jperryhouts FEniCS Novice (160 points)

1 Answer

0 votes

I found something that works! Turns out I just needed to project the previous time step's stress tensor into a tensor function space, e.g:

TE = TensorElement('DG', triangle, 2, symmetry=True)
T   = FunctionSpace(mesh, TE)
...
I = Identity(mesh.ufl_domain().geometric_dimension())
sig1 = project(Constant(0.0)*I, T)

...
for t in ...:
    ...
    solve(A, U.vector(), b)

    u, p = U.split()
    sig1 = project(K * (sym(grad(u)) + sig/(E*dt)), T)
    ...

There's probably a better way, and I'd still welcome suggestions, but this seems to work for now.

answered Nov 16, 2016 by jperryhouts FEniCS Novice (160 points)
...