Interactively providing inputs to UDF through terminal


There might be a need for an user to provide input to an UDF,during its execution.
This can be accomplished using scanf function.Please note that this procedure doesn't work on Window Machines.

The following test udf explains the usage:

============================================
scanf.c
============================================


#include "udf.h"
#include<stdio.h>

/*USER INPUTS-------------------------------------*/
#define INTERIOR_FACE 9 /*ID of the interior face*/
#define A 0.004
/*-----------------------------------------------*/

DEFINE_ON_DEMAND(inhomog)
{
float mass_flow_face,M;
float inhomogenity;
float A_face_vec[ND_ND], A_face_mag;
face_t f;
cell_t c0, c1;
Thread *tf, *tc0, *tc1;
extern Domain *domain;

mass_flow_face=0.0;
tf=Lookup_Thread(domain, INTERIOR_FACE);
tc0=THREAD_T0(tf);
tc1=THREAD_T1(tf);

scanf("%f",&M); /* READING VARIABLE USING SCANF FUNCTION*/
Message("n n");

Message("value entered = %fn", M);
/* inhomogenity calculation */
inhomogenity=0.0;
begin_f_loop(f,tf)
{
F_AREA(A_face_vec,f,tf);
A_face_mag=NV_MAG(A_face_vec);
c0=F_C0(f,tf);
c1=F_C1(f,tf);
mass_flow_face=F_FLUX(f,tf);
inhomogenity=inhomogenity+ABS((mass_flow_face*A/A_face_mag)-M);
}
end_f_loop(f,tf)


Message("n---------------------------------n");
Message("INHOMOGENITY = %fn",inhomogenity);
Message("---------------------------------nn");


scanf("%f",&M); /* READING VARIABLE USING SCANF FUNCTION*/
Message("n n");

Message("value entered = %fn", M);
/* inhomogenity calculation */
inhomogenity=0.0;
begin_f_loop(f,tf)
{
F_AREA(A_face_vec,f,tf);
A_face_mag=NV_MAG(A_face_vec);
c0=F_C0(f,tf);
c1=F_C1(f,tf);
mass_flow_face=F_FLUX(f,tf);
inhomogenity=inhomogenity+ABS((mass_flow_face*A/A_face_mag)-M);
}
end_f_loop(f,tf)


Message("n---------------------------------n");
Message("INHOMOGENITY2 = %fn",inhomogenity);
Message("---------------------------------nn");
}

Procedure:

1)Compile the udf and link it to case and data.

2)Execute the udf through Define---->User Define Functions--->Execute On Demand

3)Give the value of M through terminal from where Fluent is fired and press <ENTER>.In the above udf,two values of M are given through console.

Note:Start Fluent session without ampersand(&).





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