Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • JanHab/fxdgm
  • JanHab/fxdgm-testing
2 results
Show changes
Commits on Source (116)
Showing
with 3262 additions and 359 deletions
# Taken and adapted from: https://git.rwth-aachen.de/lamBOO/fenicsR13
# ignore VSCode's helper files
*.vscode
*.ipynb_checkpoints
# ignore python cache
*__pycache__*
*.__pycache__
*test/__pycache__
*fxdgm/__pycache__
*examples/__pycache__
*examples/ReproduableCode/__pycache__
*.pytest_cache*
# ignore Sphinx documentation output
*docs/build
# Ignore coverage files
.coverage
htmlcov
# Ignore pip folder
*egg-info/*
# Ignore venv files
venv
# Ignore .eggs
*.eggs
*eggs*
*.egg-info
# Ignore build files
build
# Ignore lyx temp files
*.lyx~
*.lyx#
# Ignore .DS_Store
.DS_Store
\ No newline at end of file
image: docker:20.10.16 # Define the Docker image
stages: # Define stages in the pipeline
- prepare
- build
- test
- deploy
prepare:
stage: prepare
tags:
- docker
services:
- docker:20.10.16-dind
before_script:
- echo "$CI_REGISTRY_PASSWORD" | docker login $CI_REGISTRY -u $CI_REGISTRY_USER --password-stdin
script:
- docker pull $CI_REGISTRY_IMAGE:latest || true
- docker build
--cache-from $CI_REGISTRY_IMAGE:latest
--tag $CI_REGISTRY_IMAGE:latest .
- docker push $CI_REGISTRY_IMAGE:latest
# Job to build documentation
build-docs:
stage: build
dependencies:
- prepare
image:
name: $CI_REGISTRY_IMAGE:latest
entrypoint: [""]
tags:
- docker
script:
- sphinx-build docs/source docs/build # Build the documentation
artifacts:
paths:
- docs/build # Save the build output for later stages
expire_in: 12 month # Optional: Set how long to keep the artifacts (default: 30 days)
# Job to test the implementation
test:
stage: test
dependencies:
- prepare
image:
name: $CI_REGISTRY_IMAGE:latest
entrypoint: [""]
tags:
- docker
script:
- pytest --cov=fxdgm --cov-report=term --cov-report=html tests/ # Run the tests and store coverage
artifacts:
paths:
- htmlcov # Save the coverage report
expire_in: 12 month # Optional: Set how long to keep the artifacts (default: 30 days)
coverage: '/^TOTAL.*\s+(\d+\%)$/'
# Job to deploy documentation to GitLab Pages
pages:
stage: deploy
dependencies:
- build-docs
- test
image:
name: $CI_REGISTRY_IMAGE:latest
entrypoint: [""]
tags:
- docker
script:
- mv docs/build public # Move the build output to the "public" directory
- mv htmlcov public # Move the coverage report to the "public" directory
artifacts:
paths:
- public # Files in the "public" folder will be deployed to GitLab Pages
only:
- main # Only deploy if the changes are in the default branch
{
"cSpell.enableFiletypes": [
"!markdown",
"!python"
],
"python.analysis.typeCheckingMode": "off"
}
\ No newline at end of file
# Start with a base image that includes conda
FROM continuumio/miniconda3:latest
# Set environment variables
ENV CONDA_DEFAULT_ENV=base
ENV PATH /opt/conda/envs/${CONDA_DEFAULT_ENV}/bin:$PATH
ENV HOME /root
# Create the environment and install packages
# FEniCSx backend + documentation and testing dependencies
# sqlite for coverage, it necessary
RUN conda install -n ${CONDA_DEFAULT_ENV} -c conda-forge fenics-dolfinx=0.8.0 mpich=4.2.1 pyvista=0.43.10 gcc=12.4.0 sphinx=7.3.7 myst-parser=4.0.0 sphinx-copybutton=0.5.2 sphinx-rtd-theme=3.0.1 pytest=8.3.3 pytest-cov=6.0.0 sqlite=3.41.2 -y
WORKDIR /root
ADD . /fxdgm
RUN pip install --editable /fxdgm/.
CMD ["bash"]
# Reproducibility Repository for: Numerical Treatment of a Thermodynamically Consistent Electrolyte Model (B.Sc. Thesis - Jan Habscheid)
# fxdgm
## Thesis
[![Pipeline Status](https://git.rwth-aachen.de/janhab/fxdgm/badges/main/pipeline.svg)](https://git.rwth-aachen.de/janhab/fxdgm/pipelines)
[![Documentation](https://img.shields.io/badge/docs-latest-blue)](https://janhab.pages.rwth-aachen.de/fxdgm/)
[![coverage report](https://git.rwth-aachen.de/JanHab/fxdgm/badges/main/coverage.svg)](https://janhab.pages.rwth-aachen.de/fxdgm/htmlcov)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.13645296.svg)](https://doi.org/10.5281/zenodo.13645296)
[![GitLab Version](https://img.shields.io/badge/version-1.0-blue.svg)](https://git.rwth-aachen.de/janhab/fxdgm/-/tags)
[![License](https://img.shields.io/badge/license-GPLv3-blue)](https://git.rwth-aachen.de/janhab/fxdgm/-/blob/main/LICENSE?ref_type=heads)
This repository contains the code to reproduce the results presented in the bachelor thesis: Numerical Treatment of a Thermodynamically Consistent Electrolyte Model
Find the thesis at:
- Insert link to thesis
*A nonlinear, mixed finite element solver for the DGM electrolyte model*
### Abstract
<img src="media/logo.svg" alt="Logo" width="200" />
- Insert Abstract from thesis
## Physical Background
The system, which is solved, refers to the original work, [Overcoming the shortcomings of the Nernst–Planck model](https://doi.org/10.1039/C3CP44390F), from Wolfgang Dreyer, Clemens Guhlke and Rüdiger Müller in 2013.\
This paper introduces a new, generalized Nernst-Planck model, which is thermodynamically consistent, as the classical Nernst-Planck model fails to predict the correct ion-concentrations close to the boundaries.
The open-source package [FEniCSx](https://fenicsproject.org/) was used for the numerical implementation.
## Main Features
- Solving steady [DGM](https://doi.org/10.1039/C3CP44390F) model in dimensionless units
- for a ternary electrolyte (cations, anions, neutral solvent)
- for an electrolyte of N arbitrary species
- Local mesh refinement for one-dimensional domains towards the electrode
- [Testcases](https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/tests?ref_type=heads) for the one-dimensional case or the two-dimensional electrolytic diode
- Solutions for the [Double-Layer Capacity](https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/ReproducableCode/DoubleLayerCapacity?ref_type=heads), both numerical and analytical
- [Numerical Convergence](https://git.rwth-aachen.de/JanHab/fxdgm/-/blob/main/examples/ReproducableCode/Convergence.py?ref_type=heads) with relaxation parameter for newtons method
- Two-dimensional testcases for the example of the [electrolytic diode](https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/ReproducableCode/ElectrolyticDiode?ref_type=heads)
## Installation
As a numerical solver, mainly FEniCSx was used and installed via conda.
All the calculations were performed on a Linux machine. According to the documentation, everything should work well on macOS, but this was not tested. FEniCSx offers some beta versions for Windows support, but it is recommended to use WSL2 instead.
Install the fxdgm package with pip to get all the implemented functions.
``` bash
pip install git+https://git.rwth-aachen.de/JanHab/fxdgm
```
conda create --name fenicsx-env python=3.12.3 -y
conda activate fenicsx-env
conda install -c conda-forge fenics-dolfinx=0.8.0 mpich=4.2.1 pyvista=0.43.10 matplotlib=3.8.4 numpy=1.26.4 scipy=1.14.0 -y
For the backend, FEniCSx was used and installed via conda.
The necessery dependencies can be installed with
``` bash
conda install -c conda-forge fenics-dolfinx=0.8.0 mpich=4.2.1 pyvista=0.43.10 gcc=12.4.0 -y
```
### Alternative installation
It is also possible to install the FEniCSx backend in a different manner. See the [FEniCSx documentation](https://fenicsproject.org/download/) for this.
Although this installation method should work, it was not tested for the purpose of this package.
### macOS installation using Docker
Use the "environment.yml" file to install all necessary environments
The docker installation method works for linux too. It was not tested on windows.
``` bash
docker compose build
docker compose run solver
```
conda env create -f environment.yml
### Testing
For testing clone the repository, install pytest and run the tests with
``` bash
pip install pytest==8.3.3
python -m pytest
```
## Usage
Find the visualizations from the thesis and some extra calculations in the "examples" folder.
In the subfolder "ReproducableCode" is the code, to execute the calculations with some first visualizations.
The subfolder "Data" stores the data for all the simulations in a *.npz file, which can be read with numpy `np.load(file.npz)`.
"Visualizations" creates the necessary figures from the thesis and stores them in *.svg format in "Figures".
In "src" there are the generic FEniCSx implementations, that were used to calculate the examples.
Find the package source code in [fxdgm](https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/fxdgm?ref_type=heads).
This implements the nonlinear electrolyte model.
Furthermore, some physical examples are provided in the [examples](https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples?ref_type=heads).
In the subfolder [ReproducableCode](https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/ReproducableCode?ref_type=heads) is the code, to execute the calculations with some first visualizations.
The subfolder [Data](https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/Data?ref_type=heads) stores the data for all the simulations in a *.npz file, which can be read with numpy `np.load(file.npz)`.
[Visualizations](https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/Visualizations?ref_type=heads) creates the necessary figures from the thesis and stores them either in *.svg or *.pdf format in "Figures".
## Contact
**Author**
### Author
- Jan Habscheid
- Jan.Habscheid@rwth-aachen.de
- [Jan.Habscheid@rwth-aachen.de](mailto:Jan.Habscheid@rwth-aachen.de)
**Supervisor**
- Dr. Lambert Theissen
- ACoM - Applied and Computational Mathematics
- RWTH Aachen University
- theisen@acom.rwth-aachen.de
### Supervisor
**Supervisor**
- Dr. Lambert Theisen
- ACoM - Applied and Computational Mathematics
- RWTH Aachen University
- [theisen@acom.rwth-aachen.de](mailto:theisen@acom.rwth-aachen.de)
- Prof. Dr. Manuel Torrilhon
- ACoM - Applied and Computational Mathematics
- RWTH Aachen University
- mt@acom.rwth-aachen.de
\ No newline at end of file
- ACoM - Applied and Computational Mathematics
- RWTH Aachen University
- [mt@acom.rwth-aachen.de](mailto:mt@acom.rwth-aachen.de)
services:
solver:
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/root/solver
stdin_open: true # Equivalent to -i for interactive mode
tty: true # Equivalent to -t for a terminal interface
command: ["/bin/bash"]
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
if "%1" == "" goto help
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
project = 'fxdgm'
copyright = '2024, Jan Habscheid'
author = 'Jan Habscheid'
release = 'September, 2024'
# Add fxdgm folder to path
import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join("..", "../fxdgm")))
sys.path.insert(0, os.path.abspath('../fxdgm'))
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = [
'sphinx.ext.napoleon',
'sphinx.ext.autodoc',
'myst_parser',
'sphinx_copybutton',
'sphinx.ext.coverage',
'sphinx.ext.autosectionlabel',
]
templates_path = ['_templates']
exclude_patterns = []
source_suffix = {
'.rst': 'restructuredtext',
'.txt': 'markdown',
'.md': 'markdown',
}
autosummary_generate = False
# autoclass_content = 'both'
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = 'sphinx_rtd_theme'
\ No newline at end of file
Example
=======
| In this example, we are going to solve the thermodynamically consistent electrolyte model for a incompressible, ternary electrolyte, as it is done in `https://git.rwth-aachen.de/JanHab/fxdgm/-/blob/main/examples/ReproducableCode/TernaryElectrolyte.py?ref_type=heads <https://git.rwth-aachen.de/JanHab/fxdgm/-/blob/main/examples/ReproducableCode/TernaryElectrolyte.py?ref_type=heads>`_.
Install the package and necessary libraries
-------------------------------------------
.. code-block:: python
pip install git+https://git.rwth-aachen.de/JanHab/fxdgm
conda install -c conda-forge fenics-dolfinx=0.8.0 mpich=4.2.1 pyvista=0.43.10 gcc=12.4.0 -y
Import the necessary libraries
-------------------------------------------
.. code-block:: python
from fxdgm import solve_System_4eq
import matplotlib.pyplot as plt
import numpy as np
Define parameters and boundary conditions
-----------------------------------------
.. code-block:: python
phi_left = 8.0
phi_right = 0.0
p_right = 0.0
y_A_R = 1/3
y_C_R = 1/3
z_A = -1.0
z_C = 1.0
K = 'incompressible'
Lambda2 = 8.553e-6
a2 = 7.5412e-4
Define mesh and solver settings
-------------------------------
.. code-block:: python
number_cells = 1024
refinement_style = 'log'
rtol = 1e-8
Solve the system
----------------
.. code-block:: python
y_A, y_C, phi, p, x = solve_System_4eq(phi_left, phi_right, p_right, z_A, z_C, y_A_R, y_C_R, K, Lambda2, a2, number_cells, relax_param=0.05, x0=0, x1=1, refinement_style='hard_log', return_type='Vector', max_iter=1_000, rtol=rtol)
Visualize the results
---------------------
.. code-block:: python
plt.figure()
plt.plot(x, phi)
plt.xlabel('x [-]')
plt.ylabel('$\\varphi$ [-]')
plt.xlim(0,0.05)
plt.grid()
plt.show()
plt.figure()
plt.plot(x, p)
plt.xlabel('x [-]')
plt.ylabel('$p$ [-]')
plt.xlim(0,0.05)
plt.grid()
plt.show()
plt.figure()
plt.plot(x, y_A, label='$y_A$')
plt.plot(x, y_C, label='$y_C$')
plt.plot(x, 1 - y_A - y_C, label='$y_S$')
plt.xlabel('x [-]')
plt.ylabel('$y_\\alpha$ [-]')
plt.xlim(0,0.05)
plt.grid()
plt.legend()
plt.show()
The electric potential
^^^^^^^^^^^^^^^^^^^^^^^
.. image:: Figures/TernaryPotential.svg
:width: 600px
The pressure
^^^^^^^^^^^^^
.. image:: Figures/TernaryPressure.svg
:width: 600px
The atomic fractions
^^^^^^^^^^^^^^^^^^^^^
.. image:: Figures/TernaryConcentrations.svg
:width: 600px
\ No newline at end of file
fxdgm
=====
.. image:: https://git.rwth-aachen.de/janhab/fxdgm/badges/main/pipeline.svg
:target: https://git.rwth-aachen.de/JanHab/fxdgm/pipelines
.. image:: https://img.shields.io/badge/docs-latest-blue
:target: https://janhab.pages.rwth-aachen.de/fxdgm/
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.13645296.svg
:target: https://doi.org/10.5281/zenodo.13645296
.. image:: https://img.shields.io/badge/version-1.0-blue.svg
:target: https://git.rwth-aachen.de/janhab/fxdgm/-/tags
*A nonlinear, mixed finite element solver for the DGM electrolyte model*
.. image:: ../../media/logo.svg
:width: 300px
Physical Background
===================
| The system, which is solved, refers to the original work, `Overcoming the shortcomings of the Nernst–Planck model <https://doi.org/10.1039/C3CP44390F>`_, from Wolfgang Dreyer, Clemens Guhlke and Rüdiger Müller in 2013.
| This paper introduces a new, generalized Nernst-Planck model, which is thermodynamically consistent, as the classical Nernst-Planck model fails to predict the correct ion-concentrations close to the boundaries.
| The open-source package `FEniCSx <https://fenicsproject.org/>`_ was used for the numerical implementation.
Main Features
=============
- Solving stationary `DGM <https://doi.org/10.1039/C3CP44390F>`_ model in dimensionless units
- for a ternary electrolyte (cations, anions, neutral solvent)
- for an electrolyte of N arbitrary species
- Local mesh refinement for one-dimensional domains towards the electrode
- `Testcases <https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/tests?ref_type=heads>`_ for the one-dimensional case or the two-dimensional electrolytic diode
- Solutions for the `Double-Layer Capacity <https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/ReproducableCode/DoubleLayerCapacity?ref_type=heads>`_, both numerical and analytical
- `Numerical Convergence <https://git.rwth-aachen.de/JanHab/fxdgm/-/blob/main/examples/ReproducableCode/Convergence.py?ref_type=heads>`_ with relaxation parameter for newtons method
- Two-dimensional testcases for the example of the `electrolytic diode <https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/ReproducableCode/ElectrolyticDiode?ref_type=heads>`_
Installation
============
| Install the fxdgm package with pip to get all the implemented functions.
.. code-block::
pip install git+https://git.rwth-aachen.de/JanHab/fxdgm
| For the backend, FEniCSx was used and installed via conda.
| The necessary dependencies can be installed with
.. code-block::
conda install -c conda-forge fenics-dolfinx=0.8.0 mpich=4.2.1 pyvista=0.43.10 gcc=12.4.0 -y
| It is also possible to install the FEniCSx backend in a different manner. See the `FEniCSx documentation <https://fenicsproject.org/download/>`_ for this.
| Although this installation method should work, it was not tested for the purpose of this package.
macOS installation using Docker
-------------------------------
| The docker installation method works for linux too. It was not tested on windows.
.. code-block::
docker compose build
docker compose run solver
Testing
=======
| For testing clone the repository, install pytest and run the tests with
.. code-block::
pip install pytest==8.3.3
python -m pytest
Usage
=====
| Find the package source code in `fxdgm <https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/fxdgm?ref_type=heads>`_
| This implements the nonlinear electrolyte model.
| Furthermore, some physical examples are provided in the `examples <https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples?ref_type=heads>`_ folder.
| In the subfolder `ReproducableCode <https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/ReproducableCode?ref_type=heads>`_ is the code, to execute the calculations with some first visualizations.
| The subfolder `Data <https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/Data?ref_type=heads>`_ stores the data for all the simulations in a \*.npz file, which can be read with numpy `np.load(file.npz)`.
| `visualizations <https://git.rwth-aachen.de/JanHab/fxdgm/-/tree/main/examples/Visualizations?ref_type=heads>`_ creates the necessary figures from the thesis and stores them either in \*.svg or \*.pdf format in "Figures".
Contact
=======
**Author**
- Jan Habscheid
- Jan.Habscheid@rwth-aachen.de
**Supervisor**
- Dr. Lambert Theisen
- ACoM - Applied and Computational Mathematics
- RWTH Aachen University
- theisen@acom.rwth-aachen.de
- Prof. Dr. Manuel Torrilhon
- ACoM - Applied and Computational Mathematics
- RWTH Aachen University
- mt@acom.rwth-aachen.de
.. toctree::
src/oneD
src/ElectrolyticDiode
src/Miscellaneous
example
:maxdepth: 2
:caption: fxdgm
:hidden:
Electrolytic Diode
===================
.. warning::
If the Newton solver diverges for any of the solutions, you may try to reduce the relaxation parameter.
.. autofunction:: ElectrolyticDiode.ElectrolyticDiode
Miscellaneous
=============
.. autofunction:: RefinedMesh1D.create_refined_mesh
.. automodule:: Helper_DoubleLayerCapacity
:members:
:undoc-members:
:show-inheritance:
\ No newline at end of file
1D Electrolyte
==============
.. warning::
If the Newton solver diverges for any of the solutions, you may try to reduce the relaxation parameter.
.. autofunction:: Eq04.solve_System_4eq
.. autofunction:: EqN.solve_System_Neq
.. autofunction:: Eq02.solve_System_2eq
\ No newline at end of file
This diff is collapsed.
No preview for this file type
No preview for this file type