Nek5000
SEM for Incompressible NS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
math.F90
Go to the documentation of this file.
1 
2 real(DP) FUNCTION vlsc3(X,Y,B,N)
3  use kinds, only : dp
4  use opctr, only : isclld, nrout, myrout, rname, dct, ncall, dcount
5  implicit none
6 
7  integer, intent(in) :: n
8  real(DP), intent(in) :: X(n),Y(n),B(n)
9 
10  REAL(DP) :: DT, T
11  integer :: isbcnt, i
12 
13 #ifndef NOTIMER
14  if (isclld == 0) then
15  isclld=1
16  nrout=nrout+1
17  myrout=nrout
18  rname(myrout) = 'VLSC3 '
19  endif
20  isbcnt = 3*n
21  dct(myrout) = dct(myrout) + float(isbcnt)
22  ncall(myrout) = ncall(myrout) + 1
23  dcount = dcount + float(isbcnt)
24 #endif
25 
26  dt = 0.0
27  DO 10 i=1,n
28  t = x(i)*y(i)*b(i)
29  dt = dt+t
30  10 END DO
31  t=dt
32  vlsc3 = t
33  RETURN
34 END FUNCTION vlsc3
35 
36 !-----------------------------------------------------------------------
38 SUBROUTINE blank(A,N)
39  implicit none
40  CHARACTER(1) :: A(*)
41  integer :: n
42  CHARACTER(1) :: BLNK = ' '
43  integer :: i
44 
45  DO 10 i=1,n
46  a(i)=blnk
47  10 END DO
48  RETURN
49 END SUBROUTINE blank
50 
51 !-----------------------------------------------------------------------
52 subroutine copy(a,b,n)
53  use kinds, only : dp
54  implicit none
55  integer :: n
56  real(DP) :: a(n),b(n)
57  a = b
58 
59  return
60 end subroutine copy
61 
62 !-----------------------------------------------------------------------
63 subroutine chcopy(a,b,n)
64  implicit none
65  integer :: n, i
66  CHARACTER(1) :: A(n), B(n)
67 
68  DO 100 i = 1, n
69  a(i) = b(i)
70  100 END DO
71  return
72 end subroutine chcopy
73 
74 !-----------------------------------------------------------------------
76 real(DP) function vlamax(vec,n)
77  use kinds, only : dp
78  implicit none
79  integer, intent(in) :: n
80  REAL(DP), intent(in) :: VEC(n)
81  integer :: i
82 
83  real(DP) :: TAMAX = 0.0
84 
85  DO i=1,n
86  tamax = max(tamax,abs(vec(i)))
87  END DO
88 
89  vlamax = tamax
90  return
91 end function vlamax
92 
93 !-----------------------------------------------------------------------
95 subroutine vcross (u1,u2,u3,v1,v2,v3,w1,w2,w3,n)
96  use kinds, only : dp
97  implicit none
98 
99  integer, intent(in) :: n
100  real(DP), intent(out) :: U1(n), U2(n), U3(n)
101  real(DP), intent(in) :: V1(n), V2(n), V3(n)
102  real(DP), intent(in) :: W1(n), W2(n), W3(n)
103  integer :: i
104 
105  DO i=1,n
106  u1(i) = v2(i)*w3(i) - v3(i)*w2(i)
107  u2(i) = v3(i)*w1(i) - v1(i)*w3(i)
108  u3(i) = v1(i)*w2(i) - v2(i)*w1(i)
109  END DO
110 
111  return
112 end subroutine vcross
113 
114 !-----------------------------------------------------------------------
116 integer function mod1(i,n)
117  implicit none
118  integer, intent(in) :: i, n
119  integer :: ii
120  mod1=0
121  IF (i == 0) THEN
122  return
123  ENDIF
124  IF (n == 0) THEN
125  WRITE(6,*) &
126  'WARNING: Attempt to take MOD(I,0) in function mod1.'
127  return
128  ENDIF
129  ii = i+n-1
130  mod1 = mod(ii,n)+1
131  return
132 end function mod1
133 
134 !-----------------------------------------------------------------------
135 integer function log2(k)
136  use kinds, only : dp
137  implicit none
138  integer, intent(in) :: k
139  real(DP) :: rk, rlog, rlog2
140 
141  rk=(k)
142  rlog=log10(rk)
143  rlog2=log10(2.0)
144  rlog=rlog/rlog2+0.5
145  log2=int(rlog)
146  return
147 end function log2
148 
149 !-----------------------------------------------------------------------
152 subroutine iswap(b,ind,n,temp)
153  implicit none
154  integer, intent(in) :: n
155  integer, intent(in) :: ind(n)
156  integer, intent(inout) :: b(n)
157  integer, intent(out) :: temp(n) ! scratch
158  integer :: i, jj
159 
160  DO i=1,n
161  jj=ind(i)
162  temp(i)=b(jj)
163  END DO
164  DO i=1,n
165  b(i)=temp(i)
166  END DO
167  return
168 end subroutine iswap
169 
170 !-----------------------------------------------------------------------
171 ! Vector reduction routines which require communication
172 ! on a parallel machine. These routines must be substituted with
173 ! appropriate routines which take into account the specific architecture.
174 
175 !----------------------------------------------------------------------------
177 real(DP) function glsc3(a,b,mult,n)
178  use kinds, only : dp
179  use opctr
180  implicit none
181  integer, intent(in) :: n
182  REAL(DP), intent(in) :: A(n),B(n),MULT(n)
183  REAL(DP) :: TMP,WORK(1)
184  integer :: i, isbcnt
185 
186 #ifndef NOTIMER
187  if (isclld == 0) then
188  isclld=1
189  nrout=nrout+1
190  myrout=nrout
191  rname(myrout) = 'glsc3 '
192  endif
193  isbcnt = 3*n
194  dct(myrout) = dct(myrout) + (isbcnt)
195  ncall(myrout) = ncall(myrout) + 1
196  dcount = dcount + (isbcnt)
197 #endif
198 
199  tmp = 0.0
200  DO i=1,n
201  tmp = tmp + a(i)*b(i)*mult(i)
202  END DO
203  CALL gop(tmp,work,'+ ',1)
204  glsc3 = tmp
205  return
206 end function glsc3
207 
208 !-----------------------------------------------------------------------
210 real(DP) function glsc2(x,y,n)
211  use kinds, only : dp
212  use opctr
213  integer, intent(in) :: n
214  real(DP), intent(in) :: x(n), y(n)
215  real(DP) :: tmp,work(1)
216  integer :: i, isbcnt
217 
218 #ifndef NOTIMER
219  if (isclld == 0) then
220  isclld=1
221  nrout=nrout+1
222  myrout=nrout
223  rname(myrout) = 'glsc2 '
224  endif
225  isbcnt = 2*n
226  dct(myrout) = dct(myrout) + (isbcnt)
227  ncall(myrout) = ncall(myrout) + 1
228  dcount = dcount + (isbcnt)
229 #endif
230 
231  tmp=0.0
232  do i=1,n
233  tmp = tmp+ x(i)*y(i)
234  END DO
235  CALL gop(tmp,work,'+ ',1)
236  glsc2 = tmp
237  return
238 end function glsc2
239 
240 !-----------------------------------------------------------------------
242 real(DP) function glsc23(x,y,z,n)
243  use kinds, only : dp
244  implicit none
245  integer :: n
246  real(DP), intent(in) :: x(n), y(n),z(n)
247  real(DP) :: tmp,work(1), ds
248  integer :: i
249 
250  ds = 0.0
251  do i=1,n
252  ds=ds+x(i)*x(i)*y(i)*z(i)
253  END DO
254  tmp=ds
255  call gop(tmp,work,'+ ',1)
256  glsc23 = tmp
257  return
258 end function glsc23
259 
260 !-----------------------------------------------------------------------
261 real(DP) function glsum (x,n)
262  use kinds, only : dp
263  implicit none
264  integer, intent(in) :: n
265  real(DP), intent(in) :: X(n)
266  real(DP) :: TMP(1),WORK(1), tsum
267  integer :: i
268  tsum = 0._dp
269  DO i=1,n
270  tsum = tsum+x(i)
271  END DO
272  tmp(1)=tsum
273  CALL gop(tmp,work,'+ ',1)
274  glsum = tmp(1)
275  return
276 end function glsum
277 
278 !-----------------------------------------------------------------------
279 real(DP) function glamax(a,n)
280  use kinds, only : dp
281  implicit none
282  integer :: n
283  REAL(DP) :: A(n)
284  real(DP) :: TMP(1),WORK(1), tmax
285  integer :: i
286  tmax = 0.0
287  DO i=1,n
288  tmax = max(tmax,abs(a(i)))
289  END DO
290  tmp(1)=tmax
291  CALL gop(tmp,work,'M ',1)
292  glamax=abs(tmp(1))
293  return
294 end function glamax
295 
296 !-----------------------------------------------------------------------
297 integer function iglmin(a,n)
298  implicit none
299  integer, intent(in) :: n, a(n)
300  integer :: tmp(1),work(1), tmin, i
301  tmin= 999999999
302  do i=1,n
303  tmin=min(tmin,a(i))
304  enddo
305  tmp(1)=tmin
306  call igop(tmp,work,'m ',1)
307  iglmin=tmp(1)
308  return
309 end function iglmin
310 
311 !-----------------------------------------------------------------------
312 integer function iglmax(a,n)
313  implicit none
314  integer, intent(in) :: n, a(n)
315  integer :: tmp(1),work(1), tmax, i
316  tmax= -999999999
317  do i=1,n
318  tmax=max(tmax,a(i))
319  enddo
320  tmp(1)=tmax
321  call igop(tmp,work,'M ',1)
322  iglmax=tmp(1)
323  return
324 end function iglmax
325 
326 !-----------------------------------------------------------------------
327 integer function iglsum(a,n)
328  implicit none
329  integer, intent(in) :: n
330  integer, intent(in) :: a(n)
331  integer :: tmp(1),work(1),tsum, i
332  tsum= 0
333  do i=1,n
334  tsum=tsum+a(i)
335  enddo
336  tmp(1)=tsum
337  call igop(tmp,work,'+ ',1)
338  iglsum=tmp(1)
339  return
340 end function iglsum
341 
342 !-----------------------------------------------------------------------
344 integer(i8) function i8glsum(a,n)
345  use kinds, only : i8
346  integer, intent(in) :: n
347  integer(i8), intent(in) :: a(n)
348 
349  integer(i8) :: tsum, tmp(1),work(1)
350  integer :: i
351 
352  tsum= 0
353  do i=1,n
354  tsum=tsum+a(i)
355  enddo
356  tmp(1)=tsum
357  call i8gop(tmp,work,'+ ',1)
358  i8glsum=tmp(1)
359  return
360 END function
361 
362 !-----------------------------------------------------------------------
363 real(DP) function glmax(a,n)
364  use kinds, only : dp
365  implicit none
366 
367  integer, intent(in) :: n
368  REAL(DP), intent(in) :: A(n)
369  real(DP) :: TMP(1),WORK(1), tmax
370  integer :: i
371 
372  tmax=-99.0e20
373  DO i=1,n
374  tmax=max(tmax,a(i))
375  END DO
376  tmp(1)=tmax
377  CALL gop(tmp,work,'M ',1)
378  glmax=tmp(1)
379  return
380 end function glmax
381 
382 !-----------------------------------------------------------------------
383 real(DP) function glmin(a,n)
384  use kinds, only : dp
385  implicit none
386  integer, intent(in) :: n
387  REAL(DP), intent(in) :: A(n)
388  real(DP) :: TMP(1),WORK(1), tmin
389  integer :: i
390  tmin=99.0e20
391  DO i=1,n
392  tmin=min(tmin,a(i))
393  END DO
394  tmp(1)=tmin
395  CALL gop(tmp,work,'m ',1)
396  glmin = tmp(1)
397  return
398 end function glmin
399 
400 !-----------------------------------------------------------------------
402 subroutine gllog(la,lb)
403  use kinds, only : dp
404  implicit none
405  LOGICAL :: LA,LB
406  real(DP) :: TMP(1),WORK(1)
407 
408  tmp(1)=1._dp
409  IF (lb) THEN
410  IF (la) tmp(1)=0._dp
411  ELSE
412  IF ( .NOT. la) tmp(1)=0._dp
413  ENDIF
414  CALL gop(tmp,work,'* ',1)
415  IF (tmp(1) == 0._dp) la=lb
416  return
417 end subroutine gllog
418 
419 !-----------------------------------------------------------------------
421 subroutine isort(a,ind,n)
422  implicit none
423  integer :: n
424  integer :: a(n),ind(n)
425  integer :: aa, j, i, ii, ir, l
426 
427  dO 10 j=1,n
428  ind(j)=j
429  10 END DO
430 
431  if (n <= 1) return
432  l=n/2+1
433  ir=n
434  100 continue
435  if (l > 1) then
436  l=l-1
437  aa = a(l)
438  ii = ind(l)
439  else
440  aa = a(ir)
441  ii = ind(ir)
442  a(ir) = a( 1)
443  ind(ir) = ind( 1)
444  ir=ir-1
445  if (ir == 1) then
446  a(1) = aa
447  ind(1) = ii
448  return
449  endif
450  endif
451  i=l
452  j=l+l
453  200 continue
454  if (j <= ir) then
455  if (j < ir) then
456  if ( a(j) < a(j+1) ) j=j+1
457  endif
458  if (aa < a(j)) then
459  a(i) = a(j)
460  ind(i) = ind(j)
461  i=j
462  j=j+j
463  else
464  j=ir+1
465  endif
466  goto 200
467  endif
468  a(i) = aa
469  ind(i) = ii
470  goto 100
471 
472 end subroutine isort
473 
474 !-------------------------------------------------------
476 subroutine sort(a,ind,n)
477  use kinds, only : dp
478  implicit none
479  integer :: n
480  real(DP) :: a(n),aa
481  integer :: ind(n)
482  integer :: j, i, ii, ir, l
483 
484  dO 10 j=1,n
485  ind(j)=j
486  10 END DO
487 
488  if (n <= 1) return
489  l=n/2+1
490  ir=n
491  100 continue
492  if (l > 1) then
493  l=l-1
494  aa = a(l)
495  ii = ind(l)
496  else
497  aa = a(ir)
498  ii = ind(ir)
499  a(ir) = a( 1)
500  ind(ir) = ind( 1)
501  ir=ir-1
502  if (ir == 1) then
503  a(1) = aa
504  ind(1) = ii
505  return
506  endif
507  endif
508  i=l
509  j=l+l
510  200 continue
511  if (j <= ir) then
512  if (j < ir) then
513  if ( a(j) < a(j+1) ) j=j+1
514  endif
515  if (aa < a(j)) then
516  a(i) = a(j)
517  ind(i) = ind(j)
518  i=j
519  j=j+j
520  else
521  j=ir+1
522  endif
523  goto 200
524  endif
525  a(i) = aa
526  ind(i) = ii
527  goto 100
528  end subroutine sort
529 
530 !-----------------------------------------------------------------------
532 integer(i8) function i8glmax(a,n)
533  use kinds, only : i8
534  integer, intent(in) :: n
535  integer(i8), intent(inout) :: a(n)
536  integer(i8) :: tmp(1),work(1),tmax
537  integer :: i
538 
539  tmax= -999999
540  do i=1,n
541  tmax=max(tmax,a(i))
542  enddo
543 
544  tmp(1)=tmax
545  call i8gop(tmp,work,'M ',1)
546 
547  i8glmax=tmp(1)
548  if (i8glmax == -999999) i8glmax=0
549 
550  return
551 END function
552 
553 !-----------------------------------------------------------------------
555 subroutine ident(a,n)
556  use kinds, only : dp
557  implicit none
558  integer, intent(in) :: n
559  real(DP), intent(out) :: a(n,n)
560  integer :: i
561 
562  a = 0._dp
563  do i=1,n
564  a(i,i) = 1._dp
565  enddo
566  return
567 end subroutine ident
568 
569 !-----------------------------------------------------------------------
570 subroutine iswapt_ip(x,p,n)
571  implicit none
572  integer, intent(in) :: n
573  integer, intent(inout) :: x(n)
574  integer, intent(inout) :: p(n)
575 
576  integer :: j, k, loop_start, next, nextp, t1, t2
577 
578 ! In-place permutation: x'(p) = x
579 
580  do k=1,n
581  if (p(k) > 0) then ! not swapped
582  loop_start = k
583  next = p(loop_start)
584  t1 = x(loop_start)
585  do j=1,n
586  if (next < 0) then
587  write(6,*) 'Hey! iswapt_ip problem.',j,k,n,next
588  call exitt
589  elseif (next == loop_start) then
590  x(next) = t1
591  p(next) = -p(next)
592  goto 10
593  else
594  t2 = x(next)
595  x(next) = t1
596  t1 = t2
597  nextp = p(next)
598  p(next) = -p(next)
599  next = nextp
600  endif
601  enddo
602  10 continue
603  endif
604  enddo
605 
606  do k=1,n
607  p(k) = -p(k)
608  enddo
609  return
610 end subroutine iswapt_ip
real(dp) function glamax(a, n)
Definition: math.F90:279
integer function mod1(i, n)
Yields MOD(I,N) with the exception that if I=K*N, result is N.
Definition: math.F90:116
subroutine ident(a, n)
Construct A = I_n (identity matrix)
Definition: math.F90:555
real(dp) function glsc23(x, y, z, n)
Perform inner-product x*x*y*z.
Definition: math.F90:242
subroutine sort(a, ind, n)
Use Heap Sort (p 231 Num. Rec., 1st Ed.)
Definition: math.F90:476
real(dp) function vlamax(vec, n)
vector local max(abs( ))
Definition: math.F90:76
integer function log2(k)
Definition: math.F90:135
real(dp) function glmax(a, n)
Definition: math.F90:363
subroutine iswap(b, ind, n, temp)
SORT ASSOCIATED ELEMENTS BY PUTTING ITEM(JJ) into item(i) where JJ = ind(i)
Definition: math.F90:152
subroutine igop(x, w, op, n)
Global vector commutative operation.
Definition: comm_mpi.F90:152
subroutine vcross(u1, u2, u3, v1, v2, v3, w1, w2, w3, n)
Compute a Cartesian vector cross product.
Definition: math.F90:95
void exitt()
Definition: comm_mpi.F90:411
integer(i8) function i8glmax(a, n)
Global maximum of long integer array.
Definition: math.F90:532
real(dp) function glsum(x, n)
Definition: math.F90:261
real(dp) function glsc2(x, y, n)
Perform inner-product in double precision.
Definition: math.F90:210
subroutine copy(a, b, n)
Definition: math.F90:52
integer function iglmin(a, n)
Definition: math.F90:297
real(dp) function vlsc3(X, Y, B, N)
local inner product, with weight
Definition: math.F90:2
integer function iglmax(a, n)
Definition: math.F90:312
real(dp) function glmin(a, n)
Definition: math.F90:383
subroutine isort(a, ind, n)
Use Heap Sort (p 231 Num. Rec., 1st Ed.)
Definition: math.F90:421
subroutine blank(A, N)
blank a string
Definition: math.F90:38
real(dp) function glsc3(a, b, mult, n)
Perform inner-product in double precision.
Definition: math.F90:177
subroutine gop(x, w, op, n)
Global vector commutative operation.
Definition: comm_mpi.F90:104
subroutine chcopy(a, b, n)
Definition: math.F90:63
subroutine iswapt_ip(x, p, n)
Definition: math.F90:570
subroutine i8gop(x, w, op, n)
Global vector commutative operation.
Definition: comm_mpi.F90:181
integer(i8) function i8glsum(a, n)
global sum (long integer)
Definition: math.F90:344
integer function iglsum(a, n)
Definition: math.F90:327
subroutine gllog(la, lb)
If ANY LA=LB, then ALL LA=LB.
Definition: math.F90:402