1 Jurnal Matematika Integratif. p-ISSN:1412-6184, e-ISSN:2549-903 2 Vol. xx, No. xx (20xx), pp. xx–xx. doi:10.24198/jmi.vxx.ny.xxxx.y-yy

3 A mixed RT0 − P0 Raviart-Thomas finite element implementation of 4 Darcy Equation in GNU Octave

1 1,† 5 Agah D. Garnadi , C. Bahriawati

1 6 Jurusan Matematika, Fakultas MIPA, Institut Pertanian Bogor, Indonesia, e-mail:

7 [email protected]

8

Abstrak In this paper we shall describe mixed formulations -differential and variational- of Darcys flow equation, an important model of elliptic problem. We describe *

9 Galerkin method with finite dimensional spaces; * Local matrices and assembling;

* Raviart-Thomas RT0 − P0 elements; * Edge basis and local matrices for RT0 − P0 FEM; * Model problem with corresponding local matrices, right hand side and treatment of boundary conditions. A simple demo written in GNU Octave is given. Kata kunci: Persamaan Darcy, Aliran di bahan berpori, Flux, Kekekalan Local, 10 Metode Elemen Hingga Campuran

Abstract In this paper we shall describe mixed formulations -differential and variational- of Darcys flow equation, an important model of elliptic problem. We describe *

11 Galerkin method with finite dimensional spaces; * Local matrices and assembling;

* Raviart-Thomas RT0 − P0 elements; * Edge basis and local matrices for RT0 − P0 FEM; * Model problem with corresponding local matrices, right hand side and treatment of boundary conditions. A simple demo written in GNU Octave is given. Keywords: Darcy flow, Flow in porous media, Flux, Local conservation, Mixed finite 12 element methods

13 Contents 14 1 Introduction 1 15 2 Problem formulation 1 16 3 Galerkin method -Mixed FEM 2 17 4 Local matrices and assembling 3 18 5 Lowest order Raviart-Thomas finite elements 3 19 6 Local properties and local edge basis for RT(0) elements 4 20 7 Local matrices 5 21 8 Model problem 7 22 9 Assembling 9

23 1. Introduction

24 This report describes basis of RT1 code, which can be characterized as a code for test- 25 ing solvers and preconditioners for FEM systems arising from lowest order Raviart-Thomas 26 discretization of Darcy flow problems, see also [2] [1]

2000 Mathematics Subject Classification: 65N15; 65M30 Received: dd-03-2020, accepted: dd-mm-yyyy. 1 2Garnadi & Bahriawati, JMI Vol x No y Okt/Apr 2020, pp. xx-yy,doi:10.24198/jmi.vxx.ny.xxxx.y-yy

27 The code is characterized by simplicity and possibility of easy modifications,

28 • directly solving model problems on square domains (generalization possible), 29 • stochastic generation of heterogeneity, 30 • fast system assembling using vectorization and sparse reconstruction, 31 • possible testing of Krylov type solvers with both (block) matrix and matrix free (vari- 32 able) preconditioners.

33 This report describes the finite element system generation, experiments are involved in 34 papers, e.g. [3].

35 2. Problem formulation

36 Let us consider Darcy flow elliptic problem in the form

−div(k(−g + grad p) = f in Ω p =p ˆ on ΓD (−k grad p) · n =u ˆ on ΓN

37 where g 6= 0 if we consider elevation changes. It can be also written in a two field form 1 n 38 with two basic variables p :Ω → and u :Ω → R ,

k−1u + grad p = g  in Ω div(u) = f 39

p =p ˆ on ΓD (−k grad p) · n =u ˆ on ΓN

40 The variational formulation uses test functions v and q to get

R k−1u · vdx + R ∇p · vdx = R g · vdx RΩ Ω RΩ Ω div(u)q = Ω fqdx

41 Transformation of one mixed term then provides

R R P ∂p P R R ∂vk ∇p · v = vkdx = { pvk · nk − p dx} Ω RΩ k ∂xk R k ∂Ω Ω ∂xk = ∂Ω p(v · n) − Ω pdiv(v)dx

42 Then the variational formulation gets the form R k−1u · v − R div(v) · p = R g · vdx − R pˆ(v · n) − R p(v · n) ∀v RΩ Ω RΩ ΓD ΓN Ω div(u)q = Ω fq ∀q

43 –or in abstract form: find (u, p) ∈ UN × P

m(u, v) + b(v, p) = G(v) ∀v ∈ U0 b(u, q) = F (v) ∀q ∈ P

44 where n U = {v ∈ L2(Ω) : div(v) ∈ L2(Ω)} → H(div) U0 = {v ∈ U : v · n = 0 on ΓN } UN = {v ∈ U : v · n =u ˆ on ΓN } P = {q ∈ L2(Ω)} R 45 Note that pressure BC enters G(v) = ... − pˆ(v · n) whereas velocity BC are included Γ0 46 in UN . Darcy - Raviart-Thomas Element 3

47 3. Galerkin method -Mixed FEM

48 We start with introducing FEM spaces Uh ⊂ U, UNh ⊂ UN ,U0h ⊂ U0 and Ph ⊂ P. 49 Then the Galerkin method is to find (uh, ph) ⊂ UhN × Ph

m(uh, vh) + b(vh, ph) = G(vh) ∀vh ∈ U0h b(uh, qh) = F (qh) ∀ph ∈ Ph

50 After a choice of bases

Uh = lin{Φi, i ∈ I},Ph = lin{Ψj : j ∈ J}

UNh = uN + u, u ∈ U0h

U0h = lin{Φi : i ∈ I0} X uN ∈ lin{Φi : i ∈ I\I0}, uN = (ˆu · n)(xi)Φi

51 the discrete mixed problem can be written as -find (uh, ph) ∈ UhN × Ph, uh = uN + P P 52 α Φ , p = β Ψ i∈I0 i i h j∈J j j

P α m(Φ , Φ ) + P β b(Φ , Ψ ) = G(Φ ) − m(u , Φ ) ∀k ∈ I i∈I0 i i k j∈J j k j k N k 0 P α b(Φ , Ψ ) = F (Ψ ) − b(u , Ψ ) ∀l ∈ J i∈I0 i i l l N l

53 Rewriting to matrix form provides

T n1 Bα + B β = G, α ∈ R , n1 = #I0 n2 Bα = F, β ∈ R , n2 = #J

n1×n1 n2×n1 T n1×n2 T 54 where M ∈ R ,Mij = m(Φj, Φi),B ∈ R ,Bij = b(Φj, Ψi),B ∈ R ,Bij = 55 b(Φi, Ψj) = Bji,G = (Gi),Gi = G(Φi),F = (Fk),Fk = F (Ψk).

56 4. Lowest order Raviart-Thomas finite elements

2 57 Let Ω ∈ R be a 2D polygonal domain, Th be its triangulation, Eh be set of edges of all 58 elements T ∈ Th see the situation in the following Figure 1. 59 Then, we can define 2 T T RT0(T ) = {v : T → R , v(x) = ξ[x1 x2] + [η1 η2] , ξ, η1, η2 ∈ R} 60 2 Uh = {v :Ω ∈ R , v|T ∈ RT0(T ) ∀T ∈ Th, v · nE is continuous over E ∈ Eh} 1 Ph = {q :Ω ∈ R , q|T is constant ∀T ∈ Th}.

61 Continuity of ν · nE guarantees Uh ∈ U, Ph ∈ P is obvious. Note that ∀E ∈ Eh we define 62 nE (unit normal vector), independently of relation to triangles and consequently in possibly 63 inner or outer direction, see Figure 2.

64 6 Local properties and local edge basis for RT(0) elements

65 Lemma 4.1. Let T ∈ Th, v ∈ RT0(T ). Then ∀E ∈ Eh ∪ ∂T : v · n|E = const.

∗ 66 Proof. Let E ∈ Eh ∪ ∂T, nE be normal to E (can be either outer or inner to T ), x ∈ E be 67 arbitrary point at E. Then ∗ ∗ ∗ x ∈ E ⇒ (x − x ) · nE = 0, nE = (n1, n2) ⇒ x1n1 + x2n2 = x1n1 + x2n2 = const. ⇒ 68 ∗ ∗ v(x) · n = ξx1n1 + ξx2n2 + η1n1 + η2n2 = ξ(x1n1 + x2n2) + η1n1 + η2n2 = const . 69  4Garnadi & Bahriawati, JMI Vol x No y Okt/Apr 2020, pp. xx-yy,doi:10.24198/jmi.vxx.ny.xxxx.y-yy

(i) (j) Gambar 1. {x } set of centres of Ei ∈ Eh, {y } barycentres of Tj ∈ Th

Gambar 2. Prescribed normal nE. Possible definition of nE,E ∈ Eh.

Gambar 3. Triangle T ∈ Th. Darcy - Raviart-Thomas Element 5

70 Lemma 4.2. (Expression for local basis functions.) Let

E Φ (x) = σ i (x − P ), σ = n n(i), i i 2|T | i i Ei (i) 71 where nEi are global prescribed normals and n are outer normals for T ∈ Th, see Figure 72 3. Then

73 (i)Φ j(x) · nEi = δij, 74 (ii)Φ i ∈ RT0(T ), 75 (iii)Φ 1, Φ2, Φ3 create a basis of RT0(T ), Ei 76 (iv) divΦi = σi |T | .

77 Proof. (i) If i 6= j, then Pi ∈ Ej and (x − Pi) · nEj = 0 for x ∈ Ej. If i = j then for

78 x ∈ Ei the value (x − Pi) · nEi appears in the projection of (x − Pi) to the height of 1 79 T passing through Pi and therefore |(x − Pi) · nEi | = hi. Moreover, 2 hi|Ei| = |T | and (i) 80 hi = 2|T |/|Ei|, (x − Pi) · n ≥ 0 -both vectors have outward direction w.r.t. T. Finally 2|T | (x − Pi) · nEi = σi |Ei|

81 (ii) obvious 3 82 P (iii) u ∈ RT0(T ), w = u − 1(u · nEi )Φi. Obviously w · nEi = 0∀Ei. Therefore ∀Pj :

83 w(Pj) · nEi = 0 and because ∀Ei : Pj ∈ Ei, it holds w(Pj) = 0∀j = 1, 2, 3. As w is 84 linear polynomial, w = 0. Proof of uniqueness: 3 X w = αiΦi = 0 ⇒ wnEj = αjΦjnEj = αj = 0∀j. 1

85 (iv) obvious 86 

87 5. Local matrices and assembling

88 Assume that Φi and Ψi are constructed as finite element basis functions above some 89 triangulation Th, i.e.T ∈ Th Φi|T ∈ {Φ1, ..., Φρ, 0 = Φ0} 90 Ψj|T ∈ {Ψ1, ...Ψs, 0 = Ψ0}.

91 Then R −1 m(Φi, Φk) = Ω k ΦiΦkdx = P R k−1Φ Φ dx T ∈Th T i k = P R k−1Φ Φ dx T ∈Th T loc(i) loc(k) R b(Φi, Ψj) = Ω(divΦi)Ψjdx = P R (divΦ )Ψ dx T ∈Th T loc(i) loc(j)

92 where lock(i) = lock(i, T ) is a transformation from global index to local index of basis 93 function on T. It can be also zero.

94 Vice versa, for T ∈ Th, it is possible to construct local matrices R −1 MT , (MT )rs = k ΦsΦrdx TR BT , (BT )rs = − T divΦs · Ψrdx

95 and then perform the assembling of local matrices to global M,B

(MT )rs → Mglob(T,r)glob(T,s) = +(MT )rs 96 (BT )rs → B = +(BT )rs glob1(T,r)glob2(T,s) 6Garnadi & Bahriawati, JMI Vol x No y Okt/Apr 2020, pp. xx-yy,doi:10.24198/jmi.vxx.ny.xxxx.y-yy

97 Note there are two sets of basis functions {Φi}, {Ψi}, two sets of local basis functions {Φi}, {Ψi} 98 and two mappings loc1(i) = loc1(i, T ), loc2 99 glob1(r, T ) = i, glob2(s, T ) = j.

100 6. Local matrices

101 Let us consider the local basis on T created by Φ1, Φ2, Φ3 ∈ RT0(T ) and Ψ1 = 1. Then 1×3 102 BT ∈ R , Z |Es| (BT )1s = (divΦs)Ψ1 = σs |T | = σs|Es|, T |T | 1×3 3×3 103 i.e. BT = [σ1|E1|, σ2|E2|, σ3|E3|] ∈ R . Further, MT ∈ R , Z Z −1 |Er||Es| −1 (MT )rs = k ΦsΦrdx = σrσs 2 k (x − Ps) · (x − Pr)dx. T 4|T | T R −1 104 To compute the integral T k (x − Ps) · (x − Pr)dx, we can use barycentric coordinates 105 at T,

x = λ1(x)P1 + λ2(x)P2 + λ3(x)P3, λ1 + λ2 + λ3 = 1,

106 thus x − Pr = λ1(x)(P1 − Pr) + λ2(x)(P2 − Pr) + λ3(x)(P3 − Pr)

107 and 3 Z |Er||Es| X (M ) = σ σ λ λ k−1(P − P ) · (P − P )dx. T rs r s 4|T |2 α β α s β r α,β=1 T R |T | 108 Assuming k constant on T and using the integration formula T λαλβ = 12 (1 + δαβ), 109 which is a special case of Z a b c a!b!c! λ1λ2λ3dx = 2|T | T (a + b + c + 2)! Z a b c d a!b!c!d! λ1λ2λ3λ4dx = 6|V | V (a + b + c + d + 3)! 110 see e.g. [4, 5]

111 the elements of MT can be expressed as

3 1 X (M ) = σ |E | (1 + δ )k−1(P − P ) · (P − P )σ |E | T rs 48|T | r r α,β α s β r s s α,β=1 6×1 112 If we define vectors vr, vs ∈ R ,     P1 − Pr P1 − Ps   x1 vr =  P2 − Pr  , vs =  P2 − Ps  , pi = x2 P3 − Pr P3 − Ps

113 Then

 2 0 1 0 1 0   0 2 0 1 0 1   −1    k 1 T  1 0 2 0 1 0  −1 (MT )rs = σr|Er|vr    k  vsσs|Es| 48|T |  0 1 0 2 0 1    k−1  1 0 1 2 0 0  0 1 0 1 0 2 Darcy - Raviart-Thomas Element 7

 2 0 1 0 1 0   0 2 0 1 0 1     1 0 2 0 1 0  C := (df)    0 1 0 2 0 1     1 0 1 2 0 0  0 1 0 1 0 2 6×6 114 Note that the diagonal elements are equal to elements of BT . If we denote C ∈ R the 115 matrix, which appeared in the expression above and

  0 P1 − P2 P1 − P3 V = [v1, v2, v3] =  P2 − P1 0 P2 − P3  P3 − P1 0 P3 − P2

116 \in R^{6\times 3}

117 then

   −1    σ1|E1| 0 0 k σ1|E1| 0 0 1 T −1 (MT ) =  0 σ2|E2| 0  V C  k  V  0 σ2|E2| 0  48|T | −1 0 0 σ3|E3| k 0 0 σ3|E3|

118 S \in R^{3\times 3} 119 L \in R^{6\times 6} 120 S

121 i.e. 1 (M ) = SV T CLV S T 48|T |   0 P1 − P2 P1 − P3 122 where S = diag[b1E1|, b2E2, b3E3],V =  P2 − P1 0 P2 − P3  , P3 − P1 P3 − P2 0 −1  k−1  −1 1 123 L = k = I, if we consider the isotropic environment, k = kT I on T.   kT k−1 124 For comparison see [2] formula (4.6). 125 Note that we constructed velocity mass matrix M. In the case of time dependent problems, R 126 we also need the pressure mass matrix (MT )rs = T ΨrΨs = δrs|T |

127 7. Model problem

128 We shall consider a model Darcy flow problems on a square domain with flow from left 129 to right induced by the pressure gradient. 130 The problem domain is divided into rectangular elements with the size characterized by 131 the parameter ns = number of segments on the side. 132 Heterogeneity. We assume that each cell can possess a different permeability coefficient 2 133 ki, i = 1, ..., nc = (ns) . This can be produced by MATLAB using command sequence

134 1 ) rng ( ’ d e f a u l t ’ ) ; 135 2 ) RM = randn ( ns , ns ) ; 136 3 ) LK = ( exp ( 1 ) . ^ ( sigma *RM) ) ;

137 The first command initializes the random number generator to make the results in this 138 example repeatable. The same sequence is generated as after restart of MATLAB. The second 139 command generate a ns-by-ns matrix of normally distributed random numbers from N(0, 1), 140 i.e. with mean µ = 0 and standard deviation 1. Then s∗RM is a matrix of normally distributed 8Garnadi & Bahriawati, JMI Vol x No y Okt/Apr 2020, pp. xx-yy,doi:10.24198/jmi.vxx.ny.xxxx.y-yy

Gambar 4. Model problem

Gambar 5. Discretization of the model problem.

2 141 random numbers with the mean µ = 0 and standard deviation σ . Third command then creates 142 matrix of conductivities such that ln(LK) has normal distribution. 143 Orientation of (global) normals to element edges

Model problem -local matrices.

1 T 1 MT = 2 SV CLV S, L = I. 24h kcell Darcy - Raviart-Thomas Element 9

Gambar 6. Global normals.

144 Lower Triangle  0 −1 0   √   0 0 −1  2   √  1 0 1  BT = [ 2h, −h, −h],S = h.  −1  ,V = h   .  0 0 −1  −1    0 −1 0  1 1 0

145 Upper triangle

 0 1 0   √   0 0 1  − 2   √  −1 0 1  BT = [− 2h, h, h],S = h.  1  = −Slow,Vupper = h   = −Vlow.  0 0 1  1    0 1 0  −1 −1 0 1 T As a conclusion -the matrices MT = 24h2 SV CLV S are the same for both lower and upper

146 147 triangles.

148 Right hand side and boundary conditions. Consider the global system

Mα + BT β = G Bα = F

149 where Z X Gi = − pˆ(pi · n) − uˆkm(Φk, Φi) Γ0 k∈I\I0 10Garnadi & Bahriawati, JMI Vol x No y Okt/Apr 2020, pp. xx-yy,doi:10.24198/jmi.vxx.ny.xxxx.y-yy

Gambar 7. Pressure boundary conditions for the model problem.

Gambar 8. Treatment of velocity boundary conditions: a) exclude corre- sponding rows and columns and rhs entries, b) or put 1 on diagonal otherwise zeros in corresponding row, columns and rhs entries

150 r.h.s. contribution 151 l.h.s., in our case

Z X Z Fj = − fΨj − uˆk div(Φk)Ψjdx = 0 Ω Ω k∈I\I0

152 = \int_{T_j} f =0 in our case 153 \int_{T_j} \mbox{div} (\Phi_k ); u_k are zero in our case

154 8. Assembling

155 Standard assembling

156 Algorithm 1 Standard assembling 157 define M = 0,B = 0 158 for 1:nt 159 take M_T ,B_T 160 for r = 1,...,3 161 for s = 1,2,3 162 Mi(T,r) j(T,s) = (M_T)_{rs} 163 B\kappa(T ) i(T,r) = (B_T )1r 164 end 165 end 166 end

167 The standard assembing has two drawbacks: for cycles, which are not efficient in MATLAB, 168 and dense matrix storage of the global matrix. Just replacing the global matrix declaration as 169 sparse is not a good solution as it the sparse structure is not given apriori but must be con- 170 structed during the assembling process. This inefficiency can be removed by gradual recording 171 the nonzero components and indices into one dimensional vectors X, I, J and constructing Darcy - Raviart-Thomas Element 11

172 the matrix through sparse(X, I, J, n, m).

173 Further improvement and loop avoiding can be done by vectorization, see [6][6]. The 174 resulting code is able fast assembly very large matrices.

Gambar 9. Transmissivity coefficient k, blue color k = 1.0, red color k = 1.4

175 9. Numerical Test

176 We test numerically an example from [7]. For simplicity, the exact uσ in Ω is set to be 177 uσ = cos(x − 0.5) ∗ exp(y).

 1.0, 0 < x < 0.5, 0 < y < 1 k = σ = 1.4, 0.5 < x < 0, 0 < y < 1  ∂xu = sin(x − 0.5) ∗ exp(y), 0 < y < 1, x = {0, 1} ∂nu = ∂yu = cos(x − 0.5) ∗ exp(y), 0 < x < 1, y = {0, 1}

178 The program implemented in GNU Octave run in octave-online.net, which is a web 179 UI for GNU Octave.

180 Acknowledgement.

181 This work is written posthumously, after the second author passed away. 182 The first author would like to thank program RKI 2020, that partially financed this work.

183 Daftar Pustaka

184 [1] Carstensen, C., 2009, Lectures on Adaptive Mixed Finite Element Methods. In: C. Carstensen, P. Wriggers: 185 Mixed finite element technologies, CISM Udine, Courses and Lectures No.509, Springer, Wien 186 [2] Bahriawati, C. Carstensen C., 2005, Three MATLAB implementations of the lowest-order Raviart-Thomas 187 MFEM with a posteriori error control. Computational Methods in Applied Mathematics, 5, pages 333-361. 188 [3] Axelsson, O, Blaheta, R., Byczanski, P., Kar atson J., and Ahmad, B,. 2015, Preconditioners for regularized 189 saddle point operators with an application for heterogeneous Darcy flow and transport problems. Journal 190 of Computational and Applied Mathematics, vol. 280, pages 141–157. 12Garnadi & Bahriawati, JMI Vol x No y Okt/Apr 2020, pp. xx-yy,doi:10.24198/jmi.vxx.ny.xxxx.y-yy

Gambar 10. Displacement

Gambar 11. Flux

191 [4] Akin, J.E., 2005, Finite Element Analysis with Errror Estimators, Wiley 192 [5] Braess, D. 2007., Finite Elements: Theory, Fast Solvers, and Applications in Solid Mechanics. Third ed., 193 Cambridge University Press 194 [6] Chen, L., Programming of finite element methods in MATLAB, 195 http : www.math.uci.edu/ chenlong/226/Ch3F EMCode.pdf on January 31,2020 196 [7] Faouzi Triki and Tao Yin., 2020,Inverse conductivity equation with internal data,arXiv, eprint= 2003.13638

197 LAMPIRAN

1981 % Program Darcy equation implementation based on 1992 % EBMFEM for2D Raviart −Thomas mixed 2003 % based on the edge−oriented basis function 2014 % 2025 % AgahD. Garnadi andC. Bahriawati 2036 % 2047 % File 2058 % 2069 %M −files you need to run 20710 % , , , , (optional) 20811 % Darcy - Raviart-Thomas Element 13

20912 % Data−(files) you need to prepare 21013 % coordinate , 21114 % element , 21215 % Dirichlet , 21316 % Neumann (optional) 21417 % 21518 % This program and corresponding data−files is modified from 21619 %"Three Matlab Implementations of the Lowest −Order Raviart−Thomas 21720 % MFEM witha Posteriori Error Control" by C.Bahriawati andC. Carstensen 21821 21922 % 22023 % A.1. The main program 22124 % load coordinate.dat; 22225 coordinate = [ 0 0; 0.5 0; 1 0; 1 0.5 ; 1 1; 0.5 1; 0 1; 0 0.5; 0.5 0.5];% 22326 % load element.dat; 22427 element = [2 8 1; 2 9 8 ; 2 4 9; 2 3 4; 9 4 5; 9 5 6; 9 6 7; 9 7 8];% 22528 % loadk element.dat; 22629 k element = [1 ; 1 ; 1.4 ; 1.4 ; 1.4 ; 1.4 ; 1 ; 1 ];% 22730 % load dirichlet.dat; 22831 dirichlet = [ 3 4; 4 5; 7 8 ; 8 1]; 22932 %load Neumann.dat; 23033 Neumann = [1 2; 2 3; 5 6; 6 7]; 23134 % 23235 [nodes2element,nodes2edge,noedges,edge2element,interioredge]=edge(element,coordinate); 23336 23437 % A.2. EBmfem 23538 %functionu=EBmfem(element,coordinate,dirichlet,Neumann,nodes2element,... 23639 % nodes2edge,noedges,edge2element); 23740 23841 % Assemble matricesB andC 23942 B=sparse(noedges, noedges); 24043 C=sparse(noedges,size(element,1)); 24144 for j = 1:size(element,1) 24245 coord=coordinate(element(j,:),:)'; 24346 I=diag(nodes2edge(element(j,[2 3 1]),element(j,[3 1 2]))); 24447 signum=ones(1,3); 24548 signum(find(j==edge2element(I,4)))=−1; 24649 B element = k element(j)*diag(signum)*stimaB(coord)*diag(signum); 24750 n=coord(:,[3,1,2])−coord(:,[2,3,1]); 24851 B(I,I)= B(I,I) + B element ; 24952 C(I,j) = diag(signum)*[norm(n(:,1)) norm(n(:,2)) norm(n(:,3))]'; 25053 end 25154 % Global stiffness matrixA 25255 A = sparse(noedges+size(element,1), noedges+size(element,1)); 25356 A = [B , C, ; 25457 C', sparse(size(C,2),size(C,2))]; 25558 % Volume force 25659 b = sparse(noedges+size(element ,1),1); 25760 for j = 1:size(element ,1) 25861 b(noedges+j)= −det([1,1,1; coordinate(element(j,:),:)']) * ... 25962 f(sum(coordinate(element(j,:),:))/3)/6; 26063 end 26164 % Dirichlet conditions 26265 for k = 1:size(dirichlet,1) 26366 b(nodes2edge(dirichlet(k,1),dirichlet(k,2)))= norm(coordinate(dirichlet(k,1),:)−... 26467 coordinate(dirichlet(k,2),:))*u D(sum(coordinate(dirichlet(k,:),:))/2); 26568 end 26669 % Neumann conditions 14Garnadi & Bahriawati, JMI Vol x No y Okt/Apr 2020, pp. xx-yy,doi:10.24198/jmi.vxx.ny.xxxx.y-yy

26770 if ¬isempty(Neumann) 26871 tmp=zeros(noedges+size(element,1),1); 26972 tmp(diag(nodes2edge(Neumann(:,1),Neumann(:,2))))=... 27073 ones(size(diag(nodes2edge(Neumann(:,1),Neumann(:,2))),1),1); 27174 FreeEdge=find(¬tmp); 27275 x=zeros(noedges+size(element,1),1); 27376 CN=coordinate(Neumann(:,2),:)−coordinate(Neumann(:,1),:); 27477 for j=1:size(Neumann,1) 27578 x(nodes2edge(Neumann(j,1),Neumann(j,2)))=... 27679 g(sum(coordinate(Neumann(j,:),:))/2,CN(j,:)*[0,−1;1,0]/norm(CN(j,:))); 27780 end 27881 b=b−A*x; 27982 x(FreeEdge)=A(FreeEdge,FreeEdge)\b(FreeEdge); 28083 else 28184 x = A\b; 28285 end 28386 figure(1) 28487 ShowDisplacement(element,coordinate,x); 28588 p=fluxEB(element,coordinate,x,noedges,nodes2edge,edge2element); 28689 figure(2) 28790 ShowFlux(element,coordinate,p); 28891 pEval=fluxEBEval(element,coordinate,x,nodes2edge,edge2element);

289 1