Calculate reaction force: sum operation in parallel

Hello everyone,

I am trying to calculate the reaction force for a set of DOFs in a hyperelasticity problem. This is how I am calculating it:

R = derivative(Pi, u, v)  #Pi is the total potential energy     
b=assemble(-R)
fint=b.copy()
Reaction=sum(fint[y_dofs_top])   #y_dofs_top is the set of DOFs where Dirichlet BCs are applied

This works perfectly fine in serial. In parallel however, each process calculates its own sum. How can I do the sum in parallel?

I am using a singularity image of FEniCS on a cluster.
Thank you in advance!

Aditya

1 Like

You should be able to use MPI.sum() to sum over processes.

1 Like

Thank for your reply Chris. I have tried MPI.sum actually in the following way:

Reaction=MPI.sum(MPI.comm_world , fint[y_dofs_top])

but that gives an error:

TypeError: sum(): incompatible function arguments. The following argument types are supported:
    1. (arg0: MPICommWrapper, arg1: float) -> float
    2. (arg0: MPICommWrapper, arg1: dolfin::Table) -> dolfin::Table

I have not been to able to figure out how to convert my array into dolfin::Table format. Can you help me with that.

Thanks again!

1 Like

Table is not what you want. Dolfin’s MPI.sum() really only takes float…

1 Like

I made it work. I was confused about float because MPI.sum was not accepting an array/list of floats. But then I tried the following (which is not very intuitive to me) and it worked:

reac=sum(fint[y_dofs_top])
Reaction=MPI.sum(MPI.comm_world, reac)

Thank you for your help!

1 Like