14 integer :: neq, norder, nvar, gts_status
21 real*8,
ALLOCATABLE :: AA(:,:)
22 real*8,
ALLOCATABLE :: BB(:)
23 integer :: LDA, N, KL, KU
28 real*8,
ALLOCATABLE :: x_grid(:,:),xg(:)
34 integer,
parameter :: Ngauss = 4
35 real*8,
parameter :: Xgauss(Ngauss) = (/ -.861136311594053D0, -.339981043584856D0, .339981043584856D0, .861136311594053D0 /)
36 real*8,
parameter :: Wgauss(Ngauss) = (/ .347854845137454D0, .652145154862546D0, .652145154862546D0, .347854845137454D0 /)
41 real*8,
allocatable :: values(:), deltas(:)
46 real*8 :: theta, zeta, gamma, hyper
51 real*8,
allocatable :: mass(:,:,:), diff(:,:,:), conv(:,:,:), reac(:,:,:), source(:,:), hyper2(:,:,:)
74 integer :: ifail, n_steps, n_in, istep, i, j, ia
75 real*8 :: timestep, time, timestep1, timestep2
76 real*8 :: dxds, bnd_err1, bnd_err2
94 if (.not.
allocated(values))
allocate(values(n_grid * nvar * neq))
96 if (.not.
allocated(deltas))
then
97 allocate(deltas(n_grid * nvar * neq))
123 time = time + timestep
132 solver%y(j,i) = values(ia)
133 solver%dy(j,i) = values(ia+neq) / dxds
137 if (
allocated(values))
deallocate(values)
138 if (
allocated(deltas))
deallocate(deltas)
139 if (
allocated(mass))
deallocate(mass)
140 if (
allocated(diff))
deallocate(diff)
141 if (
allocated(reac))
deallocate(reac)
142 if (
allocated(conv))
deallocate(conv)
143 if (
allocated(source))
deallocate(source)
144 if (
allocated(hyper2))
deallocate(hyper2)
145 if (
allocated(aa))
deallocate(aa)
146 if (
allocated(bb))
deallocate(bb)
147 if (
allocated(x_grid))
deallocate(x_grid)
148 if (
allocated(xg))
deallocate(xg)
155 REAL*8 FUNCTION spwert(N,XWERT,A,B,C,D,X,ABLTG)
172 REAL*8 xwert, a(n), b(n), c(n), d(n), x(n), abltg(3), xx
183 IF(xwert.LT.x(m))
THEN
193 abltg(1) = (3.0d0 * d(i) * xx + 2.0d0 * c(i)) * xx + b(i)
194 abltg(2) = 6.0d0 * d(i) * xx + 2.0d0 * c(i)
195 abltg(3) = 6.0d0 * d(i)
197 spwert = ((d(i)*xx + c(i))*xx + b(i))*xx + a(i)
213 real*8 :: gts_a(neq,n_in), gts_b(neq,n_in), gts_c(neq,n_in), gts_d(neq,n_in)
214 real*8 :: gts_e(neq,n_in), gts_f(neq,n_in), gts_g(neq,n_in), gts_h
215 real*8 :: x_in(n_in), c_in(n_in), spline_a(n_in), spline_b(n_in), spline_c(n_in), spline_d(n_in)
216 real*8 :: derivs(3), scale
217 integer :: n_in, index, in, j, m, npoints, i
220 npoints = ngauss * (n_grid-1)
222 if (.not.
allocated(mass))
allocate(mass(npoints,neq,neq))
223 if (.not.
allocated(diff))
allocate(diff(npoints,neq,neq))
224 if (.not.
allocated(reac))
allocate(reac(npoints,neq,neq))
225 if (.not.
allocated(conv))
allocate(conv(npoints,neq,neq))
226 if (.not.
allocated(source))
allocate(source(npoints,neq))
227 if (.not.
allocated(hyper2))
allocate(hyper2(npoints,neq,neq))
238 c_in(1:n_in) = gts_b(in,1:n_in) * gts_c(in,1:n_in)
244 call
spline(n_in,x_in,c_in,0.0d0,0.0d0,2,spline_a,spline_b,spline_c,spline_d)
248 index = ngauss*(j-1) + m
249 mass(index,in,in) =
spwert(n_in,xg(index),spline_a,spline_b,spline_c,spline_d,x_in,derivs)
253 c_in(1:n_in) = gts_d(in,1:n_in) * gts_h
257 call
spline(n_in,x_in,c_in,0.0d0,0.0d0,2,spline_a,spline_b,spline_c,spline_d)
261 index = ngauss*(j-1) + m
262 diff(index,in,in) =
spwert(n_in,xg(index),spline_a,spline_b,spline_c,spline_d,x_in,derivs)
263 hyper2(index,in,in) = 0.001d0 * gts_h * derivs(2)**2
267 c_in(1:n_in) = gts_e(in,1:n_in) * gts_h
271 call
spline(n_in,x_in,c_in,0.0d0,0.0d0,2,spline_a,spline_b,spline_c,spline_d)
275 index = ngauss*(j-1) + m
276 conv(index,in,in) =
spwert(n_in,xg(index),spline_a,spline_b,spline_c,spline_d,x_in,derivs)
280 c_in(1:n_in) = gts_c(in,1:n_in) * (gts_b(in,1:n_in) - gts_a(in,1:n_in) - gts_g(in,1:n_in) * gts_h )
284 call
spline(n_in,x_in,c_in,0.0d0,0.0d0,2,spline_a,spline_b,spline_c,spline_d)
288 index = ngauss*(j-1) + m
289 reac(index,in,in) =
spwert(n_in,xg(index),spline_a,spline_b,spline_c,spline_d,x_in,derivs)
294 c_in(1:n_in) = gts_c(in,1:n_in) * gts_f(in,1:n_in) * gts_h
298 call
spline(n_in,x_in,c_in,0.0d0,0.0d0,2,spline_a,spline_b,spline_c,spline_d)
302 index = ngauss*(j-1) + m
303 source(index, in) =
spwert(n_in,xg(index),spline_a,spline_b,spline_c,spline_d,x_in,derivs)
320 integer :: n_in, i, j, ia
321 real*8 :: x_in(n_in), y_in(neq,n_in), ym_in(neq,n_in), delta(n_in)
322 real*8 :: y_a(n_in), y_b(n_in), y_c(n_in), y_d(n_in)
323 real*8 :: d_a(n_in), d_b(n_in), d_c(n_in), d_d(n_in)
324 real*8 :: derivs(3), dxds
330 call
spline(n_in,x_in,y_in(j,1:n_in),0.0d0,0.0d0,2,y_a,y_b,y_c,y_d)
332 delta = y_in(j,:) - ym_in(j,:)
333 call
spline(n_in,x_in,delta,0.0d0,0.0d0,2,d_a,d_b,d_c,d_d)
341 values(ia) =
spwert(n_in,x_grid(1,i),y_a,y_b,y_c,y_d,x_in,derivs)
342 values(ia+neq) = derivs(1) * dxds
344 deltas(ia) =
spwert(n_in,x_grid(1,i),d_a,d_b,d_c,d_d,x_in,derivs)
345 deltas(ia+neq) = derivs(1) * dxds
369 real*8 :: elm(2*nvar*neq,2*nvar*neq),rhs(2*nvar*neq)
370 real*8 :: fe(2*nvar), dfe(2*nvar), ddfe(2*nvar)
371 real*8 :: time, timestep, eq0(neq), deq0(neq), ddeq0(neq), delta_eq0(neq)
372 real*8 :: xjac, dxds, xright, xleft
374 real*8 :: hyper_n(neq,neq)
376 integer :: mgauss, ia, ja, i, j, ife, m, k, l, in, jn, index
383 hyper_n(in,in) = hyper
395 index = (ife-1)*ngauss + m
397 xm = x_grid(1,ife) * fe(1) + x_grid(2,ife) * fe(2) &
398 + x_grid(1,ife+1) * fe(3) + x_grid(2,ife+1) * fe(4)
399 dxds = x_grid(1,ife) * dfe(1) + x_grid(2,ife) * dfe(2) &
400 + x_grid(1,ife+1) * dfe(3) + x_grid(2,ife+1) * dfe(4)
412 ia = (ife-1) * nvar * neq + (k-1)*neq + in
413 eq0(in) = eq0(in) + values(ia) * fe(k)
414 deq0(in) = deq0(in) + values(ia) * dfe(k) / dxds
415 ddeq0(in) = ddeq0(in) + values(ia) * ddfe(k) / dxds**2
416 delta_eq0(in) = delta_eq0(in) + deltas(ia) * fe(k)
428 ddv = ddfe(i) / dxds**2
436 elm(ia,ja) = elm(ia,ja) + wm * xjac * ( mass(index,in,jn) * v * fe(j) * (1.d0 + zeta) &
437 + diff(index,in,jn) * theta * timestep * dv * dfe(j) / dxds &
438 - conv(index,in,jn) * theta * timestep * dv * fe(j) &
439 - reac(index,in,jn) * theta * timestep * v * fe(j) ) &
441 + wm * xm * xjac * theta * timestep * hyper_n(in,jn) * ddv * ddfe(j)/dxds**2
448 rhs(ia) = rhs(ia) + wm * xjac * timestep * ( &
449 - diff(index,in,in) * deq0(in) * dv &
450 + conv(index,in,in) * eq0(in) * dv &
451 + reac(index,in,in) * eq0(in) * v &
452 + source(index,in) * v ) &
453 - wm * xm * xjac * timestep * hyper_n(in,in) * ddeq0(in) * ddv &
457 + wm * xjac * v * zeta * mass(index,in,in) * delta_eq0(in)
479 integer :: n_in, i, m, index,k, l
480 real*8 :: s_in(n_in), spline_a(n_in), spline_b(n_in), spline_c(n_in), spline_d(n_in)
481 real*8 :: fe(2*nvar), dfe(2*nvar), ddfe(2*nvar)
482 real*8 :: s_out, derivs(3),x_tmp,dxds
487 if (.not.
allocated(x_grid))
allocate(x_grid(2,n_grid))
488 if (.not.
allocated(xg))
allocate(xg(ngauss*(n_grid-1)))
491 s_in(i) = float(i-1)/float(n_in-1)
494 call
spline(n_in,s_in,x_in,0.0d0,0.0d0,2,spline_a,spline_b,spline_c,spline_d)
496 x_grid(1,1:n_grid) = x_in(1:n_in)
499 s_out = float(i-1)/float(n_grid-1)
500 x_tmp =
spwert(n_in,s_out,spline_a,spline_b,spline_c,spline_d,s_in,derivs)
501 x_grid(2,i) = derivs(1) / (2.d0 * float(n_grid-1))
512 index = ngauss*(i-1) + m
514 xg(index) = x_grid(1,i) * fe(1) + x_grid(2,i) * fe(2) + x_grid(1,i+1) * fe(3) + x_grid(2,i+1) * fe(4)
536 real*8 :: elm(2*nvar*neq,2*nvar*neq),rhs(2*nvar*neq)
537 real*8 :: u(neq,2), v(neq,2), w(neq,2), time, timestep, zbig
538 integer :: noff, nfe, ife, i, ia, j, ja, in
541 ku = 1 + 2*(neq*nvar-1)
546 n = n_grid * nvar * neq
548 if (.not.
allocated(aa))
ALLOCATE(aa(lda,n))
549 if (.not.
allocated(bb))
ALLOCATE(bb(n))
562 ia = (ife-1) * nvar * neq + i
566 ja = (ife-1) * nvar * neq + j
568 aa(noff+ia-ja,ja) = aa(noff+ia-ja,ja) + elm(i,j)
572 bb(ia) = bb(ia) + rhs(i)
583 aa(noff+ia-ja,ja) = v(in,1) * zbig / x_grid(2,1)
584 bb(ia) = w(in,1) * zbig - v(in,1) * values(ja) * zbig / x_grid(2,1)
587 aa(noff+ia-ja,ja) = u(in,1) * zbig
588 bb(ia) = bb(ia) - u(in,1) * values(ja) * zbig
593 ia = (n_grid-1) * nvar * neq + in
594 ja = (n_grid-1) * nvar * neq + in
596 aa(noff+ia-ja,ja) = u(in,2) * zbig
597 bb(ia) = w(in,2) * zbig - u(in,2) * values(ja) * zbig
599 ja = (n_grid-1) * nvar * neq + in + neq
600 aa(noff+ia-ja,ja) = v(in,2) * zbig / x_grid(2,n_grid)
601 bb(ia) = bb(ia) - v(in,2) * values(ja) * zbig / x_grid(2,n_grid)
615 real*8 :: fe(*),dfe(*),ddfe(*), xm
617 fe(1) = -0.25d0*(xm - 1.d0)**2 * (-xm - 2.d0); dfe(1) = -0.5d0*(xm - 1.d0) * (-xm - 2.d0) + 0.25d0*(xm - 1.d0)**2
618 fe(3) = -0.25d0*(xm + 1.d0)**2 * ( xm - 2.d0); dfe(3) = -0.5d0*(xm + 1.d0) * ( xm - 2.d0) - 0.25d0*(xm + 1.d0)**2
619 fe(2) = -0.25d0*(xm - 1.d0)**2 * (-xm - 1.d0); dfe(2) = -0.5d0*(xm - 1.d0) * (-xm - 1.d0) + 0.25d0*(xm - 1.d0)**2
620 fe(4) = +0.25d0*(xm + 1.d0)**2 * ( xm - 1.d0); dfe(4) = +0.5d0*(xm + 1.d0) * ( xm - 1.d0) + 0.25d0*(xm + 1.d0)**2
622 ddfe(1) = -0.5d0*(-xm - 2.d0) + 0.5d0*(xm - 1.d0) + 0.5d0*(xm - 1.d0)
623 ddfe(3) = -0.5d0*( xm - 2.d0) - 0.5d0*(xm + 1.d0) - 0.5d0*(xm + 1.d0)
624 ddfe(2) = -0.5d0*(-xm - 1.d0) + 0.5d0*(xm - 1.d0) + 0.5d0*(xm - 1.d0)
625 ddfe(4) = +0.5d0*( xm - 1.d0) + 0.5d0*(xm + 1.d0) + 0.5d0*(xm + 1.d0)
638 integer,
allocatable :: ipiv(:),iwork(:)
639 real*8,
allocatable :: work(:)
642 allocate(ipiv(n), work(3*n), iwork(n))
644 call dgbtrf(n,n,kl,ku,aa,lda,ipiv,info)
646 call dgbtrs(
'N',n,kl,ku,1,aa,lda,ipiv,bb,n,info)
648 deallocate(ipiv, work, iwork)
655 SUBROUTINE spline(N,X,Y,ALFA,BETA,TYP,A,B,C,D)
685 REAL*8 x(n), y(n), alfa, beta, a(n), b(n), c(n), d(n)
689 IF((typ.LT.0).OR.(typ.GT.3))
THEN
690 WRITE(*,*)
'ERROR IN ROUTINE SPLINE: FALSE TYP'
695 WRITE(*,*)
'ERROR IN ROUTINE SPLINE: N < 3'
705 IF(h(i).LE.0.0d0)
THEN
706 WRITE(*,*)
'NON MONOTONIC ABCISSAE IN SPLINE: X(I-1)>=X(I)'
714 a(i) = 3.0d0 * ((y(i+2)-y(i+1)) / h(i+1) - (y(i+1)-y(i)) / h(i))
717 d(i) = 2.0d0 * (h(i) + h(i+1))
725 a(1) = a(1) * h(2) / (h(1) + h(2))
726 a(n-2) = a(n-2) * h(n-2) / (h(n-1) + h(n-2))
728 d(n-2) = d(n-2) - h(n-1)
730 b(n-2) = b(n-2) - h(n-1)
736 a(1) = a(1) - 1.5d0 * ((y(2)-y(1)) / h(1) - alfa)
737 a(n-2) = a(n-2) - 1.5d0 * (beta - (y(n)-y(n-1)) / h(n-1))
738 d(1) = d(1) - 0.5d0 * h(1)
739 d(n-2) = d(n-2) - 0.5d0 * h(n-1)
745 a(1) = a(1) - 0.5d0 * alfa * h(1)
746 a(n-2) = a(n-2) - 0.5d0 * beta * h(n-1)
752 a(1) = a(1) + 0.5d0 * alfa * h(1) * h(1)
753 a(n-2) = a(n-2) - 0.5d0 * beta * h(n-1)* h(n-1)
755 d(n-2) = d(n-2) + h(n-1)
760 CALL
dgtsl(n-2,b,d,c,a,ierr)
768 CALL dcopy(n-2,a,1,c(2),1)
774 c(1) = c(2) + h(1) * (c(2)-c(3)) / h(2)
775 c(n) = c(n-1) + h(n-1) * (c(n-1)-c(n-2)) / h(n-2)
779 c(1) = 1.5d0*((y(2)-y(1)) / h(1) - alfa) / h(1) - 0.5d0 * c(2)
780 c(n) = -1.5d0*((y(n)-y(n-1)) / h(n-1)- beta) / h(n-1)- 0.5d0 * c(n-1)
789 c(1) = c(2) - 0.5d0 * alfa * h(1)
790 c(n) = c(n-1) + 0.5d0 * beta * h(n-1)
793 CALL dcopy(n,y,1,a,1)
796 b(i) = (a(i+1)-a(i)) / h(i) - h(i) * (c(i+1)+2.0d0 * c(i)) / 3.0d0
797 d(i) = (c(i+1)-c(i)) / (3.0d0 * h(i))
800 b(n) = (3.0d0 * d(n-1) * h(n-1) + 2.0d0 * c(n-1)) * h(n-1) + b(n-1)
804 21
FORMAT(1x,
'ERROR IN SGTSL: MATRIX SINGULAR')
815 REAL*8 c(*),d(*),e(*),b(*)
861 INTEGER k,kb,kp1,nm1,nm2
868 IF (nm1 .LT. 1) go to 40
878 IF (abs(c(kp1)) .LT. abs(c(k))) go to 10
898 IF (c(k) .NE. 0.0d0) go to 20
904 c(kp1) = d(kp1) + t*d(k)
905 d(kp1) = e(kp1) + t*e(k)
907 b(kp1) = b(kp1) + t*b(k)
910 IF (c(n) .NE. 0.0d0) go to 50
919 IF (n .EQ. 1) go to 80
920 b(nm1) = (b(nm1) - d(nm1)*b(n))/c(nm1)
921 IF (nm2 .LT. 1) go to 70
924 b(k) = (b(k) - d(k)*b(k+1) - e(k)*b(k+2))/c(k)
subroutine solution6(solver, ifail)
subroutine gts_finite_elements(xm, FE, DFE, DDFE)
subroutine gts_initialise_profiles(n_in, x_in, y_in, ym_in)
subroutine spline(N, X, Y, ALFA, BETA, TYP, A, B, C, D)
REAL *8 function spwert(N, XWERT, A, B, C, D, X, ABLTG)
subroutine gts_solve_matrix
subroutine gts_initialise_coefficients(n_in, x_in, gts_a, gts_b, gts_c, gts_d, gts_e, gts_f, gts_g, gts_h)
subroutine gts_element_matrix(ife, time, timestep, ELM, RHS)
subroutine gts_construct_grid(n_in, x_in)
subroutine dgtsl(N, C, D, E, B, INFO)
subroutine gts_construct_matrix(u, v, w, time, timestep)