libMesh / libmesh

libMesh github repository
http://libmesh.github.io
GNU Lesser General Public License v2.1
654 stars 286 forks source link

NullSpace for PETSc solver and periodic boundary conditions? #2258

Closed Laphet closed 5 years ago

Laphet commented 5 years ago

Hi,

I want to solve a PDE on a cube and the periodic conditions are imposed on all three opposite face pairs. This equation has a trivial constant solution and I can attach a NullSpace in PETSc solver, but how to implement this in LibMesh?

As a newbie, I also wonder whether there is a guide for setting periodic boundary conditions.

Thanks.

dknez commented 5 years ago

On Wed, Sep 25, 2019 at 10:15 AM Laphet notifications@github.com wrote:

Hi,

I want to solve a PDE on a cube and the periodic conditions are imposed on all three opposite face pairs. This equation has a trivial constant solution and I can attach a NullSpace in PETSc solver, but how to implement this in LibMesh?

As a newbie, I also wonder whether there is a guide for setting periodic boundary conditions.

Thanks.

In my opinion the nicest way to do this in libMesh would be to add a single SCALAR variable to your system which acts as a Lagrange multiplier that constrains your solution to have a zero average. An example of something similar to this is shown in systems_of_equations_ex5. This would remove the nullspace and would mean that you don't have to attach the NullSpace in PETSc.

If you prefer the PETSc NullSpace approach, though, then you can do that by writing explicit PETSc code (as part of your libMesh code) that attaches the NullSpace. You'd have to be familiar with PETSc in order to do that, but it should be relatively straightforward (I don't have an example of that though).

Best, David

jwpeterson commented 5 years ago

To follow up on what @dknez said, we have some support for specifying the nullspace for nonlinear problems. See, e.g. class ComputeVectorSubspace in include/systems/nonlinear_implicit_system.h and build_mat_null_space() in include/solvers/petsc_nonlinear_solver.h. Unfortunately, there does not seem to be an example or unit test of this capability anywhere, so I can't speak to its current status...

pbauman commented 5 years ago

To quickly chime in, if it’s just a constant null space, you can do this from the command line. -ksp_constant_null_space, don’t need to change code. Check out PETSc’s KSPSetFromOptions webpage.

On Sep 25, 2019, at 9:29 AM, John W. Peterson notifications@github.com wrote:

To follow up on what @dknez said, we have some support for specifying the nullspace for nonlinear problems. See, e.g. class ComputeVectorSubspace in include/systems/nonlinear_implicit_system.h and build_mat_null_space() in include/solvers/petsc_nonlinear_solver.h. Unfortunately, there does not seem to be an example or unit test of this capability anywhere, so I can't speak to its current status...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

Laphet commented 5 years ago

To quickly chime in, if it’s just a constant null space, you can do this from the command line. -ksp_constant_null_space, don’t need to change code. Check out PETSc’s KSPSetFromOptions webpage. On Sep 25, 2019, at 9:29 AM, John W. Peterson @.***> wrote: To follow up on what @dknez said, we have some support for specifying the nullspace for nonlinear problems. See, e.g. class ComputeVectorSubspace in include/systems/nonlinear_implicit_system.h and build_mat_null_space() in include/solvers/petsc_nonlinear_solver.h. Unfortunately, there does not seem to be an example or unit test of this capability anywhere, so I can't speak to its current status... — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

That is awesome! Thank you.

Laphet commented 5 years ago

Another question: I have generated a periodic mesh by Gmsh, which means the geometric relations on the opposite faces of the cube are same.

So what shall I do to constrain a pair of nodes with the same value?

Laphet commented 5 years ago

Hi, are there any tutorials for what I have mentioned?

Thanks.

jwpeterson commented 5 years ago

A cursory search suggests adaptivity_ex5, adjoints_ex1, miscellaneous_ex7, and systems_of_equations_ex9 all use periodic boundary conditions, so I'd start with one of those.