-
Notifications
You must be signed in to change notification settings - Fork 0
/
fem1d.f90
71 lines (54 loc) · 1.53 KB
/
fem1d.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
program fem1d
use linear_system
use discretisation
use solver
use save_data
use estimation_error
implicit none
integer :: n, p
double precision :: alpha, error_max
double precision, allocatable :: b(:), err(:), u(:), usol(:), xk(:), yk(:)
double precision, allocatable :: a(:,:)
write (6,*) ''
write (6,*) '1D Finite element method'
write (6,*) ''
write (6,*) '-u'''' + u = f in ]0,1['
write (6,*) 'u''(0) = alpha'
write (6,*) 'u(1) = 0'
write (6,*) ''
write (6,'(a,$)') 'Enter alpha: '
read (5,*) alpha
write (6,'(a,$)') 'Enter the number of elements n: '
read (5,*) n
allocate(xk(n+1))
allocate(a(n,n))
allocate(b(n))
allocate(u(n))
! We are first shaping the linear system and we are resolving it
call mesh(n,xk) !creating the mesh from the space ]0,1[
call calAB(alpha,n,xk,a,b) !shaping of the matrix A and vector b
call solve(a,b,n,u) !Resolving the linear system Au=b
! Then we put the solution on a file sol.dat
write (6,*) ''
write(6,'(a,$)') 'Enter the number of point of the solution to show: '
read (5,*) p
p = p-1
p = p/2*2
write (6,*) ''
allocate(yk(p+1))
allocate(usol(p))
call mesh(p,yk)
call read_sol(u,alpha,n,p,yk,usol)
! Now we can estimate the error
allocate(err(p))
call error(usol,alpha,yk,p,err,error_max)
write (6,*) 'error_max = ', error_max
! Job done, we deallocate everything
deallocate(a)
deallocate(b)
deallocate(err)
deallocate(u)
deallocate(usol)
deallocate(xk)
deallocate(yk)
end program fem1d