Nodal value initialization in parallel for specific nodes

Good day and a warm new year to all,

I have a code, where I have the mesh changed in every iteration and the previous solution interpolated to the new mesh. In the new mesh, there are new elements added, which need to be initialized to a value, say T_init, which I presently do in the following way:

Here the Extrapolate_fn() takes the arguments, the functionspace in the new mesh; step data, the previous solution, and T_init the initial value for nodes that were added.

The newElement() returns true or false based on if the coordinate from previous mesh is in the new mesh, if not, the node is given a T_init value,

def Extrapolate_fn(Space,step,T1,T_init):
    T1_proj = Function(Space)
    LagrangeInterpolator.interpolate(T1_proj,T1)
    F  = T1_proj.vector().get_local()           # get a vector with the local components of T1 in mesh2
    X  = Space.tabulate_dof_coordinates()       # array of all nodes coordinates
    T2 = Function(Space)                        # create a new function in mesh2 for the output
    i  = 0                                      # index for element number
    for x in X:                                 # for each dof x in Space
        if newElement(x,step) == False:         # if x wasn't in mesh1, we give the value T_init to the new function T2
            F[i]=T_init
        i+=1
    T2.vector().set_local(F)                    # T2 is filled with the local components of F (T1 project on Space and the values added)
    return T2

This code works well in serial execution, but in parallel, this reinitalization crashes.
Is there a way I can reinitialization of nodes of a specific region in parallel?

Thank you!

Please make your code a minimal reproducible example. It is not clear where the parallel issue occurs for your current code snippet. See for instance: Read before posting: How do I get my question answered? - #4 by nate
for a list of minimal code examples.

Hi Dokken,

The following is the simplest example of my application. This runs well in serial but gives wrong solution in mpirun because of tabulate_dof_coordinates() and the for-loop that follows:

from dolfin import *

mesh    = UnitCubeMesh.create(8, 8, 8, CellType.Type.tetrahedron)

# Function to choose DOFs in a particular range
def newElement(x):
	if((x[0]>0.5)):
		return False
	return True

def Extrapolate_fn(Space,V1,V_value):
    V1_proj = Function(Space)
    LagrangeInterpolator.interpolate(V1_proj,V1)
    F  = V1_proj.vector().get_local()
    X  = Space.tabulate_dof_coordinates()
    V2 = Function(Space)
    i  = 0
    for x in X:
        if newElement(x) == False:
            F[i]=V_value
        i+=1
    V2.vector().set_local(F)
    return V2


InitialValue 	= Constant(10.0)
NewValue 		= Constant(20.0)

ScalarSpace = FunctionSpace(mesh,'CG',1)
Variable 	= Function(ScalarSpace)


# Initial Value of 10 being placed
Variable 	= project(InitialValue,ScalarSpace)


fileResults = XDMFFile("Output.xdmf")
fileResults.parameters["flush_output"] = True
fileResults.parameters["functions_share_mesh"] = True

# Final Value of 20 being placed in dofs with x[0] > 0.5 
NewVariable   	= Extrapolate_fn(ScalarSpace,Variable,NewValue)

# Writing output
NewVariable.rename("NewVariable","label")
fileResults.write(NewVariable,0)

Do you know if this can be made to run in parallel?