ADflow  v1.0
ADflow is a finite volume RANS solver tailored for gradient-based aerodynamic design optimization.
surfaceIntegrations_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 getcostfunctions in reverse (adjoint) mode (with options noisize i4 dr8 r8):
9 ! gradient of useful results: pref machcoef dragdirection
10 ! liftdirection funcvalues
11 ! with respect to varying inputs: pref machcoef dragdirection
12 ! liftdirection globalvals funcvalues
13 ! rw status of diff variables: pref:incr machcoef:incr dragdirection:incr
14 ! liftdirection:incr globalvals:out funcvalues:in-zero
15  subroutine getcostfunctions_b(globalvals, globalvalsd, funcvalues, &
16 & funcvaluesd)
17  use constants
19  use flowvarrefstate, only : pref, prefd, rhoref, rhorefd, tref, &
27  use inputtsstabderiv, only : tsstability
28  use utils_b, only : computetsderivatives
29  use flowutils_b, only : getdirvector
30  implicit none
31 ! input/output
32  real(kind=realtype), dimension(:, :), intent(in) :: globalvals
33  real(kind=realtype), dimension(:, :) :: globalvalsd
34  real(kind=realtype), dimension(:) :: funcvalues
35  real(kind=realtype), dimension(:) :: funcvaluesd
36 ! working
37  real(kind=realtype) :: fact, factmoment, ovrnts
38  real(kind=realtype) :: factd
39  real(kind=realtype), dimension(3, ntimeintervalsspectral) :: force, &
40 & forcep, forcev, forcem, moment, cforce, cforcep, cforcev, cforcem, &
41 & cmoment, cofx, cofy, cofz
42  real(kind=realtype), dimension(3, ntimeintervalsspectral) :: forced&
43 & , forcepd, forcevd, forcemd, momentd, cforced, cforcepd, cforcevd, &
44 & cforcemd, cmomentd, cofxd, cofyd, cofzd
45  real(kind=realtype), dimension(3) :: vcoordref, vfreestreamref
46  real(kind=realtype) :: mavgptot, mavgttot, mavgrho, mavgps, mflow, &
47 & mavgmn, mavga, mavgvx, mavgvy, mavgvz, garea, mavgvi, fxlift, fylift&
48 & , fzlift
49  real(kind=realtype) :: mavgptotd, mavgttotd, mavgrhod, mavgpsd, &
50 & mflowd, mavgmnd, mavgad, mavgvxd, mavgvyd, mavgvzd, garead, mavgvid&
51 & , fxliftd, fyliftd, fzliftd
52  real(kind=realtype) :: vdotn, mag, u, v, w, ks_comp
53  real(kind=realtype) :: ks_compd
54  integer(kind=inttype) :: sps
55  real(kind=realtype), dimension(8) :: dcdq, dcdqdot
56  real(kind=realtype), dimension(8) :: dcdalpha, dcdalphadot
57  real(kind=realtype), dimension(8) :: coef0
58  intrinsic log
59  intrinsic exp
60  intrinsic sqrt
61  real(kind=realtype) :: temp
62  real(kind=realtype) :: temp0
63  real(kind=realtype) :: temp1
64  real(kind=realtype) :: tempd
65  real(kind=realtype) :: tmp
66  real(kind=realtype) :: tmpd
67  real(kind=realtype) :: tmp0
68  real(kind=realtype) :: tmpd0
69  real(kind=realtype) :: tmp1
70  real(kind=realtype) :: tmpd1
71  real(kind=realtype) :: tmp2
72  real(kind=realtype) :: tmpd2
73  real(kind=realtype) :: tmp3
74  real(kind=realtype) :: tmpd3
75  real(kind=realtype) :: tmp4
76  real(kind=realtype) :: tmpd4
77  real(kind=realtype) :: tmp5
78  real(kind=realtype) :: tmpd5
79  real(kind=realtype) :: tmp6
80  real(kind=realtype) :: tmpd6
81  real(kind=realtype) :: tmp7
82  real(kind=realtype) :: tmpd7
83  real(kind=realtype) :: tmp8
84  real(kind=realtype) :: tmpd8
85  real(kind=realtype) :: tmp9
86  real(kind=realtype) :: tmpd9
87  real(kind=realtype) :: tmp10
88  real(kind=realtype) :: tmpd10
89  real(kind=realtype) :: tmp11
90  real(kind=realtype) :: tmpd11
91  real(kind=realtype) :: tmp12
92  real(kind=realtype) :: tmpd12
93  real(kind=realtype) :: tmp13
94  real(kind=realtype) :: tmpd13
95  real(kind=realtype) :: tmp14
96  real(kind=realtype) :: tmpd14
97  real(kind=realtype) :: tmp15
98  real(kind=realtype) :: tmpd15
99  real(kind=realtype) :: tempd0
100  real(kind=realtype) :: tmp16
101  real(kind=realtype) :: tmpd16
102  real(kind=realtype) :: tmp17
103  real(kind=realtype) :: tmpd17
104  real(kind=realtype) :: tempd1
105  integer :: branch
106 ! factor used for time-averaged quantities.
107  ovrnts = one/ntimeintervalsspectral
108 ! sum pressure and viscous contributions
109  force = globalvals(ifp:ifp+2, :) + globalvals(ifv:ifv+2, :) + &
110 & globalvals(iflowfm:iflowfm+2, :)
111  forcep = globalvals(ifp:ifp+2, :)
112  forcev = globalvals(ifv:ifv+2, :)
113  forcem = globalvals(iflowfm:iflowfm+2, :)
114  cofx = globalvals(icoforcex:icoforcex+2, :)
115  cofy = globalvals(icoforcey:icoforcey+2, :)
116  cofz = globalvals(icoforcez:icoforcez+2, :)
117  moment = globalvals(imp:imp+2, :) + globalvals(imv:imv+2, :) + &
118 & globalvals(iflowmm:iflowmm+2, :)
120  cforce = fact*force
121  cforcep = fact*forcep
122  cforcev = fact*forcev
123  cforcem = fact*forcem
124 ! moment factor has an extra lengthref
125  call pushreal8(fact)
126  fact = fact/(lengthref*lref)
127  cmoment = fact*moment
128 ! zero values since we are summing.
129  funcvalues = zero
130  call pushreal8array(cofx, 3*ntimeintervalsspectral)
131  call pushreal8array(cofy, 3*ntimeintervalsspectral)
132  call pushreal8array(cofz, 3*ntimeintervalsspectral)
133 !$fwd-of ii-loop
134 ! here we finally assign the final function values
135  do sps=1,ntimeintervalsspectral
136  funcvalues(costfuncforcex) = funcvalues(costfuncforcex) + ovrnts*&
137 & force(1, sps)
138  funcvalues(costfuncforcey) = funcvalues(costfuncforcey) + ovrnts*&
139 & force(2, sps)
140  funcvalues(costfuncforcez) = funcvalues(costfuncforcez) + ovrnts*&
141 & force(3, sps)
142  funcvalues(costfuncforcexpressure) = funcvalues(&
143 & costfuncforcexpressure) + ovrnts*forcep(1, sps)
144  funcvalues(costfuncforceypressure) = funcvalues(&
145 & costfuncforceypressure) + ovrnts*forcep(2, sps)
146  funcvalues(costfuncforcezpressure) = funcvalues(&
147 & costfuncforcezpressure) + ovrnts*forcep(3, sps)
148  funcvalues(costfuncforcexviscous) = funcvalues(&
149 & costfuncforcexviscous) + ovrnts*forcev(1, sps)
150  funcvalues(costfuncforceyviscous) = funcvalues(&
151 & costfuncforceyviscous) + ovrnts*forcev(2, sps)
152  funcvalues(costfuncforcezviscous) = funcvalues(&
153 & costfuncforcezviscous) + ovrnts*forcev(3, sps)
154  funcvalues(costfuncforcexmomentum) = funcvalues(&
155 & costfuncforcexmomentum) + ovrnts*forcem(1, sps)
156  funcvalues(costfuncforceymomentum) = funcvalues(&
157 & costfuncforceymomentum) + ovrnts*forcem(2, sps)
158  funcvalues(costfuncforcezmomentum) = funcvalues(&
159 & costfuncforcezmomentum) + ovrnts*forcem(3, sps)
160 ! ------------
161  funcvalues(costfuncforcexcoef) = funcvalues(costfuncforcexcoef) + &
162 & ovrnts*cforce(1, sps)
163  funcvalues(costfuncforceycoef) = funcvalues(costfuncforceycoef) + &
164 & ovrnts*cforce(2, sps)
165  funcvalues(costfuncforcezcoef) = funcvalues(costfuncforcezcoef) + &
166 & ovrnts*cforce(3, sps)
167  funcvalues(costfuncforcexcoefpressure) = funcvalues(&
168 & costfuncforcexcoefpressure) + ovrnts*cforcep(1, sps)
169  funcvalues(costfuncforceycoefpressure) = funcvalues(&
170 & costfuncforceycoefpressure) + ovrnts*cforcep(2, sps)
171  funcvalues(costfuncforcezcoefpressure) = funcvalues(&
172 & costfuncforcezcoefpressure) + ovrnts*cforcep(3, sps)
173  funcvalues(costfuncforcexcoefviscous) = funcvalues(&
174 & costfuncforcexcoefviscous) + ovrnts*cforcev(1, sps)
175  funcvalues(costfuncforceycoefviscous) = funcvalues(&
176 & costfuncforceycoefviscous) + ovrnts*cforcev(2, sps)
177  funcvalues(costfuncforcezcoefviscous) = funcvalues(&
178 & costfuncforcezcoefviscous) + ovrnts*cforcev(3, sps)
179  funcvalues(costfuncforcexcoefmomentum) = funcvalues(&
180 & costfuncforcexcoefmomentum) + ovrnts*cforcem(1, sps)
181  funcvalues(costfuncforceycoefmomentum) = funcvalues(&
182 & costfuncforceycoefmomentum) + ovrnts*cforcem(2, sps)
183  funcvalues(costfuncforcezcoefmomentum) = funcvalues(&
184 & costfuncforcezcoefmomentum) + ovrnts*cforcem(3, sps)
185 ! ------------
186 ! center of pressure (these are actually center of all forces)
187 ! protect the divisions against zero, and divide the weighed sum by the force magnitude
188 ! for this time spectral instance before we add it to the sum
189  if (force(1, sps) .ne. zero) then
190  cofx(:, sps) = cofx(:, sps)/force(1, sps)
191  else
192  cofx(:, sps) = zero
193  end if
194  if (force(2, sps) .ne. zero) then
195  cofy(:, sps) = cofy(:, sps)/force(2, sps)
196  else
197  cofy(:, sps) = zero
198  end if
199  if (force(3, sps) .ne. zero) then
200  cofz(:, sps) = cofz(:, sps)/force(3, sps)
201  else
202  cofz(:, sps) = zero
203  end if
204 ! fx
205  funcvalues(costfunccoforcexx) = funcvalues(costfunccoforcexx) + &
206 & ovrnts*cofx(1, sps)
207  funcvalues(costfunccoforcexy) = funcvalues(costfunccoforcexy) + &
208 & ovrnts*cofx(2, sps)
209  funcvalues(costfunccoforcexz) = funcvalues(costfunccoforcexz) + &
210 & ovrnts*cofx(3, sps)
211 ! fy
212  funcvalues(costfunccoforceyx) = funcvalues(costfunccoforceyx) + &
213 & ovrnts*cofy(1, sps)
214  funcvalues(costfunccoforceyy) = funcvalues(costfunccoforceyy) + &
215 & ovrnts*cofy(2, sps)
216  funcvalues(costfunccoforceyz) = funcvalues(costfunccoforceyz) + &
217 & ovrnts*cofy(3, sps)
218 ! fz
219  funcvalues(costfunccoforcezx) = funcvalues(costfunccoforcezx) + &
220 & ovrnts*cofz(1, sps)
221  funcvalues(costfunccoforcezy) = funcvalues(costfunccoforcezy) + &
222 & ovrnts*cofz(2, sps)
223  funcvalues(costfunccoforcezz) = funcvalues(costfunccoforcezz) + &
224 & ovrnts*cofz(3, sps)
225 ! ------------
226  funcvalues(costfuncmomx) = funcvalues(costfuncmomx) + ovrnts*&
227 & moment(1, sps)
228  funcvalues(costfuncmomy) = funcvalues(costfuncmomy) + ovrnts*&
229 & moment(2, sps)
230  funcvalues(costfuncmomz) = funcvalues(costfuncmomz) + ovrnts*&
231 & moment(3, sps)
232  funcvalues(costfuncmomxcoef) = funcvalues(costfuncmomxcoef) + &
233 & ovrnts*cmoment(1, sps)
234  funcvalues(costfuncmomycoef) = funcvalues(costfuncmomycoef) + &
235 & ovrnts*cmoment(2, sps)
236  funcvalues(costfuncmomzcoef) = funcvalues(costfuncmomzcoef) + &
237 & ovrnts*cmoment(3, sps)
238 ! final part of the ks computation
239  if (computesepsensorks) then
240 ! only calculate the log part if we are actually computing for separation for ks method.
241  ks_comp = ovrnts*(sepsenmaxfamily(sps)+log(globalvals(&
242 & isepsensorks, sps))/sepsenmaxrho)
243  funcvalues(costfuncsepsensorks) = funcvalues(costfuncsepsensorks&
244 & ) + ks_comp
245  funcvalues(costfuncsepsensorksarea) = funcvalues(&
246 & costfuncsepsensorksarea) + ovrnts*globalvals(isepsensorksarea&
247 & , sps)*ks_comp*one/(one+exp(2*sepsensorkssharpness*(ks_comp+&
248 & sepsensorksoffset))) + ovrnts*globalvals(isepsensorarea, sps)
249  end if
250  funcvalues(costfuncsepsensor) = funcvalues(costfuncsepsensor) + &
251 & ovrnts*globalvals(isepsensor, sps)
252  funcvalues(costfunccavitation) = funcvalues(costfunccavitation) + &
253 & ovrnts*globalvals(icavitation, sps)
254 ! final part of the ks computation
255  if (computecavitation) then
256 ! only calculate the log part if we are actually computing for cavitation.
257 ! if we are not computing cavitation, the icpmin in globalvals will be zero,
258 ! which doesn't play well with log. we just want to return zero here.
259  funcvalues(costfunccpmin) = funcvalues(costfunccpmin) + ovrnts*(&
260 & cpmin_family(sps)-log(globalvals(icpmin, sps))/cpmin_rho)
261  end if
262  funcvalues(costfuncaxismoment) = funcvalues(costfuncaxismoment) + &
263 & ovrnts*globalvals(iaxismoment, sps)
264  funcvalues(costfuncsepsensoravgx) = funcvalues(&
265 & costfuncsepsensoravgx) + ovrnts*globalvals(isepavg, sps)
266  funcvalues(costfuncsepsensoravgy) = funcvalues(&
267 & costfuncsepsensoravgy) + ovrnts*globalvals(isepavg+1, sps)
268  funcvalues(costfuncsepsensoravgz) = funcvalues(&
269 & costfuncsepsensoravgz) + ovrnts*globalvals(isepavg+2, sps)
270  funcvalues(costfuncarea) = funcvalues(costfuncarea) + ovrnts*&
271 & globalvals(iarea, sps)
272  funcvalues(costfuncflowpower) = funcvalues(costfuncflowpower) + &
273 & ovrnts*globalvals(ipower, sps)
274  funcvalues(costfunccperror2) = funcvalues(costfunccperror2) + &
275 & ovrnts*globalvals(icperror2, sps)
276 ! mass flow like objective
277  mflow = globalvals(imassflow, sps)
278  if (mflow .ne. zero) then
279  mavgptot = globalvals(imassptot, sps)/mflow
280  mavgttot = globalvals(imassttot, sps)/mflow
281  mavgrho = globalvals(imassrho, sps)/mflow
282  mavgps = globalvals(imassps, sps)/mflow
283  mavgmn = globalvals(imassmn, sps)/mflow
284  mavga = globalvals(imassa, sps)/mflow
285  mavgvx = globalvals(imassvx, sps)/mflow
286  mavgvy = globalvals(imassvy, sps)/mflow
287  mavgvz = globalvals(imassvz, sps)/mflow
288  mavgvi = globalvals(imassvi, sps)/mflow
289  mag = sqrt(globalvals(imassnx, sps)**2 + globalvals(imassny, sps&
290 & )**2 + globalvals(imassnz, sps)**2)
291  else
292  mavgptot = zero
293  mavgttot = zero
294  mavgrho = zero
295  mavgps = zero
296  mavgmn = zero
297  mavga = zero
298  mavgvx = zero
299  mavgvy = zero
300  mavgvz = zero
301  mavgvi = zero
302  end if
303 ! area averaged objectives
304  garea = globalvals(iarea, sps)
305  if (garea .ne. zero) then
306 ! area averaged pressure
307  funcvalues(costfuncaavgptot) = funcvalues(costfuncaavgptot) + &
308 & ovrnts*globalvals(iareaptot, sps)/garea
309  funcvalues(costfuncaavgps) = funcvalues(costfuncaavgps) + ovrnts&
310 & *globalvals(iareaps, sps)/garea
311  end if
312  funcvalues(costfuncmdot) = funcvalues(costfuncmdot) + ovrnts*mflow
313  funcvalues(costfuncmavgptot) = funcvalues(costfuncmavgptot) + &
314 & ovrnts*mavgptot
315  funcvalues(costfuncmavgttot) = funcvalues(costfuncmavgttot) + &
316 & ovrnts*mavgttot
317  funcvalues(costfuncmavgrho) = funcvalues(costfuncmavgrho) + ovrnts&
318 & *mavgrho
319  funcvalues(costfuncmavgps) = funcvalues(costfuncmavgps) + ovrnts*&
320 & mavgps
321  funcvalues(costfuncmavgmn) = funcvalues(costfuncmavgmn) + ovrnts*&
322 & mavgmn
323  funcvalues(costfuncmavga) = funcvalues(costfuncmavga) + ovrnts*&
324 & mavga
325  funcvalues(costfuncmavgvx) = funcvalues(costfuncmavgvx) + ovrnts*&
326 & mavgvx
327  funcvalues(costfuncmavgvy) = funcvalues(costfuncmavgvy) + ovrnts*&
328 & mavgvy
329  funcvalues(costfuncmavgvz) = funcvalues(costfuncmavgvz) + ovrnts*&
330 & mavgvz
331  funcvalues(costfuncmavgvi) = funcvalues(costfuncmavgvi) + ovrnts*&
332 & mavgvi
333 ! bending moment calc - also broken.
334 ! call computerootbendingmoment(cforce, cmoment, liftindex, bendingmoment)
335 ! funcvalues(costfuncbendingcoef) = funcvalues(costfuncbendingcoef) + ovrnts*bendingmoment
336  end do
337 ! lift and drag (coefficients): dot product with the lift/drag direction.
338  tmp = funcvalues(costfuncforcex)*liftdirection(1) + funcvalues(&
339 & costfuncforcey)*liftdirection(2) + funcvalues(costfuncforcez)*&
340 & liftdirection(3)
341  call pushreal8(funcvalues(costfunclift))
342  funcvalues(costfunclift) = tmp
343  tmp0 = funcvalues(costfuncforcexpressure)*liftdirection(1) + &
344 & funcvalues(costfuncforceypressure)*liftdirection(2) + funcvalues(&
346  call pushreal8(funcvalues(costfuncliftpressure))
347  funcvalues(costfuncliftpressure) = tmp0
348  tmp1 = funcvalues(costfuncforcexviscous)*liftdirection(1) + &
349 & funcvalues(costfuncforceyviscous)*liftdirection(2) + funcvalues(&
351  call pushreal8(funcvalues(costfuncliftviscous))
352  funcvalues(costfuncliftviscous) = tmp1
353  tmp2 = funcvalues(costfuncforcexmomentum)*liftdirection(1) + &
354 & funcvalues(costfuncforceymomentum)*liftdirection(2) + funcvalues(&
356  call pushreal8(funcvalues(costfuncliftmomentum))
357  funcvalues(costfuncliftmomentum) = tmp2
358 !-----
359  tmp3 = funcvalues(costfuncforcex)*dragdirection(1) + funcvalues(&
360 & costfuncforcey)*dragdirection(2) + funcvalues(costfuncforcez)*&
361 & dragdirection(3)
362  call pushreal8(funcvalues(costfuncdrag))
363  funcvalues(costfuncdrag) = tmp3
364  tmp4 = funcvalues(costfuncforcexpressure)*dragdirection(1) + &
365 & funcvalues(costfuncforceypressure)*dragdirection(2) + funcvalues(&
367  call pushreal8(funcvalues(costfuncdragpressure))
368  funcvalues(costfuncdragpressure) = tmp4
369  tmp5 = funcvalues(costfuncforcexviscous)*dragdirection(1) + &
370 & funcvalues(costfuncforceyviscous)*dragdirection(2) + funcvalues(&
372  call pushreal8(funcvalues(costfuncdragviscous))
373  funcvalues(costfuncdragviscous) = tmp5
374  tmp6 = funcvalues(costfuncforcexmomentum)*dragdirection(1) + &
375 & funcvalues(costfuncforceymomentum)*dragdirection(2) + funcvalues(&
377  call pushreal8(funcvalues(costfuncdragmomentum))
378  funcvalues(costfuncdragmomentum) = tmp6
379 !-----
380  tmp7 = funcvalues(costfuncforcexcoef)*liftdirection(1) + funcvalues(&
381 & costfuncforceycoef)*liftdirection(2) + funcvalues(&
383  call pushreal8(funcvalues(costfuncliftcoef))
384  funcvalues(costfuncliftcoef) = tmp7
385  tmp8 = funcvalues(costfuncforcexcoefpressure)*liftdirection(1) + &
386 & funcvalues(costfuncforceycoefpressure)*liftdirection(2) + &
388  call pushreal8(funcvalues(costfuncliftcoefpressure))
389  funcvalues(costfuncliftcoefpressure) = tmp8
390  tmp9 = funcvalues(costfuncforcexcoefviscous)*liftdirection(1) + &
391 & funcvalues(costfuncforceycoefviscous)*liftdirection(2) + &
393  call pushreal8(funcvalues(costfuncliftcoefviscous))
394  funcvalues(costfuncliftcoefviscous) = tmp9
395  tmp10 = funcvalues(costfuncforcexcoefmomentum)*liftdirection(1) + &
396 & funcvalues(costfuncforceycoefmomentum)*liftdirection(2) + &
398  call pushreal8(funcvalues(costfuncliftcoefmomentum))
399  funcvalues(costfuncliftcoefmomentum) = tmp10
400 !-----
401  tmp11 = funcvalues(costfuncforcexcoef)*dragdirection(1) + funcvalues&
402 & (costfuncforceycoef)*dragdirection(2) + funcvalues(&
404  call pushreal8(funcvalues(costfuncdragcoef))
405  funcvalues(costfuncdragcoef) = tmp11
406  tmp12 = funcvalues(costfuncforcexcoefpressure)*dragdirection(1) + &
407 & funcvalues(costfuncforceycoefpressure)*dragdirection(2) + &
409  call pushreal8(funcvalues(costfuncdragcoefpressure))
410  funcvalues(costfuncdragcoefpressure) = tmp12
411  tmp13 = funcvalues(costfuncforcexcoefviscous)*dragdirection(1) + &
412 & funcvalues(costfuncforceycoefviscous)*dragdirection(2) + &
414  call pushreal8(funcvalues(costfuncdragcoefviscous))
415  funcvalues(costfuncdragcoefviscous) = tmp13
416  tmp14 = funcvalues(costfuncforcexcoefmomentum)*dragdirection(1) + &
417 & funcvalues(costfuncforceycoefmomentum)*dragdirection(2) + &
419  call pushreal8(funcvalues(costfuncdragcoefmomentum))
420  funcvalues(costfuncdragcoefmomentum) = tmp14
421 ! ----- center of lift
422 ! dot product the 3 forces with the lift direction separately
423  fxlift = funcvalues(costfuncforcex)*liftdirection(1)
424  fylift = funcvalues(costfuncforcey)*liftdirection(2)
425  fzlift = funcvalues(costfuncforcez)*liftdirection(3)
426 ! run the weighed average for the 3 components of center of lift
427 ! protect against division by zero
428  if (fxlift + fylift + fzlift .ne. zero) then
429  tmp15 = (fxlift*funcvalues(costfunccoforcexx)+fylift*funcvalues(&
430 & costfunccoforceyx)+fzlift*funcvalues(costfunccoforcezx))/(fxlift&
431 & +fylift+fzlift)
432  call pushreal8(funcvalues(costfunccofliftx))
433  funcvalues(costfunccofliftx) = tmp15
434  tmp16 = (fxlift*funcvalues(costfunccoforcexy)+fylift*funcvalues(&
435 & costfunccoforceyy)+fzlift*funcvalues(costfunccoforcezy))/(fxlift&
436 & +fylift+fzlift)
437  call pushreal8(funcvalues(costfunccoflifty))
438  funcvalues(costfunccoflifty) = tmp16
439  call pushcontrol1b(0)
440  else
441  call pushcontrol1b(1)
442  end if
443 ! -------------------- time spectral objectives ------------------
444  if (tsstability) then
445  stop
446  else
447  call popcontrol1b(branch)
448  if (branch .eq. 0) then
449  tmpd17 = funcvaluesd(costfunccofliftz)
450  funcvaluesd(costfunccofliftz) = 0.0_8
451  tempd = tmpd17/(fxlift+fylift+fzlift)
452  funcvaluesd(costfunccoforcexz) = funcvaluesd(costfunccoforcexz) &
453 & + fxlift*tempd
454  funcvaluesd(costfunccoforceyz) = funcvaluesd(costfunccoforceyz) &
455 & + fylift*tempd
456  funcvaluesd(costfunccoforcezz) = funcvaluesd(costfunccoforcezz) &
457 & + fzlift*tempd
458  tempd0 = -((fxlift*funcvalues(costfunccoforcexz)+fylift*&
459 & funcvalues(costfunccoforceyz)+fzlift*funcvalues(&
460 & costfunccoforcezz))*tempd/(fxlift+fylift+fzlift))
461  fxliftd = funcvalues(costfunccoforcexz)*tempd + tempd0
462  fyliftd = funcvalues(costfunccoforceyz)*tempd + tempd0
463  fzliftd = funcvalues(costfunccoforcezz)*tempd + tempd0
464  call popreal8(funcvalues(costfunccoflifty))
465  tmpd16 = funcvaluesd(costfunccoflifty)
466  funcvaluesd(costfunccoflifty) = 0.0_8
467  tempd = tmpd16/(fxlift+fylift+fzlift)
468  funcvaluesd(costfunccoforcexy) = funcvaluesd(costfunccoforcexy) &
469 & + fxlift*tempd
470  funcvaluesd(costfunccoforceyy) = funcvaluesd(costfunccoforceyy) &
471 & + fylift*tempd
472  funcvaluesd(costfunccoforcezy) = funcvaluesd(costfunccoforcezy) &
473 & + fzlift*tempd
474  tempd0 = -((fxlift*funcvalues(costfunccoforcexy)+fylift*&
475 & funcvalues(costfunccoforceyy)+fzlift*funcvalues(&
476 & costfunccoforcezy))*tempd/(fxlift+fylift+fzlift))
477  fxliftd = fxliftd + funcvalues(costfunccoforcexy)*tempd + tempd0
478  fyliftd = fyliftd + funcvalues(costfunccoforceyy)*tempd + tempd0
479  fzliftd = fzliftd + funcvalues(costfunccoforcezy)*tempd + tempd0
480  call popreal8(funcvalues(costfunccofliftx))
481  tmpd15 = funcvaluesd(costfunccofliftx)
482  funcvaluesd(costfunccofliftx) = 0.0_8
483  tempd = tmpd15/(fxlift+fylift+fzlift)
484  funcvaluesd(costfunccoforcexx) = funcvaluesd(costfunccoforcexx) &
485 & + fxlift*tempd
486  funcvaluesd(costfunccoforceyx) = funcvaluesd(costfunccoforceyx) &
487 & + fylift*tempd
488  funcvaluesd(costfunccoforcezx) = funcvaluesd(costfunccoforcezx) &
489 & + fzlift*tempd
490  tempd0 = -((fxlift*funcvalues(costfunccoforcexx)+fylift*&
491 & funcvalues(costfunccoforceyx)+fzlift*funcvalues(&
492 & costfunccoforcezx))*tempd/(fxlift+fylift+fzlift))
493  fxliftd = fxliftd + funcvalues(costfunccoforcexx)*tempd + tempd0
494  fyliftd = fyliftd + funcvalues(costfunccoforceyx)*tempd + tempd0
495  fzliftd = fzliftd + funcvalues(costfunccoforcezx)*tempd + tempd0
496  else
497  funcvaluesd(costfunccofliftz) = 0.0_8
498  funcvaluesd(costfunccoflifty) = 0.0_8
499  funcvaluesd(costfunccofliftx) = 0.0_8
500  fxliftd = 0.0_8
501  fyliftd = 0.0_8
502  fzliftd = 0.0_8
503  end if
504  funcvaluesd(costfuncforcez) = funcvaluesd(costfuncforcez) + &
505 & liftdirection(3)*fzliftd
506  liftdirectiond(3) = liftdirectiond(3) + funcvalues(costfuncforcez)&
507 & *fzliftd
508  funcvaluesd(costfuncforcey) = funcvaluesd(costfuncforcey) + &
509 & liftdirection(2)*fyliftd
510  liftdirectiond(2) = liftdirectiond(2) + funcvalues(costfuncforcey)&
511 & *fyliftd
512  funcvaluesd(costfuncforcex) = funcvaluesd(costfuncforcex) + &
513 & liftdirection(1)*fxliftd
514  liftdirectiond(1) = liftdirectiond(1) + funcvalues(costfuncforcex)&
515 & *fxliftd
516  call popreal8(funcvalues(costfuncdragcoefmomentum))
517  tmpd14 = funcvaluesd(costfuncdragcoefmomentum)
518  funcvaluesd(costfuncdragcoefmomentum) = 0.0_8
519  funcvaluesd(costfuncforcexcoefmomentum) = funcvaluesd(&
521  dragdirectiond(1) = dragdirectiond(1) + funcvalues(&
523  funcvaluesd(costfuncforceycoefmomentum) = funcvaluesd(&
525  dragdirectiond(2) = dragdirectiond(2) + funcvalues(&
527  funcvaluesd(costfuncforcezcoefmomentum) = funcvaluesd(&
529  dragdirectiond(3) = dragdirectiond(3) + funcvalues(&
531  call popreal8(funcvalues(costfuncdragcoefviscous))
532  tmpd13 = funcvaluesd(costfuncdragcoefviscous)
533  funcvaluesd(costfuncdragcoefviscous) = 0.0_8
534  funcvaluesd(costfuncforcexcoefviscous) = funcvaluesd(&
536  dragdirectiond(1) = dragdirectiond(1) + funcvalues(&
538  funcvaluesd(costfuncforceycoefviscous) = funcvaluesd(&
540  dragdirectiond(2) = dragdirectiond(2) + funcvalues(&
542  funcvaluesd(costfuncforcezcoefviscous) = funcvaluesd(&
544  dragdirectiond(3) = dragdirectiond(3) + funcvalues(&
546  call popreal8(funcvalues(costfuncdragcoefpressure))
547  tmpd12 = funcvaluesd(costfuncdragcoefpressure)
548  funcvaluesd(costfuncdragcoefpressure) = 0.0_8
549  funcvaluesd(costfuncforcexcoefpressure) = funcvaluesd(&
551  dragdirectiond(1) = dragdirectiond(1) + funcvalues(&
553  funcvaluesd(costfuncforceycoefpressure) = funcvaluesd(&
555  dragdirectiond(2) = dragdirectiond(2) + funcvalues(&
557  funcvaluesd(costfuncforcezcoefpressure) = funcvaluesd(&
559  dragdirectiond(3) = dragdirectiond(3) + funcvalues(&
561  call popreal8(funcvalues(costfuncdragcoef))
562  tmpd11 = funcvaluesd(costfuncdragcoef)
563  funcvaluesd(costfuncdragcoef) = 0.0_8
564  funcvaluesd(costfuncforcexcoef) = funcvaluesd(costfuncforcexcoef) &
565 & + dragdirection(1)*tmpd11
566  dragdirectiond(1) = dragdirectiond(1) + funcvalues(&
567 & costfuncforcexcoef)*tmpd11
568  funcvaluesd(costfuncforceycoef) = funcvaluesd(costfuncforceycoef) &
569 & + dragdirection(2)*tmpd11
570  dragdirectiond(2) = dragdirectiond(2) + funcvalues(&
571 & costfuncforceycoef)*tmpd11
572  funcvaluesd(costfuncforcezcoef) = funcvaluesd(costfuncforcezcoef) &
573 & + dragdirection(3)*tmpd11
574  dragdirectiond(3) = dragdirectiond(3) + funcvalues(&
575 & costfuncforcezcoef)*tmpd11
576  call popreal8(funcvalues(costfuncliftcoefmomentum))
577  tmpd10 = funcvaluesd(costfuncliftcoefmomentum)
578  funcvaluesd(costfuncliftcoefmomentum) = 0.0_8
579  funcvaluesd(costfuncforcexcoefmomentum) = funcvaluesd(&
581  liftdirectiond(1) = liftdirectiond(1) + funcvalues(&
583  funcvaluesd(costfuncforceycoefmomentum) = funcvaluesd(&
585  liftdirectiond(2) = liftdirectiond(2) + funcvalues(&
587  funcvaluesd(costfuncforcezcoefmomentum) = funcvaluesd(&
589  liftdirectiond(3) = liftdirectiond(3) + funcvalues(&
591  call popreal8(funcvalues(costfuncliftcoefviscous))
592  tmpd9 = funcvaluesd(costfuncliftcoefviscous)
593  funcvaluesd(costfuncliftcoefviscous) = 0.0_8
594  funcvaluesd(costfuncforcexcoefviscous) = funcvaluesd(&
596  liftdirectiond(1) = liftdirectiond(1) + funcvalues(&
598  funcvaluesd(costfuncforceycoefviscous) = funcvaluesd(&
600  liftdirectiond(2) = liftdirectiond(2) + funcvalues(&
602  funcvaluesd(costfuncforcezcoefviscous) = funcvaluesd(&
604  liftdirectiond(3) = liftdirectiond(3) + funcvalues(&
606  call popreal8(funcvalues(costfuncliftcoefpressure))
607  tmpd8 = funcvaluesd(costfuncliftcoefpressure)
608  funcvaluesd(costfuncliftcoefpressure) = 0.0_8
609  funcvaluesd(costfuncforcexcoefpressure) = funcvaluesd(&
611  liftdirectiond(1) = liftdirectiond(1) + funcvalues(&
613  funcvaluesd(costfuncforceycoefpressure) = funcvaluesd(&
615  liftdirectiond(2) = liftdirectiond(2) + funcvalues(&
617  funcvaluesd(costfuncforcezcoefpressure) = funcvaluesd(&
619  liftdirectiond(3) = liftdirectiond(3) + funcvalues(&
621  call popreal8(funcvalues(costfuncliftcoef))
622  tmpd7 = funcvaluesd(costfuncliftcoef)
623  funcvaluesd(costfuncliftcoef) = 0.0_8
624  funcvaluesd(costfuncforcexcoef) = funcvaluesd(costfuncforcexcoef) &
625 & + liftdirection(1)*tmpd7
626  liftdirectiond(1) = liftdirectiond(1) + funcvalues(&
627 & costfuncforcexcoef)*tmpd7
628  funcvaluesd(costfuncforceycoef) = funcvaluesd(costfuncforceycoef) &
629 & + liftdirection(2)*tmpd7
630  liftdirectiond(2) = liftdirectiond(2) + funcvalues(&
631 & costfuncforceycoef)*tmpd7
632  funcvaluesd(costfuncforcezcoef) = funcvaluesd(costfuncforcezcoef) &
633 & + liftdirection(3)*tmpd7
634  liftdirectiond(3) = liftdirectiond(3) + funcvalues(&
635 & costfuncforcezcoef)*tmpd7
636  call popreal8(funcvalues(costfuncdragmomentum))
637  tmpd6 = funcvaluesd(costfuncdragmomentum)
638  funcvaluesd(costfuncdragmomentum) = 0.0_8
639  funcvaluesd(costfuncforcexmomentum) = funcvaluesd(&
641  dragdirectiond(1) = dragdirectiond(1) + funcvalues(&
642 & costfuncforcexmomentum)*tmpd6
643  funcvaluesd(costfuncforceymomentum) = funcvaluesd(&
645  dragdirectiond(2) = dragdirectiond(2) + funcvalues(&
646 & costfuncforceymomentum)*tmpd6
647  funcvaluesd(costfuncforcezmomentum) = funcvaluesd(&
649  dragdirectiond(3) = dragdirectiond(3) + funcvalues(&
650 & costfuncforcezmomentum)*tmpd6
651  call popreal8(funcvalues(costfuncdragviscous))
652  tmpd5 = funcvaluesd(costfuncdragviscous)
653  funcvaluesd(costfuncdragviscous) = 0.0_8
654  funcvaluesd(costfuncforcexviscous) = funcvaluesd(&
656  dragdirectiond(1) = dragdirectiond(1) + funcvalues(&
657 & costfuncforcexviscous)*tmpd5
658  funcvaluesd(costfuncforceyviscous) = funcvaluesd(&
660  dragdirectiond(2) = dragdirectiond(2) + funcvalues(&
661 & costfuncforceyviscous)*tmpd5
662  funcvaluesd(costfuncforcezviscous) = funcvaluesd(&
664  dragdirectiond(3) = dragdirectiond(3) + funcvalues(&
665 & costfuncforcezviscous)*tmpd5
666  call popreal8(funcvalues(costfuncdragpressure))
667  tmpd4 = funcvaluesd(costfuncdragpressure)
668  funcvaluesd(costfuncdragpressure) = 0.0_8
669  funcvaluesd(costfuncforcexpressure) = funcvaluesd(&
671  dragdirectiond(1) = dragdirectiond(1) + funcvalues(&
672 & costfuncforcexpressure)*tmpd4
673  funcvaluesd(costfuncforceypressure) = funcvaluesd(&
675  dragdirectiond(2) = dragdirectiond(2) + funcvalues(&
676 & costfuncforceypressure)*tmpd4
677  funcvaluesd(costfuncforcezpressure) = funcvaluesd(&
679  dragdirectiond(3) = dragdirectiond(3) + funcvalues(&
680 & costfuncforcezpressure)*tmpd4
681  call popreal8(funcvalues(costfuncdrag))
682  tmpd3 = funcvaluesd(costfuncdrag)
683  funcvaluesd(costfuncdrag) = 0.0_8
684  funcvaluesd(costfuncforcex) = funcvaluesd(costfuncforcex) + &
685 & dragdirection(1)*tmpd3
686  dragdirectiond(1) = dragdirectiond(1) + funcvalues(costfuncforcex)&
687 & *tmpd3
688  funcvaluesd(costfuncforcey) = funcvaluesd(costfuncforcey) + &
689 & dragdirection(2)*tmpd3
690  dragdirectiond(2) = dragdirectiond(2) + funcvalues(costfuncforcey)&
691 & *tmpd3
692  funcvaluesd(costfuncforcez) = funcvaluesd(costfuncforcez) + &
693 & dragdirection(3)*tmpd3
694  dragdirectiond(3) = dragdirectiond(3) + funcvalues(costfuncforcez)&
695 & *tmpd3
696  call popreal8(funcvalues(costfuncliftmomentum))
697  tmpd2 = funcvaluesd(costfuncliftmomentum)
698  funcvaluesd(costfuncliftmomentum) = 0.0_8
699  funcvaluesd(costfuncforcexmomentum) = funcvaluesd(&
701  liftdirectiond(1) = liftdirectiond(1) + funcvalues(&
702 & costfuncforcexmomentum)*tmpd2
703  funcvaluesd(costfuncforceymomentum) = funcvaluesd(&
705  liftdirectiond(2) = liftdirectiond(2) + funcvalues(&
706 & costfuncforceymomentum)*tmpd2
707  funcvaluesd(costfuncforcezmomentum) = funcvaluesd(&
709  liftdirectiond(3) = liftdirectiond(3) + funcvalues(&
710 & costfuncforcezmomentum)*tmpd2
711  call popreal8(funcvalues(costfuncliftviscous))
712  tmpd1 = funcvaluesd(costfuncliftviscous)
713  funcvaluesd(costfuncliftviscous) = 0.0_8
714  funcvaluesd(costfuncforcexviscous) = funcvaluesd(&
716  liftdirectiond(1) = liftdirectiond(1) + funcvalues(&
717 & costfuncforcexviscous)*tmpd1
718  funcvaluesd(costfuncforceyviscous) = funcvaluesd(&
720  liftdirectiond(2) = liftdirectiond(2) + funcvalues(&
721 & costfuncforceyviscous)*tmpd1
722  funcvaluesd(costfuncforcezviscous) = funcvaluesd(&
724  liftdirectiond(3) = liftdirectiond(3) + funcvalues(&
725 & costfuncforcezviscous)*tmpd1
726  call popreal8(funcvalues(costfuncliftpressure))
727  tmpd0 = funcvaluesd(costfuncliftpressure)
728  funcvaluesd(costfuncliftpressure) = 0.0_8
729  funcvaluesd(costfuncforcexpressure) = funcvaluesd(&
731  liftdirectiond(1) = liftdirectiond(1) + funcvalues(&
732 & costfuncforcexpressure)*tmpd0
733  funcvaluesd(costfuncforceypressure) = funcvaluesd(&
735  liftdirectiond(2) = liftdirectiond(2) + funcvalues(&
736 & costfuncforceypressure)*tmpd0
737  funcvaluesd(costfuncforcezpressure) = funcvaluesd(&
739  liftdirectiond(3) = liftdirectiond(3) + funcvalues(&
740 & costfuncforcezpressure)*tmpd0
741  call popreal8(funcvalues(costfunclift))
742  tmpd = funcvaluesd(costfunclift)
743  funcvaluesd(costfunclift) = 0.0_8
744  funcvaluesd(costfuncforcex) = funcvaluesd(costfuncforcex) + &
745 & liftdirection(1)*tmpd
746  liftdirectiond(1) = liftdirectiond(1) + funcvalues(costfuncforcex)&
747 & *tmpd
748  funcvaluesd(costfuncforcey) = funcvaluesd(costfuncforcey) + &
749 & liftdirection(2)*tmpd
750  liftdirectiond(2) = liftdirectiond(2) + funcvalues(costfuncforcey)&
751 & *tmpd
752  funcvaluesd(costfuncforcez) = funcvaluesd(costfuncforcez) + &
753 & liftdirection(3)*tmpd
754  liftdirectiond(3) = liftdirectiond(3) + funcvalues(costfuncforcez)&
755 & *tmpd
756  globalvalsd = 0.0_8
757  momentd = 0.0_8
758  cforced = 0.0_8
759  cofxd = 0.0_8
760  cofyd = 0.0_8
761  cofzd = 0.0_8
762  forced = 0.0_8
763  cforcemd = 0.0_8
764  forcemd = 0.0_8
765  cforcepd = 0.0_8
766  forcepd = 0.0_8
767  cforcevd = 0.0_8
768  cmomentd = 0.0_8
769  forcevd = 0.0_8
770  call popreal8array(cofz, 3*ntimeintervalsspectral)
771  call popreal8array(cofy, 3*ntimeintervalsspectral)
772  call popreal8array(cofx, 3*ntimeintervalsspectral)
773 !$bwd-of ii-loop
774  do sps=1,ntimeintervalsspectral
775 ! ------------
776 ! ------------
777 ! center of pressure (these are actually center of all forces)
778 ! protect the divisions against zero, and divide the weighed sum by the force magnitude
779 ! for this time spectral instance before we add it to the sum
780  if (force(1, sps) .ne. zero) then
781  call pushcontrol1b(0)
782  else
783  call pushcontrol1b(1)
784  end if
785  if (force(2, sps) .ne. zero) then
786  call pushcontrol1b(0)
787  else
788  call pushcontrol1b(1)
789  end if
790  if (force(3, sps) .ne. zero) then
791  call pushcontrol1b(0)
792  else
793  call pushcontrol1b(1)
794  end if
795 ! fx
796 ! fy
797 ! fz
798 ! ------------
799 ! final part of the ks computation
800  if (computesepsensorks) then
801 ! only calculate the log part if we are actually computing for separation for ks method.
802  ks_comp = ovrnts*(sepsenmaxfamily(sps)+log(globalvals(&
803 & isepsensorks, sps))/sepsenmaxrho)
804  call pushcontrol1b(0)
805  else
806  call pushcontrol1b(1)
807  end if
808 ! final part of the ks computation
809  if (computecavitation) then
810  call pushcontrol1b(0)
811  else
812  call pushcontrol1b(1)
813  end if
814 ! mass flow like objective
815  mflow = globalvals(imassflow, sps)
816  if (mflow .ne. zero) then
817  call pushcontrol1b(0)
818  else
819  call pushcontrol1b(1)
820  end if
821 ! area averaged objectives
822  garea = globalvals(iarea, sps)
823  if (garea .ne. zero) then
824  call pushcontrol1b(0)
825  else
826  call pushcontrol1b(1)
827  end if
828  mavgvid = ovrnts*funcvaluesd(costfuncmavgvi)
829  mavgvzd = ovrnts*funcvaluesd(costfuncmavgvz)
830  mavgvyd = ovrnts*funcvaluesd(costfuncmavgvy)
831  mavgvxd = ovrnts*funcvaluesd(costfuncmavgvx)
832  mavgad = ovrnts*funcvaluesd(costfuncmavga)
833  mavgmnd = ovrnts*funcvaluesd(costfuncmavgmn)
834  mavgpsd = ovrnts*funcvaluesd(costfuncmavgps)
835  mavgrhod = ovrnts*funcvaluesd(costfuncmavgrho)
836  mavgttotd = ovrnts*funcvaluesd(costfuncmavgttot)
837  mavgptotd = ovrnts*funcvaluesd(costfuncmavgptot)
838  mflowd = ovrnts*funcvaluesd(costfuncmdot)
839  call popcontrol1b(branch)
840  if (branch .eq. 0) then
841  tempd = ovrnts*funcvaluesd(costfuncaavgps)/garea
842  globalvalsd(iareaps, sps) = globalvalsd(iareaps, sps) + tempd
843  garead = -(globalvals(iareaps, sps)*tempd/garea)
844  tempd = ovrnts*funcvaluesd(costfuncaavgptot)/garea
845  globalvalsd(iareaptot, sps) = globalvalsd(iareaptot, sps) + &
846 & tempd
847  garead = garead - globalvals(iareaptot, sps)*tempd/garea
848  else
849  garead = 0.0_8
850  end if
851  globalvalsd(iarea, sps) = globalvalsd(iarea, sps) + garead
852  call popcontrol1b(branch)
853  if (branch .eq. 0) then
854  globalvalsd(imassvi, sps) = globalvalsd(imassvi, sps) + &
855 & mavgvid/mflow
856  mflowd = mflowd - globalvals(imassvi, sps)*mavgvid/mflow**2 - &
857 & globalvals(imassvz, sps)*mavgvzd/mflow**2 - globalvals(&
858 & imassvy, sps)*mavgvyd/mflow**2 - globalvals(imassvx, sps)*&
859 & mavgvxd/mflow**2 - globalvals(imassa, sps)*mavgad/mflow**2 -&
860 & globalvals(imassmn, sps)*mavgmnd/mflow**2 - globalvals(&
861 & imassps, sps)*mavgpsd/mflow**2 - globalvals(imassrho, sps)*&
862 & mavgrhod/mflow**2 - globalvals(imassttot, sps)*mavgttotd/&
863 & mflow**2 - globalvals(imassptot, sps)*mavgptotd/mflow**2
864  globalvalsd(imassvz, sps) = globalvalsd(imassvz, sps) + &
865 & mavgvzd/mflow
866  globalvalsd(imassvy, sps) = globalvalsd(imassvy, sps) + &
867 & mavgvyd/mflow
868  globalvalsd(imassvx, sps) = globalvalsd(imassvx, sps) + &
869 & mavgvxd/mflow
870  globalvalsd(imassa, sps) = globalvalsd(imassa, sps) + mavgad/&
871 & mflow
872  globalvalsd(imassmn, sps) = globalvalsd(imassmn, sps) + &
873 & mavgmnd/mflow
874  globalvalsd(imassps, sps) = globalvalsd(imassps, sps) + &
875 & mavgpsd/mflow
876  globalvalsd(imassrho, sps) = globalvalsd(imassrho, sps) + &
877 & mavgrhod/mflow
878  globalvalsd(imassttot, sps) = globalvalsd(imassttot, sps) + &
879 & mavgttotd/mflow
880  globalvalsd(imassptot, sps) = globalvalsd(imassptot, sps) + &
881 & mavgptotd/mflow
882  end if
883  globalvalsd(imassflow, sps) = globalvalsd(imassflow, sps) + &
884 & mflowd
885  globalvalsd(icperror2, sps) = globalvalsd(icperror2, sps) + &
886 & ovrnts*funcvaluesd(costfunccperror2)
887  globalvalsd(ipower, sps) = globalvalsd(ipower, sps) + ovrnts*&
888 & funcvaluesd(costfuncflowpower)
889  globalvalsd(iarea, sps) = globalvalsd(iarea, sps) + ovrnts*&
890 & funcvaluesd(costfuncarea)
891  globalvalsd(isepavg+2, sps) = globalvalsd(isepavg+2, sps) + &
892 & ovrnts*funcvaluesd(costfuncsepsensoravgz)
893  globalvalsd(isepavg+1, sps) = globalvalsd(isepavg+1, sps) + &
894 & ovrnts*funcvaluesd(costfuncsepsensoravgy)
895  globalvalsd(isepavg, sps) = globalvalsd(isepavg, sps) + ovrnts*&
896 & funcvaluesd(costfuncsepsensoravgx)
897  globalvalsd(iaxismoment, sps) = globalvalsd(iaxismoment, sps) + &
898 & ovrnts*funcvaluesd(costfuncaxismoment)
899  call popcontrol1b(branch)
900  if (branch .eq. 0) globalvalsd(icpmin, sps) = globalvalsd(icpmin&
901 & , sps) - ovrnts*funcvaluesd(costfunccpmin)/(globalvals(&
902 & icpmin, sps)*cpmin_rho)
903  globalvalsd(icavitation, sps) = globalvalsd(icavitation, sps) + &
904 & ovrnts*funcvaluesd(costfunccavitation)
905  globalvalsd(isepsensor, sps) = globalvalsd(isepsensor, sps) + &
906 & ovrnts*funcvaluesd(costfuncsepsensor)
907  call popcontrol1b(branch)
908  if (branch .eq. 0) then
909  temp1 = 2*sepsensorkssharpness*(sepsensorksoffset+ks_comp)
910  temp0 = one + exp(temp1)
911  tempd1 = ovrnts*one*funcvaluesd(costfuncsepsensorksarea)/temp0
912  globalvalsd(isepsensorarea, sps) = globalvalsd(isepsensorarea&
913 & , sps) + ovrnts*funcvaluesd(costfuncsepsensorksarea)
914  globalvalsd(isepsensorksarea, sps) = globalvalsd(&
915 & isepsensorksarea, sps) + ks_comp*tempd1
916  ks_compd = (globalvals(isepsensorksarea, sps)-&
917 & sepsensorkssharpness*2*exp(temp1)*globalvals(&
918 & isepsensorksarea, sps)*ks_comp/temp0)*tempd1 + funcvaluesd(&
920  globalvalsd(isepsensorks, sps) = globalvalsd(isepsensorks, sps&
921 & ) + ovrnts*ks_compd/(globalvals(isepsensorks, sps)*&
922 & sepsenmaxrho)
923  end if
924  cmomentd(3, sps) = cmomentd(3, sps) + ovrnts*funcvaluesd(&
926  cmomentd(2, sps) = cmomentd(2, sps) + ovrnts*funcvaluesd(&
928  cmomentd(1, sps) = cmomentd(1, sps) + ovrnts*funcvaluesd(&
930  momentd(3, sps) = momentd(3, sps) + ovrnts*funcvaluesd(&
931 & costfuncmomz)
932  momentd(2, sps) = momentd(2, sps) + ovrnts*funcvaluesd(&
933 & costfuncmomy)
934  momentd(1, sps) = momentd(1, sps) + ovrnts*funcvaluesd(&
935 & costfuncmomx)
936  cofzd(3, sps) = cofzd(3, sps) + ovrnts*funcvaluesd(&
938  cofzd(2, sps) = cofzd(2, sps) + ovrnts*funcvaluesd(&
940  cofzd(1, sps) = cofzd(1, sps) + ovrnts*funcvaluesd(&
942  cofyd(3, sps) = cofyd(3, sps) + ovrnts*funcvaluesd(&
944  cofyd(2, sps) = cofyd(2, sps) + ovrnts*funcvaluesd(&
946  cofyd(1, sps) = cofyd(1, sps) + ovrnts*funcvaluesd(&
948  cofxd(3, sps) = cofxd(3, sps) + ovrnts*funcvaluesd(&
950  cofxd(2, sps) = cofxd(2, sps) + ovrnts*funcvaluesd(&
952  cofxd(1, sps) = cofxd(1, sps) + ovrnts*funcvaluesd(&
954  call popcontrol1b(branch)
955  if (branch .eq. 0) then
956  forced(3, sps) = forced(3, sps) - sum(cofz(:, sps)*cofzd(:, &
957 & sps))/force(3, sps)**2
958  cofzd(:, sps) = cofzd(:, sps)/force(3, sps)
959  else
960  cofzd(:, sps) = 0.0_8
961  end if
962  call popcontrol1b(branch)
963  if (branch .eq. 0) then
964  forced(2, sps) = forced(2, sps) - sum(cofy(:, sps)*cofyd(:, &
965 & sps))/force(2, sps)**2
966  cofyd(:, sps) = cofyd(:, sps)/force(2, sps)
967  else
968  cofyd(:, sps) = 0.0_8
969  end if
970  call popcontrol1b(branch)
971  if (branch .eq. 0) then
972  forced(1, sps) = forced(1, sps) - sum(cofx(:, sps)*cofxd(:, &
973 & sps))/force(1, sps)**2
974  cofxd(:, sps) = cofxd(:, sps)/force(1, sps)
975  else
976  cofxd(:, sps) = 0.0_8
977  end if
978  cforcemd(3, sps) = cforcemd(3, sps) + ovrnts*funcvaluesd(&
980  cforcemd(2, sps) = cforcemd(2, sps) + ovrnts*funcvaluesd(&
982  cforcemd(1, sps) = cforcemd(1, sps) + ovrnts*funcvaluesd(&
984  cforcevd(3, sps) = cforcevd(3, sps) + ovrnts*funcvaluesd(&
986  cforcevd(2, sps) = cforcevd(2, sps) + ovrnts*funcvaluesd(&
988  cforcevd(1, sps) = cforcevd(1, sps) + ovrnts*funcvaluesd(&
990  cforcepd(3, sps) = cforcepd(3, sps) + ovrnts*funcvaluesd(&
992  cforcepd(2, sps) = cforcepd(2, sps) + ovrnts*funcvaluesd(&
994  cforcepd(1, sps) = cforcepd(1, sps) + ovrnts*funcvaluesd(&
996  cforced(3, sps) = cforced(3, sps) + ovrnts*funcvaluesd(&
998  cforced(2, sps) = cforced(2, sps) + ovrnts*funcvaluesd(&
1000  cforced(1, sps) = cforced(1, sps) + ovrnts*funcvaluesd(&
1002  forcemd(3, sps) = forcemd(3, sps) + ovrnts*funcvaluesd(&
1004  forcemd(2, sps) = forcemd(2, sps) + ovrnts*funcvaluesd(&
1006  forcemd(1, sps) = forcemd(1, sps) + ovrnts*funcvaluesd(&
1008  forcevd(3, sps) = forcevd(3, sps) + ovrnts*funcvaluesd(&
1010  forcevd(2, sps) = forcevd(2, sps) + ovrnts*funcvaluesd(&
1012  forcevd(1, sps) = forcevd(1, sps) + ovrnts*funcvaluesd(&
1014  forcepd(3, sps) = forcepd(3, sps) + ovrnts*funcvaluesd(&
1016  forcepd(2, sps) = forcepd(2, sps) + ovrnts*funcvaluesd(&
1018  forcepd(1, sps) = forcepd(1, sps) + ovrnts*funcvaluesd(&
1020  forced(3, sps) = forced(3, sps) + ovrnts*funcvaluesd(&
1021 & costfuncforcez)
1022  forced(2, sps) = forced(2, sps) + ovrnts*funcvaluesd(&
1023 & costfuncforcey)
1024  forced(1, sps) = forced(1, sps) + ovrnts*funcvaluesd(&
1025 & costfuncforcex)
1026  end do
1027  factd = sum(moment*cmomentd)
1028  momentd = momentd + fact*cmomentd
1029  call popreal8(fact)
1030  factd = factd/(lengthref*lref) + sum(forcem*cforcemd) + sum(forcev&
1031 & *cforcevd) + sum(forcep*cforcepd) + sum(force*cforced)
1032  forcemd = forcemd + fact*cforcemd
1033  forcevd = forcevd + fact*cforcevd
1034  forcepd = forcepd + fact*cforcepd
1035  forced = forced + fact*cforced
1036  temp = gammainf*surfaceref*(lref*lref)
1037  temp0 = temp*(machcoef*machcoef)*pref
1038  tempd = -(temp*two*factd/temp0**2)
1039  machcoefd = machcoefd + 2*machcoef*pref*tempd
1040  prefd = prefd + machcoef**2*tempd
1041  globalvalsd(imp:imp+2, :) = globalvalsd(imp:imp+2, :) + momentd
1042  globalvalsd(imv:imv+2, :) = globalvalsd(imv:imv+2, :) + momentd
1043  globalvalsd(iflowmm:iflowmm+2, :) = globalvalsd(iflowmm:iflowmm+2&
1044 & , :) + momentd
1045  globalvalsd(icoforcez:icoforcez+2, :) = globalvalsd(icoforcez:&
1046 & icoforcez+2, :) + cofzd
1047  globalvalsd(icoforcey:icoforcey+2, :) = globalvalsd(icoforcey:&
1048 & icoforcey+2, :) + cofyd
1049  globalvalsd(icoforcex:icoforcex+2, :) = globalvalsd(icoforcex:&
1050 & icoforcex+2, :) + cofxd
1051  globalvalsd(iflowfm:iflowfm+2, :) = globalvalsd(iflowfm:iflowfm+2&
1052 & , :) + forcemd
1053  globalvalsd(ifv:ifv+2, :) = globalvalsd(ifv:ifv+2, :) + forcevd
1054  globalvalsd(ifp:ifp+2, :) = globalvalsd(ifp:ifp+2, :) + forcepd + &
1055 & forced
1056  globalvalsd(ifv:ifv+2, :) = globalvalsd(ifv:ifv+2, :) + forced
1057  globalvalsd(iflowfm:iflowfm+2, :) = globalvalsd(iflowfm:iflowfm+2&
1058 & , :) + forced
1059  funcvaluesd = 0.0_8
1060  end if
1061  end subroutine getcostfunctions_b
1062 
1063  subroutine getcostfunctions(globalvals, funcvalues)
1064  use constants
1066  use flowvarrefstate, only : pref, rhoref, tref, lref, gammainf, &
1067 & pinf, uref, uinf
1073  use inputtsstabderiv, only : tsstability
1074  use utils_b, only : computetsderivatives
1075  use flowutils_b, only : getdirvector
1076  implicit none
1077 ! input/output
1078  real(kind=realtype), dimension(:, :), intent(in) :: globalvals
1079  real(kind=realtype), dimension(:), intent(out) :: funcvalues
1080 ! working
1081  real(kind=realtype) :: fact, factmoment, ovrnts
1082  real(kind=realtype), dimension(3, ntimeintervalsspectral) :: force, &
1083 & forcep, forcev, forcem, moment, cforce, cforcep, cforcev, cforcem, &
1084 & cmoment, cofx, cofy, cofz
1085  real(kind=realtype), dimension(3) :: vcoordref, vfreestreamref
1086  real(kind=realtype) :: mavgptot, mavgttot, mavgrho, mavgps, mflow, &
1087 & mavgmn, mavga, mavgvx, mavgvy, mavgvz, garea, mavgvi, fxlift, fylift&
1088 & , fzlift
1089  real(kind=realtype) :: vdotn, mag, u, v, w, ks_comp
1090  integer(kind=inttype) :: sps
1091  real(kind=realtype), dimension(8) :: dcdq, dcdqdot
1092  real(kind=realtype), dimension(8) :: dcdalpha, dcdalphadot
1093  real(kind=realtype), dimension(8) :: coef0
1094  intrinsic log
1095  intrinsic exp
1096  intrinsic sqrt
1097 ! factor used for time-averaged quantities.
1098  ovrnts = one/ntimeintervalsspectral
1099 ! sum pressure and viscous contributions
1100  force = globalvals(ifp:ifp+2, :) + globalvals(ifv:ifv+2, :) + &
1101 & globalvals(iflowfm:iflowfm+2, :)
1102  forcep = globalvals(ifp:ifp+2, :)
1103  forcev = globalvals(ifv:ifv+2, :)
1104  forcem = globalvals(iflowfm:iflowfm+2, :)
1105  cofx = globalvals(icoforcex:icoforcex+2, :)
1106  cofy = globalvals(icoforcey:icoforcey+2, :)
1107  cofz = globalvals(icoforcez:icoforcez+2, :)
1108  moment = globalvals(imp:imp+2, :) + globalvals(imv:imv+2, :) + &
1109 & globalvals(iflowmm:iflowmm+2, :)
1111  cforce = fact*force
1112  cforcep = fact*forcep
1113  cforcev = fact*forcev
1114  cforcem = fact*forcem
1115 ! moment factor has an extra lengthref
1116  fact = fact/(lengthref*lref)
1117  cmoment = fact*moment
1118 ! zero values since we are summing.
1119  funcvalues = zero
1120 !$ad ii-loop
1121 ! here we finally assign the final function values
1122  do sps=1,ntimeintervalsspectral
1123  funcvalues(costfuncforcex) = funcvalues(costfuncforcex) + ovrnts*&
1124 & force(1, sps)
1125  funcvalues(costfuncforcey) = funcvalues(costfuncforcey) + ovrnts*&
1126 & force(2, sps)
1127  funcvalues(costfuncforcez) = funcvalues(costfuncforcez) + ovrnts*&
1128 & force(3, sps)
1129  funcvalues(costfuncforcexpressure) = funcvalues(&
1130 & costfuncforcexpressure) + ovrnts*forcep(1, sps)
1131  funcvalues(costfuncforceypressure) = funcvalues(&
1132 & costfuncforceypressure) + ovrnts*forcep(2, sps)
1133  funcvalues(costfuncforcezpressure) = funcvalues(&
1134 & costfuncforcezpressure) + ovrnts*forcep(3, sps)
1135  funcvalues(costfuncforcexviscous) = funcvalues(&
1136 & costfuncforcexviscous) + ovrnts*forcev(1, sps)
1137  funcvalues(costfuncforceyviscous) = funcvalues(&
1138 & costfuncforceyviscous) + ovrnts*forcev(2, sps)
1139  funcvalues(costfuncforcezviscous) = funcvalues(&
1140 & costfuncforcezviscous) + ovrnts*forcev(3, sps)
1141  funcvalues(costfuncforcexmomentum) = funcvalues(&
1142 & costfuncforcexmomentum) + ovrnts*forcem(1, sps)
1143  funcvalues(costfuncforceymomentum) = funcvalues(&
1144 & costfuncforceymomentum) + ovrnts*forcem(2, sps)
1145  funcvalues(costfuncforcezmomentum) = funcvalues(&
1146 & costfuncforcezmomentum) + ovrnts*forcem(3, sps)
1147 ! ------------
1148  funcvalues(costfuncforcexcoef) = funcvalues(costfuncforcexcoef) + &
1149 & ovrnts*cforce(1, sps)
1150  funcvalues(costfuncforceycoef) = funcvalues(costfuncforceycoef) + &
1151 & ovrnts*cforce(2, sps)
1152  funcvalues(costfuncforcezcoef) = funcvalues(costfuncforcezcoef) + &
1153 & ovrnts*cforce(3, sps)
1154  funcvalues(costfuncforcexcoefpressure) = funcvalues(&
1155 & costfuncforcexcoefpressure) + ovrnts*cforcep(1, sps)
1156  funcvalues(costfuncforceycoefpressure) = funcvalues(&
1157 & costfuncforceycoefpressure) + ovrnts*cforcep(2, sps)
1158  funcvalues(costfuncforcezcoefpressure) = funcvalues(&
1159 & costfuncforcezcoefpressure) + ovrnts*cforcep(3, sps)
1160  funcvalues(costfuncforcexcoefviscous) = funcvalues(&
1161 & costfuncforcexcoefviscous) + ovrnts*cforcev(1, sps)
1162  funcvalues(costfuncforceycoefviscous) = funcvalues(&
1163 & costfuncforceycoefviscous) + ovrnts*cforcev(2, sps)
1164  funcvalues(costfuncforcezcoefviscous) = funcvalues(&
1165 & costfuncforcezcoefviscous) + ovrnts*cforcev(3, sps)
1166  funcvalues(costfuncforcexcoefmomentum) = funcvalues(&
1167 & costfuncforcexcoefmomentum) + ovrnts*cforcem(1, sps)
1168  funcvalues(costfuncforceycoefmomentum) = funcvalues(&
1169 & costfuncforceycoefmomentum) + ovrnts*cforcem(2, sps)
1170  funcvalues(costfuncforcezcoefmomentum) = funcvalues(&
1171 & costfuncforcezcoefmomentum) + ovrnts*cforcem(3, sps)
1172 ! ------------
1173 ! center of pressure (these are actually center of all forces)
1174 ! protect the divisions against zero, and divide the weighed sum by the force magnitude
1175 ! for this time spectral instance before we add it to the sum
1176  if (force(1, sps) .ne. zero) then
1177  cofx(:, sps) = cofx(:, sps)/force(1, sps)
1178  else
1179  cofx(:, sps) = zero
1180  end if
1181  if (force(2, sps) .ne. zero) then
1182  cofy(:, sps) = cofy(:, sps)/force(2, sps)
1183  else
1184  cofy(:, sps) = zero
1185  end if
1186  if (force(3, sps) .ne. zero) then
1187  cofz(:, sps) = cofz(:, sps)/force(3, sps)
1188  else
1189  cofz(:, sps) = zero
1190  end if
1191 ! fx
1192  funcvalues(costfunccoforcexx) = funcvalues(costfunccoforcexx) + &
1193 & ovrnts*cofx(1, sps)
1194  funcvalues(costfunccoforcexy) = funcvalues(costfunccoforcexy) + &
1195 & ovrnts*cofx(2, sps)
1196  funcvalues(costfunccoforcexz) = funcvalues(costfunccoforcexz) + &
1197 & ovrnts*cofx(3, sps)
1198 ! fy
1199  funcvalues(costfunccoforceyx) = funcvalues(costfunccoforceyx) + &
1200 & ovrnts*cofy(1, sps)
1201  funcvalues(costfunccoforceyy) = funcvalues(costfunccoforceyy) + &
1202 & ovrnts*cofy(2, sps)
1203  funcvalues(costfunccoforceyz) = funcvalues(costfunccoforceyz) + &
1204 & ovrnts*cofy(3, sps)
1205 ! fz
1206  funcvalues(costfunccoforcezx) = funcvalues(costfunccoforcezx) + &
1207 & ovrnts*cofz(1, sps)
1208  funcvalues(costfunccoforcezy) = funcvalues(costfunccoforcezy) + &
1209 & ovrnts*cofz(2, sps)
1210  funcvalues(costfunccoforcezz) = funcvalues(costfunccoforcezz) + &
1211 & ovrnts*cofz(3, sps)
1212 ! ------------
1213  funcvalues(costfuncmomx) = funcvalues(costfuncmomx) + ovrnts*&
1214 & moment(1, sps)
1215  funcvalues(costfuncmomy) = funcvalues(costfuncmomy) + ovrnts*&
1216 & moment(2, sps)
1217  funcvalues(costfuncmomz) = funcvalues(costfuncmomz) + ovrnts*&
1218 & moment(3, sps)
1219  funcvalues(costfuncmomxcoef) = funcvalues(costfuncmomxcoef) + &
1220 & ovrnts*cmoment(1, sps)
1221  funcvalues(costfuncmomycoef) = funcvalues(costfuncmomycoef) + &
1222 & ovrnts*cmoment(2, sps)
1223  funcvalues(costfuncmomzcoef) = funcvalues(costfuncmomzcoef) + &
1224 & ovrnts*cmoment(3, sps)
1225 ! final part of the ks computation
1226  if (computesepsensorks) then
1227 ! only calculate the log part if we are actually computing for separation for ks method.
1228  ks_comp = ovrnts*(sepsenmaxfamily(sps)+log(globalvals(&
1229 & isepsensorks, sps))/sepsenmaxrho)
1230  funcvalues(costfuncsepsensorks) = funcvalues(costfuncsepsensorks&
1231 & ) + ks_comp
1232  funcvalues(costfuncsepsensorksarea) = funcvalues(&
1233 & costfuncsepsensorksarea) + ovrnts*globalvals(isepsensorksarea&
1234 & , sps)*ks_comp*one/(one+exp(2*sepsensorkssharpness*(ks_comp+&
1235 & sepsensorksoffset))) + ovrnts*globalvals(isepsensorarea, sps)
1236  end if
1237  funcvalues(costfuncsepsensor) = funcvalues(costfuncsepsensor) + &
1238 & ovrnts*globalvals(isepsensor, sps)
1239  funcvalues(costfunccavitation) = funcvalues(costfunccavitation) + &
1240 & ovrnts*globalvals(icavitation, sps)
1241 ! final part of the ks computation
1242  if (computecavitation) then
1243 ! only calculate the log part if we are actually computing for cavitation.
1244 ! if we are not computing cavitation, the icpmin in globalvals will be zero,
1245 ! which doesn't play well with log. we just want to return zero here.
1246  funcvalues(costfunccpmin) = funcvalues(costfunccpmin) + ovrnts*(&
1247 & cpmin_family(sps)-log(globalvals(icpmin, sps))/cpmin_rho)
1248  end if
1249  funcvalues(costfuncaxismoment) = funcvalues(costfuncaxismoment) + &
1250 & ovrnts*globalvals(iaxismoment, sps)
1251  funcvalues(costfuncsepsensoravgx) = funcvalues(&
1252 & costfuncsepsensoravgx) + ovrnts*globalvals(isepavg, sps)
1253  funcvalues(costfuncsepsensoravgy) = funcvalues(&
1254 & costfuncsepsensoravgy) + ovrnts*globalvals(isepavg+1, sps)
1255  funcvalues(costfuncsepsensoravgz) = funcvalues(&
1256 & costfuncsepsensoravgz) + ovrnts*globalvals(isepavg+2, sps)
1257  funcvalues(costfuncarea) = funcvalues(costfuncarea) + ovrnts*&
1258 & globalvals(iarea, sps)
1259  funcvalues(costfuncflowpower) = funcvalues(costfuncflowpower) + &
1260 & ovrnts*globalvals(ipower, sps)
1261  funcvalues(costfunccperror2) = funcvalues(costfunccperror2) + &
1262 & ovrnts*globalvals(icperror2, sps)
1263 ! mass flow like objective
1264  mflow = globalvals(imassflow, sps)
1265  if (mflow .ne. zero) then
1266  mavgptot = globalvals(imassptot, sps)/mflow
1267  mavgttot = globalvals(imassttot, sps)/mflow
1268  mavgrho = globalvals(imassrho, sps)/mflow
1269  mavgps = globalvals(imassps, sps)/mflow
1270  mavgmn = globalvals(imassmn, sps)/mflow
1271  mavga = globalvals(imassa, sps)/mflow
1272  mavgvx = globalvals(imassvx, sps)/mflow
1273  mavgvy = globalvals(imassvy, sps)/mflow
1274  mavgvz = globalvals(imassvz, sps)/mflow
1275  mavgvi = globalvals(imassvi, sps)/mflow
1276  mag = sqrt(globalvals(imassnx, sps)**2 + globalvals(imassny, sps&
1277 & )**2 + globalvals(imassnz, sps)**2)
1278  else
1279  mavgptot = zero
1280  mavgttot = zero
1281  mavgrho = zero
1282  mavgps = zero
1283  mavgmn = zero
1284  mavga = zero
1285  mavgvx = zero
1286  mavgvy = zero
1287  mavgvz = zero
1288  mavgvi = zero
1289  end if
1290 ! area averaged objectives
1291  garea = globalvals(iarea, sps)
1292  if (garea .ne. zero) then
1293 ! area averaged pressure
1294  funcvalues(costfuncaavgptot) = funcvalues(costfuncaavgptot) + &
1295 & ovrnts*globalvals(iareaptot, sps)/garea
1296  funcvalues(costfuncaavgps) = funcvalues(costfuncaavgps) + ovrnts&
1297 & *globalvals(iareaps, sps)/garea
1298  end if
1299  funcvalues(costfuncmdot) = funcvalues(costfuncmdot) + ovrnts*mflow
1300  funcvalues(costfuncmavgptot) = funcvalues(costfuncmavgptot) + &
1301 & ovrnts*mavgptot
1302  funcvalues(costfuncmavgttot) = funcvalues(costfuncmavgttot) + &
1303 & ovrnts*mavgttot
1304  funcvalues(costfuncmavgrho) = funcvalues(costfuncmavgrho) + ovrnts&
1305 & *mavgrho
1306  funcvalues(costfuncmavgps) = funcvalues(costfuncmavgps) + ovrnts*&
1307 & mavgps
1308  funcvalues(costfuncmavgmn) = funcvalues(costfuncmavgmn) + ovrnts*&
1309 & mavgmn
1310  funcvalues(costfuncmavga) = funcvalues(costfuncmavga) + ovrnts*&
1311 & mavga
1312  funcvalues(costfuncmavgvx) = funcvalues(costfuncmavgvx) + ovrnts*&
1313 & mavgvx
1314  funcvalues(costfuncmavgvy) = funcvalues(costfuncmavgvy) + ovrnts*&
1315 & mavgvy
1316  funcvalues(costfuncmavgvz) = funcvalues(costfuncmavgvz) + ovrnts*&
1317 & mavgvz
1318  funcvalues(costfuncmavgvi) = funcvalues(costfuncmavgvi) + ovrnts*&
1319 & mavgvi
1320 ! bending moment calc - also broken.
1321 ! call computerootbendingmoment(cforce, cmoment, liftindex, bendingmoment)
1322 ! funcvalues(costfuncbendingcoef) = funcvalues(costfuncbendingcoef) + ovrnts*bendingmoment
1323  end do
1324 ! lift and drag (coefficients): dot product with the lift/drag direction.
1325  funcvalues(costfunclift) = funcvalues(costfuncforcex)*liftdirection(&
1326 & 1) + funcvalues(costfuncforcey)*liftdirection(2) + funcvalues(&
1328  funcvalues(costfuncliftpressure) = funcvalues(costfuncforcexpressure&
1329 & )*liftdirection(1) + funcvalues(costfuncforceypressure)*&
1330 & liftdirection(2) + funcvalues(costfuncforcezpressure)*&
1331 & liftdirection(3)
1332  funcvalues(costfuncliftviscous) = funcvalues(costfuncforcexviscous)*&
1334 & (2) + funcvalues(costfuncforcezviscous)*liftdirection(3)
1335  funcvalues(costfuncliftmomentum) = funcvalues(costfuncforcexmomentum&
1336 & )*liftdirection(1) + funcvalues(costfuncforceymomentum)*&
1337 & liftdirection(2) + funcvalues(costfuncforcezmomentum)*&
1338 & liftdirection(3)
1339 !-----
1340  funcvalues(costfuncdrag) = funcvalues(costfuncforcex)*dragdirection(&
1341 & 1) + funcvalues(costfuncforcey)*dragdirection(2) + funcvalues(&
1343  funcvalues(costfuncdragpressure) = funcvalues(costfuncforcexpressure&
1344 & )*dragdirection(1) + funcvalues(costfuncforceypressure)*&
1345 & dragdirection(2) + funcvalues(costfuncforcezpressure)*&
1346 & dragdirection(3)
1347  funcvalues(costfuncdragviscous) = funcvalues(costfuncforcexviscous)*&
1349 & (2) + funcvalues(costfuncforcezviscous)*dragdirection(3)
1350  funcvalues(costfuncdragmomentum) = funcvalues(costfuncforcexmomentum&
1351 & )*dragdirection(1) + funcvalues(costfuncforceymomentum)*&
1352 & dragdirection(2) + funcvalues(costfuncforcezmomentum)*&
1353 & dragdirection(3)
1354 !-----
1355  funcvalues(costfuncliftcoef) = funcvalues(costfuncforcexcoef)*&
1356 & liftdirection(1) + funcvalues(costfuncforceycoef)*liftdirection(2)&
1357 & + funcvalues(costfuncforcezcoef)*liftdirection(3)
1358  funcvalues(costfuncliftcoefpressure) = funcvalues(&
1359 & costfuncforcexcoefpressure)*liftdirection(1) + funcvalues(&
1360 & costfuncforceycoefpressure)*liftdirection(2) + funcvalues(&
1362  funcvalues(costfuncliftcoefviscous) = funcvalues(&
1363 & costfuncforcexcoefviscous)*liftdirection(1) + funcvalues(&
1364 & costfuncforceycoefviscous)*liftdirection(2) + funcvalues(&
1366  funcvalues(costfuncliftcoefmomentum) = funcvalues(&
1367 & costfuncforcexcoefmomentum)*liftdirection(1) + funcvalues(&
1368 & costfuncforceycoefmomentum)*liftdirection(2) + funcvalues(&
1370 !-----
1371  funcvalues(costfuncdragcoef) = funcvalues(costfuncforcexcoef)*&
1372 & dragdirection(1) + funcvalues(costfuncforceycoef)*dragdirection(2)&
1373 & + funcvalues(costfuncforcezcoef)*dragdirection(3)
1374  funcvalues(costfuncdragcoefpressure) = funcvalues(&
1375 & costfuncforcexcoefpressure)*dragdirection(1) + funcvalues(&
1376 & costfuncforceycoefpressure)*dragdirection(2) + funcvalues(&
1378  funcvalues(costfuncdragcoefviscous) = funcvalues(&
1379 & costfuncforcexcoefviscous)*dragdirection(1) + funcvalues(&
1380 & costfuncforceycoefviscous)*dragdirection(2) + funcvalues(&
1382  funcvalues(costfuncdragcoefmomentum) = funcvalues(&
1383 & costfuncforcexcoefmomentum)*dragdirection(1) + funcvalues(&
1384 & costfuncforceycoefmomentum)*dragdirection(2) + funcvalues(&
1386 ! ----- center of lift
1387 ! dot product the 3 forces with the lift direction separately
1388  fxlift = funcvalues(costfuncforcex)*liftdirection(1)
1389  fylift = funcvalues(costfuncforcey)*liftdirection(2)
1390  fzlift = funcvalues(costfuncforcez)*liftdirection(3)
1391 ! run the weighed average for the 3 components of center of lift
1392 ! protect against division by zero
1393  if (fxlift + fylift + fzlift .ne. zero) then
1394  funcvalues(costfunccofliftx) = (fxlift*funcvalues(&
1395 & costfunccoforcexx)+fylift*funcvalues(costfunccoforceyx)+fzlift*&
1396 & funcvalues(costfunccoforcezx))/(fxlift+fylift+fzlift)
1397  funcvalues(costfunccoflifty) = (fxlift*funcvalues(&
1398 & costfunccoforcexy)+fylift*funcvalues(costfunccoforceyy)+fzlift*&
1399 & funcvalues(costfunccoforcezy))/(fxlift+fylift+fzlift)
1400  funcvalues(costfunccofliftz) = (fxlift*funcvalues(&
1401 & costfunccoforcexz)+fylift*funcvalues(costfunccoforceyz)+fzlift*&
1402 & funcvalues(costfunccoforcezz))/(fxlift+fylift+fzlift)
1403  else
1404  funcvalues(costfunccofliftx) = zero
1405  funcvalues(costfunccoflifty) = zero
1406  funcvalues(costfunccofliftz) = zero
1407  end if
1408 ! -------------------- time spectral objectives ------------------
1409  if (tsstability) then
1410  print*, &
1411 & 'error: tsstabilityderivatives are *broken*. they need to be ', &
1412 & 'completely verifed from scratch'
1413  stop
1414  end if
1415  end subroutine getcostfunctions
1416 
1417 ! differentiation of wallintegrationface in reverse (adjoint) mode (with options noisize i4 dr8 r8):
1418 ! gradient of useful results: pinf pref *xx *pp1 *pp2 *ssi
1419 ! *ww2 veldirfreestream machcoef pointref *(*viscsubface.tau)
1420 ! *(*bcdata.fv) *(*bcdata.fp) *(*bcdata.area) localvalues
1421 ! with respect to varying inputs: pinf pref *xx *pp1 *pp2 *ssi
1422 ! *ww2 veldirfreestream machcoef pointref *(*viscsubface.tau)
1423 ! *(*bcdata.fv) *(*bcdata.fp) *(*bcdata.area) localvalues
1424 ! rw status of diff variables: pinf:incr pref:incr *xx:incr *pp1:incr
1425 ! *pp2:incr *ssi:incr *ww2:incr veldirfreestream:incr
1426 ! machcoef:incr pointref:incr *(*viscsubface.tau):incr
1427 ! *(*bcdata.fv):in-out *(*bcdata.fp):in-out *(*bcdata.area):in-out
1428 ! localvalues:in-out
1429 ! plus diff mem management of: xx:in pp1:in pp2:in ssi:in ww2:in
1430 ! viscsubface:in *viscsubface.tau:in bcdata:in *bcdata.fv:in
1431 ! *bcdata.fp:in *bcdata.area:in
1432  subroutine wallintegrationface_b(localvalues, localvaluesd, mm)
1433 !
1434 ! wallintegrations computes the contribution of the block
1435 ! given by the pointers in blockpointers to the force and
1436 ! moment of the geometry. a distinction is made
1437 ! between the inviscid and viscous parts. in case the maximum
1438 ! yplus value must be monitored (only possible for rans), this
1439 ! value is also computed. the separation sensor and the cavita-
1440 ! tion sensor is also computed
1441 ! here.
1442 !
1443  use constants
1444  use communication
1445  use blockpointers
1446  use flowvarrefstate
1447  use inputcostfunctions
1451 & sepsenmaxrho
1452  use bcpointers_b
1453  implicit none
1454 ! input/output variables
1455  real(kind=realtype), dimension(nlocalvalues), intent(inout) :: &
1456 & localvalues
1457  real(kind=realtype), dimension(nlocalvalues), intent(inout) :: &
1458 & localvaluesd
1459  integer(kind=inttype) :: mm
1460 ! local variables.
1461  real(kind=realtype), dimension(3) :: fp, fv, mp, mv
1462  real(kind=realtype), dimension(3) :: fpd, fvd, mpd, mvd
1463  real(kind=realtype), dimension(3) :: cofsumfx, cofsumfy, cofsumfz
1464  real(kind=realtype), dimension(3) :: cofsumfxd, cofsumfyd, cofsumfzd
1465  real(kind=realtype) :: yplusmax, sepsensorks, sepsensor, &
1466 & sepsensoravg(3), sepsensorarea, cavitation, cpmin_ks_sum, &
1467 & sepsensorksarea
1468  real(kind=realtype) :: sepsensorksd, sepsensord, sepsensoravgd(3), &
1469 & sepsensoraread, cavitationd, cpmin_ks_sumd, sepsensorksaread
1470  integer(kind=inttype) :: i, j, ii, blk
1471  real(kind=realtype) :: pm1, fx, fy, fz, fn
1472  real(kind=realtype) :: pm1d, fxd, fyd, fzd
1473  real(kind=realtype) :: vecttangential(3)
1474  real(kind=realtype) :: vecttangentiald(3)
1475  real(kind=realtype) :: vectdotproductfsnormal
1476  real(kind=realtype) :: vectdotproductfsnormald
1477  real(kind=realtype) :: xc, xco, yc, yco, zc, zco, qf(3), r(3), n(3)&
1478 & , l
1479  real(kind=realtype) :: xcd, xcod, ycd, ycod, zcd, zcod, rd(3)
1480  real(kind=realtype) :: fact, rho, mul, yplus, dwall
1481  real(kind=realtype) :: v(3), sensor, sensor1, cp, tmp, plocal, &
1482 & ks_exponent
1483  real(kind=realtype) :: vd(3), sensord, sensor1d, cpd, tmpd, plocald&
1484 & , ks_exponentd
1485  real(kind=realtype) :: tauxx, tauyy, tauzz
1486  real(kind=realtype) :: tauxxd, tauyyd, tauzzd
1487  real(kind=realtype) :: tauxy, tauxz, tauyz
1488  real(kind=realtype) :: tauxyd, tauxzd, tauyzd
1489  real(kind=realtype), dimension(3) :: refpoint
1490  real(kind=realtype), dimension(3) :: refpointd
1491  real(kind=realtype), dimension(3, 2) :: axispoints
1492  real(kind=realtype) :: mx, my, mz, cellarea, m0x, m0y, m0z, mvaxis, &
1493 & mpaxis
1494  real(kind=realtype) :: mxd, myd, mzd, cellaread, m0xd, m0yd, m0zd, &
1495 & mvaxisd, mpaxisd
1496  real(kind=realtype) :: cperror, cperror2
1497  real(kind=realtype) :: cperrord, cperror2d
1498  intrinsic mod
1499  intrinsic max
1500  intrinsic sqrt
1501  intrinsic cos
1502  intrinsic exp
1503  real(kind=realtype) :: temp
1504  real(kind=realtype) :: tempd
1505  real(kind=realtype), dimension(3) :: tmp0
1506  real(kind=realtype), dimension(3) :: tmpd0
1507  real(kind=realtype) :: temp0
1508  real(kind=realtype), dimension(3) :: tmp1
1509  real(kind=realtype), dimension(3) :: tmpd1
1510  real(kind=realtype) :: tempd0
1511  real(kind=realtype) :: temp1
1512  real(kind=realtype) :: tempd1
1513  integer :: branch
1514  select case (bcfaceid(mm))
1515  case (imin, jmin, kmin)
1516  fact = -one
1517  case (imax, jmax, kmax)
1518  fact = one
1519  end select
1520 ! determine the reference point for the moment computation in
1521 ! meters.
1522  refpoint(1) = lref*pointref(1)
1523  refpoint(2) = lref*pointref(2)
1524  refpoint(3) = lref*pointref(3)
1525 ! determine the points defining the axis about which to compute a moment
1526  axispoints(1, 1) = lref*momentaxis(1, 1)
1527  axispoints(1, 2) = lref*momentaxis(1, 2)
1528  axispoints(2, 1) = lref*momentaxis(2, 1)
1529  axispoints(2, 2) = lref*momentaxis(2, 2)
1530  axispoints(3, 1) = lref*momentaxis(3, 1)
1531  axispoints(3, 2) = lref*momentaxis(3, 2)
1532 ! initialize the force and moment coefficients to 0 as well as
1533 ! yplusmax.
1534  call pushreal8array(n, 3)
1535  call pushreal8array(r, 3)
1536  call pushreal8array(v, 3)
1537  call pushreal8array(vecttangential, 3)
1538 !$fwd-of ii-loop
1539 !
1540 ! integrate the inviscid contribution over the solid walls,
1541 ! either inviscid or viscous. the integration is done with
1542 ! cp. for closed contours this is equal to the integration
1543 ! of p; for open contours this is not the case anymore.
1544 ! question is whether a force for an open contour is
1545 ! meaningful anyway.
1546 !
1547 ! loop over the quadrilateral faces of the subface. note that
1548 ! the nodal range of bcdata must be used and not the cell
1549 ! range, because the latter may include the halo's in i and
1550 ! j-direction. the offset +1 is there, because inbeg and jnbeg
1551 ! refer to nodal ranges and not to cell ranges. the loop
1552 ! (without the ad stuff) would look like:
1553 !
1554 ! do j=(bcdata(mm)%jnbeg+1),bcdata(mm)%jnend
1555 ! do i=(bcdata(mm)%inbeg+1),bcdata(mm)%inend
1556  do ii=0,(bcdata(mm)%jnend-bcdata(mm)%jnbeg)*(bcdata(mm)%inend-bcdata&
1557 & (mm)%inbeg)-1
1558  i = mod(ii, bcdata(mm)%inend - bcdata(mm)%inbeg) + bcdata(mm)%&
1559 & inbeg + 1
1560  j = ii/(bcdata(mm)%inend-bcdata(mm)%inbeg) + bcdata(mm)%jnbeg + 1
1561 ! compute the average pressure minus 1 and the coordinates
1562 ! of the centroid of the face relative from from the
1563 ! moment reference point. due to the usage of pointers for
1564 ! the coordinates, whose original array starts at 0, an
1565 ! offset of 1 must be used. the pressure is multipled by
1566 ! fact to account for the possibility of an inward or
1567 ! outward pointing normal.
1568  pm1 = fact*(half*(pp2(i, j)+pp1(i, j))-pinf)*pref
1570  cp = (half*(pp2(i, j)+pp1(i, j))-pinf)*tmp
1571  cperror = cp - bcdata(mm)%cptarget(i, j)
1572  cperror2 = cperror2 + cperror*cperror
1573  xc = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1, &
1574 & 1)) - refpoint(1)
1575  yc = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1, &
1576 & 2)) - refpoint(2)
1577  zc = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1, &
1578 & 3)) - refpoint(3)
1579  if (bcdata(mm)%iblank(i, j) .lt. 0) then
1580  blk = 0
1581  else
1582  blk = bcdata(mm)%iblank(i, j)
1583  end if
1584  fx = pm1*ssi(i, j, 1)
1585  fy = pm1*ssi(i, j, 2)
1586  fz = pm1*ssi(i, j, 3)
1587 ! note from ay: technically, we can just compute the moments using the center of force
1588 ! terms. however, the moment computations coded here distinguish pressure,
1589 ! viscous, and momentum contributions to moment. even though these individual
1590 ! contributions are not exposed to python, i still wanted to keep how it's done in the
1591 ! code in case its useful in the future. this is also true for the face integrations
1592 ! update the inviscid force and moment coefficients. iblank as we sum
1593  fp(1) = fp(1) + fx*blk
1594  fp(2) = fp(2) + fy*blk
1595  fp(3) = fp(3) + fz*blk
1596  mx = yc*fz - zc*fy
1597  my = zc*fx - xc*fz
1598  mz = xc*fy - yc*fx
1599  mp(1) = mp(1) + mx*blk
1600  mp(2) = mp(2) + my*blk
1601  mp(3) = mp(3) + mz*blk
1602 ! the force integral for the center of pressure computation.
1603 ! we need the cell centers wrt origin
1604  xco = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
1605 & , 1))
1606  yco = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
1607 & , 2))
1608  zco = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
1609 & , 3))
1610 ! accumulate in the sums. each force component is tracked separately
1611 ! force-x
1612  cofsumfx(1) = cofsumfx(1) + xco*fx*blk
1613  cofsumfx(2) = cofsumfx(2) + yco*fx*blk
1614  cofsumfx(3) = cofsumfx(3) + zco*fx*blk
1615 ! force-y
1616  cofsumfy(1) = cofsumfy(1) + xco*fy*blk
1617  cofsumfy(2) = cofsumfy(2) + yco*fy*blk
1618  cofsumfy(3) = cofsumfy(3) + zco*fy*blk
1619 ! force-z
1620  cofsumfz(1) = cofsumfz(1) + xco*fz*blk
1621  cofsumfz(2) = cofsumfz(2) + yco*fz*blk
1622  cofsumfz(3) = cofsumfz(3) + zco*fz*blk
1623 ! compute the r and n vectores for the moment around an
1624 ! axis computation where r is the distance from the
1625 ! force to the first point on the axis and n is a unit
1626 ! normal in the direction of the axis
1627  r(1) = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
1628 & , 1)) - axispoints(1, 1)
1629  r(2) = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
1630 & , 2)) - axispoints(2, 1)
1631  r(3) = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
1632 & , 3)) - axispoints(3, 1)
1633  l = sqrt((axispoints(1, 2)-axispoints(1, 1))**2 + (axispoints(2, 2&
1634 & )-axispoints(2, 1))**2 + (axispoints(3, 2)-axispoints(3, 1))**2)
1635  n(1) = (axispoints(1, 2)-axispoints(1, 1))/l
1636  n(2) = (axispoints(2, 2)-axispoints(2, 1))/l
1637  n(3) = (axispoints(3, 2)-axispoints(3, 1))/l
1638 ! compute the moment of the force about the first point
1639 ! used to define the axis, and the project that axis in
1640 ! the n direction
1641  m0x = r(2)*fz - r(3)*fy
1642  m0y = r(3)*fx - r(1)*fz
1643  m0z = r(1)*fy - r(2)*fx
1644  mpaxis = mpaxis + (m0x*n(1)+m0y*n(2)+m0z*n(3))*blk
1645 ! save the face-based forces and area
1646  bcdata(mm)%fp(i, j, 1) = fx
1647  bcdata(mm)%fp(i, j, 2) = fy
1648  bcdata(mm)%fp(i, j, 3) = fz
1649  cellarea = sqrt(ssi(i, j, 1)**2 + ssi(i, j, 2)**2 + ssi(i, j, 3)**&
1650 & 2)
1651  bcdata(mm)%area(i, j) = cellarea
1652 ! get normalized surface velocity:
1653  v(1) = ww2(i, j, ivx)
1654  v(2) = ww2(i, j, ivy)
1655  v(3) = ww2(i, j, ivz)
1656  v = v/(sqrt(v(1)**2+v(2)**2+v(3)**2)+1e-16)
1657  if (computesepsensorks) then
1658 ! freestream projection over the surface.
1659  vectdotproductfsnormal = veldirfreestream(1)*bcdata(mm)%norm(i, &
1660 & j, 1) + veldirfreestream(2)*bcdata(mm)%norm(i, j, 2) + &
1661 & veldirfreestream(3)*bcdata(mm)%norm(i, j, 3)
1662 ! tangential vector on the surface, which is the freestream projected vector
1663  vecttangential(1) = veldirfreestream(1) - vectdotproductfsnormal&
1664 & *bcdata(mm)%norm(i, j, 1)
1665  vecttangential(2) = veldirfreestream(2) - vectdotproductfsnormal&
1666 & *bcdata(mm)%norm(i, j, 2)
1667  vecttangential(3) = veldirfreestream(3) - vectdotproductfsnormal&
1668 & *bcdata(mm)%norm(i, j, 3)
1669  vecttangential = vecttangential/(sqrt(vecttangential(1)**2+&
1670 & vecttangential(2)**2+vecttangential(3)**2)+1e-16)
1671 ! computing separation sensor
1672 ! velocity dot products
1673  sensor = v(1)*vecttangential(1) + v(2)*vecttangential(2) + v(3)*&
1674 & vecttangential(3)
1675 ! sepsensor value
1676  sensor = (cos(degtorad*sepsensorksphi)-sensor)/(-cos(degtorad*&
1677 & sepsensorksphi)+cos(zero)+1e-16)
1678 ! also do the ks-based spensenor max computation
1680 & , sepsenmaxrho, ks_exponent)
1681  sepsensorksarea = sepsensorksarea + blk*cellarea
1682  sepsensorarea = cellarea*blk*one/(one+exp(-(2*&
1683 & sepsensorkssharpness*(sensor+sepsensorksoffset)))) + &
1684 & sepsensorarea
1685  sepsensorks = sepsensorks + ks_exponent*blk
1686  end if
1687 ! dot product with free stream
1688  sensor = -(v(1)*veldirfreestream(1)+v(2)*veldirfreestream(2)+v(3)*&
1689 & veldirfreestream(3))
1690 !now run through a smooth heaviside function:
1691  sensor = one/(one+exp(-(2*sepsensorsharpness*(sensor-&
1692 & sepsensoroffset))))
1693 ! and integrate over the area of this cell and save, blanking as we go.
1694  sensor = sensor*cellarea*blk
1695  sepsensor = sepsensor + sensor
1696 ! also accumulate into the sepsensoravg
1697 ! x-y-zco are computed above for center of force computations
1698  sepsensoravg(1) = sepsensoravg(1) + sensor*xco
1699  sepsensoravg(2) = sepsensoravg(2) + sensor*yco
1700  sepsensoravg(3) = sepsensoravg(3) + sensor*zco
1701  if (computecavitation) then
1702  plocal = pp2(i, j)
1703  tmp = two/(gammainf*machcoef*machcoef)
1704  cp = tmp*(plocal-pinf)
1705  sensor1 = -cp - cavitationnumber
1706  sensor1 = sensor1**cavexponent/(one+exp(2*cavsensorsharpness*(-&
1707 & sensor1+cavsensoroffset)))
1708  sensor1 = sensor1*cellarea*blk
1709  cavitation = cavitation + sensor1
1710 ! also do the ks-based cpmin computation
1711  ks_exponent = exp(cpmin_rho*(-cp+cpmin_family(spectralsol)))
1712  cpmin_ks_sum = cpmin_ks_sum + ks_exponent*blk
1713  end if
1714  end do
1715 !
1716 ! integration of the viscous forces.
1717 ! only for viscous boundaries.
1718 !
1719  if (bctype(mm) .eq. nswalladiabatic .or. bctype(mm) .eq. &
1720 & nswallisothermal) then
1721  call pushcontrol1b(0)
1722  else
1723  call pushcontrol1b(1)
1724  end if
1725  cperror2d = localvaluesd(icperror2)
1726  mpaxisd = localvaluesd(iaxismoment)
1727  mvaxisd = localvaluesd(iaxismoment)
1728  sepsensoravgd = 0.0_8
1729  sepsensoravgd = localvaluesd(isepavg:isepavg+2)
1730  cpmin_ks_sumd = localvaluesd(icpmin)
1731  cavitationd = localvaluesd(icavitation)
1732  sepsensoraread = localvaluesd(isepsensorarea)
1733  sepsensorksaread = localvaluesd(isepsensorksarea)
1734  sepsensorksd = localvaluesd(isepsensorks)
1735  sepsensord = localvaluesd(isepsensor)
1736  cofsumfzd = 0.0_8
1737  cofsumfzd = localvaluesd(icoforcez:icoforcez+2)
1738  cofsumfyd = 0.0_8
1739  cofsumfyd = localvaluesd(icoforcey:icoforcey+2)
1740  cofsumfxd = 0.0_8
1741  cofsumfxd = localvaluesd(icoforcex:icoforcex+2)
1742  mvd = 0.0_8
1743  mvd = localvaluesd(imv:imv+2)
1744  mpd = 0.0_8
1745  mpd = localvaluesd(imp:imp+2)
1746  fvd = 0.0_8
1747  fvd = localvaluesd(ifv:ifv+2)
1748  fpd = 0.0_8
1749  fpd = localvaluesd(ifp:ifp+2)
1750  call popcontrol1b(branch)
1751  if (branch .eq. 0) then
1752  rd = 0.0_8
1753  refpointd = 0.0_8
1754 !$bwd-of ii-loop
1755  do ii=0,(bcdata(mm)%jnend-bcdata(mm)%jnbeg)*(bcdata(mm)%inend-&
1756 & bcdata(mm)%inbeg)-1
1757  i = mod(ii, bcdata(mm)%inend - bcdata(mm)%inbeg) + bcdata(mm)%&
1758 & inbeg + 1
1759  j = ii/(bcdata(mm)%inend-bcdata(mm)%inbeg) + bcdata(mm)%jnbeg + &
1760 & 1
1761  if (bcdata(mm)%iblank(i, j) .lt. 0) then
1762  blk = 0
1763  else
1764  blk = bcdata(mm)%iblank(i, j)
1765  end if
1766  tauxx = viscsubface(mm)%tau(i, j, 1)
1767  tauyy = viscsubface(mm)%tau(i, j, 2)
1768  tauzz = viscsubface(mm)%tau(i, j, 3)
1769  tauxy = viscsubface(mm)%tau(i, j, 4)
1770  tauxz = viscsubface(mm)%tau(i, j, 5)
1771  tauyz = viscsubface(mm)%tau(i, j, 6)
1772 ! compute the viscous force on the face. a minus sign
1773 ! is now present, due to the definition of this force.
1774  fx = -(fact*(tauxx*ssi(i, j, 1)+tauxy*ssi(i, j, 2)+tauxz*ssi(i, &
1775 & j, 3))*pref)
1776  fy = -(fact*(tauxy*ssi(i, j, 1)+tauyy*ssi(i, j, 2)+tauyz*ssi(i, &
1777 & j, 3))*pref)
1778  fz = -(fact*(tauxz*ssi(i, j, 1)+tauyz*ssi(i, j, 2)+tauzz*ssi(i, &
1779 & j, 3))*pref)
1780 ! compute the coordinates of the centroid of the face
1781 ! relative from the moment reference point. due to the
1782 ! usage of pointers for xx and offset of 1 is present,
1783 ! because x originally starts at 0.
1784  xc = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
1785 & , 1)) - refpoint(1)
1786  yc = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
1787 & , 2)) - refpoint(2)
1788  zc = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
1789 & , 3)) - refpoint(3)
1790 ! update the viscous force and moment coefficients, blanking as we go.
1791 ! the force integral for the center of pressure computation.
1792 ! we need the cell centers wrt origin
1793  xco = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+&
1794 & 1, 1))
1795  yco = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+&
1796 & 1, 2))
1797  zco = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+&
1798 & 1, 3))
1799 ! accumulate in the sums. each force component is tracked separately
1800 ! force-x
1801 ! force-y
1802 ! force-z
1803 ! compute the r and n vectors for the moment around an
1804 ! axis computation where r is the distance from the
1805 ! force to the first point on the axis and n is a unit
1806 ! normal in the direction of the axis
1807  r(1) = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j&
1808 & +1, 1)) - axispoints(1, 1)
1809  r(2) = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j&
1810 & +1, 2)) - axispoints(2, 1)
1811  r(3) = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j&
1812 & +1, 3)) - axispoints(3, 1)
1813  l = sqrt((axispoints(1, 2)-axispoints(1, 1))**2 + (axispoints(2&
1814 & , 2)-axispoints(2, 1))**2 + (axispoints(3, 2)-axispoints(3, 1)&
1815 & )**2)
1816  n(1) = (axispoints(1, 2)-axispoints(1, 1))/l
1817  n(2) = (axispoints(2, 2)-axispoints(2, 1))/l
1818  n(3) = (axispoints(3, 2)-axispoints(3, 1))/l
1819 ! compute the moment of the force about the first point
1820 ! used to define the axis, and then project that axis in
1821 ! the n direction
1822 ! save the face based forces for the slice operations
1823 ! compute the tangential component of the stress tensor,
1824 ! which is needed to monitor y+. the result is stored
1825 ! in fx, fy, fz, although it is not really a force.
1826 ! as later on only the magnitude of the tangential
1827 ! component is important, there is no need to take the
1828 ! sign into account (it should be a minus sign).
1829 ! compute the local value of y+. due to the usage
1830 ! of pointers there is on offset of -1 in dd2wall..
1831  mxd = blk*mvd(1)
1832  myd = blk*mvd(2)
1833  mzd = blk*mvd(3)
1834  tempd1 = blk*mvaxisd
1835  m0xd = n(1)*tempd1
1836  m0yd = n(2)*tempd1
1837  m0zd = n(3)*tempd1
1838  fzd = bcdatad(mm)%fv(i, j, 3) + r(2)*m0xd - r(1)*m0yd + zco*blk*&
1839 & cofsumfzd(3) + yco*blk*cofsumfzd(2) + xco*blk*cofsumfzd(1) + &
1840 & yc*mxd - xc*myd + blk*fvd(3)
1841  bcdatad(mm)%fv(i, j, 3) = 0.0_8
1842  fyd = bcdatad(mm)%fv(i, j, 2) + r(1)*m0zd + zco*blk*cofsumfyd(3)&
1843 & - r(3)*m0xd + yco*blk*cofsumfyd(2) + xco*blk*cofsumfyd(1) + xc&
1844 & *mzd + blk*fvd(2) - zc*mxd
1845  bcdatad(mm)%fv(i, j, 2) = 0.0_8
1846  fxd = bcdatad(mm)%fv(i, j, 1) + r(3)*m0yd - r(2)*m0zd + zco*blk*&
1847 & cofsumfxd(3) + yco*blk*cofsumfxd(2) + xco*blk*cofsumfxd(1) + &
1848 & zc*myd - yc*mzd + blk*fvd(1)
1849  bcdatad(mm)%fv(i, j, 1) = 0.0_8
1850  rd(1) = rd(1) + fy*m0zd - fz*m0yd
1851  rd(2) = rd(2) + fz*m0xd - fx*m0zd
1852  rd(3) = rd(3) + fx*m0yd - fy*m0xd
1853  tempd1 = fourth*rd(3)
1854  rd(3) = 0.0_8
1855  xxd(i, j, 3) = xxd(i, j, 3) + tempd1
1856  xxd(i+1, j, 3) = xxd(i+1, j, 3) + tempd1
1857  xxd(i, j+1, 3) = xxd(i, j+1, 3) + tempd1
1858  xxd(i+1, j+1, 3) = xxd(i+1, j+1, 3) + tempd1
1859  tempd1 = fourth*rd(2)
1860  rd(2) = 0.0_8
1861  xxd(i, j, 2) = xxd(i, j, 2) + tempd1
1862  xxd(i+1, j, 2) = xxd(i+1, j, 2) + tempd1
1863  xxd(i, j+1, 2) = xxd(i, j+1, 2) + tempd1
1864  xxd(i+1, j+1, 2) = xxd(i+1, j+1, 2) + tempd1
1865  tempd1 = fourth*rd(1)
1866  rd(1) = 0.0_8
1867  xxd(i, j, 1) = xxd(i, j, 1) + tempd1
1868  xxd(i+1, j, 1) = xxd(i+1, j, 1) + tempd1
1869  xxd(i, j+1, 1) = xxd(i, j+1, 1) + tempd1
1870  xxd(i+1, j+1, 1) = xxd(i+1, j+1, 1) + tempd1
1871  zcod = fz*blk*cofsumfzd(3) + fy*blk*cofsumfyd(3) + fx*blk*&
1872 & cofsumfxd(3)
1873  ycod = fz*blk*cofsumfzd(2) + fy*blk*cofsumfyd(2) + fx*blk*&
1874 & cofsumfxd(2)
1875  xcod = fz*blk*cofsumfzd(1) + fy*blk*cofsumfyd(1) + fx*blk*&
1876 & cofsumfxd(1)
1877  tempd1 = fourth*zcod
1878  xxd(i, j, 3) = xxd(i, j, 3) + tempd1
1879  xxd(i+1, j, 3) = xxd(i+1, j, 3) + tempd1
1880  xxd(i, j+1, 3) = xxd(i, j+1, 3) + tempd1
1881  xxd(i+1, j+1, 3) = xxd(i+1, j+1, 3) + tempd1
1882  tempd1 = fourth*ycod
1883  xxd(i, j, 2) = xxd(i, j, 2) + tempd1
1884  xxd(i+1, j, 2) = xxd(i+1, j, 2) + tempd1
1885  xxd(i, j+1, 2) = xxd(i, j+1, 2) + tempd1
1886  xxd(i+1, j+1, 2) = xxd(i+1, j+1, 2) + tempd1
1887  tempd1 = fourth*xcod
1888  xxd(i, j, 1) = xxd(i, j, 1) + tempd1
1889  xxd(i+1, j, 1) = xxd(i+1, j, 1) + tempd1
1890  xxd(i, j+1, 1) = xxd(i, j+1, 1) + tempd1
1891  xxd(i+1, j+1, 1) = xxd(i+1, j+1, 1) + tempd1
1892  xcd = fy*mzd - fz*myd
1893  ycd = fz*mxd - fx*mzd
1894  zcd = fx*myd - fy*mxd
1895  tempd1 = fourth*zcd
1896  refpointd(3) = refpointd(3) - zcd
1897  xxd(i, j, 3) = xxd(i, j, 3) + tempd1
1898  xxd(i+1, j, 3) = xxd(i+1, j, 3) + tempd1
1899  xxd(i, j+1, 3) = xxd(i, j+1, 3) + tempd1
1900  xxd(i+1, j+1, 3) = xxd(i+1, j+1, 3) + tempd1
1901  tempd1 = fourth*ycd
1902  refpointd(2) = refpointd(2) - ycd
1903  xxd(i, j, 2) = xxd(i, j, 2) + tempd1
1904  xxd(i+1, j, 2) = xxd(i+1, j, 2) + tempd1
1905  xxd(i, j+1, 2) = xxd(i, j+1, 2) + tempd1
1906  xxd(i+1, j+1, 2) = xxd(i+1, j+1, 2) + tempd1
1907  tempd1 = fourth*xcd
1908  refpointd(1) = refpointd(1) - xcd
1909  xxd(i, j, 1) = xxd(i, j, 1) + tempd1
1910  xxd(i+1, j, 1) = xxd(i+1, j, 1) + tempd1
1911  xxd(i, j+1, 1) = xxd(i, j+1, 1) + tempd1
1912  xxd(i+1, j+1, 1) = xxd(i+1, j+1, 1) + tempd1
1913  tempd1 = -(pref*fact*fzd)
1914  prefd = prefd - (tauxz*ssi(i, j, 1)+tauyz*ssi(i, j, 2)+tauzz*ssi&
1915 & (i, j, 3))*fact*fzd - (tauxy*ssi(i, j, 1)+tauyy*ssi(i, j, 2)+&
1916 & tauyz*ssi(i, j, 3))*fact*fyd - (tauxx*ssi(i, j, 1)+tauxy*ssi(i&
1917 & , j, 2)+tauxz*ssi(i, j, 3))*fact*fxd
1918  tauxzd = ssi(i, j, 1)*tempd1
1919  ssid(i, j, 1) = ssid(i, j, 1) + tauxz*tempd1
1920  tauyzd = ssi(i, j, 2)*tempd1
1921  ssid(i, j, 2) = ssid(i, j, 2) + tauyz*tempd1
1922  tauzzd = ssi(i, j, 3)*tempd1
1923  ssid(i, j, 3) = ssid(i, j, 3) + tauzz*tempd1
1924  tempd1 = -(pref*fact*fyd)
1925  tauxyd = ssi(i, j, 1)*tempd1
1926  ssid(i, j, 1) = ssid(i, j, 1) + tauxy*tempd1
1927  tauyyd = ssi(i, j, 2)*tempd1
1928  ssid(i, j, 2) = ssid(i, j, 2) + tauyy*tempd1
1929  tauyzd = tauyzd + ssi(i, j, 3)*tempd1
1930  ssid(i, j, 3) = ssid(i, j, 3) + tauyz*tempd1
1931  tempd1 = -(pref*fact*fxd)
1932  tauxxd = ssi(i, j, 1)*tempd1
1933  ssid(i, j, 1) = ssid(i, j, 1) + tauxx*tempd1
1934  tauxyd = tauxyd + ssi(i, j, 2)*tempd1
1935  ssid(i, j, 2) = ssid(i, j, 2) + tauxy*tempd1
1936  tauxzd = tauxzd + ssi(i, j, 3)*tempd1
1937  ssid(i, j, 3) = ssid(i, j, 3) + tauxz*tempd1
1938  viscsubfaced(mm)%tau(i, j, 6) = viscsubfaced(mm)%tau(i, j, 6) + &
1939 & tauyzd
1940  viscsubfaced(mm)%tau(i, j, 5) = viscsubfaced(mm)%tau(i, j, 5) + &
1941 & tauxzd
1942  viscsubfaced(mm)%tau(i, j, 4) = viscsubfaced(mm)%tau(i, j, 4) + &
1943 & tauxyd
1944  viscsubfaced(mm)%tau(i, j, 3) = viscsubfaced(mm)%tau(i, j, 3) + &
1945 & tauzzd
1946  viscsubfaced(mm)%tau(i, j, 2) = viscsubfaced(mm)%tau(i, j, 2) + &
1947 & tauyyd
1948  viscsubfaced(mm)%tau(i, j, 1) = viscsubfaced(mm)%tau(i, j, 1) + &
1949 & tauxxd
1950  end do
1951  else
1952  bcdatad(mm)%fv = 0.0_8
1953  rd = 0.0_8
1954  refpointd = 0.0_8
1955  end if
1956  vd = 0.0_8
1957  vecttangentiald = 0.0_8
1958  call popreal8array(vecttangential, 3)
1959  call popreal8array(v, 3)
1960  call popreal8array(r, 3)
1961  call popreal8array(n, 3)
1962 !$bwd-of ii-loop
1963  do ii=0,(bcdata(mm)%jnend-bcdata(mm)%jnbeg)*(bcdata(mm)%inend-bcdata&
1964 & (mm)%inbeg)-1
1965  i = mod(ii, bcdata(mm)%inend - bcdata(mm)%inbeg) + bcdata(mm)%&
1966 & inbeg + 1
1967  j = ii/(bcdata(mm)%inend-bcdata(mm)%inbeg) + bcdata(mm)%jnbeg + 1
1968 ! compute the average pressure minus 1 and the coordinates
1969 ! of the centroid of the face relative from from the
1970 ! moment reference point. due to the usage of pointers for
1971 ! the coordinates, whose original array starts at 0, an
1972 ! offset of 1 must be used. the pressure is multipled by
1973 ! fact to account for the possibility of an inward or
1974 ! outward pointing normal.
1975  pm1 = fact*(half*(pp2(i, j)+pp1(i, j))-pinf)*pref
1977  cp = (half*(pp2(i, j)+pp1(i, j))-pinf)*tmp
1978  cperror = cp - bcdata(mm)%cptarget(i, j)
1979  xc = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1, &
1980 & 1)) - refpoint(1)
1981  yc = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1, &
1982 & 2)) - refpoint(2)
1983  zc = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1, &
1984 & 3)) - refpoint(3)
1985  if (bcdata(mm)%iblank(i, j) .lt. 0) then
1986  blk = 0
1987  else
1988  blk = bcdata(mm)%iblank(i, j)
1989  end if
1990  fx = pm1*ssi(i, j, 1)
1991  fy = pm1*ssi(i, j, 2)
1992  fz = pm1*ssi(i, j, 3)
1993 ! note from ay: technically, we can just compute the moments using the center of force
1994 ! terms. however, the moment computations coded here distinguish pressure,
1995 ! viscous, and momentum contributions to moment. even though these individual
1996 ! contributions are not exposed to python, i still wanted to keep how it's done in the
1997 ! code in case its useful in the future. this is also true for the face integrations
1998 ! update the inviscid force and moment coefficients. iblank as we sum
1999 ! the force integral for the center of pressure computation.
2000 ! we need the cell centers wrt origin
2001  xco = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
2002 & , 1))
2003  yco = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
2004 & , 2))
2005  zco = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
2006 & , 3))
2007 ! accumulate in the sums. each force component is tracked separately
2008 ! force-x
2009 ! force-y
2010 ! force-z
2011 ! compute the r and n vectores for the moment around an
2012 ! axis computation where r is the distance from the
2013 ! force to the first point on the axis and n is a unit
2014 ! normal in the direction of the axis
2015  r(1) = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
2016 & , 1)) - axispoints(1, 1)
2017  r(2) = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
2018 & , 2)) - axispoints(2, 1)
2019  r(3) = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
2020 & , 3)) - axispoints(3, 1)
2021  l = sqrt((axispoints(1, 2)-axispoints(1, 1))**2 + (axispoints(2, 2&
2022 & )-axispoints(2, 1))**2 + (axispoints(3, 2)-axispoints(3, 1))**2)
2023  n(1) = (axispoints(1, 2)-axispoints(1, 1))/l
2024  n(2) = (axispoints(2, 2)-axispoints(2, 1))/l
2025  n(3) = (axispoints(3, 2)-axispoints(3, 1))/l
2026 ! compute the moment of the force about the first point
2027 ! used to define the axis, and the project that axis in
2028 ! the n direction
2029 ! save the face-based forces and area
2030  cellarea = sqrt(ssi(i, j, 1)**2 + ssi(i, j, 2)**2 + ssi(i, j, 3)**&
2031 & 2)
2032 ! get normalized surface velocity:
2033  v(1) = ww2(i, j, ivx)
2034  v(2) = ww2(i, j, ivy)
2035  v(3) = ww2(i, j, ivz)
2036  tmp0 = v/(sqrt(v(1)**2+v(2)**2+v(3)**2)+1e-16)
2037  call pushreal8array(v, 3)
2038  v = tmp0
2039  if (computesepsensorks) then
2040 ! freestream projection over the surface.
2041  vectdotproductfsnormal = veldirfreestream(1)*bcdata(mm)%norm(i, &
2042 & j, 1) + veldirfreestream(2)*bcdata(mm)%norm(i, j, 2) + &
2043 & veldirfreestream(3)*bcdata(mm)%norm(i, j, 3)
2044 ! tangential vector on the surface, which is the freestream projected vector
2045  vecttangential(1) = veldirfreestream(1) - vectdotproductfsnormal&
2046 & *bcdata(mm)%norm(i, j, 1)
2047  vecttangential(2) = veldirfreestream(2) - vectdotproductfsnormal&
2048 & *bcdata(mm)%norm(i, j, 2)
2049  vecttangential(3) = veldirfreestream(3) - vectdotproductfsnormal&
2050 & *bcdata(mm)%norm(i, j, 3)
2051  tmp1 = vecttangential/(sqrt(vecttangential(1)**2+vecttangential(&
2052 & 2)**2+vecttangential(3)**2)+1e-16)
2053  call pushreal8array(vecttangential, 3)
2054  vecttangential = tmp1
2055 ! computing separation sensor
2056 ! velocity dot products
2057  sensor = v(1)*vecttangential(1) + v(2)*vecttangential(2) + v(3)*&
2058 & vecttangential(3)
2059 ! sepsensor value
2060  sensor = (cos(degtorad*sepsensorksphi)-sensor)/(-cos(degtorad*&
2061 & sepsensorksphi)+cos(zero)+1e-16)
2062 ! also do the ks-based spensenor max computation
2063  call pushcontrol1b(0)
2064  else
2065  call pushcontrol1b(1)
2066  end if
2067 ! dot product with free stream
2068  call pushreal8(sensor)
2069  sensor = -(v(1)*veldirfreestream(1)+v(2)*veldirfreestream(2)+v(3)*&
2070 & veldirfreestream(3))
2071 !now run through a smooth heaviside function:
2072  call pushreal8(sensor)
2073  sensor = one/(one+exp(-(2*sepsensorsharpness*(sensor-&
2074 & sepsensoroffset))))
2075 ! and integrate over the area of this cell and save, blanking as we go.
2076  call pushreal8(sensor)
2077  sensor = sensor*cellarea*blk
2078 ! also accumulate into the sepsensoravg
2079 ! x-y-zco are computed above for center of force computations
2080  if (computecavitation) then
2081  plocal = pp2(i, j)
2082  tmp = two/(gammainf*machcoef*machcoef)
2083  cp = tmp*(plocal-pinf)
2084  sensor1 = -cp - cavitationnumber
2085  call pushreal8(sensor1)
2086  sensor1 = sensor1**cavexponent/(one+exp(2*cavsensorsharpness*(-&
2087 & sensor1+cavsensoroffset)))
2088 ! also do the ks-based cpmin computation
2089  sensor1d = cavitationd
2090  cellaread = sensor1*blk*sensor1d
2091  sensor1d = cellarea*blk*sensor1d
2092  call popreal8(sensor1)
2093  temp1 = 2*cavsensorsharpness*(cavsensoroffset-sensor1)
2094  temp0 = one + exp(temp1)
2095  if (sensor1 .le. 0.0_8 .and. (cavexponent .eq. 0.0_8 .or. &
2096 & cavexponent .ne. int(cavexponent))) then
2097  sensor1d = cavsensorsharpness*2*exp(temp1)*sensor1**&
2098 & cavexponent*sensor1d/temp0**2
2099  else
2100  sensor1d = (cavexponent*sensor1**(cavexponent-1)/temp0+&
2101 & cavsensorsharpness*2*exp(temp1)*sensor1**cavexponent/temp0**&
2102 & 2)*sensor1d
2103  end if
2104  ks_exponentd = blk*cpmin_ks_sumd
2105  cpd = -(cpmin_rho*exp(cpmin_rho*(cpmin_family(spectralsol)-cp))*&
2106 & ks_exponentd) - sensor1d
2107  tmpd = (plocal-pinf)*cpd
2108  plocald = tmp*cpd
2109  pinfd = pinfd - tmp*cpd
2110  temp1 = gammainf*(machcoef*machcoef)
2111  machcoefd = machcoefd - 2*machcoef*gammainf*two*tmpd/temp1**2
2113  pp2d(i, j) = pp2d(i, j) + plocald
2114  else
2115  cellaread = 0.0_8
2116  end if
2117  sensord = zco*sepsensoravgd(3) + yco*sepsensoravgd(2) + xco*&
2118 & sepsensoravgd(1) + sepsensord
2119  zcod = sensor*sepsensoravgd(3)
2120  ycod = sensor*sepsensoravgd(2)
2121  xcod = sensor*sepsensoravgd(1)
2122  call popreal8(sensor)
2123  cellaread = cellaread + sensor*blk*sensord
2124  sensord = cellarea*blk*sensord
2125  call popreal8(sensor)
2126  temp1 = -(2*sepsensorsharpness*(sensor-sepsensoroffset))
2127  temp0 = one + exp(temp1)
2128  sensord = sepsensorsharpness*2*exp(temp1)*one*sensord/temp0**2
2129  call popreal8(sensor)
2130  vd(1) = vd(1) - veldirfreestream(1)*sensord
2131  veldirfreestreamd(1) = veldirfreestreamd(1) - v(1)*sensord
2132  vd(2) = vd(2) - veldirfreestream(2)*sensord
2133  veldirfreestreamd(2) = veldirfreestreamd(2) - v(2)*sensord
2134  vd(3) = vd(3) - veldirfreestream(3)*sensord
2135  veldirfreestreamd(3) = veldirfreestreamd(3) - v(3)*sensord
2136  call popcontrol1b(branch)
2137  if (branch .eq. 0) then
2138  ks_exponentd = blk*sepsensorksd
2139  temp0 = -(2*sepsensorkssharpness*(sepsensorksoffset+sensor))
2140  temp = one + exp(temp0)
2141  tempd1 = blk*one*sepsensoraread/temp
2142  cellaread = cellaread + tempd1 + blk*sepsensorksaread
2143  sensord = sepsensorkssharpness*2*exp(temp0)*cellarea*tempd1/temp
2144  call ksaggregationfunction_b(sensor, sensord, sepsenmaxfamily(&
2145 & spectralsol), sepsenmaxrho, ks_exponent, &
2146 & ks_exponentd)
2147  sensord = -(sensord/(cos(zero)-cos(degtorad*sepsensorksphi)+&
2148 & 1e-16))
2149  vd(1) = vd(1) + vecttangential(1)*sensord
2150  vecttangentiald(1) = vecttangentiald(1) + v(1)*sensord
2151  vd(2) = vd(2) + vecttangential(2)*sensord
2152  vecttangentiald(2) = vecttangentiald(2) + v(2)*sensord
2153  vd(3) = vd(3) + vecttangential(3)*sensord
2154  vecttangentiald(3) = vecttangentiald(3) + v(3)*sensord
2155  call popreal8array(vecttangential, 3)
2156  tmpd1 = vecttangentiald
2157  temp0 = vecttangential(1)*vecttangential(1) + vecttangential(2)*&
2158 & vecttangential(2) + vecttangential(3)*vecttangential(3)
2159  temp = sqrt(temp0)
2160  vecttangentiald = tmpd1/(temp+1e-16)
2161  if (temp0 .eq. 0.0_8) then
2162  tempd0 = 0.0_8
2163  else
2164  tempd0 = -(sum(vecttangential*tmpd1)/(2.0*temp*(temp+1e-16)**2&
2165 & ))
2166  end if
2167  vecttangentiald(1) = vecttangentiald(1) + 2*vecttangential(1)*&
2168 & tempd0
2169  vecttangentiald(2) = vecttangentiald(2) + 2*vecttangential(2)*&
2170 & tempd0
2171  vecttangentiald(3) = vecttangentiald(3) + 2*vecttangential(3)*&
2172 & tempd0
2173  vectdotproductfsnormald = -(bcdata(mm)%norm(i, j, 3)*&
2174 & vecttangentiald(3)) - bcdata(mm)%norm(i, j, 2)*vecttangentiald&
2175 & (2) - bcdata(mm)%norm(i, j, 1)*vecttangentiald(1)
2176  veldirfreestreamd(3) = veldirfreestreamd(3) + vecttangentiald(3)&
2177 & + bcdata(mm)%norm(i, j, 3)*vectdotproductfsnormald
2178  vecttangentiald(3) = 0.0_8
2179  veldirfreestreamd(2) = veldirfreestreamd(2) + vecttangentiald(2)&
2180 & + bcdata(mm)%norm(i, j, 2)*vectdotproductfsnormald
2181  vecttangentiald(2) = 0.0_8
2182  veldirfreestreamd(1) = veldirfreestreamd(1) + vecttangentiald(1)&
2183 & + bcdata(mm)%norm(i, j, 1)*vectdotproductfsnormald
2184  vecttangentiald(1) = 0.0_8
2185  end if
2186  mxd = blk*mpd(1)
2187  myd = blk*mpd(2)
2188  mzd = blk*mpd(3)
2189  call popreal8array(v, 3)
2190  tmpd0 = vd
2191  temp = v(1)*v(1) + v(2)*v(2) + v(3)*v(3)
2192  temp0 = sqrt(temp)
2193  vd = tmpd0/(temp0+1e-16)
2194  if (temp .eq. 0.0_8) then
2195  tempd = 0.0_8
2196  else
2197  tempd = -(sum(v*tmpd0)/(2.0*temp0*(temp0+1e-16)**2))
2198  end if
2199  vd(1) = vd(1) + 2*v(1)*tempd
2200  vd(2) = vd(2) + 2*v(2)*tempd
2201  vd(3) = vd(3) + 2*v(3)*tempd
2202  ww2d(i, j, ivz) = ww2d(i, j, ivz) + vd(3)
2203  vd(3) = 0.0_8
2204  ww2d(i, j, ivy) = ww2d(i, j, ivy) + vd(2)
2205  vd(2) = 0.0_8
2206  ww2d(i, j, ivx) = ww2d(i, j, ivx) + vd(1)
2207  vd(1) = 0.0_8
2208  cellaread = cellaread + bcdatad(mm)%area(i, j)
2209  bcdatad(mm)%area(i, j) = 0.0_8
2210  if (ssi(i, j, 1)**2 + ssi(i, j, 2)**2 + ssi(i, j, 3)**2 .eq. 0.0_8&
2211 & ) then
2212  tempd = 0.0_8
2213  else
2214  tempd = cellaread/(2.0*sqrt(ssi(i, j, 1)**2+ssi(i, j, 2)**2+ssi(&
2215 & i, j, 3)**2))
2216  end if
2217  ssid(i, j, 1) = ssid(i, j, 1) + 2*ssi(i, j, 1)*tempd
2218  ssid(i, j, 2) = ssid(i, j, 2) + 2*ssi(i, j, 2)*tempd
2219  ssid(i, j, 3) = ssid(i, j, 3) + 2*ssi(i, j, 3)*tempd
2220  tempd = blk*mpaxisd
2221  m0xd = n(1)*tempd
2222  m0yd = n(2)*tempd
2223  fzd = bcdatad(mm)%fp(i, j, 3) + r(2)*m0xd - r(1)*m0yd + zco*blk*&
2224 & cofsumfzd(3) + yco*blk*cofsumfzd(2) + xco*blk*cofsumfzd(1) + yc*&
2225 & mxd - xc*myd + blk*fpd(3)
2226  bcdatad(mm)%fp(i, j, 3) = 0.0_8
2227  m0zd = n(3)*tempd
2228  fyd = bcdatad(mm)%fp(i, j, 2) + r(1)*m0zd + zco*blk*cofsumfyd(3) -&
2229 & r(3)*m0xd + yco*blk*cofsumfyd(2) + xco*blk*cofsumfyd(1) + xc*mzd&
2230 & + blk*fpd(2) - zc*mxd
2231  bcdatad(mm)%fp(i, j, 2) = 0.0_8
2232  fxd = bcdatad(mm)%fp(i, j, 1) + r(3)*m0yd - r(2)*m0zd + zco*blk*&
2233 & cofsumfxd(3) + yco*blk*cofsumfxd(2) + xco*blk*cofsumfxd(1) + zc*&
2234 & myd - yc*mzd + blk*fpd(1)
2235  bcdatad(mm)%fp(i, j, 1) = 0.0_8
2236  rd(1) = rd(1) + fy*m0zd - fz*m0yd
2237  rd(2) = rd(2) + fz*m0xd - fx*m0zd
2238  rd(3) = rd(3) + fx*m0yd - fy*m0xd
2239  tempd = fourth*rd(3)
2240  rd(3) = 0.0_8
2241  xxd(i, j, 3) = xxd(i, j, 3) + tempd
2242  xxd(i+1, j, 3) = xxd(i+1, j, 3) + tempd
2243  xxd(i, j+1, 3) = xxd(i, j+1, 3) + tempd
2244  xxd(i+1, j+1, 3) = xxd(i+1, j+1, 3) + tempd
2245  tempd = fourth*rd(2)
2246  rd(2) = 0.0_8
2247  xxd(i, j, 2) = xxd(i, j, 2) + tempd
2248  xxd(i+1, j, 2) = xxd(i+1, j, 2) + tempd
2249  xxd(i, j+1, 2) = xxd(i, j+1, 2) + tempd
2250  xxd(i+1, j+1, 2) = xxd(i+1, j+1, 2) + tempd
2251  tempd = fourth*rd(1)
2252  rd(1) = 0.0_8
2253  xxd(i, j, 1) = xxd(i, j, 1) + tempd
2254  xxd(i+1, j, 1) = xxd(i+1, j, 1) + tempd
2255  xxd(i, j+1, 1) = xxd(i, j+1, 1) + tempd
2256  xxd(i+1, j+1, 1) = xxd(i+1, j+1, 1) + tempd
2257  zcod = zcod + fz*blk*cofsumfzd(3) + fy*blk*cofsumfyd(3) + fx*blk*&
2258 & cofsumfxd(3)
2259  ycod = ycod + fz*blk*cofsumfzd(2) + fy*blk*cofsumfyd(2) + fx*blk*&
2260 & cofsumfxd(2)
2261  xcod = xcod + fz*blk*cofsumfzd(1) + fy*blk*cofsumfyd(1) + fx*blk*&
2262 & cofsumfxd(1)
2263  tempd = fourth*zcod
2264  xxd(i, j, 3) = xxd(i, j, 3) + tempd
2265  xxd(i+1, j, 3) = xxd(i+1, j, 3) + tempd
2266  xxd(i, j+1, 3) = xxd(i, j+1, 3) + tempd
2267  xxd(i+1, j+1, 3) = xxd(i+1, j+1, 3) + tempd
2268  tempd = fourth*ycod
2269  xxd(i, j, 2) = xxd(i, j, 2) + tempd
2270  xxd(i+1, j, 2) = xxd(i+1, j, 2) + tempd
2271  xxd(i, j+1, 2) = xxd(i, j+1, 2) + tempd
2272  xxd(i+1, j+1, 2) = xxd(i+1, j+1, 2) + tempd
2273  tempd = fourth*xcod
2274  xxd(i, j, 1) = xxd(i, j, 1) + tempd
2275  xxd(i+1, j, 1) = xxd(i+1, j, 1) + tempd
2276  xxd(i, j+1, 1) = xxd(i, j+1, 1) + tempd
2277  xxd(i+1, j+1, 1) = xxd(i+1, j+1, 1) + tempd
2278  xcd = fy*mzd - fz*myd
2279  ycd = fz*mxd - fx*mzd
2280  zcd = fx*myd - fy*mxd
2281  pm1d = ssi(i, j, 3)*fzd + ssi(i, j, 2)*fyd + ssi(i, j, 1)*fxd
2282  ssid(i, j, 3) = ssid(i, j, 3) + pm1*fzd
2283  ssid(i, j, 2) = ssid(i, j, 2) + pm1*fyd
2284  ssid(i, j, 1) = ssid(i, j, 1) + pm1*fxd
2285  tempd = fourth*zcd
2286  refpointd(3) = refpointd(3) - zcd
2287  xxd(i, j, 3) = xxd(i, j, 3) + tempd
2288  xxd(i+1, j, 3) = xxd(i+1, j, 3) + tempd
2289  xxd(i, j+1, 3) = xxd(i, j+1, 3) + tempd
2290  xxd(i+1, j+1, 3) = xxd(i+1, j+1, 3) + tempd
2291  tempd = fourth*ycd
2292  refpointd(2) = refpointd(2) - ycd
2293  xxd(i, j, 2) = xxd(i, j, 2) + tempd
2294  xxd(i+1, j, 2) = xxd(i+1, j, 2) + tempd
2295  xxd(i, j+1, 2) = xxd(i, j+1, 2) + tempd
2296  xxd(i+1, j+1, 2) = xxd(i+1, j+1, 2) + tempd
2297  tempd = fourth*xcd
2298  refpointd(1) = refpointd(1) - xcd
2299  xxd(i, j, 1) = xxd(i, j, 1) + tempd
2300  xxd(i+1, j, 1) = xxd(i+1, j, 1) + tempd
2301  xxd(i, j+1, 1) = xxd(i, j+1, 1) + tempd
2302  xxd(i+1, j+1, 1) = xxd(i+1, j+1, 1) + tempd
2303  cperrord = 2*cperror*cperror2d
2304  cpd = cperrord
2305  tempd = tmp*cpd
2306  tmpd = (half*(pp2(i, j)+pp1(i, j))-pinf)*cpd
2307  pp2d(i, j) = pp2d(i, j) + half*tempd
2308  pp1d(i, j) = pp1d(i, j) + half*tempd
2309  pinfd = pinfd - tempd
2310  temp = gammainf*pinf*(machcoef*machcoef)
2311  tempd = -(two*tmpd/temp**2)
2312  pinfd = pinfd + gammainf*machcoef**2*tempd
2314  tempd = pref*fact*pm1d
2315  prefd = prefd + (half*(pp2(i, j)+pp1(i, j))-pinf)*fact*pm1d
2316  pp2d(i, j) = pp2d(i, j) + half*tempd
2317  pp1d(i, j) = pp1d(i, j) + half*tempd
2318  pinfd = pinfd - tempd
2319  end do
2320  pointrefd(3) = pointrefd(3) + lref*refpointd(3)
2321  refpointd(3) = 0.0_8
2322  pointrefd(2) = pointrefd(2) + lref*refpointd(2)
2323  refpointd(2) = 0.0_8
2324  pointrefd(1) = pointrefd(1) + lref*refpointd(1)
2325  end subroutine wallintegrationface_b
2326 
2327  subroutine wallintegrationface(localvalues, mm)
2328 !
2329 ! wallintegrations computes the contribution of the block
2330 ! given by the pointers in blockpointers to the force and
2331 ! moment of the geometry. a distinction is made
2332 ! between the inviscid and viscous parts. in case the maximum
2333 ! yplus value must be monitored (only possible for rans), this
2334 ! value is also computed. the separation sensor and the cavita-
2335 ! tion sensor is also computed
2336 ! here.
2337 !
2338  use constants
2339  use communication
2340  use blockpointers
2341  use flowvarrefstate
2342  use inputcostfunctions
2346  use bcpointers_b
2347  implicit none
2348 ! input/output variables
2349  real(kind=realtype), dimension(nlocalvalues), intent(inout) :: &
2350 & localvalues
2351  integer(kind=inttype) :: mm
2352 ! local variables.
2353  real(kind=realtype), dimension(3) :: fp, fv, mp, mv
2354  real(kind=realtype), dimension(3) :: cofsumfx, cofsumfy, cofsumfz
2355  real(kind=realtype) :: yplusmax, sepsensorks, sepsensor, &
2356 & sepsensoravg(3), sepsensorarea, cavitation, cpmin_ks_sum, &
2357 & sepsensorksarea
2358  integer(kind=inttype) :: i, j, ii, blk
2359  real(kind=realtype) :: pm1, fx, fy, fz, fn
2360  real(kind=realtype) :: vecttangential(3)
2361  real(kind=realtype) :: vectdotproductfsnormal
2362  real(kind=realtype) :: xc, xco, yc, yco, zc, zco, qf(3), r(3), n(3)&
2363 & , l
2364  real(kind=realtype) :: fact, rho, mul, yplus, dwall
2365  real(kind=realtype) :: v(3), sensor, sensor1, cp, tmp, plocal, &
2366 & ks_exponent
2367  real(kind=realtype) :: tauxx, tauyy, tauzz
2368  real(kind=realtype) :: tauxy, tauxz, tauyz
2369  real(kind=realtype), dimension(3) :: refpoint
2370  real(kind=realtype), dimension(3, 2) :: axispoints
2371  real(kind=realtype) :: mx, my, mz, cellarea, m0x, m0y, m0z, mvaxis, &
2372 & mpaxis
2373  real(kind=realtype) :: cperror, cperror2
2374  intrinsic mod
2375  intrinsic max
2376  intrinsic sqrt
2377  intrinsic cos
2378  intrinsic exp
2379  select case (bcfaceid(mm))
2380  case (imin, jmin, kmin)
2381  fact = -one
2382  case (imax, jmax, kmax)
2383  fact = one
2384  end select
2385 ! determine the reference point for the moment computation in
2386 ! meters.
2387  refpoint(1) = lref*pointref(1)
2388  refpoint(2) = lref*pointref(2)
2389  refpoint(3) = lref*pointref(3)
2390 ! determine the points defining the axis about which to compute a moment
2391  axispoints(1, 1) = lref*momentaxis(1, 1)
2392  axispoints(1, 2) = lref*momentaxis(1, 2)
2393  axispoints(2, 1) = lref*momentaxis(2, 1)
2394  axispoints(2, 2) = lref*momentaxis(2, 2)
2395  axispoints(3, 1) = lref*momentaxis(3, 1)
2396  axispoints(3, 2) = lref*momentaxis(3, 2)
2397 ! initialize the force and moment coefficients to 0 as well as
2398 ! yplusmax.
2399  fp = zero
2400  fv = zero
2401  mp = zero
2402  mv = zero
2403  cofsumfx = zero
2404  cofsumfy = zero
2405  cofsumfz = zero
2406  yplusmax = zero
2407  sepsensor = zero
2408  sepsensorks = zero
2409  sepsensorarea = zero
2410  sepsensorksarea = zero
2411  cavitation = zero
2412  cpmin_ks_sum = zero
2413  sepsensoravg = zero
2414  mpaxis = zero
2415  mvaxis = zero
2416  cperror2 = zero
2417 !$ad ii-loop
2418 !
2419 ! integrate the inviscid contribution over the solid walls,
2420 ! either inviscid or viscous. the integration is done with
2421 ! cp. for closed contours this is equal to the integration
2422 ! of p; for open contours this is not the case anymore.
2423 ! question is whether a force for an open contour is
2424 ! meaningful anyway.
2425 !
2426 ! loop over the quadrilateral faces of the subface. note that
2427 ! the nodal range of bcdata must be used and not the cell
2428 ! range, because the latter may include the halo's in i and
2429 ! j-direction. the offset +1 is there, because inbeg and jnbeg
2430 ! refer to nodal ranges and not to cell ranges. the loop
2431 ! (without the ad stuff) would look like:
2432 !
2433 ! do j=(bcdata(mm)%jnbeg+1),bcdata(mm)%jnend
2434 ! do i=(bcdata(mm)%inbeg+1),bcdata(mm)%inend
2435  do ii=0,(bcdata(mm)%jnend-bcdata(mm)%jnbeg)*(bcdata(mm)%inend-bcdata&
2436 & (mm)%inbeg)-1
2437  i = mod(ii, bcdata(mm)%inend - bcdata(mm)%inbeg) + bcdata(mm)%&
2438 & inbeg + 1
2439  j = ii/(bcdata(mm)%inend-bcdata(mm)%inbeg) + bcdata(mm)%jnbeg + 1
2440 ! compute the average pressure minus 1 and the coordinates
2441 ! of the centroid of the face relative from from the
2442 ! moment reference point. due to the usage of pointers for
2443 ! the coordinates, whose original array starts at 0, an
2444 ! offset of 1 must be used. the pressure is multipled by
2445 ! fact to account for the possibility of an inward or
2446 ! outward pointing normal.
2447  pm1 = fact*(half*(pp2(i, j)+pp1(i, j))-pinf)*pref
2449  cp = (half*(pp2(i, j)+pp1(i, j))-pinf)*tmp
2450  cperror = cp - bcdata(mm)%cptarget(i, j)
2451  cperror2 = cperror2 + cperror*cperror
2452  xc = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1, &
2453 & 1)) - refpoint(1)
2454  yc = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1, &
2455 & 2)) - refpoint(2)
2456  zc = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1, &
2457 & 3)) - refpoint(3)
2458  if (bcdata(mm)%iblank(i, j) .lt. 0) then
2459  blk = 0
2460  else
2461  blk = bcdata(mm)%iblank(i, j)
2462  end if
2463  fx = pm1*ssi(i, j, 1)
2464  fy = pm1*ssi(i, j, 2)
2465  fz = pm1*ssi(i, j, 3)
2466 ! note from ay: technically, we can just compute the moments using the center of force
2467 ! terms. however, the moment computations coded here distinguish pressure,
2468 ! viscous, and momentum contributions to moment. even though these individual
2469 ! contributions are not exposed to python, i still wanted to keep how it's done in the
2470 ! code in case its useful in the future. this is also true for the face integrations
2471 ! update the inviscid force and moment coefficients. iblank as we sum
2472  fp(1) = fp(1) + fx*blk
2473  fp(2) = fp(2) + fy*blk
2474  fp(3) = fp(3) + fz*blk
2475  mx = yc*fz - zc*fy
2476  my = zc*fx - xc*fz
2477  mz = xc*fy - yc*fx
2478  mp(1) = mp(1) + mx*blk
2479  mp(2) = mp(2) + my*blk
2480  mp(3) = mp(3) + mz*blk
2481 ! the force integral for the center of pressure computation.
2482 ! we need the cell centers wrt origin
2483  xco = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
2484 & , 1))
2485  yco = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
2486 & , 2))
2487  zco = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
2488 & , 3))
2489 ! accumulate in the sums. each force component is tracked separately
2490 ! force-x
2491  cofsumfx(1) = cofsumfx(1) + xco*fx*blk
2492  cofsumfx(2) = cofsumfx(2) + yco*fx*blk
2493  cofsumfx(3) = cofsumfx(3) + zco*fx*blk
2494 ! force-y
2495  cofsumfy(1) = cofsumfy(1) + xco*fy*blk
2496  cofsumfy(2) = cofsumfy(2) + yco*fy*blk
2497  cofsumfy(3) = cofsumfy(3) + zco*fy*blk
2498 ! force-z
2499  cofsumfz(1) = cofsumfz(1) + xco*fz*blk
2500  cofsumfz(2) = cofsumfz(2) + yco*fz*blk
2501  cofsumfz(3) = cofsumfz(3) + zco*fz*blk
2502 ! compute the r and n vectores for the moment around an
2503 ! axis computation where r is the distance from the
2504 ! force to the first point on the axis and n is a unit
2505 ! normal in the direction of the axis
2506  r(1) = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
2507 & , 1)) - axispoints(1, 1)
2508  r(2) = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
2509 & , 2)) - axispoints(2, 1)
2510  r(3) = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
2511 & , 3)) - axispoints(3, 1)
2512  l = sqrt((axispoints(1, 2)-axispoints(1, 1))**2 + (axispoints(2, 2&
2513 & )-axispoints(2, 1))**2 + (axispoints(3, 2)-axispoints(3, 1))**2)
2514  n(1) = (axispoints(1, 2)-axispoints(1, 1))/l
2515  n(2) = (axispoints(2, 2)-axispoints(2, 1))/l
2516  n(3) = (axispoints(3, 2)-axispoints(3, 1))/l
2517 ! compute the moment of the force about the first point
2518 ! used to define the axis, and the project that axis in
2519 ! the n direction
2520  m0x = r(2)*fz - r(3)*fy
2521  m0y = r(3)*fx - r(1)*fz
2522  m0z = r(1)*fy - r(2)*fx
2523  mpaxis = mpaxis + (m0x*n(1)+m0y*n(2)+m0z*n(3))*blk
2524 ! save the face-based forces and area
2525  bcdata(mm)%fp(i, j, 1) = fx
2526  bcdata(mm)%fp(i, j, 2) = fy
2527  bcdata(mm)%fp(i, j, 3) = fz
2528  cellarea = sqrt(ssi(i, j, 1)**2 + ssi(i, j, 2)**2 + ssi(i, j, 3)**&
2529 & 2)
2530  bcdata(mm)%area(i, j) = cellarea
2531 ! get normalized surface velocity:
2532  v(1) = ww2(i, j, ivx)
2533  v(2) = ww2(i, j, ivy)
2534  v(3) = ww2(i, j, ivz)
2535  v = v/(sqrt(v(1)**2+v(2)**2+v(3)**2)+1e-16)
2536  if (computesepsensorks) then
2537 ! freestream projection over the surface.
2538  vectdotproductfsnormal = veldirfreestream(1)*bcdata(mm)%norm(i, &
2539 & j, 1) + veldirfreestream(2)*bcdata(mm)%norm(i, j, 2) + &
2540 & veldirfreestream(3)*bcdata(mm)%norm(i, j, 3)
2541 ! tangential vector on the surface, which is the freestream projected vector
2542  vecttangential(1) = veldirfreestream(1) - vectdotproductfsnormal&
2543 & *bcdata(mm)%norm(i, j, 1)
2544  vecttangential(2) = veldirfreestream(2) - vectdotproductfsnormal&
2545 & *bcdata(mm)%norm(i, j, 2)
2546  vecttangential(3) = veldirfreestream(3) - vectdotproductfsnormal&
2547 & *bcdata(mm)%norm(i, j, 3)
2548  vecttangential = vecttangential/(sqrt(vecttangential(1)**2+&
2549 & vecttangential(2)**2+vecttangential(3)**2)+1e-16)
2550 ! computing separation sensor
2551 ! velocity dot products
2552  sensor = v(1)*vecttangential(1) + v(2)*vecttangential(2) + v(3)*&
2553 & vecttangential(3)
2554 ! sepsensor value
2555  sensor = (cos(degtorad*sepsensorksphi)-sensor)/(-cos(degtorad*&
2556 & sepsensorksphi)+cos(zero)+1e-16)
2557 ! also do the ks-based spensenor max computation
2559 & , sepsenmaxrho, ks_exponent)
2560  sepsensorksarea = sepsensorksarea + blk*cellarea
2561  sepsensorarea = cellarea*blk*one/(one+exp(-(2*&
2562 & sepsensorkssharpness*(sensor+sepsensorksoffset)))) + &
2563 & sepsensorarea
2564  sepsensorks = sepsensorks + ks_exponent*blk
2565  end if
2566 ! dot product with free stream
2567  sensor = -(v(1)*veldirfreestream(1)+v(2)*veldirfreestream(2)+v(3)*&
2568 & veldirfreestream(3))
2569 !now run through a smooth heaviside function:
2570  sensor = one/(one+exp(-(2*sepsensorsharpness*(sensor-&
2571 & sepsensoroffset))))
2572 ! and integrate over the area of this cell and save, blanking as we go.
2573  sensor = sensor*cellarea*blk
2574  sepsensor = sepsensor + sensor
2575 ! also accumulate into the sepsensoravg
2576 ! x-y-zco are computed above for center of force computations
2577  sepsensoravg(1) = sepsensoravg(1) + sensor*xco
2578  sepsensoravg(2) = sepsensoravg(2) + sensor*yco
2579  sepsensoravg(3) = sepsensoravg(3) + sensor*zco
2580  if (computecavitation) then
2581  plocal = pp2(i, j)
2582  tmp = two/(gammainf*machcoef*machcoef)
2583  cp = tmp*(plocal-pinf)
2584  sensor1 = -cp - cavitationnumber
2585  sensor1 = sensor1**cavexponent/(one+exp(2*cavsensorsharpness*(-&
2586 & sensor1+cavsensoroffset)))
2587  sensor1 = sensor1*cellarea*blk
2588  cavitation = cavitation + sensor1
2589 ! also do the ks-based cpmin computation
2590  ks_exponent = exp(cpmin_rho*(-cp+cpmin_family(spectralsol)))
2591  cpmin_ks_sum = cpmin_ks_sum + ks_exponent*blk
2592  end if
2593  end do
2594 !
2595 ! integration of the viscous forces.
2596 ! only for viscous boundaries.
2597 !
2598  if (bctype(mm) .eq. nswalladiabatic .or. bctype(mm) .eq. &
2599 & nswallisothermal) then
2600 ! initialize dwall for the laminar case and set the pointer
2601 ! for the unit normals.
2602  dwall = zero
2603 !$ad ii-loop
2604 ! loop over the quadrilateral faces of the subface and
2605 ! compute the viscous contribution to the force and
2606 ! moment and update the maximum value of y+.
2607  do ii=0,(bcdata(mm)%jnend-bcdata(mm)%jnbeg)*(bcdata(mm)%inend-&
2608 & bcdata(mm)%inbeg)-1
2609  i = mod(ii, bcdata(mm)%inend - bcdata(mm)%inbeg) + bcdata(mm)%&
2610 & inbeg + 1
2611  j = ii/(bcdata(mm)%inend-bcdata(mm)%inbeg) + bcdata(mm)%jnbeg + &
2612 & 1
2613  if (bcdata(mm)%iblank(i, j) .lt. 0) then
2614  blk = 0
2615  else
2616  blk = bcdata(mm)%iblank(i, j)
2617  end if
2618  tauxx = viscsubface(mm)%tau(i, j, 1)
2619  tauyy = viscsubface(mm)%tau(i, j, 2)
2620  tauzz = viscsubface(mm)%tau(i, j, 3)
2621  tauxy = viscsubface(mm)%tau(i, j, 4)
2622  tauxz = viscsubface(mm)%tau(i, j, 5)
2623  tauyz = viscsubface(mm)%tau(i, j, 6)
2624 ! compute the viscous force on the face. a minus sign
2625 ! is now present, due to the definition of this force.
2626  fx = -(fact*(tauxx*ssi(i, j, 1)+tauxy*ssi(i, j, 2)+tauxz*ssi(i, &
2627 & j, 3))*pref)
2628  fy = -(fact*(tauxy*ssi(i, j, 1)+tauyy*ssi(i, j, 2)+tauyz*ssi(i, &
2629 & j, 3))*pref)
2630  fz = -(fact*(tauxz*ssi(i, j, 1)+tauyz*ssi(i, j, 2)+tauzz*ssi(i, &
2631 & j, 3))*pref)
2632 ! compute the coordinates of the centroid of the face
2633 ! relative from the moment reference point. due to the
2634 ! usage of pointers for xx and offset of 1 is present,
2635 ! because x originally starts at 0.
2636  xc = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
2637 & , 1)) - refpoint(1)
2638  yc = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
2639 & , 2)) - refpoint(2)
2640  zc = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
2641 & , 3)) - refpoint(3)
2642 ! update the viscous force and moment coefficients, blanking as we go.
2643  fv(1) = fv(1) + fx*blk
2644  fv(2) = fv(2) + fy*blk
2645  fv(3) = fv(3) + fz*blk
2646  mx = yc*fz - zc*fy
2647  my = zc*fx - xc*fz
2648  mz = xc*fy - yc*fx
2649  mv(1) = mv(1) + mx*blk
2650  mv(2) = mv(2) + my*blk
2651  mv(3) = mv(3) + mz*blk
2652 ! the force integral for the center of pressure computation.
2653 ! we need the cell centers wrt origin
2654  xco = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+&
2655 & 1, 1))
2656  yco = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+&
2657 & 1, 2))
2658  zco = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+&
2659 & 1, 3))
2660 ! accumulate in the sums. each force component is tracked separately
2661 ! force-x
2662  cofsumfx(1) = cofsumfx(1) + xco*fx*blk
2663  cofsumfx(2) = cofsumfx(2) + yco*fx*blk
2664  cofsumfx(3) = cofsumfx(3) + zco*fx*blk
2665 ! force-y
2666  cofsumfy(1) = cofsumfy(1) + xco*fy*blk
2667  cofsumfy(2) = cofsumfy(2) + yco*fy*blk
2668  cofsumfy(3) = cofsumfy(3) + zco*fy*blk
2669 ! force-z
2670  cofsumfz(1) = cofsumfz(1) + xco*fz*blk
2671  cofsumfz(2) = cofsumfz(2) + yco*fz*blk
2672  cofsumfz(3) = cofsumfz(3) + zco*fz*blk
2673 ! compute the r and n vectors for the moment around an
2674 ! axis computation where r is the distance from the
2675 ! force to the first point on the axis and n is a unit
2676 ! normal in the direction of the axis
2677  r(1) = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j&
2678 & +1, 1)) - axispoints(1, 1)
2679  r(2) = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j&
2680 & +1, 2)) - axispoints(2, 1)
2681  r(3) = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j&
2682 & +1, 3)) - axispoints(3, 1)
2683  l = sqrt((axispoints(1, 2)-axispoints(1, 1))**2 + (axispoints(2&
2684 & , 2)-axispoints(2, 1))**2 + (axispoints(3, 2)-axispoints(3, 1)&
2685 & )**2)
2686  n(1) = (axispoints(1, 2)-axispoints(1, 1))/l
2687  n(2) = (axispoints(2, 2)-axispoints(2, 1))/l
2688  n(3) = (axispoints(3, 2)-axispoints(3, 1))/l
2689 ! compute the moment of the force about the first point
2690 ! used to define the axis, and then project that axis in
2691 ! the n direction
2692  m0x = r(2)*fz - r(3)*fy
2693  m0y = r(3)*fx - r(1)*fz
2694  m0z = r(1)*fy - r(2)*fx
2695  mvaxis = mvaxis + (m0x*n(1)+m0y*n(2)+m0z*n(3))*blk
2696 ! save the face based forces for the slice operations
2697  bcdata(mm)%fv(i, j, 1) = fx
2698  bcdata(mm)%fv(i, j, 2) = fy
2699  bcdata(mm)%fv(i, j, 3) = fz
2700 ! compute the tangential component of the stress tensor,
2701 ! which is needed to monitor y+. the result is stored
2702 ! in fx, fy, fz, although it is not really a force.
2703 ! as later on only the magnitude of the tangential
2704 ! component is important, there is no need to take the
2705 ! sign into account (it should be a minus sign).
2706  fx = tauxx*bcdata(mm)%norm(i, j, 1) + tauxy*bcdata(mm)%norm(i, j&
2707 & , 2) + tauxz*bcdata(mm)%norm(i, j, 3)
2708  fy = tauxy*bcdata(mm)%norm(i, j, 1) + tauyy*bcdata(mm)%norm(i, j&
2709 & , 2) + tauyz*bcdata(mm)%norm(i, j, 3)
2710  fz = tauxz*bcdata(mm)%norm(i, j, 1) + tauyz*bcdata(mm)%norm(i, j&
2711 & , 2) + tauzz*bcdata(mm)%norm(i, j, 3)
2712  fn = fx*bcdata(mm)%norm(i, j, 1) + fy*bcdata(mm)%norm(i, j, 2) +&
2713 & fz*bcdata(mm)%norm(i, j, 3)
2714  fx = fx - fn*bcdata(mm)%norm(i, j, 1)
2715  fy = fy - fn*bcdata(mm)%norm(i, j, 2)
2716  fz = fz - fn*bcdata(mm)%norm(i, j, 3)
2717 ! compute the local value of y+. due to the usage
2718 ! of pointers there is on offset of -1 in dd2wall..
2719  end do
2720  else
2721 ! if we had no viscous force, set the viscous component to zero
2722  bcdata(mm)%fv = zero
2723  end if
2724 ! increment the local values array with the values we computed here.
2725  localvalues(ifp:ifp+2) = localvalues(ifp:ifp+2) + fp
2726  localvalues(ifv:ifv+2) = localvalues(ifv:ifv+2) + fv
2727  localvalues(imp:imp+2) = localvalues(imp:imp+2) + mp
2728  localvalues(imv:imv+2) = localvalues(imv:imv+2) + mv
2729  localvalues(icoforcex:icoforcex+2) = localvalues(icoforcex:icoforcex&
2730 & +2) + cofsumfx
2731  localvalues(icoforcey:icoforcey+2) = localvalues(icoforcey:icoforcey&
2732 & +2) + cofsumfy
2733  localvalues(icoforcez:icoforcez+2) = localvalues(icoforcez:icoforcez&
2734 & +2) + cofsumfz
2735  localvalues(isepsensor) = localvalues(isepsensor) + sepsensor
2736  localvalues(isepsensorks) = localvalues(isepsensorks) + sepsensorks
2737  localvalues(isepsensorksarea) = localvalues(isepsensorksarea) + &
2738 & sepsensorksarea
2739  localvalues(isepsensorarea) = localvalues(isepsensorarea) + &
2740 & sepsensorarea
2741  localvalues(icavitation) = localvalues(icavitation) + cavitation
2742  localvalues(icpmin) = localvalues(icpmin) + cpmin_ks_sum
2743  localvalues(isepavg:isepavg+2) = localvalues(isepavg:isepavg+2) + &
2744 & sepsensoravg
2745  localvalues(iaxismoment) = localvalues(iaxismoment) + mpaxis + &
2746 & mvaxis
2747  localvalues(icperror2) = localvalues(icperror2) + cperror2
2748  end subroutine wallintegrationface
2749 
2750 ! differentiation of ksaggregationfunction in reverse (adjoint) mode (with options noisize i4 dr8 r8):
2751 ! gradient of useful results: ks_g g
2752 ! with respect to varying inputs: g
2753  subroutine ksaggregationfunction_b(g, gd, max_g, g_rho, ks_g, ks_gd)
2754  use precision
2755  implicit none
2756  real(kind=realtype), intent(inout) :: ks_g
2757  real(kind=realtype), intent(inout) :: ks_gd
2758  real(kind=realtype), intent(in) :: g, max_g, g_rho
2759  real(kind=realtype) :: gd
2760  intrinsic exp
2761  gd = gd + g_rho*exp(g_rho*(g-max_g))*ks_gd
2762  end subroutine ksaggregationfunction_b
2763 
2764  subroutine ksaggregationfunction(g, max_g, g_rho, ks_g)
2765  use precision
2766  implicit none
2767  real(kind=realtype), intent(inout) :: ks_g
2768  real(kind=realtype), intent(in) :: g, max_g, g_rho
2769  intrinsic exp
2770  ks_g = exp(g_rho*(g-max_g))
2771  end subroutine ksaggregationfunction
2772 
2773 ! differentiation of flowintegrationface in reverse (adjoint) mode (with options noisize i4 dr8 r8):
2774 ! gradient of useful results: timeref tref pref rgas rhoref
2775 ! *xx *pp1 *pp2 *ssi *ww1 *ww2 pointref localvalues
2776 ! with respect to varying inputs: timeref tref pref rgas rhoref
2777 ! *xx *pp1 *pp2 *ssi *ww1 *ww2 pointref localvalues
2778 ! rw status of diff variables: timeref:incr tref:incr pref:incr
2779 ! rgas:incr rhoref:incr *xx:incr *pp1:incr *pp2:incr
2780 ! *ssi:incr *ww1:incr *ww2:incr pointref:incr localvalues:in-out
2781 ! plus diff mem management of: xx:in pp1:in pp2:in ssi:in ww1:in
2782 ! ww2:in
2783  subroutine flowintegrationface_b(isinflow, localvalues, localvaluesd, &
2784 & mm)
2785  use constants
2786  use blockpointers, only : bctype, bcfaceid, bcdata, bcdatad, &
2788  use flowvarrefstate, only : pref, prefd, pinf, pinfd, rhoref, &
2793 & computettot_b
2794  use bcpointers_b, only : ssi, ssid, sface, ww1, ww1d, ww2, ww2d, pp1&
2795 & , pp1d, pp2, pp2d, xx, xxd, gamma1, gamma2
2796  use utils_b, only : mynorm2
2797  implicit none
2798 ! input/output variables
2799  logical, intent(in) :: isinflow
2800  real(kind=realtype), dimension(nlocalvalues), intent(inout) :: &
2801 & localvalues
2802  real(kind=realtype), dimension(nlocalvalues), intent(inout) :: &
2803 & localvaluesd
2804  integer(kind=inttype), intent(in) :: mm
2805 ! local variables
2806  real(kind=realtype) :: massflowrate, mass_ptot, mass_ttot, mass_ps, &
2807 & mass_mn, mass_a, mass_rho, mass_vx, mass_vy, mass_vz, mass_nx, &
2808 & mass_ny, mass_nz, mass_vi
2809  real(kind=realtype) :: massflowrated, mass_ptotd, mass_ttotd, &
2810 & mass_psd, mass_mnd, mass_ad, mass_rhod, mass_vxd, mass_vyd, mass_vzd&
2811 & , mass_nxd, mass_nyd, mass_nzd, mass_vid
2812  real(kind=realtype) :: area_ptot, area_ps
2813  real(kind=realtype) :: area_ptotd, area_psd
2814  real(kind=realtype) :: govgm1, gm1ovg, viconst, vilocal, pratio
2815  real(kind=realtype) :: vilocald, pratiod
2816  real(kind=realtype) :: mredim
2817  real(kind=realtype) :: mredimd
2818  integer(kind=inttype) :: i, j, ii, blk
2819  real(kind=realtype) :: internalflowfact, inflowfact, fact, xc, xco, &
2820 & yc, yco, zc, zco, mx, my, mz
2821  real(kind=realtype) :: xcd, xcod, ycd, ycod, zcd, zcod, mxd, myd, &
2822 & mzd
2823  real(kind=realtype) :: sf, vmag, vnm, vnmfreestreamref, vxm, vym, &
2824 & vzm, fx, fy, fz, u, v, w
2825  real(kind=realtype) :: vmagd, vnmd, vxmd, vymd, vzmd, fxd, fyd, fzd
2826  real(kind=realtype) :: pm, ptot, ttot, rhom, gammam, am
2827  real(kind=realtype) :: pmd, ptotd, ttotd, rhomd, amd
2828  real(kind=realtype) :: area, cellarea, overcellarea
2829  real(kind=realtype) :: aread, cellaread, overcellaread
2830  real(kind=realtype), dimension(3) :: fp, mp, fmom, mmom, refpoint, &
2831 & sfacecoordref
2832  real(kind=realtype), dimension(3) :: fpd, mpd, fmomd, mmomd, &
2833 & refpointd, sfacecoordrefd
2834  real(kind=realtype), dimension(3) :: cofsumfx, cofsumfy, cofsumfz
2835  real(kind=realtype), dimension(3) :: cofsumfxd, cofsumfyd, cofsumfzd
2836  real(kind=realtype) :: mnm, massflowratelocal
2837  real(kind=realtype) :: mnmd, massflowratelocald
2838  intrinsic sqrt
2839  intrinsic mod
2840  intrinsic max
2841  intrinsic min
2842  real(kind=realtype) :: temp
2843  real(kind=realtype) :: tempd
2844  real(kind=realtype) :: tempd0
2845  integer :: branch
2846  refpoint(1) = lref*pointref(1)
2847  refpoint(2) = lref*pointref(2)
2848  refpoint(3) = lref*pointref(3)
2849 ! note that these are *opposite* of force integrations. the reason
2850 ! is that we want positive mass flow into the domain and negative
2851 ! mass flow out of the domain. since the low faces have ssi
2852 ! vectors pointining into the domain, this is correct. the high
2853 ! end faces need to flip this.
2854  select case (bcfaceid(mm))
2855  case (imin, jmin, kmin)
2856  fact = one
2857  case (imax, jmax, kmax)
2858  fact = -one
2859  end select
2860 ! the sign of momentum forces are flipped for internal flows
2861  internalflowfact = one
2862  if (flowtype .eq. internalflow) internalflowfact = -one
2863  inflowfact = one
2864  if (isinflow) inflowfact = -one
2865 ! loop over the quadrilateral faces of the subface. note that
2866 ! the nodal range of bcdata must be used and not the cell
2867 ! range, because the latter may include the halo's in i and
2868 ! j-direction. the offset +1 is there, because inbeg and jnbeg
2869 ! refer to nodal ranges and not to cell ranges. the loop
2870 ! (without the ad stuff) would look like:
2871 !
2872 ! do j=(bcdata(mm)%jnbeg+1),bcdata(mm)%jnend
2873 ! do i=(bcdata(mm)%inbeg+1),bcdata(mm)%inend
2874  mredim = sqrt(pref*rhoref)
2875  mass_vid = localvaluesd(imassvi)
2876  mass_nzd = localvaluesd(imassnz)
2877  mass_nyd = localvaluesd(imassny)
2878  mass_nxd = localvaluesd(imassnx)
2879  mass_vzd = localvaluesd(imassvz)
2880  mass_vyd = localvaluesd(imassvy)
2881  mass_vxd = localvaluesd(imassvx)
2882  area_psd = localvaluesd(iareaps)
2883  area_ptotd = localvaluesd(iareaptot)
2884  cofsumfzd = 0.0_8
2885  cofsumfzd = localvaluesd(icoforcez:icoforcez+2)
2886  cofsumfyd = 0.0_8
2887  cofsumfyd = localvaluesd(icoforcey:icoforcey+2)
2888  cofsumfxd = 0.0_8
2889  cofsumfxd = localvaluesd(icoforcex:icoforcex+2)
2890  mmomd = 0.0_8
2891  mmomd = localvaluesd(iflowmm:iflowmm+2)
2892  mpd = 0.0_8
2893  mpd = localvaluesd(iflowmp:iflowmp+2)
2894  fmomd = 0.0_8
2895  fmomd = localvaluesd(iflowfm:iflowfm+2)
2896  fpd = 0.0_8
2897  fpd = localvaluesd(ifp:ifp+2)
2898  mass_mnd = localvaluesd(imassmn)
2899  mass_psd = localvaluesd(imassps)
2900  mass_ttotd = localvaluesd(imassttot)
2901  mass_ptotd = localvaluesd(imassptot)
2902  mass_ad = localvaluesd(imassa)
2903  mass_rhod = localvaluesd(imassrho)
2904  aread = localvaluesd(iarea)
2905  massflowrated = localvaluesd(imassflow)
2906  mredimd = 0.0_8
2907  ptotd = 0.0_8
2908  refpointd = 0.0_8
2909  sfacecoordrefd = 0.0_8
2910  ttotd = 0.0_8
2911 !$bwd-of ii-loop
2912  do ii=0,(bcdata(mm)%jnend-bcdata(mm)%jnbeg)*(bcdata(mm)%inend-bcdata&
2913 & (mm)%inbeg)-1
2914  i = mod(ii, bcdata(mm)%inend - bcdata(mm)%inbeg) + bcdata(mm)%&
2915 & inbeg + 1
2916  j = ii/(bcdata(mm)%inend-bcdata(mm)%inbeg) + bcdata(mm)%jnbeg + 1
2917  if (addgridvelocities) then
2918  sf = sface(i, j)
2919  else
2920  sf = zero
2921  end if
2922  if (bcdata(mm)%iblank(i, j) .lt. 0) then
2923  blk = 0
2924  else
2925  blk = bcdata(mm)%iblank(i, j)
2926  end if
2927  vxm = half*(ww1(i, j, ivx)+ww2(i, j, ivx))
2928  vym = half*(ww1(i, j, ivy)+ww2(i, j, ivy))
2929  vzm = half*(ww1(i, j, ivz)+ww2(i, j, ivz))
2930  rhom = half*(ww1(i, j, irho)+ww2(i, j, irho))
2931  pm = half*(pp1(i, j)+pp2(i, j))
2932  gammam = half*(gamma1(i, j)+gamma2(i, j))
2933  vnm = vxm*ssi(i, j, 1) + vym*ssi(i, j, 2) + vzm*ssi(i, j, 3) - sf
2934  vmag = sqrt(vxm**2 + vym**2 + vzm**2) - sf
2935  am = sqrt(gammam*pm/rhom)
2936  mnm = vmag/am
2937  cellarea = sqrt(ssi(i, j, 1)**2 + ssi(i, j, 2)**2 + ssi(i, j, 3)**&
2938 & 2)
2939  overcellarea = 1/cellarea
2940  call computeptot(rhom, vxm, vym, vzm, pm, ptot)
2941  call computettot(rhom, vxm, vym, vzm, pm, ttot)
2942  massflowratelocal = rhom*vnm*blk*fact*mredim
2943 ! re-dimentionalize quantities
2944  call pushreal8(pm)
2945  pm = pm*pref
2946  sfacecoordref(1) = sf*ssi(i, j, 1)*overcellarea
2947  sfacecoordref(2) = sf*ssi(i, j, 2)*overcellarea
2948  sfacecoordref(3) = sf*ssi(i, j, 3)*overcellarea
2949  govgm1 = gammainf/(gammainf-one)
2950  gm1ovg = one/govgm1
2951  viconst = two*govgm1*rgasdim
2952  if (one .gt. one/ptot) then
2953  pratio = one/ptot
2954  call pushcontrol1b(0)
2955  else
2956  call pushcontrol1b(1)
2957  pratio = one
2958  end if
2959  vilocal = sqrt(viconst*(one-pratio**gm1ovg)*ttot*tref)
2960  xc = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1, &
2961 & 1)) - refpoint(1)
2962  yc = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1, &
2963 & 2)) - refpoint(2)
2964  zc = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1, &
2965 & 3)) - refpoint(3)
2966 ! pressure forces. note that these need a *negative* and to subtract
2967 ! the reference pressure sign to be consistent with the force
2968 ! computation on the walls.
2969  call pushreal8(pm)
2970  pm = -((pm-pinf*pref)*fact*blk)
2971 ! update the pressure force and moment coefficients.
2972 ! the force integral for the center of pressure computation.
2973 ! we need the cell centers wrt origin
2974  xco = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
2975 & , 1))
2976  yco = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
2977 & , 2))
2978  zco = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
2979 & , 3))
2980 ! center of force computations. here we accumulate in the sums.
2981 ! accumulate in the sums. each force component is tracked separately
2982 ! blanking is included in the mdot multiplier for the force.
2983 ! force-x
2984 ! force-y
2985 ! force-z
2986 ! momentum forces are a little tricky. we negate because
2987 ! have to re-apply fact to massflowratelocal to undoo it, because
2988 ! we need the signed behavior of ssi to get the momentum forces correct.
2989 ! also, the sign is flipped between inflow and outflow types
2990  call pushreal8(massflowratelocal)
2991  massflowratelocal = massflowratelocal*fact/timeref*blk/cellarea*&
2992 & internalflowfact*inflowfact
2993  fx = massflowratelocal*ssi(i, j, 1)*vxm
2994  fy = massflowratelocal*ssi(i, j, 2)*vym
2995  fz = massflowratelocal*ssi(i, j, 3)*vzm
2996 ! center of force computations. here we accumulate in the sums.
2997 ! each force component is tracked separately
2998 ! blanking is included in the mdot multiplier for the force.
2999 ! force-x
3000 ! force-y
3001 ! force-z
3002  mxd = mmomd(1)
3003  myd = mmomd(2)
3004  mzd = mmomd(3)
3005  zcod = fz*cofsumfzd(3) + fy*cofsumfyd(3) + fx*cofsumfxd(3)
3006  fzd = zco*cofsumfzd(3) + yco*cofsumfzd(2) + xco*cofsumfzd(1) + yc*&
3007 & mxd - xc*myd + fmomd(3)
3008  ycod = fz*cofsumfzd(2) + fy*cofsumfyd(2) + fx*cofsumfxd(2)
3009  xcod = fz*cofsumfzd(1) + fy*cofsumfyd(1) + fx*cofsumfxd(1)
3010  fyd = zco*cofsumfyd(3) + yco*cofsumfyd(2) + xco*cofsumfyd(1) + xc*&
3011 & mzd + fmomd(2) - zc*mxd
3012  fxd = zco*cofsumfxd(3) + yco*cofsumfxd(2) + xco*cofsumfxd(1) + zc*&
3013 & myd - yc*mzd + fmomd(1)
3014  xcd = fy*mzd - fz*myd
3015  ycd = fz*mxd - fx*mzd
3016  zcd = fx*myd - fy*mxd
3017  ssid(i, j, 3) = ssid(i, j, 3) + massflowratelocal*vzm*fzd
3018  tempd0 = ssi(i, j, 3)*fzd
3019  massflowratelocald = vzm*tempd0
3020  vzmd = massflowratelocal*tempd0
3021  ssid(i, j, 2) = ssid(i, j, 2) + massflowratelocal*vym*fyd
3022  tempd0 = ssi(i, j, 2)*fyd
3023  massflowratelocald = massflowratelocald + vym*tempd0
3024  vymd = massflowratelocal*tempd0
3025  ssid(i, j, 1) = ssid(i, j, 1) + massflowratelocal*vxm*fxd
3026  tempd0 = ssi(i, j, 1)*fxd
3027  massflowratelocald = massflowratelocald + vxm*tempd0
3028  vxmd = massflowratelocal*tempd0
3029  call popreal8(massflowratelocal)
3030  tempd0 = fact*blk*internalflowfact*inflowfact*massflowratelocald/(&
3031 & timeref*cellarea)
3032  massflowratelocald = tempd0
3033  tempd = -(massflowratelocal*tempd0/(timeref*cellarea))
3034  timerefd = timerefd + cellarea*tempd
3035  cellaread = timeref*tempd
3036  fz = pm*ssi(i, j, 3)
3037  fy = pm*ssi(i, j, 2)
3038  fx = pm*ssi(i, j, 1)
3039  zcod = zcod + fz*cofsumfzd(3) + fy*cofsumfyd(3) + fx*cofsumfxd(3)
3040  ycod = ycod + fz*cofsumfzd(2) + fy*cofsumfyd(2) + fx*cofsumfxd(2)
3041  xcod = xcod + fz*cofsumfzd(1) + fy*cofsumfyd(1) + fx*cofsumfxd(1)
3042  tempd0 = fourth*zcod
3043  xxd(i, j, 3) = xxd(i, j, 3) + tempd0
3044  xxd(i+1, j, 3) = xxd(i+1, j, 3) + tempd0
3045  xxd(i, j+1, 3) = xxd(i, j+1, 3) + tempd0
3046  xxd(i+1, j+1, 3) = xxd(i+1, j+1, 3) + tempd0
3047  tempd0 = fourth*ycod
3048  xxd(i, j, 2) = xxd(i, j, 2) + tempd0
3049  xxd(i+1, j, 2) = xxd(i+1, j, 2) + tempd0
3050  xxd(i, j+1, 2) = xxd(i, j+1, 2) + tempd0
3051  xxd(i+1, j+1, 2) = xxd(i+1, j+1, 2) + tempd0
3052  tempd0 = fourth*xcod
3053  xxd(i, j, 1) = xxd(i, j, 1) + tempd0
3054  xxd(i+1, j, 1) = xxd(i+1, j, 1) + tempd0
3055  xxd(i, j+1, 1) = xxd(i, j+1, 1) + tempd0
3056  xxd(i+1, j+1, 1) = xxd(i+1, j+1, 1) + tempd0
3057  mzd = mpd(3)
3058  myd = mpd(2)
3059  fxd = zco*cofsumfxd(3) + yco*cofsumfxd(2) + xco*cofsumfxd(1) + zc*&
3060 & myd - yc*mzd + fpd(1)
3061  mxd = mpd(1)
3062  fzd = zco*cofsumfzd(3) + yco*cofsumfzd(2) + xco*cofsumfzd(1) + yc*&
3063 & mxd - xc*myd + fpd(3)
3064  fyd = zco*cofsumfyd(3) + yco*cofsumfyd(2) + xco*cofsumfyd(1) + xc*&
3065 & mzd + fpd(2) - zc*mxd
3066  xcd = xcd + fy*mzd - fz*myd
3067  ycd = ycd + fz*mxd - fx*mzd
3068  zcd = zcd + fx*myd - fy*mxd
3069  pmd = ssi(i, j, 3)*fzd + ssi(i, j, 2)*fyd + ssi(i, j, 1)*fxd
3070  ssid(i, j, 3) = ssid(i, j, 3) + pm*fzd
3071  ssid(i, j, 2) = ssid(i, j, 2) + pm*fyd
3072  ssid(i, j, 1) = ssid(i, j, 1) + pm*fxd
3073  call popreal8(pm)
3074  tempd0 = -(fact*blk*pmd)
3075  pmd = tempd0
3076  prefd = prefd - pinf*tempd0
3077  tempd0 = fourth*zcd
3078  refpointd(3) = refpointd(3) - zcd
3079  xxd(i, j, 3) = xxd(i, j, 3) + tempd0
3080  xxd(i+1, j, 3) = xxd(i+1, j, 3) + tempd0
3081  xxd(i, j+1, 3) = xxd(i, j+1, 3) + tempd0
3082  xxd(i+1, j+1, 3) = xxd(i+1, j+1, 3) + tempd0
3083  tempd0 = fourth*ycd
3084  refpointd(2) = refpointd(2) - ycd
3085  xxd(i, j, 2) = xxd(i, j, 2) + tempd0
3086  xxd(i+1, j, 2) = xxd(i+1, j, 2) + tempd0
3087  xxd(i, j+1, 2) = xxd(i, j+1, 2) + tempd0
3088  xxd(i+1, j+1, 2) = xxd(i+1, j+1, 2) + tempd0
3089  tempd0 = fourth*xcd
3090  refpointd(1) = refpointd(1) - xcd
3091  xxd(i, j, 1) = xxd(i, j, 1) + tempd0
3092  xxd(i+1, j, 1) = xxd(i+1, j, 1) + tempd0
3093  xxd(i, j+1, 1) = xxd(i, j+1, 1) + tempd0
3094  xxd(i+1, j+1, 1) = xxd(i+1, j+1, 1) + tempd0
3095  ssid(i, j, 3) = ssid(i, j, 3) + overcellarea*massflowratelocal*&
3096 & mass_nzd
3097  tempd0 = ssi(i, j, 3)*mass_nzd
3098  overcellaread = massflowratelocal*tempd0
3099  massflowratelocald = massflowratelocald + overcellarea*tempd0
3100  ssid(i, j, 2) = ssid(i, j, 2) + overcellarea*massflowratelocal*&
3101 & mass_nyd
3102  tempd0 = ssi(i, j, 2)*mass_nyd
3103  overcellaread = overcellaread + massflowratelocal*tempd0
3104  massflowratelocald = massflowratelocald + overcellarea*tempd0
3105  ssid(i, j, 1) = ssid(i, j, 1) + overcellarea*massflowratelocal*&
3106 & mass_nxd
3107  tempd0 = ssi(i, j, 1)*mass_nxd
3108  overcellaread = overcellaread + massflowratelocal*tempd0
3109  massflowratelocald = massflowratelocald + overcellarea*tempd0 + &
3110 & vilocal*mass_vid
3111  vilocald = massflowratelocal*mass_vid
3112  temp = one - pratio**gm1ovg
3113  if (viconst*(temp*(ttot*tref)) .eq. 0.0_8) then
3114  tempd0 = 0.0_8
3115  else
3116  tempd0 = viconst*vilocald/(2.0*sqrt(viconst*(temp*(ttot*tref))))
3117  end if
3118  if (pratio .le. 0.0_8 .and. (gm1ovg .eq. 0.0_8 .or. gm1ovg .ne. &
3119 & int(gm1ovg))) then
3120  pratiod = 0.0_8
3121  else
3122  pratiod = -(gm1ovg*pratio**(gm1ovg-1)*ttot*tref*tempd0)
3123  end if
3124  ttotd = ttotd + tref*temp*tempd0
3125  trefd = trefd + ttot*temp*tempd0
3126  call popcontrol1b(branch)
3127  if (branch .eq. 0) ptotd = ptotd - one*pratiod/ptot**2
3128  tempd = blk*area_ptotd
3129  vzmd = vzmd + uref*massflowratelocal*mass_vzd
3130  sfacecoordrefd(3) = sfacecoordrefd(3) - massflowratelocal*mass_vzd
3131  massflowratelocald = massflowratelocald + (uref*vzm-sfacecoordref(&
3132 & 3))*mass_vzd + (uref*vym-sfacecoordref(2))*mass_vyd + (uref*vxm-&
3133 & sfacecoordref(1))*mass_vxd + mnm*mass_mnd + pm*mass_psd + am*&
3134 & uref*mass_ad + rhom*rhoref*mass_rhod + ttot*tref*mass_ttotd + &
3135 & ptot*pref*mass_ptotd + massflowrated
3136  vymd = vymd + uref*massflowratelocal*mass_vyd
3137  sfacecoordrefd(2) = sfacecoordrefd(2) - massflowratelocal*mass_vyd
3138  vxmd = vxmd + uref*massflowratelocal*mass_vxd
3139  sfacecoordrefd(1) = sfacecoordrefd(1) - massflowratelocal*mass_vxd
3140  ssid(i, j, 3) = ssid(i, j, 3) + overcellarea*sf*sfacecoordrefd(3)
3141  overcellaread = overcellaread + ssi(i, j, 3)*sf*sfacecoordrefd(3) &
3142 & + ssi(i, j, 2)*sf*sfacecoordrefd(2) + ssi(i, j, 1)*sf*&
3143 & sfacecoordrefd(1)
3144  sfacecoordrefd(3) = 0.0_8
3145  ssid(i, j, 2) = ssid(i, j, 2) + overcellarea*sf*sfacecoordrefd(2)
3146  sfacecoordrefd(2) = 0.0_8
3147  ssid(i, j, 1) = ssid(i, j, 1) + overcellarea*sf*sfacecoordrefd(1)
3148  sfacecoordrefd(1) = 0.0_8
3149  pmd = pmd + cellarea*blk*area_psd + massflowratelocal*mass_psd
3150  cellaread = cellaread + pm*blk*area_psd + ptot*pref*tempd + blk*&
3151 & aread - overcellaread/cellarea**2
3152  ptotd = ptotd + pref*cellarea*tempd + massflowratelocal*pref*&
3153 & mass_ptotd
3154  mnmd = massflowratelocal*mass_mnd
3155  amd = massflowratelocal*uref*mass_ad - vmag*mnmd/am**2
3156  rhorefd = rhorefd + rhom*massflowratelocal*mass_rhod
3157  ttotd = ttotd + massflowratelocal*tref*mass_ttotd
3158  trefd = trefd + ttot*massflowratelocal*mass_ttotd
3159  call popreal8(pm)
3160  prefd = prefd + ptot*cellarea*tempd + ptot*massflowratelocal*&
3161 & mass_ptotd + pm*pmd
3162  pmd = pref*pmd
3163  tempd = blk*fact*massflowratelocald
3164  rhomd = massflowratelocal*rhoref*mass_rhod + vnm*mredim*tempd
3165  vnmd = rhom*mredim*tempd
3166  mredimd = mredimd + rhom*vnm*tempd
3167  call computettot_b(rhom, rhomd, vxm, vxmd, vym, vymd, vzm, vzmd, &
3168 & pm, pmd, ttot, ttotd)
3169  call computeptot_b(rhom, rhomd, vxm, vxmd, vym, vymd, vzm, vzmd, &
3170 & pm, pmd, ptot, ptotd)
3171  if (ssi(i, j, 1)**2 + ssi(i, j, 2)**2 + ssi(i, j, 3)**2 .eq. 0.0_8&
3172 & ) then
3173  tempd = 0.0_8
3174  else
3175  tempd = cellaread/(2.0*sqrt(ssi(i, j, 1)**2+ssi(i, j, 2)**2+ssi(&
3176 & i, j, 3)**2))
3177  end if
3178  ssid(i, j, 3) = ssid(i, j, 3) + 2*ssi(i, j, 3)*tempd + vzm*vnmd
3179  ssid(i, j, 2) = ssid(i, j, 2) + 2*ssi(i, j, 2)*tempd + vym*vnmd
3180  ssid(i, j, 1) = ssid(i, j, 1) + 2*ssi(i, j, 1)*tempd + vxm*vnmd
3181  vmagd = mnmd/am
3182  if (gammam*(pm/rhom) .eq. 0.0_8) then
3183  tempd = 0.0_8
3184  else
3185  tempd = gammam*amd/(rhom*2.0*sqrt(gammam*(pm/rhom)))
3186  end if
3187  pmd = pmd + tempd
3188  rhomd = rhomd - pm*tempd/rhom
3189  if (vxm**2 + vym**2 + vzm**2 .eq. 0.0_8) then
3190  tempd = 0.0_8
3191  else
3192  tempd = vmagd/(2.0*sqrt(vxm**2+vym**2+vzm**2))
3193  end if
3194  vxmd = vxmd + 2*vxm*tempd + ssi(i, j, 1)*vnmd
3195  vymd = vymd + 2*vym*tempd + ssi(i, j, 2)*vnmd
3196  vzmd = vzmd + 2*vzm*tempd + ssi(i, j, 3)*vnmd
3197  pp1d(i, j) = pp1d(i, j) + half*pmd
3198  pp2d(i, j) = pp2d(i, j) + half*pmd
3199  ww1d(i, j, irho) = ww1d(i, j, irho) + half*rhomd
3200  ww2d(i, j, irho) = ww2d(i, j, irho) + half*rhomd
3201  ww1d(i, j, ivz) = ww1d(i, j, ivz) + half*vzmd
3202  ww2d(i, j, ivz) = ww2d(i, j, ivz) + half*vzmd
3203  ww1d(i, j, ivy) = ww1d(i, j, ivy) + half*vymd
3204  ww2d(i, j, ivy) = ww2d(i, j, ivy) + half*vymd
3205  ww1d(i, j, ivx) = ww1d(i, j, ivx) + half*vxmd
3206  ww2d(i, j, ivx) = ww2d(i, j, ivx) + half*vxmd
3207  end do
3208  if (pref*rhoref .eq. 0.0_8) then
3209  tempd = 0.0_8
3210  else
3211  tempd = mredimd/(2.0*sqrt(pref*rhoref))
3212  end if
3213  prefd = prefd + rhoref*tempd
3214  rhorefd = rhorefd + pref*tempd
3215  pointrefd(3) = pointrefd(3) + lref*refpointd(3)
3216  refpointd(3) = 0.0_8
3217  pointrefd(2) = pointrefd(2) + lref*refpointd(2)
3218  refpointd(2) = 0.0_8
3219  pointrefd(1) = pointrefd(1) + lref*refpointd(1)
3220  end subroutine flowintegrationface_b
3221 
3222  subroutine flowintegrationface(isinflow, localvalues, mm)
3223  use constants
3224  use blockpointers, only : bctype, bcfaceid, bcdata, &
3226  use flowvarrefstate, only : pref, pinf, rhoref, timeref, lref, &
3228  use inputphysics, only : pointref, flowtype, rgasdim
3229  use flowutils_b, only : computeptot, computettot
3230  use bcpointers_b, only : ssi, sface, ww1, ww2, pp1, pp2, xx, gamma1,&
3231 & gamma2
3232  use utils_b, only : mynorm2
3233  implicit none
3234 ! input/output variables
3235  logical, intent(in) :: isinflow
3236  real(kind=realtype), dimension(nlocalvalues), intent(inout) :: &
3237 & localvalues
3238  integer(kind=inttype), intent(in) :: mm
3239 ! local variables
3240  real(kind=realtype) :: massflowrate, mass_ptot, mass_ttot, mass_ps, &
3241 & mass_mn, mass_a, mass_rho, mass_vx, mass_vy, mass_vz, mass_nx, &
3242 & mass_ny, mass_nz, mass_vi
3243  real(kind=realtype) :: area_ptot, area_ps
3244  real(kind=realtype) :: govgm1, gm1ovg, viconst, vilocal, pratio
3245  real(kind=realtype) :: mredim
3246  integer(kind=inttype) :: i, j, ii, blk
3247  real(kind=realtype) :: internalflowfact, inflowfact, fact, xc, xco, &
3248 & yc, yco, zc, zco, mx, my, mz
3249  real(kind=realtype) :: sf, vmag, vnm, vnmfreestreamref, vxm, vym, &
3250 & vzm, fx, fy, fz, u, v, w
3251  real(kind=realtype) :: pm, ptot, ttot, rhom, gammam, am
3252  real(kind=realtype) :: area, cellarea, overcellarea
3253  real(kind=realtype), dimension(3) :: fp, mp, fmom, mmom, refpoint, &
3254 & sfacecoordref
3255  real(kind=realtype), dimension(3) :: cofsumfx, cofsumfy, cofsumfz
3256  real(kind=realtype) :: mnm, massflowratelocal
3257  intrinsic sqrt
3258  intrinsic mod
3259  intrinsic max
3260  intrinsic min
3261  refpoint(1) = lref*pointref(1)
3262  refpoint(2) = lref*pointref(2)
3263  refpoint(3) = lref*pointref(3)
3264 ! note that these are *opposite* of force integrations. the reason
3265 ! is that we want positive mass flow into the domain and negative
3266 ! mass flow out of the domain. since the low faces have ssi
3267 ! vectors pointining into the domain, this is correct. the high
3268 ! end faces need to flip this.
3269  select case (bcfaceid(mm))
3270  case (imin, jmin, kmin)
3271  fact = one
3272  case (imax, jmax, kmax)
3273  fact = -one
3274  end select
3275 ! the sign of momentum forces are flipped for internal flows
3276  internalflowfact = one
3277  if (flowtype .eq. internalflow) internalflowfact = -one
3278  inflowfact = one
3279  if (isinflow) inflowfact = -one
3280 ! loop over the quadrilateral faces of the subface. note that
3281 ! the nodal range of bcdata must be used and not the cell
3282 ! range, because the latter may include the halo's in i and
3283 ! j-direction. the offset +1 is there, because inbeg and jnbeg
3284 ! refer to nodal ranges and not to cell ranges. the loop
3285 ! (without the ad stuff) would look like:
3286 !
3287 ! do j=(bcdata(mm)%jnbeg+1),bcdata(mm)%jnend
3288 ! do i=(bcdata(mm)%inbeg+1),bcdata(mm)%inend
3289  mredim = sqrt(pref*rhoref)
3290  fp = zero
3291  mp = zero
3292  fmom = zero
3293  mmom = zero
3294  cofsumfx = zero
3295  cofsumfy = zero
3296  cofsumfz = zero
3297  massflowrate = zero
3298  area = zero
3299  mass_ptot = zero
3300  mass_ttot = zero
3301  mass_ps = zero
3302  mass_mn = zero
3303  mass_a = zero
3304  mass_rho = zero
3305  mass_vx = zero
3306  mass_vy = zero
3307  mass_vz = zero
3308  mass_nx = zero
3309  mass_ny = zero
3310  mass_nz = zero
3311  mass_vi = zero
3312  area_ptot = zero
3313  area_ps = zero
3314 !$ad ii-loop
3315  do ii=0,(bcdata(mm)%jnend-bcdata(mm)%jnbeg)*(bcdata(mm)%inend-bcdata&
3316 & (mm)%inbeg)-1
3317  i = mod(ii, bcdata(mm)%inend - bcdata(mm)%inbeg) + bcdata(mm)%&
3318 & inbeg + 1
3319  j = ii/(bcdata(mm)%inend-bcdata(mm)%inbeg) + bcdata(mm)%jnbeg + 1
3320  if (addgridvelocities) then
3321  sf = sface(i, j)
3322  else
3323  sf = zero
3324  end if
3325  if (bcdata(mm)%iblank(i, j) .lt. 0) then
3326  blk = 0
3327  else
3328  blk = bcdata(mm)%iblank(i, j)
3329  end if
3330  vxm = half*(ww1(i, j, ivx)+ww2(i, j, ivx))
3331  vym = half*(ww1(i, j, ivy)+ww2(i, j, ivy))
3332  vzm = half*(ww1(i, j, ivz)+ww2(i, j, ivz))
3333  rhom = half*(ww1(i, j, irho)+ww2(i, j, irho))
3334  pm = half*(pp1(i, j)+pp2(i, j))
3335  gammam = half*(gamma1(i, j)+gamma2(i, j))
3336  vnm = vxm*ssi(i, j, 1) + vym*ssi(i, j, 2) + vzm*ssi(i, j, 3) - sf
3337  vmag = sqrt(vxm**2 + vym**2 + vzm**2) - sf
3338  am = sqrt(gammam*pm/rhom)
3339  mnm = vmag/am
3340  cellarea = sqrt(ssi(i, j, 1)**2 + ssi(i, j, 2)**2 + ssi(i, j, 3)**&
3341 & 2)
3342  area = area + cellarea*blk
3343  overcellarea = 1/cellarea
3344  call computeptot(rhom, vxm, vym, vzm, pm, ptot)
3345  call computettot(rhom, vxm, vym, vzm, pm, ttot)
3346  massflowratelocal = rhom*vnm*blk*fact*mredim
3347  massflowrate = massflowrate + massflowratelocal
3348 ! re-dimentionalize quantities
3349  pm = pm*pref
3350  mass_ptot = mass_ptot + ptot*massflowratelocal*pref
3351  mass_ttot = mass_ttot + ttot*massflowratelocal*tref
3352  mass_rho = mass_rho + rhom*massflowratelocal*rhoref
3353  mass_a = mass_a + am*massflowratelocal*uref
3354  mass_ps = mass_ps + pm*massflowratelocal
3355  mass_mn = mass_mn + mnm*massflowratelocal
3356  area_ptot = area_ptot + ptot*pref*cellarea*blk
3357  area_ps = area_ps + pm*cellarea*blk
3358  sfacecoordref(1) = sf*ssi(i, j, 1)*overcellarea
3359  sfacecoordref(2) = sf*ssi(i, j, 2)*overcellarea
3360  sfacecoordref(3) = sf*ssi(i, j, 3)*overcellarea
3361  mass_vx = mass_vx + (vxm*uref-sfacecoordref(1))*massflowratelocal
3362  mass_vy = mass_vy + (vym*uref-sfacecoordref(2))*massflowratelocal
3363  mass_vz = mass_vz + (vzm*uref-sfacecoordref(3))*massflowratelocal
3364  govgm1 = gammainf/(gammainf-one)
3365  gm1ovg = one/govgm1
3366  viconst = two*govgm1*rgasdim
3367  if (one .gt. one/ptot) then
3368  pratio = one/ptot
3369  else
3370  pratio = one
3371  end if
3372  vilocal = sqrt(viconst*(one-pratio**gm1ovg)*ttot*tref)
3373  mass_vi = mass_vi + vilocal*massflowratelocal
3374  mass_nx = mass_nx + ssi(i, j, 1)*overcellarea*massflowratelocal
3375  mass_ny = mass_ny + ssi(i, j, 2)*overcellarea*massflowratelocal
3376  mass_nz = mass_nz + ssi(i, j, 3)*overcellarea*massflowratelocal
3377  xc = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1, &
3378 & 1)) - refpoint(1)
3379  yc = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1, &
3380 & 2)) - refpoint(2)
3381  zc = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1, &
3382 & 3)) - refpoint(3)
3383 ! pressure forces. note that these need a *negative* and to subtract
3384 ! the reference pressure sign to be consistent with the force
3385 ! computation on the walls.
3386  pm = -((pm-pinf*pref)*fact*blk)
3387  fx = pm*ssi(i, j, 1)
3388  fy = pm*ssi(i, j, 2)
3389  fz = pm*ssi(i, j, 3)
3390 ! update the pressure force and moment coefficients.
3391  fp(1) = fp(1) + fx
3392  fp(2) = fp(2) + fy
3393  fp(3) = fp(3) + fz
3394  mx = yc*fz - zc*fy
3395  my = zc*fx - xc*fz
3396  mz = xc*fy - yc*fx
3397  mp(1) = mp(1) + mx
3398  mp(2) = mp(2) + my
3399  mp(3) = mp(3) + mz
3400 ! the force integral for the center of pressure computation.
3401 ! we need the cell centers wrt origin
3402  xco = fourth*(xx(i, j, 1)+xx(i+1, j, 1)+xx(i, j+1, 1)+xx(i+1, j+1&
3403 & , 1))
3404  yco = fourth*(xx(i, j, 2)+xx(i+1, j, 2)+xx(i, j+1, 2)+xx(i+1, j+1&
3405 & , 2))
3406  zco = fourth*(xx(i, j, 3)+xx(i+1, j, 3)+xx(i, j+1, 3)+xx(i+1, j+1&
3407 & , 3))
3408 ! center of force computations. here we accumulate in the sums.
3409 ! accumulate in the sums. each force component is tracked separately
3410 ! blanking is included in the mdot multiplier for the force.
3411 ! force-x
3412  cofsumfx(1) = cofsumfx(1) + xco*fx
3413  cofsumfx(2) = cofsumfx(2) + yco*fx
3414  cofsumfx(3) = cofsumfx(3) + zco*fx
3415 ! force-y
3416  cofsumfy(1) = cofsumfy(1) + xco*fy
3417  cofsumfy(2) = cofsumfy(2) + yco*fy
3418  cofsumfy(3) = cofsumfy(3) + zco*fy
3419 ! force-z
3420  cofsumfz(1) = cofsumfz(1) + xco*fz
3421  cofsumfz(2) = cofsumfz(2) + yco*fz
3422  cofsumfz(3) = cofsumfz(3) + zco*fz
3423 ! momentum forces are a little tricky. we negate because
3424 ! have to re-apply fact to massflowratelocal to undoo it, because
3425 ! we need the signed behavior of ssi to get the momentum forces correct.
3426 ! also, the sign is flipped between inflow and outflow types
3427  massflowratelocal = massflowratelocal*fact/timeref*blk/cellarea*&
3428 & internalflowfact*inflowfact
3429  fx = massflowratelocal*ssi(i, j, 1)*vxm
3430  fy = massflowratelocal*ssi(i, j, 2)*vym
3431  fz = massflowratelocal*ssi(i, j, 3)*vzm
3432  fmom(1) = fmom(1) + fx
3433  fmom(2) = fmom(2) + fy
3434  fmom(3) = fmom(3) + fz
3435  mx = yc*fz - zc*fy
3436  my = zc*fx - xc*fz
3437  mz = xc*fy - yc*fx
3438  mmom(1) = mmom(1) + mx
3439  mmom(2) = mmom(2) + my
3440  mmom(3) = mmom(3) + mz
3441 ! center of force computations. here we accumulate in the sums.
3442 ! each force component is tracked separately
3443 ! blanking is included in the mdot multiplier for the force.
3444 ! force-x
3445  cofsumfx(1) = cofsumfx(1) + xco*fx
3446  cofsumfx(2) = cofsumfx(2) + yco*fx
3447  cofsumfx(3) = cofsumfx(3) + zco*fx
3448 ! force-y
3449  cofsumfy(1) = cofsumfy(1) + xco*fy
3450  cofsumfy(2) = cofsumfy(2) + yco*fy
3451  cofsumfy(3) = cofsumfy(3) + zco*fy
3452 ! force-z
3453  cofsumfz(1) = cofsumfz(1) + xco*fz
3454  cofsumfz(2) = cofsumfz(2) + yco*fz
3455  cofsumfz(3) = cofsumfz(3) + zco*fz
3456  end do
3457 ! increment the local values array with what we computed here
3458  localvalues(imassflow) = localvalues(imassflow) + massflowrate
3459  localvalues(iarea) = localvalues(iarea) + area
3460  localvalues(imassrho) = localvalues(imassrho) + mass_rho
3461  localvalues(imassa) = localvalues(imassa) + mass_a
3462  localvalues(imassptot) = localvalues(imassptot) + mass_ptot
3463  localvalues(imassttot) = localvalues(imassttot) + mass_ttot
3464  localvalues(imassps) = localvalues(imassps) + mass_ps
3465  localvalues(imassmn) = localvalues(imassmn) + mass_mn
3466  localvalues(ifp:ifp+2) = localvalues(ifp:ifp+2) + fp
3467  localvalues(iflowfm:iflowfm+2) = localvalues(iflowfm:iflowfm+2) + &
3468 & fmom
3469  localvalues(iflowmp:iflowmp+2) = localvalues(iflowmp:iflowmp+2) + mp
3470  localvalues(iflowmm:iflowmm+2) = localvalues(iflowmm:iflowmm+2) + &
3471 & mmom
3472  localvalues(icoforcex:icoforcex+2) = localvalues(icoforcex:icoforcex&
3473 & +2) + cofsumfx
3474  localvalues(icoforcey:icoforcey+2) = localvalues(icoforcey:icoforcey&
3475 & +2) + cofsumfy
3476  localvalues(icoforcez:icoforcez+2) = localvalues(icoforcez:icoforcez&
3477 & +2) + cofsumfz
3478  localvalues(iareaptot) = localvalues(iareaptot) + area_ptot
3479  localvalues(iareaps) = localvalues(iareaps) + area_ps
3480  localvalues(imassvx) = localvalues(imassvx) + mass_vx
3481  localvalues(imassvy) = localvalues(imassvy) + mass_vy
3482  localvalues(imassvz) = localvalues(imassvz) + mass_vz
3483  localvalues(imassnx) = localvalues(imassnx) + mass_nx
3484  localvalues(imassny) = localvalues(imassny) + mass_ny
3485  localvalues(imassnz) = localvalues(imassnz) + mass_nz
3486  localvalues(imassvi) = localvalues(imassvi) + mass_vi
3487  end subroutine flowintegrationface
3488 ! ----------------------------------------------------------------------
3489 ! |
3490 ! no tapenade routine below this line |
3491 ! |
3492 ! ----------------------------------------------------------------------
3493 
3494 end module surfaceintegrations_b
3495 
Definition: BCData.F90:1
logical addgridvelocities
integer(kind=inttype) spectralsol
type(viscsubfacetype), dimension(:), pointer viscsubface
type(bcdatatype), dimension(:), pointer bcdatad
integer(kind=inttype), dimension(:), pointer bcfaceid
integer(kind=inttype), dimension(:), pointer bctype
type(viscsubfacetype), dimension(:), pointer viscsubfaced
integer(kind=inttype), dimension(:), pointer inbeg
integer(kind=inttype), parameter costfuncaxismoment
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmavgptot
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforceyviscous
Definition: constants.F90:348
integer(kind=inttype), parameter isepavg
Definition: constants.F90:455
integer(kind=inttype), parameter imassvz
Definition: constants.F90:455
integer(kind=inttype), parameter iareaps
Definition: constants.F90:455
real(kind=realtype), parameter degtorad
Definition: constants.F90:89
real(kind=realtype), parameter zero
Definition: constants.F90:71
integer(kind=inttype), parameter costfuncforceycoefviscous
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforceypressure
Definition: constants.F90:348
integer(kind=inttype), parameter costfunccoforcexx
Definition: constants.F90:348
integer(kind=inttype), parameter imax
Definition: constants.F90:293
integer(kind=inttype), parameter costfuncforcexmomentum
Definition: constants.F90:348
integer(kind=inttype), parameter iflowmp
Definition: constants.F90:455
integer(kind=inttype), parameter imassnx
Definition: constants.F90:455
integer(kind=inttype), parameter kmin
Definition: constants.F90:296
integer(kind=inttype), parameter costfunccoforcexz
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncdragviscous
Definition: constants.F90:348
integer(kind=inttype), parameter imassflow
Definition: constants.F90:455
integer(kind=inttype), parameter jmax
Definition: constants.F90:295
integer(kind=inttype), parameter costfuncforcexcoefpressure
Definition: constants.F90:348
integer(kind=inttype), parameter icoforcez
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncliftcoefpressure
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncdragcoefviscous
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmdot
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncdragcoef
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncdragcoefmomentum
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncarea
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcexpressure
Definition: constants.F90:348
integer(kind=inttype), parameter costfunccoforceyy
Definition: constants.F90:348
integer(kind=inttype), parameter costfunccavitation
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmomzcoef
Definition: constants.F90:348
integer(kind=inttype), parameter imassptot
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncmavga
Definition: constants.F90:348
integer(kind=inttype), parameter iflowfm
Definition: constants.F90:455
integer(kind=inttype), parameter icperror2
Definition: constants.F90:455
integer(kind=inttype), parameter costfunccperror2
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncliftmomentum
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcezcoefviscous
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncaavgps
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcexviscous
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncaavgptot
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncflowpower
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforceymomentum
Definition: constants.F90:348
integer, parameter irho
Definition: constants.F90:34
integer(kind=inttype), parameter costfuncliftviscous
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcex
Definition: constants.F90:348
integer(kind=inttype), parameter nswalladiabatic
Definition: constants.F90:260
integer(kind=inttype), parameter costfuncliftpressure
Definition: constants.F90:348
integer(kind=inttype), parameter imassnz
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncforceycoefpressure
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmomxcoef
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcezmomentum
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcezcoefmomentum
Definition: constants.F90:348
integer(kind=inttype), parameter imp
Definition: constants.F90:455
integer, parameter ivx
Definition: constants.F90:35
integer(kind=inttype), parameter costfuncmomz
Definition: constants.F90:348
integer(kind=inttype), parameter imassa
Definition: constants.F90:455
integer(kind=inttype), parameter ipower
Definition: constants.F90:455
integer(kind=inttype), parameter ifv
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncsepsensorksarea
Definition: constants.F90:348
integer(kind=inttype), parameter imassny
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncmomy
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmavgvy
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmomx
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcez
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmavgvx
Definition: constants.F90:348
integer(kind=inttype), parameter costfunccoforcexy
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncdragmomentum
Definition: constants.F90:348
integer(kind=inttype), parameter isepsensorarea
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncforcexcoef
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmavgvi
Definition: constants.F90:348
integer(kind=inttype), parameter icoforcex
Definition: constants.F90:455
integer(kind=inttype), parameter costfunccoforceyx
Definition: constants.F90:348
real(kind=realtype), parameter one
Definition: constants.F90:72
integer(kind=inttype), parameter costfuncforcexcoefmomentum
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmavgps
Definition: constants.F90:348
integer(kind=inttype), parameter iflowmm
Definition: constants.F90:455
integer(kind=inttype), parameter imassvy
Definition: constants.F90:455
integer(kind=inttype), parameter costfunccoforceyz
Definition: constants.F90:348
real(kind=realtype), parameter half
Definition: constants.F90:80
integer(kind=inttype), parameter costfunccofliftx
Definition: constants.F90:348
integer(kind=inttype), parameter costfunccoforcezz
Definition: constants.F90:348
integer(kind=inttype), parameter costfunccpmin
Definition: constants.F90:348
integer(kind=inttype), parameter imassvx
Definition: constants.F90:455
integer(kind=inttype), parameter imassrho
Definition: constants.F90:455
integer(kind=inttype), parameter imin
Definition: constants.F90:292
integer(kind=inttype), parameter costfunccoflifty
Definition: constants.F90:348
integer(kind=inttype), parameter imassmn
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncforcezcoefpressure
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmavgmn
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforceycoef
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncliftcoefmomentum
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcey
Definition: constants.F90:348
integer(kind=inttype), parameter icoforcey
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncdrag
Definition: constants.F90:348
integer, parameter ivz
Definition: constants.F90:37
integer(kind=inttype), parameter iarea
Definition: constants.F90:455
integer(kind=inttype), parameter costfunccofliftz
Definition: constants.F90:348
integer(kind=inttype), parameter imassvi
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncforcexcoefviscous
Definition: constants.F90:348
integer(kind=inttype), parameter iaxismoment
Definition: constants.F90:455
real(kind=realtype), parameter two
Definition: constants.F90:73
integer(kind=inttype), parameter costfuncsepsensoravgz
Definition: constants.F90:348
integer(kind=inttype), parameter imv
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncdragcoefpressure
Definition: constants.F90:348
integer(kind=inttype), parameter isepsensorksarea
Definition: constants.F90:455
integer(kind=inttype), parameter imassps
Definition: constants.F90:455
real(kind=realtype), parameter fourth
Definition: constants.F90:82
integer(kind=inttype), parameter isepsensor
Definition: constants.F90:455
integer(kind=inttype), parameter nswallisothermal
Definition: constants.F90:261
integer(kind=inttype), parameter costfunclift
Definition: constants.F90:348
integer(kind=inttype), parameter costfunccoforcezy
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmavgttot
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncliftcoef
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmomycoef
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncsepsensoravgy
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmavgvz
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncliftcoefviscous
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncsepsensoravgx
Definition: constants.F90:348
integer(kind=inttype), parameter icpmin
Definition: constants.F90:455
integer(kind=inttype), parameter costfunccoforcezx
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcezpressure
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforcezviscous
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncmavgrho
Definition: constants.F90:348
integer(kind=inttype), parameter kmax
Definition: constants.F90:297
integer, parameter ivy
Definition: constants.F90:36
integer(kind=inttype), parameter costfuncsepsensor
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncsepsensorks
Definition: constants.F90:348
integer(kind=inttype), parameter isepsensorks
Definition: constants.F90:455
integer(kind=inttype), parameter icavitation
Definition: constants.F90:455
integer(kind=inttype), parameter imassttot
Definition: constants.F90:455
integer(kind=inttype), parameter jmin
Definition: constants.F90:294
integer(kind=inttype), parameter costfuncforcezcoef
Definition: constants.F90:348
integer(kind=inttype), parameter internalflow
Definition: constants.F90:120
integer(kind=inttype), parameter ifp
Definition: constants.F90:455
integer(kind=inttype), parameter costfuncdragpressure
Definition: constants.F90:348
integer(kind=inttype), parameter costfuncforceycoefmomentum
Definition: constants.F90:348
integer(kind=inttype), parameter iareaptot
Definition: constants.F90:455
subroutine computeptot(rho, u, v, w, p, ptot)
subroutine computeptot_b(rho, rhod, u, ud, v, vd, w, wd, p, pd, ptot, ptotd)
subroutine getdirvector(refdirection, alpha, beta, winddirection, liftindex)
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) sepsensorsharpness
Definition: inputParam.F90:307
real(kind=realtype) cavsensoroffset
Definition: inputParam.F90:309
real(kind=realtype) cavsensorsharpness
Definition: inputParam.F90:310
logical computesepsensorks
Definition: inputParam.F90:303
real(kind=realtype) sepsensoroffset
Definition: inputParam.F90:304
real(kind=realtype) sepsensorkssharpness
Definition: inputParam.F90:308
real(kind=realtype) sepsensorksphi
Definition: inputParam.F90:306
real(kind=realtype) sepsensorksoffset
Definition: inputParam.F90:305
integer(kind=inttype) cavexponent
Definition: inputParam.F90:311
logical computecavitation
Definition: inputParam.F90:312
real(kind=realtype) cpmin_rho
Definition: inputParam.F90:606
real(kind=realtype) sepsenmaxrho
Definition: inputParam.F90:608
integer(kind=inttype) equations
Definition: inputParam.F90:583
real(kind=realtype), dimension(:), allocatable sepsenmaxfamily
Definition: inputParam.F90:609
real(kind=realtype) betad
Definition: inputParam.F90:612
real(kind=realtype), dimension(3) liftdirectiond
Definition: inputParam.F90:614
real(kind=realtype), dimension(3) pointref
Definition: inputParam.F90:602
real(kind=realtype), dimension(3, 2) momentaxis
Definition: inputParam.F90:603
real(kind=realtype), dimension(3) dragdirectiond
Definition: inputParam.F90:615
real(kind=realtype), dimension(3) pointrefd
Definition: inputParam.F90:616
integer(kind=inttype) liftindex
Definition: inputParam.F90:592
real(kind=realtype), dimension(3) dragdirection
Definition: inputParam.F90:601
real(kind=realtype), dimension(3) veldirfreestreamd
Definition: inputParam.F90:613
real(kind=realtype) alphad
Definition: inputParam.F90:612
real(kind=realtype) beta
Definition: inputParam.F90:591
real(kind=realtype), dimension(:), allocatable cpmin_family
Definition: inputParam.F90:607
real(kind=realtype) lengthref
Definition: inputParam.F90:598
real(kind=realtype) machcoef
Definition: inputParam.F90:593
real(kind=realtype) cavitationnumber
Definition: inputParam.F90:605
real(kind=realtype), dimension(3) liftdirection
Definition: inputParam.F90:600
real(kind=realtype) machcoefd
Definition: inputParam.F90:618
integer(kind=inttype) flowtype
Definition: inputParam.F90:583
real(kind=realtype) surfaceref
Definition: inputParam.F90:598
real(kind=realtype) rgasdim
Definition: inputParam.F90:595
real(kind=realtype), dimension(3) veldirfreestream
Definition: inputParam.F90:599
real(kind=realtype) alpha
Definition: inputParam.F90:591
integer(kind=inttype) ntimeintervalsspectral
Definition: inputParam.F90:645
integer, parameter realtype
Definition: precision.F90:112
subroutine getcostfunctions(globalvals, funcvalues)
subroutine wallintegrationface_b(localvalues, localvaluesd, mm)
subroutine ksaggregationfunction_b(g, gd, max_g, g_rho, ks_g, ks_gd)
subroutine wallintegrationface(localvalues, mm)
subroutine getcostfunctions_b(globalvals, globalvalsd, funcvalues, funcvaluesd)
subroutine flowintegrationface(isinflow, localvalues, mm)
subroutine ksaggregationfunction(g, max_g, g_rho, ks_g)
subroutine flowintegrationface_b(isinflow, localvalues, localvaluesd, mm)
real(kind=realtype) function mynorm2(x)
Definition: utils_b.f90:1482
subroutine computetsderivatives(force, moment, coef0, dcdalpha, dcdalphadot, dcdq, dcdqdot)
Definition: utils_b.f90:1030