Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dokken/change of var #3

Merged
merged 8 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ description = "Finite element simulations of hydrogen transport"
readme = "README/md"
requires-python = ">=3.9"
license = { file = "LICENSE" }
dependencies = ["tqdm", "scifem>=0.2.8"]
dependencies = ["tqdm", "scifem>=0.2.13"]
classifiers = [
"Natural Language :: English",
"Topic :: Scientific/Engineering",
Expand Down
30 changes: 22 additions & 8 deletions src/festim/hydrogen_transport_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import tqdm.autonotebook
import ufl
from dolfinx import fem
from scifem import NewtonSolver
from scifem import BlockedNewtonSolver

import festim.boundary_conditions
import festim.problem
Expand Down Expand Up @@ -1209,18 +1209,32 @@ def mixed_term(u, v, n):
self.forms = dolfinx.fem.form(
[subdomain.F for subdomain in self.volume_subdomains],
entity_maps=entity_maps,
jit_options={
"cffi_extra_compile_args": ["-O3", "-march=native"],
"cffi_libraries": ["m"],
},
)
self.J = dolfinx.fem.form(
J,
entity_maps=entity_maps,
jit_options={
"cffi_extra_compile_args": ["-O3", "-march=native"],
"cffi_libraries": ["m"],
},
)
self.J = dolfinx.fem.form(J, entity_maps=entity_maps)

def create_solver(self):
self.solver = NewtonSolver(
self.solver = BlockedNewtonSolver(
self.forms,
self.J,
[subdomain.u for subdomain in self.volume_subdomains],
J=self.J,
bcs=self.bc_forms,
max_iterations=self.settings.max_iterations,
petsc_options=self.petsc_options,
)
self.solver.max_iterations = (self.settings.max_iterations,)
RemDelaporteMathurin marked this conversation as resolved.
Show resolved Hide resolved
jorgensd marked this conversation as resolved.
Show resolved Hide resolved
self.solver.convergence_criterion = self.settings.convergence_criterion
self.solver.atol = self.settings.atol
self.solver.rtol = self.settings.rtol

def create_flux_values_fenics(self):
"""For each particle flux create the ``value_fenics`` attribute"""
Expand Down Expand Up @@ -1279,8 +1293,8 @@ def iterate(self):

self.update_time_dependent_values()

# solve main problem
self.solver.solve(self.settings.atol, self.settings.rtol)
# Solve main problem
self.solver.solve()

# post processing
self.post_processing()
Expand Down Expand Up @@ -1308,7 +1322,7 @@ def run(self):
self.progress_bar.refresh() # refresh progress bar to show 100%
else:
# Solve steady-state
self.solver.solve(self.settings.rtol)
self.solver.solve()
self.post_processing()

def __del__(self):
Expand Down
7 changes: 7 additions & 0 deletions src/festim/settings.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Literal

import festim as F


Expand All @@ -14,6 +16,7 @@ class Settings:
Defaults to None
stepsize (festim.Stepsize, optional): stepsize for a transient
simulation. Defaults to None
convergence_criterion: resiudal or incremental (for Newton solver)

Attributes:
atol (float): Absolute tolerance for the solver.
Expand All @@ -23,6 +26,8 @@ class Settings:
final_time (float): Final time for a transient simulation.
stepsize (festim.Stepsize): stepsize for a transient
simulation.
convergence_criterion: resiudal or incremental (for Newton solver)

"""

def __init__(
Expand All @@ -33,13 +38,15 @@ def __init__(
transient=True,
final_time=None,
stepsize=None,
convergence_criterion: Literal["residual", "incremental"] = "residual",
) -> None:
self.atol = atol
self.rtol = rtol
self.max_iterations = max_iterations
self.transient = transient
self.final_time = final_time
self.stepsize = stepsize
self.convergence_criterion = convergence_criterion

@property
def stepsize(self):
Expand Down
6 changes: 3 additions & 3 deletions test/system_tests/test_multi_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def c_exact_bot_np(x):

my_model.temperature = 500.0 # lambda x: 300 + 10 * x[1] + 100 * x[0]

my_model.settings = F.Settings(atol=None, rtol=1e-5, transient=False)
my_model.settings = F.Settings(atol=1e-5, rtol=1e-5, transient=False)
my_model.exports = [
F.VTXSpeciesExport(f"u_{subdomain.id}.bp", field=H, subdomain=subdomain)
for subdomain in my_model.volume_subdomains
Expand Down Expand Up @@ -216,7 +216,7 @@ def test_1_material_discontinuous_version():

my_model.temperature = lambda x: 300 + 100 * x[0]

my_model.settings = F.Settings(atol=None, rtol=1e-5, transient=False)
my_model.settings = F.Settings(atol=1e-5, rtol=1e-5, transient=False)

my_model.exports = [
F.VTXSpeciesExport(
Expand Down Expand Up @@ -384,7 +384,7 @@ def test_2_mats_particle_flux_bc():

my_model.temperature = lambda x: 300 + 10 * x[1] + 100 * x[0]

my_model.settings = F.Settings(atol=None, rtol=1e-5, transient=False)
my_model.settings = F.Settings(atol=1e-5, rtol=1e-5, transient=False)

my_model.exports = [
F.VTXSpeciesExport(f"u_{subdomain.id}.bp", field=H, subdomain=subdomain)
Expand Down
Loading