100 integer ,
parameter :: verb = 2
104 real(RP),
parameter :: L_1 = 1.0_rp
105 real(RP),
parameter :: L_2 = 1.0_rp
116 integer ,
parameter :: fe_v =
fe_p2_2d 117 integer ,
parameter :: fe_s =
fe_p2_1d 120 character(LEN=1),
parameter :: mesh_idx =
"2" 128 type(quadmesh) :: qdm
131 character(len=100),
parameter :: mesh_file= &
132 & trim(GMSH_DIR)//
"square/square_"//mesh_idx//
".msh" 139 integer,
parameter :: prec_type =
pc_0 150 type(csr) :: mass, stiff, K
152 real(RP),
dimension(:),
allocatable :: rhs, u_h, aux
157 real(RP) :: err_L2, err_H1
159 character(LEN=300) :: shell_com
172 write(*,*)
'diffusion_Neumann: start' 174 write(*,*)
" EXAMPLE OF AN ELLIPTIC PROBLEM" 176 write(*,*)
" -div(B(x) grad u) + rho(x)u = f on \Omega" 178 write(*,*)
" WITH A NEUMANN BOUNDARY CONDITION " 180 write(*,*)
" B(x)grad u . n = g on \partial\Omega" 182 write(*,*)
" AND WITH AN ANISOTROPIC DIFFUSIVITY TENSOR B(x)." 184 write(*,*)
" The problem data 'B', 'u', 'f' and 'g' " 185 write(*,*)
" have been derived in" 186 write(*,*)
" choral/maple/example_diffusion_Neumann.mw" 192 write(*,*)
"================================== MESH ASSEMBLING" 193 msh = mesh(mesh_file,
'gmsh')
198 write(*,*)
"================================== FINITE ELEMENT& 207 write(*,*)
"================================== INTEGRATION METHOD& 208 & ON \Omega ASSEMBLING" 215 write(*,*)
"================================== MASS AND STIFFNESS& 217 call diffusion_massmat(mass ,
rho, x_h, qdm)
218 call diffusion_stiffmat(stiff,
bl_form_b, x_h, qdm)
222 write(*,*)
"================================== LINEAR SYSTEM MATRIX& 223 & AND PRECONDITIONING" 226 call add(k, stiff, 1._rp, mass, 1._rp)
233 pc = precond(k, prec_type)
237 write(*,*)
"================================== RIGHT HAND SIDE" 238 write(*,*)
" 1- COMPUTATION OF F" 243 call l2_product(rhs,
f, x_h, qdm)
247 write(*,*)
"================================== RIGHT HAND SIDE" 248 write(*,*)
" 2- COMPUTATION OF G" 255 call diffusion_neumann_rhs(aux,
g_x_0, x_h, qd_s,
x_le_0)
259 call diffusion_neumann_rhs(aux,
g_x_1, x_h, qd_s,
x_ge_1)
263 call diffusion_neumann_rhs(aux,
g_y_0, x_h, qd_s,
y_le_0)
267 call diffusion_neumann_rhs(aux,
g_y_1, x_h, qd_s,
y_ge_1)
271 write(*,*)
"================================== SOLVE LINEAR SYSTEM& 275 kry = krylov(
kry_cg, tol=1
e-10_rp, itmax=1000, verb=0)
279 call interp_scal_func(u_h,
u, x_h)
282 call solve(u_h, kry, rhs, k, pc)
290 write(*,*)
"================================== POST-TREATMENT" 296 shell_com =
'diff_Neumann_u.msh' 299 call write(x_h, trim(shell_com),
'gmsh')
302 call gmsh_addview(x_h, u_h, &
304 &
'Diffusion problem: numerical solution', 0.0_rp, 1)
307 shell_com =
'gmsh -option '//trim(gmsh_dir)//
'gmsh-options-view'&
308 & //
' '//trim(shell_com)
309 call system(shell_com)
318 write(*,*)
"Numerical errors" 319 err_l2 = l2_dist(
u, u_h, x_h, qdm)
320 err_h1 = l2_dist_grad(
grad_u, u_h, x_h, qdm)
321 write(*,*)
" Error | u - u_h|_L2 =", err_l2
322 write(*,*)
" Error |\nabla (u - u_h)|_L2 =", err_h1
333 real(RP),
dimension(3),
intent(in) :: x
335 u = sin(pi*x(1) ) * sin(pi*x(2))
343 real(RP),
dimension(3) :: grad_u
344 real(RP),
dimension(3),
intent(in) :: x
346 grad_u(1) = pi * cos(pi*x(1)) * sin(pi*x(2))
347 grad_u(2) = pi * sin(pi*x(1)) * cos(pi*x(2))
357 real(RP),
dimension(3),
intent(in) :: x
359 real(RP) :: cx, sx, cy, sy, aux
360 real(RP) :: t, ct, st
374 aux = 2.0_rp*ct*st - 2.0_rp*ct**2 + 1.0_rp
377 aux =-2.0_rp*ct*st - 2.0_rp*ct**2 + 1.0_rp
382 aux = 2.0_rp*(l_1+l_2)
385 f = f * pi**2 * 0.5_rp +
rho(x)*
u(x)
393 real(RP),
dimension(3),
intent(in) :: x
396 rho = log( 1.0_rp + rho)
403 function bl_form_b(x, w1, w2)
result(res)
405 real(RP),
dimension(3),
intent(in) :: x, w1, w2
407 real(RP),
dimension(2,2) :: B_x
408 real(RP),
dimension(2 ) :: B_w1
411 call matvecprod(b_w1, b_x, w1(1:2))
413 res = b_w1(1)*w2(1) + b_w1(2)*w2(2)
423 real(RP),
dimension(3),
intent(in) :: x
425 theta = 0.5_rp * pi * ( x(1) + x(2) )
432 real(RP),
dimension(2,2) :: B
433 real(RP),
dimension(3),
intent(in) :: x
441 t = l_1 * c**2 + l_2 * s**2
443 b(2,2) = l_1 + l_2 - t
445 t = (l_1 - l_2) * c*s
455 function x_le_0(x)
result(r)
457 real(RP),
dimension(3),
intent(in) :: x
466 function x_ge_1(x)
result(r)
468 real(RP),
dimension(3),
intent(in) :: x
476 function y_le_0(x)
result(r)
478 real(RP),
dimension(3),
intent(in) :: x
487 function y_ge_1(x)
result(r)
489 real(RP),
dimension(3),
intent(in) :: x
498 function g_x_0(x)
result(r)
500 real(RP),
dimension(3),
intent(in) :: x
502 real(RP) :: t, c2, s2
508 r = - pi * sin(pi*x(2)) * (l_1*c2 + l_2*s2)
515 function g_x_1(x)
result(r)
517 real(RP),
dimension(3),
intent(in) :: x
526 function g_y_0(x)
result(r)
528 real(RP),
dimension(3),
intent(in) :: x
530 real(RP) :: t, c2, s2
536 r = - pi * sin(pi*x(1)) * (l_1*s2 + l_2*c2)
543 function g_y_1(x)
result(r)
545 real(RP),
dimension(3),
intent(in) :: x
real(rp) function x_ge_1(x)
To characterise {x=1}.
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 g_y_1(x)
g(x) on {y=1}
integer, parameter quad_gauss_edg_4
real(rp) function x_le_0(x)
To characterise {x=0}.
real(rp) function bl_form_b(x, w1, w2)
real(rp) function e(x, v1, v2)
real(rp) function y_le_0(x)
To characterise {x=0}.
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'
real(rp) function y_ge_1(x)
To characterise {x=1}.
real(rp) function rho(x)
density '(x)'
real(rp) function g_y_0(x)
g(x) on {y=0}
real(rp) function g_x_0(x)
g(x) on {x=0}
real(rp) function g_x_1(x)
g(x) on {x=1}
integer, parameter quad_gauss_trg_12
real(rp) function theta(x)
Angle of the principal direction with e_x.
integer, parameter pc_0
void preconditioning
integer, parameter fe_p2_1d
integer, parameter kry_cg
CG linear solver.
real(rp) function b(x, w1, w2)
program diffusion_neumann
SOLVES THE DIFFUSION PROBLEM with Neumann boundary conditions