FLUENT 6 - Accessing the zones by names in a UDF


now there is no easy way to acces zones by their names in UDF. This is the consequence of conversion between zone ID and zone name that takes place only at the scheme level. It is highly desirable to enable users to access zone names, in addition to zone IDs, from UDF.
The following scheme code creates to *list* rpvariables and fills them with the IDs and the names of all existing zones (threads). By these RP_List variables, they are then accessible on the UDF C side. See the second Resolution in this Solution for a small C sample code.

;; Accessing zones in UDF by their names:

;; This creates two *list* rp variables, 'jos-thread-id-list
;; and 'jos-thread-name-list.
;; These are filled with the ID's and NAMES of all defined threads.
;; As both lists have the same order, they can be used in UDF
;; to access a thread by name.

(rp-var-define 'jos-thread-id-list () 'list #f)
(rpsetvar 'jos-thread-id-list ())
(for-each (lambda (t) (rpsetvar 'jos-thread-id-list (list-add
(rpgetvar 'jos-thread-id-list) (thread-id t))))
(get-all-threads))
(rpgetvar 'jos-thread-id-list)


(rp-var-define 'jos-thread-name-list () 'list #f)
(rpsetvar 'jos-thread-name-list ())
(for-each (lambda (t) (rpsetvar 'jos-thread-name-list (list-add
(rpgetvar 'jos-thread-name-list) (thread-name t))))
(get-all-threads))
(rpgetvar 'jos-thread-name-list)

;; Now you can use the following in your UDF:
;;
;; RP_Get_List_Length("jos-thread-*-list")
;; Gives the number of entries in the lists -- should be both the same!
;; RP_Get_List_Ref_Int("jos-thread-id-list", N)
;; Gives the Thread ID of the Nth entry in the list.
;; RP_Get_List_Ref_String("jos-thread-name-list", N)
;; Gives the Thread name of the same (Nth) entry.
;;
;; This has NOT been thoroughly tested yet..
;;
;
; #include "udf.h"
; #include "var.h"
;
; #ifdef STRUCT_REF
; #define PRINT printf
; #else
; #define PRINT CX_Message
; #endif
;
; DEFINE_ON_DEMAND(listlists)
; {
; int i;
; int jos_thread_id_list_length = RP_Get_List_Length("jos-thread-id-list");
; int jos_thread_name_list_length = RP_Get_List_Length("jos-thread-name-list");
; PRINT("length of ID list: %dn", jos_thread_id_list_length);
; PRINT("length of NAME list: %dn", jos_thread_name_list_length);
;
; for (i = 0; i < jos_thread_id_list_length; i++)
; {
; PRINT("Zone ID: %4d ...has the name "%s"n",
; RP_Get_List_Ref_Int("jos-thread-id-list", i),
; RP_Get_List_Ref_String("jos-thread-name-list", i));
; }
; }
; Sample C code to use with the Scheme text in the previous "Resolution":


#include "udf.h"
#include "var.h"

#ifdef STRUCT_REF
#define PRINT printf
#else
#define PRINT CX_Message
#endif

DEFINE_ON_DEMAND(listlists)
{
int i;
int jos_thread_id_list_length = RP_Get_List_Length("jos-thread-id-list");
int jos_thread_name_list_length = RP_Get_List_Length("jos-thread-name-list");
PRINT("length of ID list: %dn", jos_thread_id_list_length);
PRINT("length of NAME list: %dn", jos_thread_name_list_length);

for (i = 0; i < jos_thread_id_list_length; i++)
{
PRINT("Zone ID: %4d ...has the name "%s"n",
RP_Get_List_Ref_Int("jos-thread-id-list", i),
RP_Get_List_Ref_String("jos-thread-name-list", i));
}
}





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