CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

need some corrections in my UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By `e`
  • 1 Post By `e`
  • 1 Post By `e`
  • 1 Post By Bruno Machado

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 3, 2015, 04:42
Default need some corrections in my UDF
  #1
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
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)
}
Attached Images
File Type: jpg Error-UDF-wave.jpg (110.3 KB, 15 views)
engrmansoor2534 is offline   Reply With Quote

Old   September 3, 2015, 06:43
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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 likes this.
`e` is offline   Reply With Quote

Old   September 4, 2015, 00:42
Default
  #3
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
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
engrmansoor2534 is offline   Reply With Quote

Old   September 4, 2015, 01:40
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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 likes this.
`e` is offline   Reply With Quote

Old   September 4, 2015, 01:57
Default
  #5
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
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.
engrmansoor2534 is offline   Reply With Quote

Old   September 4, 2015, 16:16
Default
  #6
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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 likes this.
`e` is offline   Reply With Quote

Old   September 7, 2015, 02:47
Default
  #7
Member
 
Mansoor Ahmed
Join Date: Apr 2014
Location: https://t.me/pump_upp
Posts: 47
Rep Power: 12
engrmansoor2534 is on a distinguished road
Send a message via ICQ to engrmansoor2534 Send a message via AIM to engrmansoor2534 Send a message via Yahoo to engrmansoor2534
Great.the previous errors have vanished but we have the following two new errors
..\..\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
engrmansoor2534 is offline   Reply With Quote

Old   September 7, 2015, 10:09
Default
  #8
Senior Member
 
Bruno Machado
Join Date: May 2014
Posts: 271
Rep Power: 13
Bruno Machado is on a distinguished road
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);
engrmansoor2534 likes this.
Bruno Machado is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic Mesh UDF Qureshi FLUENT 7 March 23, 2017 07:37
WILLING TO PAY/ FREELANCER REQUIRED / small UDF coding force loads over body / 6DOF acasas CFD Freelancers 1 January 23, 2015 07:26
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 22:14
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 21:38
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 04:01


All times are GMT -4. The time now is 03:44.