ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
zipperIntegrations_b.f90
Go to the documentation of this file.
1 ! generated by tapenade (inria, ecuador team)
2 ! tapenade 3.16 (develop) - 22 aug 2023 15:51
3 !
5  implicit none
6 
7 contains
8 ! differentiation of flowintegrationzipper in reverse (adjoint) mode (with options noisize i4 dr8 r8):
9 ! gradient of useful results: timeref tref pref rgas rhoref
10 ! pointref vars localvalues
11 ! with respect to varying inputs: timeref tref pref rgas rhoref
12 ! pointref vars localvalues
13 ! rw status of diff variables: timeref:incr tref:incr pref:incr
14 ! rgas:incr rhoref:incr pointref:incr vars:incr
15 ! localvalues:in-out
16  subroutine flowintegrationzipper_b(isinflow, conn, fams, vars, varsd, &
17 & localvalues, localvaluesd, famlist, sps, ptvalid)
18 ! integrate over the trianges for the inflow/outflow conditions.
19  use constants
20  use blockpointers, only : bctype
21  use sorting, only : faminlist
22  use flowvarrefstate, only : pref, prefd, pinf, pinfd, rhoref, &
30  implicit none
31 ! input/output variables
32  logical, intent(in) :: isinflow
33  integer(kind=inttype), dimension(:, :), intent(in) :: conn
34  integer(kind=inttype), dimension(:), intent(in) :: fams
35  real(kind=realtype), dimension(:, :), intent(in) :: vars
36  real(kind=realtype), dimension(:, :) :: varsd
37  real(kind=realtype), dimension(nlocalvalues), intent(inout) :: &
38 & localvalues
39  real(kind=realtype), dimension(nlocalvalues), intent(inout) :: &
40 & localvaluesd
41  integer(kind=inttype), dimension(:), intent(in) :: famlist
42  integer(kind=inttype), intent(in) :: sps
43  logical(kind=inttype), dimension(:), optional, intent(in) :: ptvalid
44 ! working variables
45  integer(kind=inttype) :: i, j
46  real(kind=realtype) :: sf, vmag, vnm, vxm, vym, vzm, fx, fy, fz, u, &
47 & v, w, vnmfreestreamref
48  real(kind=realtype) :: sfd, vmagd, vnmd, vxmd, vymd, vzmd, fxd, fyd&
49 & , fzd
50  real(kind=realtype), dimension(3) :: fp, mp, fmom, mmom, refpoint, &
51 & ss, x1, x2, x3, norm, sfacecoordref
52  real(kind=realtype), dimension(3) :: fpd, mpd, fmomd, mmomd, &
53 & refpointd, ssd, x1d, x2d, x3d, normd, sfacecoordrefd
54  real(kind=realtype) :: pm, ptot, ttot, rhom, gammam, mnm, &
55 & massflowratelocal, am
56  real(kind=realtype) :: pmd, ptotd, ttotd, rhomd, gammamd, mnmd, &
57 & massflowratelocald, amd
58  real(kind=realtype) :: massflowrate, mass_ptot, mass_ttot, mass_ps, &
59 & mass_mn, mass_a, mass_rho, mass_vx, mass_vy, mass_vz, mass_nx, &
60 & mass_ny, mass_nz, mass_vi
61  real(kind=realtype) :: massflowrated, mass_ptotd, mass_ttotd, &
62 & mass_psd, mass_mnd, mass_ad, mass_rhod, mass_vxd, mass_vyd, mass_vzd&
63 & , mass_nxd, mass_nyd, mass_nzd, mass_vid
64  real(kind=realtype) :: area, cellarea, overcellarea
65  real(kind=realtype) :: aread, cellaread, overcellaread
66  real(kind=realtype) :: area_ptot, area_ps
67  real(kind=realtype) :: area_ptotd, area_psd
68  real(kind=realtype) :: govgm1, gm1ovg, viconst, vilocal, pratio
69  real(kind=realtype) :: vilocald, pratiod
70  real(kind=realtype) :: mredim
71  real(kind=realtype) :: mredimd
72  real(kind=realtype) :: internalflowfact, inflowfact, xc, xco, yc, &
73 & yco, zc, zco, mx, my, mz
74  real(kind=realtype) :: xcd, xcod, ycd, ycod, zcd, zcod, mxd, myd, &
75 & mzd
76  real(kind=realtype), dimension(3) :: cofsumfx, cofsumfy, cofsumfz
77  real(kind=realtype), dimension(3) :: cofsumfxd, cofsumfyd, cofsumfzd
78  logical :: triisvalid
79  intrinsic sqrt
80  intrinsic size
81  intrinsic present
82  intrinsic min
83  real(kind=realtype), dimension(3) :: arg1
84  real(kind=realtype), dimension(3) :: arg1d
85  real(kind=realtype), dimension(3) :: arg2
86  real(kind=realtype), dimension(3) :: arg2d
87  real(kind=realtype) :: temp
88  real(kind=realtype) :: tempd
89  real(kind=realtype) :: temp0
90  real(kind=realtype) :: tempd0
91  integer :: branch
92  mredim = sqrt(pref*rhoref)
93  refpoint(1) = lref*pointref(1)
94  refpoint(2) = lref*pointref(2)
95  refpoint(3) = lref*pointref(3)
96  internalflowfact = one
97  if (flowtype .eq. internalflow) internalflowfact = -one
98  inflowfact = one
99  if (isinflow) inflowfact = -one
100  mass_vid = localvaluesd(imassvi)
101  mass_nzd = localvaluesd(imassnz)
102  mass_nyd = localvaluesd(imassny)
103  mass_nxd = localvaluesd(imassnx)
104  mass_vzd = localvaluesd(imassvz)
105  mass_vyd = localvaluesd(imassvy)
106  mass_vxd = localvaluesd(imassvx)
107  area_psd = localvaluesd(iareaps)
108  area_ptotd = localvaluesd(iareaptot)
109  cofsumfzd = 0.0_8
110  cofsumfzd = localvaluesd(icoforcez:icoforcez+2)
111  cofsumfyd = 0.0_8
112  cofsumfyd = localvaluesd(icoforcey:icoforcey+2)
113  cofsumfxd = 0.0_8
114  cofsumfxd = localvaluesd(icoforcex:icoforcex+2)
115  mmomd = 0.0_8
116  mmomd = localvaluesd(iflowmm:iflowmm+2)
117  mpd = 0.0_8
118  mpd = localvaluesd(iflowmp:iflowmp+2)
119  fmomd = 0.0_8
120  fmomd = localvaluesd(iflowfm:iflowfm+2)
121  fpd = 0.0_8
122  fpd = localvaluesd(ifp:ifp+2)
123  mass_mnd = localvaluesd(imassmn)
124  mass_psd = localvaluesd(imassps)
125  mass_ttotd = localvaluesd(imassttot)
126  mass_ptotd = localvaluesd(imassptot)
127  mass_ad = localvaluesd(imassa)
128  mass_rhod = localvaluesd(imassrho)
129  aread = localvaluesd(iarea)
130  massflowrated = localvaluesd(imassflow)
131  mredimd = 0.0_8
132  normd = 0.0_8
133  ptotd = 0.0_8
134  refpointd = 0.0_8
135  sfacecoordrefd = 0.0_8
136  ttotd = 0.0_8
137 !$bwd-of ii-loop
138  do i=1,size(conn, 2)
139  if (faminlist(fams(i), famlist)) then
140 ! if the ptvalid list is given, check if we should integrate
141 ! this triangle.
142  triisvalid = .true.
143  if (present(ptvalid)) then
144 ! check if each of the three nodes are valid
145  if (((ptvalid(conn(1, i)) .eqv. .false.) .or. (ptvalid(conn(2&
146 & , i)) .eqv. .false.)) .or. (ptvalid(conn(3, i)) .eqv. &
147 & .false.)) then
148  call pushcontrol1b(0)
149  triisvalid = .false.
150  else
151  call pushcontrol1b(0)
152  end if
153  else
154  call pushcontrol1b(1)
155  end if
156  if (triisvalid) then
157 ! compute the averaged values for this triangle
158  vxm = zero
159  vym = zero
160  vzm = zero
161  rhom = zero
162  pm = zero
163  gammam = zero
164  sf = zero
165  do j=1,3
166  rhom = rhom + vars(conn(j, i), irho)
167  vxm = vxm + vars(conn(j, i), ivx)
168  vym = vym + vars(conn(j, i), ivy)
169  vzm = vzm + vars(conn(j, i), ivz)
170  pm = pm + vars(conn(j, i), irhoe)
171  gammam = gammam + vars(conn(j, i), izippflowgamma)
172  sf = sf + vars(conn(j, i), izippflowsface)
173  end do
174 ! divide by 3 due to the summation above:
175  rhom = third*rhom
176  vxm = third*vxm
177  vym = third*vym
178  vzm = third*vzm
179  pm = third*pm
180  gammam = third*gammam
181  sf = third*sf
182 ! get the nodes of triangle.
183  x1 = vars(conn(1, i), izippflowx:izippflowz)
184  x2 = vars(conn(2, i), izippflowx:izippflowz)
185  x3 = vars(conn(3, i), izippflowx:izippflowz)
186  arg1(:) = x2 - x1
187  arg2(:) = x3 - x1
188  call cross_prod(arg1(:), arg2(:), norm)
189  ss = half*norm
190  call computeptot(rhom, vxm, vym, vzm, pm, ptot)
191  call computettot(rhom, vxm, vym, vzm, pm, ttot)
192  vnm = vxm*ss(1) + vym*ss(2) + vzm*ss(3) - sf
193  vmag = sqrt(vxm**2 + vym**2 + vzm**2) - sf
194  am = sqrt(gammam*pm/rhom)
195  mnm = vmag/sqrt(gammam*pm/rhom)
196  cellarea = sqrt(ss(1)**2 + ss(2)**2 + ss(3)**2)
197  overcellarea = 1/cellarea
198  massflowratelocal = rhom*vnm*mredim
199  call pushreal8(pm)
200  pm = pm*pref
201  sfacecoordref(1) = sf*ss(1)*overcellarea
202  sfacecoordref(2) = sf*ss(2)*overcellarea
203  sfacecoordref(3) = sf*ss(3)*overcellarea
204  govgm1 = gammainf/(gammainf-one)
205  gm1ovg = one/govgm1
206  viconst = two*govgm1*rgasdim
207  if (one .gt. one/ptot) then
208  pratio = one/ptot
209  call pushcontrol1b(0)
210  else
211  call pushcontrol1b(1)
212  pratio = one
213  end if
214  vilocal = sqrt(viconst*(one-pratio**gm1ovg)*ttot*tref)
215 ! compute the average cell center.
216  xco = zero
217  yco = zero
218  zco = zero
219  do j=1,3
220  xco = xco + vars(conn(1, i), izippflowx)
221  yco = yco + vars(conn(2, i), izippflowy)
222  zco = zco + vars(conn(3, i), izippflowz)
223  end do
224 ! finish average for cell center
225  xco = third*xco
226  yco = third*yco
227  zco = third*zco
228 ! x-y-zco is the cell center w.r.t. the origin, x-y-zc is w.r.t. the reference point
229  xc = xco - refpoint(1)
230  yc = yco - refpoint(2)
231  zc = zco - refpoint(3)
232  call pushreal8(pm)
233  pm = -(pm-pinf*pref)
234 ! update the pressure force and moment coefficients.
235 ! center of force computations. here we accumulate in the sums.
236 ! force-x
237 ! force-y
238 ! force-z
239 ! momentum forces
240 ! get unit normal vector.
241  call pushreal8array(ss, 3)
242  ss = ss/cellarea
243  call pushreal8(massflowratelocal)
244  massflowratelocal = massflowratelocal/timeref*internalflowfact&
245 & *inflowfact
246  fx = massflowratelocal*ss(1)*vxm
247  fy = massflowratelocal*ss(2)*vym
248  fz = massflowratelocal*ss(3)*vzm
249 ! center of force computations. here we accumulate in the sums.
250 ! force-x
251 ! force-y
252 ! force-z
253  mxd = mmomd(1)
254  myd = mmomd(2)
255  mzd = mmomd(3)
256  zcod = fz*cofsumfzd(3) + fy*cofsumfyd(3) + fx*cofsumfxd(3)
257  fzd = zco*cofsumfzd(3) + yco*cofsumfzd(2) + xco*cofsumfzd(1) +&
258 & yc*mxd - xc*myd - fmomd(3)
259  ycod = fz*cofsumfzd(2) + fy*cofsumfyd(2) + fx*cofsumfxd(2)
260  xcod = fz*cofsumfzd(1) + fy*cofsumfyd(1) + fx*cofsumfxd(1)
261  fyd = zco*cofsumfyd(3) + yco*cofsumfyd(2) + xco*cofsumfyd(1) +&
262 & xc*mzd - zc*mxd - fmomd(2)
263  fxd = zco*cofsumfxd(3) + yco*cofsumfxd(2) + xco*cofsumfxd(1) +&
264 & zc*myd - yc*mzd - fmomd(1)
265  xcd = fy*mzd - fz*myd
266  ycd = fz*mxd - fx*mzd
267  zcd = fx*myd - fy*mxd
268  ssd = 0.0_8
269  ssd(3) = ssd(3) + massflowratelocal*vzm*fzd
270  massflowratelocald = vzm*ss(3)*fzd + vym*ss(2)*fyd + vxm*ss(1)&
271 & *fxd
272  vzmd = massflowratelocal*ss(3)*fzd
273  ssd(2) = ssd(2) + massflowratelocal*vym*fyd
274  vymd = massflowratelocal*ss(2)*fyd
275  ssd(1) = ssd(1) + massflowratelocal*vxm*fxd
276  vxmd = massflowratelocal*ss(1)*fxd
277  call popreal8(massflowratelocal)
278  tempd0 = internalflowfact*inflowfact*massflowratelocald/&
279 & timeref
280  massflowratelocald = tempd0
281  timerefd = timerefd - massflowratelocal*tempd0/timeref
282  call popreal8array(ss, 3)
283  cellaread = -(sum(ss*ssd)/cellarea**2)
284  ssd = ssd/cellarea
285  fz = pm*ss(3)
286  fy = pm*ss(2)
287  fx = pm*ss(1)
288  mzd = mpd(3)
289  myd = mpd(2)
290  fxd = zco*cofsumfxd(3) + yco*cofsumfxd(2) + xco*cofsumfxd(1) +&
291 & zc*myd - yc*mzd + fpd(1)
292  mxd = mpd(1)
293  fzd = zco*cofsumfzd(3) + yco*cofsumfzd(2) + xco*cofsumfzd(1) +&
294 & yc*mxd - xc*myd + fpd(3)
295  fyd = zco*cofsumfyd(3) + yco*cofsumfyd(2) + xco*cofsumfyd(1) +&
296 & xc*mzd + fpd(2) - zc*mxd
297  xcd = xcd + fy*mzd - fz*myd
298  xcod = xcod + fz*cofsumfzd(1) + fy*cofsumfyd(1) + fx*cofsumfxd&
299 & (1) + xcd
300  ycd = ycd + fz*mxd - fx*mzd
301  ycod = ycod + fz*cofsumfzd(2) + fy*cofsumfyd(2) + fx*cofsumfxd&
302 & (2) + ycd
303  zcd = zcd + fx*myd - fy*mxd
304  zcod = zcod + fz*cofsumfzd(3) + fy*cofsumfyd(3) + fx*cofsumfxd&
305 & (3) + zcd
306  pmd = ss(3)*fzd + ss(2)*fyd + ss(1)*fxd
307  ssd(3) = ssd(3) + pm*fzd
308  ssd(2) = ssd(2) + pm*fyd
309  ssd(1) = ssd(1) + pm*fxd
310  call popreal8(pm)
311  prefd = prefd + pinf*pmd
312  pmd = -pmd
313  refpointd(3) = refpointd(3) - zcd
314  refpointd(2) = refpointd(2) - ycd
315  refpointd(1) = refpointd(1) - xcd
316  zcod = third*zcod
317  ycod = third*ycod
318  xcod = third*xcod
319  do j=3,1,-1
320  varsd(conn(3, i), izippflowz) = varsd(conn(3, i), izippflowz&
321 & ) + zcod
322  varsd(conn(2, i), izippflowy) = varsd(conn(2, i), izippflowy&
323 & ) + ycod
324  varsd(conn(1, i), izippflowx) = varsd(conn(1, i), izippflowx&
325 & ) + xcod
326  end do
327  ssd(3) = ssd(3) + overcellarea*massflowratelocal*mass_nzd
328  overcellaread = massflowratelocal*ss(3)*mass_nzd + &
329 & massflowratelocal*ss(2)*mass_nyd + massflowratelocal*ss(1)*&
330 & mass_nxd
331  massflowratelocald = massflowratelocald + overcellarea*ss(3)*&
332 & mass_nzd + overcellarea*ss(2)*mass_nyd + overcellarea*ss(1)*&
333 & mass_nxd + vilocal*mass_vid
334  ssd(2) = ssd(2) + overcellarea*massflowratelocal*mass_nyd
335  ssd(1) = ssd(1) + overcellarea*massflowratelocal*mass_nxd
336  vilocald = massflowratelocal*mass_vid
337  temp0 = one - pratio**gm1ovg
338  if (viconst*(temp0*(ttot*tref)) .eq. 0.0_8) then
339  tempd = 0.0_8
340  else
341  tempd = viconst*vilocald/(2.0*sqrt(viconst*(temp0*(ttot*tref&
342 & ))))
343  end if
344  if (pratio .le. 0.0_8 .and. (gm1ovg .eq. 0.0_8 .or. gm1ovg &
345 & .ne. int(gm1ovg))) then
346  pratiod = 0.0_8
347  else
348  pratiod = -(gm1ovg*pratio**(gm1ovg-1)*ttot*tref*tempd)
349  end if
350  ttotd = ttotd + tref*temp0*tempd
351  trefd = trefd + ttot*temp0*tempd
352  call popcontrol1b(branch)
353  if (branch .eq. 0) ptotd = ptotd - one*pratiod/ptot**2
354  sfacecoordrefd(3) = sfacecoordrefd(3) - massflowratelocal*&
355 & mass_vzd
356  massflowratelocald = massflowratelocald + (uref*vzm-&
357 & sfacecoordref(3))*mass_vzd + (uref*vym-sfacecoordref(2))*&
358 & mass_vyd + (uref*vxm-sfacecoordref(1))*mass_vxd + mnm*&
359 & mass_mnd + pm*mass_psd + am*uref*mass_ad + rhom*rhoref*&
360 & mass_rhod + ttot*tref*mass_ttotd + ptot*pref*mass_ptotd + &
361 & massflowrated
362  sfacecoordrefd(2) = sfacecoordrefd(2) - massflowratelocal*&
363 & mass_vyd
364  sfacecoordrefd(1) = sfacecoordrefd(1) - massflowratelocal*&
365 & mass_vxd
366  overcellaread = overcellaread + sf*ss(3)*sfacecoordrefd(3) + &
367 & sf*ss(2)*sfacecoordrefd(2) + sf*ss(1)*sfacecoordrefd(1)
368  pmd = pmd + cellarea*area_psd + massflowratelocal*mass_psd
369  cellaread = cellaread + pm*area_psd + ptot*pref*area_ptotd + &
370 & aread - overcellaread/cellarea**2
371  mnmd = massflowratelocal*mass_mnd
372  amd = massflowratelocal*uref*mass_ad
373  call popreal8(pm)
374  prefd = prefd + ptot*cellarea*area_ptotd + ptot*&
375 & massflowratelocal*mass_ptotd + pm*pmd
376  vnmd = rhom*mredim*massflowratelocald
377  if (ss(1)**2 + ss(2)**2 + ss(3)**2 .eq. 0.0_8) then
378  tempd0 = 0.0_8
379  else
380  tempd0 = cellaread/(2.0*sqrt(ss(1)**2+ss(2)**2+ss(3)**2))
381  end if
382  temp = gammam*pm/rhom
383  temp0 = sqrt(temp)
384  vmagd = mnmd/temp0
385  if (temp .eq. 0.0_8) then
386  tempd = 0.0_8
387  else
388  tempd = -(vmag*mnmd/(rhom*2.0*temp0**3))
389  end if
390  rhomd = massflowratelocal*rhoref*mass_rhod + vnm*mredim*&
391 & massflowratelocald - temp*tempd
392  pmd = pref*pmd + gammam*tempd
393  gammamd = pm*tempd
394  temp = gammam*pm/rhom
395  if (temp .eq. 0.0_8) then
396  tempd = 0.0_8
397  else
398  tempd = amd/(rhom*2.0*sqrt(temp))
399  end if
400  gammamd = gammamd + pm*tempd
401  pmd = pmd + gammam*tempd
402  rhomd = rhomd - temp*tempd
403  if (vxm**2 + vym**2 + vzm**2 .eq. 0.0_8) then
404  tempd = 0.0_8
405  else
406  tempd = vmagd/(2.0*sqrt(vxm**2+vym**2+vzm**2))
407  end if
408  vzmd = vzmd + uref*massflowratelocal*mass_vzd + 2*vzm*tempd + &
409 & ss(3)*vnmd
410  vymd = vymd + uref*massflowratelocal*mass_vyd + 2*vym*tempd + &
411 & ss(2)*vnmd
412  vxmd = vxmd + uref*massflowratelocal*mass_vxd + 2*vxm*tempd + &
413 & ss(1)*vnmd
414  ssd(3) = ssd(3) + sf*overcellarea*sfacecoordrefd(3) + 2*ss(3)*&
415 & tempd0 + vzm*vnmd
416  sfd = overcellarea*ss(3)*sfacecoordrefd(3) + overcellarea*ss(2&
417 & )*sfacecoordrefd(2) + overcellarea*ss(1)*sfacecoordrefd(1) -&
418 & vmagd - vnmd
419  sfacecoordrefd(3) = 0.0_8
420  ssd(2) = ssd(2) + sf*overcellarea*sfacecoordrefd(2) + 2*ss(2)*&
421 & tempd0 + vym*vnmd
422  sfacecoordrefd(2) = 0.0_8
423  ssd(1) = ssd(1) + sf*overcellarea*sfacecoordrefd(1) + 2*ss(1)*&
424 & tempd0 + vxm*vnmd
425  sfacecoordrefd(1) = 0.0_8
426  ptotd = ptotd + pref*cellarea*area_ptotd + massflowratelocal*&
427 & pref*mass_ptotd
428  rhorefd = rhorefd + rhom*massflowratelocal*mass_rhod
429  ttotd = ttotd + massflowratelocal*tref*mass_ttotd
430  trefd = trefd + ttot*massflowratelocal*mass_ttotd
431  mredimd = mredimd + rhom*vnm*massflowratelocald
432  call computettot_b(rhom, rhomd, vxm, vxmd, vym, vymd, vzm, &
433 & vzmd, pm, pmd, ttot, ttotd)
434  call computeptot_b(rhom, rhomd, vxm, vxmd, vym, vymd, vzm, &
435 & vzmd, pm, pmd, ptot, ptotd)
436  normd = normd + half*ssd
437  call cross_prod_b(arg1(:), arg1d(:), arg2(:), arg2d(:), norm, &
438 & normd)
439  x1d = 0.0_8
440  x3d = 0.0_8
441  x3d = arg2d
442  x1d = -arg2d - arg1d
443  x2d = 0.0_8
444  x2d = arg1d
445  varsd(conn(3, i), izippflowx:izippflowz) = varsd(conn(3, i), &
446 & izippflowx:izippflowz) + x3d
447  varsd(conn(2, i), izippflowx:izippflowz) = varsd(conn(2, i), &
448 & izippflowx:izippflowz) + x2d
449  varsd(conn(1, i), izippflowx:izippflowz) = varsd(conn(1, i), &
450 & izippflowx:izippflowz) + x1d
451  sfd = third*sfd
452  gammamd = third*gammamd
453  pmd = third*pmd
454  vzmd = third*vzmd
455  vymd = third*vymd
456  vxmd = third*vxmd
457  rhomd = third*rhomd
458  do j=3,1,-1
459  varsd(conn(j, i), izippflowsface) = varsd(conn(j, i), &
460 & izippflowsface) + sfd
461  varsd(conn(j, i), izippflowgamma) = varsd(conn(j, i), &
462 & izippflowgamma) + gammamd
463  varsd(conn(j, i), irhoe) = varsd(conn(j, i), irhoe) + pmd
464  varsd(conn(j, i), ivz) = varsd(conn(j, i), ivz) + vzmd
465  varsd(conn(j, i), ivy) = varsd(conn(j, i), ivy) + vymd
466  varsd(conn(j, i), ivx) = varsd(conn(j, i), ivx) + vxmd
467  varsd(conn(j, i), irho) = varsd(conn(j, i), irho) + rhomd
468  end do
469  end if
470  call popcontrol1b(branch)
471  end if
472  end do
473  pointrefd(3) = pointrefd(3) + lref*refpointd(3)
474  refpointd(3) = 0.0_8
475  pointrefd(2) = pointrefd(2) + lref*refpointd(2)
476  refpointd(2) = 0.0_8
477  pointrefd(1) = pointrefd(1) + lref*refpointd(1)
478  if (pref*rhoref .eq. 0.0_8) then
479  tempd = 0.0_8
480  else
481  tempd = mredimd/(2.0*sqrt(pref*rhoref))
482  end if
483  prefd = prefd + rhoref*tempd
484  rhorefd = rhorefd + pref*tempd
485  end subroutine flowintegrationzipper_b
486 
487  subroutine flowintegrationzipper(isinflow, conn, fams, vars, &
488 & localvalues, famlist, sps, ptvalid)
489 ! integrate over the trianges for the inflow/outflow conditions.
490  use constants
491  use blockpointers, only : bctype
492  use sorting, only : faminlist
493  use flowvarrefstate, only : pref, pinf, rhoref, pref, timeref, &
495  use inputphysics, only : pointref, flowtype, rgasdim
496  use flowutils_b, only : computeptot, computettot
498  use utils_b, only : mynorm2, cross_prod
499  implicit none
500 ! input/output variables
501  logical, intent(in) :: isinflow
502  integer(kind=inttype), dimension(:, :), intent(in) :: conn
503  integer(kind=inttype), dimension(:), intent(in) :: fams
504  real(kind=realtype), dimension(:, :), intent(in) :: vars
505  real(kind=realtype), dimension(nlocalvalues), intent(inout) :: &
506 & localvalues
507  integer(kind=inttype), dimension(:), intent(in) :: famlist
508  integer(kind=inttype), intent(in) :: sps
509  logical(kind=inttype), dimension(:), optional, intent(in) :: ptvalid
510 ! working variables
511  integer(kind=inttype) :: i, j
512  real(kind=realtype) :: sf, vmag, vnm, vxm, vym, vzm, fx, fy, fz, u, &
513 & v, w, vnmfreestreamref
514  real(kind=realtype), dimension(3) :: fp, mp, fmom, mmom, refpoint, &
515 & ss, x1, x2, x3, norm, sfacecoordref
516  real(kind=realtype) :: pm, ptot, ttot, rhom, gammam, mnm, &
517 & massflowratelocal, am
518  real(kind=realtype) :: massflowrate, mass_ptot, mass_ttot, mass_ps, &
519 & mass_mn, mass_a, mass_rho, mass_vx, mass_vy, mass_vz, mass_nx, &
520 & mass_ny, mass_nz, mass_vi
521  real(kind=realtype) :: area, cellarea, overcellarea
522  real(kind=realtype) :: area_ptot, area_ps
523  real(kind=realtype) :: govgm1, gm1ovg, viconst, vilocal, pratio
524  real(kind=realtype) :: mredim
525  real(kind=realtype) :: internalflowfact, inflowfact, xc, xco, yc, &
526 & yco, zc, zco, mx, my, mz
527  real(kind=realtype), dimension(3) :: cofsumfx, cofsumfy, cofsumfz
528  logical :: triisvalid
529  intrinsic sqrt
530  intrinsic size
531  intrinsic present
532  intrinsic min
533  real(kind=realtype), dimension(3) :: arg1
534  real(kind=realtype), dimension(3) :: arg2
535  mredim = sqrt(pref*rhoref)
536  fp = zero
537  mp = zero
538  fmom = zero
539  mmom = zero
540  cofsumfx = zero
541  cofsumfy = zero
542  cofsumfz = zero
543  massflowrate = zero
544  area = zero
545  mass_ptot = zero
546  mass_ttot = zero
547  mass_ps = zero
548  mass_mn = zero
549  mass_a = zero
550  mass_rho = zero
551  mass_vx = zero
552  mass_vy = zero
553  mass_vz = zero
554  mass_nx = zero
555  mass_ny = zero
556  mass_nz = zero
557  mass_vi = zero
558  area_ptot = zero
559  area_ps = zero
560  refpoint(1) = lref*pointref(1)
561  refpoint(2) = lref*pointref(2)
562  refpoint(3) = lref*pointref(3)
563  internalflowfact = one
564  if (flowtype .eq. internalflow) internalflowfact = -one
565  inflowfact = one
566  if (isinflow) inflowfact = -one
567 !$ad ii-loop
568  do i=1,size(conn, 2)
569  if (faminlist(fams(i), famlist)) then
570 ! if the ptvalid list is given, check if we should integrate
571 ! this triangle.
572  triisvalid = .true.
573  if (present(ptvalid)) then
574 ! check if each of the three nodes are valid
575  if (((ptvalid(conn(1, i)) .eqv. .false.) .or. (ptvalid(conn(2&
576 & , i)) .eqv. .false.)) .or. (ptvalid(conn(3, i)) .eqv. &
577 & .false.)) triisvalid = .false.
578  end if
579  if (triisvalid) then
580 ! compute the averaged values for this triangle
581  vxm = zero
582  vym = zero
583  vzm = zero
584  rhom = zero
585  pm = zero
586  mnm = zero
587  gammam = zero
588  sf = zero
589  do j=1,3
590  rhom = rhom + vars(conn(j, i), irho)
591  vxm = vxm + vars(conn(j, i), ivx)
592  vym = vym + vars(conn(j, i), ivy)
593  vzm = vzm + vars(conn(j, i), ivz)
594  pm = pm + vars(conn(j, i), irhoe)
595  gammam = gammam + vars(conn(j, i), izippflowgamma)
596  sf = sf + vars(conn(j, i), izippflowsface)
597  end do
598 ! divide by 3 due to the summation above:
599  rhom = third*rhom
600  vxm = third*vxm
601  vym = third*vym
602  vzm = third*vzm
603  pm = third*pm
604  gammam = third*gammam
605  sf = third*sf
606 ! get the nodes of triangle.
607  x1 = vars(conn(1, i), izippflowx:izippflowz)
608  x2 = vars(conn(2, i), izippflowx:izippflowz)
609  x3 = vars(conn(3, i), izippflowx:izippflowz)
610  arg1(:) = x2 - x1
611  arg2(:) = x3 - x1
612  call cross_prod(arg1(:), arg2(:), norm)
613  ss = half*norm
614  call computeptot(rhom, vxm, vym, vzm, pm, ptot)
615  call computettot(rhom, vxm, vym, vzm, pm, ttot)
616  vnm = vxm*ss(1) + vym*ss(2) + vzm*ss(3) - sf
617  vmag = sqrt(vxm**2 + vym**2 + vzm**2) - sf
618  am = sqrt(gammam*pm/rhom)
619  mnm = vmag/sqrt(gammam*pm/rhom)
620  cellarea = sqrt(ss(1)**2 + ss(2)**2 + ss(3)**2)
621  area = area + cellarea
622  overcellarea = 1/cellarea
623  massflowratelocal = rhom*vnm*mredim
624  massflowrate = massflowrate + massflowratelocal
625  pm = pm*pref
626  mass_ptot = mass_ptot + ptot*massflowratelocal*pref
627  mass_ttot = mass_ttot + ttot*massflowratelocal*tref
628  mass_rho = mass_rho + rhom*massflowratelocal*rhoref
629  mass_a = mass_a + am*massflowratelocal*uref
630  mass_ps = mass_ps + pm*massflowratelocal
631  mass_mn = mass_mn + mnm*massflowratelocal
632  area_ptot = area_ptot + ptot*pref*cellarea
633  area_ps = area_ps + pm*cellarea
634  sfacecoordref(1) = sf*ss(1)*overcellarea
635  sfacecoordref(2) = sf*ss(2)*overcellarea
636  sfacecoordref(3) = sf*ss(3)*overcellarea
637  mass_vx = mass_vx + (vxm*uref-sfacecoordref(1))*&
638 & massflowratelocal
639  mass_vy = mass_vy + (vym*uref-sfacecoordref(2))*&
640 & massflowratelocal
641  mass_vz = mass_vz + (vzm*uref-sfacecoordref(3))*&
642 & massflowratelocal
643  govgm1 = gammainf/(gammainf-one)
644  gm1ovg = one/govgm1
645  viconst = two*govgm1*rgasdim
646  if (one .gt. one/ptot) then
647  pratio = one/ptot
648  else
649  pratio = one
650  end if
651  vilocal = sqrt(viconst*(one-pratio**gm1ovg)*ttot*tref)
652  mass_vi = mass_vi + vilocal*massflowratelocal
653  mass_nx = mass_nx + ss(1)*overcellarea*massflowratelocal
654  mass_ny = mass_ny + ss(2)*overcellarea*massflowratelocal
655  mass_nz = mass_nz + ss(3)*overcellarea*massflowratelocal
656 ! compute the average cell center.
657  xco = zero
658  yco = zero
659  zco = zero
660  do j=1,3
661  xco = xco + vars(conn(1, i), izippflowx)
662  yco = yco + vars(conn(2, i), izippflowy)
663  zco = zco + vars(conn(3, i), izippflowz)
664  end do
665 ! finish average for cell center
666  xco = third*xco
667  yco = third*yco
668  zco = third*zco
669 ! x-y-zco is the cell center w.r.t. the origin, x-y-zc is w.r.t. the reference point
670  xc = xco - refpoint(1)
671  yc = yco - refpoint(2)
672  zc = zco - refpoint(3)
673  pm = -(pm-pinf*pref)
674  fx = pm*ss(1)
675  fy = pm*ss(2)
676  fz = pm*ss(3)
677 ! update the pressure force and moment coefficients.
678  fp(1) = fp(1) + fx
679  fp(2) = fp(2) + fy
680  fp(3) = fp(3) + fz
681  mx = yc*fz - zc*fy
682  my = zc*fx - xc*fz
683  mz = xc*fy - yc*fx
684  mp(1) = mp(1) + mx
685  mp(2) = mp(2) + my
686  mp(3) = mp(3) + mz
687 ! center of force computations. here we accumulate in the sums.
688 ! force-x
689  cofsumfx(1) = cofsumfx(1) + xco*fx
690  cofsumfx(2) = cofsumfx(2) + yco*fx
691  cofsumfx(3) = cofsumfx(3) + zco*fx
692 ! force-y
693  cofsumfy(1) = cofsumfy(1) + xco*fy
694  cofsumfy(2) = cofsumfy(2) + yco*fy
695  cofsumfy(3) = cofsumfy(3) + zco*fy
696 ! force-z
697  cofsumfz(1) = cofsumfz(1) + xco*fz
698  cofsumfz(2) = cofsumfz(2) + yco*fz
699  cofsumfz(3) = cofsumfz(3) + zco*fz
700 ! momentum forces
701 ! get unit normal vector.
702  ss = ss/cellarea
703  massflowratelocal = massflowratelocal/timeref*internalflowfact&
704 & *inflowfact
705  fx = massflowratelocal*ss(1)*vxm
706  fy = massflowratelocal*ss(2)*vym
707  fz = massflowratelocal*ss(3)*vzm
708  fmom(1) = fmom(1) - fx
709  fmom(2) = fmom(2) - fy
710  fmom(3) = fmom(3) - fz
711  mx = yc*fz - zc*fy
712  my = zc*fx - xc*fz
713  mz = xc*fy - yc*fx
714  mmom(1) = mmom(1) + mx
715  mmom(2) = mmom(2) + my
716  mmom(3) = mmom(3) + mz
717 ! center of force computations. here we accumulate in the sums.
718 ! force-x
719  cofsumfx(1) = cofsumfx(1) + xco*fx
720  cofsumfx(2) = cofsumfx(2) + yco*fx
721  cofsumfx(3) = cofsumfx(3) + zco*fx
722 ! force-y
723  cofsumfy(1) = cofsumfy(1) + xco*fy
724  cofsumfy(2) = cofsumfy(2) + yco*fy
725  cofsumfy(3) = cofsumfy(3) + zco*fy
726 ! force-z
727  cofsumfz(1) = cofsumfz(1) + xco*fz
728  cofsumfz(2) = cofsumfz(2) + yco*fz
729  cofsumfz(3) = cofsumfz(3) + zco*fz
730  end if
731  end if
732  end do
733 ! increment the local values array with what we computed here
734  localvalues(imassflow) = localvalues(imassflow) + massflowrate
735  localvalues(iarea) = localvalues(iarea) + area
736  localvalues(imassrho) = localvalues(imassrho) + mass_rho
737  localvalues(imassa) = localvalues(imassa) + mass_a
738  localvalues(imassptot) = localvalues(imassptot) + mass_ptot
739  localvalues(imassttot) = localvalues(imassttot) + mass_ttot
740  localvalues(imassps) = localvalues(imassps) + mass_ps
741  localvalues(imassmn) = localvalues(imassmn) + mass_mn
742  localvalues(ifp:ifp+2) = localvalues(ifp:ifp+2) + fp
743  localvalues(iflowfm:iflowfm+2) = localvalues(iflowfm:iflowfm+2) + &
744 & fmom
745  localvalues(iflowmp:iflowmp+2) = localvalues(iflowmp:iflowmp+2) + mp
746  localvalues(iflowmm:iflowmm+2) = localvalues(iflowmm:iflowmm+2) + &
747 & mmom
748  localvalues(icoforcex:icoforcex+2) = localvalues(icoforcex:icoforcex&
749 & +2) + cofsumfx
750  localvalues(icoforcey:icoforcey+2) = localvalues(icoforcey:icoforcey&
751 & +2) + cofsumfy
752  localvalues(icoforcez:icoforcez+2) = localvalues(icoforcez:icoforcez&
753 & +2) + cofsumfz
754  localvalues(iareaptot) = localvalues(iareaptot) + area_ptot
755  localvalues(iareaps) = localvalues(iareaps) + area_ps
756  localvalues(imassvx) = localvalues(imassvx) + mass_vx
757  localvalues(imassvy) = localvalues(imassvy) + mass_vy
758  localvalues(imassvz) = localvalues(imassvz) + mass_vz
759  localvalues(imassnx) = localvalues(imassnx) + mass_nx
760  localvalues(imassny) = localvalues(imassny) + mass_ny
761  localvalues(imassnz) = localvalues(imassnz) + mass_nz
762  localvalues(imassvi) = localvalues(imassvi) + mass_vi
763  end subroutine flowintegrationzipper
764 
765 ! differentiation of wallintegrationzipper in reverse (adjoint) mode (with options noisize i4 dr8 r8):
766 ! gradient of useful results: pointref vars localvalues
767 ! with respect to varying inputs: pointref vars localvalues
768 ! rw status of diff variables: pointref:incr vars:incr localvalues:in-out
769  subroutine wallintegrationzipper_b(conn, fams, vars, varsd, &
770 & localvalues, localvaluesd, famlist, sps)
771  use constants
772  use sorting, only : faminlist
773  use flowvarrefstate, only : lref
774  use inputphysics, only : pointref, pointrefd
776  implicit none
777 ! input/output
778  integer(kind=inttype), dimension(:, :), intent(in) :: conn
779  integer(kind=inttype), dimension(:), intent(in) :: fams
780  real(kind=realtype), dimension(:, :), intent(in) :: vars
781  real(kind=realtype), dimension(:, :) :: varsd
782  real(kind=realtype), intent(inout) :: localvalues(nlocalvalues)
783  real(kind=realtype), intent(inout) :: localvaluesd(nlocalvalues)
784  integer(kind=inttype), dimension(:), intent(in) :: famlist
785  integer(kind=inttype), intent(in) :: sps
786 ! working
787  real(kind=realtype), dimension(3) :: fp, fv, mp, mv
788  real(kind=realtype), dimension(3) :: fpd, fvd, mpd, mvd
789  real(kind=realtype), dimension(3) :: cofsumfx, cofsumfy, cofsumfz
790  real(kind=realtype), dimension(3) :: cofsumfxd, cofsumfyd, cofsumfzd
791  integer(kind=inttype) :: i, j
792  real(kind=realtype), dimension(3) :: ss, norm, refpoint
793  real(kind=realtype), dimension(3) :: ssd, normd, refpointd
794  real(kind=realtype), dimension(3) :: p1, p2, p3, v1, v2, v3, x1, x2&
795 & , x3
796  real(kind=realtype), dimension(3) :: p1d, p2d, p3d, v1d, v2d, v3d, &
797 & x1d, x2d, x3d
798  real(kind=realtype) :: fact, triarea, fx, fy, fz, mx, my, mz, xc, &
799 & xco, yc, yco, zc, zco
800  real(kind=realtype) :: triaread, fxd, fyd, fzd, mxd, myd, mzd, xcd, &
801 & xcod, ycd, ycod, zcd, zcod
802  intrinsic size
803  real(kind=realtype), dimension(3) :: arg1
804  real(kind=realtype), dimension(3) :: arg1d
805  real(kind=realtype), dimension(3) :: arg2
806  real(kind=realtype), dimension(3) :: arg2d
807  real(kind=realtype) :: result1
808  real(kind=realtype) :: result1d
809  real(kind=realtype) :: tempd
810 ! determine the reference point for the moment computation in
811 ! meters.
812  refpoint(1) = lref*pointref(1)
813  refpoint(2) = lref*pointref(2)
814  refpoint(3) = lref*pointref(3)
815  cofsumfzd = 0.0_8
816  cofsumfzd = localvaluesd(icoforcez:icoforcez+2)
817  cofsumfyd = 0.0_8
818  cofsumfyd = localvaluesd(icoforcey:icoforcey+2)
819  cofsumfxd = 0.0_8
820  cofsumfxd = localvaluesd(icoforcex:icoforcex+2)
821  mvd = 0.0_8
822  mvd = localvaluesd(imv:imv+2)
823  mpd = 0.0_8
824  mpd = localvaluesd(imp:imp+2)
825  fvd = 0.0_8
826  fvd = localvaluesd(ifv:ifv+2)
827  fpd = 0.0_8
828  fpd = localvaluesd(ifp:ifp+2)
829  normd = 0.0_8
830  refpointd = 0.0_8
831 !$bwd-of ii-loop
832  do i=1,size(conn, 2)
833  if (faminlist(fams(i), famlist)) then
834 ! get the nodes of triangle.
835  x1 = vars(conn(1, i), izippwallx:izippwallz)
836  x2 = vars(conn(2, i), izippwallx:izippwallz)
837  x3 = vars(conn(3, i), izippwallx:izippwallz)
838  arg1(:) = x2 - x1
839  arg2(:) = x3 - x1
840  call cross_prod(arg1(:), arg2(:), norm)
841  ss = half*norm
842 ! the third here is to account for the summation of p1, p2
843 ! and p3
844  result1 = mynorm2(ss)
845  triarea = result1*third
846 ! compute the average cell center.
847  xco = third*(x1(1)+x2(1)+x3(1))
848  yco = third*(x1(2)+x2(2)+x3(2))
849  zco = third*(x1(3)+x2(3)+x3(3))
850  xc = xco - refpoint(1)
851  yc = yco - refpoint(2)
852  zc = zco - refpoint(3)
853 ! update the pressure force and moment coefficients.
854  p1 = vars(conn(1, i), izippwalltpx:izippwalltpz)
855  p2 = vars(conn(2, i), izippwalltpx:izippwalltpz)
856  p3 = vars(conn(3, i), izippwalltpx:izippwalltpz)
857 ! accumulate in the sums. each force component is tracked separately
858 ! force-x
859 ! force-y
860 ! force-z
861 ! update the viscous force and moment coefficients
862  v1 = vars(conn(1, i), izippwalltvx:izippwalltvz)
863  v2 = vars(conn(2, i), izippwalltvx:izippwalltvz)
864  v3 = vars(conn(3, i), izippwalltvx:izippwalltvz)
865  fx = (v1(1)+v2(1)+v3(1))*triarea
866  fy = (v1(2)+v2(2)+v3(2))*triarea
867  fz = (v1(3)+v2(3)+v3(3))*triarea
868 ! note: momentum forces have opposite sign to pressure forces
869 ! accumulate in the sums. each force component is tracked separately
870 ! force-x
871 ! force-y
872 ! force-z
873  mxd = mvd(1)
874  myd = mvd(2)
875  mzd = mvd(3)
876  zcod = fz*cofsumfzd(3) + fy*cofsumfyd(3) + fx*cofsumfxd(3)
877  fzd = zco*cofsumfzd(3) + yco*cofsumfzd(2) + xco*cofsumfzd(1) + &
878 & yc*mxd - xc*myd + fvd(3)
879  ycod = fz*cofsumfzd(2) + fy*cofsumfyd(2) + fx*cofsumfxd(2)
880  xcod = fz*cofsumfzd(1) + fy*cofsumfyd(1) + fx*cofsumfxd(1)
881  fyd = zco*cofsumfyd(3) + yco*cofsumfyd(2) + xco*cofsumfyd(1) + &
882 & xc*mzd + fvd(2) - zc*mxd
883  fxd = zco*cofsumfxd(3) + yco*cofsumfxd(2) + xco*cofsumfxd(1) + &
884 & zc*myd - yc*mzd + fvd(1)
885  xcd = fy*mzd - fz*myd
886  ycd = fz*mxd - fx*mzd
887  zcd = fx*myd - fy*mxd
888  v1d = 0.0_8
889  v2d = 0.0_8
890  v3d = 0.0_8
891  tempd = triarea*fzd
892  triaread = (v1(3)+v2(3)+v3(3))*fzd + (v1(2)+v2(2)+v3(2))*fyd + (&
893 & v1(1)+v2(1)+v3(1))*fxd
894  v1d(3) = v1d(3) + tempd
895  v2d(3) = v2d(3) + tempd
896  v3d(3) = v3d(3) + tempd
897  tempd = triarea*fyd
898  v1d(2) = v1d(2) + tempd
899  v2d(2) = v2d(2) + tempd
900  v3d(2) = v3d(2) + tempd
901  tempd = triarea*fxd
902  v1d(1) = v1d(1) + tempd
903  v2d(1) = v2d(1) + tempd
904  v3d(1) = v3d(1) + tempd
905  varsd(conn(3, i), izippwalltvx:izippwalltvz) = varsd(conn(3, i)&
906 & , izippwalltvx:izippwalltvz) + v3d
907  varsd(conn(2, i), izippwalltvx:izippwalltvz) = varsd(conn(2, i)&
908 & , izippwalltvx:izippwalltvz) + v2d
909  varsd(conn(1, i), izippwalltvx:izippwalltvz) = varsd(conn(1, i)&
910 & , izippwalltvx:izippwalltvz) + v1d
911  fz = (p1(3)+p2(3)+p3(3))*triarea
912  fy = (p1(2)+p2(2)+p3(2))*triarea
913  fx = (p1(1)+p2(1)+p3(1))*triarea
914  mzd = mpd(3)
915  myd = mpd(2)
916  fxd = zco*cofsumfxd(3) + yco*cofsumfxd(2) + xco*cofsumfxd(1) + &
917 & zc*myd - yc*mzd + fpd(1)
918  mxd = mpd(1)
919  fzd = zco*cofsumfzd(3) + yco*cofsumfzd(2) + xco*cofsumfzd(1) + &
920 & yc*mxd - xc*myd + fpd(3)
921  fyd = zco*cofsumfyd(3) + yco*cofsumfyd(2) + xco*cofsumfyd(1) + &
922 & xc*mzd + fpd(2) - zc*mxd
923  xcd = xcd + fy*mzd - fz*myd
924  xcod = xcod + fz*cofsumfzd(1) + fy*cofsumfyd(1) + fx*cofsumfxd(1&
925 & ) + xcd
926  ycd = ycd + fz*mxd - fx*mzd
927  ycod = ycod + fz*cofsumfzd(2) + fy*cofsumfyd(2) + fx*cofsumfxd(2&
928 & ) + ycd
929  zcd = zcd + fx*myd - fy*mxd
930  zcod = zcod + fz*cofsumfzd(3) + fy*cofsumfyd(3) + fx*cofsumfxd(3&
931 & ) + zcd
932  p1d = 0.0_8
933  p2d = 0.0_8
934  p3d = 0.0_8
935  tempd = triarea*fzd
936  triaread = triaread + (p1(3)+p2(3)+p3(3))*fzd + (p1(2)+p2(2)+p3(&
937 & 2))*fyd + (p1(1)+p2(1)+p3(1))*fxd
938  p1d(3) = p1d(3) + tempd
939  p2d(3) = p2d(3) + tempd
940  p3d(3) = p3d(3) + tempd
941  tempd = triarea*fyd
942  p1d(2) = p1d(2) + tempd
943  p2d(2) = p2d(2) + tempd
944  p3d(2) = p3d(2) + tempd
945  tempd = triarea*fxd
946  p1d(1) = p1d(1) + tempd
947  p2d(1) = p2d(1) + tempd
948  p3d(1) = p3d(1) + tempd
949  varsd(conn(3, i), izippwalltpx:izippwalltpz) = varsd(conn(3, i)&
950 & , izippwalltpx:izippwalltpz) + p3d
951  varsd(conn(2, i), izippwalltpx:izippwalltpz) = varsd(conn(2, i)&
952 & , izippwalltpx:izippwalltpz) + p2d
953  varsd(conn(1, i), izippwalltpx:izippwalltpz) = varsd(conn(1, i)&
954 & , izippwalltpx:izippwalltpz) + p1d
955  refpointd(3) = refpointd(3) - zcd
956  refpointd(2) = refpointd(2) - ycd
957  refpointd(1) = refpointd(1) - xcd
958  x1d = 0.0_8
959  x2d = 0.0_8
960  x3d = 0.0_8
961  tempd = third*zcod
962  x1d(3) = x1d(3) + tempd
963  x2d(3) = x2d(3) + tempd
964  x3d(3) = x3d(3) + tempd
965  tempd = third*ycod
966  x1d(2) = x1d(2) + tempd
967  x2d(2) = x2d(2) + tempd
968  x3d(2) = x3d(2) + tempd
969  tempd = third*xcod
970  x1d(1) = x1d(1) + tempd
971  x2d(1) = x2d(1) + tempd
972  x3d(1) = x3d(1) + tempd
973  result1d = third*triaread
974  call mynorm2_b(ss, ssd, result1d)
975  normd = normd + half*ssd
976  call cross_prod_b(arg1(:), arg1d(:), arg2(:), arg2d(:), norm, &
977 & normd)
978  x3d = x3d + arg2d
979  x1d = x1d - arg2d - arg1d
980  x2d = x2d + arg1d
981  varsd(conn(3, i), izippwallx:izippwallz) = varsd(conn(3, i), &
982 & izippwallx:izippwallz) + x3d
983  varsd(conn(2, i), izippwallx:izippwallz) = varsd(conn(2, i), &
984 & izippwallx:izippwallz) + x2d
985  varsd(conn(1, i), izippwallx:izippwallz) = varsd(conn(1, i), &
986 & izippwallx:izippwallz) + x1d
987  end if
988  end do
989  pointrefd(3) = pointrefd(3) + lref*refpointd(3)
990  refpointd(3) = 0.0_8
991  pointrefd(2) = pointrefd(2) + lref*refpointd(2)
992  refpointd(2) = 0.0_8
993  pointrefd(1) = pointrefd(1) + lref*refpointd(1)
994  end subroutine wallintegrationzipper_b
995 
996  subroutine wallintegrationzipper(conn, fams, vars, localvalues, &
997 & famlist, sps)
998  use constants
999  use sorting, only : faminlist
1000  use flowvarrefstate, only : lref
1001  use inputphysics, only : pointref
1002  use utils_b, only : mynorm2, cross_prod
1003  implicit none
1004 ! input/output
1005  integer(kind=inttype), dimension(:, :), intent(in) :: conn
1006  integer(kind=inttype), dimension(:), intent(in) :: fams
1007  real(kind=realtype), dimension(:, :), intent(in) :: vars
1008  real(kind=realtype), intent(inout) :: localvalues(nlocalvalues)
1009  integer(kind=inttype), dimension(:), intent(in) :: famlist
1010  integer(kind=inttype), intent(in) :: sps
1011 ! working
1012  real(kind=realtype), dimension(3) :: fp, fv, mp, mv
1013  real(kind=realtype), dimension(3) :: cofsumfx, cofsumfy, cofsumfz
1014  integer(kind=inttype) :: i, j
1015  real(kind=realtype), dimension(3) :: ss, norm, refpoint
1016  real(kind=realtype), dimension(3) :: p1, p2, p3, v1, v2, v3, x1, x2&
1017 & , x3
1018  real(kind=realtype) :: fact, triarea, fx, fy, fz, mx, my, mz, xc, &
1019 & xco, yc, yco, zc, zco
1020  intrinsic size
1021  real(kind=realtype), dimension(3) :: arg1
1022  real(kind=realtype), dimension(3) :: arg2
1023  real(kind=realtype) :: result1
1024 ! determine the reference point for the moment computation in
1025 ! meters.
1026  refpoint(1) = lref*pointref(1)
1027  refpoint(2) = lref*pointref(2)
1028  refpoint(3) = lref*pointref(3)
1029  fp = zero
1030  fv = zero
1031  mp = zero
1032  mv = zero
1033  cofsumfx = zero
1034  cofsumfy = zero
1035  cofsumfz = zero
1036 !$ad ii-loop
1037  do i=1,size(conn, 2)
1038  if (faminlist(fams(i), famlist)) then
1039 ! get the nodes of triangle.
1040  x1 = vars(conn(1, i), izippwallx:izippwallz)
1041  x2 = vars(conn(2, i), izippwallx:izippwallz)
1042  x3 = vars(conn(3, i), izippwallx:izippwallz)
1043  arg1(:) = x2 - x1
1044  arg2(:) = x3 - x1
1045  call cross_prod(arg1(:), arg2(:), norm)
1046  ss = half*norm
1047 ! the third here is to account for the summation of p1, p2
1048 ! and p3
1049  result1 = mynorm2(ss)
1050  triarea = result1*third
1051 ! compute the average cell center.
1052  xco = third*(x1(1)+x2(1)+x3(1))
1053  yco = third*(x1(2)+x2(2)+x3(2))
1054  zco = third*(x1(3)+x2(3)+x3(3))
1055  xc = xco - refpoint(1)
1056  yc = yco - refpoint(2)
1057  zc = zco - refpoint(3)
1058 ! update the pressure force and moment coefficients.
1059  p1 = vars(conn(1, i), izippwalltpx:izippwalltpz)
1060  p2 = vars(conn(2, i), izippwalltpx:izippwalltpz)
1061  p3 = vars(conn(3, i), izippwalltpx:izippwalltpz)
1062  fx = (p1(1)+p2(1)+p3(1))*triarea
1063  fy = (p1(2)+p2(2)+p3(2))*triarea
1064  fz = (p1(3)+p2(3)+p3(3))*triarea
1065  fp(1) = fp(1) + fx
1066  fp(2) = fp(2) + fy
1067  fp(3) = fp(3) + fz
1068  mx = yc*fz - zc*fy
1069  my = zc*fx - xc*fz
1070  mz = xc*fy - yc*fx
1071  mp(1) = mp(1) + mx
1072  mp(2) = mp(2) + my
1073  mp(3) = mp(3) + mz
1074 ! accumulate in the sums. each force component is tracked separately
1075 ! force-x
1076  cofsumfx(1) = cofsumfx(1) + xco*fx
1077  cofsumfx(2) = cofsumfx(2) + yco*fx
1078  cofsumfx(3) = cofsumfx(3) + zco*fx
1079 ! force-y
1080  cofsumfy(1) = cofsumfy(1) + xco*fy
1081  cofsumfy(2) = cofsumfy(2) + yco*fy
1082  cofsumfy(3) = cofsumfy(3) + zco*fy
1083 ! force-z
1084  cofsumfz(1) = cofsumfz(1) + xco*fz
1085  cofsumfz(2) = cofsumfz(2) + yco*fz
1086  cofsumfz(3) = cofsumfz(3) + zco*fz
1087 ! update the viscous force and moment coefficients
1088  v1 = vars(conn(1, i), izippwalltvx:izippwalltvz)
1089  v2 = vars(conn(2, i), izippwalltvx:izippwalltvz)
1090  v3 = vars(conn(3, i), izippwalltvx:izippwalltvz)
1091  fx = (v1(1)+v2(1)+v3(1))*triarea
1092  fy = (v1(2)+v2(2)+v3(2))*triarea
1093  fz = (v1(3)+v2(3)+v3(3))*triarea
1094 ! note: momentum forces have opposite sign to pressure forces
1095  fv(1) = fv(1) + fx
1096  fv(2) = fv(2) + fy
1097  fv(3) = fv(3) + fz
1098  mx = yc*fz - zc*fy
1099  my = zc*fx - xc*fz
1100  mz = xc*fy - yc*fx
1101  mv(1) = mv(1) + mx
1102  mv(2) = mv(2) + my
1103  mv(3) = mv(3) + mz
1104 ! accumulate in the sums. each force component is tracked separately
1105 ! force-x
1106  cofsumfx(1) = cofsumfx(1) + xco*fx
1107  cofsumfx(2) = cofsumfx(2) + yco*fx
1108  cofsumfx(3) = cofsumfx(3) + zco*fx
1109 ! force-y
1110  cofsumfy(1) = cofsumfy(1) + xco*fy
1111  cofsumfy(2) = cofsumfy(2) + yco*fy
1112  cofsumfy(3) = cofsumfy(3) + zco*fy
1113 ! force-z
1114  cofsumfz(1) = cofsumfz(1) + xco*fz
1115  cofsumfz(2) = cofsumfz(2) + yco*fz
1116  cofsumfz(3) = cofsumfz(3) + zco*fz
1117  end if
1118  end do
1119 ! increment into the local vector
1120  localvalues(ifp:ifp+2) = localvalues(ifp:ifp+2) + fp
1121  localvalues(ifv:ifv+2) = localvalues(ifv:ifv+2) + fv
1122  localvalues(imp:imp+2) = localvalues(imp:imp+2) + mp
1123  localvalues(imv:imv+2) = localvalues(imv:imv+2) + mv
1124  localvalues(icoforcex:icoforcex+2) = localvalues(icoforcex:icoforcex&
1125 & +2) + cofsumfx
1126  localvalues(icoforcey:icoforcey+2) = localvalues(icoforcey:icoforcey&
1127 & +2) + cofsumfy
1128  localvalues(icoforcez:icoforcez+2) = localvalues(icoforcez:icoforcez&
1129 & +2) + cofsumfz
1130  end subroutine wallintegrationzipper
1131 
1132 end module zipperintegrations_b
1133 
integer(kind=inttype), dimension(:), pointer bctype
integer(kind=inttype), parameter imassvz
Definition: constants.F90:455
integer(kind=inttype), parameter iareaps
Definition: constants.F90:455
real(kind=realtype), parameter zero
Definition: constants.F90:71
integer(kind=inttype), parameter nlocalvalues
Definition: constants.F90:454
integer(kind=inttype), parameter izippflowy
Definition: constants.F90:508
integer(kind=inttype), parameter iflowmp
Definition: constants.F90:455
integer(kind=inttype), parameter imassnx
Definition: constants.F90:455
integer(kind=inttype), parameter imassflow
Definition: constants.F90:455
real(kind=realtype), parameter third
Definition: constants.F90:81
integer(kind=inttype), parameter icoforcez
Definition: constants.F90:455
integer(kind=inttype), parameter imassptot
Definition: constants.F90:455
integer(kind=inttype), parameter iflowfm
Definition: constants.F90:455
integer(kind=inttype), parameter izippwallz
Definition: constants.F90:523
integer, parameter irho
Definition: constants.F90:34
integer(kind=inttype), parameter izippflowx
Definition: constants.F90:507
integer(kind=inttype), parameter imassnz
Definition: constants.F90:455
integer(kind=inttype), parameter imp
Definition: constants.F90:455
integer, parameter ivx
Definition: constants.F90:35
integer(kind=inttype), parameter imassa
Definition: constants.F90:455
integer, parameter irhoe
Definition: constants.F90:38
integer(kind=inttype), parameter ifv
Definition: constants.F90:455
integer(kind=inttype), parameter imassny
Definition: constants.F90:455
integer(kind=inttype), parameter izippflowsface
Definition: constants.F90:506
integer(kind=inttype), parameter icoforcex
Definition: constants.F90:455
real(kind=realtype), parameter one
Definition: constants.F90:72
integer(kind=inttype), parameter iflowmm
Definition: constants.F90:455
integer(kind=inttype), parameter imassvy
Definition: constants.F90:455
real(kind=realtype), parameter half
Definition: constants.F90:80
integer(kind=inttype), parameter imassvx
Definition: constants.F90:455
integer(kind=inttype), parameter imassrho
Definition: constants.F90:455
integer(kind=inttype), parameter izippwalltpz
Definition: constants.F90:516
integer(kind=inttype), parameter imassmn
Definition: constants.F90:455
integer(kind=inttype), parameter icoforcey
Definition: constants.F90:455
integer, parameter ivz
Definition: constants.F90:37
integer(kind=inttype), parameter iarea
Definition: constants.F90:455
integer(kind=inttype), parameter imassvi
Definition: constants.F90:455
real(kind=realtype), parameter two
Definition: constants.F90:73
integer(kind=inttype), parameter imv
Definition: constants.F90:455
integer(kind=inttype), parameter imassps
Definition: constants.F90:455
integer(kind=inttype), parameter izippwalltvx
Definition: constants.F90:517
integer(kind=inttype), parameter izippflowgamma
Definition: constants.F90:505
integer(kind=inttype), parameter izippwalltvz
Definition: constants.F90:519
integer, parameter ivy
Definition: constants.F90:36
integer(kind=inttype), parameter izippwalltpx
Definition: constants.F90:514
integer(kind=inttype), parameter imassttot
Definition: constants.F90:455
integer(kind=inttype), parameter izippwallx
Definition: constants.F90:521
integer(kind=inttype), parameter internalflow
Definition: constants.F90:120
integer(kind=inttype), parameter ifp
Definition: constants.F90:455
integer(kind=inttype), parameter iareaptot
Definition: constants.F90:455
integer(kind=inttype), parameter izippflowz
Definition: constants.F90:509
subroutine computeptot(rho, u, v, w, p, ptot)
subroutine computeptot_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, ptot, ptotd)
subroutine computettot(rho, u, v, w, p, ttot)
Definition: flowUtils_b.f90:66
subroutine computettot_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, ttot, ttotd)
Definition: flowUtils_b.f90:13
real(kind=realtype) gammainf
real(kind=realtype) rhoinfd
real(kind=realtype) uinf
real(kind=realtype) pinf
real(kind=realtype) rgas
real(kind=realtype) uref
real(kind=realtype) trefd
real(kind=realtype) uinfd
real(kind=realtype) rgasd
real(kind=realtype) prefd
real(kind=realtype) rhoref
real(kind=realtype) urefd
real(kind=realtype) pinfd
real(kind=realtype) tref
real(kind=realtype) lref
real(kind=realtype) rhoinf
real(kind=realtype) pref
real(kind=realtype) rhorefd
real(kind=realtype) timeref
real(kind=realtype) timerefd
real(kind=realtype), dimension(3) pointref
Definition: inputParam.F90:602
real(kind=realtype), dimension(3) pointrefd
Definition: inputParam.F90:616
integer(kind=inttype) flowtype
Definition: inputParam.F90:583
real(kind=realtype) rgasdim
Definition: inputParam.F90:595
logical function faminlist(famID, famList)
Definition: sorting.F90:7
type(familyexchange), dimension(:, :), allocatable, target bcfamexchange
real(kind=realtype) function mynorm2(x)
Definition: utils_b.f90:1482
subroutine cross_prod(a, b, c)
Definition: utils_b.f90:1526
subroutine mynorm2_b(x, xd, mynorm2d)
Definition: utils_b.f90:1462
subroutine cross_prod_b(a, ad, b, bd, c, cd)
Definition: utils_b.f90:1504
subroutine wallintegrationzipper(conn, fams, vars, localvalues, famlist, sps)
subroutine flowintegrationzipper(isinflow, conn, fams, vars, localvalues, famlist, sps, ptvalid)
subroutine flowintegrationzipper_b(isinflow, conn, fams, vars, varsd, localvalues, localvaluesd, famlist, sps, ptvalid)
subroutine wallintegrationzipper_b(conn, fams, vars, varsd, localvalues, localvaluesd, famlist, sps)
real(kind=realtype) function triarea(pt1, pt2, pt3)
Definition: stringOps.F90:1309