pyfvtool 0.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. pyfvtool-0.6.0/AUTHORS +5 -0
  2. pyfvtool-0.6.0/LICENSE +21 -0
  3. pyfvtool-0.6.0/PKG-INFO +156 -0
  4. pyfvtool-0.6.0/README.md +134 -0
  5. pyfvtool-0.6.0/pyproject.toml +41 -0
  6. pyfvtool-0.6.0/setup.cfg +4 -0
  7. pyfvtool-0.6.0/setup.py +4 -0
  8. pyfvtool-0.6.0/src/pyfvtool/__init__.py +32 -0
  9. pyfvtool-0.6.0/src/pyfvtool/advection.py +1848 -0
  10. pyfvtool-0.6.0/src/pyfvtool/averaging.py +590 -0
  11. pyfvtool-0.6.0/src/pyfvtool/boundary.py +2129 -0
  12. pyfvtool-0.6.0/src/pyfvtool/calculus.py +474 -0
  13. pyfvtool-0.6.0/src/pyfvtool/cell.py +647 -0
  14. pyfvtool-0.6.0/src/pyfvtool/diffusion.py +495 -0
  15. pyfvtool-0.6.0/src/pyfvtool/face.py +622 -0
  16. pyfvtool-0.6.0/src/pyfvtool/mesh.py +1254 -0
  17. pyfvtool-0.6.0/src/pyfvtool/pdesolver.py +190 -0
  18. pyfvtool-0.6.0/src/pyfvtool/solvers/oneMKL_pardiso/__init__.py +6 -0
  19. pyfvtool-0.6.0/src/pyfvtool/solvers/oneMKL_pardiso/pardiso_wrapper.py +433 -0
  20. pyfvtool-0.6.0/src/pyfvtool/solvers/oneMKL_pardiso/spsolve.py +81 -0
  21. pyfvtool-0.6.0/src/pyfvtool/source.py +146 -0
  22. pyfvtool-0.6.0/src/pyfvtool/utilities.py +217 -0
  23. pyfvtool-0.6.0/src/pyfvtool/visualization.py +168 -0
  24. pyfvtool-0.6.0/src/pyfvtool.egg-info/PKG-INFO +156 -0
  25. pyfvtool-0.6.0/src/pyfvtool.egg-info/SOURCES.txt +49 -0
  26. pyfvtool-0.6.0/src/pyfvtool.egg-info/dependency_links.txt +1 -0
  27. pyfvtool-0.6.0/src/pyfvtool.egg-info/requires.txt +3 -0
  28. pyfvtool-0.6.0/src/pyfvtool.egg-info/top_level.txt +1 -0
  29. pyfvtool-0.6.0/tests/test_BC.py +159 -0
  30. pyfvtool-0.6.0/tests/test_BC_utility_methods.py +287 -0
  31. pyfvtool-0.6.0/tests/test_CellVariable_copy.py +93 -0
  32. pyfvtool-0.6.0/tests/test_CellVariable_methods.py +110 -0
  33. pyfvtool-0.6.0/tests/test_PyFVTool_basic_test.py +340 -0
  34. pyfvtool-0.6.0/tests/test_PyFVTool_introduction_demo.py +985 -0
  35. pyfvtool-0.6.0/tests/test_README_script.py +75 -0
  36. pyfvtool-0.6.0/tests/test_TrackedArray.py +127 -0
  37. pyfvtool-0.6.0/tests/test_benchmark_1d.py +149 -0
  38. pyfvtool-0.6.0/tests/test_cell_volumes.py +208 -0
  39. pyfvtool-0.6.0/tests/test_coordinate_labels.py +360 -0
  40. pyfvtool-0.6.0/tests/test_cylindrical1D_diffusion.py +221 -0
  41. pyfvtool-0.6.0/tests/test_cylindrical1D_diffusion_source_photothermal.py +331 -0
  42. pyfvtool-0.6.0/tests/test_cylindrical1D_diffusion_steady.py +203 -0
  43. pyfvtool-0.6.0/tests/test_cylindrical2D_convection_Taylor.py +363 -0
  44. pyfvtool-0.6.0/tests/test_div_grad.py +52 -0
  45. pyfvtool-0.6.0/tests/test_facevariable.py +145 -0
  46. pyfvtool-0.6.0/tests/test_oneMKL_PARDISO_interface.py +359 -0
  47. pyfvtool-0.6.0/tests/test_pdesolver_mason_weaver.py +102 -0
  48. pyfvtool-0.6.0/tests/test_runs.py +166 -0
  49. pyfvtool-0.6.0/tests/test_spherical1D_diffusion.py +226 -0
  50. pyfvtool-0.6.0/tests/test_spherical_coordinate_examples.py +506 -0
  51. pyfvtool-0.6.0/tests/test_visualization.py +12 -0
pyfvtool-0.6.0/AUTHORS ADDED
@@ -0,0 +1,5 @@
1
+ PyFVTool Authors
2
+ ================
3
+
4
+ Ali A. Eftekhari <aliak@dtu.dk>
5
+ Martinus H. V. Werts <martinus.werts@univ-angers.fr>
pyfvtool-0.6.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2025 Ali A. Eftekhari and Martinus H. V. Werts
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,156 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyfvtool
3
+ Version: 0.6.0
4
+ Summary: Finite-volume toolbox in Python
5
+ Author-email: "Ali A. Eftekhari" <aliak@dtu.dk>, "Martinus H. V. Werts" <martinus.werts@univ-angers.fr>
6
+ Project-URL: Homepage, https://github.com/FiniteVolumeTransportPhenomena/PyFVTool
7
+ Project-URL: Bug Tracker, https://github.com/FiniteVolumeTransportPhenomena/PyFVTool/issues
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
14
+ Requires-Python: >=3.12
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ License-File: AUTHORS
18
+ Requires-Dist: numpy>=2
19
+ Requires-Dist: scipy
20
+ Requires-Dist: matplotlib
21
+ Dynamic: license-file
22
+
23
+ # PyFVTool: Python toolbox for the finite volume method
24
+
25
+ [![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.17904660-blue.svg)](https://doi.org/10.5281/zenodo.17904660)
26
+
27
+ PyFVTool discretizes and numerically solves the conservative form of transient [convection-diffusion-reaction](https://en.wikipedia.org/wiki/Convection%E2%80%93diffusion_equation) equations with variable velocity field/diffusion coefficients and source terms. PyFVTool uses the [finite volume method](https://en.wikipedia.org/wiki/Finite_volume_method) (FVM) to do this.
28
+
29
+ The partial differential equations that can be solved numerically with PyFVTool have the general form
30
+
31
+ ```math
32
+ \underbrace{\alpha\frac{\partial\phi}{\partial t}}_{\textrm{Transient term}}+\underbrace{\vec{\nabla} \cdot \left(\vec{u}\phi\right)}_{\textrm{Advection term}}+\underbrace{\vec{\nabla} \cdot (-D\vec{\nabla}\phi)}_{\textrm{Diffusion term}}+\underbrace{\beta\phi}_{\textrm{Linear source term}}+\underbrace{\gamma}_{\textrm{Constant source term}}=0
33
+ ```
34
+ with the following general form of boundary conditions (specified by constants $a$, $b$ and $c$, with $\hat{e}$ being the unit vector in the direction of the coordinate at the specific boundary):
35
+
36
+ ```math
37
+ a(\vec{\nabla}\phi \cdot \hat{e})+b\phi=c
38
+ ```
39
+ An important feature of PyFVTool is that it is 'pure scientific Python' (*i.e.* it needs only Python and the standard scientific computing libraries `numpy`, `scipy` and `matplotlib` to run). Further optional dependencies may appear in the future, *e.g.*, for increasing the computational speed via optimised numerical libraries, but these will remain optional.
40
+
41
+ PyFVTool is limited to calculations on structured meshes (regular grids). It is oriented to calculation of heat and mass transport phenomena (diffusion-advection-reaction) for the frequent cases where the flow velocity field is already known (or where flow is absent). It is not particularly suited for fluid dynamics (solving Navier-Stokes), which requires implementation of further numerical schemes on top of the current PyFVTool ([simulkade](https://github.com/simulkade) knows how). For fluid dynamics, other specialized finite-volume codes exist.
42
+
43
+ The [finite-volume](https://en.wikipedia.org/wiki/Finite_volume_method) discretization schemes in PyFVTool include:
44
+ * 1D, 2D and 3D Cartesian, cylindrical and spherical grids
45
+ * Second order (central difference) [diffusion](https://en.wikipedia.org/wiki/Diffusion_equation) terms
46
+ * Second order (central difference), first order ([upwind](https://en.wikipedia.org/wiki/Upwind_scheme)), and [total variation diminishing](https://en.wikipedia.org/wiki/Total_variation_diminishing) (TVD) for advection terms
47
+ * Constant and linear source terms
48
+ * Backward and forward [Euler](https://en.wikipedia.org/wiki/Euler_method) for transient terms
49
+ * [Dirichlet](https://en.wikipedia.org/wiki/Dirichlet_boundary_condition), [Neumann](https://en.wikipedia.org/wiki/Neumann_boundary_condition), [Robin](https://en.wikipedia.org/wiki/Robin_boundary_condition), and [periodic](https://en.wikipedia.org/wiki/Periodic_boundary_conditions) boundary conditions
50
+ * (Relatively) easy linearization of nonlinear PDEs
51
+ * Averaging methods (linear, arithmetic, geometric, harmonic, upwind, TVD)
52
+ * Divergence and gradient terms
53
+
54
+ PyFVTool is a Python implementation of [A. A. Eftekhari](https://github.com/simulkade)'s Matlab/Octave FVM solver [FVTool](https://github.com/FiniteVolumeTransportPhenomena/FVTool). It was strongly inspired by [FiPy](https://pages.nist.gov/fipy/en/latest/index.html), but it has only a fraction of FiPy's features. Boundary conditions, however, are more easily (and arguably more consistently) implemented in PyFVTool.
55
+
56
+ PyFVTool is under active development. Several test cases have been validated to match analytical solutionsn with more validation under way, in particular through the use of this toolbox in ongoing research projects. The documentation can be found at https://finitevolumetransportphenomena.github.io/PyFVTool/. It includes many [examples](https://finitevolumetransportphenomena.github.io/PyFVTool/examples/index.html) in the form of Jupyter notebooks. From these examples, it is easy to understand how to set up finite-volume solvers for heat and mass transfer.
57
+
58
+
59
+ ## Installation
60
+
61
+ ### Python environment
62
+
63
+ We recommend to use PyFVTool with Python 3.12 (no more, no less) and the most recent NumPy and SciPy versions. It is also highly recommended to use the [MiniForge](https://conda-forge.org/download/) / Anaconda / miniconda Python distributions and to set up a specific environment for PyFVTool (we'll call the environment `pyfvtool_user`).
64
+
65
+ This requires two commands to be launched from the command-line prompt.
66
+ ```
67
+ conda create --name pyfvtool_user python=3.12 numpy scipy matplotlib spyder jupyterlab tqdm
68
+
69
+ conda activate pyfvtool_user
70
+ ```
71
+
72
+ Of course, do not forget to `conda activate pyfvtool_user` the environment every time you run Python code that uses PyFVTool.
73
+
74
+ ### Installation of PyFVTool
75
+
76
+ Install PyFVTool into your specific PyFVTool Conda environment using `pip`. You will need `Python 3.12` (or later) and `numpy` (version 2.0.0 or later), `scipy`, and `matplotlib`, which are provided for by the Conda `pyfvtool_user` environment. The current `pip` install sources PyFVTool directly from GitHub.
77
+
78
+ ```
79
+ pip install git+https://github.com/FiniteVolumeTransportPhenomena/PyFVTool.git
80
+ ```
81
+
82
+ If you'd like to use PyFVTool in [Google Colab](https://colab.research.google.com/), you can enter the following in the first cell of a Colab Notebook:
83
+
84
+ ```
85
+ !pip install git+https://github.com/FiniteVolumeTransportPhenomena/PyFVTool.git
86
+ ```
87
+
88
+ This will install PyFVTool in the current Colab instance, and make it available for import in the Notebook.
89
+
90
+
91
+
92
+
93
+ ### Development installation
94
+ If you would like to work on the source code, it is possible to install a development version using `pip`. See [`CONTRIBUTING.md`](https://github.com/FiniteVolumeTransportPhenomena/PyFVTool/blob/main/CONTRIBUTING.md)
95
+
96
+
97
+
98
+
99
+ ## Example
100
+
101
+ Here is a simple example of a 1D transient diffusion equation. Further [examples](https://finitevolumetransportphenomena.github.io/PyFVTool/examples/index.html) can be found in the [documentation](https://finitevolumetransportphenomena.github.io/PyFVTool/). These examples are also available as Jupyter notebook source files in [`./docs/source/notebook-examples/`](docs/source/notebook-examples/).
102
+
103
+
104
+ ```python
105
+ import pyfvtool as pf
106
+ import matplotlib.pyplot as plt
107
+
108
+ # Solving a 1D diffusion equation with a fixed concentration
109
+ # at the left boundary and a closed boundary on the right side
110
+
111
+
112
+ # Calculation parameters
113
+ Nx = 100 # number of finite volume cells
114
+ Lx = 1.0 # [m] length of the domain
115
+ c_left = 1.0 # left boundary concentration
116
+ c_init = 0.0 # initial concentration
117
+ D_val = 1e-5 # diffusion coefficient (gas phase)
118
+ t_simulation = 7200.0 # [s] simulation time
119
+ dt = 60.0 # [s] time step
120
+ Nskip = 10 # plot every Nskip-th profile
121
+
122
+ # Define mesh
123
+ mesh = pf.Grid1D(Nx, Lx)
124
+
125
+ # Create a cell variable with initial concentration
126
+ # By default, 'no flux' boundary conditions are applied
127
+ c = pf.CellVariable(mesh, c_init)
128
+
129
+ # Switch the left boundary to Dirichlet: fixed concentration
130
+ c.BCs.left.fixedValue(c_left)
131
+
132
+ # Assign diffusivity: the diffusivity is needed at the interface between cells.
133
+ # The required `pf.FaceVariable` is obtained here using the `pf.geometricMean`
134
+ # averager.
135
+ D_cell = pf.CellVariable(mesh, D_val)
136
+ D_face = pf.geometricMean(D_cell)
137
+
138
+ # Time loop (with integrated plotting)
139
+ plt.figure(1)
140
+ plt.clf()
141
+ t = 0.0
142
+ nplot = 0
143
+ while t<t_simulation:
144
+ # Compose discretized terms for matrix equation
145
+ eqnterms = [ pf.transientTerm(c, dt),
146
+ -pf.diffusionTerm(D_face)]
147
+
148
+ # Solve PDE
149
+ pf.solvePDE(c, eqnterms)
150
+ t+=dt
151
+
152
+ if (nplot % Nskip == 0):
153
+ pf.visualizeCells(c)
154
+ nplot+=1
155
+ plt.show()
156
+ ```
@@ -0,0 +1,134 @@
1
+ # PyFVTool: Python toolbox for the finite volume method
2
+
3
+ [![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.17904660-blue.svg)](https://doi.org/10.5281/zenodo.17904660)
4
+
5
+ PyFVTool discretizes and numerically solves the conservative form of transient [convection-diffusion-reaction](https://en.wikipedia.org/wiki/Convection%E2%80%93diffusion_equation) equations with variable velocity field/diffusion coefficients and source terms. PyFVTool uses the [finite volume method](https://en.wikipedia.org/wiki/Finite_volume_method) (FVM) to do this.
6
+
7
+ The partial differential equations that can be solved numerically with PyFVTool have the general form
8
+
9
+ ```math
10
+ \underbrace{\alpha\frac{\partial\phi}{\partial t}}_{\textrm{Transient term}}+\underbrace{\vec{\nabla} \cdot \left(\vec{u}\phi\right)}_{\textrm{Advection term}}+\underbrace{\vec{\nabla} \cdot (-D\vec{\nabla}\phi)}_{\textrm{Diffusion term}}+\underbrace{\beta\phi}_{\textrm{Linear source term}}+\underbrace{\gamma}_{\textrm{Constant source term}}=0
11
+ ```
12
+ with the following general form of boundary conditions (specified by constants $a$, $b$ and $c$, with $\hat{e}$ being the unit vector in the direction of the coordinate at the specific boundary):
13
+
14
+ ```math
15
+ a(\vec{\nabla}\phi \cdot \hat{e})+b\phi=c
16
+ ```
17
+ An important feature of PyFVTool is that it is 'pure scientific Python' (*i.e.* it needs only Python and the standard scientific computing libraries `numpy`, `scipy` and `matplotlib` to run). Further optional dependencies may appear in the future, *e.g.*, for increasing the computational speed via optimised numerical libraries, but these will remain optional.
18
+
19
+ PyFVTool is limited to calculations on structured meshes (regular grids). It is oriented to calculation of heat and mass transport phenomena (diffusion-advection-reaction) for the frequent cases where the flow velocity field is already known (or where flow is absent). It is not particularly suited for fluid dynamics (solving Navier-Stokes), which requires implementation of further numerical schemes on top of the current PyFVTool ([simulkade](https://github.com/simulkade) knows how). For fluid dynamics, other specialized finite-volume codes exist.
20
+
21
+ The [finite-volume](https://en.wikipedia.org/wiki/Finite_volume_method) discretization schemes in PyFVTool include:
22
+ * 1D, 2D and 3D Cartesian, cylindrical and spherical grids
23
+ * Second order (central difference) [diffusion](https://en.wikipedia.org/wiki/Diffusion_equation) terms
24
+ * Second order (central difference), first order ([upwind](https://en.wikipedia.org/wiki/Upwind_scheme)), and [total variation diminishing](https://en.wikipedia.org/wiki/Total_variation_diminishing) (TVD) for advection terms
25
+ * Constant and linear source terms
26
+ * Backward and forward [Euler](https://en.wikipedia.org/wiki/Euler_method) for transient terms
27
+ * [Dirichlet](https://en.wikipedia.org/wiki/Dirichlet_boundary_condition), [Neumann](https://en.wikipedia.org/wiki/Neumann_boundary_condition), [Robin](https://en.wikipedia.org/wiki/Robin_boundary_condition), and [periodic](https://en.wikipedia.org/wiki/Periodic_boundary_conditions) boundary conditions
28
+ * (Relatively) easy linearization of nonlinear PDEs
29
+ * Averaging methods (linear, arithmetic, geometric, harmonic, upwind, TVD)
30
+ * Divergence and gradient terms
31
+
32
+ PyFVTool is a Python implementation of [A. A. Eftekhari](https://github.com/simulkade)'s Matlab/Octave FVM solver [FVTool](https://github.com/FiniteVolumeTransportPhenomena/FVTool). It was strongly inspired by [FiPy](https://pages.nist.gov/fipy/en/latest/index.html), but it has only a fraction of FiPy's features. Boundary conditions, however, are more easily (and arguably more consistently) implemented in PyFVTool.
33
+
34
+ PyFVTool is under active development. Several test cases have been validated to match analytical solutionsn with more validation under way, in particular through the use of this toolbox in ongoing research projects. The documentation can be found at https://finitevolumetransportphenomena.github.io/PyFVTool/. It includes many [examples](https://finitevolumetransportphenomena.github.io/PyFVTool/examples/index.html) in the form of Jupyter notebooks. From these examples, it is easy to understand how to set up finite-volume solvers for heat and mass transfer.
35
+
36
+
37
+ ## Installation
38
+
39
+ ### Python environment
40
+
41
+ We recommend to use PyFVTool with Python 3.12 (no more, no less) and the most recent NumPy and SciPy versions. It is also highly recommended to use the [MiniForge](https://conda-forge.org/download/) / Anaconda / miniconda Python distributions and to set up a specific environment for PyFVTool (we'll call the environment `pyfvtool_user`).
42
+
43
+ This requires two commands to be launched from the command-line prompt.
44
+ ```
45
+ conda create --name pyfvtool_user python=3.12 numpy scipy matplotlib spyder jupyterlab tqdm
46
+
47
+ conda activate pyfvtool_user
48
+ ```
49
+
50
+ Of course, do not forget to `conda activate pyfvtool_user` the environment every time you run Python code that uses PyFVTool.
51
+
52
+ ### Installation of PyFVTool
53
+
54
+ Install PyFVTool into your specific PyFVTool Conda environment using `pip`. You will need `Python 3.12` (or later) and `numpy` (version 2.0.0 or later), `scipy`, and `matplotlib`, which are provided for by the Conda `pyfvtool_user` environment. The current `pip` install sources PyFVTool directly from GitHub.
55
+
56
+ ```
57
+ pip install git+https://github.com/FiniteVolumeTransportPhenomena/PyFVTool.git
58
+ ```
59
+
60
+ If you'd like to use PyFVTool in [Google Colab](https://colab.research.google.com/), you can enter the following in the first cell of a Colab Notebook:
61
+
62
+ ```
63
+ !pip install git+https://github.com/FiniteVolumeTransportPhenomena/PyFVTool.git
64
+ ```
65
+
66
+ This will install PyFVTool in the current Colab instance, and make it available for import in the Notebook.
67
+
68
+
69
+
70
+
71
+ ### Development installation
72
+ If you would like to work on the source code, it is possible to install a development version using `pip`. See [`CONTRIBUTING.md`](https://github.com/FiniteVolumeTransportPhenomena/PyFVTool/blob/main/CONTRIBUTING.md)
73
+
74
+
75
+
76
+
77
+ ## Example
78
+
79
+ Here is a simple example of a 1D transient diffusion equation. Further [examples](https://finitevolumetransportphenomena.github.io/PyFVTool/examples/index.html) can be found in the [documentation](https://finitevolumetransportphenomena.github.io/PyFVTool/). These examples are also available as Jupyter notebook source files in [`./docs/source/notebook-examples/`](docs/source/notebook-examples/).
80
+
81
+
82
+ ```python
83
+ import pyfvtool as pf
84
+ import matplotlib.pyplot as plt
85
+
86
+ # Solving a 1D diffusion equation with a fixed concentration
87
+ # at the left boundary and a closed boundary on the right side
88
+
89
+
90
+ # Calculation parameters
91
+ Nx = 100 # number of finite volume cells
92
+ Lx = 1.0 # [m] length of the domain
93
+ c_left = 1.0 # left boundary concentration
94
+ c_init = 0.0 # initial concentration
95
+ D_val = 1e-5 # diffusion coefficient (gas phase)
96
+ t_simulation = 7200.0 # [s] simulation time
97
+ dt = 60.0 # [s] time step
98
+ Nskip = 10 # plot every Nskip-th profile
99
+
100
+ # Define mesh
101
+ mesh = pf.Grid1D(Nx, Lx)
102
+
103
+ # Create a cell variable with initial concentration
104
+ # By default, 'no flux' boundary conditions are applied
105
+ c = pf.CellVariable(mesh, c_init)
106
+
107
+ # Switch the left boundary to Dirichlet: fixed concentration
108
+ c.BCs.left.fixedValue(c_left)
109
+
110
+ # Assign diffusivity: the diffusivity is needed at the interface between cells.
111
+ # The required `pf.FaceVariable` is obtained here using the `pf.geometricMean`
112
+ # averager.
113
+ D_cell = pf.CellVariable(mesh, D_val)
114
+ D_face = pf.geometricMean(D_cell)
115
+
116
+ # Time loop (with integrated plotting)
117
+ plt.figure(1)
118
+ plt.clf()
119
+ t = 0.0
120
+ nplot = 0
121
+ while t<t_simulation:
122
+ # Compose discretized terms for matrix equation
123
+ eqnterms = [ pf.transientTerm(c, dt),
124
+ -pf.diffusionTerm(D_face)]
125
+
126
+ # Solve PDE
127
+ pf.solvePDE(c, eqnterms)
128
+ t+=dt
129
+
130
+ if (nplot % Nskip == 0):
131
+ pf.visualizeCells(c)
132
+ nplot+=1
133
+ plt.show()
134
+ ```
@@ -0,0 +1,41 @@
1
+ # minimalist pyproject.toml for PyFVTool
2
+
3
+ [project]
4
+ name = "pyfvtool"
5
+ dynamic = ["version"] # version will be read from pyfvtool/__init__.py
6
+ authors = [
7
+ { name="Ali A. Eftekhari", email="aliak@dtu.dk" },
8
+ { name="Martinus H. V. Werts", email="martinus.werts@univ-angers.fr" }
9
+ ]
10
+ description = "Finite-volume toolbox in Python"
11
+ classifiers = [
12
+ "Programming Language :: Python :: 3",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Operating System :: OS Independent",
15
+ "Development Status :: 4 - Beta",
16
+ "Intended Audience :: Science/Research",
17
+ "Topic :: Scientific/Engineering :: Mathematics"
18
+ ]
19
+ readme = "README.md"
20
+ requires-python = ">=3.12"
21
+ dependencies = [
22
+ "numpy>=2",
23
+ "scipy",
24
+ "matplotlib"
25
+ ]
26
+
27
+
28
+ [project.urls]
29
+ "Homepage" = "https://github.com/FiniteVolumeTransportPhenomena/PyFVTool"
30
+ "Bug Tracker" = "https://github.com/FiniteVolumeTransportPhenomena/PyFVTool/issues"
31
+
32
+ [build-system]
33
+ requires = ["setuptools>=61.0", "numpy>=2", "scipy", "matplotlib"]
34
+ build-backend = "setuptools.build_meta"
35
+
36
+ [tool.setuptools.packages.find]
37
+ where = ["src"]
38
+
39
+ [tool.setuptools.dynamic]
40
+ # version will be read from pyfvtool/__init__.py
41
+ version = {attr = "pyfvtool.__version__"}
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,4 @@
1
+ # minimalist setup.py
2
+ from setuptools import setup
3
+
4
+ setup()
@@ -0,0 +1,32 @@
1
+ __version__ = "0.6.0"
2
+
3
+ __author__ = ["Ali A. Eftekhari", "Martinus H. V. Werts"]
4
+
5
+ __email__ = ["aliak@dtu.dk", "martinus.werts@univ-angers.fr"]
6
+
7
+ __copyright__ = "Copyright 2023-2026, The Authors"
8
+
9
+ __license__ = "MIT License"
10
+
11
+
12
+
13
+ from .mesh import Grid1D, CylindricalGrid1D, SphericalGrid1D
14
+ from .mesh import Grid2D, CylindricalGrid2D, PolarGrid2D
15
+ from .mesh import Grid3D, CylindricalGrid3D, SphericalGrid3D
16
+ from .advection import convectionTerm, convectionTVDupwindRHSTerm,\
17
+ convectionUpwindTerm
18
+ from .diffusion import diffusionTerm
19
+ from .source import linearSourceTerm, constantSourceTerm, transientTerm
20
+ from .boundary import BoundaryConditions, boundaryConditionsTerm
21
+ from .utilities import fluxLimiter
22
+ from .calculus import gradient, gradientFixedBC
23
+ from .calculus import divergence, divergenceTerm
24
+ from .averaging import linearMean, arithmeticMean, upwindMean,\
25
+ harmonicMean, geometricMean, tvdMean
26
+ from .pdesolver import solveMatrixPDE, solvePDE, solveExplicitPDE
27
+ from .cell import CellVariable
28
+ from .cell import funceval, celleval
29
+ from .cell import cellLocations
30
+ from .face import FaceVariable, faceeval
31
+ from .face import faceLocations
32
+ from .visualization import visualizeCells