Changing the Distribution of Diameters in a Transient Injection
This example examines the case of particles such as droplets being injected into the simulation.
Simcenter STAR-CCM+ uses the Rosin-Rammler distribution to describe droplet diameters. The probability of finding a particle with diameter in a given set of particles (the probability density function, or PDF) is:
where is the Rosin-Rammler diameter and is the Rosin-Rammler exponent.
On a log-log graph, this distribution is a straight line; is the intercept and is the slope. The cumulative probability density function (or CDF) is the integrated probability:
where is the mass fraction of droplets with diameter less than and is bounded between zero and one. This relation can be solved for to obtain a sample of diameters at different mass fraction points:
This relation can be used to return diameters for a given random sample of in the range [0,1]. Writing a routine to return the diameter is straightforward in Fortran or C, but you must provide some additional coding to link the routine into Simcenter STAR-CCM+.
This example requires four files:
- A file that defines the size of variables in a module for a shared Fortran object library, StarReal.f
- A file containing definitions that link the variables inside Simcenter STAR-CCM+ to the external library created for the case, uflib.f
- Source code, returning the appropriate diameter, rosinRammlerDiameter.f
- A makefile, for convenience
Module File StarReal.f
The first file, StarReal.f, defines a module which denotes the standard variable sizes that are used in Simcenter STAR-CCM+. Compiling StarReal.f creates the Fortran shared object library. The file is:
module StarRealMod
integer, parameter :: StarInt = kind(1)
integer, parameter :: StarReal = kind(1.0)
integer, parameter :: CoordReal = kind(1D0)
integer, parameter :: StarIntSize = StarInt
integer, parameter :: StarRealSize = StarReal
integer, parameter :: CoordRealSize = CoordReal
end module StarRealMod
Note | When using double precision, define StarReal as kind(1.0d0). |
Library File uflib.f
The library file, uflib.f, registers the user routine and defines the internal variables to be passed into your code. The file is:
subroutine uflib()
use StarRealMod
implicit none
c Register user functions here
external rosinRammlerDiameter
call uffunc(rosinRammlerDiameter,
& "ParcelProfile",
& "Rosin-Rammler Diameter")
return
end
In this case, the internal routine uffunc looks for a module named rosinRammerDiameter, which is being applied internally to a ParcelProfile.
The third argument in the list, Rosin-Rammler Diameter, is the title that appears in the interface when the library is loaded.
Subroutine rosinRammlerDiameter.f
This subroutine calculates the diameters by sampling the CDF uniformly. The example here uses the built-in Fortran random number generator rand(), which means that this implementation depends on the machine and compiler combination. Other suitable pseudorandom number generators are available from several sources.
subroutine rosinRammlerDiameter(result,size)
c particle diameter example
use StarRealMod
implicit none
integer, intent(in) :: size
real(StarReal), intent(out) :: result(size)
real(StarReal), parameter :: meandiam = 1e-5
real(StarReal), parameter :: rrexpon = 1.0/3.5
integer i
do i = 1,size
result(i) = meandiam*(-log(1.0-rand()))**rrexpon
end do
return
end
The makefile
Below is an example of a makefile that contains the compilation flags for gnu Fortran95:
default: libuser.so
libuser.so: StarReal.f uflib.f rosinRammlerDiameter.f
f95 StarReal.f uflib.f rosinRammlerDiameter.f -fPIC -shared -o $@
Running the makefile produces a shared object library libuser.so. After building the library, you connect the function to Simcenter STAR-CCM+.
Connecting User Code to Simcenter STAR-CCM+
To connect the user code:
-
Right-click the New User Library....
node and select -
Browse for libuser.so in the file system and expand the User Code node:
Assuming an appropriate injection has been defined for the case, the User Code option appears as an option for the Particle Diameter definition.
- To select the Rosin-Rammler distribution, edit the Function property of the User Code node.
The case that is shown here defines two injectors. In one, the particle diameter is given by the Rosin-Rammler particle size distribution as defined internally by Simcenter STAR-CCM+. In the other, the user coding defines the Rosin-Rammler distribution. The injectors are otherwise the same.
The following graph is the histogram of particle diameter for the internally defined Rosin-Rammler diameter distribution:

The following graph is the histogram of particle diameter for the user-coded Rosin-Rammler diameter distribution:

There are slight differences in mean diameter and actual number distribution for the two definitions. These differences are due mostly to the choice of sampling for the random numbers and clipping of maximum and minimum values between the methods. In both cases, the Rosin-Rammler diameter was 1.0E-5 meters and the Rosin-Rammler exponent was set to 3.5. The differences become smaller for a larger number of samples.