22 #include "sll_errors.h"
23 #include "sll_working_precision.h"
92 sll_int64,
intent(in) :: n
95 intrinsic :: not, iand
97 if ((n > 0) .and. (0 .eq. (iand(n, (n - 1)))))
then
106 sll_int32,
intent(in) :: n
111 if (modulo(n, 2) .eq. 0)
then
122 sll_int32,
intent(in) :: n
129 print *,
'ERROR, factorial_int32(): n < 0 or n > 20, if latter, ', &
130 'function will overflow a 64-bit integer. n = ', n
135 do i = int(n, kind=i64), 1, -1
147 sll_int64,
intent(in) :: n
153 if ((n < 0) .or. (n > 20))
then
154 print *,
'ERROR, factorial_int64(): either a negative n was passed: ', &
155 'or n > 20, which will overflow a 64-bit integer. n = ', n
170 integer,
intent(in) :: istep
171 character(len=*),
intent(out) :: cstep
174 character(len=8) :: str_fmt
178 if (istep >= 0 .and. istep < 10**l)
then
179 str_fmt =
"(I0"//char(l + 48)//
"."//char(l + 48)//
")"
180 write (cstep, str_fmt) istep
182 sll_warning(
'sll_s_int2string',
'index is negative or too big')
183 print *,
'index =', istep,
' cstep length = ', l
191 sll_int32,
intent(out) :: file_id
192 sll_int32,
intent(out) :: error
198 do 100 file_id = 20, 99
200 inquire (unit=file_id, opened=lopen)
204 open (file_id, status=
'SCRATCH', err=100)
205 close (file_id, status=
'DELETE', err=100)
218 sll_real64,
dimension(:),
intent(in) :: array
219 character(len=*),
intent(in) :: real_format
221 character(len=20) :: display_format
226 write (display_format,
"('(''|''',i4,a,''' |'')')") n, real_format
229 write (*, display_format) (array(i), i=1, n)
236 sll_int32,
dimension(:),
intent(in) :: array
237 character(len=*),
intent(in) :: integer_format
239 character(len=20) :: display_format
244 write (display_format,
"('(''|''',i4,a,''' |'')')") n, integer_format
247 write (*, display_format) (array(i), i=1, n)
254 sll_real64,
dimension(:, :),
intent(in) :: array
255 character(len=*),
intent(in) :: real_format
257 character(len=20) :: display_format
258 sll_int32 :: n1, n2, i, j
263 write (display_format,
"('(''|''',i4,a,''' |'')')") n2, real_format
267 write (*, display_format) (array(i, j), j=1, n2)
275 sll_int32,
dimension(:, :),
intent(in) :: array
276 character(len=*),
intent(in) :: integer_format
278 character(len=20) :: display_format
279 sll_int32 :: n1, n2, i, j
284 write (display_format,
"('(''|''',i4,a,''' |'')')") n2, integer_format
288 write (*, display_format) (array(i, j), j=1, n2)
297 sll_int32,
intent(out) :: data_file_id
298 sll_int32,
intent(out) :: thf_file_id
300 character(len=*),
parameter :: this_sub_name =
"initialize_file"
301 character(len=72) :: filename
305 call get_command_argument(1, filename)
308 open (data_file_id, file=trim(filename), iostat=io_stat)
309 if (io_stat /= 0) sll_error(this_sub_name,
"Miss argument file.nml")
312 open (thf_file_id, file=
"thf.dat", iostat=io_stat, position=
'append')
313 if (io_stat /= 0) sll_error(this_sub_name,
"Cannot open file thf.dat")
322 sll_int32,
intent(in) :: file_id
323 character(3),
intent(in) :: desc
324 character(14),
intent(in) :: fformat
325 sll_real64,
dimension(:),
intent(in) :: array
327 if (desc(1:3) ==
"thf")
then
328 open (file_id, file=
"thf.dat", position=
'append')
333 write (file_id, fformat) array
336 write (*, *) desc,
" not recognized"
351 sll_int32,
intent(in) :: n
352 sll_int32,
intent(in) :: numprocs
353 sll_int32,
intent(in) :: myid
354 sll_int32,
intent(out) :: s
355 sll_int32,
intent(out) :: e
362 deficit = mod(n, numprocs)
363 s = s + min(myid, deficit)
364 if (myid < deficit)
then
368 if (e > n .or. myid == numprocs - 1) e = n
389 sll_real64,
intent(out) :: s
390 sll_real64,
intent(in) :: t
391 sll_real64,
intent(in) :: tflat
392 sll_real64,
intent(in) :: tl
393 sll_real64,
intent(in) :: tr
394 sll_real64,
intent(in) :: twl
395 sll_real64,
intent(in) :: twr
396 sll_real64,
intent(in) :: t0
397 logical,
intent(in) :: turn_drive_off
399 sll_real64 :: epsilon
404 if (turn_drive_off)
then
405 epsilon = 0.5_f64*(tanh((t0 - tl)/twl) - tanh((t0 - tr)/twr))
406 s = 0.5_f64*(tanh((t - tl)/twl) - tanh((t - tr)/twr)) - epsilon
409 epsilon = 0.5_f64*(tanh((t0 - tl)/twl) + 1.0_f64)
410 s = 0.5_f64*(tanh((t - tl)/twl) + 1.0_f64) - epsilon
411 s = s/(1.0_f64 - epsilon)
416 s = s + 0.0_f64*tflat
437 sll_real64,
intent(inout) :: bloc_coord(2)
438 sll_int32,
intent(inout) :: bloc_index(3)
439 sll_int32,
intent(in) :: n
442 sll_int32 :: i1, i2, n_coarse, n_local, n_fine
453 if ((bloc_index(1) == 1) .and. (bloc_index(3) == 1))
then
455 n_local = bloc_index(2)
456 n_coarse = floor(real(n, f64)/(1._f64 + (b - a)*(real(n_local, f64) - 1._f64)))
457 if (n_local /= 1)
then
458 i2 = (n - n_coarse)/(n_local - 1)
460 i2 = floor((b - a)*real(n_coarse, f64))
462 n_coarse = n - i2*(n_local - 1)
463 i1 = floor(a*real(n_coarse, f64))
466 n_fine = n_local*(i2 - i1)
467 bloc_index(2) = n_fine
468 bloc_index(3) = n - i1 - n_fine
469 bloc_coord(1) = real(i1, f64)/real(n_coarse, f64)
470 bloc_coord(2) = real(i2, f64)/real(n_coarse, f64)
472 print *,
'#uniform fine mesh would be:', n_coarse*n_local
473 print *,
'#N_coarse=', n_coarse
474 print *,
'#saving:', real(n, f64)/real(n_coarse*n_local, f64)
475 print *,
'#new x(i1),x(i1+N_fine)=', bloc_coord(1), bloc_coord(2)
476 print *,
'#error for x(i1),x(i1+N_fine)=', bloc_coord(1) - a, bloc_coord(2) - b
477 print *,
'#i1,i1+N_fine,N_fine,N=', i1, i1 + n_fine, n_fine, n
481 print *,
'case in sll_s_compute_bloc not implemented yet'
498 sll_real64,
intent(in) :: bloc_coord(2)
499 sll_int32,
intent(in) :: bloc_index(3)
500 sll_real64,
dimension(:),
intent(out) :: node_positions
502 sll_int32 :: i, i1, i2, n
505 n = bloc_index(1) + bloc_index(2) + bloc_index(3)
507 i2 = i1 + bloc_index(2)
508 node_positions(1:n + 1) = -1._f64
509 node_positions(1) = 0._f64
510 node_positions(i1 + 1) = bloc_coord(1)
511 node_positions(i2 + 1) = bloc_coord(2)
512 node_positions(n + 1) = 1._f64
515 if (bloc_index(1) .ne. 0)
then
516 dx = bloc_coord(1)/real(bloc_index(1), f64)
517 do i = 2, bloc_index(1)
518 node_positions(i) = (real(i, f64) - 1._f64)*dx
521 if (bloc_index(2) .ne. 0)
then
522 dx = (bloc_coord(2) - bloc_coord(1))/real(bloc_index(2), f64)
523 do i = 2, bloc_index(2)
524 node_positions(i + i1) = bloc_coord(1) + (real(i, f64) - 1._f64)*dx
527 if (bloc_index(3) .ne. 0)
then
528 dx = (1._f64 - bloc_coord(2))/real(bloc_index(3), f64)
529 do i = 2, bloc_index(3)
530 node_positions(i + i2) = bloc_coord(2) + (real(i, f64) - 1._f64)*dx
539 character(len=*),
intent(in) :: env_variable
540 logical,
intent(in) :: default_value
542 character(len=255) :: env_str
546 call get_environment_variable(env_variable,
value=env_str)
548 if (len_trim(env_str) > 0)
then
549 select case (trim(env_str))
550 case (
"1",
"ON",
"TRUE",
"on",
"true")
552 case (
"0",
"OFF",
"FALSE",
"off",
"false")
570 integer,
parameter :: wp = f64
572 real(wp),
intent(out) :: array(:)
573 real(wp),
intent(in) :: vmin
574 real(wp),
intent(in) :: vmax
575 logical,
intent(in),
optional :: endpoint
576 real(wp),
intent(out),
optional :: step
589 if (
present(endpoint))
then
590 nc = merge(np - 1, np, endpoint)
600 a = vmin/real(nc, wp)
601 b = vmax/real(nc, wp)
603 array(i) = a*real(nc + 1 - i, f64) + b*real(i - 1, f64)
607 if (np == nc + 1) array(np) = vmax
610 if (
present(step))
then
Functions to display on screen matrix or vector.
Some common numerical utilities.
subroutine display_vector_real(array, real_format)
Display a vector to screen.
integer(kind=i64) function factorial_int32(n)
It would have been nice to declare the next functions as 'pure' functions, but it is safer to be able...
subroutine display_vector_integer(array, integer_format)
Display a vector to screen.
subroutine, public sll_s_mpe_decomp1d(n, numprocs, myid, s, e)
From the MPE library.
subroutine, public sll_s_int2string(istep, cstep)
Convert an integer < 9999 to a 4 characters string.
subroutine initialize_file(data_file_id, thf_file_id)
Subroutine to open data file for slv2d and create the thf.dat file to write results.
pure subroutine, public sll_s_new_array_linspace(array, vmin, vmax, endpoint, step)
Equivalent to numpy.linspace @contact Yaman Güçlü, IPP Garching.
logical function, public sll_f_is_even(n)
Check if an integer is even.
subroutine time_history(file_id, desc, fformat, array)
Routine from slv2d to write diagnostics.
subroutine, public sll_s_compute_mesh_from_bloc(bloc_coord, bloc_index, node_positions)
logical function, public sll_f_is_power_of_two(n)
Check if an integer is equal to.
subroutine, public sll_s_display_matrix_2d_integer(array, integer_format)
Display matrix to screen.
subroutine, public sll_s_compute_bloc(bloc_coord, bloc_index, N)
integer(kind=i64) function factorial_int64(n)
It would have been nice to declare the next functions as 'pure' functions, but it is safer to be able...
subroutine display_matrix_2d_real(array, real_format)
Display matrix to screen.
subroutine, public sll_s_pfenvelope(S, t, tflat, tL, tR, twL, twR, t0, turn_drive_off)
S: the wave form at a given point in time. This wave form is not scaled (its maximum value is 1)....
integer, parameter, public sll_p_byte_size
kind of integers
subroutine, public sll_s_new_file_id(file_id, error)
Get a file unit number free before creating a file.
logical function, public sll_f_query_environment(env_variable, default_value)
Query an environment variable for the values on,off,1,0,true,false and return the result as a logical...