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

Interface concentration discontinuities (fenicsx) #878

Merged
Show file tree
Hide file tree
Changes from 142 commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
b195072
started a generic script
RemDelaporteMathurin Aug 14, 2024
439df28
Merge remote-tracking branch 'origin/update-dolfinx-0.8' into discont…
RemDelaporteMathurin Aug 15, 2024
4034cc6
progress (runs on dolfinx nightly)
RemDelaporteMathurin Aug 15, 2024
73fe94b
removed unneeded stuff
RemDelaporteMathurin Aug 15, 2024
3f2f8c6
bcs generic
RemDelaporteMathurin Aug 15, 2024
a50810f
bcs before jacobian
RemDelaporteMathurin Aug 15, 2024
c59a875
issue with results
RemDelaporteMathurin Aug 15, 2024
c0f9d09
fixed double reaction + inner instead of dot
RemDelaporteMathurin Aug 15, 2024
994931b
fixed test function for reactant
RemDelaporteMathurin Aug 15, 2024
66adf7c
fixed a few random bugs
RemDelaporteMathurin Aug 15, 2024
0e5f5ba
correct way of making forms with parent functions
RemDelaporteMathurin Aug 16, 2024
ac07643
formatting
RemDelaporteMathurin Aug 16, 2024
659cc7b
added integration with parent mesh coefficients
RemDelaporteMathurin Aug 16, 2024
fb43151
now solubility is generic
RemDelaporteMathurin Aug 16, 2024
91a6a73
back to solubility of 2
RemDelaporteMathurin Aug 16, 2024
53e7430
T varies in x
RemDelaporteMathurin Aug 16, 2024
f1f6d65
K_S no longer hard coded
RemDelaporteMathurin Aug 16, 2024
9f05c82
+ and - restrictions correspond to the correct solubilities
RemDelaporteMathurin Aug 16, 2024
de79789
simplified code
RemDelaporteMathurin Aug 16, 2024
dab4590
HTransportProblemDiscontinuous class
RemDelaporteMathurin Aug 16, 2024
6a700b0
added back the derived quantities + removed unused stuff
RemDelaporteMathurin Aug 16, 2024
34f82e3
correspondance dicts are initialised in species
RemDelaporteMathurin Aug 20, 2024
e5c6793
add subdomains arg and attribute to Species + documentation
RemDelaporteMathurin Aug 20, 2024
ce31d38
gather connectivity dicts
RemDelaporteMathurin Aug 20, 2024
4f075be
NotImplementedError for exports for now
RemDelaporteMathurin Aug 20, 2024
ea3da5d
Refactor code to import HydrogenTransportProblem and HTransportProble…
RemDelaporteMathurin Aug 20, 2024
76d1ac2
remove problem file + comment
RemDelaporteMathurin Aug 20, 2024
1665bcf
need to define the correct ds
RemDelaporteMathurin Aug 20, 2024
ec5aeb5
Merge remote-tracking branch 'upstream/fenicsx' into discontinuity-ge…
RemDelaporteMathurin Aug 20, 2024
5b32d26
Merge branch 'discontinuity-generic' into add_fluxes
RemDelaporteMathurin Aug 20, 2024
dd0f65c
particle fluxes work correctly
RemDelaporteMathurin Aug 20, 2024
46b6c47
use festim k_B
RemDelaporteMathurin Aug 20, 2024
f7408fe
ICs not implemented
RemDelaporteMathurin Aug 20, 2024
0df9338
black formatted
RemDelaporteMathurin Aug 20, 2024
89fbef5
added new dict
RemDelaporteMathurin Aug 20, 2024
bbd3865
Merge remote-tracking branch 'upstream/fenicsx' into discontinuity-ge…
RemDelaporteMathurin Aug 20, 2024
d382ad4
added integration with Mesh1D
RemDelaporteMathurin Aug 20, 2024
21f5a3c
Merge branch 'discontinuity-generic' into post-processing
RemDelaporteMathurin Aug 20, 2024
28c1d44
added usage in implementation script
RemDelaporteMathurin Aug 20, 2024
eb7885c
small changes
RemDelaporteMathurin Aug 20, 2024
2144141
a few changes + comment about random SEGV crash
RemDelaporteMathurin Aug 20, 2024
20947cf
Merge branch 'discontinuity-generic' into post-processing
RemDelaporteMathurin Aug 20, 2024
283abd4
added a map to collapsed function space and parent map
RemDelaporteMathurin Aug 20, 2024
b906931
store collapsed functions and function space + update in post process
RemDelaporteMathurin Aug 20, 2024
256fe06
don't need to collapse here
RemDelaporteMathurin Aug 20, 2024
d83f0b7
integrated VTX Export
RemDelaporteMathurin Aug 20, 2024
9b75dd6
integrated export in example
RemDelaporteMathurin Aug 20, 2024
3f2c79c
integrated VTX export in examples
RemDelaporteMathurin Aug 20, 2024
ffe8212
added example for only one material (no interfaces)
RemDelaporteMathurin Aug 20, 2024
2231f89
started implementing transient
RemDelaporteMathurin Aug 20, 2024
2c47f52
updated times
RemDelaporteMathurin Aug 20, 2024
c91dd3d
added K_S to material + black
RemDelaporteMathurin Aug 22, 2024
2b58f00
Implemented refactoring done by Jorgen
RemDelaporteMathurin Aug 22, 2024
c209600
removed unused variable
RemDelaporteMathurin Aug 23, 2024
97067b6
removed unused variables
RemDelaporteMathurin Aug 23, 2024
ad3fd37
get_solubility_coefficient + black
RemDelaporteMathurin Aug 23, 2024
dfe204c
black formatted
RemDelaporteMathurin Aug 23, 2024
1f714fa
removed unused import
RemDelaporteMathurin Aug 23, 2024
eaf13a3
dirichlet BC more generic
RemDelaporteMathurin Aug 23, 2024
9c8d029
use sub functionspace instead of full functionspace for dirichletBC
RemDelaporteMathurin Aug 23, 2024
10aab18
removed entity maps as attribute
RemDelaporteMathurin Aug 23, 2024
26898db
Merge branch 'progress-bar-optional' into discontinuity-generic
RemDelaporteMathurin Aug 29, 2024
1c83c38
adapted progress bar
RemDelaporteMathurin Aug 29, 2024
959e4a9
penalty term is now exposed
RemDelaporteMathurin Aug 29, 2024
8adc073
tolerance of solver is exposed
RemDelaporteMathurin Aug 29, 2024
6b53b01
exposed petsc options
RemDelaporteMathurin Aug 29, 2024
4005db5
Improved NewtonSolver
RemDelaporteMathurin Oct 4, 2024
4f91d91
new solver
RemDelaporteMathurin Oct 4, 2024
aab8750
scale is now alpha + topology._cpp_object
RemDelaporteMathurin Oct 4, 2024
1ca73b3
support for sources
RemDelaporteMathurin Oct 4, 2024
d3b0c07
added MMS test in 2D
RemDelaporteMathurin Oct 4, 2024
b8006ba
black
RemDelaporteMathurin Oct 4, 2024
e2ee473
updated dolfinx version in CI + removed dev container
RemDelaporteMathurin Oct 10, 2024
45f4db7
fixed fenics script
RemDelaporteMathurin Oct 10, 2024
e649792
added failing test
RemDelaporteMathurin Oct 10, 2024
51a6961
check for dofs functionspace
RemDelaporteMathurin Oct 10, 2024
0be3749
added more tests
RemDelaporteMathurin Oct 10, 2024
38057f7
removed duplicate of subdomain_1 subdomain_2
RemDelaporteMathurin Oct 11, 2024
77b3f6e
docstrings + removed unused variables
RemDelaporteMathurin Oct 11, 2024
c92121a
more docstrings
RemDelaporteMathurin Oct 11, 2024
1282892
removed mt and parent mesh from constructor of interface
RemDelaporteMathurin Oct 11, 2024
01948a4
more type hinting
RemDelaporteMathurin Oct 11, 2024
e39946d
type check for species.subdomains
RemDelaporteMathurin Oct 11, 2024
60b9b2e
fixed script
RemDelaporteMathurin Oct 12, 2024
6a1456b
fixed the examples
RemDelaporteMathurin Oct 23, 2024
56940d0
UPdate python version
jorgensd Oct 23, 2024
2f16118
removed discontinuity-generic since we have lots of examples
RemDelaporteMathurin Oct 23, 2024
67d6e4a
moved the examples to examples folder
RemDelaporteMathurin Oct 23, 2024
4fbbab4
Fix docstrings
RemDelaporteMathurin Oct 23, 2024
ad6c4b0
Fixed docstrings again
RemDelaporteMathurin Oct 23, 2024
a6e1de6
domain 0 and 1 instead of 1 and 2
RemDelaporteMathurin Oct 23, 2024
97a0864
Merge branch 'discontinuity-generic' of https://github.com/RemDelapor…
RemDelaporteMathurin Oct 23, 2024
5df377b
- Add in/outfiles to git ignore
jorgensd Oct 23, 2024
f7e4916
Merge remote-tracking branch 'remi/discontinuity-generic' into dokken…
jorgensd Oct 23, 2024
124fb29
removed top and bottom subscripts
RemDelaporteMathurin Oct 23, 2024
eab5fa5
type hinting for as_fenics_constant
RemDelaporteMathurin Oct 23, 2024
d46fc1a
removed unused var
RemDelaporteMathurin Oct 23, 2024
8ed278c
Rewrite docs
jorgensd Oct 23, 2024
8b2db98
format
RemDelaporteMathurin Oct 23, 2024
4d6954e
added API
RemDelaporteMathurin Oct 23, 2024
e6565d8
Merge branch 'dokken/suggested-changes' of https://github.com/RemDela…
RemDelaporteMathurin Oct 23, 2024
ec2ceb4
fixed docstrings
RemDelaporteMathurin Oct 23, 2024
586d7c1
fixed dolfinx version in benchmark
RemDelaporteMathurin Oct 23, 2024
9fcd1e5
black
RemDelaporteMathurin Oct 23, 2024
9ece9f4
black 2
RemDelaporteMathurin Oct 23, 2024
fd34d03
fixed benchmark for dolfinx 0.9
RemDelaporteMathurin Oct 23, 2024
5dc7432
Refactor writers
jorgensd Oct 23, 2024
b278110
Black formatting / ruff
jorgensd Oct 23, 2024
28c66f1
Sort imports
jorgensd Oct 23, 2024
60dcb5b
Remove setup files
jorgensd Oct 24, 2024
3101c40
Change linting
jorgensd Oct 24, 2024
729272e
Add dependabot
jorgensd Oct 24, 2024
6b174cb
Apply suggestions from code review
jorgensd Oct 24, 2024
ca99a72
Formatting and importing within coer
jorgensd Oct 24, 2024
d3883ec
Import changes
jorgensd Oct 24, 2024
e36a70c
Move to source layout
jorgensd Oct 24, 2024
830d2ac
Merge remote-tracking branch 'remi/discontinuity-generic' into dokken…
jorgensd Oct 24, 2024
cef405a
Get ruff and black to agree
jorgensd Oct 24, 2024
692d167
Simplify input to boundary conditions and add some error handling in …
jorgensd Oct 24, 2024
b67aa0b
Ruff
jorgensd Oct 24, 2024
edc86cf
Add tests
jorgensd Oct 24, 2024
3e12a60
Make mypy non-blocking
jorgensd Oct 24, 2024
35928cf
Update mesh class
jorgensd Oct 24, 2024
584692b
Ruff
jorgensd Oct 24, 2024
761f2c3
Merge pull request #1 from RemDelaporteMathurin/dokken/suggested-changes
RemDelaporteMathurin Oct 25, 2024
682a4f3
added tolerances in the solver
RemDelaporteMathurin Oct 25, 2024
99f57af
Fix switch
jorgensd Oct 25, 2024
e713ef5
Use 3.10 syntax
jorgensd Oct 25, 2024
ce344e8
fixed a few more multilines
RemDelaporteMathurin Oct 25, 2024
085bd30
Last 3.10 backports of fstring
jorgensd Oct 25, 2024
f989dbe
One more fstring backoport
jorgensd Oct 25, 2024
25a9790
Lasts tests
jorgensd Oct 25, 2024
6fd66db
Simplify form compilation
jorgensd Oct 25, 2024
dbde7e3
Minor fixes to transfer meshtags
jorgensd Oct 25, 2024
f05d785
Unify formatting for integration measures with Rem(i)
jorgensd Oct 25, 2024
18e4cad
Various fixes to post-processing
jorgensd Oct 25, 2024
9e149e3
Fix variable name
jorgensd Oct 25, 2024
7271ec9
Fix variable name
jorgensd Oct 25, 2024
0ea4875
More fixes
jorgensd Oct 25, 2024
a4cdb82
Fix test
jorgensd Oct 25, 2024
f3df3b0
fixed test
RemDelaporteMathurin Oct 28, 2024
403192e
format
RemDelaporteMathurin Oct 28, 2024
ae17698
vtxfile write in HydrogenTransportProblem
RemDelaporteMathurin Oct 29, 2024
31ac03c
Merge remote-tracking branch 'upstream/fenicsx' into discontinuity-ge…
RemDelaporteMathurin Oct 29, 2024
d2f7787
moved convergence rates
RemDelaporteMathurin Oct 30, 2024
6371bb6
comment
RemDelaporteMathurin Oct 30, 2024
7d0a6d4
comment
RemDelaporteMathurin Oct 30, 2024
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
15 changes: 15 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "github-actions" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
- package-ecosystem: "pip" # See documentation for possible values
directory: "./"
schedule:
interval: "weekly"
18 changes: 9 additions & 9 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ on: [pull_request, push]
jobs:
benchmark:
runs-on: ubuntu-latest
container: dolfinx/dolfinx:v0.7.3
container: dolfinx/dolfinx:v0.9.0

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Checkout code
uses: actions/checkout@v2

- name: Install local package and dependencies
run: |
pip install .[test]
- name: Install local package and dependencies
run: |
pip install .[test]

- name: Run benchmark
run: |
python3 test/benchmark.py
- name: Run benchmark
run: |
python3 test/benchmark.py
2 changes: 1 addition & 1 deletion .github/workflows/ci_conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Create Conda environment
shell: bash -l {0}
run: |
conda install -c conda-forge fenics-dolfinx=0.8.0
conda install -c conda-forge fenics-dolfinx=0.9.0

- name: Install local package and dependencies
shell: bash -l {0}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
container_version: [v0.8.0, nightly]
container_version: [v0.9.0, nightly]
container: dolfinx/dolfinx:${{ matrix.container_version }}
steps:
- name: Checkout code
Expand Down
24 changes: 22 additions & 2 deletions .github/workflows/code_formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,25 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install linting tools
run: pip install mypy ruff

- name: ruff format
run: |
ruff format --check .

- name: ruff check
continue-on-error: true
run: |
ruff check .

- name: mypy
continue-on-error: true
run: |
python -m mypy .
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,9 @@ venv.bak/

# version file
**_version.py

# Input/Output files
*.bp
*.xdmf
*.h5
*.txt
39 changes: 25 additions & 14 deletions convergence_rates.py
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We probably don't need to keep this

Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import festim as F
import numpy as np
from dolfinx import fem
import ufl
import mpi4py.MPI as MPI

import matplotlib.pyplot as plt
import numpy as np
import ufl
from dolfinx import fem

import festim as F


def source_from_exact_solution(
Expand Down Expand Up @@ -58,19 +60,27 @@ def error_L2(u_computed, u_exact, degree_raise=3):


def run(N):
exact_solution = lambda x, t: 2 * x[0] ** 2 + 20 * t
def exact_solution(x, t):
return 2 * x[0] ** 2 + 20 * t

def density(T):
return 0.2 * T + 2

density = lambda T: 0.2 * T + 2
heat_capacity = lambda T: 0.2 * T + 3
thermal_conductivity = lambda T: 0.1 * T + 4
def heat_capacity(T):
return 0.2 * T + 3

def thermal_conductivity(T):
return 0.1 * T + 4

mms_source_from_sp = source_from_exact_solution(
exact_solution,
density=lambda x, t: density(exact_solution(x, t)),
heat_capacity=lambda x, t: heat_capacity(exact_solution(x, t)),
thermal_conductivity=lambda x, t: thermal_conductivity(exact_solution(x, t)),
)
mms_source = lambda x, t: mms_source_from_sp((x[0], None, None), t)

def mms_source(x, t):
return mms_source_from_sp((x[0], None, None), t)

my_problem = F.HeatTransferProblem()

Expand Down Expand Up @@ -110,18 +120,19 @@ def run(N):
my_problem.settings.stepsize = F.Stepsize(0.05)

my_problem.exports = [
F.VTXExportForTemperature(filename="test_transient_heat_transfer.bp")
F.VTXSpeciesExport(filename="test_transient_heat_transfer.bp")
]

my_problem.initialise()
my_problem.run()

computed_solution = my_problem.u
final_time_sim = (
my_problem.t.value
) # we use the exact final time of the simulation which may differ from the one specified in the settings
# we use the exact final time of the simulation which may differ from the one specified in the settings
final_time_sim = my_problem.t.value

def exact_solution_end(x):
return exact_solution(x, final_time_sim)

exact_solution_end = lambda x: exact_solution(x, final_time_sim)
L2_error = error_L2(computed_solution, exact_solution_end)
return L2_error

Expand Down
26 changes: 26 additions & 0 deletions docs/source/api/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FESTIM API
==========


.. automodule:: festim.boundary_conditions
:members:
:show-inheritance:
:exclude-members: __weakref__
:private-members:
:inherited-members:


.. .. automodule:: festim.hydrogen_transport_problem
.. :members:
.. :show-inheritance:
.. :exclude-members: __weakref__
.. :private-members:
.. :inherited-members:



.. .. automodule:: festim.heat_transfer_problem
.. :members:
.. :show-inheritance:
.. :exclude-members: __weakref__
.. :inherited-members:
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Contents
userguide/index
devguide/index
publications
api/index


Indices and tables
Expand Down
2 changes: 1 addition & 1 deletion examples/multi_isotope_trapping_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import festim as F
import numpy as np

import festim as F

my_model = F.HydrogenTransportProblem()

Expand Down
102 changes: 102 additions & 0 deletions examples/multi_material_1d.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import numpy as np

import festim as F

my_model = F.HTransportProblemDiscontinuous()

interface_1 = 0.5
interface_2 = 0.7

# for some reason if the mesh isn't fine enough then I have a random SEGV error
N = 2000
vertices = np.concatenate(
[
np.linspace(0, interface_1, num=N),
np.linspace(interface_1, interface_2, num=N),
np.linspace(interface_2, 1, num=N),
]
)

my_model.mesh = F.Mesh1D(vertices)

material_left = F.Material(D_0=2.0, E_D=0)
material_mid = F.Material(D_0=2.0, E_D=0)
material_right = F.Material(D_0=2.0, E_D=0)

material_left.K_S_0 = 2.0
material_left.E_K_S = 0
material_mid.K_S_0 = 4.0
material_mid.E_K_S = 0
material_right.K_S_0 = 6.0
material_right.E_K_S = 0

left_domain = F.VolumeSubdomain1D(
3, borders=[vertices[0], interface_1], material=material_left
)
middle_domain = F.VolumeSubdomain1D(
4, borders=[interface_1, interface_2], material=material_mid
)
right_domain = F.VolumeSubdomain1D(
5, borders=[interface_2, vertices[-1]], material=material_right
)

left_surface = F.SurfaceSubdomain1D(id=1, x=vertices[0])
right_surface = F.SurfaceSubdomain1D(id=2, x=vertices[-1])

# the ids here are arbitrary in 1D, you can put anything as long as it's not the same as the surfaces
my_model.interfaces = [
F.Interface(6, (left_domain, middle_domain)),
F.Interface(7, (middle_domain, right_domain)),
]
my_model.subdomains = [
left_domain,
middle_domain,
right_domain,
left_surface,
right_surface,
]
my_model.surface_to_volume = {
right_surface: right_domain,
left_surface: left_domain,
}

H = F.Species("H", mobile=True)
trapped_H = F.Species("H_trapped", mobile=False)
empty_trap = F.ImplicitSpecies(n=0.5, others=[trapped_H])

my_model.species = [H, trapped_H]

for species in my_model.species:
species.subdomains = my_model.volume_subdomains


my_model.reactions = [
F.Reaction(
reactant=[H, empty_trap],
product=[trapped_H],
k_0=2,
E_k=0,
p_0=0.1,
E_p=0,
volume=domain,
)
for domain in [left_domain, middle_domain, right_domain]
]

my_model.boundary_conditions = [
F.DirichletBC(left_surface, value=0.05, species=H),
F.DirichletBC(right_surface, value=0.2, species=H),
]


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

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

my_model.exports = [
F.VTXSpeciesExport(filename=f"u_{subdomain.id}.bp", field=H, subdomain=subdomain)
for subdomain in my_model.volume_subdomains
]

my_model.initialise()
my_model.run()
Loading
Loading