[petsc-users] Options database in petsc4py
Matthew Knepley
knepley at gmail.com
Mon Oct 27 12:54:40 CDT 2025
On Mon, Oct 27, 2025 at 11:48 AM SCOTTO Alexandre <
alexandre.scotto at irt-saintexupery.com> wrote:
> Hello Matthew,
>
>
>
> I was indeed wondering if there was a clean way to match a given set of
> options to a specific KSP instance. Does the following makes sense:
>
> 1. Associate a given a KSP instance a unique string, e.g. “toto”
> and call ksp_1.setOptionsPrefix(“toto”)
>
> 2. Create an option database with corresponding prefix: options =
> Options(“toto_ksp_”)
>
> 3. Then a call to ksp_1.setFromOptions() will only consider entrees
> in the option database starting with “toto”
>
Yes, that is how it works, although you would need
sp_1.setOptionsPrefix(“toto_”)
Thanks,
Matt
> Regards,
>
> Alexandre.
>
>
>
> *De :* Matthew Knepley <knepley at gmail.com>
> *Envoyé :* lundi 27 octobre 2025 11:27
> *À :* SCOTTO Alexandre <alexandre.scotto at irt-saintexupery.com>
> *Cc :* petsc-users at mcs.anl.gov
> *Objet :* Re: [petsc-users] Options database in petsc4py
>
>
>
> On Mon, Oct 27, 2025 at 10:24 AM SCOTTO Alexandre via petsc-users <
> petsc-users at mcs.anl.gov> wrote:
>
> Dear PETSc Community,
>
>
>
> In my developments, I am managing possibly several KSP solvers with
> options handled by the Options database. During my tests, I encountered the
> following behavior:
>
>
>
> *Code*:
>
> options = PETSc.Options("ksp_")
>
> options.setValue("atol", 7e-8)
>
> options.view()
>
>
>
> options.clear()
>
> options.view()
>
>
>
> *Output*:
>
> #PETSc Option Table entries:
>
> -ksp_atol 7e-08 # (source: code)
>
> #End of PETSc Option Table entries
>
>
>
> #PETSc Option Table entries:
>
> -ksp_atol 7e-08 # (source: code)
>
> #End of PETSc Option Table entries
>
>
>
> It seems that the clear() method does not really clear the Option
> database. To ensure that the several KSP I deal with are set with their own
> options (without getting options from a KSP previously set), the only way I
> found was to explicitly call the delValue() method for all the option
> keys passed:
>
>
>
> 1. Iterate over a dictionary of options and use setValue(name,
> value)
>
> 2. Set the KSP with option database: KSP.setFromOptions()
>
> 3. Iterate over a the keys of the dictionary and use delValue(name)
> to effectively clear the option database.
>
>
>
> Does it seem normal to you, is there something I am missing out?
>
>
>
> That for pointing out this bug.
>
>
>
> However, I don't think I would manage options this way. We normally give
> each separate solver a new _prefix_, meaning a string that prefaces all its
> options. That way they do not collide.
>
>
>
> Thanks,
>
>
>
> Matt
>
>
>
> Regards,
>
> Alexandre Scotto.
>
>
>
>
> --
>
> 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://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!YMkD_E3cPBzKrGzS-WVqigVxG6DXZlQPuvqu6tLu_iC00xlFN2GbMAeTOK-jzVRPXE3L68ICKFUq6KCdZrvu$
> <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!YMkD_E3cPBzKrGzS-WVqigVxG6DXZlQPuvqu6tLu_iC00xlFN2GbMAeTOK-jzVRPXE3L68ICKFUq6Gif_7Bl$ >
>
--
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://urldefense.us/v3/__https://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!YMkD_E3cPBzKrGzS-WVqigVxG6DXZlQPuvqu6tLu_iC00xlFN2GbMAeTOK-jzVRPXE3L68ICKFUq6KCdZrvu$ <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!YMkD_E3cPBzKrGzS-WVqigVxG6DXZlQPuvqu6tLu_iC00xlFN2GbMAeTOK-jzVRPXE3L68ICKFUq6Gif_7Bl$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20251027/0fd7b085/attachment.html>
More information about the petsc-users
mailing list