A User-Coded Region Profile
This section contains an example of a user-coded region profile.
Suppose that you wish to initialize the velocity to a constant swirl condition. You could create a user function that is called initVelocity which takes the centroids as an argument and returns the velocity vector at those centroid locations.
In C, the following could be coded in a file initVelocity.c, using the uclib.h file:
#include "uclib.h"
/* Initial velocity based on uniform swirl */
void USERFUNCTION_EXPORT
initVelocity(Real (*result)[3], int size, CoordReal (*centroid)[3])
{
/* Angular velocity and origin of rotation */
CoordReal omega[3] = {0.0, 0.0, 100.0};
CoordReal origin[3] = {0.0, 0.0, 0.0};
CoordReal dr[3];
int i;
/* Loop through all entities applying u = omega x (centroid - origin) */
for (i = 0; i != size; ++i)
{
dr[0] = centroid[i][0] - origin[0];
dr[1] = centroid[i][1] - origin[1];
dr[2] = centroid[i][2] - origin[2];
result[i][0] = (Real)(omega[1]*dr[2] - omega[2]*dr[1]);
result[i][1] = (Real)(omega[2]*dr[0] - omega[0]*dr[2]);
result[i][2] = (Real)(omega[0]*dr[1] - omega[1]*dr[0]);
}
}
The equivalent in Fortran 90 could be a file initVelocity.f, using the StarReal.f file:
C Initial velocity based on uniform swirl
subroutine initVelocity(result,size,centroid)
use StarRealMod
implicit none
integer, intent(in) :: size
real(StarReal), intent(out) :: result(3,size)
real(CoordReal), intent(in) :: centroid(3,*)
integer i
real(CoordReal) dr(3)
C Angular velocity and origin of rotation
real(CoordReal), parameter :: omega(3) = (/0.0,0.0,100.0/)
real(CoordReal), parameter :: origin(3) = (/0.0,0.0,0.0/)
C Loop through all entities applying u = omega x (centroid - origin)
do i = 1,size
dr(1) = centroid(1,i) - origin(1)
dr(2) = centroid(2,i) - origin(2)
dr(3) = centroid(3,i) - origin(3)
result(1,i) = omega(2)*dr(3) - omega(3)*dr(2)
result(2,i) = omega(3)*dr(1) - omega(1)*dr(3)
result(3,i) = omega(1)*dr(2) - omega(2)*dr(1)
end do
return
end
This user function can then be registered with Simcenter STAR-CCM+.