Skip to content

Settings and Stepsize classes#616

Merged
jhdark merged 21 commits into
festim-dev:fenicsxfrom
jhdark:settings_stepsize
Oct 20, 2023
Merged

Settings and Stepsize classes#616
jhdark merged 21 commits into
festim-dev:fenicsxfrom
jhdark:settings_stepsize

Conversation

@jhdark
Copy link
Copy Markdown
Collaborator

@jhdark jhdark commented Oct 19, 2023

Proposed changes

With this change, users can directly alter the parameters of the solver: the absolute and relative tolerance, the maximum iterations and final time of a transient simulations. The stepsize will be defined in its own class stepsize as this will likely evolve to something very similar to festim in its current version (v0.11.0). Stepsize will be an attribute of F.Settings.

Usage:

my_model.settings = F.Settings(
        absolute_tolerance=1e10,
        relative_tolerance=1e-10,
        max_iterations=30,
        final_time=50,
    )

and for stepsize:

my_model.settings.stepsize = F.Stepsize(initial_value=1 / 20)

Additional solver modifications can be made after the initialisation of the simulation for more niche cases:

   my_model.settings = F.Settings(
        absolute_tolerance=1e10,
        relative_tolerance=1e-10,
        max_iterations=30,
        final_time=50,
    )

  my_model.initialise()

  my_model.solver.convergence_criterion = "incremental"
  ksp = my_model.solver.krylov_solver
  opts = PETSc.Options()
  option_prefix = ksp.getOptionsPrefix()
  opts[f"{option_prefix}ksp_type"] = "cg"
  opts[f"{option_prefix}pc_type"] = "gamg"
  opts[f"{option_prefix}pc_factor_mat_solver_type"] = "mumps"
  ksp.setFromOptions()

Types of changes

What types of changes does your code introduce to FESTIM?

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code refactoring
  • Documentation Update (if none of the other choices apply)
  • New tests

Checklist

  • Black formatted
  • Unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@jhdark jhdark added enhancement New feature or request fenicsx Issue that is related to the fenicsx support labels Oct 19, 2023
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 19, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b26c407) 96.98% compared to head (bf61b3a) 97.47%.
Report is 11 commits behind head on fenicsx.

Additional details and impacted files
@@             Coverage Diff             @@
##           fenicsx     #616      +/-   ##
===========================================
+ Coverage    96.98%   97.47%   +0.48%     
===========================================
  Files           13       16       +3     
  Lines          398      475      +77     
===========================================
+ Hits           386      463      +77     
  Misses          12       12              
Files Coverage Δ
festim/__init__.py 75.00% <100.00%> (+3.00%) ⬆️
festim/hydrogen_transport_problem.py 97.79% <100.00%> (+0.01%) ⬆️
festim/reaction.py 100.00% <100.00%> (ø)
festim/settings.py 100.00% <100.00%> (ø)
festim/species.py 96.96% <100.00%> (+8.08%) ⬆️
festim/stepsize.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Collaborator

@RemDelaporteMathurin RemDelaporteMathurin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round of comments

Comment thread festim/hydrogen_transport_problem.py Outdated
Comment thread festim/hydrogen_transport_problem.py Outdated
Comment thread festim/settings.py Outdated
Comment thread festim/settings.py Outdated
Comment thread festim/settings.py Outdated
Comment thread festim/stepsize.py Outdated
Comment thread festim/settings.py Outdated
jhdark and others added 4 commits October 19, 2023 17:09
Co-authored-by: Rémi Delaporte-Mathurin <40028739+RemDelaporteMathurin@users.noreply.github.com>
Co-authored-by: Rémi Delaporte-Mathurin <40028739+RemDelaporteMathurin@users.noreply.github.com>
Comment thread festim/hydrogen_transport_problem.py
Comment thread festim/stepsize.py
Comment thread festim/settings.py Outdated
Comment thread test/test_settings.py Outdated
@jhdark jhdark merged commit 6f627cd into festim-dev:fenicsx Oct 20, 2023
@jhdark jhdark deleted the settings_stepsize branch October 20, 2023 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fenicsx Issue that is related to the fenicsx support

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants