CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   udf problem (http://www.cfd-online.com/Forums/fluent/33320-udf-problem.html)

Karthick March 26, 2004 05:43

udf problem
 
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


FJ March 26, 2004 05:56

Re: udf problem
 
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

Karthick March 26, 2004 11:31

Re: udf problem
 
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


Jun March 26, 2004 14:36

Re: udf problem
 
seems you didn't close the file.

Regards

Jun

FJ March 28, 2004 22:42

Re: udf problem
 
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

Karthick March 29, 2004 03:50

Re: udf problem
 
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

FJ March 29, 2004 22:46

Re: udf problem
 
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

Karthick March 30, 2004 02:19

Re: udf problem
 
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

FJ March 30, 2004 04:13

Re: udf problem
 
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

Karthick March 30, 2004 04:46

Re: udf problem
 
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


FJ March 30, 2004 05:35

Re: udf problem
 
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

Karthick March 30, 2004 07:19

Re: udf problem
 
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

satishkumar44 April 27, 2009 15:40

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?


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