19.8.1. User CEL Example 1: User Defined Momentum Source

19.8.1.1. Problem Setup

A common application of user CEL functions is the specification of user defined source terms. In the following example, a constant source term for the y-component of the momentum equation has to be applied on two rectangular boxes characterized by their extension in the x and y coordinate direction.

19.8.1.2. Creating the User CEL Function

Additional information on creating user CEL functions in CFX-Pre is available in User Functions in the CFX-Pre User's Guide.

First, you should first create a user routine with the following settings:

  • Routine Name: UserSourceRoutine

  • Option: User CEL Function

  • Calling Name: user_source

  • Library Name: MomentumSource1

  • Library Path: /home/cfxuser/shared_libraries

Next, you should create a User Function with the following settings:

  • Function Name: UserSource

  • Option: User Function

  • User Routine Name:

  • Argument List: [m], [m]

  • Result Units: [kg m^-2 s^-2]

In this example, the compiled code for the user subroutine MomentumSource1.F is stored in the shared library libMomentumSource1.so (the prefix and suffix may vary depending on your platform), which can be found under the /home/cfxuser/shared_libraries/<architecture> directory. If there is a problem linking the shared library to the CFX-Solver, you can check that it has been created, but you will usually not need to know about this library.

The new user CEL function can now be used to set the momentum source components within the subdomain as follows:

  • Momentum x-comp: 0.0

  • Momentum y-comp: UserSource(X,Y)

  • Momentum z-comp: 0.0

These values are set on the Subdomain Sources form. For details, see Sources Tab in the CFX-Pre User's Guide.

19.8.1.3. User Fortran Routine

Source terms for the momentum equations can be specified in CEL for a given subdomain. Because the user CEL routine defined the extent of the source, the source subdomain can be defined to cover the entire flow domain. The subroutine was developed from the template routine ucf_template.F available in <CFXROOT>/examples/. Note that some commented sections of the routine have not been included here. The routine MomentumSource1.F has the following form:

#include "cfx5ext.h"
 dllexport(user_source)
      SUBROUTINE USER_SOURCE (
     & NLOC,NRET,NARG,RET,ARGS,CRESLT,CZ,DZ,IZ,LZ,RZ)
C
C .....
C
C ------------------------------
C        Argument list
C ------------------------------
C
      INTEGER NLOC, NRET, NARG
      CHARACTER CRESLT*(*)
      REAL    RET(1:NLOC,1:NRET), ARGS(1:NLOC,1:NARG)
C
      INTEGER IZ(*)
      CHARACTER CZ(*)*(1)
      DOUBLE PRECISION DZ(*)
      LOGICAL LZ(*)
      REAL RZ(*)
C
C .....
C
C ------------------------------
C    Executable statements
C ------------------------------
C
C---------------------------------------------------------
C     SOURCE = RET(1:NLOC,1)
C     X      = ARGS(1:NLOC,1)
C     Y      = ARGS(1:NLOC,2)
C---------------------------------------------------------
C
C---- Low level user routine
      CALL USER_SOURCE_SUB (NLOC,RET(1,1),ARGS(1,1),ARGS(1,2))
C
      CRESLT = 'GOOD'
      END
      SUBROUTINE USER_SOURCE_SUB (NLOC,SOURCE,X,Y)
C
C .....
C
C ------------------------------
C        Local Variables
C ------------------------------
      INTEGER NLOC, ILOC
      REAL    SOURCE(NLOC), X(NLOC), Y(NLOC)
C---------------------------------------------------------
C     -  0.5<x<1.5 and 1.25<y<1.75 --> SOURCE =  1000.0
C     -  3.5<x<4.5 and 1.25<y<1.75 --> SOURCE = -1000.0
C---------------------------------------------------------
C ---------------------------
C    Executable Statements
C ---------------------------
      DO ILOC=1,NLOC
         SOURCE(ILOC) = 0.0
         IF (X(ILOC).GE.0.5  .AND. X(ILOC).LE.1.5  .AND.
     &    Y(ILOC).GE.1.25 .AND. Y(ILOC).LE.1.75) THEN
            SOURCE(ILOC) =  1000.0
         ELSE IF (X(ILOC).GE.3.5  .AND. X(ILOC).LE.4.5  .AND.
     &     Y(ILOC).GE.1.25 .AND. Y(ILOC).LE.1.75) THEN
            SOURCE(ILOC) = -1000.0
         END IF
      END DO
C
      END