From eda42ac22c8615e86236bb77f22303e23422cde9 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Mon, 10 Jun 2024 14:53:08 +0200 Subject: [PATCH 1/8] started adding codetest blocks --- docs/environment.yml | 1 + docs/source/userguide/boundary_conditions.rst | 28 +++++---- .../userguide/export_post_processing.rst | 61 +++++++++++++------ docs/source/userguide/initial_conditions.rst | 10 +-- docs/source/userguide/materials.rst | 8 ++- docs/source/userguide/mesh.rst | 28 +++++++-- docs/source/userguide/newton_solver.rst | 14 +++-- 7 files changed, 104 insertions(+), 46 deletions(-) diff --git a/docs/environment.yml b/docs/environment.yml index 42892d354..5fe2f5baa 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -8,6 +8,7 @@ dependencies: - pip>=20.1 - sphinx==7 - folium + - numpy==1.24 - pip: - sympy - sphinx_book_theme==1.1.0rc1 diff --git a/docs/source/userguide/boundary_conditions.rst b/docs/source/userguide/boundary_conditions.rst index 355148a0d..962c271c3 100644 --- a/docs/source/userguide/boundary_conditions.rst +++ b/docs/source/userguide/boundary_conditions.rst @@ -3,6 +3,10 @@ Boundary conditions =================== +.. testsetup:: BCs + + from festim import * + The boundary conditions (BCs) are essential to FESTIM simulations. They describe the mathematical problem at the boundaries of the simulated domain. If no BC is set on a boundary, it is assumed that the flux is null. This is also called a symmetry BC. @@ -16,7 +20,7 @@ Imposing the solution The value of solutions (concentration, temperature) can be imposed on boundaries with :class:`festim.DirichletBC`: -.. code-block:: python +.. testcode:: BCs my_bc = DirichletBC(surfaces=[2, 4], value=10, field=0) @@ -26,7 +30,7 @@ The value of solutions (concentration, temperature) can be imposed on boundaries The `value` argument can be space and time dependent by making use of the FESTIM variables ``x``, ``y``, ``z`` and ``t``: -.. code-block:: python +.. testcode:: BCs from festim import x, y, z, t my_bc = DirichletBC(surfaces=3, value=10 + x**2 + t, field="T") @@ -34,7 +38,7 @@ The `value` argument can be space and time dependent by making use of the FESTIM To use more complicated mathematical expressions, you can use the sympy package: -.. code-block:: python +.. testcode:: BCs from festim import x, y, z, t import sympy as sp @@ -45,7 +49,7 @@ To use more complicated mathematical expressions, you can use the sympy package: The value of the concentration field can be temperature-dependent (useful when dealing with heat-transfer solvers) with :class:`festim.CustomDirichlet`: -.. code-block:: python +.. testcode:: BCs def value(T): return 3*T + 2 @@ -58,14 +62,14 @@ Imposing the flux When the flux needs to be imposed on a boundary, use the :class:`festim.FluxBC` class. -.. code-block:: python +.. testcode:: BCs my_bc = FluxBC(surfaces=3, value=10 + x**2 + t, field="T") As for the Dirichlet boundary conditions, the flux can be dependent on temperature and mobile hydrogen concentration: -.. code-block:: python +.. testcode:: BCs def value(T, mobile): return mobile**2 + T @@ -85,7 +89,7 @@ Recombination flux A recombination flux can be set on boundaries as follows: :math:`Kr \, c_\mathrm{m}^n` (See :class:`festim.RecombinationFlux`). Where :math:`Kr` is the recombination coefficient, :math:`c_\mathrm{m}` is the mobile hydrogen concentration and :math:`n` is the recombination order. -.. code-block:: python +.. testcode:: BCs my_bc = RecombinationFlux(surfaces=3, Kr_0=2, E_Kr=0.1, order=2) @@ -96,7 +100,7 @@ Dissociation flux Dissociation flux can be set on boundaries as: :math:`Kd \, P` (see :class:`festim.DissociationFlux`). Where :math:`Kd` is the dissociation coefficient, :math:`P` is the partial pressure of hydrogen. -.. code-block:: python +.. testcode:: BCs my_bc = DissociationFlux(surfaces=2, Kd_0=2, E_Kd=0.1, P=1e05) @@ -106,7 +110,7 @@ Sievert's law of solubility Impose the mobile concentration of hydrogen as :math:`c_\mathrm{m} = S(T) \sqrt{P}` where :math:`S` is the Sievert's solubility and :math:`P` is the partial pressure of hydrogen (see :class:`festim.SievertsBC`). -.. code-block:: python +.. testcode:: BCs from festim import t @@ -119,7 +123,7 @@ Henry's law of solubility Similarly, the mobile concentration can be set from Henry's law of solubility :math:`c_\mathrm{m} = K_H P` where :math:`K_H` is the Henry solubility (see :class:`festim.HenrysBC`). -.. code-block:: python +.. testcode:: BCs from festim import t @@ -131,7 +135,7 @@ Plasma implantation approximation Plasma implantation can be approximated by a Dirichlet boundary condition with the class :class:`festim.ImplantationDirichlet` . Refer to the :ref:`theory` section for more details. -.. code-block:: python +.. testcode:: BCs from festim import t @@ -151,7 +155,7 @@ Heat transfer BCs A convective heat flux can be set as :math:`\mathrm{flux} = - h (T - T_\mathrm{ext})` (see :class:`festim.ConvectiveFlux`). -.. code-block:: python +.. testcode:: BCs from festim import t diff --git a/docs/source/userguide/export_post_processing.rst b/docs/source/userguide/export_post_processing.rst index 6f1a597bf..b88da35c1 100644 --- a/docs/source/userguide/export_post_processing.rst +++ b/docs/source/userguide/export_post_processing.rst @@ -24,12 +24,13 @@ The most straightforward way to export solutions (concentrations, temperature) w This class leverages the ``XDMFFile`` class of ``fenics`` and allows solutions to be exported in the XDMF format. The following example shows how to export the solution of a 1D problem: -.. code-block:: python +.. testcode:: import festim as F + import numpy as np my_model = F.Simulation() - my_model.mesh = F.MeshFromVertices([0, 1, 2, 3]) + my_model.mesh = F.MeshFromVertices(np.linspace(0, 1, 60)) my_model.materials = F.Material(id=1, D_0=1, E_D=0) my_model.boundary_conditions = [ F.DirichletBC(surfaces=[1, 2], value=0, field="solute"), @@ -54,6 +55,11 @@ The following example shows how to export the solution of a 1D problem: my_model.initialise() my_model.run() +.. testoutput:: + :options: +ELLIPSIS + :hide: + + ... Running this should produce a file called ``mobile_conc.xdmf`` in the current directory. The file can then be opened in Paraview or any other software that can read XDMF files. @@ -63,7 +69,7 @@ It is possible to change this behaviour to limit the number of times the file is By setting the ``mode`` attribute to ``10``, for example, the solution will be exported every 10 timesteps. Setting it to ``last`` will export the solution only at the last timestep. -.. code-block:: python +.. testcode:: my_model.exports = [ F.XDMFExport( @@ -75,7 +81,7 @@ Setting it to ``last`` will export the solution only at the last timestep. ) ] -The ``checkpoint`` attribute must be set to ``True`` for the XDMF file to be readable by Paraveiw. +The ``checkpoint`` attribute must be set to ``True`` for the XDMF file to be readable by Paraview. ^^^^^^^^^^^^^^^ TXT export (1D) @@ -84,7 +90,7 @@ TXT export (1D) The ``TXTExport`` class allows solutions to be exported in a simple text format. It works in 1D only. For multi-dimensional problems, use the :class:`festim.XDMFExport` class instead. -.. code-block:: python +.. testcode:: import festim as F @@ -95,7 +101,7 @@ This file will contain the solution of the ``solute`` field at the degrees of fr To only export at specific times in the simulation, use the ``times`` argument: -.. code-block:: python +.. testcode:: my_export = F.TXTExport( field="solute", filename="./mobile_conc.txt", times=[0, 1, 2, 3] @@ -108,7 +114,7 @@ Point value If information about the solution at a specific point is needed, the :class:`festim.PointValue` class can be used. It is implemented as a derived quantity. See :ref:`Derived quantities` for more information. Here are a few examples: -.. code-block:: python +.. testcode:: import festim as F @@ -129,7 +135,7 @@ First, you want to create a :class:`festim.DerivedQuantities` object. This will Then, you can add the derived quantities you want to compute to this object. Finally, you can add the :class:`festim.DerivedQuantities` object to the simulation object. -.. code-block:: python +.. testcode:: my_derived_quantities = F.DerivedQuantities( [ @@ -140,7 +146,7 @@ Finally, you can add the :class:`festim.DerivedQuantities` object to the simulat ] ) - my_model.exports = [my_derived_quantities, ....] + my_model.exports = [my_derived_quantities] The complete list of derived quantities can be found at: :ref:`Exports`. @@ -148,18 +154,18 @@ The complete list of derived quantities can be found at: :ref:`Exports`. The data can be accessed in three different ways: - directly from the :class:`festim.DerivedQuantities` (plural) object: -.. code-block:: python +.. testcode:: my_derived_quantities = F.DerivedQuantities( [ F.SurfaceFlux(field="solute", surface=3), - F.SurfaceFlux(field="T", surface=1), + F.AverageVolume(field="T", volume=1), F.AverageVolume(field="retention", volume=1), F.TotalVolume(field="retention", volume=2), ] ) - my_model.exports = [my_derived_quantities, ....] + my_model.exports = [my_derived_quantities] my_model.initialise() my_model.run() @@ -167,22 +173,28 @@ The data can be accessed in three different ways: print(my_derived_quantities.t) print(my_derived_quantities.data) +.. testoutput:: + :options: +ELLIPSIS + :hide: + + ... + - from the :class:`festim.DerivedQuantity` (singular) object (eg. ``F.SurfaceFlux(...)``): -.. code-block:: python +.. testcode:: flux_surf_3 = F.SurfaceFlux(field="solute", surface=3) my_derived_quantities = F.DerivedQuantities( [ flux_surf_3, - F.SurfaceFlux(field="T", surface=1), + F.AverageVolume(field="T", volume=1), F.AverageVolume(field="retention", volume=1), F.TotalVolume(field="retention", volume=2), ] ) - my_model.exports = [my_derived_quantities, ....] + my_model.exports = [my_derived_quantities] my_model.initialise() my_model.run() @@ -191,25 +203,36 @@ The data can be accessed in three different ways: print(flux_surf_3.data) print(my_derived_quantities[2].data) +.. testoutput:: + :options: +ELLIPSIS + :hide: + + ... + - export and read from a .csv file: -.. code-block:: python +.. testcode:: my_derived_quantities = F.DerivedQuantities( [ F.SurfaceFlux(field="solute", surface=3), - F.SurfaceFlux(field="T", surface=1), + F.AverageVolume(field="T", volume=1), F.AverageVolume(field="retention", volume=1), F.TotalVolume(field="retention", volume=2), ], filename="./my_derived_quantities.csv", ) - my_model.exports = [my_derived_quantities, ....] + my_model.exports = [my_derived_quantities] my_model.initialise() my_model.run() +.. testoutput:: + :options: +ELLIPSIS + :hide: + + ... By default, the derived quantities will be computed at each timestep and exported at the last timestep. This behaviour can be changed by setting the ``nb_iterations_between_compute`` and ``nb_iterations_between_exports`` attributes of the :class:`festim.DerivedQuantities` object. @@ -219,7 +242,7 @@ This behaviour can be changed by setting the ``nb_iterations_between_compute`` a my_derived_quantities = F.DerivedQuantities( [ F.SurfaceFlux(field="solute", surface=3), - F.SurfaceFlux(field="T", surface=1), + F.AverageVolume(field="T", volume=1), F.AverageVolume(field="retention", volume=1), F.TotalVolume(field="retention", volume=2), ], diff --git a/docs/source/userguide/initial_conditions.rst b/docs/source/userguide/initial_conditions.rst index 11f590a36..ec2ec76f1 100644 --- a/docs/source/userguide/initial_conditions.rst +++ b/docs/source/userguide/initial_conditions.rst @@ -6,7 +6,7 @@ The initial conditions are essential to transient FESTIM simulations. They descr By default, the initial conditions are set to zero. However, it is possible to set the initial conditions with the :class:`festim.InitialCondition` class. -.. code-block:: python +.. testcode:: import festim as F @@ -14,7 +14,7 @@ However, it is possible to set the initial conditions with the :class:`festim.In The value can also be a function of space: -.. code-block:: python +.. testcode:: import festim as F from festim import x, y, z @@ -23,14 +23,14 @@ The value can also be a function of space: Initial conditions can also be read from a previously written XDMF file. This is useful when restarting a simulation. -.. code-block:: python +.. testcode:: import festim as F my_ic = F.InitialCondition( - filename="ic_file.xdmf", + value="ic_file.xdmf", label="mobile", - timestep=-1, + time_step=-1, field=0 ) diff --git a/docs/source/userguide/materials.rst b/docs/source/userguide/materials.rst index f3028e849..492458898 100644 --- a/docs/source/userguide/materials.rst +++ b/docs/source/userguide/materials.rst @@ -6,7 +6,11 @@ Materials are vital components of hydrogen transport simulations. They hold diff To define a material, use the :class:`festim.Material` class: -.. code-block:: python +.. testsetup:: + + from festim import Material, Simulation + +.. testcode:: mat1 = Material(id=1, D_0=2, E_D=0.1) mat2 = Material(id=2, D_0=3, E_D=0.4) @@ -14,7 +18,7 @@ To define a material, use the :class:`festim.Material` class: Materials are then assigned to the model: -.. code-block:: python +.. testcode:: my_model = Simulation(materials=[mat1, mat2]) diff --git a/docs/source/userguide/mesh.rst b/docs/source/userguide/mesh.rst index c2b7a2a4c..c90271606 100644 --- a/docs/source/userguide/mesh.rst +++ b/docs/source/userguide/mesh.rst @@ -2,6 +2,10 @@ Mesh ==== +.. testsetup:: + + from festim import MeshFromVertices, MeshFromXDMF + Meshes are required to discretise the geometrical domain of the simulation. As FESTIM is not a meshing tool, the meshing capabilities are limited to simple 1D meshes. @@ -11,13 +15,13 @@ As FESTIM is not a meshing tool, the meshing capabilities are limited to simple The easiest way to define a 1D mesh in FESTIM is to define it from a list of vertices (see :class:`festim.MeshFromVertices`): -.. code-block:: python +.. testcode:: mesh = MeshFromVertices([0, 1, 2, 4, 5, 10]) For bigger meshes, use the numpy library to generate an array of vertices. -.. code-block:: python +.. testcode:: import numpy as np @@ -25,7 +29,7 @@ For bigger meshes, use the numpy library to generate an array of vertices. Numpy arrays can be combined to have local refinements: -.. code-block:: python +.. testcode:: import numpy as np @@ -44,10 +48,26 @@ Meshes from XDMF More complex meshes can be read from XDMF files (see :class:`festim.MeshFromXDMF`): -.. code-block:: python +.. testsetup:: + + import fenics as f + + mesh = f.UnitSquareMesh(10, 10) + + volume_markers = f.MeshFunction("size_t", mesh, mesh.topology().dim(), 1) + surface_markers = f.MeshFunction("size_t", mesh, mesh.topology().dim() - 1, 1) + + f.XDMFFile("volume_file.xdmf").write(volume_markers) + f.XDMFFile("boundary_file.xdmf").write(surface_markers) + +.. testcode:: mesh = MeshFromXDMF(volume_file="volume_file.xdmf", boundary_file="boundary_file.xdmf") +.. testoutput:: + + Succesfully load mesh with 200 cells + The recommended workflow is to mesh your geometry with your favourite meshing software (`SALOME `_, `gmsh `_...) and convert the produced mesh with `meshio `_. GMSH example diff --git a/docs/source/userguide/newton_solver.rst b/docs/source/userguide/newton_solver.rst index 67753a551..60e3f9dd5 100644 --- a/docs/source/userguide/newton_solver.rst +++ b/docs/source/userguide/newton_solver.rst @@ -46,7 +46,9 @@ The preconditioner can be set with the ``preconditioner`` attribute. The list of Similarly, the Newton solver parameters of :class:`festim.HeatTransferProblem`, :class:`festim.ExtrinsicTrap`, or :class:`festim.NeutronInducedTrap` can be defined if needed. Here is an example for the heat transfer problem: -.. code-block:: python +.. testcode:: + + from festim import HeatTransferProblem model.T = HeatTransferProblem( transient=True, @@ -70,7 +72,9 @@ For a finer control, the built-in Newton solver can be overwritten with a custom A user-defined Newton solver can be provided after :class:`festim.Simulation.initialise()`. Here is a simple example for the H transport problem: -.. code-block:: python +.. testcode:: + + import fenics custom_solver = fenics.NewtonSolver() custom_solver.parameters["error_on_nonconvergence"] = False @@ -93,9 +97,11 @@ A user-defined Newton solver can be provided after :class:`festim.Simulation.ini To extend the functionality, the `NewtonSolver `_ class can be overwritten: -.. code-block:: python +.. testcode:: + + import fenics - class CustomSolver(f.NewtonSolver): + class CustomSolver(fenics.NewtonSolver): def __init__(self): super().__init__() From 0fdaf7635ec8f4a5740a71ddcc73f327403cf467 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Mon, 10 Jun 2024 15:57:56 +0200 Subject: [PATCH 2/8] added workflow --- .github/workflows/doctest.yml | 21 +++++++++++++++++++++ docs/environment.yml | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/doctest.yml diff --git a/.github/workflows/doctest.yml b/.github/workflows/doctest.yml new file mode 100644 index 000000000..9de319a99 --- /dev/null +++ b/.github/workflows/doctest.yml @@ -0,0 +1,21 @@ +name: Documentation test + +on: [push, pull_request] + +jobs: + docbuild: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up Conda + uses: conda-incubator/setup-miniconda@v2 + with: + activate-environment: festim-docs + environment-file: docs/example-environment.yml + + - name: Doc Tests + shell: bash -l {0} + run: sphinx-build -b doctest -d build/doctrees docs build/doctest \ No newline at end of file diff --git a/docs/environment.yml b/docs/environment.yml index 5fe2f5baa..f6ef950de 100644 --- a/docs/environment.yml +++ b/docs/environment.yml @@ -1,4 +1,4 @@ -name: fenics +name: festim-docs channels: - conda-forge - defaults From a66238a2fe877c64ab0c1b0e06ff4f2af6c46794 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Mon, 10 Jun 2024 16:29:01 +0200 Subject: [PATCH 3/8] fixed tests for newton solver --- docs/source/userguide/newton_solver.rst | 42 +++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/docs/source/userguide/newton_solver.rst b/docs/source/userguide/newton_solver.rst index 60e3f9dd5..269f1beab 100644 --- a/docs/source/userguide/newton_solver.rst +++ b/docs/source/userguide/newton_solver.rst @@ -46,6 +46,21 @@ The preconditioner can be set with the ``preconditioner`` attribute. The list of Similarly, the Newton solver parameters of :class:`festim.HeatTransferProblem`, :class:`festim.ExtrinsicTrap`, or :class:`festim.NeutronInducedTrap` can be defined if needed. Here is an example for the heat transfer problem: +.. testsetup:: + + import fenics + import festim as F + + model = F.Simulation() + model.mesh = F.MeshFromVertices([1, 2, 3, 4, 5]) + model.materials = F.Material(id=1, D_0=1, E_D=0, thermal_cond=10, rho=2, heat_capacity=3) + model.settings = F.Settings( + absolute_tolerance=1e-10, + relative_tolerance=1e-10, + final_time=1, + ) + model.dt = F.Stepsize(1) + .. testcode:: from festim import HeatTransferProblem @@ -57,7 +72,9 @@ can be defined if needed. Here is an example for the heat transfer problem: relative_tolerance=1e-10, maximum_iterations=50, linear_solver="gmres", - preconditioner="icc") + preconditioner="icc", + ) + -------------- @@ -72,7 +89,22 @@ For a finer control, the built-in Newton solver can be overwritten with a custom A user-defined Newton solver can be provided after :class:`festim.Simulation.initialise()`. Here is a simple example for the H transport problem: -.. testcode:: +.. testsetup:: custom_solver_simple + + import fenics + import festim as F + + model = F.Simulation() + model.T = 500 + model.mesh = F.MeshFromVertices([1, 2, 3, 4, 5]) + model.materials = F.Material(id=1, D_0=1, E_D=0) + model.settings = F.Settings( + absolute_tolerance=1e-10, + relative_tolerance=1e-10, + transient=False, + ) + +.. testcode:: custom_solver_simple import fenics @@ -90,6 +122,12 @@ A user-defined Newton solver can be provided after :class:`festim.Simulation.ini model.run() +.. testoutput:: custom_solver_simple + :options: +ELLIPSIS + :hide: + + ... + .. warning:: For a stationary heat transfer problem, a custom Newton solver has to be provided before the simulation initialisation! From ddc66f731d1c55a9389dd60ba0d357eced4aadd2 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Mon, 10 Jun 2024 16:37:48 +0200 Subject: [PATCH 4/8] finished testing --- docs/source/userguide/settings.rst | 2 +- docs/source/userguide/sources.rst | 8 ++++---- docs/source/userguide/stepsize.rst | 10 +++++----- docs/source/userguide/temperature.rst | 14 +++++++++----- docs/source/userguide/traps.rst | 12 ++++++------ docs/source/userguide/troubleshooting.rst | 8 ++++---- 6 files changed, 29 insertions(+), 25 deletions(-) diff --git a/docs/source/userguide/settings.rst b/docs/source/userguide/settings.rst index 90f4cd4c8..cdead3f97 100644 --- a/docs/source/userguide/settings.rst +++ b/docs/source/userguide/settings.rst @@ -6,7 +6,7 @@ Settings The settings of a FESTIM simulation are defined with a :class:`festim.Settings` object. -.. code-block:: python +.. testcode:: import festim as F diff --git a/docs/source/userguide/sources.rst b/docs/source/userguide/sources.rst index 8ae5ecc27..983185a68 100644 --- a/docs/source/userguide/sources.rst +++ b/docs/source/userguide/sources.rst @@ -10,7 +10,7 @@ Volumetric sources Volumetric sources can be set in a simulation by using the :class:`festim.Source` class. -.. code:: python +.. testcode:: import festim as F @@ -28,7 +28,7 @@ Implantation flux Hydrogen implanted in a material can be simulated by a Gaussian-shaped volumetric source with the :class:`festim.ImplantationFlux` class. -.. code:: python +.. testcode:: import festim as F @@ -51,7 +51,7 @@ Radioactive decay Radioactive decay can be simulated by a volumetric source with the :class:`festim.RadioactiveDecay` class. -.. code:: python +.. testcode:: import festim as F @@ -61,6 +61,6 @@ Radioactive decay can be simulated by a volumetric source with the :class:`festi F.RadioactiveDecay( decay_constant=1.78e-9, volume=1, - fields="all", + field="all", ), ] diff --git a/docs/source/userguide/stepsize.rst b/docs/source/userguide/stepsize.rst index 971b299ca..8cc30b3a3 100644 --- a/docs/source/userguide/stepsize.rst +++ b/docs/source/userguide/stepsize.rst @@ -7,14 +7,14 @@ For transient problems, a :class:`festim.Stepsize` is required. It represents the time discretisation of the problem. Here is an example creating a stepsize of 1.2 seconds: -.. code-block:: python +.. testcode:: import festim as F my_stepsize = F.Stepsize(initial_value=1.2) To use the adaptive time stepping implemented in FESTIM, the arguments ``stepsize_change_ratio`` needs to be set to a value above 1. -.. code-block:: python +.. testcode:: my_stepsize = F.Stepsize(initial_value=1.2, stepsize_change_ratio=1.5) @@ -25,7 +25,7 @@ Moreover, if the solver doesn't converge, the stepsize will be reduced and the s Setting the ``dt_min`` argument will prevent the stepsize from becoming too small and will stop the simulation when this happens. To cap the stepsize after some time, the parameters ``t_stop`` and ``stepsize_stop_max`` can be used. -.. code-block:: python +.. testcode:: my_stepsize = F.Stepsize( initial_value=1.2, @@ -41,7 +41,7 @@ To cap the stepsize after some time, the parameters ``t_stop`` and ``stepsize_st Another option for controlling the stepsize is to use the ``max_stepsize`` parameter. This parameter defines the maximal value of the stepsize during simulations, and it can be set as a constant or a callable function of time: -.. code-block:: python +.. testcode:: def max_stepsize(t): if t <= 5: @@ -60,7 +60,7 @@ and it can be set as a constant or a callable function of time: The ``milestones`` argument can be used to make sure the simulation passes through specific times. This will modify the stepsize as needed. -.. code-block:: python +.. testcode:: my_stepsize = F.Stepsize( initial_value=1.2, diff --git a/docs/source/userguide/temperature.rst b/docs/source/userguide/temperature.rst index 8a93268c3..0100a237e 100644 --- a/docs/source/userguide/temperature.rst +++ b/docs/source/userguide/temperature.rst @@ -2,6 +2,10 @@ Temperature =========== +.. testsetup:: + + from festim import HeatTransferProblem, TemperatureFromXDMF + Definition of a temperature field or problem is essential for hydrogen transport and FESTIM as a whole. Regardless of how you define the temperature of the problem, it is passed to the :code:`T` attribute of the :class:`festim.Simulation` object. @@ -12,7 +16,7 @@ Analytical expressions The temperature can be defined as a constant value in Kelvin (K): -.. code-block:: python +.. testcode:: my_temperature = 300 @@ -40,7 +44,7 @@ More complex expressions can be expressed with sympy: would be passed to FESTIM as: -.. code-block:: python +.. testcode:: from festim import x, t import sympy as sp @@ -49,12 +53,12 @@ would be passed to FESTIM as: Conditional expressions are also possible: -.. code-block:: python +.. testcode:: from festim import x, t import sympy as sp - my_temp = sp.Piecewise((400, F.t < 10), (300, True)) + my_temp = sp.Piecewise((400, t < 10), (300, True)) --------------------------- From a heat transfer solver @@ -64,7 +68,7 @@ Temperature can also be obtained by solving the heat equation. Users can define heat transfer problems using :class:`festim.HeatTransferProblem`. -.. code-block:: python +.. testcode:: my_temp = HeatTransferProblem() diff --git a/docs/source/userguide/traps.rst b/docs/source/userguide/traps.rst index 6cc7dcb7f..43586ca27 100644 --- a/docs/source/userguide/traps.rst +++ b/docs/source/userguide/traps.rst @@ -16,7 +16,7 @@ A trap in FESTIM is defined by: * its density * the materials where it is located -.. code-block:: python +.. testcode:: import festim as F @@ -26,7 +26,7 @@ A trap in FESTIM is defined by: If the trap is located in several materials, instead of creating another :class:`festim.Trap` object, simply use a list of materials: -.. code-block:: python +.. testcode:: import festim as F @@ -37,7 +37,7 @@ If the trap is located in several materials, instead of creating another :class: The trap density can be a function of space and time. For example: -.. code-block:: python +.. testcode:: import festim as F @@ -52,7 +52,7 @@ The trap density can be a function of space and time. For example: Boolean expressions can also be used to restrict the trap to certain regions: -.. code-block:: python +.. testcode:: import festim as F @@ -76,7 +76,7 @@ Extrinsic traps An extrinsic trap is defined as a trap with a density evolving over time. If the temporal evolution of the trap's density is known `a priori`, then a "normal" trap can be used with a time dependent expression as density (see above). -.. code-block:: python +.. testcode:: import festim as F @@ -94,7 +94,7 @@ Let's imagine a case where you have two subdomains. Trap 1 is defined only in th It would be possible to define one trap in each subdomain. Grouping traps together helps save computational time by reducing the number of degrees of freedom. -.. code-block:: python +.. testcode:: import festim as F diff --git a/docs/source/userguide/troubleshooting.rst b/docs/source/userguide/troubleshooting.rst index a999a8884..0f44586f2 100644 --- a/docs/source/userguide/troubleshooting.rst +++ b/docs/source/userguide/troubleshooting.rst @@ -23,7 +23,7 @@ The first thing to check is the details of the Newton solver iterations. To do so, you must set the ``log_level`` to ``20`` (default is ``40``). This will provide more information during the solving stage. -.. code-block:: python +.. testcode:: import festim as F @@ -47,7 +47,7 @@ This is often due to an excessively high absolute tolerance. The Newton solver then converges in zero iterations. In other words, nothing is solved. First, check that this is the case by setting the log level to 20: -.. code-block:: python +.. testcode:: import festim as F @@ -57,9 +57,9 @@ First, check that this is the case by setting the log level to 20: Then increase the absolute tolerance of the solver: -.. code-block:: python +.. testcode:: my_model.settings = F.Settings( - ..., absolute_tolerance=1e10, + relative_tolerance=1e-10, ) \ No newline at end of file From 87e043d261125aab544380cf960573dd1d1c2d66 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Mon, 10 Jun 2024 16:38:58 +0200 Subject: [PATCH 5/8] fixed syntax --- .github/workflows/doctest.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doctest.yml b/.github/workflows/doctest.yml index 9de319a99..c7e2af83d 100644 --- a/.github/workflows/doctest.yml +++ b/.github/workflows/doctest.yml @@ -13,8 +13,8 @@ jobs: - name: Set up Conda uses: conda-incubator/setup-miniconda@v2 with: - activate-environment: festim-docs - environment-file: docs/example-environment.yml + activate-environment: festim-docs + environment-file: docs/example-environment.yml - name: Doc Tests shell: bash -l {0} From 38667546b682acf59c0a4267e1b5ee4d0d9d1532 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Mon, 10 Jun 2024 16:39:48 +0200 Subject: [PATCH 6/8] fixed syntax 2 --- .github/workflows/doctest.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/doctest.yml b/.github/workflows/doctest.yml index c7e2af83d..c86a6b7ad 100644 --- a/.github/workflows/doctest.yml +++ b/.github/workflows/doctest.yml @@ -16,6 +16,6 @@ jobs: activate-environment: festim-docs environment-file: docs/example-environment.yml - - name: Doc Tests - shell: bash -l {0} - run: sphinx-build -b doctest -d build/doctrees docs build/doctest \ No newline at end of file + - name: Doc Tests + shell: bash -l {0} + run: sphinx-build -b doctest -d build/doctrees docs build/doctest \ No newline at end of file From 1d1820a92f5d99151bf3f9b2587fbe20be6c08b1 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Mon, 10 Jun 2024 16:40:34 +0200 Subject: [PATCH 7/8] correct env file --- .github/workflows/doctest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doctest.yml b/.github/workflows/doctest.yml index c86a6b7ad..6d3e46f4e 100644 --- a/.github/workflows/doctest.yml +++ b/.github/workflows/doctest.yml @@ -14,7 +14,7 @@ jobs: uses: conda-incubator/setup-miniconda@v2 with: activate-environment: festim-docs - environment-file: docs/example-environment.yml + environment-file: docs/environment.yml - name: Doc Tests shell: bash -l {0} From 48842ddffaff987ab5c899cf525499e8c0d66584 Mon Sep 17 00:00:00 2001 From: RemDelaporteMathurin Date: Mon, 10 Jun 2024 16:47:54 +0200 Subject: [PATCH 8/8] fixed command --- .github/workflows/doctest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doctest.yml b/.github/workflows/doctest.yml index 6d3e46f4e..bfc2b2d44 100644 --- a/.github/workflows/doctest.yml +++ b/.github/workflows/doctest.yml @@ -18,4 +18,4 @@ jobs: - name: Doc Tests shell: bash -l {0} - run: sphinx-build -b doctest -d build/doctrees docs build/doctest \ No newline at end of file + run: sphinx-build -b doctest docs/source docs/_build/doctest \ No newline at end of file