Is there any effective way to reverse functions

Hello,

If I have the function f(x,y), and I want to get f(x,-y), is there any way to accomplish it effectively?

  1. This function is obtained by FEM so I don’t have the analytical expression of it, but only the discrete solution.
  2. The domain is completely symmetric.
  3. What I do is to extract the coordinates and function values, then I compare the coordinates one by one (a nested loop) to match the DOFs, the issues is that when I goes to 3D problem f(x,y,z)->f(x,-y,-z) , the computation becomes extremely expensive since the amount of DOFs is very high,

Does anyone have any suggestions regarding my problem? Thanks very much!

The domain may be symmetric, but is the mesh symmetric as well?

How many times do you have to do this? Only once, or several times?

  1. Yes the mesh is symmetric, I use quads and cubic element, so the mesh is structured and symmetric
  2. I need to do it several times(around 10)

A starting point could be that you use the non matching mesh interpolation: please search the forum for several questions and snippets on this. I’d expect that to be faster than your manually coded nested for loop.

If that is still not fast enough, you could exploit the fact that the (x,y) and (x, -y) meshes are actually matching. Prepare a dolfinx.fem.Function that contains as DOFs np.arange(0, # of dofs), and then apply the interpolation from (x, y) to (x, -y). If the meshes are truly matching, the result of the interpolation will still contain integer numbers, telling you for instance that DOF 2 in the (x,y) case corresponds to DOF 87 in the (x, -y) case. Once you have the result of the interpolation, you will have another vector which is a permutation of the original content, which was np.arange(0, # of dofs). Extract that vector as a numpy array, save it in a local variable, and use that local variable 10 times to permute the 10 solutions.

1 Like

Hello, I have tried to make this work, but unfornately it didn’t.

Could you tell me more details about this step, how could I interpolate from f(x,y) to f(x,-y), is this finished by the nonmatching mesh interpolation?

Thanks!

Please add the code you tried to write to implement that task. You waited one month and half to answer and I can honestly say I can’t remember anymore what the original question was :rofl:, but if you add the code it will be easier to remind myself (and everyone else reading these message) and start back.

I just found another way for my problem, but still thanks for you attention!