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

Is there a way to expand a 2D solution to 3D, then take it as the initial condition for a 3D simulation?

+1 vote

I am trying to take a 2D flow solution as the initial condition for the 3D flow simulation. Basically, I need to project the 2D solution profile U(x,y) along the addition z direction (e.g. circle into a cylinder), then take the projected 3D geometry as the initial condition for a new 3D simulation.

So two challenges here:

  1. how to expand a 2D solution (assume saved in a .xml file) to a projected 3D geometry?
  2. How to take this 3D geometry as the initial condition. Currently use Expression to define the IC in the 3D simulation, and it's working,

Any help/suggestions are appreciated.

asked Jun 13, 2014 by cutejeff FEniCS Novice (230 points)

1 Answer

0 votes

Hi, in the following I assume u is the 2d function loaded from file. To make it 3d consider

 from dolfin import *


class SymTransZ(Expression):
    'Given u: (x, y) --> R create v: (x, y, z) --> R, v(x, y, z) = u(x, y).'
    def __init__(self, u):
        self.u = u

    def eval(self, values, x):
        values[0] = self.u(x[0], x[1])

mesh2d = RectangleMesh(-1, -1, 1, 1, 8, 8)
V = FunctionSpace(mesh2d, 'CG', 1)
u = interpolate(Expression('x[0]*x[0] + x[1]*x[1]'), V)
plot(u)

mesh3d = BoxMesh(-1, -1, -1, 1, 1, 1, 16, 16, 5)
W = FunctionSpace(mesh3d, 'CG', 1)
U = SymTransZ(u)
v = interpolate(U, W)

plot(v)
interactive()

In you 3d simulation you would use v in the same way as the expression you mentioned.

answered Jun 14, 2014 by MiroK FEniCS Expert (80,920 points)
...