CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   a math operator in UDF (http://www.cfd-online.com/Forums/fluent/36759-math-operator-udf.html)

lichun Dong May 24, 2005 12:22

a math operator in UDF
 
hi, All:

How to get the reminder of two number in UDF, like 7.2 % 2 = 1.2 in C. I need to input a asymmetric moving wall condition which has a period of 2*pi. I tried % in UDF, it does not work. Anybody has an experience?

Thanks a lot

Mark May 24, 2005 13:12

Re: a math operator in UDF
 
I believe you use the div command to store the quotient and remainder. Then access the remainder using .rem

Example:

divide = div(numerator,denominator); remainder = divide.rem;

Mark

Mark May 24, 2005 13:13

Re: a math operator in UDF
 
Sorry, the example came out poorly formatted.

Example:

divide = div(numerator,denominator);

remainder = divide.rem;

Mark

lichun Dong May 24, 2005 15:34

Re: a math operator in UDF
 
hi, Mark:

Thanks a lot, so what is the data type of divide? Array of real?

Lichun

Mark May 24, 2005 15:56

Re: a math operator in UDF
 
Hi,

Sorry, I should have included that with the example. I declared the variable using:

div_t divide;

So that would make it a type "div_t" (I think).

Mark

Saad May 29, 2005 07:53

Re: a math operator in UDF
 
I think you can use the function rem(a,b). For example, rem(5,3) = 2.

Saad

Mahesh June 7, 2005 10:11

Re: a math operator in UDF
 
I have used once to define square wave velocity function as below. ================================= #include "udf.h" DEFINE_PROFILE(sq50_velocity, thread, nv) { face_t f; real t= RP_Get_Real("flow-time"); int p,q; real T=0.01; p=t/(T/2); q=p%2;

begin_f_loop(f, thread) { if(q==0)

F_PROFILE(f, thread, nv) =30;

else

F_PROFILE(f, thread, nv) = 0; } end_f_loop(f, thread) }

manish mehta June 18, 2005 22:04

Re: a math operator in UDF
 
Dear Mahesh,

I am really new with UDF files. If my square wave needs to go from 180 psi to 0 psi, and it has a frequency of 10 Hz. How would I go about doing this?

I thought of doing a Fourier Transform of a square wave that I need, but there are problems with that approach. Any advice would be benefical.

Hope you can help. -Manish


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