Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief A wrapper around pw_to_cube() which accepts particle_list_type
10 : !> \author Ole Schuett
11 : ! **************************************************************************************************
12 : MODULE cp_realspace_grid_cube
13 : USE atomic_kind_types, ONLY: get_atomic_kind
14 : USE cp_output_handling, ONLY: cp_mpi_io_get
15 : USE kinds, ONLY: dp
16 : USE particle_list_types, ONLY: particle_list_type
17 : USE pw_types, ONLY: pw_r3d_rs_type
18 : USE realspace_grid_cube, ONLY: cube_to_pw,&
19 : pw_to_cube,&
20 : pw_to_simple_volumetric
21 : #include "./base/base_uses.f90"
22 :
23 : IMPLICIT NONE
24 :
25 : PRIVATE
26 :
27 : PUBLIC :: cp_pw_to_cube, cp_pw_to_simple_volumetric, cp_cube_to_pw
28 :
29 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_realspace_grid_cube'
30 :
31 : CONTAINS
32 :
33 : ! **************************************************************************************************
34 : !> \brief ...
35 : !> \param pw ...
36 : !> \param unit_nr ...
37 : !> \param title ...
38 : !> \param particles ...
39 : !> \param stride ...
40 : !> \param zero_tails ...
41 : !> \param silent minimal I/O
42 : !> \param mpi_io True if cube should be written in parallel using MPI
43 : ! **************************************************************************************************
44 1920 : SUBROUTINE cp_pw_to_cube(pw, unit_nr, title, particles, stride, zero_tails, silent, mpi_io)
45 : TYPE(pw_r3d_rs_type), INTENT(IN) :: pw
46 : INTEGER, INTENT(IN) :: unit_nr
47 : CHARACTER(*), INTENT(IN), OPTIONAL :: title
48 : TYPE(particle_list_type), POINTER :: particles
49 : INTEGER, DIMENSION(:), OPTIONAL, POINTER :: stride
50 : LOGICAL, INTENT(IN), OPTIONAL :: zero_tails, silent, mpi_io
51 :
52 : INTEGER :: i, n
53 1920 : INTEGER, ALLOCATABLE, DIMENSION(:) :: particles_z
54 1920 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: particles_r
55 : TYPE(particle_list_type), POINTER :: my_particles
56 :
57 1920 : NULLIFY (my_particles)
58 1920 : my_particles => particles
59 1920 : IF (ASSOCIATED(my_particles)) THEN
60 1920 : n = my_particles%n_els
61 5760 : ALLOCATE (particles_z(n))
62 5760 : ALLOCATE (particles_r(3, n))
63 8464 : DO i = 1, n
64 6544 : CALL get_atomic_kind(my_particles%els(i)%atomic_kind, z=particles_z(i))
65 28096 : particles_r(:, i) = my_particles%els(i)%r(:)
66 : END DO
67 :
68 : CALL pw_to_cube(pw=pw, unit_nr=unit_nr, title=title, &
69 : particles_z=particles_z, particles_r=particles_r, &
70 : stride=stride, zero_tails=zero_tails, &
71 1920 : silent=silent, mpi_io=mpi_io)
72 : ELSE
73 : CALL pw_to_cube(pw=pw, unit_nr=unit_nr, title=title, &
74 : stride=stride, zero_tails=zero_tails, &
75 0 : silent=silent, mpi_io=mpi_io)
76 : END IF
77 :
78 1920 : END SUBROUTINE cp_pw_to_cube
79 :
80 : ! **************************************************************************************************
81 : !> \brief Prints grid in a simple format: X Y Z value
82 : !> \param pw ...
83 : !> \param unit_nr ...
84 : !> \param stride ...
85 : !> \param pw2 ...
86 : !> \par History
87 : !> Created [Vladimir Rybkin] (08.2017)
88 : ! **************************************************************************************************
89 16 : SUBROUTINE cp_pw_to_simple_volumetric(pw, unit_nr, stride, pw2)
90 : TYPE(pw_r3d_rs_type), INTENT(IN) :: pw
91 : INTEGER, INTENT(IN) :: unit_nr
92 : INTEGER, DIMENSION(:), OPTIONAL, POINTER :: stride
93 : TYPE(pw_r3d_rs_type), INTENT(IN), OPTIONAL :: pw2
94 :
95 16 : IF (.NOT. PRESENT(pw2)) THEN
96 16 : CALL pw_to_simple_volumetric(pw, unit_nr, stride)
97 : ELSE
98 0 : CALL pw_to_simple_volumetric(pw, unit_nr, stride, pw2)
99 : END IF
100 :
101 16 : END SUBROUTINE cp_pw_to_simple_volumetric
102 :
103 : ! **************************************************************************************************
104 : !> \brief Thin wrapper around routine cube_to_pw
105 : !> \param grid pw to read from cube file
106 : !> \param filename name of cube file
107 : !> \param scaling scale values before storing
108 : !> \param silent minimal I/O
109 : !> \par History
110 : !> Created [Nico Holmberg] (09.2018)
111 : ! **************************************************************************************************
112 38 : SUBROUTINE cp_cube_to_pw(grid, filename, scaling, silent)
113 : TYPE(pw_r3d_rs_type), INTENT(IN) :: grid
114 : CHARACTER(len=*), INTENT(in) :: filename
115 : REAL(kind=dp), INTENT(in) :: scaling
116 : LOGICAL, INTENT(in), OPTIONAL :: silent
117 :
118 : LOGICAL :: parallel_read
119 :
120 : ! Determine whether to use MPI I/O for reading cube filename
121 38 : parallel_read = .TRUE.
122 : ! Parallel routine falls back to stream read in serial mode,
123 : ! but it has slight overhead compared to sequential read
124 : ! Therefore, we use sequential version in serial mode
125 38 : IF (grid%pw_grid%para%group%num_pe == 1) parallel_read = .FALSE.
126 : ! Check if MPI I/O was disabled in GLOBAL section
127 38 : IF (.NOT. cp_mpi_io_get()) parallel_read = .FALSE.
128 :
129 38 : CALL cube_to_pw(grid, filename, scaling, parallel_read, silent=silent)
130 :
131 38 : END SUBROUTINE cp_cube_to_pw
132 :
133 : END MODULE cp_realspace_grid_cube
|