@@ -119,6 +119,45 @@ def define_boundary_conditions(self):
119119 form = self .create_dirichletbc_form (bc )
120120 self .bc_forms .append (form )
121121
122+ def get_petsc_options (self ) -> dict [str , Any ]:
123+ """
124+ Gets the PETSc options to pass to the NewtonProblem solver. Default
125+ options are updated with user-provided options, if any.
126+
127+ Returns:
128+ the petsc options to pass to the NewtonProblem solver.
129+ """
130+ petsc_options = get_default_petsc_options ()
131+
132+ # Update default PETSc options with user-provided options, if any
133+ if self .petsc_options :
134+ petsc_options .update (self .petsc_options )
135+
136+ if self .petsc_options :
137+ if (
138+ "snes_atol" in self .petsc_options
139+ or "snes_rtol" in self .petsc_options
140+ or "snes_max_it" in self .petsc_options
141+ ):
142+ warnings .warn (
143+ "You have set one of the following PETSc options: snes_atol, "
144+ "snes_rtol or snes_max_it. These options will be overwritten by "
145+ "the values in festim.Settings (atol, rtol and max_iterations) to "
146+ "ensure consistency between different versions of dolfinx. If you "
147+ "want to set these options manually, please set them in "
148+ "festim.Settings and not in the petsc_options dictionary."
149+ )
150+
151+ petsc_options .update (
152+ {
153+ "snes_atol" : self .settings .atol ,
154+ "snes_rtol" : self .settings .rtol ,
155+ "snes_max_it" : self .settings .max_iterations ,
156+ }
157+ )
158+
159+ return petsc_options
160+
122161 def create_solver (self ):
123162 """Creates the solver of the model"""
124163
@@ -160,33 +199,7 @@ def create_solver(self):
160199 elif Version (dolfinx .__version__ ) > Version ("0.9.0" ):
161200 from dolfinx .fem .petsc import NonlinearProblem
162201
163- petsc_options = get_default_petsc_options ()
164-
165- # Update default PETSc options with user-provided options, if any
166- if self .petsc_options :
167- petsc_options .update (self .petsc_options )
168-
169- if (
170- "snes_atol" in self .petsc_options
171- or "snes_rtol" in self .petsc_options
172- or "snes_max_it" in self .petsc_options
173- ):
174- warnings .warn (
175- "You have set one of the following PETSc options: snes_atol, "
176- "snes_rtol or snes_max_it. These options will be overwritten by "
177- "the values in festim.Settings (atol, rtol and max_iterations) to "
178- "ensure consistency between different versions of dolfinx. If you "
179- "want to set these options manually, please set them in "
180- "festim.Settings and not in the petsc_options dictionary."
181- )
182- petsc_options .update (
183- {
184- "snes_atol" : self .settings .atol ,
185- "snes_rtol" : self .settings .rtol ,
186- "snes_max_it" : self .settings .max_iterations ,
187- }
188- )
189-
202+ petsc_options = self .get_petsc_options ()
190203 self .solver = NonlinearProblem (
191204 self .formulation ,
192205 self .u ,
0 commit comments