[petsc-users] How to replace the default global database?
Barry Smith
bsmith at mcs.anl.gov
Mon May 29 13:31:13 CDT 2017
> On May 29, 2017, at 1:20 PM, Lucas Clemente Vella <lvella at gmail.com> wrote:
>
> Hi. Not really what I need. Every time I run my program, I need to pass the non-trivial solver setup that works as a command line argument (I am using Schur complement with BCGS and Hypre as internal KSP and PC). I want to hardcode the complex solver setup so that I can use it depending on a runtime switch. Like this:
>
> if(use_schur) {
> // change global PETSc options to the settings I know to work.
This is ok. You can use PetscOptionsSetValue() or PetscOptionsInsert() to put the values in.
> }
>
> my_solver_struct *s = create_petsc_solver();
>
> if(use_schur) {
> // restore original PETSc options.
> }
Why do you need to "restore original PETSc options" at this point? What are the options used for that they need to be reset? If they control other solvers, for example, then just give them a different prefix.
>
> 2017-05-26 19:55 GMT-03:00 Barry Smith <bsmith at mcs.anl.gov>:
>
> I do not think you want to do this. The standard way we handle what it seems you need is to use PetscObjectSetOptionsPrefix() for the different PETSc objects giving them different prefixes and then appending the prefix for the options when you provide them to the options database. For example if you have a KSP for a flow solver and a KSP for a pressure solver you might do
>
> KSPCreate(PETSC_COMM_WORLD,&flow);
> KSPSetOptionsPrefix(flow,"u");
>
> KSPCreate(PETSC_COMM_WORLD,&pressure);
> KSPSetOptionsPrefix(pressure,"p");
>
> and set options like
>
> -u_pc_type jacobi
>
> -p_pc_type gamg
>
> Will this do what you need?
>
> Barry
>
> Because the options data base can be accessed by any object at any time (not just when it is created), it doesn't make sense to change the default options database ever because it would be uncertain what objects the change affected or did not affect.
>
>
>
>
>
>
> > On May 26, 2017, at 4:20 PM, Lucas Clemente Vella <lvella at gmail.com> wrote:
> >
> > Here is what I want to do:
> > - Take the global PetscOptions and store it somewhere;
> > - Create my own PetscOptions;
> > - Populate it with my options;
> > - Set my new PetscOptions as the global default;
> > - Create some PETSc objects;
> > - Restore old PetscOptions as default global;
> > - Destroy the PetscOptions I created.
> >
> > I could not find a function to replace global PetscOptions, or to copy one PetscOptions to another. Is it possible to do what I want to do? How?
> >
> > --
> > Lucas Clemente Vella
> > lvella at gmail.com
>
>
>
>
> --
> Lucas Clemente Vella
> lvella at gmail.com
More information about the petsc-users
mailing list