Affine transformation of function in Parallel

Hi, I want to do affine transformation of a function in parallel. Below is the sample code I am using from : Affine transformation: Translation X-Axis of Function
This works fine in serial but gives incorrect result in parallel.

from dolfin import * 
from dolfin_adjoint import *

import matplotlib.pyplot as plt
import numpy as np

lx = 1.0
xmin=0.0
xmax=1.0

mesh = UnitSquareMesh(16,16)
V = FunctionSpace(mesh,'CG', 1)

u_0 = interpolate(Expression("x[0]",degree=3), V)

# Shift spatially along x the dofs
b = lx/2.0 #shift along x-axis

class ShiftedExpr(UserExpression):
    def __init__(self,func,**kwargs):
        super().__init__(**kwargs)
        self.func = func
    def eval(self,values,x):
        x0_shift = x[0] - b
        if(x0_shift < xmin):
            x0_shift += lx
        x_shift = np.array([x0_shift,x[1]])
        values[0] = self.func(x_shift)
    def value_shape(self):
        return ()
    
u_1 = project(ShiftedExpr(u_0),V)

The problem in parallel seems to be in the line:
u_1 = project(ShiftedExpr(u_0),V)

How to interpolate between non-matching meshes in parallel? : I also tried to use transfer_function given in this link instead of project(), but it fails too.
Could this be resolved for parallel?

1 Like

I found that LagrangeInterpolator works in parallel as an alternative to interpolate or project for Lagrange functions as per this link: Function interpolation in parallel? - FEniCS Q&A
But, with LagrangeInterpolator used in parallel, my code is not completing.

Am I missing anything here?
Any help will be highly appreciated! Thanks!

After running in parallel, the code is stuck with the similar message shown below:
"Process 0: Computed bounding box tree with 249 nodes for 125 points.
Process 3: Building point search tree to accelerate distance queries.
Process 3: Computed bounding box tree with 263 nodes for 132 points. "

Here is the minimal test code that I am running in parallel.

from dolfin import * 
from dolfin_adjoint import *

import matplotlib.pyplot as plt
import numpy as np

lx = 1.0
xmin=0.0
xmax=1.0

mesh = UnitSquareMesh(16,16)
V = FunctionSpace(mesh,'CG', 1)

# u_0 = interpolate(Expression("x[0]",degree=3), V)

# Shift spatially along x the dofs
b = lx/2.0 #shift along x-axis

class ShiftedExpr(UserExpression):
    def __init__(self,func,**kwargs):
        super().__init__(**kwargs)
        self.func = func
    def eval(self,values,x):
        x0_shift = x[0] - b
        if(x0_shift < xmin):
            x0_shift += lx
        x_shift = np.array([x0_shift,x[1]])
        values[0] = self.func(x_shift)
    def value_shape(self):
        return ()
    
# u_1 = project(ShiftedExpr(u_0),V)

u_0= Function(V)
u_0.set_allow_extrapolation(True) 

u_1=Function(V)
LagrangeInterpolator.interpolate(u_1, ShiftedExpr(u_0))

1 Like