How can i cut a solution field from one problem and apply to another

I am solving two problems. The first is the steady-state flow in the tube. The second flow in a pipe with a more complex geometry. I want to take the velocity field from the first problem and set it as an initial condition for the second problem. How can i do this?

How are you expecting this to work? Is the complex geometry a sub-set of the simplified tube?

I would suggest you solve a Stokes-flow on the complex geometry to get an initial condition for the second problem.

I have tube R=1:

I solve Navie-stoks equation and get u field.
I want to take a field from the section z = 1 and solve a problem with a different geometry:

R=1 the radus are the same

i try this:

...
V = VectorFunctionSpace(mesh, "P", 1, constrained_domain=pbc)
P = FunctionSpace(mesh, "P", 1)
...
u_n = Function(V)
...
mesh_2 = Mesh()
with XDMFFile("mesh.xdmf") as infile:
    infile.read(mesh_2)
V_2 = VectorFunctionSpace(mesh_2, "P", 1)
P_2 = FunctionSpace(mesh_2, "P", 1)
class V0(UserExpression):
    def eval(self, values, x):
        values[0] = 0
        values[1] = 0
        values[2] = u_n([x[0], x[1], x[2]])
    def value_shape(self):
        return (3,)
vel = V0()
vel_2 = Function(V_2)
u_n.set_allow_extrapolation(True)
vel_2 = interpolate(vel, V_2)

But i have this mistake:

TypeError                                 Traceback (most recent call last)
TypeError: only size-1 arrays can be converted to Python scalars

The above exception was the direct cause of the following exception:

ValueError                                Traceback (most recent call last)
<ipython-input-44-bbea50705d89> in <module>
      2 vel_2 = Function(V_2)
      3 u_n.set_allow_extrapolation(True)
----> 4 vel_2 = interpolate(vel, V_2)

/usr/lib/petsc/lib/python3/dist-packages/dolfin/fem/interpolation.py in interpolate(v, V)
     69     # Compute interpolation
     70     if hasattr(v, "_cpp_object"):
---> 71         Pv.interpolate(v._cpp_object)
     72     else:
     73         Pv.interpolate(v)

/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/function.py in interpolate(self, u)
    381             self._cpp_object.interpolate(u._cpp_object)
    382         else:
--> 383             self._cpp_object.interpolate(u)
    384 
    385     def compute_vertex_values(self, mesh=None):

/usr/lib/petsc/lib/python3/dist-packages/dolfin/function/expression.py in wrapped_eval(self, values, x)
     51         # Wrap eval functions
     52         def wrapped_eval(self, values, x):
---> 53             self.user_expression.eval(values, x)
     54 
     55         def wrapped_eval_cell(self, values, x, cell):

<ipython-input-43-cf5e08782cda> in eval(self, values, x)
      3         values[0] = 0
      4         values[1] = 0
----> 5         values[2] = u_n([x[0], x[1], x[2]])
      6     def value_shape(self):
      7         return (3,)

ValueError: setting an array element with a sequence.

u_n is a solution from a vector function space, and thus the evaluated output is a vector, not a scalar value

I decided this problem:

...
V = VectorFunctionSpace(mesh, "P", 1, constrained_domain=pbc)
...
u_n = Function(V)
...
V_2 = VectorFunctionSpace(mesh_2, "P", 1)
...
bcu_inflow = DirichletBC(V_2, u_n, facet_domains_2, 12)

Where 12 is inlet surface. It’s work, but i don’t understand why it works.