Skip to content

Commit

Permalink
petsc_options as args
Browse files Browse the repository at this point in the history
  • Loading branch information
RemDelaporteMathurin committed Oct 31, 2024
1 parent 013937a commit 364a1b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __init__(
settings=None,
exports=None,
traps=None,
petsc_options=None,
):
super().__init__(
mesh=mesh,
Expand All @@ -157,6 +158,7 @@ def __init__(
subdomains=subdomains,
boundary_conditions=boundary_conditions,
settings=settings,
petsc_options=petsc_options,
)

self.species = species or []
Expand Down
18 changes: 14 additions & 4 deletions src/festim/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ufl
from dolfinx import fem
from dolfinx.nls.petsc import NewtonSolver
from petsc4py import PETSc

import festim as F
from festim.mesh.mesh import Mesh as _Mesh
Expand Down Expand Up @@ -41,7 +42,7 @@ def __init__(
subdomains=None,
boundary_conditions=None,
settings=None,
petcs_options=None,
petsc_options=None,
) -> None:
self.mesh = mesh
# for arguments to initialise as empty list
Expand All @@ -60,7 +61,7 @@ def __init__(
self.formulation = None
self.bc_forms = []
self.show_progress_bar = True
self.petcs_options = petcs_options
self.petsc_options = petsc_options

@property
def volume_subdomains(self):
Expand Down Expand Up @@ -123,12 +124,21 @@ def create_solver(self):
self.solver.rtol = self.settings.rtol
self.solver.max_it = self.settings.max_iterations

if self.petcs_options is None:
ksp = self.solver.krylov_solver
ksp = self.solver.krylov_solver

if self.petsc_options is None:
ksp.setType("preonly")
ksp.getPC().setType("lu")
ksp.getPC().setFactorSolverType("mumps")
ksp.setErrorIfNotConverged(True)
else:
# Set PETSc options
opts = PETSc.Options()
for k, v in self.petsc_options.items():
opts[k] = v
ksp.setFromOptions()

print(opts)

def run(self):
"""Runs the model"""
Expand Down

0 comments on commit 364a1b9

Please sign in to comment.