A User-Coded Boundary Profile

This section contains an example of a user-coded boundary profile.

Suppose that you wish to specify the temperature on a boundary as the same temperature that is in the neighboring cell. You could create a user function that is called zeroGradT which takes the temperature and face-cell index fields as arguments and returns the boundary temperature.

In C, the following could be coded in a file zeroGradT.c, using the uclib.h file:


  #include "uclib.h"
    
  /* Set boundary temperature equal to cell temperature */
  void
  USERFUNCTION_EXPORT zeroGradT(Real *result, int size, int (*fc)[2], Real *T)
  {
    int i;
  
  /* Loop through all entities applying T_boundary = T_cell *
   * fc[i][0] is the cell next to i                         */
    for (i = 0; i != size; ++i)
    {
      result[i] = T[fc[i][0]];
    }
  }

The equivalent in Fortran 90 could be a file zeroGradT.f, using the StarReal.f file:



C Set boundary temperature equal to cell temperature
      subroutine zeroGradT(result,size,fc,T)
      use StarRealMod
      implicit none
      integer, intent(in) :: size
      real(StarReal), intent(out) :: result(size)
      integer, intent(in) :: fc(2,*)
      real(StarReal), intent(in) :: T(*)
      integer i
C Loop through all entities applying T_boundary = T_cell
C fc(1,i) is the cell next to i
      do i = 1,size
        result(i) = T(fc(1,i))
      end do
      
      return
      end

This user function can then be registered with Simcenter STAR-CCM+.