# Computing Effective Permeability of Porous Media with FEM and Micro-CT: An Educational Approach

^{1}

^{2}

^{3}

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Effective Permeability through Numerical Homogenization

^{2}), the pressure gradient (unit of pressure per length, e.g., Pa/m), and the inverse of the fluid viscosity (Pa∙s).

## 3. Computational Fluid Dynamics with Finite Element Method (FEM)

**N**. In classical formulations of the FEM, there arises a matrix whose elements contain derivatives of the shape functions, known as the

**B**matrix. These matrices establish the following relationships:

**u**and p, respectively, and

**L**is the matrix of the differential operators.

**u**; therefore, $\mathsf{\psi}={N}^{u}{\overline{\mathsf{\psi}}}^{u}$. The weight function $\psi $ presented in Equation (6) is associated with the volume change of the fluid element; thus, it should be understood as a virtual hydrostatic pressure that causes this volume variation. That way, we define $\psi ={N}^{p}\u200a{\overline{\mathsf{\psi}}}^{p}$.

**B**and

**N**. Equations (7) and (6) should be respectively rewritten, in the element domain, as follows:

**f**.

**K**is the viscosity matrix,

**G**is the gradient matrix,

**D**is the velocity divergent matrix and is equal to the transpose of

**G**matrix,

**P**represents the pressure stabilization matrix.

## 4. Implementation of Boundary Conditions

## 5. Octave/Matlab Implementation

#### 5.1. Input and Initialization

Listing 1. Implementation of input data and initializations | |

1 | %% Determining permeability of porous materials |

2 | %% Reads the image |

3 | z = imread(’filename.tif’); |

4 | %% Increases the image resolution by n times |

5 | n = 1; |

6 | z = repelem(z,n,n); |

7 | %% Displays the image |

8 | Figure 1 |

9 | imshow(z) |

10 | %% Determines the effective permeability |

11 | lx = 1; % horizontal dimension |

12 | ly = 1; % vertical dimension |

13 | KH = compute_permeability(lx,ly,z); |

Listing 2. Implementation of the main function to compute permeability. | |

14 | function KH = compute_permeability(lx,ly,z) |

15 | %% Initializations |

16 | [nely, nelx] = size(z); |

17 | dx = lx/nelx; |

18 | dy = ly/nely; |

19 | nel = nelx*nely; |

Listing 3. Implementation of periodic boundary conditions. | |

20 | %% Periodic boundary conditions (PBC) |

21 | nnPBC = nel; %Number of unique nodes |

22 | m_IdNodesPBC = reshape(1:nnPBC, nelx, nely); % Matrix of unique nodes |

23 | m_IdNodesPBC(end+1,:) = m_IdNodesPBC(1,:); % Numbering bottom nodes |

24 | m_IdNodesPBC(:,end+1) = m_IdNodesPBC(:,1); % Numbering right nodes |

25 | m_ConnectPBC = zeros(nel,4); % Matrix with element connectivity |

26 | m_ConnectPBC = [reshape(m_IdNodesPBC(2:end,1:end-1),nel,1)... |

27 | reshape(m_IdNodesPBC(2:end,2:end),nel,1)... |

28 | reshape(m_IdNodesPBC(1:end-1,2:end),nel,1)... |

29 | reshape(m_IdNodesPBC(1:end-1,1:end-1),nel,1)]; |

30 | ndofPBC = 3*nnPBC; |

#### 5.2. Coeficient Matrix and RHS Contribution of Each Element

Listing 4. Implementation to call the function to compute the element domain matrices. | |

31 | %% Calculation of element matrices |

32 | [ke,ge,pe,fe,SN] = calculate_matrices(dx, dy); |

Listing 5. Implementation of a function to calculate the finite element matrices. | |

33 | %% Element Matrices |

34 | function [k,g,pe,f,SN] = calculate_matrices(dx, dy) |

35 | coordsElem = [0 0; dx 0; dx dy; 0 dy]; |

36 | rr = [−1/sqrt(3) 1/sqrt(3)]; |

37 | ww = [1 1]; |

38 | ss = rr; |

39 | k = zeros(8); |

40 | SN=zeros(2,8); |

41 | C = [2 0 0; 0 2 0; 0 0 1]; |

42 | g = zeros(8,4); |

43 | pe = zeros(4); |

44 | h2 = ((dx)^2)+((dy)^2); |

45 | stab = h2/12; |

46 | f = zeros(4,1); |

47 | for i = 1:2 |

48 | r = rr(1,i); |

49 | for j = 1:2 |

50 | s = ss(1,j); |

51 | N=(1/4)*[(1−s)*(1−r) 0 (1−s)*(1+r) 0 (1+s)*(1+r) 0 (1−r)*(1+s) 0; |

52 | 0 (1−s)*(1−r) 0 (1−s)*(1+r) 0 (1+s)*(1+r) 0 (1−r)*(1+s)]; |

53 | dN1dr = −1/4*(1−s); |

54 | dN2dr = +1/4*(1−s); |

55 | dN3dr = +1/4*(1+s); |

56 | dN4dr = −1/4*(1+s); |

57 | dN1ds = −1/4*(1−r); |

58 | dN2ds = −1/4*(1+r); |

59 | dN3ds = +1/4*(1+r); |

60 | dN4ds = +1/4*(1−r); |

61 | DN = [dN1dr dN2dr dN3dr dN4dr; |

62 | dN1ds dN2ds dN3ds dN4ds]; |

63 | J = DN*coordsElem; |

64 | invJ = 1.0/det(J)*[J(2,2) −J(1,2); −J(2,1) J(1,1)]; |

65 | DNxy = invJ*DN; |

66 | B = [DNxy(1,1) 0 DNxy(1,2) 0 DNxy(1,3) 0 DNxy(1,4) 0; |

67 | 0 DNxy(2,1) 0 DNxy(2,2) 0 DNxy(2,3) 0 DNxy(2,4); |

68 | DNxy(2,1) DNxy(1,1) DNxy(2,2) DNxy(1,2) DNxy(2,3) DNxy(1,3) DNxy(2,4) DNxy(1,4)]; |

69 | k = k + (B’)*C*B*det(J)*ww(1,i)*ww(1,j); |

70 | g = g + (B’)*[1;1;0]*N(1:4:end)*(det(J))*ww(1,i)*ww(1,j); |

71 | Bp = inv(J)*[DN(1,:);DN(2,:)]; |

72 | pe = pe + stab*(Bp’)*Bp*(det(J))*ww(1,i)*ww(1,j); |

73 | f = f + N(1,1:2:end)’*det(J)*ww(1,i)*ww(1,j); |

74 | SN = SN + N*det(J)*ww(1,i)*ww(1,j); |

75 | end |

76 | end |

77 | end |

**f**and the matrices

**k**,

**g**, and

**pe**can be calculated within the same function, making the algorithm more compact and elegant.

#### 5.3. Assembly of the Linear Algebraic System

**K**,

**G**,

**G**, and

^{T}**P**are allocated to each element. An intuitive and didactic way to do this assembly is using Listing 6.

Listing 6. Didactic implementation of assembly in the FEM. | |

%% Assembling the system of linear algebraic equations with loops | |

v_elemF = find(~z); % vector with fluid region elements only | |

for elem = 1:size(v_elemF,1) | |

e= v_elemF(elem); | |

v_dofF = [m_ConnectPBC(e,1)*2-1; m_ConnectPBC(e,1)*2; | |

m_ConnectPBC(e,2)*2-1; m_ConnectPBC(e,2)*2; | |

m_ConnectPBC(e,3)*2-1; m_ConnectPBC(e,3)*2; | |

m_ConnectPBC(e,4)*2-1; m_ConnectPBC(e,4)*2; | |

2*nel+m_ConnectPBC(e,1); | |

2*nel+m_ConnectPBC(e,2); | |

2*nel+m_ConnectPBC(e,3); | |

2*nel+m_ConnectPBC(e,4)]; | |

% dof 1, 2 (velocities) of each node and dof 3 (pressure) of each node | |

for i=1:8 | |

for j=1:8 % allocates viscosity matrix | |

A(v_dofF(i), v_dofF(j)) = A(v_dofF(i), v_dofF(j)) + ke(i,j); | |

end | |

for j=1:4 % allocates gradient matrix | |

A(v_dofF(i), v_dofF(8+j)) = A(v_dofF(i), v_dofF(8+j)) + ge(i,j); | |

end | |

end | |

for i=1:4 % allocates right-hand side matrix | |

F(v_dofF(i*2-1),1) = F(v_dofF(i*2-1),1) + f(i); | |

F(v_dofF(i*2),2) = F(v_dofF(i*2),2) + f(i); | |

for j=1:4 % allocates pressure matrix | |

A(v_dofF(8+i),v_dofF(8+j)) = A(v_dofF(8+i),v_dofF(8+j)) - pe(i,j); | |

end | |

end | |

end | |

G = A(1:nel*2,nel*2+1:nel *3); | |

A(nel*2+1:nel*3,1:nel*2) = G’; |

Listing 7. Efficient implementation of assembly in the FEM. | |

78 | %% Assembling the system of linear algebraic equations with triplets |

79 | disp(’--- ASSEMBLY ---’); |

80 | v_elemF = find(~z); % Vector containing only fluid elements |

81 | nelemF = size(v_elemF,1); |

82 | m_dofF = [m_ConnectPBC(v_elemF,1)’*2-1; m_ConnectPBC(v_elemF,1)’*2; |

83 | m_ConnectPBC(v_elemF,2)’*2-1; m_ConnectPBC(v_elemF,2)’*2; |

84 | m_ConnectPBC(v_elemF,3)’*2-1; m_ConnectPBC(v_elemF,3)’*2; |

85 | m_ConnectPBC(v_elemF,4)’*2-1; m_ConnectPBC(v_elemF,4)’*2; |

86 | 2*nel+m_ConnectPBC(v_elemF,1)’; % |

87 | 2*nel+m_ConnectPBC(v_elemF,2)’; |

88 | 2*nel+m_ConnectPBC(v_elemF,3)’; |

89 | 2*nel+m_ConnectPBC(v_elemF,4)’]; |

90 | % dof 1 and 2 (velocities) of each node and dof 3 (pressure) of each node |

91 | iK = repelem(reshape(m_dofF(1:8,1:end),nelemF*8,1),8,1); |

92 | jK = reshape(repmat(m_dofF(1:8,1:end),8,1),nelemF*64,1); |

93 | iG = repelem(reshape(m_dofF(1:8,1:end),nelemF*8,1),4,1); |

94 | jG = reshape(repmat(m_dofF(9:12,1:end),8,1),nelemF*32,1); |

95 | iP = repelem(reshape(m_dofF(9:12,1:end),nelemF*4,1),4,1); |

96 | jP = reshape(repmat(m_dofF(9:12,1:end),4,1),nelemF*16,1); |

97 | iA = [iK;iG;jG;iP]; |

98 | jA = [jK;jG;iG;jP]; |

99 | clear iK iG iP jK jG jP |

100 | ke = reshape(ke’,64,1); |

101 | ge = reshape(ge’,32,1); |

102 | pe = reshape(pe’,16,1); |

103 | coeff = [repmat(ke,nelemF,1);repmat(ge,nelemF,1);repmat(ge,nelemF,1);- |

104 | repmat(pe,nelemF,1)]; |

105 | A = sparse(iA,jA,coeff); |

106 | clear iA jA coeff |

107 | iF = [reshape(m_dofF(1:2:8,1:end),nelemF*4,1); |

108 | reshape(m_dofF(2:2:8,1:end),nelemF*4,1)]; |

109 | jF = [ones(nelemF*4,1);2*ones(nelemF*4,1)]; |

110 | sF = repmat(fe,nelemF*2,1); |

111 | F = sparse(iF,jF,sF,ndofPBC,2); |

112 | clear iF jF sF |

#### 5.4. Boundary Conditions and Linear Equation System Solution

Listing 8. Implementation of zero velocity condition on the interface. | |

113 | %% Solving system of equations |

114 | solveF_u = 1:nel*2; |

115 | nullnodes = [unique(m_ConnectPBC(find(z),1:4))]; |

116 | nulldof = [nullnodes*2-1 nullnodes*2]; |

117 | solveF_u(nulldof) = [[]; %Matrix reduction |

118 | solveF_p = (nel*2+unique(m_ConnectPBC(find(~z),1:4)))’; |

119 | solveF = [solveF_u solveF_p]; |

120 | clear solveF_u solveF_p nullnodes nulldof m_ConnectPBC |

121 | X = zeros(ndofPBC,2); |

122 | disp(’--- SOLVE ---’); |

123 | X(solveF,:) = A(solveF,solveF)\F(solveF,:); |

#### 5.5. Obtaining Permeability

**N**is used to approximate the velocity field. This process can be performed using Listing 9.

Listing 9. Alternative implementation for permeability calculation. | |

%% Permeability Calculation | |

KH = zeros(2); | |

for elem=1:nelemF | |

velem_c1(:,elem) = SN*X(m_dofF(1:8,elem),1); | |

velem_c2(:,elem) = SN*X(m_dofF(1:8,elem),2); | |

end | |

vel_c1 = sum(velem_c1,2); | |

vel_c2 = sum(velem_c2,2); | |

KH(1,1) = vel_c1(1,1); | |

KH(1,2) = vel_c1(2,1); | |

KH(2,1) = vel_c2(1,1); | |

KH(2,2) = vel_c2(2,1); | |

KH = KH/nel/dx/dy; | |

end |

Listing 10. Efficient implementation of permeability calculation. | |

124 | %% Permeability Calculation |

125 | % sum of elements’ velocities in case 1 |

126 | vel_c1 = SN*sum(reshape(X(m_dofF(1:8,:),1),8,nelemF),2); |

127 | %sum of elements’ velocities in case 2 |

128 | vel_c2 = SN*sum(reshape(X(m_dofF(1:8,:),2),8,nelemF),2); |

129 | KH = [vel_c1’; vel_c2’]/(nel*dx*dy); |

130 | disp(KH) |

131 | end |

#### 5.6. Validation Test

^{−3}is obtained via the analytical solution. Figure 4 shows the results obtained through numerical modeling using the program proposed in this paper.

## 6. Real Case Application: Permeability of Sandstone

#### 6.1. Image Acquisition: Microcomputed Tomography

#### 6.2. Image Processing and Segmentation

#### 6.3. Sandstone Absolute Permeability

^{2}and Kyy = 0.1603 µm

^{2}. This means that the sample is anisotropic with respect to permeability. The mesh size of 2400 × 2400 was limited by the random-access memory (RAM) of 32 Gb. A computer with 16 Gb RAM would allow refinement up to 1600 × 1600.

## 7. Conclusions

## Author Contributions

## Funding

## Acknowledgments

## Conflicts of Interest

## References

- Andreassen, E.; Andreasen, C.S. How to Determine Composite Material Properties Using Numerical Homogenization. Comput. Mater. Sci.
**2014**, 83, 488–495. [Google Scholar] [CrossRef] [Green Version] - Aarnes, J.E.; Gimse, T.; Lie, K.A. An Introduction to the Numerics of Flow in Porous Media using Matlab. In Geometric Modelling, Numerical Simulation, and Optimization; Springer: Berlin/Heidelberg, Germany, 2007. [Google Scholar]
- Sheng, X.Y.; Zhi, X.X. A New Numerical Method for the Analysis of the Permeability Anisotropy Ratio. Chin. Phys.
**2002**, 11, 1009–1963. [Google Scholar] - Akanji, L.T.; Matthai, S.K. Finite Element-Based Characterization of Pore-Scale Geometry and Its Impact on Fluid Flow. Transp. Porous Media
**2010**, 81, 241–259. [Google Scholar] [CrossRef] - Yang, L.; Yang, J.; Boek, E.; Sakai, M.; Pain, C. Image-Based Simulation of Absolute Permeability with Massively Parallel Pseudo-Compressible Stabilized Finite Element Solver. Comput. Geosci.
**2019**, 23, 881–893. [Google Scholar] [CrossRef] - Reddy, J.N. An Introduction to The Finite Element Method, 3rd ed; McGraw-Hill: New York, NY, USA, 2005. [Google Scholar]
- Ladyzhenskaya, O.A. The Mathematical Theory of Viscous Incompressible Flow, 2014th ed.; Gordon and Breach: New York, NY, USA, 1969. [Google Scholar]
- Babuška, I. Error-Bounds for Finite Element Method. Numer. Math.
**1971**, 16, 322–333. [Google Scholar] [CrossRef] - Brezi, F. On the Existence, Uniqueness and Approximation of Saddle-Point Problems Arising from Lagrangian Multipliers. Analyse Numérique. Rev. Française D’automatique Inform. Rech. Oper.
**1974**, 8, 129–151. [Google Scholar] - Elman, H.C.D.; Silvester, J.; Wahereen, A.J. Finite Elements and Fast Iterative Solvers: With Applications in Incompressible Fluid Dynamics; Oxford University Press: Oxford, UK, 2006. [Google Scholar]
- Bathe, K.J. Finite Element Procedures, 1st ed.; Prentice Hall: Upper Saddle River, NJ, USA, 1982. [Google Scholar]
- Karim, M.R.; Krabbenhoft, K.; Lyamin, A.V. Permeability Determination of Porous Media Using Large-Scale Finite Elements and Iterative Solver. Int. J. Numer. Anal. Methods Geomech.
**2014**, 38, 991–1012. [Google Scholar] [CrossRef] - Braack, M.; Schieweck, F. Equal-Order Finite Elements with Local Projection Stabilization for the Darcy–Brinkman Equations. Comput. Methods Appl. Mech. Eng.
**2011**, 200, 1126–1136. [Google Scholar] [CrossRef] - Codina, R.; Blasco, J. A Finite Element Formulation for The Stokes Problem Allowing Equal Velocity-Pressure Interpolation. Comput. Methods Appl. Mech. Eng.
**1997**, 143, 373–391. [Google Scholar] [CrossRef] - Becker, R.; Hansbo, P. A Simple Pressure Stabilization Method for The Stokes Equation. Int. J. Numer. Methods Biomed. Eng.
**2008**, 24, 1421–1430. [Google Scholar] [CrossRef] [Green Version] - Drummond, J.E.; Tahil, M.I. Laminar Viscous Flow Through Regular Arrays of Parallel Solid Cylinders. Int. J. Multiph. Flow
**1984**, 10, 515–540. [Google Scholar] [CrossRef]

**Figure 1.**Representation of a periodic medium in an image representing the medium’s representative elementary volume (REV).

**Figure 2.**Steps for numbering mesh nodes considering periodic boundary conditions: (

**a**) firstly, we number nodes except for those on the bottom and right edges; (

**b**) next, we copy the node numbers from the top edge to the bottom edge; (

**c**) finally, we copy the node numbers from the left edge to the right edge.

**Figure 5.**Workflow in digital petrophysics from sample preparation to computer simulation, covering image acquisition, reconstruction of the virtual sample, image processing, segmentation, and mesh generation.

**Figure 7.**Two-dimensional (2D) slice of a sandstone microtomography, segmentation of the same 2D slice, and representation of the mesh in a region of 25 × 25 pixels.

Mesh | K_{xx} (µm^{2}) | K_{yy} (µm^{2}) |
---|---|---|

600 × 600 | 0.2769 | 0.2952 |

800 × 800 | 0.2018 | 0.2343 |

1000 × 1000 | 0.1638 | 0.2050 |

1200 × 1200 | 0.1419 | 0.1888 |

1400 × 1400 | 0.1282 | 0.1789 |

1600 × 1600 | 0.1191 | 0.1723 |

1800 × 1800 | 0.1127 | 0.1678 |

2000 × 2000 | 0.1081 | 0.1646 |

2200 × 2200 | 0.1046 | 0.1621 |

2400 × 2400 | 0.1019 | 0.1603 |

© 2020 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Vianna, R.S.; Cunha, A.M.; Azeredo, R.B.V.; Leiderman, R.; Pereira, A.
Computing Effective Permeability of Porous Media with FEM and Micro-CT: An Educational Approach. *Fluids* **2020**, *5*, 16.
https://doi.org/10.3390/fluids5010016

**AMA Style**

Vianna RS, Cunha AM, Azeredo RBV, Leiderman R, Pereira A.
Computing Effective Permeability of Porous Media with FEM and Micro-CT: An Educational Approach. *Fluids*. 2020; 5(1):16.
https://doi.org/10.3390/fluids5010016

**Chicago/Turabian Style**

Vianna, Rafael S., Alexsander M. Cunha, Rodrigo B. V. Azeredo, Ricardo Leiderman, and Andre Pereira.
2020. "Computing Effective Permeability of Porous Media with FEM and Micro-CT: An Educational Approach" *Fluids* 5, no. 1: 16.
https://doi.org/10.3390/fluids5010016