Debian Codegraph @

src/read_data_cactus_hdf5_futils.f90

raw
1 !-------------------------------------------------------------------------
2 !
3 ! Utility routines for the cactus hdf5 data read
4 ! Module contains interface routines to c functions
5 ! that perform the actual calls to the HDF5 libs
6 !
7 !-------------------------------------------------------------------------
8 module cactushdf5read
9 use params, only:maxplot
10 use labels, only:lenlabel
11 use, intrinsic :: iso_c_binding, only:c_int,c_double,c_char
12 implicit none
13 character(len=lenlabel), dimension(maxplot) :: blocklabel
14 character(len=130) :: datfileprev = ' '
15 logical :: file_is_open = .false.
16 integer :: ntoti_prev,ncol_prev,nstep_prev
17
18 interface
19 subroutine open_cactus_hdf5_file(filename,istep,npart,ncol,nstep_max,ndim,ndimV,time,ignoretl,ierr) bind(c)
20 import
21 character(kind=c_char), dimension(*), intent(in) :: filename
22 integer(kind=c_int), intent(in), value :: istep,ignoretl
23 integer(kind=c_int), intent(out) :: npart,ncol,nstep_max,ndim,ndimV,ierr
24 real(kind=c_double), intent(out) :: time
25 end subroutine open_cactus_hdf5_file
26
27 subroutine read_cactus_hdf5_data(filename,istep,npart,time,dx,ignoretl,ierr) bind(c)
28 import
29 character(kind=c_char), dimension(*), intent(in) :: filename
30 integer(kind=c_int), intent(in), value :: istep,ignoretl
31 integer(kind=c_int), intent(out) :: npart,ierr
32 real(kind=c_double), intent(out) :: time,dx
33 end subroutine read_cactus_hdf5_data
34
35 subroutine close_cactus_hdf5_file(ierr) bind(c)
36 import
37 integer(kind=c_int), intent(out) :: ierr
38 end subroutine close_cactus_hdf5_file
39
40 end interface
41
42 contains
43
44 !-------------------------------------------------------------------------
45 !
46 ! The following routines are callback routines called by the c
47 ! utilities
48 !
49 !-------------------------------------------------------------------------
50 subroutine set_blocklabel_cactus(icol,name,lenname) bind(c)
51 use, intrinsic :: iso_c_binding, only:c_int, c_char
52 ! use cactushdf5read, only:blocklabel
53 use asciiutils, only:fstring
54 integer(kind=c_int), intent(in) :: icol,lenname
55 character(kind=c_char), intent(in) :: name(lenname)
56 character(len=24) :: temp
57 integer :: ivar
58
59 temp = fstring(name)
60 ivar = index(temp,'::')
61 if (ivar > 0) temp = temp(ivar+2:)
62 if (icol <= size(blocklabel)) then
63 blocklabel(icol) = trim(temp)
64 else
65 print*,'ERROR - too many columns in file'
66 endif
67 !print*,icol,' name = ',trim(blocklabel(icol))
68
69 end subroutine set_blocklabel_cactus
70
71 subroutine sort_cactus_data(n,iter,iorder) bind(c)
72 use, intrinsic :: iso_c_binding, only:c_int
73 use sort, only:indexxi
74 integer(kind=c_int), intent(in) :: n
75 integer(kind=c_int), intent(in) :: iter(n)
76 integer(kind=c_int), intent(out) :: iorder(n)
77
78 call indexxi(n,iter,iorder)
79
80 end subroutine sort_cactus_data
81
82 !-------------------------------------------------------------------------
83 !
84 ! The following routines compute useful things, e.g. tr K
85 !
86 !-------------------------------------------------------------------------
87 subroutine calc_trK(gxxd,gxyd,gxzd,gyyd,gyzd,gzzd,kxxd,kxyd,kxzd,kyyd,kyzd,kzzd,trk)
88 !
89 ! Subroutine to calculate trace K ( trK = g^{ij} K_{ij} )
90 ! Takes g_{ij} and K_{ij} at one position and time, returns trK
91 !
92 use vectorutils,only:matrixinvert3D
93 real, intent(in) :: gxxd,gxyd,gxzd,gyyd,gyzd,gzzd ! spatial down metric components
94 real, intent(in) :: kxxd,kxyd,kxzd,kyyd,kyzd,kzzd ! down extrinsic curvature components
95 real :: gxxu,gxyu,gxzu,gyyu,gyzu,gzzu ! spatial up metric components
96 real, intent(out) :: trk
97 real, dimension(3,3) :: gijd, giju ! 4x4 metric down and up respectively
98 integer :: ierr
99
100 ! down components
101 gijd(1,1) = gxxd
102 gijd(1,2) = gxyd
103 gijd(1,3) = gxzd
104 gijd(2,1) = gxyd
105 gijd(2,2) = gyyd
106 gijd(2,3) = gyzd
107 gijd(3,1) = gxzd
108 gijd(3,2) = gyzd
109 gijd(3,3) = gzzd
110
111 call matrixinvert3D(gijd,giju,ierr)
112
113 ! up (inverse) components
114 gxxu = giju(1,1)
115 gxyu = giju(1,2)
116 gxzu = giju(1,3)
117 gyyu = giju(2,2)
118 gyzu = giju(2,3)
119 gzzu = giju(3,3)
120
121
122 trk = (gxxu * kxxd) + (2. * gxyu * kxyd) + (2. * gxzu * kxzd) + &
123 & (gyyu * kyyd) + (2. * gyzu * kyzd) + (gzzu * kzzd)
124
125 end subroutine calc_trK
126
127
128 !
129 ! find location of metric and extrinsic curvature in columns
130 !
131 subroutine find_metric(ncols,labelcol,igxx,igxy,igxz,igyy,igyz,igzz,ikxx,ikxy,ikxz,ikyy,ikyz,ikzz,&
132 irho,ialp,ivel0,ivel1,ivel2,gotrho,gotalp)
133 integer, intent(in) :: ncols
134 character(len=*), intent(in) :: labelcol(ncols)
135 integer, intent(out) :: igxx,igxy,igxz,igyy,igyz,igzz
136 integer, intent(out) :: ikxx,ikxy,ikxz,ikyy,ikyz,ikzz
137 integer, intent(out) :: irho,ialp,ivel0,ivel1,ivel2
138 integer :: i, idens
139 logical, intent(out) :: gotrho, gotalp
140 gotrho = .False.; gotalp = .False.
141
142 igxx = 0; igxy = 0; igxz = 0; igyy = 0; igyz = 0; igzz = 0
143 ikxx = 0; ikxy = 0; ikxz = 0; ikyy = 0; ikyz = 0; ikzz = 0
144 irho = 0; ialp = 0; ivel0 = 0; ivel1 = 0; ivel2 = 0
145 do i=1,ncols
146 select case(labelcol(i))
147 case('gxx')
148 igxx = i
149 case('gxy')
150 igxy = i
151 case('gxz')
152 igxz = i
153 case('gyy')
154 igyy = i
155 case('gyz')
156 igyz = i
157 case('gzz')
158 igzz = i
159 case('kxx')
160 ikxx = i
161 case('kxy')
162 ikxy = i
163 case('kxz')
164 ikxz = i
165 case('kyy')
166 ikyy = i
167 case('kyz')
168 ikyz = i
169 case('kzz')
170 ikzz = i
171 case('rho')
172 irho = i
173 gotrho = .True.
174 case('dens')
175 idens = i
176 case('alp')
177 ialp = i
178 gotalp = .True.
179 case('vel[0]')
180 ivel0 = i
181 case('vel[1]')
182 ivel1 = i
183 case('vel[2]')
184 ivel2 = i
185 end select
186 enddo
187
188 ! if we didn't find 'rho' in cols, use dens instead
189 if (gotrho .eqv. .False.) irho = idens
190
191 end subroutine find_metric
192
193 subroutine compute_extra_columns(ncols,nextra,dat)
194 integer, intent(in) :: ncols
195 integer, intent(out) :: nextra
196 real, intent(inout), optional :: dat(:,:)
197 integer :: i,n,itrk
198 integer :: igxx,igxy,igxz,igyy,igyz,igzz
199 integer :: ikxx,ikxy,ikxz,ikyy,ikyz,ikzz
200 integer :: irho,ialp,ivel0,ivel1,ivel2
201 logical :: gotrho,gotalp
202
203 nextra = 0
204 call find_metric(ncols,blocklabel,igxx,igxy,igxz,igyy,igyz,igzz,ikxx,ikxy,ikxz,ikyy,ikyz,ikzz,&
205 irho,ialp,ivel0,ivel1,ivel2,gotrho,gotalp)
206 n = size(dat(:,1))
207 if (igxx > 0 .and. igxy > 0 .and. igxz > 0 .and. igyy > 0 .and. igyz > 0 .and. igzz > 0 .and. &
208 ikxx > 0 .and. ikxy > 0 .and. ikxz > 0 .and. ikyy > 0 .and. ikyz > 0 .and. ikzz > 0) then
209 itrk = ncols + 1
210 blocklabel(itrk) = 'tr K'
211 nextra = 1
212 if (present(dat)) then
213 !print*,' getting trk ',igxx,igxy,igxz,igyy,igyz,igzz,ikxx,ikxy,ikxz,ikyy,ikyz,ikzz,itrk
214 do i=1,n
215 call calc_trK(dat(i,igxx),dat(i,igxy),dat(i,igxz),dat(i,igyy),dat(i,igyz),dat(i,igzz),&
216 dat(i,ikxx),dat(i,ikxy),dat(i,ikxy),dat(i,ikyy),dat(i,ikyz),dat(i,ikzz),dat(i,itrk))
217 enddo
218 endif
219 endif
220
221 end subroutine compute_extra_columns
222
223 end module cactushdf5read