ETS-Core  version:0.0.4-46-ge2d8
Core actors for the ETS-6
 All Classes Files Functions Variables Pages
interpolations.f90
Go to the documentation of this file.
1 
4 
5  USE l3interps
6  USE ids_schemas, ONLY: ids_real
7 
8  IMPLICIT NONE
9 
10 CONTAINS
11 
16  SUBROUTINE lininterp( YIN , XIN , NIN , YOUT , XOUT , NOUT )
17  REAL(8), INTENT(IN) :: yin(nin)
18  REAL(8), INTENT(IN) :: xin(nin)
19  REAL(8), INTENT(OUT) :: yout(nout)
20  REAL(8), INTENT(IN) :: xout(nout)
21  INTEGER, INTENT(IN) :: nin
22  INTEGER, INTENT(IN) :: nout
23 
24  ! Internal
25  REAL(8), PARAMETER :: very_small = sqrt(tiny(1.0d0))
26  REAL(8) :: frac
27  REAL(8) :: direction
28  INTEGER :: jin, jout
29 
30  ! Check for identical grids:
31  IF (nin == nout) THEN
32  IF ( maxval(abs(xin-xout)) < very_small) THEN
33  yout = yin
34  RETURN
35  END IF
36  END IF
37 
38  yout = -9.0d40
39 
40  direction = sign(1d0, xin(nin) - xin(1))
41 
42  DO jout = 1,nout
43  ! Increasing XIN (DIRECTION=+1), then XOUT-XIN(1) < 0 mean that XOUT < XIN(1)
44  ! Decreasing XIN (DIRECTION=-1), then -XOUT+XIN(1) < 0 mean that XOUT > XIN(1)
45  IF (direction * (xout(jout) - xin(1)) <= 0.0d0) THEN
46  yout(jout) = yin(1)
47  ELSEIF ( direction * (xout(jout) - xin(nin)) >= 0.0d0 ) THEN
48  yout(jout) = yin(nin)
49  ELSE
50  DO jin = 1,nin
51  IF (direction * (xout(jout) - xin(jin+1)) <= 0.0d0) THEN
52  frac = (xout(jout) - xin(jin)) / (xin(jin+1) - xin(jin))
53  yout(jout) = (1.0d0 - frac) * yin(jin) + frac * yin(jin+1)
54  EXIT
55  END IF
56  END DO
57  END IF
58  END DO
59  END SUBROUTINE lininterp
60 
61 
63  SUBROUTINE linderiv( YIN , XIN , NIN , YOUT , XOUT , NOUT )
64  REAL(8), INTENT(IN) :: yin(nin)
65  REAL(8), INTENT(IN) :: xin(nin)
66  REAL(8), INTENT(OUT) :: yout(nout)
67  REAL(8), INTENT(IN) :: xout(nout)
68  INTEGER, INTENT(IN) :: nin
69  INTEGER, INTENT(IN) :: nout
70 
71  ! Internal
72  REAL(8) :: dx
73  REAL(8) :: direction
74  INTEGER :: jin, jout
75 
76  yout = -9.0d40
77 
78  direction = sign(1d0, xin(nin) - xin(1))
79 
80  DO jout = 1,nout
81  ! Increasing XIN (DIRECTION=+1), then XOUT-XIN(1) < 0 mean that XOUT < XIN(1)
82  ! Decreasing XIN (DIRECTION=-1), then -XOUT+XIN(1) < 0 mean that XOUT > XIN(1)
83  IF (direction * (xout(jout) - xin(1)) <= 0.0d0) THEN
84  yout(jout) = (yin(2) - yin(1)) / (xin(2) - xin(1))
85  ELSEIF ( direction * (xout(jout) - xin(nin)) >= 0.0d0 ) THEN
86  yout(jout) = (yin(nin) - yin(nin-1)) / (xin(nin) - xin(nin-1))
87  ELSE
88  DO jin = 1,nin
89  IF (direction * (xout(jout) - xin(jin+1)) <= 0.0d0) THEN
90  yout(jout) = (yin(jin+1) - yin(jin)) / (xin(jin+1) - xin(jin))
91  EXIT
92  END IF
93  END DO
94  END IF
95  END DO
96  END SUBROUTINE linderiv
97 
98 
100  SUBROUTINE linderiv_pointer( YIN , XIN , YOUT , XOUT )
101  REAL(8), POINTER, INTENT(IN) :: yin(:)
102  REAL(8), POINTER, INTENT(IN) :: xin(:)
103  REAL(8), INTENT(OUT) :: yout(:)
104  REAL(8), INTENT(IN) :: xout(:)
105 
106  IF ( (.NOT. ASSOCIATED(xin)) .OR. (.NOT. ASSOCIATED(yin)) ) THEN
107  yout(:) = -9d40
108  RETURN
109  END IF
110  IF ( SIZE(xin) /= SIZE(yin) ) THEN
111  yout(:) = -9d40
112  RETURN
113  END IF
114 
115  CALL linderiv( yin , xin , SIZE(xin) , yout , xout , SIZE(xout) )
116 
117  END SUBROUTINE linderiv_pointer
118 
119 
120  SUBROUTINE l3interp_pointer( YIN , XIN , YOUT , XOUT )
121  REAL(8), POINTER, INTENT(IN) :: yin(:)
122  REAL(8), POINTER, INTENT(IN) :: xin(:)
123  REAL(8), INTENT(OUT) :: yout(:)
124  REAL(8), INTENT(IN) :: xout(:)
125 
126  IF ( (.NOT. ASSOCIATED(xin)) .OR. (.NOT. ASSOCIATED(yin)) ) THEN
127  yout(:) = -9d40
128  RETURN
129  END IF
130  IF ( SIZE(xin) /= SIZE(yin) ) THEN
131  yout(:) = -9d40
132  RETURN
133  END IF
134 
135  CALL l3interp( yin , xin , SIZE(xin) , yout , xout , SIZE(xout) )
136 
137  END SUBROUTINE l3interp_pointer
138 
139 
142  SUBROUTINE l3interp_alloc( YIN , XIN , YOUT , XOUT )
143  REAL(8), ALLOCATABLE, INTENT(IN) :: yin(:)
144  REAL(8), ALLOCATABLE, INTENT(IN) :: xin(:)
145  REAL(8), INTENT(OUT) :: yout(:)
146  REAL(8), INTENT(IN) :: xout(:)
147 
148  IF ( (.NOT. ALLOCATED(xin)) .OR. (.NOT. ALLOCATED(yin)) ) THEN
149  yout(:) = -9d40
150  RETURN
151  END IF
152  IF ( SIZE(xin) /= SIZE(yin) ) THEN
153  yout(:) = -9d40
154  RETURN
155  END IF
156 
157  CALL l3interp( yin , xin , SIZE(xin) , yout , xout , SIZE(xout) )
158 
159  END SUBROUTINE l3interp_alloc
160 
161 
164  SUBROUTINE l3deriv_pointer( YIN , XIN , YOUT , XOUT )
165  REAL(8), POINTER, INTENT(IN) :: yin(:)
166  REAL(8), POINTER, INTENT(IN) :: xin(:)
167  REAL(8), INTENT(OUT) :: yout(:)
168  REAL(8), INTENT(IN) :: xout(:)
169 
170  IF ( (.NOT. ASSOCIATED(xin)) .OR. (.NOT. ASSOCIATED(yin)) ) THEN
171  yout(:) = -9d40
172  RETURN
173  END IF
174  IF ( SIZE(xin) /= SIZE(yin) ) THEN
175  yout(:) = -9d40
176  RETURN
177  END IF
178 
179  CALL l3deriv( yin , xin , SIZE(xin) , yout , xout , SIZE(xout) )
180 
181  END SUBROUTINE l3deriv_pointer
182 
183 
186  SUBROUTINE l3deriv_alloc( YIN , XIN , YOUT , XOUT )
187  REAL(8), ALLOCATABLE, INTENT(IN) :: yin(:)
188  REAL(8), ALLOCATABLE, INTENT(IN) :: xin(:)
189  REAL(8), INTENT(OUT) :: yout(:)
190  REAL(8), INTENT(IN) :: xout(:)
191 
192  IF ( (.NOT. ALLOCATED(xin)) .OR. (.NOT. ALLOCATED(yin)) ) THEN
193  yout(:) = -9d40
194  RETURN
195  END IF
196  IF ( SIZE(xin) /= SIZE(yin) ) THEN
197  yout(:) = -9d40
198  RETURN
199  END IF
200 
201  CALL l3deriv( yin , xin , SIZE(xin) , yout , xout , SIZE(xout) )
202 
203  END SUBROUTINE l3deriv_alloc
204 
205 
207  REAL(IDS_REAL) FUNCTION integral(XIN, YIN)
208  USE prec_rkind, ONLY: rkind
209  USE interpos_module, ONLY: interpos
210  REAL(IDS_REAL), INTENT(IN) :: xin(:)
211  REAL(IDS_REAL), INTENT(IN) :: yin(:)
212 
213  ! Internal
214  REAL(RKIND) :: cum_integral(size(xin))
215  REAL(RKIND) :: xin_kind(size(xin))
216  REAL(RKIND) :: yin_kind(size(xin))
217  REAL(RKIND) :: ybc(2) = (/ 0.0_rkind , 0.0_rkind /) ! Both boundary condition are y''=0.
218  INTEGER :: nbc(2) = (/ 0 , 0 /) ! Specify y'' at both boundaries using YBC.
219  INTEGER :: nrho
220 
221  nrho=SIZE(xin)
222  xin_kind = REAL(xin, rkind)
223  yin_kind = REAL(yin, rkind)
224  CALL interpos(xin_kind, yin_kind, nrho, &
225  nrho, xout=xin_kind, youtint=cum_integral, nbc=nbc, ybc=ybc)
226  integral = REAL(CUM_INTEGRAL(NRHO), ids_real)
227 
228  END FUNCTION integral
229 
230 END MODULE interpolations
subroutine linderiv(YIN, XIN, NIN, YOUT, XOUT, NOUT)
Use linear interpolatation to calculate the derivatives YOUT at XOUT,.
subroutine linderiv_pointer(YIN, XIN, YOUT, XOUT)
Use linear interpolatation to calculate the derivatives YOUT at XOUT,.
subroutine l3interp_alloc(YIN, XIN, YOUT, XOUT)
Interpolate YIN(XIN) using L3INTERP, but the input arrays are allocatables.
subroutine l3deriv_alloc(YIN, XIN, YOUT, XOUT)
Calculate the derivative of YIN(XIN) using L3INTERP, but the input arrays are allocatables.
subroutine l3deriv_pointer(YIN, XIN, YOUT, XOUT)
Calculate the derivative of YIN(XIN) using L3INTERP, but the input arrays are pointers.
subroutine l3interp_pointer(YIN, XIN, YOUT, XOUT)
subroutine lininterp(YIN, XIN, NIN, YOUT, XOUT, NOUT)
Linear interpolatation and constant extrapolation. The input function is YIN given at XIN and with le...
Interpolations, derivatives and integrals of 1d functions. Includes wrappers to L3INTERP, L3DERIV and INTERPOS.
subroutine integral(n, h, r, f, int)
Definition: solution2.f90:527