Wall unit normal

21 views
Skip to first unread message

Filipe Brandao

unread,
Jun 17, 2026, 5:21:20 PM (7 days ago) Jun 17
to Nek5000
Hi,

I am trying to implement a BC in userbc that I may need to use the variables unx, uny and unz which are the x, y, and z components of face unit normal, repectively.

I thought that by accessing them inside the userbc subroutine, we only would have access to the values of the boundary face, but we actually have access to the all the 6 faces of the element adjacent to the wall. How can we know which face exactly is the one at the boundary?

Thanks,
Filipe

YuHsiang Lan

unread,
Jun 20, 2026, 10:41:26 PM (4 days ago) Jun 20
to Nek5000
Hi Filipe,

I assume you want to add surface integral term via userbc like this
  flux = Fx * unx + Fy * uny + Fz * unz

This can be tricky because we pass the volumetric index (ix,iy,iz,iel) to userbc.
And, what you really want is the face index (ia,iface,iel)

Nek5000 typically maps from face index to the volume one 
like this:
         DO 2000 IE=1,NEL
         DO 2000 IFACE=1,NFACES
            IA=0
            CALL FACIND (KX1,KX2,KY1,KY2,KZ1,KZ2,lx1,ly1,lz1,IFACE)
            DO 200 IZ=KZ1,KZ2
            DO 200 IY=KY1,KY2
            DO 200 IX=KX1,KX2
               IA = IA + 1
               S(IX,IY,IZ,IE) = S(IX,IY,IZ,IE) +
     $            HC*AREA(IA,1,IFACE,IE)/BM1(IX,IY,IZ,IE)

but the reverse mapping is rarely used (it's also not unique on edges and corners)

Two approaches to consider:

a). You could define dummy arrays for each face and assign values in userchk:

    real my_flux(lx1,ly1,lz1,6,lelt)
    common /my_fld/ my_flux
    ! set up my_flux

    and then reference them in userbc

    iel = gllel(ieg)
    flux = my_flux(ix,iy,iz,iface,iel)

    However, this requires 6 volume arrays, which is quite a waste as we only care of some surface point.
    Face based array is required. Otherwise, edges will be double counted.
    The is an exception: if the desired face doesn't intersect with other faces with Neumann BC.

b). Add surface integral to right hand side like userq
    (Also see BCNEUSC in bdry.f in terms of how to select the faces)
    What you eventually need is 
         q(ix,iy,iz,ie) = q(ix,iy,iz,ie) 
     $                  + flux(ia,1,iface,ie) * conductivity * area(ia,1,iface,ie) / bm1(ix,iy,iz,ie)

    You can then save 1 volume array, pre-compute it in userchk, and reference it in userq via a common block.

Note that, a) and b) are not identical:
a) computes the flux based on current solution and use it as Neumann BC for the next.
b) directly computes the needed surface integral at right hand side. Then, Nek will do extrapolation on the top of it.
I'd assume b) is more accurate but can sometimes be unstable depending on how dynamic the BC changes.

Hope this helps,
Yu-Hsiang
--

Fischer, Paul

unread,
Jun 21, 2026, 9:54:12 AM (4 days ago) Jun 21
to YuHsiang Lan, Nek5000
Hi Yu-Hsiang,

I see I did not reply all...  pasting here.

Paul

The "f" variable indicates the face, "eg" indicates the global element number --- local to the processor is given by:

      Integer e,eg,f

      e = gllel(eg)

f is in the range [1:6] for 3D, [1:ndim] for ndim = 2 or 3


The following should provide your desired unit normals for any face data that is passed to userbc(),
 which is called point-by-point but only for faces that have BCs which are user functions.

        subroutine userbc(i,j,k,f,eg)
      
        include 'SIZE'
        include 'TOTAL'
      
        integer e,eg,f
      
        e = gllel(eg)  ! Local element number
      
        if (f.eq.1.or.f.eq.3) then
           ip=i
           jp=k
        elseif (f.eq.2.or.f.eq.4) then   
           ip=j  
           jp=k  
        else     
           ip=i
           jp=j
        endif
         
        unl = unx(ip,jp,f,e)
        vnl = uny(ip,jp,f,e)
        wnl = unz(ip,jp,f,e)
            
            
You should test this to make sure it conforms with your intuition.

Look at subroutine setedge in connect1.f for the preprocessor face
notation, which governs the assignment of "f" to faces.


From: nek...@googlegroups.com <nek...@googlegroups.com> on behalf of YuHsiang Lan <seanl...@gmail.com>
Sent: Saturday, June 20, 2026 9:41 PM
To: Nek5000 <nek...@googlegroups.com>
Subject: [nek5000] Re: Wall unit normal
 
--
You received this message because you are subscribed to the Google Groups "Nek5000" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nek5000+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/nek5000/e4501701-4804-4975-bc53-2042b5688f5en%40googlegroups.com.

Donkiss Boss

unread,
Jun 23, 2026, 7:04:20 AM (2 days ago) Jun 23
to Nek5000


Reply all
Reply to author
Forward
0 new messages