Numerical Modeling of Nanoparticle Transport in Porous Media: MATLAB/PYTHON Approach (Micro & Nano Technologies) 9780323905114

Numerical Modeling of Nanoparticle Transport in Porous Media: MATLAB/PYTHON Approach focuses on modeling and numerical a

236 22 26MB

English Pages 417 Year 2023

Report DMCA / Copyright

DOWNLOAD PDF FILE

Table of contents :
Cover
NUMERICAL MODELING OF NANOPARTICLE TRANSPORT IN POROUS MEDIA: MATLAB/PYTHON Approach
Copyright
Preface
Introduction
1 Nanotechnology
2 Units and dimensions
3 Some basics of mathematics
3.1 Notations and definitions
3.2 Error function
3.3 Matrices
3.4 Equations types
4 Some basics of numerical analysis
4.1 Error estimation
4.2 Taylor series
4.3 Newton–Raphson method
4.4 Runge–Kutta method
4.5 Finite difference method
4.6 Finite element method
4.6.1 Standard finite element method
4.6.2 Mixed finite element method
5 Short guide to MATLAB
5.1 Arithmetic and array operators
5.2 Multiple statements in a single line
5.3 Long line dividing
5.4 Priority of arithmetic operations
5.5 Linearly spaced vector
5.6 Colon operator
5.7 Matrix multiplication
5.8 Matrix transpose
5.9 Matrix inverse
5.10 Element-wise operations
5.11 Concatenation
5.12 Relational and logical operators:
5.13 Plotting
6 Short guide to python
6.1 Arithmetic and logical operator of Python
References
Dedication
Acknowledgment
1 . Basic concepts and modeling aspects
1.1 Continuum theory and fluid flow
1.2 Flow in porous media
1.3 Rock properties
1.3.1 Porosity
1.3.2 Permeability
1.4 Fluid properties
1.4.1 Density
1.4.2 Viscosity
1.4.3 Saturation
1.4.4 Capillary pressure
1.4.5 Relative permeability
1.5 Modeling of flow in porous media
1.5.1 Mass conservation equation
1.5.2 Darcy's law
1.5.3 Single-phase flow model
1.5.4 Dispersion model
1.6 Filtration theory
1.7 Nanoparticles transport with single-phase flow
1.7.1 Transport equations
1.7.2 Model validation
1.7.3 MATLAB code
1.8 Nanoparticles transport with two-phase flow
1.8.1 Porosity and permeability variations
1.8.2 MATLAB code of porosity–permeability variations
1.8.3 Relative permeability variations
1.8.4 Model validation
1.9 General model for different nanoparticles interval sizes
References
Further reading
2 . Dimensional analysis and analytical solutions
2.1 Dimensional analysis
2.1.1 Nanoparticles transport with single-phase flow
2.1.2 Nondimensional single-phase model
2.1.3 Nanoparticles transport with two-phase flow
2.1.4 MATLAB code of dimensional two-phase case
2.1.5 Nondimensional two-phase model
2.2 Analytical solutions
2.2.1 Nanoparticles transport with attachment model
2.2.2 MATLAB code of transport model with attachment
2.2.3 MATLAB code of one-site model
References
Further reading
3 . Spatial numerical discretization methods for nanoparticles transport in porous media
3.1 Mesh generation
3.1.1 MATLAB code for 1D-grid function
3.1.2 MATLAB code for uniform 2D-grid function
3.1.3 MATLAB code for nonuniform 2D-grid function
3.1.4 MATLAB code for nonuniform 3D-grid function
3.2 Cell-centered finite difference method
3.2.1 Pressure equation discretization
3.2.2 Darcy's law discretization
3.2.3 Boundary conditions treatment
3.2.4 MATLAB codes
3.3 Shifting matrix method with MATLAB implementation
3.3.1 Shifting technique
3.3.2 Harmonic mean of permeability
3.3.3 Transmissibility's matrices
3.3.4 Difference equations
3.3.5 MATLAB codes of the diffusion and advection terms
3.4 Finite element method
3.4.1 Finite elements discretization
3.4.2 Weak formulation
3.4.3 Raviart–Thomas (RT0) space
3.5 Mixed finite element method
3.5.1 Mixed weak formulation
3.5.2 Mixed finite element approximation
3.5.3 Numerical algorithm
3.5.4 Numerical test
References
4 . Temporal numerical discretization schemes
4.1 Introduction
4.2 Forward and backward uler difference schemes
4.3 Courant–Friedrichs–Lewy stability condition
4.4 Multiscale time-splitting scheme
4.5 Relaxation factor
4.6 Implicit pressure implicit concentration scheme
4.7 Implicit pressure explicit saturation implicit concentration scheme
4.8 MATLAB code
4.9 Stability analysis of the IMPES method
References
5 . Iterative schemes and convergence analysis
5.1 Introduction
5.2 Iterative method for nanoparticles in single-phase flow
5.2.1 Implicit pressure–concentration scheme
5.2.2 Iterative Implicit Pressure Concentration scheme
5.2.3 Convergence theory
5.2.3.1 Assumptions
5.2.3.2 Lemmas
5.2.3.3 Theorem
5.3 Iterative method for nanoparticles in two-phase flow
5.3.1 Implicit Pressure Explicit Saturation–Implicit Concentration scheme
5.3.2 Iterative IMPES-IMC technique
5.3.3 Convergence theory
5.3.3.1 Assumptions
5.3.3.2 Lemmas
5.3.3.3 Theorem
5.4 Numerical example
5.5 MATLAB code
References
6 . Nanoparticles transport in fractured porous media
6.1 Introduction
6.2 Dual-continuum approaches
6.3 Boundary conditions approach
6.4 Shape factor approach
6.5 Discrete fracture model
6.5.1 DFM for nanoparticles in single-phase flow
6.5.2 DFM for nanoparticles in two-phase flow
6.5.3 Multiscale time-splitting scheme
6.5.3.1 MSTS for pressure
6.5.3.2 MSTS for saturation
6.5.3.3 MSTS for concentration
6.5.4 Numerical example
6.6 Hybrid embedded fracture model
References
7 . Nanoparticles transport in anisotropic porous media
7.1 Nature of the anisotropic porous media
7.2 Modeling of flow in anisotropic porous media
7.3 Nanoparticles transport in anisotropic porous media
7.4 Numerical methods for anisotropic porous media
7.5 Multipoint flux approximation
7.6 Numerical example
References
8 . Magnetic nanoparticles transport in porous media
8.1 Introduction
8.2 Modeling of magnetic nanoparticles
8.2.1 MATLAB code
8.3 Magnetic nanoparticles in single-phase flow
8.4 Magnetic nanoparticles in two-phase flow
8.4.1 Example: countercurrent imbibition
8.4.2 MATLAB code
8.5 Analytical solutions
8.5.1 Analytical solution of magnetic nanoparticles in porous media
8.5.2 MATLAB code
References
Further reading
9 . Nano-ferrofluids transport in porous media
9.1 Introduction
9.2 Properties of ferrofluids
9.3 Ferrofluids in single-phase flow
9.4 Analytical solutions
9.4.1 MATLAB code
9.4.2 MATLAB code
9.4.3 MATLAB code
9.5 Nonisothermal ferrofluids transport in porous media
9.5.1 Numerical algorithm
9.5.2 Numerical example
9.6 Ferrofluids transport in two-phase flow
9.6.1 Governing equations and constraints
9.6.2 Numerical algorithm
References
10 . Other nanoparticles transport interactions
10.1 Stability of nanoparticles suspensions
10.2 Nanoparticles with NAPL transport
10.3 Polymer transport under magnetic field in porous media
10.3.1 Analytical solution of polymer flow
10.4 Nanoparticles with nonisothermal flow
10.4.1 Thermal properties of nanofluids
10.4.2 Governing model
10.4.3 Numerical method
10.5 Nanofluids in boundary layer flow
10.5.1 Flow over a vertical flat plate
10.5.2 Flow over a horizontal flat plate
10.5.3 Convective nanofluids in non-Darcy porous media
10.5.4 Numerical method
10.5.5 MATLAB code
References
11 . Machine learning techniques for nanoparticles transport
11.1 Introduction
11.2 Machine learning techniques
11.2.1 Linear regression
11.2.2 K-nearest neighbor
11.2.3 Decision trees
11.2.4 Random forest
11.2.5 Support vector machines
11.2.6 Gradient boosting regression
11.2.7 Artificial neural networks
11.3 Performance evaluation metrics
11.3.1 Mean absolute error
11.3.2 Mean squared error
11.3.3 Root mean squared error
11.3.4 Mean absolute percentage error
11.3.5 R2 correlation
11.4 Datasets
11.4.1 Artificial datasets
11.4.2 Data preprocessing and correlation
11.4.3 Features importance
11.5 Machine learning implementation
11.6 Hyperparameters tuning
11.7 Example of Jupyter Notebook implementation
11.7.1 Import libraries
11.7.2 Data preparation
11.7.3 Data correlation
11.7.4 Machine learning algorithm
11.7.5 Features importance
11.7.6 Data scaling
11.7.7 Hyperparameters tuning implementation
11.8 Implementation of LR, k-NN, RF, SVR, GBR, and ANN method
References
12 . Applications of nanoparticles in porous media
12.1 Introduction
12.2 Nanoparticles in enhanced oil recovery
12.3 Nanoparticles with heat transfer
12.4 Combination of nanoparticles and surfactants
12.5 Using nanoparticles in harvesting atmosphere water
12.6 Carbon dioxide capture by nanoporous materials
12.7 CO2–nanoparticles sequestration in geological storages
12.8 Nanofluids in metal hydride hydrogen storages
References
Further reading
Index
Recommend Papers

Numerical Modeling of Nanoparticle Transport in Porous Media: MATLAB/PYTHON Approach (Micro & Nano Technologies)
 9780323905114

  • 0 0 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

NUMERICAL MODELING OF NANOPARTICLE TRANSPORT IN POROUS MEDIA MATLAB/PYTHON Approach MOHAMED F. EL-AMIN Department of Mathematics, Effat University, Jeddah, Saudi Arabia; Mathematics Department, Faculty of Science, Aswan University, Aswan, Egypt

Elsevier Radarweg 29, PO Box 211, 1000 AE Amsterdam, Netherlands The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, United Kingdom 50 Hampshire Street, 5th Floor, Cambridge, MA 02139, United States Copyright Ó 2023 Elsevier Inc. All rights reserved. MATLABÒ is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks does not warrant the accuracy of the text or exercises in this book. This book’s use or discussion of MATLABÒ software or related products does not constitute endorsement or sponsorship by The MathWorks of a particular pedagogical approach or particular use of the MATLABÒ software. No part of this publication may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or any information storage and retrieval system, without permission in writing from the publisher. Details on how to seek permission, further information about the Publisher’s permissions policies and our arrangements with organizations such as the Copyright Clearance Center and the Copyright Licensing Agency, can be found at our website: www.elsevier.com/permissions. This book and the individual contributions contained in it are protected under copyright by the Publisher (other than as may be noted herein).

Notices

Knowledge and best practice in this field are constantly changing. As new research and experience broaden our understanding, changes in research methods, professional practices, or medical treatment may become necessary. Practitioners and researchers must always rely on their own experience and knowledge in evaluating and using any information, methods, compounds, or experiments described herein. In using such information or methods they should be mindful of their own safety and the safety of others, including parties for whom they have a professional responsibility. To the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume any liability for any injury and/or damage to persons or property as a matter of products liability, negligence or otherwise, or from any use or operation of any methods, products, instructions, or ideas contained in the material herein. ISBN: 978-0-323-90511-4

For information on all Elsevier publications visit our website at https://www.elsevier.com/books-and-journals

Publisher: Matthew Deans Acquisitions Editor: Ana Claudia A. Garcia Editorial Project Manager: Tessa Kathryn Production Project Manager: Fizza Fathima Cover Designer: Greg Harris Typeset by TNQ Technologies

Preface Nanotechnology has been considered a great scientific and industrial revolution in the last 2 decades, which has undisputedly touched all branches of science and all applications. These tiny particles hold many unique properties that have made them impressive in solving many scientific problems. It is well known that nanoparticles have many applications in daily life and significantly develop their design, experiments, and creation. However, the advancement in nanoparticle transport’s mathematical and numerical modeling is rather slow compared to other aspects. So, we present this book to contribute to solving this issue and to push the research of numerical modeling of nanoparticle transport in porous media. This book focuses on mathematical modeling and numerical aspects of nanoparticle transport in porous media associated with single- or two-phase flows. It discusses representative models, dimensional analysis, numerical algorithms and solutions, and convergence analysis of nanoparticle transport in porous media. Different types of porous media have been considered, such as heterogeneous fractured and anisotropic porous media. Moreover, different types of nanoparticles are studied, such as magnetic nanoparticles and ferrofluids. Machine learning is another scientific revolution in this era that we should not ignore in this book. So, we explored the usage of machine learning techniques in the prediction of nanoparticle transport in porous media. Although several books have been published on nanoparticles, none of them considered the mathematical modeling and numerical analysis of nanoparticle transport in porous media. This book blends into a complete reference on mathematical modeling and computational aspects of nanoparticle transport in porous media that has been collected to be in one manuscript. This book contains some key features for interested readers. It is written in an easy and self-contained way so that it does not require the reader to have a deep background in mathematics, physics, and engineering. The book includes several examples of MATLAB codes. It contains both mathematical and physical interpretations as required and the most updated results in the field.

xii

Preface

Introduction briefly covers nanotechnology, nanoparticle types, properties, applications, nanoparticle transport in porous media, and particularly in enhanced oil recovery. Also, to reduce the prerequisites of this book, we provided a basic elementary introduction to the used mathematics and numerical analysis throughout the book. Moreover, the codes of this book are written in MATLAB (and Python for Chapter 11), so readers may need to have a basic foundation in programming in both MATLAB and Python. Therefore, some basics in both MATLAB and Python are presented to help understand coding in this book. Chapter 1 presents basic concepts related to the mathematical modeling of nanoparticle transport in porous media that will be used throughout this book. The continuum theory of fluid flow will be also presented, followed by the flow in porous media. The rock and fluid physical properties are introduced. The mathematical modeling of single-phase and two-phase flow in porous media is discussed. It is well known that an analytical solution helps in the validation of numerical methods/solutions as well as the comprehension of mechanisms and physical effects. Analytical solutions of the problem of flow in porous media, magnetic flow in porous media, nanoparticles transport in porous media, and magnetic nanoparticles transport in porous media are addressed in Chapter 2. Also, dimensional analysis is vital in handling problems regardless of their actual dimensions, which is helpful in large-scale problems such as hydrocarbon reservoirs. A simplified one-dimensional model of the nanoparticles transport in porous media and its generalized nondimensional form and its analytical and numerical solutions have been provided. Computational methods are becoming a third research approach parallel to experimental and theoretical approaches. With the aid of the fast development of computers, numerical simulation is turning into the most crucial process, especially in oil engineering, groundwater, and transport phenomena. Generally, when adopting a numerical approach to simulate a particular problem, the first step is to establish a mathematical model according to the physical laws of the problem. The second procedure is discretizing the mathematical model, followed by the third step, which is to code and run it on the computer to get results. Finally, we try to interpret the simulation results. Chapter 3 introduces numerical methods that will be used for the spatial discretization of nanoparticle transport in porous media. We present mesh generation using MATLAB, the cell-centered finite difference method, to treat different boundary conditions. Then,

Preface

the vectored implementation in MATLAB of the cell-centered finite difference method was presented. Also, the harmonic mean of permeability and transmissibility matrices has been formulated. Moreover, the finite element method is discussed, highlighting its discretization, weak formulation, and theoretical foundation with the required spaces. It is essential for solving elliptic PDEs that govern flow and transport in porous media. Chapter 4 is concerned with the numerical methods frequently used for temporal discretization in the problems of nanoparticle transport in porous media. The forward and backward Euler difference schemes are presented in Chapter 4. Chapter 4 also contains the multiscale time splitting and relaxation factor used with the CFL stability condition. In addition to the IMP-IMC scheme, the IMPES-IMC scheme and stability analysis for the IMPES scheme have been provided. Chapter 5 focuses on the iterative methods and investigates their theoretical and numerical convergence. Moreover, a theoretical foundation for the convergence of the iterative approach has been proved using the mathematical induction method. The nonlinear iterative numerical schemes such as iterative Implicit Pressure Concentration (IMPC) and the iterative Implicit Pressure Explicit SaturationeImplicit Concentration (IMPES-IMC) have been introduced. The iterative IMP-IMC scheme is devoted to solving the problem of nanoparticle transport with singlephase flow in porous media, while the iterative IMPES-IMC treats the two-phase flow case. As the natural porous media are usually fractured, Chapter 6 aims to cover the modeling of nanoparticle transport in fractured porous media. It discusses the most common fundamental approaches and presents their physical, mathematical, and numerical aspects of nanoparticle transport in fractured porous media. Several approaches are introduced including the dualcontinuum, boundary conditions, shape-factor, and discrete fracture model (DFM). After that, we focus on the DFM for nanoparticle transport in single-phase flow and two-phase flow. A numerical multiscale time-splitting scheme has been developed to solve the DFM model. Finally, the hybrid embedded fracture model has been discussed. Moreover, anisotropy of porous media is an essential feature in subsurface formations. In Chapter 7, nanoparticle transport in anisotropic porous media is discussed. The chapter introduces the mathematical modeling of the flow in anisotropic porous media. Moreover, the model of nanoparticle transport in anisotropic porous media has been developed. Then, the numerical techniques that are appropriate

xiii

xiv

Preface

for anisotropic porous media have been discussed, particularly the multipoint flux approximation (MPFA), followed by a numerical example. Magnetic nanoparticles can be controlled by applying an external magnetic field to optimize the utilization of nanotechnology. This might pave the way for various uses, such as directing flow in reservoir monitoring and increasing injection fluid advancement during pressure maintenance to improve oil recovery. Chapter 8 presents the mathematical modeling of magnetic nanoparticle transport with single-phase flow in porous media under the effect of an external magnetic field. Numerical solutions to the problem of magnetic nanoparticle transport with two-phase have been obtained. Analytical solutions are also gotten for the single-phase case. Nanoferrofluids type is one of the prospective applications of nanoparticles that work with the magnetic field. Chapter 9 discusses nanoferrofluids transport in porous media by highlighting their properties. The ferrofluids transport in single-phase flow has been introduced with analytical solutions for some cases. The model of nonisothermal ferrofluids transport in porous media has been established with the appropriate numerical algorithm for the two-phase flow. Chapter 10 presents some special aspects of nanoparticle interactions, e.g., nanoparticle cotransport and/or interaction with nonaqueous phase liquids (NAPLs), nanoparticle-polymers transport in porous media, and nanoparticles associated with heat transfer. The concept of stability of nanoparticle suspensions is presented. It also introduces the polymer transport under a magnetic field in porous media with possible analytical solutions, in addition to the nanoparticle interactions with heat transfer. Machine learning is a branch of artificial intelligence (AI) concerned with creating and developing algorithms that enable computers to learn behaviors or patterns from empirical data. The aim of Chapter 11 is to introduce the implementation of machine learning algorithms to predict nanoparticle transport in the oil reservoir. We used Jupyter Notebook for the implementation, which utilizes the Python programming language. Chapter 11 explores machine learning techniques, starting with fundamentals, followed by basic metrics to evaluate the performance. After that, we discuss datasets and their analysis and explain how to implement machine learning techniques in Python. Several applications of using nanoparticle transport in porous media are listed briefly as examples in chapter 12. Nanoparticle applications in the field of oil/gas exploration/production have

Preface

recently emerged as a promising area of study. Also, the use of nanoparticles with heat transfer has massive applications. Carbon dioxide capture by nanoporous materials is another type of its application. Moreover, carbon dioxideenanoparticles sequestration in geological storage is a potential technique relying on the enhancement of the nanoparticle addition. This book is expected to have a wide range of audiences in both academic and industrial sectors. The audience of this book of interest might include computational and applied scientists; hydrologists; mathematicians; and petroleum, mechanical, chemical, and environmental engineers, in addition to academic specialties in material sciences, porous materials, and numerical modeling, especially for students or engineers who are working in fluidic fields. Researchers, graduate students, scientists, and engineers who are working in the fields of porous media, reservoir simulation, numerical analysis, applied mathematics, contaminant hydrology, and enhanced oil recovery (EOR) can be examples of the target audience of this book. This book may be used to be taught to graduate MSc and Ph.D. students who work in reservoir modeling and simulation, EOR, applied numerical analysis, and applied mathematics. This book requires students to have a background in calculus and basic numerical analysis as prerequisites when using it for course teaching. Some basic knowledge of MATLAB and fundamentals of reservoir engineering may be required too. Also, the book material can be used in courses at summer schools and the training of engineers. Mohamed F. El-Amin

xv

Introduction 1. Nanotechnology In 1959, the concept of nanotechnology was first introduced by Richard Feynman [1] and defined as the application of science, engineering, and technology at the nanoscale. A nanoparticle is a tiny, invisible particle with a diameter of 1e100 nanometers (nm), where a nanometer equals 109 m (nanoscale). According to the European Commission’s definition (2011/696/ EU), at least 50% of the particles in a number size distribution must have a particle size of 100 nm or less. Nanoparticles (NPs) have radically different physical and chemical properties than their bigger material counterparts. One of the most important characteristics of NPs is that gravity becomes insignificant, but surface tension and van der Waals attraction become essential. Nanotechnology commands a far-reaching impact on various industries and has shown great promise in many significant scientific and engineering advances. A nanofluid is a colloidal suspension commonly made by dispersing nanoparticles in a working fluid such as water or oil that can sustain extreme conditions. The design of nanoparticles increases surface area, which potentially affects molecular reactions. Fig. 1 shows a polysilicon nanoparticles image observed under the transmission electron microscope [2]. Nanoparticles are divided into many categories based on their size, shape, and physical and chemical properties. Carbon-based, ceramic, polymeric, metal, and semiconductor nanoparticles are all classified as nanoparticles [3]. Two types of carbon-based nanoparticles are carbon nanotubes, which are graphene sheets wrapped into a tube and fullerenes. Furthermore, carbon nanotubes are divided into two kinds, namely, single-walled and multiwalled carbon nanotubes [4]. Ceramic nanoparticles, composed of oxides, carbonates, carbides, and phosphates, are chemically and thermally inert solids with high heat resistance. By adjusting the nanoparticles’ features, such as size, surface area, porosity, and surface-to-volume ratio, ceramic nanoparticles can be used in photocatalysis, imaging, and drug delivery. Polymeric nanoparticles are organic-based nanoparticles with nanocapsules or nanosphere-like shapes. The morphology of a nanosphere particle is matrix-like, whereas the morphology

xx

Introduction

Figure 1 Polysilicon nanoparticles image observed under TEM [2].

of a nanocapsule particle is a core shell. Drug delivery and diagnostics both benefit from polymeric nanoparticles. Metal nanoparticles are made up of metal precursors and can be produced chemically, electrochemically, or photochemically. Metal nanoparticles can be used in various applications, including imaging, biomolecules, and other environmental and bioanalytical research [3]. Semiconductor nanoparticles, such as gallium nitride (GaN), zinc oxide (ZnO), and zinc sulfide (ZnS), have similar features to both metal and nonmetal nanoparticles. Photocatalysis, electronics, photo-optics, and water splitting are only a few of their applications. Also, it may be useful to the EOR nanoparticles’ mechanism to classify polysilicon nanoparticles into two categories based on their surface wettability [2], lipophobic and hydrophilic polysilicon nanoparticles and hydrophobic and lipophilic polysilicon nanoparticles. In the secondary oil recovery phase, the fluid injection aims to maintain the pressure inside the reservoir to continue the oil displacement. In the secondary oil recovery stage, the fluid injection aims to maintain the pressure inside the reservoir to continue the oil displacement. On the other hand, in the tertiary phase, or EOR, the injected fluid interacts with the reservoir components, including rocks and hydrocarbons. Despite the EOR mechanisms being the most crucial stage in the oil recovery process, they face several issues, such as limited sweep efficiency and the risk of formation damage. In contemporary nanoparticle research, the majority of the difficulties associated with traditional EOR techniques are seen as possible solutions [5]. EOR

Introduction

nanoparticles are used in the form of nanofluids, nanoemulsions, and nanocatalysts. This might assist with wettability alterations, injection fluid viscosity, asphaltene precipitation prevention, and interfacial tension reduction. Also, EOR nanoparticles can help the traditional EOR methods, such as thermal, chemical, and gas techniques. Nanoparticles can be considered a potential EOR mechanism to improve hydrocarbon recovery by changing the characteristics of rocks and fluids. Rockeoil interaction and wettability are rock properties that are modified with nanoparticle addition. Nanoparticles can change the rock’s wettability from oil-wet to water-wet. Oil tends to adhere to the walls of porous media in oil-wet rocks, and waterflooding is ineffective in these rocks because oil droplets cannot flow quickly between the matrix pores. On the other hand, the injection of nanoparticles can shift the wettability of rocks from water-wet to water-wet. Water tends to imbibe the rock surface in water-wet rock, and oil pushes toward the production well due to water flooding; hence, oil recovery improves. Moreover, the nanoparticle adhering affects fluid viscosity, interfacial tension reduction, and emulsion stabilization, which increases the recovery rate compared to conventional chemical surfactant-polymer flooding [3]. On the other hand, it is known that the high temperature inside the reservoir reduces the efficiency of surfactant polymer flooding. On the other hand, the nanoparticle suspension has stable behavior at higher temperatures, making it a viable solution for high-temperature EOR approaches [4]. The mathematical modeling and numerical analysis of nanoparticle transport with single- or two-phase flows have been given more attention in recent years [6e18], which is also the theme of this book. Additionally, many kinds of nanoparticles, including ferrofluids and magnetic nanoparticles, are researched (see, for example, [19e22]). Also, we do not have to skim through the current scientific revolution in machine learning in this book. Therefore, we investigated how machine learning approaches could be used to forecast the transport of nanoparticles via porous media [23e32]. Heat transfer is greatly enhanced by the inclusion of a small volume portion of nanoparticles. Dispersed nanoparticles improve the fluid’s effective thermal conductivity, which rises with the nanoparticle volume fraction in heat transfer applications. On the other hand, nanoparticles induce Brownian movements that promote particle-base liquid interaction and collision. Moreover, nanofluid can be used to boost solar energy absorption. There are two fundamental methods to prepare

xxi

xxii

Introduction

nanofluids: one-step and two-step physical in addition to the chemical process which is considered a new approach for creating nanofluids. In the one-step approach, the physical vapor deposition process creates a stable nanofluid. This method produces direct evaporation and condensation of nanoparticles within the base fluid to prepare a pure and homogenous nanofluid. The main disadvantages of this approach include the high cost and the presence of residual reactants in the nanofluid. The two-step technique is the most cost-effective way to prepare nanofluid on a wide scale. In this method, the nanoparticles can be created using various techniques and then distributed into the base liquid to make the nanofluid. However, nanoparticle aggregation is the principal downside of the two-step method. In general, it is necessary to maintain a good dispersion of nanoparticles in the base fluid (called nanofluid stability). Adding surfactants or dispersants is usually utilized to increase the stability of nanofluids. In addition, the surface of the particles may be modified by applying strong forces to the dispersed nanoparticles, which may improve the stability of nanofluids. Also, a magnetic stirrer using a rotating magnetic field can increase the nanofluid’s homogeneity by reducing sediment. In nanofluid preparation, the determination of nanoparticle concentration in the base fluid is essential. The volumetric concentration percentage can be calculated using the form, Wnp =r C ¼ W r þWnp r %, where is C the volume concentration, Wnp is np = np bf = bf the weight of nanoparticles, Wbf is the weight of the base fluid, and rnp is the density of nanofluid. All other thermophysical properties are directly related to the volume concentration as we will see in the forthcoming chapter including Chapter 1 and Chapter 10.

2. Units and dimensions Any physical situation can be described by certain well-known qualities like length, velocity, area, volume, and acceleration. The standard components we employ to quantify these properties are units. The first international standard for units was “Système International d’Unités (SI)” (also referred to as the metric system). Later, English units adopted the standard SI units as their definition, and they are being used today. Certain common abbreviations assign to units such as length [L], mass [M], time [T], and temperature ¼ [Q]. We can represent all the physical properties we are interested in with L, T, and M, besides Q if the system is nonisothermal. These notes will always use the LTM

Introduction

xxiii

combination. The following table lists the dimensions of some standard physical quantities:

Table 1 Dimensions of selected standard physical quantities. Quantity Length Mass Time Temperature Area Volume Velocity Acceleration Force Density Quantity of heat Specific heat Dynamic viscosity Kinematic viscosity Surface tension

Pressure (or stress)

Permeabilitya Diffusivity Thermal conductivity

Thermal diffusivity

SI Unit M Kg S K m2 m3 m/s ¼ ms1 m/s2 ¼ ms2 N¼ kg m/s2 ¼ kg ms2 kg/m3 ¼ kg m3 J¼Nm J/[kg K] ¼ J kg1 K1 N s/m2¼ kg/m s ¼ Pa s m2/s ¼ m2 s1 N/m¼ N sm2¼ kg/s2 ¼ kg m1s1 Pa¼ N/m2¼ kg/m/s2 ¼ Nm2¼ kg m1s2 2 m m2/s ¼ m2 s1 W/(mK)¼ W.m1K1 ¼ J/(mKs)¼ W.m1K1s1 2 m /s ¼ m2 s1

Dimension

meter kilogram second kelvin square meter cubic meter meter per second meter per second squared Newton

[L] [M] [T] [Q] [L2] [L3] [LT1] [LT2] [M LT2]

kilogram per cubic meter

[ML3]

joule joule per kilogram-kelvin

[M L2T2] [L2 Q1 T2]

Pascal-second

[M L1T1]

square meter per second

[M2T1]

Newton per meter

[MT2]

Pascal

[ML1T2]

square meter square meter per second

[L2] [L2T1]

Watts per meter-kelvin

[ML Q1 T3]

square meter per second

[L2T1]

a The permeability has a very common unit called darcy (D or d), which is typically is equivalent to 9.869,2331013 m2. Millidarcy (mD or md) is also usually used.

xxiv

Introduction

In addition to the above basics of units, we need specific units of concentration. In the following, we will introduce several standard units of concentration including molarity, molality, mass percentage, parts per thousand, parts per million, and parts per billion. Molarity is defined as the number of moles of solute divided by the number of liters of solutions [mol/L]. Molality is defined as the number of moles of solute per kilogram of solvent [mol/kg]. Also, the third type of concentration unit is percentage composition by mass (or mass percentage, % m/m), which is defined as the mass of solute divided by the mass of the entire sample multiplied by 100%. The last one is the most appropriate one to measure nanoparticle concentration in its suspension. In engineering applications, empirical data from experiments are frequently used; however, displaying these data in a readable format can be challenging. Even graphs can be difficult to understand. The dimensional analysis offers a method for selecting pertinent data and deciding how to present it. This method is beneficial in all engineering disciplines that rely on experimentation. Also, the mathematical governing equations of a given system can be transformed into a dimensionless form. The dimensional analysis can establish a relationship between different physical situations. We will discuss the dimensional analysis for nanoparticle transport in porous media in Chapter 2 of this book.

3. Some basics of mathematics 3.1 Notations and definitions Throughout this book, we use a number of Greek notations including 4 which pronounces “phi” and refers to porosity. r is pronounced “rho” and refers to density. m is pronounced “mu” and refers to dynamic viscosity. v is pronounced “nu” and refers to kinematic viscosity. a is pronounced “alpha” and refers to phase superscript. q is pronounced “theta” and refers to fluidsurface contact angle. V is pronounced “Nabla” and refers to gradient if it is used with scalar quantity such as pressure p, and temperature T, i.e., grad p ¼ Vp. While it is used with vector quantity,  it is called divergence such as div u ¼ V,u, here u [ ux ; uy ; uz is a vector with the three components ux ; uy ; and uz in the directions x; y ; and z, respectively. The operator   v v v ; ; V¼ ð1Þ vx vy vz

Introduction

v refers where ðx; y; zÞ is the Cartesian space vector. The symbol vx v is to the first partial derivative with respect to the coordinate x, vy v is the first partial derivative with respect to the coordinate y, and vz the first partial derivative with respect to the coordinate z. Therefore, the gradient can be written as   vp vp vp ; ; ð2Þ Vp ¼ vx vy vz

which is a vector quantity, while the divergence V,u ¼

vux vuy vuz þ þ vx vy vz

ð3Þ

results in a scalar quantity, due to the scalar (dot) product which is referred by the period (,) between the two vectors V and u. Now, let us introduce the Laplace operator as follows: D¼

v2 v2 v2 þ 2 þ 2 ¼ V,V ¼ V2 2 vx vy vz

ð4Þ

which is a scalar operator that can be applied to either vector or scalar fields. As we mentioned derivatives here, it is worthy to distinguish d between partial derivative vxv and ordinary derivative dx such that the latter one is used in one-dimensional cases. Also, we use the 2 d2 symbols vxv 2 for second partial derivative or dx 2 for second ordinary derivative and so on. To continue, s is the tortuosity and pronounced as “tau.” Also, the symbol j j refers to the absolute value of the inside quantity. Another symbol called norm k k is used to express the magnitude of vector and defined as qffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi ð5Þ kuk ¼ u2x þ u2y þ u2z The summation symbol S is called “sigma” and usually used to denote a sum of multiple terms. The expression Xn x ¼ x1 þ x2 þ x3 þ /: þ xn ð6Þ i¼1 i represents the sum of n terms. The symbol U is called “omega” and usually used to refer to the computational domain, while vU is called “delta omega” that is used to refer to the boundary of computational domain. The symbol G is pronounced “gamma” and used to refer to the subdomain. The whole boundary may be represented as a union of

xxv

xxvi

Introduction

different types of boundary such as Dirichlet and Neumann conditions, so vU ¼ GD WGN and GD XGN ¼ B, where GD is the Dirichlet boundary and GN is the Neumann boundary. The symbol W is used to express the union operation, while X is used to express the intersection operation. B (Phi) is the empty set.

3.2 Error function In this book, we provided some analytical solutions which somewhere include the Gauss error function or briefly called the error function and denoted by erf and defined by an integral special sigmoid function: Z z 2 2 erf z ¼ pffiffiffi e t dt ð7Þ p 0 It is also closely related to the complementary error function (erfc) which is defined as follows: erfc z ¼ 1  erf z

ð8Þ

3.3 Matrices A matrix is a rectangular array or table of entries, arranged in rows and columns. Matrices are commonly written in box brackets: 3 2 a11 a12 / a1n 7 6 7 6a 6 21 a22 / a2n 7   mn A¼6 ð9Þ 7 ¼ aij ˛R 6 « « 1 « 7 5 4 am1 am2 / amn

The specifics of symbolic matrix notation vary widely, with some prevailing trends. Matrices are usually symbolized using upper-case letters (such as A in the examples above), while the corresponding lower-case letters, with subscript indices, aij , represent the entries. R is often used to refer to the real number set. The matrix dimension (or size) is defined by the number of rows and columns, such that, a matrix with m rows and n columns is called an m  n matrix and reads m-by-nmatrix. A matrix with a single row is called a row-vector, while that with a single column is called a column-vector. Matrices that

Introduction

have same number of rows and columns are called a square matrix. The sum of two matrices A þ B of dimension m-by- n is calculated elementwise as ðA þ BÞi;j ¼ A i;j þ Bi;j , where 1  i  m and 1  j  n. The multiplication of matrix A with the scalar c, i.e., cA is given by multiplying each element of the matrix A by the scalar c, i.e., ðcAÞi;j ¼ c,A i;j . The transpose of the m-by- n matrix A is the n-by- m matrix A u tr (oruA formed by turning rows into columns and vice versa, i.e., A i;j ¼ A j;i . Matrices multiplication is valid only if the number of columns of the left matrix is the same as the number of rows of the right matrix. Thus, if there is an m  n matrix A and another n p matrix B, then the product AB is the m  p. Thus, for where 1  i  m and 1  j  p, n X ½ABi;j ¼ ai;1 b1;j þ ai;2 b2;j þ / þ ai;n bn;j ¼ ai;r br;j . ð10Þ r ¼1

Having three matrices, A, B and C, the following rules are valid: associativity ðABÞC ¼ AðBCÞ; left and right distributivity: ðA þBÞC ¼ AC þ BC and CðA þBÞ ¼ CA þ CB. However, the product AB is not mutual, i.e., ABsBA. When all elements of a matrix A below the main diagonal are zeros, A is called an upper triangular matrix. 2 3 u u u / u 1;1 1;2 1;3 1;n 6 7 6 u2;2 u2;3 / u2;n 7 6 7 6 7 6 1 1 « 7 U ¼6 ð11Þ 7 6 7 1 un1;n 7 6 4 5 un;n

Similarly, if all entries of A above the main diagonal are zero, A is called a lower triangular matrix. 2 3 [ 0 6 1;1 7 6[ 7 6 2;1 [ 2;2 7 6 7 6 7 L ¼ 6 [ 3;1 [ 3;2 1 ð12Þ 7 6 7 « « 1 1 6 7 4 5 [ n;1 [ n;2 . [ n;n1 [ n;n

xxvii

xxviii

Introduction

The diagonal matrix is a square matrix A with the entries, aij ¼ di dij ; such that dij is the Kronecker delta, di are nonzero elements, and i ¼ j ¼ 1; 2; .; m. The diagonal matrix is written as 3 2 d1 0 / 0 7 6 6 0 d / 0 7 2 7 6 ð13Þ Dm ¼ 6 7 6 « « 1 « 7 5 4 0 0 / dm It is also denoted diag ðd1 ; d2 ; .; dm Þ. If the main diagonal elements are equal to 1 in the diagonal matrix, it is called an identity matrix, i.e., 3 2 1 0 / 0 7 6 60 1 / 07 7 6 ð14Þ In ¼ 6 7 6« « 1 «7 5 4 0 0 / 1 Note that AI ¼ IA ¼ A. The system of linear equations, often known as multiple linear equations, can be written and operated on in a compact manner using matrices. Thus, the system of linear equations a1;1 x1 þ a1;2 x2 þ / þ a1;n xn ¼ b1 « am;1 x1 þ am;2 x2 þ / þ am;n xn ¼ bm

ð15Þ

is equivalent to the matrix equation, Ax ¼ b

ð16Þ

If n ¼ m, the solution of the above linear system can be written as x ¼ A 1 b

ð17Þ

where A 1 is the inverse matrix of A. If A is an invertible matrix, then, A1 ¼

1 ðadj ðAÞÞ. det ðAÞ

ð18Þ

Introduction

where adj ðAÞ is the adjoint and det ðAÞ is the determinant of the matrix A. It follows from the associativity of matrix multiplication that if A1 A ¼ AA1 ¼ I.

ð19Þ

3.4 Equations types There are three well-known types of equations that are of interest to be distinguished from each other, including algebraic equations (AEs), ordinary differential equations (ODEs), and partial differential equations (PDEs). They frequently appear and are used in the fields of computational mathematics/physics/ engineering/science/./etc. Equation usually refers to a mathematical expression of two sides separated by an equal sign. If all terms of the equation do not include any derivative, then the equation is called an AE. Whenever the equation contains any derivative, it is called a differential equation. If the dependent variables and derivatives are functions of one independent variable, then the equation is called an ODE. On the other hand, if the dependent variables and derivatives are functions of more than one independent variable, then the equation is called a PDE. The laws of physics, such as the conservation of energy, mass, and momentum, can all be expressed as PDEs.

4. Some basics of numerical analysis Unlike traditional mathematics, which uses symbolic manipulations to find exact or analytical solutions for algebraic and differential equations, numerical analysis studies numerical approximations that can solve vast categories of complicated problems. The analytical methods are too limited in solving complex problems compared to numerical or computational analysis. Numerical analysis has many applications in all fields of engineering and other disciplines. It increases computing power, enabling more complex numerical analysis and providing detailed and realistic mathematical models in science and engineering. Numerical analysis is developing as it benefits from the capability of modern computers, which is why it is called computational sciences. The differential equations are approximated by discretization numerical techniques employing the model equations that need to be solved. This discretization converts the differential equation into an AE to be solved and provides a proper approximated solution. There are several

xxix

xxx

Introduction

numerical methods available to solve differential equations such as the finite difference method (FDM), finite element method (FEM), finite volume method, etc.

4.1 Error estimation The error of a solution of any numerical method is defined as the difference between the approximation and the exact solution. Generally, there are two main types of errors, namely, round-off error, which is the loss of precision due to computer rounding of decimal quantities, and truncation error or discretization error, the difference between the exact solution and the exact one. Suppose that we have an exact value (variable or solution) x and its approximation x  . We define the absolute error as jx x  j, and jx  x  j , such that xs0 the relative error as jxj An algorithm may be either numerically stable or unstable. If the error of an algorithm does not grow to be much larger during the calculation, the algorithm is called stable, and the opposite is true.

4.2 Taylor series Taylor polynomials and series are used extensively in numerical analysis. Suppose that there exists a continuous function f and its derivatives until the order n þ 1, i.e., f ðnþ1Þ on the interval ½a; b, and x0 ˛½a; b is an initial approximation. For every x˛½a; b, there exists a number xðxÞ between x0 and x with f ðxÞ ¼ Pn ðxÞ þ Rn ðxÞ; such that f 00 ðx0 Þ ðx  x0 Þ2 þ / 2! n X f ðnÞ ðx0 Þ f ðkÞ ðx0 Þ ðx  x0 Þn ¼ ðx  x0 Þk þ n! k! k¼0

Pn ðxÞ ¼ f ðx0 Þ þ f 0 ðx0 Þðx  x0 Þ þ

where Rn ðxÞ ¼

k!

denotes

f ðnþ1Þ ðaÞ ðx ðnþ1Þ!

 x0 Þ

nþ1

the

factorial

of

k,

ð20Þ

and

, a ˛½x0 ; x. Here, Pn ðxÞ is called the

n-th Taylor polynomial for f about x0 , and Rn ðxÞ is called the remainder term (or truncation error) associated with Pn ðxÞ. In the case x0 ¼ 0, the Taylor polynomial\series are often called a Maclaurin polynomial\series. Taylor polynomial is effectively used in function linearization as f ðxÞ z LðxÞ ¼ f ðx0 Þ þ f 0 ðx0 Þðx  x0 Þ

ð21Þ

Introduction

4.3 NewtoneRaphson method The NewtoneRaphson (or Newton’s) method is one of the most powerful and well-known numerical methods for root-finding of AEs. Newton’s method is derived by assuming that since jx x0 j is small, the term involving ðx  x0 Þ2 is much smaller, so 0 z f ðx0 Þ þ ðx  x0 Þf 0 ðx0 Þ

ð22Þ

The unknown variable x becomes x z x0 

f ðx0 Þ hx1 f 0 ðx0 Þ

ð23Þ

Starting with a given initial value x0 one can generate a sequence fxn gN n¼0 , by using the equation xn ¼ xn1 

f ðxn1 Þ ; for n  1 f 0 ðxn1 Þ

ð24Þ

Another version of Newton’s method called the secant method had been developed mainly to avoid using the derivative in Newton’s method formula, by the definition f 0 ðxn1 Þ ¼

lim

x/xn1

f ðxÞf ðxn1 Þ xxn1

ð25Þ

If xn2 is close to xn1 , then f 0 ðxn1 Þ z

f ðxn2 Þ  f ðxn1 Þ f ðxn1 Þ  f ðxn2 Þ ¼ xn2  xn1 xn1  xn2

ð26Þ

Using this approximation for f 0 ðxn1 Þ in Newton’s formula gives xn ¼ xn1 

f ðxn1 Þðxn1  xn2 Þ f ðxn1 Þ  f ðxn2 Þ

ð27Þ

4.4 RungeeKutta method The RungeeKutta method is a very common and accurate technique for resolving highly nonlinear ODEs. Consider the following first-order initial-value problem:

xxxi

xxxii

Introduction

We will consider the first-order initial-value problem as follows: ( y 0 ¼ f ðx; yÞ; a  x  b ð28Þ yðaÞ ¼ y0 Let us divide the interval ½a; b into N subintervals as ½xn ; xnþ1 . Then integrate the differential equation y 0 ¼ f ðx; y Þ over ½xn ; xnþ1  and use the mean value theorem for integrals to get: Z xnþ1 f ðx; yðxÞÞdx ¼ hf ðx; yðxÞÞ ð29Þ yðxnþ1 Þ  yðxn Þ ¼ xn

where h ¼ xnþ1  xn ; x ˛ ½xn ; xnþ1 ; yðxnþ1 Þ ¼ yðxn Þ þ hf ðx; yðxÞÞ The approximate function f ðx; y ðxÞÞ can be obtained as follows: ynþ1 ¼ yn þ h

m X i¼1

f ðxi ; yðxi ÞÞ

ð30Þ

The RungeeKutta method has different versions such as second-order and fourth-order. The latter is the most common one which requires four sequential functions to be evaluated. The numerical solution of the initial value problem in Eq. (28) based on the fourth-order RungeeKutta method is

where

1 ynþ1 ¼ yn þ ðk1 þ k2 þ k3 þ k4 Þ 6

ð31Þ

  8 k1 ¼ hf xn ; yn > > >   > > > h k1 > > ; y k ¼ hf x þ þ > n n < 2 2 2   > h k2 > > > k3 ¼ hf xn þ ; yn þ > > 2 2 > > >   : k4 ¼ hf xn þ h; yn þ k3

ð32Þ

Introduction

4.5 Finite difference method One of the main numerical methods for solving differential equations and mainly the partial type is the FDM in which basically the derivative is approximated by a finite difference expression (it is also called rate of change) which in turn returns back to the fundamental derivative definition using the limit f 0 ðxÞ ¼ lim

h/0

f ðx þ hÞ  f ðxÞ h

ð33Þ

Such that the limit of the difference formula approaches the derivative as the increment h approaches zero. Therefore, the derivative can be expressed as an approximation of the rate of change as f 0 ðxÞz

f ðx þ hÞ  f ðxÞ h

ð34Þ

It is interesting to mention that the above equation was derived from Taylor series expansion. We can derive an approximation for the first derivative of the function f ðxÞ by first truncating the Taylor polynomial f ðx þ hÞ ¼ f ðxÞ þ f 0 ðxÞh þ R1 ðxÞ; Solving this equation for f 0 ðxÞ

Figure 2 Finite difference discretization.

ð35Þ

xxxiii

xxxiv

Introduction

f 0 ðxÞ ¼

f ðx þ hÞ  f ðxÞ RðxÞ  h h

ð36Þ

If the reminder (error) RðxÞ is sufficiently small, then we obtain the derivative finite difference approximation as in Eq. (36). In order to approximate the solution to a given problem using the FDM (or any other numerical method), the first step is to discretize (divide) the problem and its domain. This can be achieved by dividing the domain into a uniform or nonuniform grid (see Fig. 2), which produces a set of discrete numerical approximations to the derivative. To solve a number of differential equations numerically, one can substitute their derivatives with finite difference approximations on the discretized domain. This results in an algebraic system of equations that can be solved one at a time (explicit methods) or simultaneously (implicit methods). The finitedifference approach is produced when a set of concurrent nonlinear PDEs is solved explicitly. This eliminates the requirement to solve AEs in order to determine the future state of the system from the present state. The implicit FDM is different from the explicit method of getting the solution by solving an equation involving the current state of the system and the latter one. The FDM is said to be consistent when it well approximates the solution of the differential equation. Consistency is measured in terms of the difference between a differential equation and a difference equation. For example, the first and second derivatives can be approximated as vu ui  ui1 ¼ þ OðDxÞ vx Dx

ð37Þ

v2 u uiþ1  2ui þ ui1 ¼ þ OðDxÞ2 vx2 ðDxÞ2

ð38Þ

One may note that the second term of the right-hand side of the above equations represents the truncation error which must be small as the increment Dx is very small, roughly speaking. Moreover, when explicit time integration schemes are employed to solve certain PDEs, the CouranteFriedrichseLewy condition must be held. Accordingly, the time step must be less than a particular value in many explicit time-marching computers simulation.

Introduction

4.6 Finite element method The finite element method is a numerical method to solve different types of differential equations. In FEM, functions are transformed from an infinite-dimensional space into others in a finite-dimensional space. The latter is transformed into ordinary vectors in a vector space that can be solved numerically. The idea is to divide the domain into small elements (e.g., triangles) and find a polynomial approximation to the dependent variables (unknown functions) on each element. This means that after applying the finite element method to these functions, they are converted to ordinary vectors. The approach combines discrete approximations to obtain a global solution. Popular polynomials with triangles include linear and quadratic types. The mathematical process of FEM is to multiply the PDE with a suitable test function to create a residual or error in the form of a dot product that needs to be minimized. Then integrate the inner product and set it to zero, which is called weak form (or variational formulation). One of the standard variational formulations is the Galerkin method. In other words, it minimizes the error approximation by fitting test functions into the PDE. The method removes all spatial derivatives from the PDE, resulting in a local approximation of the PDE using a set of AEs for steady-state problems (or a set of ODEs for transient problems). There are several versions of the finite element methods such as the standard finite element method, control volume finite element method, discontinuous finite element method, mixed finite element method (MFEM), characteristic finite element method, and adaptive finite element method. In this book, we mainly focused on the MFEM and control volume finite element method as they suit more the elliptic PDEs. But before this, we have to start with the standard finite element method to understand the theory behind the FEM and how to implement it.

4.6.1 Standard finite element method Let us first explore a one-dimension simple example using the Galerkin method. It is based on representing the solution as a linear combination of basis functions. Let us start with a simple example. Consider the following one-dimensional Poisson differential equation (the pressure equation represents the simple flow in porous media) which is defined on the one-dimensional domain U ¼ ð0; 1Þ ˛ R: p00 ðxÞ ¼ f ðxÞ; on U

ð39Þ

xxxv

xxxvi

Introduction

where f is a given function and p is the unknown dependent variable. Eq. (39) is associated with homogeneous boundary conditions on the domain boundary vU: pð0Þ ¼ pð1Þ ¼ 0

ð40Þ

Now, let us consider the functional space:

 S0 ðUÞ: ¼ fp: p is sufficiently smooth; pjvU ¼ 0

ð41Þ

The statement "sufficiently smooth" means that   p ˛ H 1 ðUÞ ¼ p ˛L2 ðUÞ : p 0 ˛ L2 ðUÞ is sufficient for our purposes. If we multiply both sides of Eq. (37) by a test function f ˛S0 ðUÞ, we obtain: fp00 ¼ ff and integrate over U to have Z 1 Z  fp00 dx ¼ 0

0

ð42Þ 1

ð43Þ

ffdx

Then use integration by parts to reduce the derivative order of the left-hand side and apply the boundary conditions: Z 1 Z 1 Z 1 1  fp00 dx ¼  ½fp0 0 þ f0 p0 dx ¼ f0 p0 dx ð44Þ 0

0

0

Thus, the problem can be formulated as: find p ˛ S0 ðUÞ, such that Z 1 Z 1 0 0 f p dx ¼ ffdx; for all f ˛ S0 ðUÞ ð45Þ 0

0

which is the weak form. We discretize the solution domain U into the intervals ½xk1 ; xk , such that xk are the grid nodes, x0 ¼ 0, xn ¼ 1, and x0 < x1 < . < xn . Therefore, one can discretize the domain equally, i.e., xk ¼ kDx, where Dx ¼ n1 , and each interval ek is called an element. The elements could be not all equal, and in this case, the discretization is called unstructured or nonuniform grids. In order to approximate the solution in a piecewise linear form in terms of the basis functions, i.e.,

Introduction

Figure 3 Finite element basis function.

eðxÞ ¼ p

n X j¼0

pj fj ðxÞ

ð46Þ

  such that fi is linear per element and fi xj ¼ dij , where dij is the Kronecker delta defined above (Fig. 3). Note that fj ð0Þ ¼ fj ð1Þ, for all j ˛f1; .; n  1g. Similar to the expression of the unknown function in Eq. (46), the arbitrary function f can be written as a linear combination of the basis functions as follows: f¼

n X j¼0

bj f j

ð47Þ

where bj are constants. Substituting the two approximations (46) and (47) into Eq. (44) to get: 0 1 ! Z 1 X Z 1 n n n X X d @ d bj fj A pi fi ðxÞ dx ¼ f bj fj dx ð48Þ dx i ¼ 0 0 dx 0 j¼0 j¼0 We can choose bj as bj ¼

(

1 if i ¼ j 0 if isj

Therefore, Z 1 Z 1 n X dfi dfj dx ¼ pi f fj dx; for j ¼ 0; 1; .; n. 0 dx dx 0 i¼0

ð49Þ

ð50Þ

xxxvii

xxxviii

Introduction

The above Eq. (50) can be written in an algebraic matrixvector form as Mp ¼ f ð51Þ It can also be written in an element-wise form as Z 1 n Z X dfi dfj dfi dfj dx ¼ dx Mij ¼ dx dx 0 dx dx k ¼ 1 ek

ð52Þ

Most of the integrals in this matrix are zeros except for four integrals per element. These four integrals are stored in the element’s matrix as: Z 3 2Z dfk1 dfk1 dfk1 dfk dx dx 7 6 e dx dx dx ek 7 6 k dx M ek ¼ 6 Z ð53Þ 7 Z 5 4 dfk dfk1 dfk dfk dx dx dx ek dx ek dx dx Referring to Fig. 4, the derivative of the basis function is always either 1=Dx or 1=Dx, Dx ¼ xk  xk1 , assuming a uniform grid. Therefore, " # 1 1 1 ek M ¼ ; ck ð54Þ Dx 1 1 Note that the symbol c refers to (for all). The element vector becomes Z 2 3 f fk1 dx 6 e 7 f ek ¼ 4 Zk ð55Þ 5 f fk dx ek

The calculation of the above integrals in the vector f depends on the given function f . It might have no analytical solution. Alternatively, we use a numerical integration method. If we use the trapezium rule along with the basis functions in Fig. 3, we obtain " # f ðxk1 Þ 1 ek f ¼ Dx ; ck ð56Þ 2 f ðxk Þ

Introduction

Figure 4 MATLAB traditional interface with a code of some simple arithmetic operations.

The above procedure will be repeated for each element. After that, we can calculate the whole matrix and vector as M 0 ¼ 0nn ; f 0 ¼ 0;

M k ¼ M k1 þ M ek f k ¼ f k1 þ f ek

ð57Þ

Now, let us impose the boundary conditions in Eq. (40) that can be expressed as p0 ¼ pn ¼ 0

ð58Þ

This means that the first and the last term of Eq. (46) are both zero. Therefore, the sum will be from 1 to n  1, which consequently eliminates the first and last row and column of the matrix M and the first and last element of the vector f. In the case of nonhomogeneous boundary conditions such as pð0Þ ¼ a; pð1Þ ¼ 0

ð59Þ

xxxix

xl

Introduction

Thus, p0 ¼ a. We deal with it differently as n X

eðxÞ ¼ p

j¼1

pj fj ðxÞ þ af0 ðxÞ

ð60Þ

This implies that Eq. (50) be written as Z 1 Z 1 Z 1 n X dfi dfj df0 dfj dx ¼ dx; for pi f fj dx  a 0 dx dx 0 0 dx dx i¼1

ð61Þ

j ¼ 1; 2; .; n. The other possible type of boundary condition is the Neumann boundary condition, in which the derivative is provided on the boundary such as p 0 ð0Þ ¼ b. In the case of homogeneous Neumann boundary conditions, Eq. (50) stays exactly the same. However, in the case of nonhomogeneous Neumann boundary conditions, we add a term to one entry of the vector f. In order to calculate the final solution, the obtained algebraic system is solved to find p.

4.6.2 Mixed finite element method The MFEM can calculate multiple physical quantities simultaneously, which usually implies higher accuracy of the results. Mixed FEM is working efficiently for some fluid flow problems, particularly, flow in porous media. Consider the problem in the two variables u and p as: ( u0 ¼ f ðxÞ; ð62Þ p0 ¼ u; Defined on the domain U ¼ ð0; 1Þ. Multiply each of the equations by a different test function, namely f and j, respectively, and integrate over U: Z 

0

1

u0 fdx ¼

Z 0

Z

1

ffdx

0

1

p0 jdx ¼

Z 0

1

judx

ð63Þ

Introduction

Then integration by parts to get: Z 1 Z 1 Z 1 0 0  u fdx ¼ ½uf0 þ uf dx ¼ 0

0

1

uf0 dx

0

ð64Þ

and Z

1 0

0

p jdx ¼

½pj10

Z 

1 0

0

Z

pj dx ¼ 

1

0

pj0 dx

ð65Þ

We can write approximations of u and p and set f and j to one of their respective basis functions: Xn e¼ u j ; j ¼ jj; u j¼0 j j e¼ p

Xn

pj fj ; f ¼ fj .

j¼0

Which implies that 8 Z 1 Z 1 n X djj > >  f u dx ¼ fi fdx; > j > > dx i < j¼0 0 0 Z n > X > > > uj > : j¼0

1 0

jj ji dx þ

n X j¼0

Z pj

1

0

for all i; ð66Þ

dj fj i dx ¼ 0; dx

for all i

The matrix-vector equation takes the form #" # " # " u f A 0 ¼ u p 0 B A

ð67Þ

where Z Aij ¼

1 0

fi

djj dx; Bij ¼ dx

Z 0

1

Z ji jj dx and f i ¼

0

1

fi fdx.

ð68Þ

This is a short introduction to the mathematics and numerical analysis that are used in this book. In Chapters 3 and 4, there is a full explanation and coding for the numerical techniques.

xli

xlii

Introduction

5. Short guide to MATLAB MATLAB was invented by the mathematician Cleve Moler. The idea for MATLAB was based on linear algebra programming (as an interactive matrix calculator) by Fortran programming language in 1971. MATLAB was named as an abbreviation of MATrix LABoratory and released to the public for the first time in February 1979, containing 71 built-in functions. After that, MATLAB was written in the C language to act as a programming language with toolbox features and became commercial software in 1984. MATLAB now is owned by MathWorks. It is classified now as one of the most fantastic numeric computing environments and high-level programming languages. MATLAB is relatively easy to learn and combines calculation and graphic plotting. Recently, MATLAB witnessed significant changes, including several technical and user interface improvements such as the MATLAB Live Editor notebook and other features. The MATLAB interface involves using the Command Window or executing text files (called m-files) containing MATLAB code. We prefer using the text m-files as they have the complete code instead of the command window, i.e., it contains a series of MATLAB statements. The m-files can be a script or function and has a filename extension (file name.m). To create an m-file using the MATLAB editor: File / New / m-file. Then write the statements in the file in the desired order, and save the file with the “m” extension. Recently, MATLAB released another editor version called “MATLAB Live Editor” and has (.mlx) as an extension. But both types of files with the two extensions, “m” or “mlx,” are working well.

5.1 Arithmetic and array operators The arithmetic and array operators used by MATLAB are listed in Table 1. However, the operators used with arrays usually require a period before the sign. It is also called as element-wise operations. Unlike other programming languages, MATLAB variables can be assigned without declaring their type, except if they are to be treated as symbolic objects. Variables are defined using the equal sign (¼) as an assignment operator. For example, let us create a new file called “Example_1.m,” as shown in Fig. 4. The figure contains the MATLAB traditional interface with a code of some simple arithmetic operations. The code starts with a declaration in a form of a comment. The comment sign in MATLAB is “%,” which means that the statement in this line is not executive. We may also notice that the lines of the script are

Introduction

autonumbering. In lines 4e5, the three variables x, y, and z are defined. Each line is ended with a semicolon “; ”. The other three dependent variables u, v, and w are defined in lines 8, 10, and 12, respectively. It may be noticed that these statements do not contain the semicolon “; ”, which allows us to see the results under the cursor after ruing the code. When we do that the equal sign is highlighted in yellow. If we close any statement with “; ”, the results would not appear under the cursor. Any statement can be written after the cursor and once the “Enter” button is hit it will be executed. This is a simple way of learning but practically writing all statements consequently in one script is the more efficient way.

5.2 Multiple statements in a single line In MATLAB, it is fine to enter multiple statements on a single line, separate with a semicolon “; ”. For example, put three statements: x [ 100; y [ 1; z [ x  yLy;

5.3 Long line dividing Enter three dots “...” at the end of the line to indicate that a statement continues on the following line if it does not fit on the current line. Then proceed to type the statement on the following line, and so forth.

5.4 Priority of arithmetic operations The basic arithmetic operations in MATLAB are as follows: addition: “þ”, subtraction: dimensions of some standard physical quantities “”, multiplication: “*”, division: “/”, and powers: “^”. See other operators in Table 2. The operations are performed in the following order: 1. Expressions in brackets: ( ). 2. Powers:^. 3. Multiplication and division: *,/. 4. Addition and subtraction: þ, . For instance, the evaluation of division and multiplication with the same priority goes from left to right. In everyday written mathematics, we occasionally omit brackets and assume that readers would know where they go. Computers, on the other hand, strictly abide by the guidelines for assessing expressions. If in doubt, it will not harm to use a few more parentheses.

xliii

xliv

Introduction

Table 2 Arithmetic and array operators. Character

Description

þ  * / ^ .* ./ .^ .\ .’

Addition Subtraction Scalar and array multiplication Division Power or exponentiation Array multiplication Array (right) division Array power Array (left) division Array (nonconjugate) transpose

Unlike other programming languages, MATLAB is designed to work mainly on complete matrices and arrays. Thus, all MATLAB variables are naturally multidimensional arrays. For example, to create a row vector of four elements, separate the elements with either a comma “,” or a space: A ¼ [0 1 2 3]. However, separate the rows with semicolons to create a 33matrix: A ¼ [0 1 2; 3 4 5; 6 7 8], to create the matrix: 2 3 0 1 2 6 7 7 A¼6 43 4 55 6 7 8

Some special matrices can be created using a MATLAB function, such as ones, zeros, or rand. For example, the function zeros (5,1) creates a 51 column vector of zeros, while zeros(1,5) creates a 15 row vector of zeros. The matrix dimensions are provided using the command ‘size’. Thus, the statement size (A) returns: ans ¼ 3 3 A square identity matrix can be created using MAtLAB function eye(n,n), where n is its size. For example, I¼eye(3,3) gives: 2 3 1 0 0 6 7 7 I¼6 40 1 05 0 0 1

Introduction

5.5 Linearly spaced vector To create a linearly spaced vector, we use the MATLAB command “linspace.” For instance, the statement x ¼ linspace(a,b) creates a row vector y with 100 points by default, including a and b, while x ¼ linspace(a,b,n) creates a row vector with n points including a and b.

5.6 Colon operator The colon operator (:) creates a vector using a command in the form; “start-point:step-size:end-point” with direct control over the number of points. For example, x¼0:1:5 gives the row vector x¼[0 1 2 3 4 5]. The colon operator can be used to pick out a certain row or column in a matrix. For example, the statement A(m:n,k:l) specifies rows m to n and column k to l. Subscript expressions refer to portions of a matrix. For example, R¼A(2,:) gives R ¼ [3 4 5]. 2 3 2 3 1 1 2 6 7 6 7 7 6 7 While C¼A(:,2) gives C ¼ 6 4 4 5, D¼A(:,2:3) gives D ¼ 4 4 5 5, and 7 7 8 so on. Moreover, the colon operator (:) is commonly used to create a vector form of a matrix A as V¼A(:) which gives 0 1 2 3 V¼ 4 5 6 7 8

5.7 Matrix multiplication For standard matrix multiplication, the “*” operator can be used with the restriction of using mathematical regular rules that

xlv

xlvi

Introduction

computes the inner products between rows and columns. For example, a matrix B¼[3 1; 0 2; 4 4] can be multiplied with the matrix A from right as E¼A*B to give: 0 8 10 1 B C B E ¼ B 29 23 C A @ 50 52

The values in a matrix can be processed by a single arithmetic operator or function, such as: 2 3 1 2 3 6 7 7 Aþ1 ¼ 6 44 5 65 7 8 9

5.8 Matrix transpose In order to find the matrix transpose, put a single quote (’) around a matrix to transpose it: 2 3 0 3 6 6 7 7 A0 ¼ 6 41 4 75 2 5 8

5.9 Matrix inverse In order to calculate the matrix inverse A1 , MATLAB provides a function called “inv” which can be used as D¼ invðAÞ; it gives the following answer with the warning message “Warning: Matrix is singular to working precision.” 2 3 Inf Inf Inf 6 7 7 D¼6 4 Inf Inf Inf 5 Inf Inf Inf

Now, if we tried another matrix C,

Introduction

2

3 0 1 2 6 7 7 C ¼6 43 0 55 6 7 8 The inverse in MATLAB D ¼ invðCÞ, will be: 2 0:7292 0:1250 0:1042 6 6 D ¼ 4 0:1250 0:2500 0:1250 0:4375

0:1250

0:0625

3 7 7 5

In order to confirm that a matrix times its inverse C  invðCÞ, returns the identity matrix: 2 3 1:0000 0 0 6 7 D¼6 1:0000 0:0000 7 4 0 5 0 0:0000 1:0000 Which is not a matrix of integer values. Arithmetic operations are sensitive to slight differences between the real value and its floating-point representation, which is how MATLAB saves numbers.

5.10 Element-wise operations To perform element-wise multiplication rather than matrix multiplication, use the “.*” operator, D¼ C.*C: 2 3 0 1 4 6 7 D¼6 0 25 7 4 9 5 36 49 64 Similarly, we can handle the other matrix operators in an element-wise sense as shown in Table 1.

5.11 Concatenation One can concatenate arrays together to create bigger ones. Horizontal concatenation is the process of joining arrays that are adjacent to one another using commas. There must be an equal

xlvii

xlviii

Introduction

number of rows in each array. Similarly, you can concatenate vertically using semicolons when the arrays have the same number of columns. The concatenation operator is represented by the pair of square brackets [ ]. For example, F ¼ [C,C] gives: 0 1 2 F¼ 3 0 5

0 1 2 3 0 5

6 7 8

6 7 8

which is of a 36 dimension. Also, we can do another concatenation F ¼ [C; C] to give: 0 1 2 F¼

3 0 5 6 7 8 0 1 2 3 0 5 6 7 8

which is of a 63 dimension.

5.12 Relational and logical operators: The relational and logical operators are presented below in Table 3; dimensions of some standard physical quantities. The logic operators in MATLAB include less than “”; greater than or equal “”; equal “¼¼;” and not equal “w¼.” Moreover, MATLAB offers two types

Table 3 Relational and logical operators. Character

Description

< £ > ‡ [[ w¼ & j && jj

Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to Logical or element-wise AND Logical or element-wise OR Short-circuit AND Short-circuit OR

Introduction

of logical operators, namely, element-wise and short-circuit. Element-wise logical operators operate element-by-element on logical arrays. The symbol & refers to “AND”; “j” refers to “OR”; and “w” refers to “NOT”. While short-circuit logical operators allow short-circuiting on logical operations. The symbol “&&” refers to “sort-circuit AND”; and “jj” refers to “short-circuit OR”. “clc” and “clear” functions: There are two important commands that are usually used to start a MATALB code. One is the “clc” used to clear the “Command Window”. Another is “clear (all)” used to remove all variables from the workspace and computer memory. “meshgrid” function: One of the useful MATLAB functions is the “meshgrid” which is usually used to prepare data for visualization. The “meshgrid” function could be 2D or 3D grids. For example, the statement [X,Y] ¼ meshgrid(x,y) returns 2D grid coordinates where X is a matrix with each row is typically x. Also, the matrix Y consists of a repeated column y. Thus, the grid represented by the coordinates X and Y has length(y) rows and length(x) columns. For example, x ¼ 1:4; y ¼ 1:7; [X,Y] ¼ meshgrid(x,y) returns 1 2 3 4 1 2 3 4 1 2 3 4 X¼ 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 1 1

1

2 2 2 3 3 3

2 3

Y¼ 4 4 4

4

5 5 5 6 6 6

5 6

7 7 7

7

xlix

l

Introduction

“reshape” function: The “reshape” is a MATLAB function used to change a matrix dimension as desired. The statement B¼reshape (A,m,n) returns the mn matrix B where the matrix A must have m*n elements. There are many cases and options that can be used with this function. Example.

Reshape a 2-by-3 matrix into a 3-by-2 matrix. A¼

1 4 7 2 5 8

B ¼ reshape(A,3,2) 1 3 B¼ 4 5 5 6 “diag” function: The “diag” function returns a square diagonal matrix with the elements of vector v on the main diagonal. Also, it returns the main diagonal elements of a given matrix A. For example for a given vector v ¼ [1 2 3 5], the statement D¼diag(v) creates a 44 square matrix with the main diagonal of the elements of the vector v. Thus, D ¼ diag(v) returns 1

0 0 0

0 D¼ 0

2 0 0 0 3 0

0

0 0 4

Another example: Having a square matrix 1 2 3 A¼ 4 5 6 7 8 9 B¼diag(A) returns 1 0

0

B¼ 0 1 0 0

0 1

Introduction

5.13 Plotting There are several functions that can be used to plot data in MATLAB such as “plot”, “scatter”, “contour”, “surf”, “quiver”, etc. A MATLAB function is a collection of connected statements that accomplishe a single purpose. Functions assist in segmenting our program into manageable, modular portions. Our program becomes more organized and controlled as it gets bigger and bigger. It also makes the code reusable and prevents repetition. The MATLAB function syntax takes the form function [ ,

,...,

] =

( ,

,...,

)

where x1 ; x2 ; :::; xM are the inputs and y1 ; y2 ; :::; yN is the return output. The following function returns the average and standard deviation of the given set of numbers or a vector, x.

Example.

function [AVR,STD] = Av_St(x) n = length(x); AVR = sum(x)/n; STD = sqrt(sum((x-AVR).^2/n)); end

Multiple local functions or nested functions can be stated in one file. Use the end keyword to mark the completion of each function in a file so that it is easier to read. Any nested or local function must have the “end” keyword. In general, it is worth mentioning that MATLAB has a wealth of documentation to help online. I believe that researchers and students mainly depend on it to enrich their knowledge in MATLAB.

6. Short guide to python As Chapter 11 of this book uses Python to program machine learning techniques, readers may need to have a foundational understanding of the language. Python is a high-level programming language, flexible, and has a big number of libraries. It is also open-source (free of charge) which led to a vast user community that supports it, with lots of packages, making it easy to go with little effort. The availability of open-source programming languages significantly affects the learning curve. In order to run Python on your PC, there are several ways to do so. We will be limited to using “Jupyter Notebook” to run Python through it. Jupyter Notebook is a very powerful browser-

li

lii

Introduction

based Python environment. In order to install “Jupyter Notebook” please search it on the web because this section is limited to presenting the necessary background. The Python standard library, written in C language, is extensive and provides a wide range of capabilities. The library includes built-in modules that give access to system features like file I/O and modules written in Python that offer standardized solutions for many problems that arise in regular programming. In Python, most of the functions or algorithms packages are already available, but if not, it is easy to install them. The available packages that may be needed initially to be installed by pip are Jupyter, IPython, NumPy, SciPy, h5py, matplotlib, cartopy, and joblib; by the command “pip install package_name” and upgraded to the latest version by the command “pip install –upgrade package_name” such that pip is the package manager. Also, it can be uninstalled using the command “pip uninstall package_name.” Moreover, the command “pip list” is for seeing all installed packages. The easiest way to install and use “Jupyter notebook” within “anaconda” is using the link: https://docs. anaconda.com/anaconda/install/. Anaconda can be installed on different platforms including Windows, macOS, Linux, etc. The Jupyter notebook is an open-source web application that enables you to create and run code in many disciplines, including numerical simulation, machine learning, etc. Now, let us explore how to run Python code using the Jupyter notebook. If we type “Jupyter Notebook” in the terminal or double-click its icon on the anaconda navigator interface as shown in Fig. 5, a local web page will pop up which can be used to create a new Python3 notebook using the upper right button of the open page (see Fig. 6). The open page contains cells, and each of them starts with “In [ ]:”. This line is for writing the code statement (Fig. 7).

6.1 Arithmetic and logical operator of Python The arithmetic operators are the same as mentioned above in the MATLAB section. The logical operators can be classified as comparison operators (Table 4) and logical operators as shown in Table 5. The variables are defined in python as shown below in Table 6.

Introduction

Figure 5 Anaconda navigator interface.

Figure 6 Local web page of the working directory.

liii

liv

Introduction

Figure 7 Python working page for writing the code statement.

Table 4 Comparison operators. Operator

Description

¼¼ !¼ >  < 

Equal Not equal Greater than Greater than or equal Less than Less than or equal

Table 5 Logical operators. Operator

Example

Description

AND

P and Q

OR

P or Q

NOT

not P

True if both P and Q are True. False otherwise True if either P or Q is True. False otherwise True if P is False. False if P is True

Introduction

lv

Table 6 Arithmetic operators of Python. Operator

Name

Description

þ  * / %

Addition Subtraction Multiplication Division Modulus

** //

power Floor division

Adds values to the operator’s sides. The right-hand operand is subtracted from the left-hand operand. Values on either side of the operator are multiplied. Divides the right-hand operand by the left-hand operand. Returns the remaining after dividing the left-hand operand by the right-hand operand. Calculates operators’ exponential (power) values. The division of operands when the resulting quotient has the decimal digits eliminated as the result. In contrast, the result is floored, or rounded away from zero, if one of the operands is negative.

In order to implement the above arithmetic operators, let us have the following Python code:

Example.

# Example x = 21 y = 10 z = 0 z1 = x + y print ("z1 = x + y = ", z1) z2 = x - y print ("z2 = x - y = ", z2) z3 = x * y print ("z3 = x * y = ", z3) z4 = x / y print ("z4 = x / y = ", z4) z5 = x % y print ("z5 = x % y = ", z5) r = 2 s = 3 p = r**s print ("p = r**s = ", p) g = 10 h = 5 d = g//h print ("d = g//h = ", d)

lvi

Introduction

Run this code to get the following results: z1 = x + z2 = x z3 = x * z4 = x / z5 = x % p = r**s d = g//h

y y y y y = =

= = = = = 8 2

31 11 210 2.1 0

In the Jupyter Notebook environment, it looks as (Fig. 8):

Figure 8 Python arithmetic operators code as appears in the Jupyter notebook environment.

Introduction

Example.

Python logical operator

# Example for Python logical operator x = 3 y = 5 z = -7 if x > 0 and y > 0: print("Numbers are greater than zero") if x > 0 and y > 0 and z > 0: print("Numbers are greater than zero") else: print("At least one number is not greater than zer o")

Run the code to have the following results: Numbers are greater than 0 At least one number is not greater than 0

It takes the following in the Jupyter Notebook environment (Fig. 9):

Figure 9 Python logical operator code as appears in the Jupyter notebook environment.

lvii

lviii

Introduction

Python functions are similar to MATLAB functions utilized to make our program more organized, prevent repetition, and can do several tasks. The following python function returns arithmetic operations of two numbers including addition, subtraction, multiplication, and division (Fig. 10).

Example.

Figure 10 Python addition, subtraction, multiplication, and division operator code.

References [1] R.P. Feynman, There’s plenty of room at the bottom [data storage], J. Microelectromech. Sys. 1 (1) (Mar. 1992) 60e66, https://doi.org/10.1109/ 84.128057. [2] B. Ju, T. Fan, Experimental study and mathematical model of nanoparticle transport in porous media, Powder Technol. 192 (2) (2009) 195e202, https:// doi.org/10.1016/j.powtec.2008.12.017. [3] Y. Kazemzadeh, S. Shojaei, M. Riazi, Review on application of nanoparticles for EOR purposes: A critical review of the opportunities and challenges, Chinese J. Chem. Eng. 27 (2) (2019) 237e246. [4] N. Lashari, T. Ganat, Emerging applications of nanomaterials in chemical enhanced oil recovery: Progress and perspective, Chinese J. Chem. Eng. 28 (8) (2020) 1995e2009. [5] X. Sun, Y. Zhang, G. Chen, Z. Gai, Application of nanoparticles in enhanced oil recovery: A critical review of recent progress, Energies 10 (2017) 345, https://doi.org/10.3390/en10030345. [6] M.F. El-Amin, J. Kou, S. Sun, Discrete-fracture-model of multi-scale timesplitting two-phase flow including nanoparticles transport in fractured porous media, J. Comp. App. Math. 333 (2018) 249e327. [7] M.F. El-Amin, J. Kou, S. Sun, Convergence analysis of the nonlinear iterative method for two-phase flow in porous media associated with nanoparticle injection, Int. J. Num. Meth. Heat Fluid Flow 27 (10) (2017) 2289e2317. [8] M.F. El-Amin, A. Salama, S. Sun, Numerical and dimensional analysis of nanoparticles transport with two-phase flow in porous media, J. Petrol. Sci. Eng. 128 (2015) 53e64. [9] A. Salama, A. Negara, M.F. El-Amin, S. Sun, Numerical investigation of nanoparticle transport in anisotropic porous media, J. Contam. Hydrol. 181 (2015) 114e130.

Introduction

[10] M.F. El-Amin, J. Kou, S. Sun, A. Salama, An iterative implicit scheme for nanoparticles transport with two-phase flow in porous media, Procedia Computer Sci. 80 (2016) 1344e1353. [11] M.F. El-Amin, J. Kou, S. Sun, A multiscale time-splitting discrete fracture model of nanoparticles transport in fractured porous media, SPE Kingdom Saudi Arabia Ann. Techn. Sympos. Exhib. (2017). [12] M.F. El-Amin, J. Kou, S. Sun, Multiscale adaptive time-splitting technique for nonisothermal two-phase flow and nanoparticles transport in heterogenous porous media, in: SPE-186047-MS, SPE Reservoir Characterisation and Simulation Conference and Exhibition, 8e10 May, Abu Dhabi, UAE, 2017. [13] Meng-Huo Chen, Amgad Slama, M.F. El-Amin, Numerical aspects related to the dynamic update of anisotropic permeability field during the transport of nanoparticles in the subsurface, Procedia Computer Sci. 80 (2016) 1382e1391. [14] M.F. El-Amin, S. Abdel Naeem, N. Ibrahim, Numerical modeling of nanofluids flow and heat transfer in a porous cavity, in: the 2019 8th International Conference on Modeling Simulation and Applied Optimization (ICMSAO), ICMSAO’19, 15e17 April, Manama, Bahrain, 2019. [15] M.F. El-Amin, J. Kou, S. Sun, Adaptive time-splitting scheme for nanoparticles transport with two-phase flow in heterogeneous porous media, in: Y. Shi, et al. (Eds.), Computational SciencedICCS 2018. ICCS 2018. Lecture Notes in Computer Science vol 10862, Springer, Cham, 2018. [16] M.F. El-Amin, S. Sun, A. Salama, Enhanced oil recovery by nanoparticles injection: modeling and simulation, in: 18th Middle East Oil & Gas Show and Conference (MEOS), Bahrain, 13e15 March 2013, 2013. [17] M.F. El-Amin, S. Sun, A. Salama, Modeling and simulation of nanoparticle transport in multiphase flows in porous media: CO2 sequestration, in: Mathematical Methods in Fluid Dynamics and Simulation of Giant Oil and Gas Reservoirs, Istanbul, Turkey, 3e5 September 2012, 2012. [18] M.F. El-Amin, A. Salama, S. Sun, Modeling and simulation of nanoparticles transport in a two-phase flow in porous media, in: SPE International Oilfield Nanotechnology Conference and Exhibition held in Noordwijk, The Netherlands, 12e14 June 2012, 2012. [19] M.F. El Amin, A.M. Saad, A. Salama, S. Sun, Modeling and analysis of magnetic nanoparticles injection in water-oil two-phase flow in porous media under magnetic field effect, Geofluids 2017 (2017). [20] M.F. El-Amin, A.M. Saad, S. Sun, A. Salama, Numerical simulation of magnetic nanoparticles injection into two-phase flow in a porous medium, Procedia Computer Sci. 2017 (2017) 2260e2264. [21] M.F. El-Amin, T. Brahimi, Numerical modeling of magnetic nanoparticles transport in a two-phase flow in porous media, in: SPE Reservoir Characterisation and Simulation Conference and Exhibition, 8e10 May, Abu Dhabi, UAE, 2017. [22] M.F. El-Amin, U. Khalid, A. Beroual, Magnetic field effect on a ferromagnetic fluid flow and heat transfer in a porous cavity, Energies 11 (11) (2018) 3235. [23] S. Mohaghegh, S. Ameri, Artificial neural network as a valuable tool for petroleum engineers, Paper SPE 29220 (1995). [24] A.Á. del Castillo, E. Santoyo, O. García-Valladares, A new void fraction correlation inferred from artificial neural networks for modeling two-phase flows in geothermal wells, Computers Geosci. 41 (2012) 25e39. [25] S. Changdar, S. Saha, S. De, A smart model for prediction of viscosity of nanofluids using deep learning, Smart Sci. (2020) 1e15.

lix

lx

Introduction

[26] S. A. Irfan and A. Shafie, "Artificial neural network modeling of nanoparticles assisted enhanced oil recovery," in Advanced Methods for Processing and Visualizing the Renewable Energy: Springer, pp. 59-75. [27] M. Pirizadeh, N. Alemohammad, M. Manthouri, M. Pirizadeh, A new machine learning ensemble model for class imbalance problem of screening enhanced oil recovery methods, J. Petrol. Sci. Eng. 198 (2021) 108214. [28] B. Daribayev, D. Akhmed-Zaki, T. Imankulov, Y. Nurakhov, Y. Kenzhebek, Using machine learning methods for oil recovery prediction, in: ECMOR XVII 2020, European Association of Geoscientists and Engineers, 2020, pp. 1e13. [29] J. You, W. Ampomah, Q. Sun, Development and application of a machine learning based multi-objective optimization workflow for CO2-EOR projects, Fuel 264 (2020) 116758. [30] K. Van den Doel, M. Robinson, C. Stove, G. Stove, Subsurface temperature measurement using electromagnetic waves and machine learning for enhanced oil recovery, in: 82nd EAGE Annual Conference and Exhibition, European Association of Geoscientists and Engineers, 2020, pp. 1e5. [31] M.H. Esfe, M. Bahiraei, O. Mahian, Experimental study for developing an accurate model to predict viscosity of CuO-ethylene glycol nanofluid using genetic algorithm based neural network, Powder Technol. 338 (2018) 383e390. [32] B. Alwated, M.F. El-Amin, Enhanced oil recovery by nanoparticles flooding: From numerical modeling improvement to machine learning prediction, Adv. Geo-Energy Res. 5 (3) (2021) 297e317.

To my parents, wife, and kids (Arwa, Rawan, Abdullah, Tala, and Taliyah)

Acknowledgment

I would like to express my heartfelt gratitude to my friend Professor Jisheng Kou, Hubei Engineering University, for his invaluable support throughout the writing of this book. Also, I would also like to extend my appreciation to Mr. Ahmed Almasarani, my former MSc student, for his skillful preparation of many of the illustrative diagrams in the book. Furthermore, I would like to thank Ms. Mariana Kuhl and Ms. Tessa Kathryn, Editorial Project Managers, Mohanraj Rajendran, Copyrights Specialist, and Ms. Fizza Fathima, Production Project Manager, for their tireless efforts in ensuring the smooth publication of this book. Their professionalism and dedication have been a key factor in bringing this project to fruition. Once again, I express my sincere thanks to all those who have contributed to this work in one way or another.

1 Basic concepts and modeling aspects 1.1 Continuum theory and fluid flow Continuum mechanics is a method of analyzing material behavior without considering its particular origin. A continuum can be divided and infinitely subdivided, which allows for studying matter movement on scales larger than particle distances. Therefore, researchers in continuum mechanics are interested in the average behavior of large numbers of particles (atoms), and not their individual motions. The continuum approach is used to study a vast range of phenomena, including fluid flow, such as air and water flow, and flow in porous media such as hydrocarbon transport, in underground reservoirs. Fluid mechanics is a branch of continuum mechanics that studies the behavior of fluids such as liquids and gases. The continuum assumption is helpful because it eliminates molecular discontinuities by averaging microscopic quantities across a limited smaller volume. In fluid mechanics, all macroscopic parameters, including density, velocity, pressure, temperature, etc., are considered to fluctuate continuously from point to point inside the flow. Fluid dynamics is a branch of fluid mechanics that concerns the effect of forces on fluid motion and is an evolving research theme, one that is often mathematically challenging. Many problems are wholly or partially unsolved, and numerical approaches, generally involving computers, are the most effective way to solve them. For the flow in porous media, the averaging process is much more complicated as the averaging volume must be large enough to ensure that the average properties are independent of the representative elementary volume (REV). Still, it must be substantially smaller than the full domain size. Regarding scales, the molecular scale ( z 1010 m) is the scale at which individual molecule movements and interactions are described, whereas the scale determined from molecular scale averaging is microscale ( z 106  102 m). The matter appears to be continuous at this scale, and the molecular movement seems to be not observed. Numerical Modeling of Nanoparticle Transport in Porous Media. https://doi.org/10.1016/B978-0-323-90511-4.00014-9 Copyright © 2023 Elsevier Inc. All rights reserved.

1

2

Chapter 1 Basic concepts and modeling aspects

The scale generated from averaging the microscale properties within a sample elementary volume is called macroscale ( z 103  101 m, REV). Finally, the field-scale ( z 101  104 m) represents the scale of interest in typical underground reservoirs. The transition from the microscale to macroscale leads to another basic equation called Darcy’s law involving different parameters such as saturation and permeability. Differential equations can be used to describe conservation laws by applying the continuum hypothesis to transport phenomena in porous media.

1.2 Flow in porous media A porous medium is a solid material containing pores (voids or spaces) through which a fluid (gas or liquid) can pass (as shown in Fig. 1.1). The skeleton of the material is often called a matrix which is almost solid. The porous medium is most often characterized by its porosity and permeability. Additionally, the following assumptions on the geometry of the porous medium should be considered: • The void space of the porous medium is assumed to be interconnected to allow fluid to flow. • The continuum hypotheses state that the dimensions of the void space must be large compared to the mean free path length equals one of the fluid molecules. • The void space is small enough so that the fluid flow is controlled by adhesive forces at fluidesolid interfaces and cohesive forces at fluidefluid interfaces.

Figure 1.1 Porous media sketch.

Chapter 1 Basic concepts and modeling aspects

There are many examples of natural porous media including rocks and soil (e.g., in aquifers, petroleum reservoirs) and biological tissues (e.g., bones, wood, cork) as well as man-made porous media such as cements and ceramics. Porous media are used in many disciplines such as filtration, petroleum engineering, bioremediation, construction engineering, geosciences, biology, and material science. Fluid properties such as density and viscosity and the properties of porous media such as porosity and permeability that are essential for describing flow are described in the in the following subsections. One of the most common oil and gas reservoirs, identified by petroleum firms worldwide, is sandstone, which is considered an example of a random porous medium. Sandstone, characterized by different grains’ sizes, is a porous medium deposited over a long geological time by consolidation and compaction. The pore in sandstone consists of the pore chamber (the widest portion of the pore) and the pore throat. Pore throats in sandstone range in size from 0.5 to 5.0 mm, while pore chambers range from 5.0 to 50.0 mm [1,2]. Note that 1 mm ¼ 1  106 m.

1.3 Rock properties 1.3.1 Porosity The porosity is a measure of the pore volume in a porous medium. It is defined by the ratio between the volume of the pores and the total volume, i.e., 4¼

Vpores Vtotal

(1.1)

In some cases, it is necessary to distinguish between porosity and effective porosity, i.e., the pore volume that is accessible for fluid flow. Fig. 1.2 illustrates an actual field porosity map.

1.3.2 Permeability The absolute (intrinsic) permeability is a measure of the resistance of a particular porous medium toward the flow of a fluid in its pores. It is a material property of the porous medium and is assumed to be independent of the fluid. The absolute permeability is linked to the hydraulic conductivity Kf , by considering the viscosity m and density r of the fluid, namely m (1.2) K ¼ Kf rg

3

4

Chapter 1 Basic concepts and modeling aspects

Figure 1.2 Actual field porosity.

where g is the gravitational constant. In most cases, the Kf values refer to pure water as the pore-filling fluid. Permeability is dependent on the porosity and the grain-size distribution of the porous medium (e.g., Hazen [4]). However, large porosities do not necessarily mean high permeabilities, e.g., clays have high porosities but very low permeabilities [5]. The unit for permeability used in reservoir engineering is Darcy [D] (or Millidarcy [mD]). 1D refers to the permeability that leads to a specific discharge of 1 cm=s for a fluid with a viscosity of 1cpð1cP ¼ 1 Centi  poise ¼ 1  103 Pa s and a density of 1000 kg m3 at a hydraulic gradient of 1000 m=m. One Darcy corresponds to a permeability of 1  1012 m2 . Table 1.1 presents some typical permeabilities for different types of soil and rock. Fig. 1.3 shows a real field (reservoir) permeability map.

Chapter 1 Basic concepts and modeling aspects

Table 1.1 Permeabilities for different soil and rock types [6].

Soil/Rock type

Permeability [mD]

Clean gravel Clean sand, gravel, and sand Oil rocks, peat, fine sand Sandstone, stratified clay Limestone, dolomite, clay Granite, breccia

108  106 106  104 104  101 101  101 101  103 103  105

Figure 1.3 Real field (reservoir) permeability. Adapted from A.M. Al-Dhafeeri, H.A. Nasr-El-Din, Characteristics of highpermeability zones using core analysis, and production logging data. J. Pet. Sci. Eng. 55 (2007) 18e36.

5

6

Chapter 1 Basic concepts and modeling aspects

1.4 Fluid properties 1.4.1 Density Density may be defined in two different ways, mass density    and molar density. Mass density g m3 is defined as mass m per volume V , m (1.3) V   while in molar density moles ½m3 m3 is the number of moles per volume. The density of a pure substance depends on pressure and temperature and usually increases with increasing pressure and decreasing temperature. In the case of mixtures, the density depends additionally on the composition. For example, the density of water in deep geological formations that contain high salt concentrations is significantly higher than that of pure water. Different materials usually have different densities, and density is directly related to buoyancy which is related to temperature and/or concentrations of species. r¼

1.4.2 Viscosity Dynamic viscosity is the proportionality factor of the relation x between the fluid’s shear tension and the velocity gradient, vu vy and is given by s (1.4) m¼ vux =vy The viscosity of a liquid usually increases with increasing pressure and decreasing temperature. In a gaseous fluid, viscosity increases with pressure, but decreases with decreasing temperature. As for the density, it is necessary to consider pressure and temperature effects on viscosity, as well as its dependence on composition in mixtures in some cases. In this study, dynamic viscosity is referred to when mentioning viscosity. Nevertheless, in certain circumstances, it may be necessary to use the kinematic viscosity, where m v¼ (1.5) r

1.4.3 Saturation In the case of several phases flowing in a porous medium, it is necessary to have a measure of the fraction of the pores filled with a fluid phase. This is given by the saturation that is defined

Chapter 1 Basic concepts and modeling aspects

as the ratio between the volume of the pores filled with phase a and the total pore volume, namely Sa ¼

Va Vpores

(1.6)

Following this definition, it is clear that the phase saturations have to sum up to unity, i.e., X Sa ¼ 1 (1.7) a

1.4.4 Capillary pressure The pressure difference on the curved interface between two immiscible fluids in a tiny capillary tube is known as capillary pressure (Fig. 1.4). Therefore, the capillary pressure, Pc , takes the form Pc ¼ Pnw  Pw

(1.8)

where Pnw is pressure of the nonwetting phase and Pw is the pressure of the wetting phase. The forceebalance relationship satisfies the equilibrium between fluid phases in a capillary tube (or pore in the case of porous media), i.e., Pc ¼

2s cosq r

(1.9)

where s is the interfacial (or surface) tension, q is the contact angle, and r is the pore radius. The capillary pressure depends on the pore geometry, fluid properties, and phase saturations. It can be expressed as

Figure 1.4 Sketch of capillary pressure in porous media.

7

8

Chapter 1 Basic concepts and modeling aspects

Pc ¼ g

pffiffiffiffiffiffiffiffiffiffi 4=K JðSÞ

(1.10)

where g is the interfacial tension and JðSÞ is the Leverett function which is a function of the normalized saturation S, i.e., S¼

Sw  Siw ;0  S  1 1  Snwr  Siw

(1.11)

where Siw is the irreducible wetting phase saturation and Snwr is the residual nonwetting phase saturation. Typically, the Leverett function, JðSÞ, lies between two limits, drainage and imbibition (Fig. 1.5). There are many empirical formulae to represent the capillary pressure and are mainly dependent on the type of application. The goal of injecting a water-nanoparticles suspension into an oil reservoir is to modify the medium’s wettability from oil-wet to water-wet, resulting in a mixed-wet rock. As a result, a more general correlation for capillary pressure should be included in any mathematical model to describe its variation due to wettability changes. Positive standard capillary pressure correlations are the most common ones and they are limited to primary drainage. Huang et al. [7] proposed a broad correlation encompassing all components of the bounding hysteresis loop, including spontaneous and forced imbibition and spontaneous and forced secondary drainage. Based on Brooks and Corey’s basic power-law form for primary drainage capillary pressure, Skjaeveland et al. [8]

Figure 1.5 Sketch of the capillary pressure curves.

Chapter 1 Basic concepts and modeling aspects

proposed a generic capillary pressure correlation for mixed-wet reservoir rock. Other mixed-wet systems require symmetrical correlation for the two fluids because neither dominates the wettability between the two extremes, a completely water-wet system and a completely oil-wet system. Summing the two limiting expressions that result in the general expression yields the general correlation,  a  a 1  Swr w 1  Sor o p c ¼ cw þ co (1.12) sw  swr So  sor where cw is the entry pressure for imbibition and co is the entry pressure for drainage. The constant 1=aw is the pore size distribution index for imbibition and 1=a0 is the pore size distribution index for drainage. Water imbibes into the rock when the oil pressure gradually decreases, and the water saturation rises. If the water saturation reaches the spontaneous imbibition case, the oil and water pressures are equal (pc ¼ 0). By increasing the water pressure above the oil pressure, the saturation rises from this point. Therefore, the capillary pressure becomes negative [9].

1.4.5 Relative permeability The relative permeability of the wetting phase is provided as 0 krw ¼ krw Sa

(1.13)

while the relative permeability of the nonwetting phase is 0 krn ¼ krn ð1  SÞb

(1.14)

where 0 krw ¼ krw ðS ¼ 1Þ 0 krn ¼ krn ðS ¼ 0Þ

and the normalized saturation is S¼

Sw  Siw 0.1)&(cxs.0)&(cys.30)&(cxs.2)&(cys.5)&(cxs.0)&(cys.70)&(cxs.2)&(cys uc ; vCs2 ¼ gpt jujC; vt

C ¼ CB ; Cs1 ¼ Cs2 ¼ 0 on GD j,n ¼ jB on GN

(3.10) (3.11) (3.12)

(3.13) (3.14)

where j is the diffusive flux vector, c is nanoparticles concentration, D is the dispersion tensor, and jB is the concentration flux at the boundary. We divide the rectangular region into nx  ny cell and the mesh defined as  o n (3.15) xi ; yj ; i ¼ 0; 1; /; nx ; j ¼ 0; 1; /; ny where 0 ¼ x0 < x1 < / < xnx ¼ Lx and 0 ¼ y0 < y1 < / < yny ¼ Ly .

3.2.1 Pressure equation discretization The discretized CCFD pressure takes the form (Fig. 3.4) 1 0 C B piþ12;jþ11 ¼ p@xiþ12 ; yjþ12 A

(3.16)

65

66

Chapter 3 Spatial numerical discretization methods

uy 1

i , j1 2

p

1 i , j1 2

uy

i, j

p

uy

1 2

i, j

i1, j

p

1 1 i , j 2 2

1 2

p

1 2

i1, j

1 2

hy

uy 1

y

i , j 2

p

x

hx

1 i , j 2

Figure 3.4 Generic CCFD rectangular cell.

The pressure in Eq. (3.10) is discretized as K i;jþ12

piþ12;jþ12  pi12;jþ12 xiþ12  xi12

þ K iþ1;jþ12

piþ32;jþ12  piþ12;jþ12 xiþ32  xiþ12

xiþ1  xi

K iþ12;j þ

piþ12;jþ12  piþ12;j12 yjþ12  yj12

þ K iþ12;jþ1

piþ12;jþ32  piþ12;jþ12

yjþ1  yj

yjþ32  yjþ12

nþ1 ¼ qiþ 1;jþ1 2

2

(3.17)

where 1 ðxi þ xiþ1 Þ; Dxi ¼ xiþ1  xi ; i ¼ 0; 1; /; nx  1 2 (3.18)  1 ¼ yj þ yjþ1 ; Dyj ¼ yjþ1  yj ; j ¼ 0; 1; /; ny  1 2

xiþ12 ¼ yjþ12

3.2.2 Darcy’s law discretization Let us denote to the discretized as 0

1

B C uxi;jþ1 ¼ ux @xi ; yjþ12 A 0

1

B C y uiþ1;j ¼ uy @xiþ12 ; yj A 2

(3.19)

Chapter 3 Spatial numerical discretization methods

We calculate the permeability tensor using the weighted harmonic average in which the permeability x-component is xiþ1  xi1 xx Ki;jþ 1 ¼ xiþ1  xi xi  xi1 2 þ xx xx Kiþ Ki1;jþ1 1;jþ1 2

2

2

(3.20)

2

and the permeability y-component is yjþ1  yj1 yy Kiþ1;j ¼ y  y y  y jþ1 j i i1 2 þ yy Kiþ12;j12 Kiþ1;jþ1 2

(3.21)

2

The CCFD approximation of the x-component of Darcy’s law is given by piþ12;jþ12  pi12;jþ12 xx uxi;jþ1 ¼  Ki;jþ ; i ¼ 1; /; nx ; j ¼ 0; /; ny  1. 1 2 2 xiþ12  xi12 (3.22) On the west boundary we have xx ux0;jþ1 ¼ K0;jþ 1 2

ux0;jþ1 2

p12;jþ12  pW B;jþ1 2

x12  x0

2

; j ¼ 0; /; nI ; 0 < nI < ny

(3.23)

¼ 0; j ¼ nI þ 1; /; ny

While on the east boundary we have uxnx ;jþ1 ¼  Knxxx ;jþ1 2

2

pEB;jþ1  pnx 12;jþ12 2

xnx  xnx 12

; j ¼ 0; /; ny  1

(3.24)

In the above equations, pW denotes the pressure at the west boundary and pE the pressure on the east boundary. Also, in the above equations we may need to define the permeabilities on the boundaries as the permeabilities of the nearest cells, that is, xx xx K0;jþ 1 ¼ K1;jþ1 ; j ¼ 0; /; ny  1 2

2

2

Knxxx ;jþ1 ¼ Knxxx 1;jþ1 ; j ¼ 0; /; ny  1 2

2

(3.25)

2

Similarly, the CCFD approximation of the y-component of Darcy’s law may be written as y

yy

uiþ1;j ¼  Kiþ1;j 2

2

piþ12;jþ12  piþ12;j12 yjþ12  yj12

; i ¼ 0; /; nx  1; j ¼ 1; /; ny (3.26)

67

68

Chapter 3 Spatial numerical discretization methods

On the south and north boundaries, we have, respectively, y

y

uiþ1;0 ¼ 0; uiþ1;ny ¼ 0; i ¼ 0; 1; /; nx  1. 2

(3.27)

2

The nanoparticles transport equation involves an accumulation term, advection term, diffusion term, and R. The advection term is discretized based on the upwind scheme, such that, 82 3 2 39 > > < = 1 6 þ 7 6 þ 7   V , uC ¼ 4ux;iþ1;jþ1 Ciþ12;jþ12 þ ux;iþ1;jþ12 Ciþ32;jþ12 5  4ux;i;jþ1 Ci12;jþ12 þ ux;i;jþ12 Ciþ12;jþ12 5 2 2 > DxðiÞ > : ;

(3.28)

The treatment of the diffusion term is similar to the pressure equation; thus, Di;jþ12 V , DVC ¼

Ciþ12;jþ12  Ci12;jþ12 xiþ12  xi12

þ Diþ1;jþ12

Ciþ32;jþ12  Ciþ12;jþ12 xiþ32  xiþ12

xiþ1  xi Ciþ12;jþ12  Ciþ12;j12 Ciþ1;jþ3  Ciþ12;jþ12 Diþ12;j þ Diþ12;jþ1 2 2 yjþ12  yj12 yjþ32  yjþ12 þ yjþ1  yj (3.28)

3.2.3 Boundary conditions treatment The treatment of various boundary conditions depends on the type of those boundary conditions. There could be Neuman B.Cs., Dirichlet B.Cs., or even mixed B.Cs. In general, the treatment can be written in form of cases equation as 8 > > > > p12;jþ12  p0;jþ12 > > > if dDiri < K12xx 0;jþ12 ¼ 0 ;jþ12 x12  x0 x u0;jþ1 ¼ (3.29) 2 > > Diri 0 > > uB;0;jþ1 if d0;jþ1 ¼ 1 > 2 2 > > :

Chapter 3 Spatial numerical discretization methods

Figure 3.5 Treatments boundary conditions at different types and regions.

We have implemented both Dirichlet and Neumann boundary conditions where we have defined a factor d that indicates whether at the location there is a Dirichlet boundary condition ðd ¼ 1Þ or a Neumann boundary condition ðd ¼ 0Þ. This equation is an example of the general boundary condition at the west boundary. Other boundaries follow the same pattern. Eight types of boundary conditions are treated as shown in Fig. 3.5. Therefore, there are eight versions of discretization for pressure, velocities, and concentration equations in areas one to eight.

3.2.4 MATLAB codes Now, let us present a MATLAB code for the computation of discretized pressure and velocity equations in traditional CCFD discretization.

69

70

Chapter 3 Spatial numerical discretization methods

MATLAB Code to calculate pressure % MATLAB Code of Pressure Equation % div( K grad P ) = 0 General PDE to be discretized without source term clc clear all close all Lx=10; Ly=15; nx ny

= 40; = 60;

% Discretization along X direction x1 = Lx; x2 = 0.0; ratio = 0.1; xe xe x dx

= = = =

elm_line1 (x1,x2,nx,ratio); fliplr(xe)'; zeros(nx,1); zeros(nx,ny);

y1 = 0; y2 = Ly; ratio = 0.1; ye = elm_line1 (y1,y2,ny,ratio); y = zeros(1,ny); dy = zeros(nx,ny); for iy = 1:ny y(1,iy) = ye(1,iy+1) - ye(1,iy); end for ix = 1:nx for iy = 1:ny dy(ix,iy) = y(1,iy); end end k0 = 2e-14; % Permeability (k(i,j)) in m^2 phi0 = 0.3; % Porosity of the medium phi = ones(nx,ny)*phi0; k = ones(nx+1,ny+1)*k0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Boundary Conditions % Inflow Rate at the Right Bdry (m/s) Uleft = ((Lx*Ly*1*phi0)*0.1)/(sum(y(1,ny-2:ny))*1)/(365*24*3600);

Chapter 3 Spatial numerical discretization methods

Pright = 2*101325; % Pressure head in Pa %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %

Coefficients in x and y directions for ix = 1:nx+1 for iy = 1:ny Kx(ix,iy)

= k(ix,iy);

end end for ix = 1:nx for iy = 1:ny+1 Ky(ix,iy)

= k(ix,iy);

end end

for ix = 1:nx for iy = 1:ny % Area 1 if ix == 1 && iy == 1 z

= ix + nx * (iy-1);

A(z,z) = ( Kx(ix+1,iy) / ( dx(ix+1,iy)/2 + dx(ix,iy)/2 ) / dx(ix,iy) ) + ( Ky(ix,iy+1)... / ( dy(ix,iy+1)/2 + dy(ix,iy)/2 ) / dy(ix,iy) ); A(z,z+1)

= -1 * Kx(ix+1,iy) / ( dx(ix+1,iy)/2 + dx(ix,iy)/2 )

A(z,z+nx)

= -1 * Ky(ix,iy+1) / ( dy(ix,iy+1)/2 + dy(ix,iy)/2 )

/ dx(ix,iy);

/ dy(ix,iy); % Area 4' elseif ix == 1 && iy>=ny-2 && iy1 && iy1 && ix1 && iy1 && ix1 && ix1 && iy=ny-2 && iy1 && iy1 velx (ix,iy) = - Kx(ix,iy) * (P(ix,iy) - P(ix-1,iy)) / ( dx(ix,iy)/2 + dx(ix-1,iy)/2 ); end end end ix = nx+1; for iy=1:ny velx (ix,iy) = - 2 * Kx(ix,iy) * (Pright - P(ix-1,iy)) / dx(ix1,iy); end for ix=1:nx for iy=1:ny if iy == 1 vely(ix,iy) = 0; elseif iy>1 vely (ix,iy) = - Ky(ix,iy) * (P(ix,iy) - P(ix,iy-1)) / ( dy(ix,iy)/2 + dy(ix,iy-1)/2 ); end end end iy = ny+1; for ix=1:nx vely (ix,iy) = 0; end

Chapter 3 Spatial numerical discretization methods

MATLAB Code to advection term in concentration equation % The following MATLAB Code is to calculate the advection term of the % concentration equation based on upwind scheme and CCFD method for iT=1:nT conc(1,1) = conc(1,1) + (1/phi(1,1)) * ( BC(1,1) +(1/dx(1))*(max(velx(2,1),0)*conc(1,1)-max(velx(1,1),0)*BC_W(1)) +(1/dy(1))*(max(vely(1,2),0)*conc(1,1)-max(vely(1,1),0)*BC_S(1,1)) +(1/dx(1))*(min(velx(2,1),0)*conc(2,1)-min(velx(1,1),0)*conc(1,1)) +(1/dy(1))*(min(vely(1,2),0)*conc(1,2)-min(vely(1,1),0)*conc(1,1)) )*dt;

conc(1,ny) = conc(1,ny) + (1/phi(1,ny)) * ( BC(1,ny) +(1/dx(1))*(max(velx(2,ny),0)*conc(1,ny)-max(velx(1,ny),0)*BC_W(ny)) +(1/dy(ny))*(max(vely(1,ny+1),0)*conc(1,ny)-max(vely(1,ny),0)*conc(1,ny-1)) 1/dx(1))*(min(velx(2,ny),0)*conc(2,ny)-min(velx(1,ny),0)*conc(1,ny)) 1/dy(ny))*(min(vely(1,ny+1),0)*BC_N(1)-min(vely(1,ny),0)*conc(1,ny)))*dt;

for iy =2:ny-1 conc(1, iy) = conc(1, iy) + (1/phi(1, iy)) * (BC(1, iy) +(1/dx(1))*(max(velx(2,iy),0)*conc(1,iy)-max(velx(1,iy),0)*BC_W(iy)) +(1/dy(iy))*(max(vely(1,iy+1),0)*conc(1,iy)-max(vely(1,iy),0)*conc(1,iy-1)) +(1/dx(1))*(min(velx(2,iy),0)*conc(2,iy)-min(velx(1,iy),0)*conc(1,iy)) 1/dy(iy))*(min(vely(1,iy+1),0)*conc(1,iy+1)min(vely(1,iy),0)*conc(1,iy)))*dt; end conc(nx,1) = conc(nx,1) + (1/phi(nx,1)) * (BC(nx,1) +(1/dx(nx))*(max(velx(nx+1,1),0)*conc(nx,1)-max(velx(nx,1),0)*conc(nx-1,1))+(1/dy(1))*(max(vely(nx,2),0)*conc(nx,1)-max(vely(nx,1),0)*BC_S(nx)) +(1/dx(nx))*(min(velx(nx+1,1),0)*BC_E(1)-min(velx(nx,1),0)*conc(nx,1)) +(1/dy(1))*(min(vely(nx,2),0)*conc(nx,2)-min(vely(nx,1),0)*conc(nx,1)))*dt;

conc(nx,ny) = conc(nx,ny) + (1/phi(nx,ny)) * (BC(nx,ny) +(1/dx(nx))*(max(velx(nx+1,ny),0)*conc(nx,ny)-max(velx(nx,ny),0)*conc(nx-1,ny)) +(-1/dy(ny))*(max(vely(nx,ny+1),0)*conc(nx,ny)-max(vely(nx,ny),0)*conc(nx,ny1))+(-1/dx(nx))*(min(velx(nx+1,ny),0)*BC_E(ny)min(velx(nx,ny),0)*conc(nx,ny)) 1/dy(ny))*(min(vely(nx,ny+1),0)*BC_N(nx)min(vely(nx,ny),0)*conc(nx,ny)))*dt;

for iy = 2:ny-1

77

78

Chapter 3 Spatial numerical discretization methods

conc(nx,iy) = conc(nx,iy) + (1/phi(nx,iy)) * (BC(nx,iy) +(1/dx(nx))*(max(velx(nx+1,iy),0)*conc(nx,iy)-max(velx(nx,iy),0)*conc(nx1,iy))+(-1/dy(iy))*(max(vely(nx,iy+1),0)*conc(nx,iy)max(vely(nx,iy),0)*conc(nx,iy-1))+(-1/dx(nx))*(min(velx(nx+1,iy),0)*BC_E(iy)min(velx(nx,iy),0)*conc(nx,iy))+(1/dy(iy))*(min(vely(nx,iy+1),0)*conc(nx,iy+1)min(vely(nx,iy),0)*conc(nx,iy)))*dt; end

for ix= 2:nx-1 conc(ix,1) = conc(ix,1) + (1/phi(ix,1)) * (BC(ix,1) +(1/dx(ix))*(max(velx(i+1,1),0)*conc(ix,1)-max(velx(ix,1),0)*conc(i-1,1)) +(-1/dy(1))*(max(vely(ix,2),0)*conc(ix,1)-max(vely(ix,1),0)*BC_S(ix)) +(-1/dx(ix))*(min(velx(i+1,1),0)*conc(i+1,1)-min(velx(ix,1),0)*conc(ix,1)) +(-1/dy(1))*(min(vely(ix,2),0)*conc(ix,2)-min(vely(ix,1),0)*conc(ix,1)))*dt; end

for ix= 2:nx-1 conc(ix,ny) = conc(ix,ny) + (1/phi(ix,ny)) * (BC(ix,ny) +(1/dx(ix))*(max(velx(i+1,ny),0)*conc(ix,ny)-max(velx(ix,ny),0)*conc(i-1,ny)) +(-1/dy(ny))*(max(vely(ix,ny+1),0)*conc(ix,ny)-max(vely(ix,ny),0)*conc(ix,ny1)) +(1/dx(ix))*(min(velx(i+1,ny),0)*conc(i+1,ny)-min(velx(ix,ny),0)*conc(ix,ny)) +(-1/dy(ny))*(min(vely(ix,ny+1),0)*BC_N(ix)min(vely(ix,ny),0)*conc(ix,ny)))*dt; end

for ix= 2:nx-1 for iy = 2:ny-1 conc(ix,iy) = conc(ix,iy) + (1/phi(ix,iy)) * (BC(ix,iy) +(1/dx(ix))*(max(velx(i+1,iy),0)*conc(ix,iy)-max(velx(ix,iy),0)*conc(i-1,iy)) +(-1/dy(iy))*(max(vely(ix,iy+1),0)*conc(ix,iy)-max(vely(ix,iy),0)*conc(ix,iy1)) +(1/dx(ix))*(min(velx(i+1,iy),0)*conc(i+1,iy)-min(velx(ix,iy),0)*conc(ix,iy)) +(-1/dy(iy))*(min(vely(ix,iy+1),0)*conc(ix,iy+1)min(vely(ix,iy),0)*conc(ix,iy)))*dt; end

Chapter 3 Spatial numerical discretization methods

end FWMC(iT) = (sum(velx(end,:).*conc(nx,:))/(sum(velx(end,:))));

if iT == 400 conc = conc; end end

Remark: One can obtain the flow-weighted mean concentration on the entire outflow boundary using the formula R ðu•nÞds G . FWMC ¼ R outflow Goutflow ðu•nÞds And the implementation is realized by a simple discretized scheme for each time step, P ðvelxðnx þ 1; 1: nyÞ Cðnx; 1: nyÞÞ P . FWMC ¼ velxðnx þ 1; 1: nyÞ The temporal discretization of the convection equation follows the forward Euler’s method. For the first time step, we use the initial condition to get the concentration C k , and then obtain C kþ1 based on C k (the temporal discretization will be discussed in detail in Chapter 4). We calculate the concentration distribution at different times. Usually, the time scale of the subsurface application is given in years, and the unit of velocity is m/years.

3.3 Shifting matrix method with MATLAB implementation One of the issues of efficiency in solving partial differential equations numerically is designing efficient and robust algorithms. Using an efficient algorithm, we may achieve the solution in less time than required. It is known that MATLAB is one of the most powerful in using matrices. However, it is inefficient in loops because of the required interpreting procedures for every single loop. Therefore, it is important that we perform matrix operations without looping processes. Sun et al. [2] introduced a technique in which cell-centered information and face-

79

80

Chapter 3 Spatial numerical discretization methods

centered information are shifted to the adjacent face-center and cell-center, respectively. Therefore, loops are no longer used within the code, significantly reducing CPU time. This enables the difference equations to be done for all the cells at once using matrix operations rather than within loops. Moreover, for postprocessing, the face-center information can be mapped to the physical grid nodes for contour plotting and streamlines construction. We use the finite difference technique in our implementation, which may equally be used in finite-volume and finite-element settings.

3.3.1 Shifting technique On the traditional coding of the above set of PDEs, exhaustively longer time will be required for calling and updating arrays that are usually done within a loop in particular using some programming languages which require repeating interpretation such as MATLAB. To overcome this problem, we introduce a more robust technique by minimizing loops. The main idea of the shifting technique is to construct the difference scheme so that it can be done for all the nodes at the same time using array operations that are available in MATLAB. The technique has the following steps [2]: • Reshaping cells and edges variables into column vectors. • Shifting these newly established column vectors in such a way that subtracting the corresponding components results in the formulas given in difference equations. • Inserting zeros in the places where we shift the column vector. So, the resulting column vector is larger by m or n places which are later filled with information of the boundary. • The pressure data are usually saved in 2m  n array, 3 2 p1;1 p1;2 / p1;n 7 6 7 6p 6 2;1 p2;2 / p2;n 7 pi;j ¼ 6 (3.30) 7 6 « « 1 « 7 5 4 pm;1 pm;2 / pm;n Now, let us reshape this matrix as a column vector of dimension mn  1.

Chapter 3 Spatial numerical discretization methods

2



p1;1

6 6 « 6 6 6p 6 m;1 6 6 6 p1;2 6 6 6 « 6 6 6 pm;2 6 6 6 « 6 6 6 « 6 6 6 « 6 6 6 6 « 6 6 6 p1;n 6 6 6 « 4

pm;n

3 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 5

(3.31)

½mn1

Implementation: reshape ðA; m; nÞ returns the m  n matrix whose elements are taken column-wise from A.

Example 3.1.

Reshape the following matrix A which of order 4  3, 3 2 1 2 3 7 6 6 4 5 6 7 7 6 (3.32) A¼6 7 6 7 8 9 7 5 4 10 11 12 43

into a 2  6 matrix and a 1  12 matrix.

81

82

Chapter 3 Spatial numerical discretization methods

Then shifting up and inserting zeros in the extra elements’ locations, we get a vector of dimension ½ðm þ1Þn 1, 2 2

p1;1

6 6 « 6 6 6p 6 m;1 6 6 6 p1;2 6 6 6 « 6 6 6 pm;2 6 6 6 « 6 6 6 « 6 6 6 « 6 6 6 6 « 6 6 6 p1;n 6 6 6 « 4

pm;n

3 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 5 ½mn1

Shift Up

!

p1;1

3

6 7 6 7 6 « 7 6 7 6 7 6 pm;1 7 6 7 6 7 6 0 7 6 7 6 7 6 p1;2 7 6 7 6 7 6 « 7 6 7 6 7 6p 7 6 m;2 7 6 7 6 0 7 6 7 6 7 6 7 6 « 7 6 7 6 7 6 « 7 6 7 6 7 6 « 7 6 7 6 7 6 « 7 6 7 6 7 6p 7 6 1;n 7 6 7 6 « 7 6 7 6 7 6 7 6 pm;n 7 4 5

0

(3.33)

½ðmþ1Þn1

Chapter 3 Spatial numerical discretization methods

Similarly, shifting down and insert zeros in the extra elements’ locations, again we get a vector of dimension ½ðm þ1Þn 1, 2

p1;1

6 6 « 6 6 6p 6 m;1 6 6 6 p1;2 6 6 6 « 6 6 6 pm;2 6 6 6 « 6 6 6 « 6 6 6 « 6 6 6 « 6 6 6 6 p1;n 6 6 6 « 4

pm;n

2

3

6 6 6 « 6 6 6 pm;1 6 6 6 0 6 6 6 p1;2 6 6 6 « 6 6 6p 6 m;2 6 6 6 « 6 6 6 « 6 6 6 « 6 6 6 « 6 6 6 0 6 6 6p 6 1;n 6 6 6 « 4

7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 5

0 6 7 6 p 7 6 1;1 7

3 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 5

Shift Down

!

½mn1

pm;n

(3.34)

½ðmþ1Þn1

After shifting processes, two useful operations may be done using these new forms of the pressure field: • Subtracting these new vectors will generate the difference scheme which is required in the finite difference algorithms. • Adding these new vectors may be used to generate average values between adjacent cell information. The operation of A E on cell-centered information vectors maps these vector of dimension mn to a higher space of dimension ðm þ1Þn. In a similar fashion, the other three shifting matrices toward the A W ; A N and A S can map vectors of dimension mn to a one of higher space of dimension ðm þ1Þn. Remark: The above set of shifting matrices is characterized by the following interesting properties: • A TE AE ¼ ATW A W ¼ ATS AS ¼ ATN AN ¼ Imnmn • A TE BE ¼ ATW BW ¼ 0mnn • A TN BN ¼ A TS BS ¼ 0mnm • A E A TE ; A W ATW ; AS ATS ; AN A TN sI; 0

83

84

Chapter 3 Spatial numerical discretization methods

Moreover, the boundary shifting matrices provided information on the boundaries. Furthermore, we can construct shifting matrices to transfer face center information to the nodes. These kinds of matrices are necessary for postprocessing and plotting of the data. For the north-south shifting, these matrices map spaces with ðm þ1Þn dimensions to spaces with ðm þ1Þðn þ1Þ dimensions. And for the east-west shifting, these matrices maps spaces with ðn þ1Þm dimensions to spaces with ðm þ1Þðn þ1Þ dimensions. Remark: Extending this technique to a three-dimensional Cartesian grid is straight forward. In this case, two more shifting matrices would be required to shift cell center information to the top and bottom faces and vice versa.

3.3.2 Harmonic mean of permeability Now, we use the above-defined shifting matrices to construct the difference equations that appear from CCFD discretization of the governing equations. For example, if the permeability is considered as a piecewise constant function over each cell, the permeability at cell edges is the weighted harmonic mean of the permeability of the neighboring cells. Therefore, we have Kxx ði; jÞ ¼

DxðiÞ þ Dxði  1Þ DxðiÞ Dxði  1Þ þ Kxx ði; jÞ Kxx ði  1; jÞ

(3.35)

and the permeability y-component is Kyy ði; jÞ ¼

DyðjÞ þ Dyðj  1Þ DyðjÞ Dyðj  1Þ þ Kyy ði; jÞ Kyy ði; j  1Þ

(3.36)

3.3.3 Transmissibility’s matrices One may note that the left-hand side permeability corresponds to that at the face centers while those at the left-hand side are those at cell centers.

Chapter 3 Spatial numerical discretization methods

Moreover, the transmissibility’s matrices can be defined as follows:

Dxx ði; jÞ ¼

8 > > > > >
> > 2ðiÞ > > : Kxxði; jÞ

is1; m þ 1 and j ¼ 1; n

i ¼ 1; m þ 1 and j ¼ 1; n (3.37)

and

Dyy ði; jÞ ¼

8 > > > > > < > > > > > :

2 DyðiÞ Dyðj  1Þ ði; j  1Þ þ Kyy ði; jÞ Kyy 2ðjÞ Kyyði; jÞ

js1; n þ 1 and i ¼ 1; m

j ¼ 1; n þ 1 and i ¼ 1; m (3.38)

where Dxx ˛Rðmþ1Þnðmþ1Þn and Dyy ˛Rmðnþ1Þmðnþ1Þ are diagonal and square matrices. Now, let us define the segments length in x and y-directions, dx ˛Rm and dy  ˛Rn , respectively, such that dx ðiÞ ¼ xði þ 1Þ  xðiÞ;

(3.39)

dy  ðjÞ ¼ yðj þ 1Þ  yð jÞ

(3.40)

Then repeating dx n-times and dy T m-times, one gets   dx ¼ repeatfdx ; ng; dy  ¼ repeat dy T ; m (3.41) such that dx ; dy  ˛Rmn . After that, we can perform element wise division of dx by kxx ði; jÞ and reshape the result matrix  . Similarly, perform element wise division into a column vector, kxx  of dy by kyy ði; jÞ and reshape the result matrix into a column vec . Therefore, we can construct the two column vectors, tor, kyy   , and then, D and ðA S þA N Þkyy ðA W þA E Þkxx xx and Dyy , respectively.

85

86

Chapter 3 Spatial numerical discretization methods

Definition: repeat is a MATLAB function constructs matrix of dimension m  n by repeating the m  1 vector n times.

Code 3.5.

MATLAB Code for the transmissibility matrices

difxx = (ones(nx+1,1) * hys') .* 2 ./ [0 + ... (hxs(1)*ones(1,ny))./difXX(1 ,:); ... (hxs(1:end-1)*ones(1,ny))./permXX(1:end-1,:) + ... (hxs(2:end)*ones(1,ny))./permXX(2:end,:); ... (hxs(end)*ones(1,ny))./permXX(end,:) + 0 ]; difyy = (hxs * ones(1, ny+1)) .* 2 ./ [0 + ... (ones(nx,1)*hys(1))./difYY(:,1), ... (ones(nx,1)*hys(1:end-1)')./permYY(: ,1:end-1) + ... (ones(nx,1)*hys(2:end)')./permYY(: ,2:end), ... (ones(nx,1)*hys(end)')./permYY(: ,end) + 0 ];

3.3.4 Difference equations Furthermore, the differences of the unknown pressure in x-direction, Dx p, and y-direction, Dy p, with incorporating the conditions may be written, respectively, as Dx p ¼ ½ðA W  A E Þp  BW pBW þ BE pBE ½ðmþ1Þn1

Dy p ¼ ðA S  A N Þp þ BN pBN  BS pBS ½ðmþ1Þn1

(3.41)

where pBW ; pBE ; pBS and pBS are the given pressures at the west, east, south, and north boundaries, respectively. It is noteworthy that the vectors pBW ; pBE are of the dimension ðn þ1Þ  1; however, the vectors pBS ; pBN are of the dimension ðm þ1Þ  1. Similarly, we can write the difference equations in x and y-directions of the unknown velocity, Dx ux and Dy uy respectively, as

T Dx ux ¼ ðA E  A W Þ ux ½mn1 (3.42)

T Dy uy ¼ ðA N  A S Þ uy ½mn1 Using the above shown adjacency matrices technique to write the CCFD approximation of the Darcy’s law,

Chapter 3 Spatial numerical discretization methods





ðAW  A E ÞT Dxx ðAW  A E Þ p þ ðAS  A N ÞT Dyy ðAS  AN Þ p ¼ q  ½ðAW  

AE ÞT Dxx ðBW pBW  BE pBE Þ p  ðAS  AN ÞT Dyy BN pBN  BS pBS p (3.43)

where Dxx ¼ diag

Dxx dx



and Dyy ¼ diag

Dyy dy

. The right-hand

side of the above equation consists of two symmetric and positive definite matrices, namely, A ¼ A x þ A y ,

T A x ¼ ðA W  A E Þ Dxx ðA W  A E Þ mnmn (3.44)

T A y ¼ ðA S  A N Þ Dyy ðA S  A N Þ mnmn Note the matrices A x ; A y and A are of dimension mn  mn. The above system of equation can easily be solved in MATLAB using any of the available solvers. For the general case where both Neumann and Dirichlet boundary conditions exist, the above system needs to be modified to include the known velocity at the boundary. On comparing the CPU time when modeling this problem using the conventional looping method and shifting matrices technique, one finds that the latter significantly reduces the execution time for the same grid.

3.3.5 MATLAB codes of the diffusion and advection terms The spatial discretization of the partial differential equations that govern the transport of nanoparticles in porous media with single/two/three phase flow mainly takes the form of diffusion or advection terms. For example, the pressure term in Darcy’s equation takes the form of a diffusion term. Therefore, it is useful to present two MATLAB functions for advection and diffusion terms using the CCFD shifting technique. Then we can call them when required.

87

88

Chapter 3 Spatial numerical discretization methods

MATLAB Function of Diffusion MATLAB Function of Diffusion: This function employs the cell-centered finite difference method (CCFD) on a nonuniform rectangular 2D mesh for the following diffusion problem. Input: por(x_n,y_n): porosity at cell centers Diff_x(x_n,y_n):x-component of the diffusion coefficient at cell centers Diff_y(x_n,y_n): y-component of the diffusion coefficient at cell centers C_W(y_n): concentration on the west boundary C_E(y_n): concentration on the east boundary C_S(x_n): concentration on the south boundary C_N(x_n): concentration on the north boundary v_W(y_n): x-component of the diffusive flux on the west boundary v_E(y_n): x-component of the diffusive flux on the east boundary v_S(x_n): y-component of the diffusive flux on the south boundary v_N(x_n): y-component of the diffusive flux on the north boundary C_init(x_n,y_n): initial concentration at cell centers x(x_n+1): coordinates of x-discretization (points) y(y_n+1): coordinates of y-discretization (points) T_tot: final simulation time (assuming t0=0) NTS: number of total time steps Output: M_mat(x_n*y_n, x_n*y_n): the mass matrix A_mat(x_n*y_n, x_n*y_n): the advection matrix RHS(x_n*y_n): the right-hand-side vector b C(x_n, y_n): computed C solution at T_tot function [M_mat, A_mat, RHS, C, Flx_x, Flx_y,PARS] = Diffusion(por, Diff_x, Diff_y, C_W, C_E, C_S, C_N, v_W, v_E, v_S, v_N, C_init, x, y, T_tot, NTS) % pre-processing data: x_h = x(2:end) - x(1:end-1); y_h = y(2:end) - y(1:end-1); Diff_xBar = (ones(x_n+1,1) * y_h') .* 2 ./ [ 0 + (x_h(1)*ones(1,y_n))./Diff_x(1,:); ... (x_h(1:end-1)*ones(1,y_n))./Diff_x(1:end-1,:) + (x_h(2:end)*ones(1,y_n))./Diff_x(2:end,:); ... (x_h(end)*ones(1,y_n))./Diff_x(end,:) + 0 ];

Diff_yBar = (x_h * ones(1, y_n+1)) .* 2 ./ [ 0 + (ones(x_n,1)*y_h(1))./Diff_y(:,1), ... (ones(x_n,1)*y_h(1:end-1)')./Diff_y(:,1:end-1) + (ones(x_n,1)*y_h(2:end)')./Diff_y(:,2:end), ... (ones(x_n,1)*y_h(end)')./Diff_y(:,end) + 0 ];

Chapter 3 Spatial numerical discretization methods

porBar = por .* (x_h * y_h'); % Treatment of boundary types: v_W = 0; v_E = 0; v_S = 0; v_N = 0; % assuming Neumman BCs: Diff_xBar = 0; Diff_xBar = 0; Diff_yBar = 0; Diff_yBar = 0; % % construct adjacency matrices of face-cell: ad_W_unit = { [sparse(1, x_n); speye(x_n, x_n)] }; ad_W = blkdiag( ad_W_unit{ones(y_n, 1)} ); ad_E_unit = { [speye(x_n, x_n); sparse(1, x_n)] }; ad_E = blkdiag( ad_E_unit{ones(y_n, 1)} ); ad_S = [sparse(x_n, x_n*y_n); speye(x_n*y_n, x_n*y_n)]; ad_N = [speye(x_n*y_n, x_n*y_n); sparse(x_n, x_n*y_n)]; ad_BW_unit = { [1; sparse(x_n, 1)] }; ad_BW = blkdiag( ad_BW_unit{ones(y_n, 1)} ); ad_BE_unit = { [sparse(x_n, 1); 1] }; ad_BE = blkdiag( ad_BE_unit{ones(y_n, 1)} ); ad_BS = [speye(x_n, x_n); sparse(x_n*y_n, x_n)]; ad_BN = [sparse(x_n*y_n, x_n); speye(x_n, x_n)]; % % compute A_mat and RHS A_mat = (ad_W - ad_E)' * diag(sparse(Diff_xBar(:))) * (ad_W - ad_E) ... + (ad_S - ad_N)' * diag(sparse(Diff_yBar(:))) * (ad_S - ad_N) ; RHS = -(ad_W - ad_E)' * ( Diff_xBar(:).*( ad_BW*C_W - ad_BE*C_E ) ... + ad_BW*(v_W.*y_h) + ad_BE*(v_E.*y_h) ) ... - (ad_S - ad_N)' * ( Diff_yBar(:).*( ad_BS*C_S - ad_BN*C_N ) ... + ad_BS*(v_S.*x_h) + ad_BN*(v_N.*x_h) ) ; C = A_mat\RHS; % compute M_mat: M_mat = diag( sparse(porBar(:)) ); % Backward Euler method: % M*dc/dt + A*c = b C = C_init(:); if NTS>0 ht = T_tot / NTS;

89

90

Chapter 3 Spatial numerical discretization methods

for iT=1:NTS % (M + A*dt)*c_(k+1) = M*c_k + b*dt: C = (M_mat + A_mat*ht) \ (M_mat*C + RHS*ht); end end % post-processing: computer diffusive flux (velocity): PARS.Diff_xBar = Diff_xBar; PARS.ad_W = ad_W; PARS.ad_E = ad_E; PARS.ad_BW = ad_BW; PARS.C_W = C_W; PARS.ad_BE = ad_BE; PARS.C_E = C_E; PARS.v_W = v_W; PARS.v_E = v_E; PARS.x_h = x_h; PARS.y_h = y_h; PARS.Diff_yBar = Diff_yBar; PARS.ad_S = ad_S; PARS.ad_N = ad_N; PARS.ad_BS = ad_BS; PARS.C_S = C_S; PARS.ad_BN = ad_BN; PARS.C_N = C_N; PARS.v_S = v_S; PARS.v_N = v_N;

if exist('Diff_xBar', 'var') % for method 2 only! Flx_x = Diff_xBar(:).*( (ad_W - ad_E)*C + ad_BW*C_W - ad_BE*C_E ) ... + ad_BW*(v_W.*y_h) + ad_BE*(v_E.*y_h); Flx_x = reshape(Flx_x, [x_n+1, y_n]); Flx_x = Flx_x ./ (ones(x_n+1,1) * y_h'); % convert back to flux per unit face area Flx_y = Diff_yBar(:).*( (ad_S - ad_N)*C + ad_BS*C_S - ad_BN*C_N ) ... + ad_BS*(v_S.*x_h) + ad_BN*(v_N.*x_h); Flx_y = reshape(Flx_y, [x_n, y_n+1]); Flx_y = Flx_y ./ (x_h * ones(1, y_n+1)); % convert back to flux per unit face area else Flx_x = {}; Flx_y = {}; end C = reshape(C, [x_n, y_n]);

end

% convert back to 2D C

Chapter 3 Spatial numerical discretization methods

MATLAB Function of Advection MATLAB Function of Advection: This function employs the cell-centered finite difference method on a nonuniform rectangular 2D mesh for the following advection PDE problem: d(por*c)/dt + div( vel*c ) = src Input: por(nx,ny): porosity at cell centers velx(nx+1,ny): x-component of the velocity at x-face centers vely(nx,ny+1): y-component of the velocity at y-face centers c_W(ny): concentration on the west boundary c_E(ny): concentration on the east boundary c_S(nx): concentration on the south boundary c_N(nx): concentration on the north boundary c_i(nx,ny): initial concentration at cell centers x(nx+1): coordinates of x-discretization (points) y(ny+1): coordinates of y-discretization (points) T_tot: final simulation time (assuming t0=0) NTS: number of total time steps Output: M_mat(nx*ny, nx*ny): the mass matrix A_mat(nx*ny, nx*ny): the advection matrix RHS(nx*ny): the right-hand-side vector b conc(nx, ny): computed conc solution at T_tot function [M_mat, A_mat, RHS, conc] = Advection(por, velx, vely, c_W, c_E, c_S, c_N, c_i, x, y, T_tot, NTS) % pre-processing data: nx = length(x)-1; ny = length(y)-1; x_h = x(2:end) - x(1:end-1); y_h = y(2:end) - y(1:end-1); velxB = velx .* (ones(nx+1,1) * y_h'); velyB = vely .* (x_h * ones(1, ny+1)); porBar = por .* (x_h * y_h'); % construct adjacency matrices of face-cell: ad_W_unit = { [sparse(1, nx); speye(nx, nx)] }; ad_W = blkdiag( ad_W_unit{ones(ny, 1)} ); ad_E_unit = { [speye(nx, nx); sparse(1, nx)] }; ad_E = blkdiag( ad_E_unit{ones(ny, 1)} ); ad_S = [sparse(nx, nx*ny); speye(nx*ny, nx*ny)]; ad_N = [speye(nx*ny, nx*ny); sparse(nx, nx*ny)]; ad_BW_unit = { [1; sparse(nx, 1)] }; ad_BW = blkdiag( ad_BW_unit{ones(ny, 1)} ); ad_BE_unit = { [sparse(nx, 1); 1] }; ad_BE = blkdiag( ad_BE_unit{ones(ny, 1)} ); ad_BS = [speye(nx, nx); sparse(nx*ny, nx)]; ad_BN = [sparse(nx*ny, nx); speye(nx, nx)];

91

92

Chapter 3 Spatial numerical discretization methods

% compute A_mat and RHS vxPlus = max(0, sparse(velxB(:))); vxMinus = min(0, sparse(velxB(:))); vyPlus = max(0, sparse(velyB(:))); vyMinus = min(0, sparse(velyB(:))); A_mat = (ad_W - ad_E)' * ( diag(vxPlus)*ad_W + diag(vxMinus)*ad_E ) ... + (ad_S - ad_N)' * ( diag(vyPlus)*ad_S + diag(vyMinus)*ad_N ); RHS = -(ad_W - ad_E)' * ( vxPlus.*(ad_BW*c_W) + vxMinus.*(ad_BE*c_E) ) ... - (ad_S - ad_N)' * ( vyPlus.*(ad_BS*c_S) + vyMinus.*(ad_BN*c_N) ); % compute M_mat and M_mat_inv: M_mat = diag( sparse(porBar(:)) ); M_mat_inv = diag( sparse(1 ./ porBar(:)) ); % Forward Euler method: % M*dc/dt + A*c = b conc = c_i(:); if NTS>0 ht = T_tot / NTS; for iT=1:NTS conc = conc + M_mat_inv * (RHS - A_mat * conc) * ht; end end conc = reshape(conc, [nx, ny]);

% convert back to 2D conc

end

3.4 Finite element method Finite element methods (FEMs) are powerful numerical methods for resolving complex engineering problems. FEMs first arose in the mid-nineteenth century and were widely employed in solid mechanics [3]. The FEM has been studied and refined extensively over the previous 5 decades [4], and it is presently employed to solve highly nonlinear situations [5]. Consider incompressible nongravitational single-phase flow in a polygonal/polyhedral Lipschitz domain U 3 Rd ; d ˛ f2; 3g, on which we define the standard L2 ðUÞ space such that  d L2 ðUÞh L2 ðUÞ . The governing PDEs can be written as K 1 u ¼ Vp V,u ¼ q p ¼ pB

in U in U on vU

(3.45)

Chapter 3 Spatial numerical discretization methods

where u is the Darcy velocity. p is the pressure. K is the hydraulic conductivity tensor defined by, K ¼ k=m, such that k is the permeability and m is the fluid viscosity. q is the source term. pB is the pressure on the boundary vU, while U is the domain of the solution. We may note that UWvU ¼ U, where U is the closure of U. Remark: The permeability K is moved to the left-hand side to avoid discontinuity when we integrate Vp by parts.

3.4.1 Finite elements discretization Representing of the unknown scalar fields in terms of sums of finite element basis functions is called weighted residual formulation. We need to use different basis functions for the velocity components and the pressure. The continuous vector field u can be approximated to the discretized vector field uh , i.e., u z uh and the continuous scalar field p can be approximated to the discretized scalar field ph , i.e., p z ph ; thus, uh ¼

d X m X

ukj nk Nj

(3.46)

k¼1 j¼1

ph ¼

n X

pkj Lj

(3.47)

j¼1

where n o

ukj ¼ u11 ; u12 ; /; u1m ; u21 ; u22 ; /; u2m ; /; ud1 ; ud2 ; /; udm

(3.48)

is the unknown vector consisting of the velocity values. And  k

p ¼ p1 ; p2 ; /; pn (3.49) is the unknown vector consisting of the pressure values. The Nj is the j th basis functions for the velocity and Lj is the j th basis func  tions for the pressure. The nd are the unit vectors in Cartesian coordinates in d dimensions. A Galerkin approach consists of using Nj as weighting functions for Eq. 3.45 and Lj as weighting functions for Eq. (3.47). Therefore, we generate d  m þ n equations for the d  m þ n unknowns in d space dimensions. The pressure

93

94

Chapter 3 Spatial numerical discretization methods

gradient term in Eq. (3.45) is integrated by parts, resulting in the following system of discrete equations m X

Aij ukj þ

j¼1

n X

Bijk pj ¼ 0; i ¼ ; 1; 2; /; m; k ¼ 1; 2; /; d

(3.50)

j¼1 d X m X

Bjik ukj ¼ qi ; i ¼ ; 1; 2; /; n

(3.51)

k¼1 j¼1

uh ¼

where

j¼1

ukj Nj ,

ph ¼

n P j¼1

pj L j ,

Aij ¼

R U

Ni Nj dU,

R vNi dU, and qi ¼ U qLi dU. vxk Now, we can write the above formulation Eqs. (3.50) and (3.51) in the following matrix equation form " #" # " # f uh A BT ¼ (3.52) q ph B 0 Bijk ¼ 

R

m P

U

The matrix A is m  m, while the matrix B is n  m. If we multiply the first equation of system Eq. (3.52) by A1 , we may find uh ¼ A1 f  A1 BT ph

(3.53)

Then substituting from Eq. (3.53) into Eq. (3.52) results in BA1 BT ph ¼ q  BA1 f

(3.54)

Note that the BA1 BT is called the pressure Schur complement. Remarks. 1. Because B is n  m matrix, the pressure Schur complement BA1 BT is " # A BT not invertible; consequently, the matrix, M ¼ is not B 0 invertible. 2. If the velocity and the pressure are approximated with the same type of elements, then the pressure is singular that may result in pressure oscillations. 3. The invertible matrix M is ensured by the following BabuskaeBrezzi conditions. a. The matrix A is sufficiently invertible, i.e., uh AuTh > 0; cuh ˛ KerðBÞ. b. The pressure Schur complement BA1 BT   Ker BT ¼ f0g.

is invertible if

Chapter 3 Spatial numerical discretization methods

3.4.2 Weak formulation The following are the weak forms of the above strong form Eq. (3.45)   1 K u; v ¼ CpB ; v,nD þ ðp; V,vÞ cv ˛ L2 ðUÞ  Hðdiv; UÞ ðV,u; wÞ ¼ ðq; wÞ

cw ˛ L2 ðUÞ (3.55)

where the inner product in U is defined as Z ðf ; gÞU ¼ f ðxÞgðxÞdVcf ; g : U / R

(3.56)

U

Note that for d ¼ 1, the inner product becomes simply Z ðf ; gÞU ¼ f ðxÞgðxÞdxcf ; g : U / R (3.57) U

and the inner product on vU is defined as Z Cf ; gDvU ¼ fgdScf ; g : vU / R

(3.58)

vU

Given,

L ðUÞ ¼



Z f : U / R:

2

f dx < þ N 2

U

(3.59)

Seeking the largest possible space to include solution for the weak formulations in Eq. (3.55). L2 ðUÞ is the largest Hilbert space   which includes u and v, i.e., u; v ˛L2 ðUÞ, such that, K1 u; v is well defined. Also, if ðp; V ,vÞ is well defined, then, p; V,v ˛L2 ðUÞ. It is required, p; w ˛L2 ðUÞ and u, v ˛Hðdiv; UÞ. The space Hðdiv; UÞ is composed of those functions u for which it holds u ˛L2 ðUÞ and V,u ˛L2 ðUÞ, i.e., u ˛Hðdiv; UÞ where   Hðdiv; UÞ ¼ f ˛ L2 ðUÞ: V , f ˛ L2 ðUÞ (3.60) which is a Hilbert space with norm given by 2

k fkHðdiv;UÞ ¼ k fk2 þ k V,fk2

(3.61)

which means that not only the function v needs to be squareintegrable but also its divergence V,v must hold square integrability over U. In case of scalar function, we choose to be in the space L2 ðUÞ. Similarly, if v ˛L2 ðUÞ and V,v ˛L2 ðUÞ hold, we have

95

96

Chapter 3 Spatial numerical discretization methods

v ˛Hðdiv; UÞ. In the context of mixed finite element, Hðdiv; UÞ is the typical finite element space. Therefore, the seeking solution is ðp; uÞ ˛ L2 ðUÞ  Hðdiv; UÞ

(3.62)

such that p and u are smooth. For numerical discretization, we define the two discretized spaces Wh 3 L2 ðUÞ; dimðWh Þ < þ N

(3.63)

Vh 3 Hðdiv; UÞ; dimðVh Þ < þ N

(3.64)

and The condition Vh 3Hðdiv; UÞ translates into a continuity condition over the interelement boundaries E ˛Eh of the mesh K h . In other words, one requires that the normal component u,n is continuous across the interelement boundaries. We seek the velocity uh ˛Vh and the pressure ph ˛Wh .

3.4.3 RaviarteThomas ðRT0 Þ space The RT0 elements are designed to approximate Hðdiv; UÞ. We consider the RT0 space for which   (3.65) Wh ¼ w ˛ L2 ðUÞ: wjE ˛ P0 ðEÞ; E ˛ Eh and

  Vh ¼ v ˛ Hðdiv; UÞ: vjE ˛ P1 ðEÞ; E ˛ Eh

(3.66)

where w is discontinuous piecewise constant and v is piecewise linear. For d ¼ 2, one may write ! a1 x þ b1 (3.67) vjE ðx; yÞ ¼ ; a1 ; b1 ; a2 ; b2 ˛R a2 y þ b2 Moreover, for d ¼ 3, we can write, 1 0 a1 x þ b1 C B C vjE ðx; y; zÞ ¼ B @ a2 y þ b2 A; a1 ; b1 ; a2 ; b2 ; a3 ; b3 ˛R a3 z þ b3

(3.68)

Chapter 3 Spatial numerical discretization methods

They are continuous only in the normal direction across the elements boundaries such that ( 1 if i ¼ j (3.69) vjE , n ¼ 0 if isj   where vjE ¼ fvi g is the basis functions and n ¼ nj is the normal vectors associated with the side i and j, respectively. One can obtain the solution   ph ; uh ˛ Wh  Vh (3.70) by solving the following discretized weak formulations that corresponding to the weak formulations in Eq. (3.55),     1 (3.71) K uh ; v U ¼  CpB ; v,nDvU þ ph ; V,v U; cv ˛Vh ðV,uh ; wÞU ¼ ðq; wÞU cw ˛Wh

(3.72)

The solution requires: • Solvable uniquely. • Convergence: k uh  u k is small. • CPU efficiency.

3.5 Mixed finite element method When addressing an elliptic problem that characterizes flow in porous media, the typical FEM encountered several instabilities [6,7]. On the other hand, mixed finite element methods (MFEMs) have successfully removed these kinds of instabilities [8e12] because they may be expanded to higher-order approximations and are locally stable. The scalar and its flux are the two main variables in the parabolic system, and each of these variables belongs to a particular finite element space. The mixed method is then used to estimate both variables simultaneously, resulting in a higher-order approximation of both. The compatibility requirement is an essential condition that must exist for the two finite element spaces. The mixed method is guaranteed to be stable due to the compatibility of the two spaces. It extends the concept of consistency and convergence by adding additional restrictions to the numerical discretization [6,8,9]. Suppose that U3Rd ðd ¼ 2; 3Þ is a polygonal and bounded domain. The traditional notations are used for the Lebesgue spaces Lp ðUÞ and Sobolev spaces W k;p ðUÞ with 1  p  N over

97

98

Chapter 3 Spatial numerical discretization methods

the domain U. In particular, W k;2 ðUÞ is denoted by H k ðUÞ. The corresponding norms are denoted by k ,kLp ðUÞ ; k ,kW k;p ðUÞ and k ,kH k ðUÞ respectively. For simplicity, we also denote k ,kLp ðUÞ by k , k . The inner product of Lp ðUÞ or ðLp ðUÞÞd is denoted by ð ,; ,Þ. We also use j,j to represent the two-norm of a vector in Rd and a matrix in Rdd . The norms for a vectorvalue function v ˛ðLp ðUÞÞd and a matrix-value function A ˛ðLp ðUÞÞdd are defined as k v kðLp ðUÞÞd : ¼ k jvj kLp ðUÞ ; k A kðLp ðUÞÞdd : ¼ k jAj kLp ðUÞ

(3.73)

For notation simplicity, the norms k , kL2 ðUÞ ; k , k k,k

d and ðL2 ðUÞÞ are also written as k , k for scalar-value, vector-

ðL2 ðUÞÞ value, and matrix-value functions, respectively. Let T be the final simulation time. For a given normed space X and 1  p  N, we define dd

Lp ð0; T ; X Þ: ¼ f4: 4ðtÞ ˛ X ; k 4 kX ˛ Lp ð0; T Þg

(3.74)

which is a normed linear space equipped with the norm given as k 4kLp ð0;T ;X Þ : ¼ k ðk 4 kX Þ kLp ð0;T Þ

(3.75)

3.5.1 Mixed weak formulation Define two functional spaces as o n d  V ¼ v ˛ L2 ðUÞ : V , v ˛ L2 ðUÞ

(3.76)

and V0 ¼ fv ˛ V : v , n ¼ 0 on vUg Furthermore, we define other functional spaces as, o n d  Hðdiv; UÞ ¼ v ˛ L2 ðUÞ : V , v ˛ L2 ðUÞ

(3.77)

(3.78)

and H0 ðdiv; UÞ ¼ fv ˛ Hðdiv; UÞ: v , n ¼ 0 on vUg

(3.79)

In order to apply MFEM, we define an auxiliary flux variable q as q ¼ uc  DðuÞVc

(3.80)

Chapter 3 Spatial numerical discretization methods

The mixed weak form describing wormhole problem is formulated as shown below ðV , u; 4Þ ¼ 0; 4˛L2 ðUÞ  1  K u; v ¼ ðp; V , vÞ; v˛V0

(3.81) (3.82)

vð4cÞ ; j þ ðV , q; jÞ ¼ ðRðu; cÞ þ Qc ; jÞ; j˛L2 ðUÞ (3.83) vt     1 1 DðuÞ q; w ¼ DðuÞ uc; w þ ðc; V , wÞ; w˛H0 (3.84) 8 < ðgd jujc; jÞ; u  ur ; vcs1 ;j ¼ : ðg jujc  g ju  u jc ; jÞ; u > u ; j˛L2 ðUÞ vt

d

vcs2 ;j vt



e

r

s1

r

  ¼ gpt jujc; j ; u > ur ; j˛L2 ðUÞ (3.85)

In the above equations, gd is the rate coefficient for surface retention of the nanoparticles, ge is the rate coefficient for entrainment of the nanoparticles, ur is the critical velocity of the water phase, and gpt is the pore throat blocking constants.

3.5.2 Mixed finite element approximation We use a partition Eh of the domain U, which is composed of triangles or quadrilaterals if d ¼ 2, or tetrahedra, prisms or hexahedra if d ¼ 3. Denote by hE the diameter of E ˛Eh and let h ¼ max E˛Eh hE such that h=hE  C. We assume that Eh is nondegenerate; that is, each element is convex, and that there exists r > 0 such that each of the subtriangles (for d ¼ 2) or subtetrahedra (for d ¼ 3 ) of element E contains a ball of radius rhE in its interior. Let the approximating subspaces X 3V ; X0 3V0 ; Y 3H ðdiv; UÞ; Y0 3H0 ðdiv; UÞ and W 3L2 ðUÞ be the r-th order ðr  0Þ RaviarteThomas space ðRTr Þ on the partition Eh . Denote J ¼ ð0; T , where T > 0. The mixed finite element formulation is stated as shown below: find ph ð,; tÞ; ch ð,; tÞ ˛W and uh ð,; tÞ ˛X0 ; qh ð,; tÞ ˛Y0 ðt ˛JÞ such that ðV , uh ; 4Þ ¼ 0; 4 ˛W ;  1    K uh ; v ¼ ph ; V , v ; v ˛X0 ;

(3.86) (3.87)

99

100

Chapter 3 Spatial numerical discretization methods

  vð4ch Þ ; j þ V , qh ; j ¼ ðRðuh ; ch Þ þ Qc ; jÞ; j ˛W ; (3.88) vt     1 1 Dðuh Þ qh ; w ¼ Dðuh Þ uh ch ; w þ ðch ; V , wÞ; w ˛Yn ; (3.89) 8 ðgd juh jch ; jÞ; uh  ur ; > > > > < vcs1;h ðgd juh jch  ge juh  ur jcs1;h ; jÞ; uh > ur ; j ˛W ; ;j ¼ > vt > vcs2;h   > > ; j ¼ gpt juh jch ; j ; uw > ur ; j ˛W : : vt (3.90)

3.5.3 Numerical algorithm To provide an explicit flux, MFE approximations with a quadrature rule were used. Consider n þ 1 as the current time and n is the previous one, and the total time-interval is [0,T]. Dt n ¼ t nþ1  t n is used to discretize the time derivative with a number of N T time-steps. The discretized MFEM equations are written as ðV , uh ; 4Þ ¼ 0; 4˛W ; (3.91)    nþ1 K 1 unþ1 (3.92) h ; v ¼ ph ; V , v ; v˛X0 ; nþ1       c  chn n nþ1 ; j þ V , qhnþ1 ; j ¼ R unþ1 4 h h ; ch þ Qh ; j ; j˛W ; Dt (3.93)   nþ1  nþ1  ! ( gd uh ch ; j ; unþ1  ur ; nþ1 n h cs1;h  cs1;h   ;j ¼  nþ1  nþ1  nþ1  n Dt  ge u  ur c ; j ; unþ1 > ur ; j˛W ; gd u c 

h

h

h

s1;h

h

(3.94) nþ1 cs2;h

 Dt

n cs2;h

! ;j

 nþ1  nþ1   c ; j ; u > ur ; j˛W . ¼ gpt unþ1 h h h

(3.95)

n n , the following scheme can be Give pnh ; unh ; chn ; cs1;h and cs2;h executed to obtain pressures, velocities, and concentrations based on the steps: 1. Calculate all physical functions explicitly. 2. Find pnþ1 and unþ1 by solving Eqs. (3.91) and (3.92). h h nþ1 3. Find ch by solving Eq. (3.93). nþ1 4. Find cs1;h by solving Eq. (3.94). nþ1 5. Find cs2;h by solving Eq. (3.95).

Chapter 3 Spatial numerical discretization methods

The CCFD approach has been used for spatial discretization to solve flow in porous media problems. In the case of rectangular elements, the CCFD method is locally conservative. Arbogast et al. [1] proved that the CCFD method is a particular case of the mixed finite element approach.

3.5.4 Numerical test To evaluate the scheme’s performance, we present a numerical example. Table 3.1 contains the values and units of the physical parameters that are employed in the calculations. A heterogeneous permeability field has been as shown in Fig. 3.6. The field contains three barriers with lower permeability than other locations on the map. Figs. 3.7e3.9 show, respectively, the distribution of pressure, nanoparticles concentration, and nanoparticles deposition. It can be seen from these figures that the distribution of different physics, including pressure, nanoparticles concentration, and deposited nanoparticles concentration, is affected by the permeability distribution. Also, the MFE solutions look smooth though the significant discrepancy in the permeability. Also, the second example presents a piece of permeability of a real oil reservoir with high heterogeneity (Fig. 3.9).

Table 3.1 Values of the physical parameters.

Parameter

Value

Units

gd gpt ge ur c0 D m pw

16 1.28 30 4.6E6 0.1 5E8 1 50

m1 m1 m1 m s1 e m2 s1 cP ¼ 1E3 Pa s bar ¼ 1E5 Pa

101

102

Chapter 3 Spatial numerical discretization methods

Figure 3.6 Permeability map.

Figure 3.7 Pressure contours.

Chapter 3 Spatial numerical discretization methods

Figure 3.8 Nanoparticles concentration contours.

Figure 3.9 Deposited nanoparticles concentration on pore surface contours.

103

104

Chapter 3 Spatial numerical discretization methods

References [1] T. Arbogast, C.N. Dawson, P.T. Keenan, M.F. Wheeler, I. Yotov, Enhanced cell-centered finite differences for elliptic equations on general geometry, SIAM J. Sci. Comp. 19 (1998) 404e425. [2] S. Sun, A. Salama, M.F. El-Amin, Matrix-oriented implementation for the numerical solution of the partial differential equations governing flows and transport in porous media, Comput. Fluids 68 (2012) 38e46. [3] O.C. Zienkiewicz, R.L. Taylor, The Finite Element Method fifth ed., vol. 1, The basis, Butterworth Heinemann, Oxford, 2000. [4] K.J. Bathe, Finite Element Procedures, Prentice Hall, Englewood Cliffs, NJ, 1996. [5] O.C. Zienkiewicz, R.L. Taylor, The Finite Element Method fifth ed., vol. 3, fluid dynamics, Butterworth Heinemann, Oxford, 2000. [6] F. Brezzi, V. Fortin, Mixed and Hybrid Finite Element Methods, SpringerVerlag, New York, 1991. [7] Z. Chen, Finite Element Methods and Their Applications, Ch. 3, SpringerVerlag Berlin and Heidelberg GmbH and Co. KG, 2010. [8] F. Brezzi, J. Douglas, L.D. Marini, Two families of mixed finite elements for second order elliptic problems, Numer. Math. 47 (1985) 217e235. [9] P.A. Raviart, J.M. Thomas, A mixed finite element method for 2nd order elliptic problems. Mathematical aspects of finite element methods, in: Proc. Conf., Consiglio Naz. Delle Ricerche (C.N.R.), Rome, 1975, Lect. Notes Math vol 606, Springer, Berlin, 1977, pp. 292e315. [10] M.F. El-Amin, J. Kou, S. Sun, Mixed finite element simulation with stability analysis for gas transport in low-permeability reservoirs, Energies 111 (2018) 208e226. [11] M.F. El-Amin, J. Kou, S. Sun, Theoretical stability analysis of mixed finite element model of shale-gas flow with geomechanical effect, Oil Gas Sci. Technol. Rev. IFP Energies Nouvelles 75 (2020) 33 (2020). [12] M.F. El-Amin, J. Kou, S. Sun, A. Salama, Adaptive time-splitting scheme for two-phase flow in heterogeneous porous media, Adv. Geo-Energy Res 1 (2017) 182e189.

4 Temporal numerical discretization schemes 4.1 Introduction The nanoparticles transport in porous media is governed by a set of time-dependent partial differential equations, including saturation, nanoparticles concentration, deposited nanoparticles concentration on the pore walls, and entrapped nanoparticles concentration in pore throats. The time-dependent term in each equation could be a source of instabilities or divergence. Therefore, the discretization of the time derivative term is a crucial aspect. The convergence test has been examined against the CouranteFriedrichseLewy (CFL) condition and a relaxation factor. The instability and divergence of numerical solutions are not solely caused by time-dependent terms, but also by other terms like the advection term, which demands specific handling, such as the upwind scheme. In the problem of the two-phase flow in porous media, the Implicit Pressure Explicit Saturation (IMPES) scheme is one of the most popular efficient methods. Also, the Implicit Pressure Explicit Saturation Implicit Concentration (IMPES-IMC) has been developed by the author to solve the model of nanoparticles transport in porous media for the twophase case. Also, the Implicit Pressure Implicit Concentration (IMP-IMC) scheme has been devoted to solving the problem of nanoparticles transport with single-phase flow in porous media. In addition, as the model consists of coupled equations for different physics, namely, pressure, saturation, and concentrations, the selected time-step size for each one might be different to reach accurate solutions. Therefore, multiscale time-splitting and time-stepping techniques may be used. There are two primary time discretization strategies that are frequently used to solve the model of two-phase fluid flow in porous media, namely, the fully implicit scheme [1e3], and the IMplicit-EXplicit (IMEX) [4,5]. The implicit scheme is unconditionally stable and retains the two-phase flow model’s inherent coupling. Although the IMEX technique is conditionally stable, it Numerical Modeling of Nanoparticle Transport in Porous Media. https://doi.org/10.1016/B978-0-323-90511-4.00011-3 Copyright © 2023 Elsevier Inc. All rights reserved.

105

106

Chapter 4 Temporal numerical discretization schemes

has the advantage of lowering the original equations’ nonlinearity. In the more specific IMEX method applied to this field, the IMPES approach solves the pressure equation implicitly and explicitly updates the saturation. As the IMPES method is conditionally stable, it must take a tiny step, especially for highly heterogeneous porous media. Several versions of the IMPES approach have been developed (e.g., Refs. [6e8]). To combine the implicit saturation equation with the pressure equation, Kou and Sun [9] presented a linear approximation of capillary pressure in terms of saturation. To solve the model of nanoparticles transport in porous media, the IMP-IMC and IMPES-IMC methods were proposed by El-Amin et al. [10e12]. The IMP-IMC scheme is dedicated to solving the problem of nanoparticle transport in porous media with single-phase flow, whereas the IMPES-IMC system is for twophase flow.

4.2 Forward and backward uler difference schemes Let us assume that T is finite, and construct a partition of IT into the union of NTs1 subintervals In ¼ ðtn1 ; tn Þ of uniform size of Dt ¼ T =NT such that tn ¼ t0 þ nDt; n ¼ 0; 1; .; NT. Set the time interval ½tn , tnþ1 , n ¼ 0; 1; .; NT  1, the forward Euler method is defined as   n n Snþ1 ¼ Sn þ Dt RHS tn ; un ; Sn ; C n ; Cs1 ; (4.1) ; Cs2   n n C nþ1 ¼ C n þ Dt RHS tn ; un ; Sn ; C n ; Cs1 ; (4.2) ; Cs2   nþ1 n n n CS1 ¼ CS1 þ Dt RHS tn ; un ; Sn ; C n ; Cs1 ; Cs2 ; (4.3)   nþ1 n n n ¼ CS2 þ Dt RHS tn ; un ; Sn ; C n ; Cs1 ; Cs2 CS2 . (4.4) The abbreviation RHS refers to the right hand side of the equation. Similarly, there is an alternative technique, called as the backward Euler method, defined as   nþ1 nþ1 ; Cs2 ; (4.5) Snþ1 ¼ Sn þ Dt RHS tnþ1 ; unþ1 ; Snþ1 ; C nþ1 ; Cs1   nþ1 nþ1 ; Cs2 ; (4.6) C nþ1 ¼ C n þ Dt RHS tnþ1 ; unþ1 ; Snþ1 ; C nþ1 ; Cs1   nþ1 n nþ1 nþ1 ; (4.7) ¼ CS1 þ Dt RHS tnþ1 ; unþ1 ; Snþ1 ; C nþ1 ; Cs1 ; Cs2 CS1   nþ1 n nþ1 nþ1 . (4.8) CS2 ¼ CS2 þ Dt RHS tnþ1 ; unþ1 ; Snþ1 ; C nþ1 ; Cs1 ; Cs2

Chapter 4 Temporal numerical discretization schemes

For a positive constant c which is independent of the time-step size Dt, the convergence of the forward and backward Euler methods can be achieved by holding the following error criterion: jErrn j G c Dt; n ¼ 0; .; NT

(4.9)

From the definitions of both the forward and backward Euler methods given above, we can infer that their convergence is of first order concerning Dt. However, the remarkable difference is that the forward Euler method is explicit, while the backward Euler method is implicit and generally nonlinear. Therefore, the computational cost is quite different than that of the backward scheme being significantly larger than that of the forward scheme.

4.3 CouranteFriedrichseLewy stability condition The stability CFL condition is necessary while solving partial differential equations using explicit time schemes. In many explicit time-depending simulations, the time step must be shorter than the specified time; otherwise, the simulation will yield inaccurate results. The CFL conditions in two-dimensional domain are as follows: ux Dt  Cx;max Dx uy Dt  Cy;max CFLy ¼ Dy

CFLx ¼

(4.10)

The typical value of Cmax bound is Cmax ¼ 1. It is very useful to develop an adaptive multistepping based on satisfying the CFL stability condition (CFL < 1 ). For each step, we check if CFLx > 1 or CFLy > 1; the time step of saturation and concentration is divided by two and the CFLx and CFLy is recalculated. This procedure will be repeated until satisfying the condition CFLx < 1 and CFLy < 1; then the final adaptive time step for both saturation and concentration is obtained.

4.4 Multiscale time-splitting scheme In the multiscale time-splitting method, we use a different time-step size for each time derivative term as they have other physics. For example, the time-step size of the pressure can be set larger than that of saturation and nanoparticle concentration. The explicit-stepping CFL condition usually requires a time size

107

108

Chapter 4 Temporal numerical discretization schemes

  of less than O h2 , with h being the spatial mesh size, which is too restrictive for our applications. The pressure domain is used as the first level of time discretization. Thus, we divide the total time interval ½0; T  into Np steps, i.e., 0 ¼ t 0 < t 1 < / < t Np ¼ T and the time-step length is Dt i ¼ t iþ1  t i . We use a smaller time-step size for the saturation because it varies more rapidly than pressure. Thus, we divide each    subinterval t i ; t iþ1 ] into Np;f subsubintervals as t i ; t iþ1 S s 1  i;j i;jþ1  ¼ N t ;t , where t i;0 ¼ t i and t i;Ns ¼ t iþ1 and Dt i;j j¼0 ¼ t i;jþ1  t i;j . Moreover, for concentration, we can go for further  discretization if needed for the time-step t i;j ; t i;jþ1 ] into Nc sub  SNc 1  i;j;k i;j;kþ1  i;j;0 t ;t ;t ¼ t i;j and steps such that t i;j ; t i;jþ1 ¼ k¼0 i;j;N i;jþ1 c ¼ t . t For more complicated physics, such as transport in fractured porous media, we opt for a higher discretization level for fractures than matrix blocks when needed.

4.5 Relaxation factor As explained above, the CFL condition has been developed to guarantee the stability satisfactory (i.e., CFL ur The entrapped nanoparticles concentration in the pore throats vcs2 ¼ gpt jujc vt

(4.15)

As stated in Chapter. 1, the porosity varies as, 4 ¼ 40  d4, such that 40 is the initial porosity and d4 ¼ cs1 þ cs2 . Consequently, the permeability variation is estimated by the following . il h permeabilityeporosity relationship K ¼ K0 ð1  f Þkf þ f 4 40 , where K0 is the initial permeability, kf and l are constants, and the flow efficiency is, f ¼ 1  gf ðcs1 þcs2 Þ, where gf is the coefficient of flow efficiency. All terms and notations that appear in the above system of equations have been presented in the previous chapters. To solve the above governing PDEs numerically, we divide the total time interval ½0; T  into NT time steps of Dt n ¼ t nþ1  t n . As a result, the nanoparticles concentration, deposited nanoparticles concentration on the pore walls, and entrapped nanoparticles concentration in the pore throats are implicitly computed. The permeability, porosity, and other parameters are updated as postprocessing. This procedure is repeated until the convergence criterion of error is satisfied. The simplest error method that can be used is the absolute error. So, the convergence criterion of error may be expressed as

109

110

Chapter 4 Temporal numerical discretization schemes

nþ1 nþ1 ref p pref  εp , cnþ1 c ref  εc , cs1 cs1  εcs1 , and nþ1 ref cs2 cs2  εcs2 , where the superscript ‘ref’ indicates a solution and εp ; εc ; εcs1 ; εcs2 /0. The discretized pressure equation may have the form  n n  nþ1 V , K cs1 ; cs2 Vp ¼ qnþ1

(4.16)

where n þ 1 refers to the current time step, while n refers to the previous one. Therefore, the velocity vector unþ1 can be calculated directly from Darcy’s law. The backward Euler time discretization is utilized in the equation of nanoparticles concentration to obtain  nþ1  n n  cnþ1  cn

 n n Vc 4 cs1 ; cs2 þ V , unþ1 cnþ1  D pnþ1 ; cs1 ; cs2 n  nþ1 nDt n  ¼ R p ; c ; cs1 þ Qcnþ1 (4.17) Similarly, the backward Euler time discretization of the deposited nanoparticles concentration on the pore walls becomes ( nþ1 n unþ1  ur gd unþ1 cnþ1 ; cs1  cs1 ¼ nþ1 Dt n gd unþ1 c nþ1;kþ1  ar ge unþ1  ur cs1 ; unþ1 > ur (4.18) and the backward Euler time discretization of the entrapped nanoparticles concentration in the pore throats nþ1 n cs2  cs2 ¼ gpt unþ1 cnþ1 n Dt

(4.19)

One may notice that the advection terms in the above transport Eqs. (4.17-4.19) are multiplied with the relaxation factor, ar . As the velocity vector u is a function of the pressure p, both permeability K and porosity 4 are also functions of the pressure p; and concentration c; while both D and R are functions of p; cs1 and cs2 . Therefore, K and 4 will be used from the previous iteration step of cs1 and cs2 . Also, D and R are calculated at current iteration step of p, cs1 , and cs2 .

4.7 Implicit pressure explicit saturation implicit concentration scheme Sheldon et al. [13] and Stone and Gardner [14] were the first to create an IMPES approach. The IMPES technique is commonly

Chapter 4 Temporal numerical discretization schemes

utilized in the petroleum sector. The essential idea behind this traditional method for solving a partial differential coupled system for two-phase flow in a porous medium is to separate pressure and saturation computations. The pressure equation is solved implicitly, while the saturation equation is solved explicitly. Therefore, the coupled system is split into a pressure equation and a saturation equation. The IMPES method is efficient and needs smaller computer memory than other methods. However, it requires minimal time steps for saturation to be stable, or in other words, it is conditionally stable. The pressure equation’s implicit calculation takes longer than the saturation equation’s explicit calculation, while the pressure varies less rapidly than the saturation [15]. The IMPES-IMC technique has been developed to solve the problem of nanoparticles transport in a twophase flow. As seen by its name, the IMPES-IMC approach is clearly based on the IMPES. Now, let us briefly bring the model of two-phase flow in a porous medium. The saturation (mass balance) equation for each phase is: 4

vðra sa Þ þ V , ðra ua Þ ¼ ra qa ; a ¼ w; n vt

(4.20)

Darcy’s law (momentum balance equation) is given by: ua ¼ 

kra KVðpa  ra gzÞ; a ¼ w; n ma

(4.21)

The constraint of saturations is: sw þ sn ¼ 1 The capillary pressure function is: pc ðsw Þ ¼ pn  pw The phase mobility is given as: la ðsÞ ¼ Kmra ; a ¼ w; n a The total mobility becomes: lt ðsÞ ¼ lw þ ln The fractional flow is defined by: fa ðsÞ ¼ llat ; a ¼ w; n where w denotes the wetting phase and n indicates the nonwetting phase. 4 is the porosity and K is the permeability of medium. g is the gravitational constant, z is the depth, and the z-coordinate is in the vertical downward direction. ra ; sa ; ua , qa pa ; ma , and kra are, respectively, the density, saturation, velocity, and external volumetric flow rate of the pressure, viscosity, and relative permeability of the a-phase. Let us define the total velocity ut ¼ uw þ un by using Eq. (4.21) along with the algebraic constrains to find   (4.22) ut ¼  K lt ðsÞVp  lw ðsÞVpc  ðlw rw þ ln rn ÞgVz

111

112

Chapter 4 Temporal numerical discretization schemes

Also, if we assume that the two fluids are incompressible (the density is constant), and sum the two mass conservation Eq. (4.20) with keeping the fact, sw þ sn ¼ 1, one gets V , ut ¼ qt ¼ qw þ qn

(4.23)

Substituting from Eq. (4.22) into Eq. (4.23), we obtain the pressure equation as    (4.24) V , ðKlt VpÞ ¼ qt  V, K lw Vpc þ ðlw rw þ ln rn ÞgVz On the other hand, in order to solve the saturation equation, we substitute uw into the wetting-phase saturation equation and obtain  

vsw dpc ¼ qw  V, Kfw ðsÞln ðsÞ Vs þ ðro  rw ÞgVz þ fw ðsÞu 4 vt ds (4.25) where Dr ¼ rn  rw . The governing equations of the one-interval size nanoparticles transport with two-phase flow in porous media can be summarized as 4

vðsw cÞ þ V•ðuw c  4sw DVcÞ ¼ R vt vCs1 vCs2 þ vt vt

(4.27)

gd juw jc; juw j  uc gd juw jc  ge juw  uc jcs1 ; juw j > uc ;

(4.28)

R¼ vcs1 ¼ vt

(

(4.26)

vcs2 ¼ gpt juw jc; vt

(4.29)

The details of the above system of governing equations and their terms, variables, and constants were provided in Chapter 1 and other previous chapters. If we divide the total time interval ½0; T  into NT steps with the length, Dt n ¼ t nþ1  t n , where n þ 1 refers to the current time step and n represents the previous time-step, we use the backward Euler method to discretize the time derivatives in the equations of saturation and concentrations. In order to calculate the pressure the following two equations are solved simultaneously:    n n  nþ1    n n   V , lt swn K cs1 ; cs2 Vpw  V , ln swn K cs1 ; cs2 Vpc swn ¼ qtn (4.30)

Chapter 4 Temporal numerical discretization schemes

 n n  swnþ1  swn    n n  nþ1 4 cs1 ; cs2  qwn ¼  V,lt swn K cs1 ; cs2 VPw n Dt

(4.31)

The saturation is update using the explicit equation:    n n  swnþ1  swn ¼ qwnþ1 ; cs2 þ V , fwn unþ1 4 cs1 a n Dt

(4.32)

The equations of nanoparticles concentration and deposited/ released nanoparticles concentrations are represented, respectively, as follows:

 n n  swnþ1 cnþ1  swn c n nþ1 ; cs2 þ V , unþ1 4 cs1 w c n Dt   nþ1 (4.33) n n  D swnþ1 ; pnþ1 w ; cs1 ; cs2 Vc   n n nþ1 ; ¼ R swnþ1 ; Pnþ1 w ; c ; cs1 þ Qc nþ1 ( nþ1 nþ1 u  ur nþ1 n gd uw c ; cs1  cs1 w ¼ nþ1 nþ1 nþ1 nþ1 nþ1 Dt n gd uw c  ge uw  ur cs1 ; uw > ur (4.34) and nþ1 n nþ1 nþ1 cs2  cs2 c ¼ gpt uw Dt n

(4.35)

In the above scheme, both K and 4 are used from the previous step n of cs1 and cs2 , while D and R are calculated at current step n þ 1 of Sw and pw and previous step n of cs1 and cs2 . Finally, the parameters lw ; ln ; lt and fw are estimated in the previous step n. In Chapter 5, more schemes will be presented including iterative methods.

4.8 MATLAB code Because most of the terms in governing differential equations can be classified as advection or diffusion terms, the MATLAB program for the above scheme mainly depends on calling the ‘Advection’ and ‘Diffusion’ MATLAB functions that were presented in Chapter 3. This code is used to solve the two-phase flow associated with nanoparticle transport in porous media.

113

114

Chapter 4 Temporal numerical discretization schemes

Discretization parameters: nx ny NTS inj Lx Ly T_tot ht x y serr

= = = = = = = = = = =

30; 20; 100; 0.2; 0.6; 0.4; 0.5/inj; T_tot/NTS; Lx*(0:nx)'/nx; Ly*(0:ny)'/ny; 10^(-4);

Physical parameters: D = 5.6e-8; % diffusion coefficient Ucrit = 4.6e-6; gamad = 16; gamapt = 1.28; gamae = 30; md = 9.86923*10^(-16); % md to m^2 cp = 1.0e-3; % cP to Pa.s visw = 1*cp; % visW/visN visn = 0.45*cp; porval = 0.3; permType= 2; Srw = 0; Srn = serr; Swbdry = 1.0; Seb = (Swbdry-Srw)/( 1-Srw-Srn ); krwb = ( Seb.^permType ) / visw; krnb = ((1 - Seb).^permType) / visn; lagtb = krwb + krnb; krwEdges= krwb./lagtb;

Initial conditions: swInit = 1.0 * serr * ones(nx, ny); cs1Init = 0.0 * ones(nx, ny); cs2Init = 0.0 * ones(nx, ny);

Chapter 4 Temporal numerical discretization schemes

Boundary conditions: krw_W = krwEdges * ones(ny, 1); krw_E = 0.0 * ones(ny, 1); krw_S = 0.0 * ones(nx, 1); krw_E = 0.0 * ones(nx, 1); vpw_W = ( inj*Lx*porval) * ones(ny, 1); % The unit of vel is m/year vpw_E = 0.0 * ones(ny, 1); vpw_S = 0.0 * ones(nx, 1); vpw_N = 0.0 * ones(nx, 1); pw_W = 0.0 * ones(ny, 1); pw_E = 0.0 * ones(ny, 1); % Outside pres pw_S = 0.0 * ones(nx, 1); pw_N = 0.0 * ones(nx, 1); vpc_W = 0.0 * ones(ny, 1); vpc_E = 0.0 * ones(ny, 1); vpc_S = 0.0 * ones(nx, 1); vpc_N = 0.0 * ones(nx, 1); pc_W = 0.0 * ones(ny, 1); pc_S = 0.0 * ones(nx, 1); pc_N = 0.0 * ones(nx, 1); vpsBdryW = 0.0 * ones(ny, 1); vpsBdryE = 0.0 * ones(ny, 1); vpsBdry = 0.0 * ones(nx, 1); vpsBdryN = 0.0 * ones(nx, 1); psBdryW = 0.0 * ones(ny, 1); psBdryE = 0.0 * ones(ny, 1); psBdry = 0.0 * ones(nx, 1); psBdryN = 0.0 * ones(nx, 1);

Transport parameters: por0 permXX0 cx cy xisLowPerm yisLowPerm

= = = = = =

porval * ones(nx, ny); 100 * md * ones(nx, ny); 0.5*(x(2:end) + x(1:end-1)); 0.5*(y(2:end) + y(1:end-1)); find( (cx>.0)&(cx.0)&(cy