Using Tools > Working with User Code > User Code Examples > A User-Coded Field Function

Your Ad Here




A User-Coded Field Function

Suppose that you would like to define the Sutherland viscosity law as a field function. You might want to do this so that you can visualize the Sutherland viscosity for a given temperature field without having to apply it as the dynamic viscosity in your region of interest. The law is simple enough to be implemented as a user field function, but here we will show how it can be implemented as a user function. The function could be called sutherlandViscosity, taking the temperature as an argument and returning the viscosity.

In C the following could be coded in a file sutherlandViscosity.c:

  #include <math.h>
  #include "Real.h"
  /* Dynamic viscosity based on Sutherland's law */
  void
  sutherlandViscosity(Real *result, int size, Real *T)
  {
  /* Reference viscosity, Sutherland constant and reference temperature */
    Real v0 = 1.716E-5;
    Real Cs = 110.0;
    Real T0 = 273.15;
    int i;
  /* Loop through all entities applying Sutherland's law */
    for (i = 0; i != size; ++i)
    {
      result[i] = v0 * pow(T[i]/T0, 1.5) * (T0 + Cs)/(T[i] + Cs);
    }
  }

The equivalent in Fortran 90 could be a file sutherlandViscosity.f:

C Dynamic viscosity based on Sutherland's law
      subroutine sutherlandViscosity(result,size,T)
      use StarRealMod
      implicit none
      integer, intent(in) :: size
      real(StarReal), intent(out) :: result(size)
      real(StarReal), intent(in) :: T(*)
      integer i
C Reference viscosity, Sutherland constant and reference temperature
      real(StarReal), parameter :: v0 = 1.716E-5
      real(StarReal), parameter :: Cs = 110.0
      real(StarReal), parameter :: T0 = 273.15
      
C Loop through all entities applying Sutherland's law
      do i = 1,size
        result(i) = v0 * (T(i)/T0)**1.5 * (T0 + Cs)/(T(i) + Cs)
      end do
      
      return
      end

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

Return to CD-adapco STAR-CCM+ Index


Your Ad Here