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/)
-   -   need some corrections in my UDF (https://www.cfd-online.com/Forums/fluent-udf/158768-need-some-corrections-my-udf.html)

engrmansoor2534 September 3, 2015 04:42

need some corrections in my UDF
 
1 Attachment(s)
Hi all
I am trying to simulate flow in a 2D channel by giving motion to the channel wall.
here is the udf but after building the library fluent shows some errors. I need someone who can kindly correct my UDF.
#include "udf.h"
#include <stdlib.h>
#include <math.h>
#define AH 0.1 // Average Height of Channel
#define XL 1.0 // Length
#define WA 0.01 // Wave Amplitude
#define PI 3.1415925
#define C 0.05 //Wave Speed
#define Lambda 3.0 // wavelength
#define XStep 0.001
#define XSize XL/XStep
#define HStep 0.0001
#define HSize AH/HStep

DEFINE_GRID_MOTION(peristaltic, domain, dt, time, dtime)
{

Thread *tf = DT_THREAD(dt) ;

face_t f ;
float curr_time = CURRENT_TIME ;
//float xVec[XSize] ; //based on XStep you can pre compute how much should be the vector dimension (number of elements in xVec, say 1000 (replace it here)
float xVec[1000] ;
xVec[0] = 0 ;

face_t counter = 1 ;
for (counter = 1 ; counter < XSize ; counter++)
{
xVec[counter] = xVec[counter - 1] + XStep;
}

float hVec[1000] ; //if float is not available then it may be real (check it out and also change others)

begin_f_loop(f,tf)
{
curr_time = CURRENT_TIME;
float sint = sin (2 * PI/Lambda * xVec - C * curr_time);
hVec = AH * WA * sint; //i = i + 1; //This statement has no effect so just delete it if not needed
}
end_f_loop(f,tf)
}

`e` September 3, 2015 06:43

As the error shows, the problem is on line 26:

Code:

face_t counter = 1 ;
You're using the wrong data type, the counter should be an integer. Furthermore, declare your variables at the start of the code block to conform with ANSI C (for example, with Thread *tf).

engrmansoor2534 September 4, 2015 00:42

thank you 'e' for your quick response. I have very little understanding of C language and UDF's. This code is written for me by my Brother. As a software engineer he does not understand proper syntax recognized by fluent. Can you kindly make the necessary changes in my code.
that will help me a lot.
Regards

`e` September 4, 2015 01:40

Try:

Code:

#include "udf.h"
#include <stdlib.h>
#include <math.h>
#define AH 0.1 // Average Height of Channel
#define XL 1.0 // Length
#define WA 0.01 // Wave Amplitude
#define PI 3.1415925
#define C 0.05 //Wave Speed
#define Lambda 3.0 // wavelength
#define XStep 0.001
#define XSize XL/XStep
#define HStep 0.0001
#define HSize AH/HStep

DEFINE_GRID_MOTION(peristaltic, domain, dt, time, dtime)
{

Thread *tf = DT_THREAD(dt) ;
int counter ;

face_t f ;
float curr_time = CURRENT_TIME ;
//float xVec[XSize] ; //based on XStep you can pre compute how much should be the vector dimension (number of elements in xVec, say 1000 (replace it here)
float xVec[1000] ;
xVec[0] = 0 ;

for (counter = 1 ; counter < XSize ; counter++)
{
xVec[counter] = xVec[counter - 1] + XStep;
}

float hVec[1000] ; //if float is not available then it may be real (check it out and also change others)

begin_f_loop(f,tf)
{
curr_time = CURRENT_TIME;
float sint = sin (2 * PI/Lambda * xVec - C * curr_time);
hVec = AH * WA * sint; //i = i + 1; //This statement has no effect so just delete it if not needed
}
end_f_loop(f,tf)
}


engrmansoor2534 September 4, 2015 01:57

Thank you so much 'e'.
After running your code the errors reduced to just two. given below

#include "udf.h"
#include <stdlib.h>
#include <math.h>
#define AH 0.1 // Average Height of Channel
#define XL 1.0 // Length
#define WA 0.01 // Wave Amplitude
#define PI 3.1415925
#define C 0.05 //Wave Speed
#define Lambda 3.0 // wavelength
#define XStep 0.001
#define XSize XL/XStep
#define HStep 0.0001
#define HSize AH/HStep

DEFINE_GRID_MOTION(peristaltic, domain, dt, time, dtime)
{

Thread *tf = DT_THREAD(dt) ;
int counter ;

face_t f ;
float curr_time = CURRENT_TIME ;
//float xVec[XSize] ; //based on XStep you can pre compute how much should be the vector dimension (number of elements in xVec, say 1000 (replace it here)
float xVec[1000] ;
xVec[0] = 0 ;

for (counter = 1 ; counter < XSize ; counter++)
{
xVec[counter] = xVec[counter - 1] + XStep;
}

float hVec[1000] ; //if float is not available then it may be real (check it out and also change others)

begin_f_loop(f,tf)
{
curr_time = CURRENT_TIME;
float sint = sin (2 * PI/Lambda * xVec - C * curr_time);
}
end_f_loop(f,tf)
}

# Generating ud_io1.h
udfnew.c
..\..\src\udfnew.c(32) : error C2143: syntax error : missing ';' before 'type'
..\..\src\udfnew.c(37) : error C2143: syntax error : missing ';' before 'type'

Done.

`e` September 4, 2015 16:16

That's the same error, move the declarations to the start of the code block:

Code:

#include "udf.h"
#include <stdlib.h>
#include <math.h>
#define AH 0.1 // Average Height of Channel
#define XL 1.0 // Length
#define WA 0.01 // Wave Amplitude
#define PI 3.1415925
#define C 0.05 //Wave Speed
#define Lambda 3.0 // wavelength
#define XStep 0.001
#define XSize XL/XStep
#define HStep 0.0001
#define HSize AH/HStep

DEFINE_GRID_MOTION(peristaltic, domain, dt, time, dtime)
{

Thread *tf = DT_THREAD(dt) ;
int counter ;

face_t f ;
float curr_time = CURRENT_TIME ;
//float xVec[XSize] ; //based on XStep you can pre compute how much should be the vector dimension (number of elements in xVec, say 1000 (replace it here)
float xVec[1000] ;
float hVec[1000] ; //if float is not available then it may be real (check it out and also change others)
float sint ;
xVec[0] = 0 ;

for (counter = 1 ; counter < XSize ; counter++)
{
xVec[counter] = xVec[counter - 1] + XStep;
}

begin_f_loop(f,tf)
{
curr_time = CURRENT_TIME;
sint = sin (2 * PI/Lambda * xVec - C * curr_time);
}
end_f_loop(f,tf)
}


engrmansoor2534 September 7, 2015 02:47

Great.the previous errors have vanished :) but we have the following two new errors :o
..\..\src\final_UDF2.c(37) : error C2297: '*' : illegal, right operand has type 'float [1000]'
..\..\src\final_UDF2.c(37) : error C2198: 'sin' : too few arguments for call

Bruno Machado September 7, 2015 10:09

In this line you should add in the xVec the counter ([counter] or something like that).

sint = sin (2 * PI/Lambda * xVec[counter] - C * curr_time);


All times are GMT -4. The time now is 02:00.