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

udf problem

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 26, 2004, 04:43
Default udf problem
  #1
Karthick
Guest
 
Posts: n/a
I have to get the value of velocity in each cell from a 3d model at particular time step and write it into a data file. My code is like this

#include "udf.h" #include "fstream.h"

DEFINE_ON_DEMAND(my_demand) {

Domain *d;

real uturb=0.;

Thread *t;

cell_t c;

FILE *fp;

fp=fopen("datafile.dat","r");

thread_loop_c(t,d)

{

begin_c_loop(c,t)

{

uturb=C_U(c,t);

fprintf(fp,"%g\n",uturb);

}

end_c_loop(c,t)

} } What is the problem in this code? It is running, but it is not writing the datas.

Regards Karthick

  Reply With Quote

Old   March 26, 2004, 04:56
Default Re: udf problem
  #2
FJ
Guest
 
Posts: n/a
Hi,

fp=fopen("datafile.dat","r") should be changed to fp=fopen("datafile.dat","w").

"fprint" is used for writing a file. So "r" should be changed to "w".

Thank you.

FJ
  Reply With Quote

Old   March 26, 2004, 10:31
Default Re: udf problem
  #3
Karthick
Guest
 
Posts: n/a
Thanx FJ. A small mistake I haven't noticed. thanx once again. But the udf is executing when I give DEFINE_ADJUST. It is giving the following error if I run n DEFINE_ON_DEMAND.

Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: ()

What may be the possible problem?

Regards Karthick

  Reply With Quote

Old   March 26, 2004, 13:36
Default Re: udf problem
  #4
Jun
Guest
 
Posts: n/a
seems you didn't close the file.

Regards

Jun
  Reply With Quote

Old   March 28, 2004, 22:42
Default Re: udf problem
  #5
FJ
Guest
 
Posts: n/a
Hi,

As Jun remarks, "fclose" is needed . But the core problem of this error is the followings, I think.

"Domain *d "

This command should be changed to "Domain *d= Get_Domain(1)".

This expression "Domain *d " was for Fluent5, probably. Some UDF macros are changing from Fluent6.

I've forgot it :->).

Thank you.

FJ
  Reply With Quote

Old   March 29, 2004, 03:50
Default Re: udf problem
  #6
Karthick
Guest
 
Posts: n/a
Hello FJ

Thankx once again. I want to patch velocity values from one case to another case(both the cases has same model only). I've taken the velocity values from the model and write into one data file. That part we have completed. I've successfully write into a data file. This values to be patched in the next model. I am trying it for the past 3 days. What is the problem in this programme?

#include "udf.h" #include "FSTREAM.H"

real uturb=0.;

float arr[50], arr2[50];

int i=0, count=0;

DEFINE_ADJUST(my_adjust,d) {

Thread *t;

cell_t c;

FILE *fp;

fp=fopen("datafilenew.dat","r");

while (!feof(fp))

{

fscanf(fp,"%f",&arr[i]);

i++;

}

fclose(fp);

i=0;

thread_loop_c(t,d)

{

begin_c_loop(c,t)

{

C_U(c,t)=C_U(c,t)+arr[i];

i++;

}

end_c_loop(c,t)

} }

Regards Karthick
  Reply With Quote

Old   March 29, 2004, 22:46
Default Re: udf problem
  #7
FJ
Guest
 
Posts: n/a
Hello Karthick

DEFINE_ADJUST is not able to give any values to Fluent. It only can get values from Fluent at every iterations.

So to use DEFINE_INIT is the best way.

Thank you

FJ
  Reply With Quote

Old   March 30, 2004, 02:19
Default Re: udf problem
  #8
Karthick
Guest
 
Posts: n/a
Thanx. But I want my velocity values to be added after each time step. If I use DEFINE_INIT, it will be added only during the initialisation step only. Can I use DEFINE_AT_END for giving values to Fluent after each time step.

One more thing, I am repeatedly getting Line 1: Parse error when I try to execute my udf in interpreted mode. Are u having any idea about it? How can I get rid off?

Regards Karthick
  Reply With Quote

Old   March 30, 2004, 04:13
Default Re: udf problem
  #9
FJ
Guest
 
Posts: n/a
Hi,

Yes.yes. DEFINE_INIT can't give any values at each time step.

As your remarks, DEFINE_EXECUTE_AT_END can return some values at each time step but only this macro is not enough.

So combination of DEFINE_PROFILE will be better.

I mean , reading values with DEFINE_EXECUTE_AT_END and store it with UDM. Then, refer to the UDM with DEFINE_PROFILE. And use "Fixed Values" at the zone where you want to specify velocities in the panel of "Define-Boundary Conditions-Zone"

Thank you

FJ
  Reply With Quote

Old   March 30, 2004, 04:46
Default Re: udf problem
  #10
Karthick
Guest
 
Posts: n/a
Is it possible to attach DEFINE_PROFILE WITH DEFINE_AT_END. How it is possible, both are different function calls, right?

Also I want to add the velocity values of each cell with the values I am having it in my .dat Not the velocity inlet boundary conditions. (I think only for changing Velocity inlet profile, we'll use DEFINE_PROFILE, is it right?)

Regards Karthick

  Reply With Quote

Old   March 30, 2004, 05:35
Default Re: udf problem
  #11
FJ
Guest
 
Posts: n/a
Hi,

Don't worry. I understand that you don't want to specify boundary profile. You want to know how to specify cell values at each time step,right?.

Generally ,DEFINE_PROFILE is used to specified boundary profile as you know, but from Fluent6, we can give the cell values as well. I show the program below.

#include "udf.h"

DEFINE_PROFILE(cell_value, t, i) {

cell_t c;

begin_c_loop(c, t)

{

F_PROFILE(c, t, i) = 1.0;

}end_c_loop(c, t)

}

This program only set a certain value as "1" for all cell values. In other words ,there is no special meanings this program. However, when a certain fluid zone is selected in the panel of "define-boundary conditions-zones" and defining this function as "X Velocity" with "Fixed Values", all cell values of "X Velocity" are set as "1".

About relationship of DEFINE_EXECUTE_AT_END, I'll write the code. send me all data.

Thank you

FJ
  Reply With Quote

Old   March 30, 2004, 07:19
Default Re: udf problem
  #12
Karthick
Guest
 
Posts: n/a
Hello

I'll tell u the whole problem of my udf. I have two case files say file1 and file2 both having same mesh file. The thing is I have to take x,y,z velocity from file1 for each cell across the domain and patch it into file2 for that corresponding cell. For this I am writing udf for writing the velocity values from file1 to a dat file and another udf in file2 for reading that values and patches it in that corresponding cell.

The first part is ok and it is working well. The second part of reading the values from dat file and patching is creating the problem.

I've already attached the udf file. Please do me the needful.

Regards Karthick
  Reply With Quote

Old   April 27, 2009, 14:40
Default
  #13
New Member
 
satish saluja
Join Date: Apr 2009
Posts: 1
Rep Power: 0
satishkumar44 is on a distinguished road
hey bro i m new in ANSYS CFX And m using it for DRAG coefficient measurement. i have designed got the results Like force, torque, or pressure but i dont know how to relate it for Coefficient of drag Measurement. if anyone could help?
satishkumar44 is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
ATTN ALL: SOLUTON TO UDF COMPILE PROBLEM Rizwan Fluent UDF and Scheme Programming 40 March 18, 2018 06:05
Problem with my udf july Fluent UDF and Scheme Programming 3 June 20, 2010 06:56
UDF problem mansha goraya FLUENT 0 October 29, 2007 00:31
udf compiling problem akr FLUENT 3 August 22, 2007 07:14
UDF problem chiseung FLUENT 4 January 10, 2002 09:58


All times are GMT -4. The time now is 22:56.