Re: [petsc-users] Applying Multi-Point-Constraints with SNES
Thanks Matt. To clarify, were you referring to the following section in DMPlexCreateBoxMesh_Tensor_SFC_Periodicity_Private()? PetscCall(DMPlexSetIsoperiodicFaceSF(dm, sfper)); PetscScalar t[4][4] = {{0}}; t[0][0] = 1; t[1][1] = 1; t[2][2] = 1; t[3][3] = 1; for (PetscInt i = 0; i < dim; i++) if (periodicity[i] == DM_BOUNDARY_PERIODIC) t[i][3] = upper[i] - lower[i]; PetscCall(DMPlexSetIsoperiodicFaceTransform(dm, [0][0])); In my understanding, DMPlexSetIsoperiodicFaceSF() defines the points where the constrains exists. The constrains are specified in t matrix and set by calling DMPlexSetIsoperiodicFaceTransform(). Is this correct? Does constraints set by this also apply to non-displacement DoFs? Our application is of phase-field fracture in elasticity so we have a scalar DoF on each vertices in addition to displacement field. In other words, the section has two fields, where displacement field has 2 DoFs and phase-field has 1 DoF. Thanks, Hongrui From: Matthew Knepley Sent: Thursday, July 6, 2023 3:34 PM To: Hongrui Yu Cc: petsc-users@mcs.anl.gov Subject: Re: [petsc-users] Applying Multi-Point-Constraints with SNES On Thu, Jul 6, 2023 at 3:40 PM Hongrui Yu mailto:yuhong...@utexas.edu> > wrote: Hello PETSc users, In our Finite Element application we would like to apply Multi-Point-Constraints to some vertices. In these Multi-Point-Constraints we force certain DoF in the following nodes to be the same as those in controlling nodes. We use DMPlex to store our mesh. I’m wondering what would be a good way to implement this together with SNES? Or is there an example that does similar thing? There is a simple thing that Jed implemented call "isoperiodicity" in plexsfc.c, and you can see him using it to define a periodic box in DMPlexCreateBoxMesh_Tensor_SFC_Periodicity_Private() You could use exactly this to define an affine relation between two dofs. Currently both right-hand-side and solution vectors in out application are created using DMCreateGlobalVec(). And we tried (unsuccessfully) to modify solution within FormRHS or FormJacobian routines but the solution vector seems to be read-only (for good reason). Is there a way to tell SNES about these constraints? Or perhaps one can somehow create a vector with only a subset of the DoFs (the actual “unknowns”)? Doing it as above will eliminate the constrained unknowns from the SNES automatically, so this will not be a concern. Thanks, Matt Thank you in advance for any help or advice! Hongrui -- What most experimenters take for granted before they begin their experiments is infinitely more interesting than any results to which their experiments lead. -- Norbert Wiener https://www.cse.buffalo.edu/~knepley/ <http://www.cse.buffalo.edu/~knepley/>
[petsc-users] Applying Multi-Point-Constraints with SNES
Hello PETSc users, In our Finite Element application we would like to apply Multi-Point-Constraints to some vertices. In these Multi-Point-Constraints we force certain DoF in the following nodes to be the same as those in controlling nodes. We use DMPlex to store our mesh. I'm wondering what would be a good way to implement this together with SNES? Or is there an example that does similar thing? Currently both right-hand-side and solution vectors in out application are created using DMCreateGlobalVec(). And we tried (unsuccessfully) to modify solution within FormRHS or FormJacobian routines but the solution vector seems to be read-only (for good reason). Is there a way to tell SNES about these constraints? Or perhaps one can somehow create a vector with only a subset of the DoFs (the actual "unknowns")? Thank you in advance for any help or advice! Hongrui
Re: [petsc-users] Abort SNES Mid-iteration
Thanks Barry, this is exactly what I was looking for! Hongrui From: Barry Smith Sent: Wednesday, July 5, 2023 8:23 PM To: Hongrui Yu Cc: petsc-users@mcs.anl.gov Subject: Re: [petsc-users] Abort SNES Mid-iteration I assume you want to stop the SNES solve, but you do not want the program to end immediately? Instead, you want SNESSolve() to end immediately with a very useful message? This is done with https://petsc.org/release/manualpages/SNES/SNESSetFunctionDomainError/#snessetfunctiondomainerror or https://petsc.org/release/manualpages/SNES/SNESSetJacobianDomainError/#snessetjacobiandomainerror In conjunction with using this, you must call https://petsc.org/release/manualpages/SNES/SNESGetConvergedReason/#snesgetconvergedreason immediately after each SNESSolve() and check if the reason is negative. The specific values <https://petsc.org/release/manualpages/SNES/SNESConvergedReason/> SNES_DIVERGED_FUNCTION_DOMAIN will be set if you had called SNESSetFunctionDomainError() and <https://petsc.org/release/manualpages/SNES/SNESConvergedReason/> SNES_DIVERGED_JACOBIAN_DOMAIN will be set if you had called SNESSetJacobianDomainError(). Also take a look at the Note in https://petsc.org/release/manualpages/SNES/SNESSetFunctionDomainError/#snessetfunctiondomainerror. This provides two alternatives to simply giving up on the nonlinear solve but provides ways to either bound the tentative solutions into their physical regime or to "nudge" the tentative solutions back into their physical regime. PETSc errors are hard, meaning when one is encountered the program ends! Thus one cannot use the error handler infrastructure to recover from errors, even user created errors; that is why we provide the SNES domain "error" mechanism since it does not involve the PETSc error handlers. Good luck. On Jul 5, 2023, at 8:54 PM, Hongrui Yu mailto:yuhong...@utexas.edu> > wrote: Hello PETSc users, I’d like to use the error handling mechanism to abort SNES mid-iteration if certain quantities become nonphysical by calling SETERRQ() inside FormFunction() or FormJacobian(). I’m wondering if users can define their own error handler routines to use with PetscPushErrorHandler() and PetscPopErrorHandler()? I’m also open to any suggestion on better ways to quit SNES mid-iteration. Thanks in advance for any help or advice! Hongrui
[petsc-users] Abort SNES Mid-iteration
Hello PETSc users, I'd like to use the error handling mechanism to abort SNES mid-iteration if certain quantities become nonphysical by calling SETERRQ() inside FormFunction() or FormJacobian(). I'm wondering if users can define their own error handler routines to use with PetscPushErrorHandler() and PetscPopErrorHandler()? I'm also open to any suggestion on better ways to quit SNES mid-iteration. Thanks in advance for any help or advice! Hongrui
Re: [petsc-users] Modifying Entries Tied to Specific Points in Finite Element Stiffness Matrix using DMPlex
Thank you for your reply! Unfortunately yes.. I’ll need to modify stiffness between nodes on the boundary so most of them are going to be in completely general location. I can create an IS after distribution using DMPlexCreatePointNumbering() but they are Global numbering. Is there a way to get a map from Natural numbering to Global numbering? I assume this is used somewhere in DMPlexNaturalToGlobal()? This way I can find the correct entry to modify. Thanks, Kevin > On Dec 9, 2022, at 09:10, Matthew Knepley wrote: > > >> On Thu, Dec 8, 2022 at 6:06 PM Hongrui Yu wrote: > >> Hello! I’m trying to adapt a serial Finite Element code using PETSc. In this >> code it reads in special stiffness terms between the boundary DoFs from an >> input file, and add them to corresponding locations in the global Jacobian >> matrix. >> > > Hmm, so in completely general locations, or on the diagonal? > >> I currently use a DM Plex object to store the mesh information. My >> understanding is that once the DM is distributed its points are renumbered >> across different ranks. >> > > That is true. > >> I wonder if there is a good way to find the corresponding entries that needs >> to be modified in the global Jacobian matrix? >> >> >> >> For Vectors I’m currently creating a Natural Vector and simply do >> DMPlexNaturalToGlobal. Is there a way to create a “Natural Mat” just like >> “Natural Vector” and then do some sort of NaturalToGlobal for this Mat? >> >> >> >> Any help would be highly appreciated! >> > > If it is completely general, this will take some coding. > > Thanks, > > Matt > >> Kevin >> > > > -- > What most experimenters take for granted before they begin their experiments > is infinitely more interesting than any results to which their experiments > lead. > -- Norbert Wiener > > https://www.cse.buffalo.edu/~knepley/
[petsc-users] Modifying Entries Tied to Specific Points in Finite Element Stiffness Matrix using DMPlex
Hello! I'm trying to adapt a serial Finite Element code using PETSc. In this code it reads in special stiffness terms between the boundary DoFs from an input file, and add them to corresponding locations in the global Jacobian matrix. I currently use a DM Plex object to store the mesh information. My understanding is that once the DM is distributed its points are renumbered across different ranks. I wonder if there is a good way to find the corresponding entries that needs to be modified in the global Jacobian matrix? For Vectors I'm currently creating a Natural Vector and simply do DMPlexNaturalToGlobal. Is there a way to create a "Natural Mat" just like "Natural Vector" and then do some sort of NaturalToGlobal for this Mat? Any help would be highly appreciated! Kevin