how to perform swirl ratio calculation in Fluent


For IC simulation, a lot of times the swirl ratio is of in terest. Fluent currently does not provided a button to do that.
A udf along with a scheme has been created for this. The scheme will help build a panel and it looks just like normal fluent panel. A push of the button will give the swirl ratio for selected cell zones and defined swirl axis. Some explanation on how to use it is on top of the scheme file.

********************************************************************** THE UDF swirl_scheme.c ****************************************************************

# include "udf.h"

/*************************** UDF used to calculate swirl *******************************************
Writen by : Xiao Hu
Date : 02/24/03
****************************************************************************************************/

static void find_CG(int cell_zone_ID, real * CG)
{
cell_t c;
Thread * thread;
real mass_x[ND_ND], x[ND_ND], volume, density, total_mass, mass;
Domain *domain;

domain=Get_Domain(1);

thread=Lookup_Thread(domain, cell_zone_ID);

NV_S(mass_x,=,0);
total_mass=0;
begin_c_loop(c, thread)
{
C_CENTROID(x, c, thread);

volume=C_VOLUME(c, thread);
density=C_R(c, thread);
mass=density*volume;

total_mass+=mass;

NV_VS(mass_x, +=, x, * ,mass);

}
end_c_loop(c, thread)

NV_VS(CG, =, mass_x, /, total_mass);
}

static real find_mass(int cell_zone_ID)
{
cell_t c;
Thread * thread;
real total_mass;
Domain *domain;

domain=Get_Domain(1);

thread=Lookup_Thread(domain, cell_zone_ID);

total_mass=0;
begin_c_loop(c, thread)
{
total_mass+=C_R(c, thread)*C_VOLUME(c, thread);
}
end_c_loop(c, thread)

return total_mass;
}

DEFINE_ON_DEMAND(Cal_Angular_Mom_I)
{
int i, ncellzones, cellzoneid;
real x[3], r[3], tmp[3], CG[3], total_rvm[3], rv[3], v[3], I,
total_mass, mass, mass_CG[3], volume, density, mag, rpm, swirl_axis[3];

cell_t c;
Thread * thread;
Domain *domain;

domain=Get_Domain(1);

ncellzones=RP_Get_List_Length("exps");

rpm = RP_Get_Real("dynamesh/in-cyn/crank-rpm");

/* Calculate CG */

NV_S(mass_CG, =, 0);
total_mass=0;

swirl_axis[0]=RP_Get_Real("swirl/tx");
swirl_axis[1]=RP_Get_Real("swirl/ty");
swirl_axis[2]=RP_Get_Real("swirl/tz");

for (i=0; i<ncellzones; i++)
{
cellzoneid=RP_Get_List_Ref_Int("exps", i);

thread=Lookup_Thread(domain, cellzoneid);

find_CG(cellzoneid, CG);
mass=find_mass(cellzoneid);

NV_VS(mass_CG, +=, CG, *, mass);
total_mass+=mass;
}
NV_VS(CG, =, mass_CG, /, total_mass);

/* Normalize swirl axis */

mag=NV_MAG(swirl_axis);
NV_S(swirl_axis, /=, mag);

/* Calculate angular momentum and moment of inertia */

NV_S(total_rvm, =, 0);
I=0;
for (i=0; i<ncellzones; i++)
{
cellzoneid=RP_Get_List_Ref_Int("exps", i);

thread=Lookup_Thread(domain, cellzoneid);

begin_c_loop(c, thread)
{
volume=C_VOLUME(c, thread);
density=C_R(c, thread);
C_CENTROID(x, c, thread);

mass=density*volume;
NV_VV(r, =, x, -, CG);

ND_SET(v[0], v[1], v[2], C_U(c, thread), C_V(c, thread), C_W(c, thread));

NV_CROSS(rv, r, v);

NV_VS(total_rvm, +=, rv, *, mass);

NV_CROSS(tmp, r, swirl_axis);
I += NV_MAG2(tmp)*mass;
}
end_c_loop(c, thread)
}

Message0("nnn********************* Swirl Results in SI Units ***********************n");
Message0("nCG = (%12.4e %12.4e %12.4e)n", CG[0], CG[1], CG[2]);
Message0("nAngular Momentum about CG = (%12.4e %12.4e %12.4e)n", total_rvm[0], total_rvm[1],total_rvm[2]);
Message0("Angular Momentum about swirl axis = %11.4en", NV_DOT(total_rvm, swirl_axis));
Message0("nMoment of inertia about swirl axis = %11.4en", I);

Message0("nSwirl ratio is = %10.4en", NV_DOT(total_rvm, swirl_axis)/I/(rpm/60*2*M_PI));
Message0("n***********************************************************************nn");

}


********************************************************** THE SCHEME swirl_scheme.scm******************************************************

;;;; swirl_scheme.scm

;;;; Scheme file which
;;;; creates a GUI input panel for
;;;; Swirl ratio calculation - for
;;;; the UDF C file "swirl_scheme.c"

;;;;
;;;; Usage:

;;;; 1) Build or use the library for "swirl_scheme.c"
;;;; The library should have the name of libudf.so
;;;; 2) File>Read>Scheme .. this file
;;;; 3) Report>Swirl Calculation, specify the
;;;; a) Fluid zones to be used
;;;; b) swirl reference axis
;;;; 4) Compute

;; Do not change below this line without calling for support
;;==========================================================
(define (make-new-rpvar name default type)
(if (not (rp-var-object name))
(rp-var-define name default type #f)))
;;
;;


(make-new-rpvar 'exps '() 'thread-list)
(make-new-rpvar 'swirl/tx 0 'real)
(make-new-rpvar 'swirl/ty 0 'real)
(make-new-rpvar 'swirl/tz 1 'real)

;;
(define
gpr
(let ((panel #f)
(writeb)
(surfaces)
(s-orient-vect)
(swrx)
(swry)
(swrz)
)

(define (surfaces-cb widget selection)
(cx-enable-item writeb
(or #t
(and (pair? (cx-show-list-selections surfaces))
))))
;;;

(define set-cb
(let* ((default #f)
(callback (lambda ()
(rpsetvar 'exps
(map thread-name->id
(cx-show-symbol-list-selections surfaces)))
(ti-menu-load-string "/def/ud/compf load libudf")
(ti-menu-load-string "/def/ud/eod "Cal_Angular_Mom_I::libudf"")
)))
(lambda args (callback))
))
;;;
(define (update-cb . args)
(cx-set-list-items surfaces
(map thread-name
(sort-threads-by-name (get-threads-of-type 'fluid))))
(cx-set-list-selections surfaces
(map thread-id->name (rpgetvar 'exps)))
(cx-set-real-entry swrx (rpgetvar 'swirl/tx))
(cx-set-real-entry swry (rpgetvar 'swirl/ty))
(cx-set-real-entry swrz (rpgetvar 'swirl/tz))
)

;;;;

(define (compute-cb . args)
(rpsetvar 'swirl/tx (cx-show-real-entry swrx))
(rpsetvar 'swirl/ty (cx-show-real-entry swry))
(rpsetvar 'swirl/tz (cx-show-real-entry swrz))
(set-cb)
)

;;;

(lambda args
(if (not panel)
(let ((table))
(set! panel (cx-create-panel "Swirl Computation"
'update-callback update-cb 'apply-callback compute-cb))

(set! writeb (cx-set-panel-button-label panel "Apply" "Compute"))

(set! table (cx-create-table panel ""
'border #t
'below 0
'right-of 0))

(set! s-orient-vect (cx-create-table table
"Swirl Reference Axis"
'row 0))

(set! swrx (cx-create-real-entry s-orient-vect
"X"
'row 1
'col 2))
(set! swry (cx-create-real-entry s-orient-vect
"Y"
'row 2
'col 2))
(set! swrz (cx-create-real-entry s-orient-vect
"Z"
'row 3
'col 2))

(set! surfaces (cx-create-symbol-list
panel "Fluid Cells"
'below 0 'right-of table
'width *gui-name-list-width*
'visible-lines 8
'sorted #t
'multiple-selections #t
'activate-callback surfaces-cb))

))
;; tell solver to display the panel
(cx-show-panel panel))))

(cx-add-item "Report"
"Swirl Calculation"
#U
#f
cx-client?
gpr)





Show Form
No comments yet. Be the first to add a comment!