# Linear problem depending on a nonlinear solution and an eigenmode, in parallel

Hello,

I am using two codes, in parallel:

• one to solve with PETSc (`SNESSolve`) a nonlinear problem → let’s call the solution u,
• one to solve with SLEPc complex (`EPSSolve`) an eigenvalue problem that depends on u → let’s call the eigenmode v.

This is working correctly.

Now, I would like to use a third code to solve another (linear) problem that depends on both u and v. I have tried to define and solve the problem naively with `problem`. I do obtain a solution, but it seems that the original partition is not preserved correctly: saving the solution with `savevtk` and visualizing it in Paraview shows something that is messed up (I’m using the exact same `savevtk` command as for u and v).

I’m not sure what is the best way to do that. Should I use `varf` instead of `problem`? Do I need PETSc? Some advice and/or an example would be very helpful.

Thank you!

It all depends on what you are solving, how you are saving `u` and `v`, so on and so forth. There are too little details in your question to give you an appropriate answer. You could just do as in FreeFem-sources/navier-stokes-2d-PETSc.edp at master · FreeFem/FreeFem-sources · GitHub and FreeFem-sources/navier-stokes-2d-SLEPc-complex.edp at master · FreeFem/FreeFem-sources · GitHub. In your third script, use the same routines as in `navier-stokes-2d-SLEPc-complex.edp`.

Thank you for the prompt reply.

I’m trying to follow exactly `navier-stokes-2d-SLEPc-complex.edp`. In line 19, does it make a difference whether one uses `mesh Th;` or `meshN Th;`? In the latter case, line 21 `loadDmesh(Th, ...)` works, but in the former case it yields an error:

– FreeFem++ v4.9 (Fri Jun 18 14:45:02 CEST 2021 - git v4.9)
Load: lg_fem lg_mesh lg_mesh3 eigenvalue parallelempi
load: init metis (v 5 )
error operator = PPKN5Fem2D4MeshE, N5Fem2D5Mesh3E
(…)
Error line number 465, in file macro: loadDmesh in /home/FreeFem/lib/ff++/4.9/idp/macro_ddm.idp, before token ;

`meshN` is a template-like type that will automatically translate to `mesh` or `mesh3`, depending on whether you define `macro dimension()2//` or `macro dimension()3//` before the inclusion of `macro_ddm.idp`. So, yes, it makes a difference if you are doing 3D. Otherwise, no difference. The type `N5Fem2D5Mesh3E` from your log indicates that you are doing 3D, so switch to either `meshN Th` or `mesh3 Th`.

Thank you, that makes perfect sense.

1. Now I’m trying to solve the linear system. What should I use? (You suggested I use the same routines as in `navier-stokes-2d-SLEPc-complex.edp`, but those are for an eigenvalue problem. And those in `navier-stokes-2d-PETSc.edp` are for a non-linear system.)

2. I don’t seem to be able to mix real and complex quantities. In my case u is real and v is complex. Should I define everything as complex?

1. `KSPSolve()` or `^-1` directly.
2. if you want everything in a single script, then yes, you’ll need to stick to complexes all the way.

Thank you, `KSPSolve()` seems to be working!