[petsc-users] Options database in petsc4py
SCOTTO Alexandre
alexandre.scotto at irt-saintexupery.com
Mon Oct 27 05:48:43 CDT 2025
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”
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<mailto: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!ZnPxnrdflWTbGbGUEH1FqwWm8qDvjVXbO9Vcz0i-G4kvOUAXnvdAeosPUQrtGbXE74bfCgrSlkSnKeAt0Pd0lPTS4gzeowrsYHOBb_MjQw$ <https://urldefense.us/v3/__http://www.cse.buffalo.edu/*knepley/__;fg!!G_uCfscf7eWS!ZnPxnrdflWTbGbGUEH1FqwWm8qDvjVXbO9Vcz0i-G4kvOUAXnvdAeosPUQrtGbXE74bfCgrSlkSnKeAt0Pd0lPTS4gzeowrsYHPXgj5rjg$ >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20251027/b32e6c13/attachment-0001.html>
More information about the petsc-users
mailing list