CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Calling zone name, zone id and total pressure from Fluent scheme to UDF (https://www.cfd-online.com/Forums/fluent-udf/132597-calling-zone-name-zone-id-total-pressure-fluent-scheme-udf.html)

kuldip April 3, 2014 05:10

Calling zone name, zone id and total pressure from Fluent scheme to UDF
 
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?

villager October 4, 2014 09:52

UDF for calculating volume-integral absolute pressure in all zones
 
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.

kuldip October 6, 2014 00:23

Thank you very much for your reply
:):)


All times are GMT -4. The time now is 01:46.