78 integer,
parameter :: verb = 2
97 character(len=100),
parameter :: &
98 & mesh_file= trim(GMSH_DIR)//
"square/square_3.msh" 111 type(csr) :: mass, stiff, K
112 real(RP),
dimension(:),
allocatable :: rhs, u_h
117 real(RP) :: err_L2, err_H1
119 character(LEN=300) :: shell_com
132 write(*,*)
'poisson_2d: start' 134 write(*,*)
" RESOLUTION OF THE POISSON PROBLEM" 136 write(*,*)
" -Delta u + u = f on \Omega" 138 write(*,*)
" WITH A HOMOGENEOUS NEUMANN BOUNDARY CONDITION " 140 write(*,*)
" grad u . n = 0 on \partial\Omega" 144 write(*,*)
"================================== ASSEMBLING THE MESH " 145 msh = mesh(mesh_file,
'gmsh')
146 if (verb>1)
call print(msh)
149 write(*,*)
"================================== ASSEMBLING THE& 150 & FINITE ELEMENT SPACE" 154 if (verb>1)
call print(x_h)
157 write(*,*)
"================================== ASSEMBLING THE& 158 & INTEGRATION METHOD ON \Omega" 162 if (verb>1)
call print(qdm)
165 write(*,*)
"================================== ASSEMBLING THE& 166 & MASS AND STIFFNESS MATRICES" 169 call diffusion_massmat(mass , one_r3, x_h, qdm)
172 call diffusion_stiffmat(stiff, emetric, x_h, qdm)
175 call add(k, stiff, 1._rp, mass, 1._rp)
178 write(*,*)
"================================== RIGHT HAND SIDE 'F'" 183 call l2_product(rhs,
f, x_h, qdm)
186 write(*,*)
"================================== SOLVE THE LINEAR SYSTEM& 190 kry = krylov(
kry_cg, tol=1
e-6_rp, itmax=1000, verb=verb)
191 if (verb>1)
call print(kry)
194 call allocmem(u_h, x_h%nbDof)
198 call solve(u_h, kry, rhs, k)
201 write(*,*)
"================================== POST-TREATMENT" 208 write(*,*)
"Numerical errors" 209 err_l2 = l2_dist(
u, u_h, x_h, qdm)
210 err_h1 = l2_dist_grad(
grad_u, u_h, x_h, qdm)
211 write(*,*)
" Error | u - u_h|_L2 =", err_l2
212 write(*,*)
" Error |\nabla (u - u_h)|_L2 =", err_h1
219 write(*,*)
"Graphical display" 221 shell_com =
'poisson_2d_u.msh' 224 call write(x_h, trim(shell_com),
'gmsh')
227 call gmsh_addview(x_h, u_h, &
229 &
'Poisson problem: numerical solution', 0.0_rp, 1)
232 shell_com =
'gmsh -option '//trim(gmsh_dir)//
'gmsh-options-view'&
233 & //
' '//trim(shell_com)
234 call system(shell_com)
249 real(RP),
dimension(3),
intent(in) :: x
251 f = (2._rp * pi**2 + 1._rp) * cos(pi*x(1)) * cos(pi*x(2))
262 real(RP),
dimension(3),
intent(in) :: x
264 u = cos(pi*x(1)) * cos(pi*x(2))
273 real(RP),
dimension(3) :: grad_u
274 real(RP),
dimension(3),
intent(in) :: x
276 grad_u(1) =-pi * sin(pi*x(1)) * cos(pi*x(2))
277 grad_u(2) =-pi * cos(pi*x(1)) * sin(pi*x(2))
subroutine, public choral_init(verb)
Initialisation for the CHORAL library
TOP-LEVEL MODULE FOR THE LIBRARY CHORAL
integer, parameter fe_p2_2d
real(rp) function e(x, v1, v2)
real(rp) function, dimension(3) grad_u(x)
gradient of the exact solution
real(rp) function f(x)
right hand side 'f'
real(rp) function u(x)
exact solution 'u'
program poisson_2d
SOLVES THE POISSON PROBLEM with homogeneous Neumann boundary conditions
integer, parameter quad_gauss_trg_12
integer, parameter kry_cg
CG linear solver.