Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RFLU_ComputeEnerDissOLES.F90
Go to the documentation of this file.
1 ! *********************************************************************
2 ! * Rocstar Simulation Suite *
3 ! * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4 ! * *
5 ! * Illinois Rocstar LLC *
6 ! * Champaign, IL *
7 ! * www.illinoisrocstar.com *
8 ! * sales@illinoisrocstar.com *
9 ! * *
10 ! * License: See LICENSE file in top level of distribution package or *
11 ! * http://opensource.org/licenses/NCSA *
12 ! *********************************************************************
13 ! *********************************************************************
14 ! * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15 ! * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16 ! * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17 ! * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18 ! * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19 ! * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20 ! * Arising FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21 ! * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22 ! *********************************************************************
23 !******************************************************************************
24 !
25 ! Purpose: Compute kinetic energy and dissipation for use in optimal LES
26 ! weight computation.
27 !
28 ! Description: None.
29 !
30 ! Input:
31 ! region Region for which energy and dissipation is to be computed
32 !
33 ! Output: None.
34 !
35 ! Notes:
36 ! 1. At present, works only for single region
37 !
38 !******************************************************************************
39 !
40 ! $Id: RFLU_ComputeEnerDissOLES.F90,v 1.5 2008/12/06 08:44:29 mtcampbe Exp $
41 !
42 ! Copyright: (c) 2002 by the University of Illinois
43 !
44 !******************************************************************************
45 
46 SUBROUTINE rflu_computeenerdissoles(region)
47 
48  USE moddatatypes
49  USE moderror
50  USE modglobal, ONLY: t_global
51  USE moddatastruct, ONLY: t_region
52  USE modparameters
53  USE modtools, ONLY: makenonzero
54 
55  USE rflu_modoles
56 
57  IMPLICIT NONE
58 
59 ! ... parameters
60  TYPE(t_region) :: region
61 
62 ! ... loop variables
63  INTEGER :: ic,ifc,iv1,iv2
64 
65 ! ... local variables
66  CHARACTER(CHRLEN) :: rcsidentstring
67  INTEGER :: a,c1g,c2g,d,errorflag,hloc1,ic1l,ic2l,ifcp,j,l,ncells,nfaces,vloc1
68  INTEGER, DIMENSION(:), POINTER :: f2fpoles
69  INTEGER, DIMENSION(:,:), POINTER :: fsoles
70  REAL(RFREAL) :: avgfac,corr,eneroles,numer,sum1,sum2,sum3,term,uavg,var, &
71  vavg,wavg
72  REAL(RFREAL), DIMENSION(:), POINTER :: vol
73  REAL(RFREAL), DIMENSION(:,:), POINTER :: cv
74  REAL(RFREAL), DIMENSION(:,:,:), ALLOCATABLE :: int2oles
75  REAL(RFREAL), DIMENSION(:,:,:), POINTER :: int20oles,int21oles
76  TYPE(t_global), POINTER :: global
77 
78 !******************************************************************************
79 
80  rcsidentstring = '$RCSfile: RFLU_ComputeEnerDissOLES.F90,v $ $Revision: 1.5 $'
81 
82  global => region%global
83 
84  CALL registerfunction(global,'RFLU_ComputeEnerDissOLES',&
85  'RFLU_ComputeEnerDissOLES.F90')
86 
87 ! ******************************************************************************
88 ! Start, check that have primitive variables
89 ! ******************************************************************************
90 
91  IF ( region%mixt%cvState == cv_mixt_state_cons ) THEN
92  CALL errorstop(global,err_cv_state_invalid,__line__)
93  END IF ! region
94 
95 ! ******************************************************************************
96 ! Set pointers and variables
97 ! ******************************************************************************
98 
99  vol => region%grid%vol
100  cv => region%mixt%cv
101 
102  eneroles = global%enerOLES
103 
104  fsoles => region%grid%fsOLES
105  f2fpoles => region%grid%f2fpOLES
106 
107  int20oles => region%grid%int20OLES
108  int21oles => region%grid%int21OLES
109 
110  ncells = region%grid%nCells
111  nfaces = region%grid%nFaces
112  avgfac = 1.0_rfreal/REAL(ncells,kind=rfreal)
113 
114 ! ******************************************************************************
115 ! Compute kinetic energy (average over cells)
116 ! ******************************************************************************
117 
118  eneroles = 0.0_rfreal
119 
120  DO ic = 1,ncells
121  eneroles = eneroles + cv(cv_mixt_xvel,ic)*cv(cv_mixt_xvel,ic) &
122  + cv(cv_mixt_yvel,ic)*cv(cv_mixt_yvel,ic) &
123  + cv(cv_mixt_zvel,ic)*cv(cv_mixt_zvel,ic)
124  END DO ! ic
125 
126  global%enerOLES = avgfac*0.5_rfreal*eneroles
127 
128 ! DEBUG
129  uavg = 0.0_rfreal
130  vavg = 0.0_rfreal
131  wavg = 0.0_rfreal
132 
133  DO ic = 1,ncells
134  uavg = uavg + cv(cv_mixt_xvel,ic)*cv(cv_mixt_xvel,ic)
135  vavg = vavg + cv(cv_mixt_yvel,ic)*cv(cv_mixt_yvel,ic)
136  wavg = wavg + cv(cv_mixt_zvel,ic)*cv(cv_mixt_zvel,ic)
137  END DO ! ic
138 
139  uavg = avgfac*uavg
140  vavg = avgfac*vavg
141  wavg = avgfac*wavg
142 
143  global%uVarOLES = uavg
144  global%vVarOLES = vavg
145  global%wVarOLES = wavg
146 ! END DEBUG
147 
148 ! ******************************************************************************
149 ! Compute dissipation rate
150 ! ******************************************************************************
151 
152  ncells = SIZE(region%grid%fsOLES,1)
153  avgfac = 3.0_rfreal/REAL(nfaces,kind=rfreal)
154 
155  ALLOCATE(int2oles(3,3*ncells,3*ncells),stat=errorflag)
156  global%error = errorflag
157  IF ( global%error /= err_none ) THEN
158  CALL errorstop(global,err_allocate,__line__,'int2OLES')
159  END IF ! global%error
160 
161  int2oles(:,:,:) = 0.0_rfreal
162 
163 ! ==============================================================================
164 ! Compute integral through loop over faces
165 ! ==============================================================================
166 
167  DO ifc = 1,nfaces
168  ifcp = f2fpoles(ifc) ! get prototype face
169 
170 ! ------------------------------------------------------------------------------
171 ! Loop over cells
172 ! ------------------------------------------------------------------------------
173 
174  DO ic1l = 1,ncells
175  c1g = fsoles(ic1l,ifc)
176  d = ic1l
177 
178  DO ic2l = 1,ncells
179  c2g = fsoles(ic2l,ifc)
180  a = ic2l
181 
182  term = vol(c1g)*vol(c2g)
183 
184 ! ----- Loop over velocity components ------------------------------------------
185 
186  DO iv1 = 1,3
187  l = iv1
188 
189  DO iv2 = 1,3
190  j = iv2
191 
192 ! --------- Compute correlation
193 
194  corr = term*cv(iv1+1,c1g)*cv(iv2+1,c2g)
195 
196 ! --------- Determine storage location for correlation
197 
198  vloc1 = rflu_geti1posoles(l,d)
199  hloc1 = rflu_getlposoles(j,a)
200 
201 ! --------- Store correlation
202 
203  int2oles(ifcp,vloc1,hloc1) = int2oles(ifcp,vloc1,hloc1) + corr
204 
205  END DO ! iv2
206  END DO ! iv1
207 
208  END DO ! icl2
209  END DO ! icl1
210 
211  END DO ! ifcp
212 
213 ! ==============================================================================
214 ! Normalize and average integrals
215 ! ==============================================================================
216 
217  int2oles(:,:,:) = avgfac*int2oles(:,:,:)
218 
219 ! ==============================================================================
220 ! Attempt to extract dissipation from I20 and I21
221 ! ==============================================================================
222 
223  sum1 = 0.0_rfreal
224  sum2 = 0.0_rfreal
225  sum3 = 0.0_rfreal
226 
227  DO ifcp = 1,3
228 
229  DO ic1l = 1,ncells
230  d = ic1l
231 
232  DO ic2l = 1,ncells
233  a = ic2l
234 
235 ! 1x1x2 stencil
236  IF ( ic1l /= ic2l ) THEN
237 ! 1x1x4 stencil, innermost cells - should give the same as 1x1x2
238 ! IF ( (ic1l == 2 .OR. ic1l == 3) .AND. (ic2l == 3 .OR. ic2l == 2) .AND. &
239 ! (ic1l /= ic2l) ) THEN
240 ! 1x1x4 stencil, outermost cells
241 ! IF ( (ic1l == 1 .OR. ic1l == 4) .AND. (ic2l == 4 .OR. ic2l == 1) .AND. &
242 ! (ic1l /= ic2l) ) THEN
243 ! 1x1x6 stencil, innermost cells
244 ! IF ( (ic1l == 3 .OR. ic1l == 4) .AND. (ic2l == 4 .OR. ic2l == 3) .AND. &
245 ! (ic1l /= ic2l) ) THEN
246 ! 1x1x6 stencil, 2nd-innermost cells
247 ! IF ( (ic1l == 2 .OR. ic1l == 5) .AND. (ic2l == 5 .OR. ic2l == 2) .AND. &
248 ! (ic1l /= ic2l) ) THEN
249 ! 1x1x6 stencil, outermost cells
250 ! IF ( (ic1l == 1 .OR. ic1l == 6) .AND. (ic2l == 6 .OR. ic2l == 1) .AND. &
251 ! (ic1l /= ic2l) ) THEN
252 ! 1x1x8 stencil, innermost cells
253 ! IF ( (ic1l == 4 .OR. ic1l == 5) .AND. (ic2l == 5 .OR. ic2l == 4) .AND. &
254 ! (ic1l /= ic2l) ) THEN
255 ! 1x1x8 stencil, 2nd-innermost cells
256 ! IF ( (ic1l == 3 .OR. ic1l == 6) .AND. (ic2l == 6 .OR. ic2l == 3) .AND. &
257 ! (ic1l /= ic2l) ) THEN
258 ! 1x1x8 stencil, 3rd-innermost cells
259 ! IF ( (ic1l == 2 .OR. ic1l == 7) .AND. (ic2l == 7 .OR. ic2l == 2) .AND. &
260 ! (ic1l /= ic2l) ) THEN
261 ! 1x1x8 stencil, outermost cells
262 ! IF ( (ic1l == 1 .OR. ic1l == 8) .AND. (ic2l == 8 .OR. ic2l == 1) .AND. &
263 ! (ic1l /= ic2l) ) THEN
264  DO iv1 = 1,3
265  l = iv1
266 
267  iv2 = iv1
268  j = iv2
269 
270  vloc1 = rflu_geti1posoles(l,d)
271  hloc1 = rflu_getlposoles(j,a)
272 
273  sum1 = sum1 + int2oles(ifcp,vloc1,hloc1)
274  sum2 = sum2 + int20oles(ifcp,vloc1,hloc1)
275  sum3 = sum3 + int21oles(ifcp,vloc1,hloc1)
276  END DO ! iv1
277  END IF ! ic1l
278 
279  END DO ! ic2l
280  END DO ! ic1l
281 
282  END DO ! ifcp
283 
284 ! NOTE: Assume that rhoOLES has a constant value throughout solution region, so
285 ! use rhoOLES(1). This will need to be modified if the grids become non-uniform
286 
287  var = 2.0_rfreal*global%enerOLES/3.0_rfreal
288  numer = sum1/region%grid%deltaOLES**6 - var*sum2
289  global%dissOLES = (max(numer/sum3,tiny(1.0_rfreal)))**(3.0_rfreal/2.0_rfreal)/ &
290  region%grid%rhoOLES(1)
291 
292  WRITE(*,'(3(2X,E15.8))') sum1/region%grid%deltaOLES**6,var*sum2,sum3
293  WRITE(71,'(4(2X,E15.8))') global%currentTime,sum1/region%grid%deltaOLES**6, &
294  var*sum2,sum3
295 
296 ! DEBUG
297  WRITE(*,'(5(2X,E15.8))') global%enerOLES,global%dissOLES, &
298  uavg/(makenonzero(3.0_rfreal*var)), &
299  vavg/(makenonzero(3.0_rfreal*var)), &
300  wavg/(makenonzero(3.0_rfreal*var))
301 ! END DEBUG
302 
303 
304  DEALLOCATE(int2oles,stat=errorflag)
305  global%error = errorflag
306  IF ( global%error /= err_none ) THEN
307  CALL errorstop(global,err_deallocate,__line__,'int2OLES')
308  END IF ! global%error
309 
310 ! ******************************************************************************
311 ! End
312 ! ******************************************************************************
313 
314  CALL deregisterfunction(global)
315 
316 END SUBROUTINE rflu_computeenerdissoles
317 
318 !******************************************************************************
319 !
320 ! RCS Revision history:
321 !
322 ! $Log: RFLU_ComputeEnerDissOLES.F90,v $
323 ! Revision 1.5 2008/12/06 08:44:29 mtcampbe
324 ! Updated license.
325 !
326 ! Revision 1.4 2008/11/19 22:17:42 mtcampbe
327 ! Added Illinois Open Source License/Copyright
328 !
329 ! Revision 1.3 2004/01/22 16:04:33 haselbac
330 ! Changed declaration to eliminate warning on ALC
331 !
332 ! Revision 1.2 2002/10/08 15:49:29 haselbac
333 ! {IO}STAT=global%error replaced by {IO}STAT=errorFlag - SGI problem
334 !
335 ! Revision 1.1 2002/09/09 15:39:57 haselbac
336 ! Initial revision
337 !
338 !******************************************************************************
339 
340 
341 
342 
343 
344 
345 
const NT & d
Vector_n max(const Array_n_const &v1, const Array_n_const &v2)
Definition: Vector_n.h:354
subroutine registerfunction(global, funName, fileName)
Definition: ModError.F90:449
**********************************************************************Rocstar Simulation Suite Illinois Rocstar LLC All rights reserved ****Illinois Rocstar LLC IL **www illinoisrocstar com **sales illinoisrocstar com WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **Arising OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE **********************************************************************INTERFACE SUBROUTINE ic
INTEGER function, public rflu_geti1posoles(l, d)
INTEGER function, public rflu_getlposoles(j, a)
IndexType nfaces() const
Definition: Mesh.H:641
subroutine rflu_computeenerdissoles(region)
j indices j
Definition: Indexing.h:6
subroutine errorstop(global, errorCode, errorLine, addMessage)
Definition: ModError.F90:483
subroutine deregisterfunction(global)
Definition: ModError.F90:469
RT a() const
Definition: Line_2.h:140
real(rfreal) function makenonzero(x)
Definition: ModTools.F90:85