integration_example.usr 13.4 KB
Newer Older
Cody Permann's avatar
Cody Permann committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
c-----------------------------------------------------------------------
C
C  USER SPECIFIED ROUTINES:
C
C     - boundary conditions
C     - initial conditions
C     - variable properties
C     - local acceleration for fluid (a)
C     - forcing function for passive scalar (q)
C     - general purpose routine for checking errors etc.
C
c-----------------------------------------------------------------------
      subroutine uservp (ix,iy,iz,eg)
      include 'SIZE'
      include 'TOTAL'
      include 'NEKUSE'
      integer e,f,eg
      udiff =0.
      utrans=0.
      return
      end
c-----------------------------------------------------------------------
      subroutine userf  (ix,iy,iz,eg)
      include 'SIZE'
      include 'TOTAL'
      include 'NEKUSE'
      integer e,f,eg
      ffx=0.0
      ffy=0.0
      ffz=0.0     
      return
      end
c-----------------------------------------------------------------------
      subroutine userq  (ix,iy,iz,eg)
      include 'SIZE'
      include 'TOTAL'
      include 'NEKUSE'

      integer e,f,eg
c     e = gllel(eg)

      qvol   = 0.0

      return
      end
c-----------------------------------------------------------------------
      subroutine userchk
      include 'SIZE'
      include 'TOTAL'
50 51 52 53 54 55 56
      parameter (nl_max=100)
      parameter (nf_max=100)
      common/expansion_tdata/n_legendre, m_fourier
      common/expansion_tcoef/coeff_tij(nl_max,nf_max)
      common/expansion_fcoef/coeff_fij(nl_max,nf_max)
      common/expansion_recon/flux_recon(lx1,ly1,lz1,lelt)
      common/test_passing/ flux_moose, temp_nek 
Cody Permann's avatar
Cody Permann committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
      real sint, sint1, sarea, sarea1, wtmp
      integer e, f 

      n1=nelt*lx1*ly1*lz1
      n2=nelt*lx2*ly2*lz2

      pmin=glmin(pr,n2)
      pmax=glmax(pr,n2)
      wmin=glmin(vz,n1)
      wmax=glmax(vz,n1)
      tmin=glmin(t,n1)
      tmax=glmax(t,n1)

      ifflow=.false. 

      sint1=0.0
      sarea1=0.0

      do e=1,lelt
        do f=1,6
          call surface_int(sint,sarea,t,e,f)
          if (cbc(f,e,1).eq.'W  ') then
           sint1=sint1+sint  
           sarea1=sarea1+sarea
          endif          
         enddo 
      enddo

      call  gop(sint1,wtmp,'+  ',1)
      call  gop(sarea1,wtmp,'+  ',1)

      temp_nek=sint1/sarea1
      
      if (nid.eq.0) then
         write(6,*)"*** Temperature: ",tmin," - ",tmax
92
         write(6,*)"*** Average Temperature: ",temp_nek
Cody Permann's avatar
Cody Permann committed
93 94
      endif

95 96
c     Will this be overwritten -----------------
      write(6,*)"*** Setting polynomial orders ..." 
Elia Merzari's avatar
Elia Merzari committed
97 98
      n_legendre=5
      m_fourier=2
99 100 101 102 103 104 105 106 107 108 109
c-----------------------------------------------

c This is for testing -----------
c      call flux_reconstruction()
c      call nek_expansion()
c      call nek_diag()
c      if (nid.eq.0) write(6,*)" *** Expansion done"
c      call nek_testp() 
c      call exitt()
c--------------------------------

110 111 112 113 114 115 116 117
c This is to test coefficients with MOOSE --
c      do i0=1,n_legendre
c        do j0=1,m_fourier
c        if (nid.eq.0) write(6,*)"C(",i0,",",j0,")=",
c     &      coeff_fij(i0,j0)
c        enddo 
c      enddo
c------------------------------------------
Cody Permann's avatar
Cody Permann committed
118 119 120 121 122 123 124 125 126
      return
      end
c-----------------------------------------------------------------------
      subroutine userbc (ix,iy,iz,iside,ieg)
      include 'SIZE'
      include 'TOTAL'
      include 'NEKUSE'
      
      common/test_passing/ flux_moose, temp_nek
127
      common/expansion_recon/flux_recon(lx1,ly1,lz1,lelt)
Cody Permann's avatar
Cody Permann committed
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

      integer e,ieg
      real ucx, ucy, ucz, ucy_e, yy 

      e=gllel(ieg)

      zz  = zm1(ix,iy,iz,e)
      xx  = xm1(ix,iy,iz,e)
      yy  = ym1(ix,iy,iz,e)
      rr  = sqrt(xx**2 + yy**2)

      ux = 0.0
      uy = 0.0
      uz = 1.0
      temp = 0.0
143
      flux = flux_recon(ix,iy,iz,e) !flux_moose
Cody Permann's avatar
Cody Permann committed
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272

      return
      end
c-----------------------------------------------------------------------
      subroutine useric (ix,iy,iz,ieg)
      include 'SIZE'
      include 'TOTAL'
      include 'NEKUSE'

      integer idum, e
      save    idum
      data    idum / 0 /

      if (idum.eq.0) idum = 99 + nid
      eps = .35

      uz=0.0
      uy=0.0
      ux=0.0
      temp=0

      return
      end
c-----------------------------------------------------------------------
      subroutine usrdat
      include 'SIZE'
      include 'TOTAL'

      return
      end
c-----------------------------------------------------------------------
      subroutine usrdat2
      include 'SIZE'
      include 'TOTAL'

      param(66) = 4.   ! These give the std nek binary i/o and are 
      param(67) = 4.   ! good default values
      ifuservp=.false.

      return
      end
c-----------------------------------------------------------------------
      subroutine usrdat3
      include 'SIZE'
      include 'TOTAL'
c
      return
      end

C=======================================================================
      subroutine nek_init_step()
      include 'SIZE'
      include 'TSTEP'
      include 'INPUT'
      include 'CTIMER'
      real*4 papi_mflops
      integer*8 papi_flops
      integer icall, kstep, i, pstep
      common /cht_coupler/ pstep
      save icall
 
      if (icall.eq.0) then
      call nekgsync()
      if (instep.eq.0) then
        if(nid.eq.0) write(6,'(/,A,/,A,/)')
     &     ' nsteps=0 -> skip time loop',
     &     ' running solver in post processing mode'
      else
        if(nio.eq.0) write(6,'(/,A,/)') 'Starting time loop ...'
      endif
      isyc  = 0
      itime = 0
      if(ifsync) isyc=1
      itime = 1
      call nek_comm_settings(isyc,itime)
      call nek_comm_startstat()
      istep  = 0
      endif

      istep=istep+1

      if (lastep .eq. 1) then
        pstep=2
      else
        call nek_advance
        pstep=2
      endif

      return
      end
C=======================================================================
      subroutine nek_step()

      include 'SIZE'
      include 'TSTEP'
      include 'INPUT'
      include 'CTIMER'
      common /cht_coupler/ pstep
      integer pstep

      pstep=pstep+1
      call heat(pstep)

      return
      end
C=======================================================================
      subroutine nek_finalize_step()
      include 'SIZE'
      include 'TSTEP'
      include 'INPUT'
      include 'CTIMER'
      common /cht_coupler/ pstep
      integer pstep 

      real*4 papi_mflops
      integer*8 papi_flops
      integer icall, kstep, knstep, i

      if (param(103).gt.0)   call q_filter      (param(103))
      call setup_convect (pstep)  ! Save convective velocity _after_ filter

      call userchk
      call prepost (.false.,'his')
      call in_situ_check()

      if (mod(istep,nsteps).eq.0) lastep=1
      call nek_comm_settings(isyc,0)
      call comment

273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
      return
      end
C=======================================================================
      subroutine nek_expansion()

      parameter (nl_max=100)
      parameter (nf_max=100)

      include 'SIZE'
      include 'TOTAL'       
      common/expansion_tdata/n_legendre, m_fourier
      common/expansion_tcoef/coeff_tij(nl_max,nf_max)  
      integer e,f

      real*8 fmode(lx1,ly1,lz1,lelt), cache(lx1,ly1,lz1,lelt) 
      real*8 sint, sint1

      ntot=nx1*ny1*nz1*nelt

      zmin=glmin(zm1,ntot)
      zmax=glmax(zm1,ntot)

      call rzero(fmode,ntot)
         do i0=1,n_legendre
           do j0=1,m_fourier
             call nek_mode(fmode,i0,j0)
             sint1=0.0 
             do e=1,nelt
               do f=1,6
                 sint=0.0
                 if (cbc(f,e,1).eq.'W  ') then
                   call col3(cache,fmode,t,ntot)
                   call surface_int(sint,sarea,cache,e,f)
                   sint1=sint1+sint
                 endif
               enddo
             enddo
          call  gop(sint1,wtmp,'+  ',1)
!                                   
          coeff_tij(i0,j0)=sint1*2.0/(0.5*(zmax-zmin))
!         Note that R=0.5 here!!!!
        enddo 
      enddo

      return
      end
C=======================================================================
      subroutine nek_diag()
      parameter (nl_max=100)
      parameter (nf_max=100)
      include 'SIZE'
      include 'TOTAL'
      common/expansion_tdata/n_legendre, m_fourier
      common/expansion_tcoef/coeff_tij(nl_max,nf_max)
      common/diags_coeff/diag_c(nl_max,nf_max)
      integer e,f

      real*8 fmode(lx1,ly1,lz1,lelt)
      real*8 cache(lx1,ly1,lz1,lelt)
      real*8 sint, sint1

      ntot=nx1*ny1*nz1*nelt

      zmin=glmin(zm1,ntot)
      zmax=glmax(zm1,ntot)

      call rzero(fmode,ntot)
         do i0=1,n_legendre
           do j0=1,m_fourier
             call nek_mode(fmode,i0,j0)  
             sint1=0.0
             do e=1,nelt
               do f=1,6
                 sint=0.0
                 if (cbc(f,e,1).eq.'W  ') then
                   call col3(cache,fmode,fmode,ntot)
                   call surface_int(sint,sarea,cache,e,f)
                   sint1=sint1+sint
                 endif
               enddo
             enddo
          call  gop(sint1,wtmp,'+  ',1)
          diag_c(i0,j0)=sint1*2.0/(0.5*(zmax-zmin))
          if (nid.eq.0) write(6,*)i0,j0,diag_c(i0,j0)
        enddo
      enddo

      return
      end
C=======================================================================
      subroutine nek_testp()
      parameter (nl_max=100)
      parameter (nf_max=100)
      include 'SIZE'
      include 'TOTAL'
      common/expansion_tdata/n_legendre, m_fourier
      common/expansion_tcoef/coeff_tij(nl_max,nf_max)
      integer e,f
      real*8 fmode(lx1,ly1,lz1,lelt), cache(lx1,ly1,lz1,lelt)
      real*8 fun(lx1,ly1,lz1,lelt) 
      ntot=nx1*ny1*nz1*nelt
      call rzero(fmode,ntot)
      call rzero(fun,ntot)   
         do i0=1,n_legendre
           do j0=1,m_fourier
             call nek_mode(fmode,i0,j0)
             do i=1,ntot
             fun(i,1,1,1)=fun(i,1,1,1)+fmode(i,1,1,1)*coeff_tij(i0,j0) 
             enddo  
          enddo
         enddo
      call rzero(cache,ntot) 
      call sub3(cache,fun,t,ntot)
 
      sint1=0.0
      sarea1=0.0
      do e=1,lelt
        do f=1,6
          call surface_int(sint,sarea,cache,e,f)
          if (cbc(f,e,1).eq.'W  ') then
           sint1=sint1+sint
           sarea1=sarea1+sarea
          endif
         enddo
      enddo
      call  gop(sint1,wtmp,'+  ',1)
      call  gop(sarea1,wtmp,'+  ',1)

      er_avg=sint1/sarea1
      if (nid.eq.0) write(6,*)"Error: ",er_avg
      return
      end
C=======================================================================
      subroutine nek_mode(fmode,im,jm)
      include 'SIZE'
      include 'TOTAL'
      integer e,f
      real*8 fmode(lx1,ly1,lz1,lelt) 
      ntot=nx1*ny1*nz1*nelt
      zmin=glmin(zm1,ntot)
      zmax=glmax(zm1,ntot)
             do e=1,nelt
               do f=1,6
                 if (cbc(f,e,1).eq.'W  ') then
                   call dsset(nx1,ny1,nz1)
                   iface  = eface1(f)
                   js1    = skpdat(1,iface)
                   jf1    = skpdat(2,iface)
                   jskip1 = skpdat(3,iface)
                   js2    = skpdat(4,iface)
                   jf2    = skpdat(5,iface)
                   jskip2 = skpdat(6,iface)
                   do j2=js2,jf2,jskip2
                     do j1=js1,jf1,jskip1
                       x=xm1(j1,j2,1,e)
                       y=ym1(j1,j2,1,e)
                       z=zm1(j1,j2,1,e)
                       z_leg=2*((z-zmin)/zmax)-1
                       theta=atan2(y,x)
                       fmode(j1,j2,1,e)=
     &                 pl_leg(z_leg,im-1)*fl_four(theta,jm-1)
                     enddo
                   enddo
                 endif
              enddo
            enddo
      return
      end 
c-----------------------------------------------------------------------
      subroutine flux_reconstruction()
      include 'SIZE'
      include 'TOTAL'
      parameter (nl_max=100)
      parameter (nf_max=100) 
      common/expansion_tdata/n_legendre, m_fourier
      common/expansion_tcoef/coeff_tij(nl_max,nf_max)
      common/expansion_fcoef/coeff_fij(nl_max,nf_max)
      common/expansion_recon/flux_recon(lx1,ly1,lz1,lelt)
      integer e,f
      real*8 fmode(lx1,ly1,lz1,lelt)
      ntot=nx1*ny1*nz1*nelt

      call rzero(flux_recon,ntot)
      call rzero(fmode,ntot) 
         do i0=1,n_legendre
           do j0=1,m_fourier
             call nek_mode(fmode,i0,j0)
             do i=1,ntot
             flux_recon(i,1,1,1)= flux_recon(i,1,1,1)
     &                           + fmode(i,1,1,1)*coeff_fij(i0,j0)
             enddo
          enddo
         enddo

c---- Below is for testing
c             do i=1,ntot
c             flux_recon(i,1,1,1)= 1.0
c             enddo
c--------------------------
Cody Permann's avatar
Cody Permann committed
472 473 474
      return
      end
c-----------------------------------------------------------------------
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
      function pl_leg(x,n)
!======================================
!    calculates Legendre polynomials Pn(x)
!    using the recurrence relation
!    if n > 100 the function retuns 0.0
!======================================
      real*8 pl,pl_leg
      real*8 x
      real*8 pln(0:n)
      integer n, k
      pln(0) = 1.0
      pln(1) = x
      if (n.le.1) then
        pl = pln(n)
          else
            do k=1,n-1
              pln(k+1)=
     &  ((2.0*k+1.0)*x*pln(k)-dble(k)*pln(k-1))/(dble(k+1))
            end do
            pl = pln(n)
      end if
      pl_leg=pl*sqrt(dble(2*n+1)/2.0)
      return 
      end
!======================================
      function fl_four(x,n)
      real*8 fl_four,pi
      real*8 x, A
      integer n, k
      pi=4.0*atan(1.0)
      A=1.0/sqrt(2*pi)
      if (n.gt.0) A=1.0/sqrt(pi)  
      fl_four=A*cos(n*x)    
c       fl_four=1.0/sqrt(pi)
      return 
      end