CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Calling zone name, zone id and total pressure from Fluent scheme to UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By villager

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 3, 2014, 06:10
Unhappy 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
kuldip is on a distinguished road
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
kuldip is offline   Reply With Quote

Old   October 4, 2014, 10:52
Smile 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
villager is on a distinguished road
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);
In FLUENT, run scheme code:

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)
Compile the following UDF in C:

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 will obtain the volume-integral of absoulte pressure for each cell zone.

You can compare the values with
Code:
report/volume-integrals/vol-avg
values for each cell zone of abs-pressure, and they agree.
wc34071209 likes this.

Last edited by villager; October 4, 2014 at 11:30. Reason: corrected report command
villager is offline   Reply With Quote

Old   October 6, 2014, 01:23
Default
  #3
New Member
 
Kuldip Kulkarni
Join Date: Nov 2012
Location: Pune, Maharashtra
Posts: 4
Rep Power: 14
kuldip is on a distinguished road
Thank you very much for your reply
kuldip is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 16:10.