CDR-Solv: Solving the Convection-Diffusion-Reaction Equation with Algebraic Sub-Grid Scale Stabilization Using Python
Abstract
1. Introduction
1.1. Equation
1.2. Concepts
1.3. Solution Methods
1.4. Galerkin’s Method
1.4.1. Variational Formulation
1.4.2. Approach Space
1.4.3. Galerkin Discretization
1.4.4. Error Analysis
1.4.5. Instability
1.5. Related Works
1.6. Outline
2. Materials and Methods
2.1. Mathematical Models
2.2. Shape Functions
2.3. Regular Mesh
2.4. Connectivity Matrix
2.5. Elementary Matrix and Force Vector
2.6. User Interface and Execution
- main_cdr.py: This is the main file that contains initialization, the user interface, and all the used functions;
- get_config: This function retrieves all data entered in the user interface and verifies it;
- nodes: This function creates the regular mesh. The first column is the X coordinate, the second column is the Y coordinate, and each row represents a different node. The order of the nodes in this matrix determines the overall node numbering;
- tc3: This function generates the connectivity matrix. As shown in Figure 2, each row represents a triangular element and its component nodes;
- cccnpg: A function that transforms Cartesian coordinates to natural coordinates at a Gauss point;
- kefe2DT: A function that obtains the elemental matrix and force vector, corrected according to ASGS stabilization;
- ffT: A function that generates shape functions and their derivatives at a Gauss point for a given polynomial degree;
- vffydp2DT: Calculates the values of the shape functions and their partial derivatives at all Gauss points for triangular elements and all polynomial degrees;
- gauss2DT: Function to obtain matrices with Gauss weights and points;
- es2: Assembles and solves the system of equations under the entered parameters.
3. Results
3.1. Evolution with Polynomial Degree
3.2. Other Functions for Source Term
3.3. Comparative Validation
4. Discussion
5. Conclusions
Author Contributions
Funding
Institutional Review Board Statement
Informed Consent Statement
Data Availability Statement
Acknowledgments
Conflicts of Interest
References
- Yang, J.; Tao, Y.; Ren, W.; Cao, P. Numerical simulation of groundwater contaminant transport in unsaturated flow. Water Supply 2020, 20, 3730–3738. [Google Scholar] [CrossRef]
- Ziemys, A.; Klemm, S.; Milosevic, M.; Yokoi, K.; Ferrari, M.; Kojic, M. Computational analysis of drug transport in tumor microenvironment as a critical compartment for nanotherapeutic pharmacokinetics. Drug Deliv. 2016, 23, 2524–2531. [Google Scholar] [CrossRef]
- Zuo, H.; Yin, Y.; Yang, Z.; Deng, S.; Li, H.; Liu, H. High-order models for convection–diffusion-reaction transport in multiscale porous media. Chem. Eng. Sci. 2024, 286, 119663. [Google Scholar] [CrossRef]
- Torres, R.C. Influencia Del Término Difusivo en el Modelamiento de Transporte de Masa Usando la Ecuación de Convección Difusión no Lineal. Ph.D. Thesis, Universidad Nacional de Trujillo, Trujillo, Peru, 2024. Available online: https://dspace.unitru.edu.pe/items/756435db-e611-4478-8241-7f1be2b71638 (accessed on 27 July 2025).
- Torres, C.P.C. Evaluación de la Concentración de Material Radiactivo Disperso en la Atmósfera a Través de la Ecuación de Difusión: Solución de la Ecuación de Advección Para la Liberación Instantánea de Contaminantes; Escuela Politécnica Nacional: Quito, Ecuador, 2023; Available online: https://bibdigital.epn.edu.ec/handle/15000/24851 (accessed on 27 July 2025).
- Galeano, C.H.; Mantilla, J.M.; Garzón-Alvarado, D.A. Experimentos numéricos sobre ecuaciones de reacción convección difusión con divergencia nula del campo de velocidad. Rev. Int. Métodos Numéricos Para Cálculo Y Diseño En Ing. 2010, 26, 69–81. Available online: https://core.ac.uk/download/pdf/41822303.pdf (accessed on 27 July 2025).
- López, J.A.M. Análisis Numérico de un Método de Galerkin Para un Problema Evolutivo no Lineal; Universidad de Córdoba: Córdoba, Spain, 2024; Available online: https://repositorio.unicordoba.edu.co/handle/ucordoba/8849 (accessed on 27 July 2025).
- Marulanda, A.F.H.; Posada, L.J.G. Solución de la ecuación de convección difusión mediante las funciones de base radial multicuádricas. Ing. USBMed 2020, 11, 48–53. [Google Scholar] [CrossRef]
- Guzman, F.C.O.; Rodriguez, P.A.A.; Parra, C.A.B. Solución Numérica de una ecuación de convección-difusión no local fraccionaria. Entre Cienc. E Ing. 2024, 18, 25–31. [Google Scholar] [CrossRef]
- Asensi, I.P. Resolución de Ecuaciones de Convección-Difusión en 2D Usando el Método de las Diferencias Finitas Compactas. Master’s Thesis, Universitat Politècnica de València, Valencia, Spain, 2019. Available online: https://riunet.upv.es/handle/10251/129534 (accessed on 27 July 2025).
- González, T.C. Adaptación de Mallados de Elementos Finitos Conformes Utilizando Elementos de Tipo Hexaedro. Master’s Thesis, Universidad Politécnica de Madrid, Madrid, Spain, 2021. Available online: https://oa.upm.es/67850/ (accessed on 27 July 2025).
- Rodríguez, C.A.T. Desarrollo de Código Bidimensional Transitorio Para el Estudio de la Transferencia de Calor en Flujo Laminar e Incompresible Aplicado a Convección Natural Con Alta Variación de Relaciones de Aspect. Master’s Thesis, Universidade Estadual de Campinas, Campinas, Brazil, 2022. Available online: https://repositorio.unicamp.br/acervo/detalhe/1242115 (accessed on 27 July 2025).
- Broersen, D.; Stevenson, R.P. A Petrov-Galerkin discretization with optimal test space of a mild-weak formulation of convection-diffusion equations in mixed form. IMA J. Numer. Anal. 2015, 35, 39–73. [Google Scholar] [CrossRef]
- Benítez, M.; Cockburn, B. Post-processing for spatial accuracy-enhancement of pure Lagrange–Galerkin schemes applied to convection-diffusion equations. IMA J. Numer. Anal. 2022, 42, 54–77. [Google Scholar] [CrossRef]
- Knobloch, P.; Tobiska, L. On the stability of finite-element discretizations of convection-diffusion-reaction equations. IMA J. Numer. Anal. 2011, 31, 147–164. [Google Scholar] [CrossRef]
- Morton, K.W. The convection-diffusion Petrov-Galerkin story. IMA J. Numer. Anal. 2010, 30, 231–240. [Google Scholar] [CrossRef]
- Chen, Y.; Cockburn, B. Analysis of variable-degree HDG methods for convection-diffusion equations. Part I: General nonconforming meshes. IMA J. Numer. Anal. 2012, 32, 1267–1293. [Google Scholar] [CrossRef]
- Dolejsi, V.; Feistauer, M.; Kucera, V.; Sobotikova, V. An optimal L (L2)-error estimate for the discontinuous Galerkin approximation of a nonlinear non-stationary convection-diffusion problem. IMA J. Numer. Anal. 2007, 28, 496–521. [Google Scholar] [CrossRef]
- Chen, L.; Bagci, H. Steady-State Simulation of Semiconductor Devices Using Discontinuous Galerkin Methods. IEEE Access 2020, 8, 16203–16215. [Google Scholar] [CrossRef]
- King, B.B.; Krueger, D.A. The 1-D convection diffusion equation: Galerkin least squares approximations and feedback control. In Proceedings of the 2004 43rd IEEE Conference on Decision and Control (CDC) (IEEE Cat. No.04CH37601), Nassau, Bahamas, 14–17 December 2004; Volume 2, pp. 1502–1507. [Google Scholar] [CrossRef]
- Gómez, H.; Colominas, I.; Martínez, F.L.N.; Maldonado, M.C. Un nuevo enfoque para el tratamiento de los términos difusivos en la ecuación de convección-difusión en el método de Galerkin discontinuo. Rev. Int. Métodos Numéricos Para Cálculo Y Diseño En Ing. 2007, 23, 343–362. Available online: https://engineering.purdue.edu/gomez/assets/pdf/art03.pdf (accessed on 27 July 2025).
- Chen, H.; Li, J.; Qiu, W. Robust a posteriori error estimates for HDG method for convection–diffusion equations. IMA J. Numer. Anal. 2015, 36, 437–462. [Google Scholar] [CrossRef]
- Brooks, A.N.; Hughes, T.J.R. Streamline upwind/Petrov-Galerkin formulations for convection dominated flows with particular emphasis on the incompressible Navier-Stokes equations. Comput. Methods Appl. Mech. Eng. 1982, 32, 199–259. [Google Scholar] [CrossRef]
- Lima, S.A.; Kamrujjaman, M.; Islam, M.S. Numerical solution of convection–diffusion–reaction equations by a finite element method with error correlation. AIP Adv. 2021, 11, 085225. [Google Scholar] [CrossRef]
- Balsa-Canto, E.; López-Núñez, A.; Vázquez, C. Numerical methods for a nonlinear reaction–diffusion system modelling a batch culture of biofilm. Appl. Math. Model. 2017, 41, 164–179. [Google Scholar] [CrossRef]
- Nadukandi, P.; Oñate, E.; Garcia, J. A high-resolution Petrov–Galerkin method for the 1D convection–diffusion–reaction problem. Comput. Methods Appl. Mech. Eng. 2010, 199, 525–546. [Google Scholar] [CrossRef]
- Nadukandi, P.; Oñate, E.; García, J. A high-resolution Petrov–Galerkin method for the convection–diffusion–reaction problem. Part II—A multidimensional extension. Comput. Methods Appl. Mech. Eng. 2012, 213–216, 327–352. [Google Scholar] [CrossRef]
- Shirzadi, A.; Ling, L.; Abbasbandy, S. Meshless simulations of the two-dimensional fractional-time convection–diffusion–reaction equations. Eng. Anal. Bound. Elem. 2012, 36, 1522–1527. [Google Scholar] [CrossRef]
- Liu, S.; Li, P.-W.; Fan, C.-M.; Gu, Y. Localized method of fundamental solutions for two- and three-dimensional transient convection-diffusion-reaction equations. Eng. Anal. Bound. Elem. 2021, 124, 237–244. [Google Scholar] [CrossRef]
- Theeraek, P.; Phongthanapanich, S.; Dechaumphai, P. Solving convection-diffusion-reaction equation by adaptive finite volume element method. Math. Comput. Simul. 2011, 82, 220–233. [Google Scholar] [CrossRef]
- Mkhatshwa, M.P.; Khumalo, M. Trivariate Spectral Collocation Approach for the Numerical Solution of Three-Dimensional Elliptic Partial Differential Equations. Mathematics 2022, 10, 2260. [Google Scholar] [CrossRef]
- Wei, J.; Ge, Y.; Wang, Y. High-Order Compact Difference Method for Solving Two- and Three-Dimensional Unsteady Convection Diffusion Reaction Equations. Axioms 2022, 11, 111. [Google Scholar] [CrossRef]
- Ullmann, S.; Müller, C.; Lang, J. Stochastic Galerkin Reduced Basis Methods for Parametrized Linear Convection–Diffusion–Reaction Equations. Fluids 2021, 6, 263. [Google Scholar] [CrossRef]
- Xiao, X.; Feng, X.; Li, Z. A gradient recovery–based adaptive finite element method for convection-diffusion-reaction equations on surfaces. Int. J. Numer. Methods Eng. 2019, 120, 901–917. [Google Scholar] [CrossRef]
- Zalesak, S.T. Fully multidimensional flux-corrected transport algorithms for fluids. J. Comput. Phys. 1979, 31, 335–362. [Google Scholar] [CrossRef]
- Parhizi, M.; Kilaz, G.; Ostanek, J.K.; Jain, A. Analytical solution of the convection-diffusion-reaction-source (CDRS) equation using Green’s function technique. Int. Commun. Heat Mass Transf. 2022, 131, 105869. [Google Scholar] [CrossRef]
- Baratta, I.A.; Dean, J.P.; Dokken, J.S.; Habera, M.; Hale, J.S.; Richardson, C.N.; Rognes, M.E.; Scroggs, M.W.; Sime, N.; Wells, G.N. DOLFINx: The Next Generation FEniCS Problem Solving Environment, Version v1; Zenodo: Geneva, Switzerland, 2023. [Google Scholar] [CrossRef]
- OpenCFD Ltd. OpenFOAM: The Open Source CFD Toolbox, Version 11; OpenCFD Ltd.: Berkshire, UK, 2025; Available online: https://www.openfoam.com/ (accessed on 27 July 2025).
- Hughes, T.J.R.; Franca, L.P.; Hulbert, G.M. A new finite element formulation for computational fluid dynamics: VIII. The galerkin/least-squares method for advective-diffusive equations. Comput. Methods Appl. Mech. Eng. 1989, 73, 173–189. [Google Scholar] [CrossRef]
- Huang, W.; Russell, R.D. Adaptive Moving Mesh Methods. In Applied Mathematical Sciences; Springer: New York, NY, USA, 2011; Volume 174. [Google Scholar] [CrossRef]
- Codina, R. Stabilized finite element approximation of transient incompressible flows using orthogonal subscales. Comput. Methods Appl. Mech. Eng. 2002, 191, 4295–4321. [Google Scholar] [CrossRef]
- Hughes, T.J.R.; Scovazzi, G.; Franca, L.P. Multiscale and Stabilized Methods. In Encyclopedia of Computational Mechanics; Wiley: Hoboken, NJ, USA, 2004. [Google Scholar] [CrossRef]
Parameters | CDR-Solv Solution | FEniCS Solution | Average Execution Times * |
---|---|---|---|
CDR-Solv: 1.0135 FEniCS: 1.0908 Approximate computational complexity: | |||
CDR-Solv: 0.9874 FEniCS: 1.1572 Approximate computational complexity: | |||
CDR-Solv: 1.1538 FEniCS: 1.2270 Approximate computational complexity: | |||
CDR-Solv: 1.5529 FEniCS: 2.1067 Approximate computational complexity: |
Name | Technique | Advantages | Limitations |
---|---|---|---|
CDR-Solv (Present Study) | ASGS stabilization with Python implementation | Open-source accessibility, educational value, high-order finite elements, robust stabilization, user-friendly interface | Limited to structured meshes, requires Python environment |
Nadukandi et al. [26] | High-resolution Petrov–Galerkin (HRPG) with linear elements | Superior shock-capturing, second-order accuracy in smooth regimes | Complex parameter calibration, limited to 1D problems, requires specialized implementation |
Liu et al. [29] | Localized Method of Fundamental Solutions (LMFS) with MATLAB | Meshless approach, sparse matrix structure, large-scale capability | Requires MATLAB license, complex mathematical formulation, limited geometric flexibility |
Mkhatshwa & Khumalo [31] | Trivariate Spectral Collocation (TSQLM) with MATLAB | Exceptional accuracy (10−17), minimal grid points, spectral convergence | MATLAB dependency, limited to elliptic problems, requires specialized mathematical expertise |
Parhizi et al. [36] | Green’s function analytical approach | Pure analytical framework, superior computational speed, exact solutions | Limited to specific source terms, complex mathematical derivations, restricted geometric applications |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Villota-Cadena, Á.P.; Sandoval-Palis, I.P.; Grijalva-Villegas, G.F.; Herrera-Granda, E.P. CDR-Solv: Solving the Convection-Diffusion-Reaction Equation with Algebraic Sub-Grid Scale Stabilization Using Python. Appl. Sci. 2025, 15, 10256. https://doi.org/10.3390/app151810256
Villota-Cadena ÁP, Sandoval-Palis IP, Grijalva-Villegas GF, Herrera-Granda EP. CDR-Solv: Solving the Convection-Diffusion-Reaction Equation with Algebraic Sub-Grid Scale Stabilization Using Python. Applied Sciences. 2025; 15(18):10256. https://doi.org/10.3390/app151810256
Chicago/Turabian StyleVillota-Cadena, Ángel P., Iván P. Sandoval-Palis, Gabriel F. Grijalva-Villegas, and Erick P. Herrera-Granda. 2025. "CDR-Solv: Solving the Convection-Diffusion-Reaction Equation with Algebraic Sub-Grid Scale Stabilization Using Python" Applied Sciences 15, no. 18: 10256. https://doi.org/10.3390/app151810256
APA StyleVillota-Cadena, Á. P., Sandoval-Palis, I. P., Grijalva-Villegas, G. F., & Herrera-Granda, E. P. (2025). CDR-Solv: Solving the Convection-Diffusion-Reaction Equation with Algebraic Sub-Grid Scale Stabilization Using Python. Applied Sciences, 15(18), 10256. https://doi.org/10.3390/app151810256