I'm currently working on a multi-scale method, which works roughly as follows. The initial problem is set over say, $\Omega = [0,1]\times[0,1]$, which is meshed with a coarse structured mesh (built with UnitSquareMesh
). In each rectangular cell $C$ of this mesh, one has to solve a sub-problem $P(C)$, which gives a solution $u_C$. This is done on a fine mesh (which meshes $C$). As several quantities/functions are cell independent, I solve all sub-problems on the same mesh, over say $[0, \epsilon] \times [0, \epsilon]$. Then, the $u_C$ s have to be stitched together to recover a function over $\Omega$.
What I'm trying to do at the moment is:
- Translate $u_C$ so that they are defined on the correct domain
- Extend them by zero to functions of $\Omega$.
- (Add them together, disregarding continuity issues)
I don't know how to do 1., more precisely, how can I define v
in the code below so that $v(x, y) = u(x-1, y-1) (= x-1)$ ?
mesh = UnitSquareMesh(10, 10)
translated_mesh = UnitSquareMesh(10, 10)
translated_mesh.coordinates()[:] = translated_mesh.coordinates()+1
V = FunctionSpace(mesh, "P", 1)
tV = FunctionSpace(translate_mesh, "P", 1)
u = Function(V)
u.interpolate(Expression('x[0]'))
v = Function(tV)
# v = ?
I have an idea about 2. although I am unable to make @mikael-mortensen's interpolation function work. Have I missed any obvious option/way to extend a function by zero over a non-matching domain, à la parameters['allow_extrapolation'] = True
, but without trying to be smart about the unknown values for the new functions ?
Thanks for any advice you might have, otherwise, thanks for reading this far ;)