Multiple dof_to_vertex_map in parallel

I defined material properties by interpolating a .txt file on the mesh using dof_to_vertex_map. The txt file and the vertices of the mes have the same number of lines, otherwise it wouldn’t work.

Setting only one property, it works fine, either running not-parallel or parallel. When the second (and also the third) property is added from different .txt files, FEniCS returns the interpolate mesh corresponding to the very first .txt interpolate property.

the part of the script corresponding to this is:

FIRST PROPERTY INTERPOLATION

T = FunctionSpace(mesh, ‘CG’, 1)

local_range = T.dofmap().ownership_range()
local_dim = local_range[1] - local_range[0]
file_vals = open ( ‘E_FINE.txt’ )
list_vals = [ float ( line ) for line in file_vals.readlines() ]

array_vals = np.array ( list_vals)
E = Function ( T )
d2v = dof_to_vertex_map ( T )
global_vertex_numbers = mesh.topology().global_indices(0)
global_vertices = global_vertex_numbers[d2v[:local_dim]]
local_data = array_vals[global_vertices]
E.vector()[:] = local_data[:local_dim]
file = File (“./0/E.pvd”)
file << E

SECOND PROPERTY INTERPOLATION

TT = FunctionSpace(mesh, ‘CG’, 1)

local_range_nuu = TT.dofmap().ownership_range()
local_dim_nuu = local_range_nuu[1] - local_range_nuu[0]
file_vals_nuu = open ( ‘nu_tot.txt’ )
list_vals_nuu = [ float ( line ) for line in file_vals_nuu.readlines() ]
array_vals_nuu = np.array ( list_vals_nuu)

nuu = Function ( TT )
d2v_nuu = dof_to_vertex_map ( TT )
global_vertex_numbers_nuu = mesh.topology().global_indices(0)
global_vertices_nuu = global_vertex_numbers_nuu[d2v_nuu[:local_dim_nuu]]
local_data_nuu = array_vals[global_vertices_nuu]
nuu.vector()[:] = local_data_nuu[:local_dim_nuu]
file = File (“./1/nuu.pvd”)
file << nuu

What is the issue that I am missing? I searched through the topics, but I couldn’t manage.

I appreciate any help.
Thanks

1 Like

Could you provide a minimal working example?

I would also suggest you to use 3x` encapsulation (mardown syntax) to encapsulate your code and make it more readable to other users.

For further information on how to post a question, you can read the community guidelines.

1 Like

Hi,

The minimal code that I previously pasted is working, but it is not capturing the second property as it must be, instead it captures also the first interpolated property.

Thanks

What @CastriMik means by this could you provide a mesh and corresponding text files (preferrably a 1x1 unit square mesh) which you can reproduce the error with?

Hi, thank you for clarifying,

How do I attach my xml mesh file and the txt files here?

Thank you!

You can copy-paste the content of your txt in your message and encapsulating it with three backticks (```) above and below, or upload it on Github as a gist. For the mesh, try to reproduce the error with a 1x1 unit square mesh as @dokken suggested, so that it is easier to understand what the problem is. Then, upload your complete code, since the one above is incomplete (for instance, it does not show how you import the libraries and load the mesh).

Thank you so much!

I’ve uploaded the files of a minimal example here:

The real model is 3D and a bit complex, so a unit square mesh wouldn’t reproduce very well my problem.

Best.

both properties are the same, however they should be different, since the txt files are also different (different properties)

I am running in parallel because the real problem is more complex than a simple cube.

Thanks once again

I have not run your code, but at line 60 you are using array_vals instead of array_vals_nuu.

1 Like

Indeed!

Thank you so much!

Problem solved