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