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