|
[Sponsors] |
Calling zone name, zone id and total pressure from Fluent scheme to UDF |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
April 3, 2014, 06:10 |
Calling zone name, zone id and total pressure from Fluent scheme to UDF
|
#1 |
New Member
Kuldip Kulkarni
Join Date: Nov 2012
Location: Pune, Maharashtra
Posts: 4
Rep Power: 14 |
Hello,
I am calling zone id, zone name and total pressure from fluent scheme language to fluent UDF. I got appropriate zone id and zone name, but total pressure is not correct. Following is the Scheme which I used; (rp-var-define 'a () 'list #f) (rpsetvar 'a ()) (for-each (lambda (t) (rpsetvar 'a (list-add (rpgetvar 'a) (thread-id t)))) (get-all-threads)) (rpgetvar 'a) (rp-var-define 'b () 'list #f) (rpsetvar 'b ()) (for-each (lambda (t) (rpsetvar 'b (list-add (rpgetvar 'b) (thread-name t)))) (get-all-threads)) (rpgetvar 'b) (rp-var-define 'p() 'total-pressure #f) (rpsetvar 'p()) (for-each ( lambda (t) (rpsetvar 'p (list-add (rpgetvar 'p) (thread-id t)))) (get-all-threads)) (rpgetvar 'p) and following is the UDF; #include "udf.h" #include "var.h" #ifdef STRUCT_REF #define PRINT printf #define thread-id-list a #define thread-name-list b #define total-pressure p #else #define PRINT CX_Message #endif DEFINE_ON_DEMAND(zoneid_zonename) { int i; int a = RP_Get_List_Length("a"); int b = RP_Get_List_Length("b"); int p = RP_Get_List_Length("p"); PRINT("length of ID list: %dn", a); PRINT("length of NAME list: %dn", b); PRINT("length of PRESSURE list : %dn", p); for (i = 0; i < a; i++) { PRINT("Zone ID: %d ...has the name %s... has the pressure = %d\n", RP_Get_List_Ref_Int("a", i), RP_Get_List_Ref_String("b", i), RP_Get_List_Ref_Int("p",i)); } } Could anybody help me, what is wrong in UDF/scheme? Last edited by kuldip; May 2, 2014 at 07:36. Reason: Unable to get answer |
|
October 4, 2014, 10:52 |
UDF for calculating volume-integral absolute pressure in all zones
|
#2 |
Member
vlg
Join Date: Jul 2011
Location: My home :)
Posts: 81
Rep Power: 18 |
As I understand, the problem was that you added (thread-id t) again to p.
I don't know about methods of obtaining total-pressure for ZONE in FLUENT, becuse it is quantity determined in each CELL. However, we can calculate volume-integral of total-pressure in the zone directly in the UDF code. Below is the code to calculate ABSOLUTE pressure in fluent (TOTAL+OPERATING) because it is more informative, then total pressure. To calculate total pressure (relative), just exclude adding p_operating to the abs_pressure variable in the code, it would be: Code:
abs_pressure+=C_P(c,c_thread)*C_VOLUME(c,c_thread); Code:
rp-var-define 'a () 'list #f) (rpsetvar 'a ()) (for-each (lambda (t) (rpsetvar 'a (list-add (rpgetvar 'a) (thread-id t)))) (get-all-threads)) (rpgetvar 'a) (rp-var-define 'b () 'list #f) (rpsetvar 'b ()) (for-each (lambda (t) (rpsetvar 'b (list-add (rpgetvar 'b) (thread-name t)))) (get-all-threads)) (rpgetvar 'b) Code:
#include "udf.h" #include "stdlib.h" #include "var.h" #ifdef STRUCT_REF #define PRINT printf #define thread-id-list a #define thread-name-list b #define abs-pressure p #else #define PRINT CX_Message #endif DEFINE_ON_DEMAND(zoneid_zonename) { /*print thread id_s, thread_names and volume-integral values of abs-pressure for each thread*/ int i; real p_operating=RP_Get_Float("operating-pressure");/*operating pressure*/ int a = RP_Get_List_Length("a"); int b = RP_Get_List_Length("b"); PRINT("length of ID list: %d\n", a); PRINT("length of NAME list: %d\n", b); Domain *domain; domain = Get_Domain(1);/*assuming not multiphase flow, there is only one domain with number=1*/ Thread *c_thread; int threads=0; thread_loop_c(c_thread, domain) { threads++;/*count cell threads number in our calculation domain*/ } real* p = (double*)malloc(threads * sizeof(double*));/*array of volume-integral values of abs-pressure for each thread*/ for (i = 0; i < threads; i++) p[i]=0.0; real abs_pressure; real total_volume; thread_loop_c(c_thread, domain)/*here we loop over all cell threads in domain*/ { abs_pressure=0.0; total_volume=0.0; for (i = 0; i < a; i++) if (RP_Get_List_Ref_Int("a", i)==THREAD_ID(c_thread)) { cell_t c; begin_c_loop(c, c_thread)/*we should loop over all cells in the thread*/ { abs_pressure+=(C_P(c,c_thread)+p_operating)*C_VOLUME(c,c_thread); total_volume+=C_VOLUME(c,c_thread); } end_c_loop(c, c_thread) abs_pressure/=total_volume; p[i]=abs_pressure; break; } } for (i = 0; i < a; i++) { PRINT("Zone ID: %d ...has the name %s... has the pressure = %f\n", RP_Get_List_Ref_Int("a", i), RP_Get_List_Ref_String("b", i), p[i]); } free(p); } You can compare the values with Code:
report/volume-integrals/vol-avg Last edited by villager; October 4, 2014 at 11:30. Reason: corrected report command |
|
October 6, 2014, 01:23 |
|
#3 |
New Member
Kuldip Kulkarni
Join Date: Nov 2012
Location: Pune, Maharashtra
Posts: 4
Rep Power: 14 |
Thank you very much for your reply
|
|
|
|