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

Simulation with UDF for species mass fraction and velocity profile

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

Like Tree1Likes
  • 1 Post By litterfree

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 18, 2011, 06:19
Default Simulation with UDF for species mass fraction and velocity profile
  #1
New Member
 
Join Date: Apr 2011
Location: Italy
Posts: 9
Rep Power: 14
virgy is on a distinguished road
Hi
I want to simulate a simple pipe (radius= 0.0005 m) in 3D. The inlet has 2 boundary conditions written with UDF:
-the first boundary condition is the parabolic profile of velocity
- the second one is a parabolic profile of mass fraction of a species without reaction along the pipe.

I calculate the velocity with UDF (it works) and I save it in a file .dat.
After Fluent has calculated it, I keep the file .dat with the profile of velocity, I turn off the Navier-Stokes model and I activate the species model (I'd like to separate Navier-Stokes model and species model because it reduces the the time of simulation).
The UDF for the mass fraction is correctly interpreted by Fluent, I can select my UDF profile in species mass fraction boundary condition, but when I press the button "calculate" I receive this message: "FLUENT received fatal signal (ACCESS_VIOLATION)".

Does anybody know what to do? Can I give two different UDF in this way? Is there anything wrong in my UDF?



My UDF for mass fraction of a species is here:



# include "udf.h"
# include "mem.h"

DEFINE_PROFILE (indop, thread, nv)
{
face_t f;
real x;
real y;
real n[ND_ND];
real coeff = 0.01;
real r = 0.0005;
real r2 = (pow((r),2));

begin_f_loop (f,thread)
{
F_CENTROID(n,f,thread);
x=n[0];
y=n[1];

F_YI(f,thread,nv)= coeff-(coeff/r2) * ( (pow((x),2))+(pow((y),2)) );
}
end_f_loop (f,thread)
}


Thanks a lot,
Virgy
virgy is offline   Reply With Quote

Old   November 25, 2011, 03:34
Default
  #2
New Member
 
litter
Join Date: May 2011
Posts: 17
Rep Power: 14
litterfree is on a distinguished road
F_YI(f,thread,nv) ???-----> F_PROFILE(f,thread,nv)???
virgy likes this.
__________________
never ever give up
litterfree is offline   Reply With Quote

Old   November 25, 2011, 05:37
Default UDF for profile with fopen function
  #3
New Member
 
Join Date: Apr 2011
Location: Italy
Posts: 9
Rep Power: 14
virgy is on a distinguished road
Quote:
Originally Posted by litterfree View Post
F_YI(f,thread,nv) ???-----> F_PROFILE(f,thread,nv)???
Sure!! F_YI is a macro for boundary face flow! Thank you so much!
Now, can I ask another question to you?

I want to modify the last UDF in this way: now the profile has to change every time Fluent changes time step (my simulation now is transient with a fixed physical time step = 0.1 s).
I define and initialize an array A. A contains the values (constant) for my profile.
Example:
time step #1 : F_PROFILE=A1;
time step #2 : F_PROFILE=A2;
time step #n : F_PROFILE=An.
I use "RP_Get_Integer" to take the current number of iteration and I put it in the variable "n_iter". I define the profile in this way:
F_PROFILE= A[n_iter];
This UDF works correctly!!
But if the values of array A are taken from an external file .txt with the function fopen, Fluent exit automatically when I press the button "Calculate" (the UDF is correctly interpretated).
Do you know why?

This is my new UDF:


#include "udf.h"

real x;
real y;

real A[5]; // the array with coefficients for my profile of species

FILE *fp; // pointer for the function fopen



DEFINE_PROFILE(mass_fraction_profile, thread, i)
{
int n_iter = RP_Get_Integer ("time-step"); /* every time step, the variable n_iter will contain a new value */
real a[ND_ND];

face_t f;

begin_f_loop(f,thread)
{
F_CENTROID(a,f,thread);


x=a[0];
y=a[1];

fp = fopen ("coefficients", "r"); // coefficients is my file .txt

F_PROFILE(f,thread,i) = A[n_iter];

fclose (fp);
}
end_f_loop (f,thread)
}



My file "coefficients.txt":

A[0]=0.1;
A[1]=0.05;
A[2]=1;
A[3]=0.6;
A[4]=0.3;

Thank you!!
Virgy
virgy is offline   Reply With Quote

Old   February 7, 2012, 02:34
Default
  #4
New Member
 
litter
Join Date: May 2011
Posts: 17
Rep Power: 14
litterfree is on a distinguished road
Quote:
Originally Posted by virgy View Post
Hi
I want to simulate a simple pipe (radius= 0.0005 m) in 3D. The inlet has 2 boundary conditions written with UDF:
-the first boundary condition is the parabolic profile of velocity
- the second one is a parabolic profile of mass fraction of a species without reaction along the pipe.

I calculate the velocity with UDF (it works) and I save it in a file .dat.
After Fluent has calculated it, I keep the file .dat with the profile of velocity, I turn off the Navier-Stokes model and I activate the species model (I'd like to separate Navier-Stokes model and species model because it reduces the the time of simulation).
The UDF for the mass fraction is correctly interpreted by Fluent, I can select my UDF profile in species mass fraction boundary condition, but when I press the button "calculate" I receive this message: "FLUENT received fatal signal (ACCESS_VIOLATION)".

Does anybody know what to do? Can I give two different UDF in this way? Is there anything wrong in my UDF?



My UDF for mass fraction of a species is here:



# include "udf.h"
# include "mem.h"

DEFINE_PROFILE (indop, thread, nv)
{
face_t f;
real x;
real y;
real n[ND_ND];
real coeff = 0.01;
real r = 0.0005;
real r2 = (pow((r),2));

begin_f_loop (f,thread)
{
F_CENTROID(n,f,thread);
x=n[0];
y=n[1];

F_YI(f,thread,nv)= coeff-(coeff/r2) * ( (pow((x),2))+(pow((y),2)) );
}
end_f_loop (f,thread)
}


Thanks a lot,
Virgy
first,
i think you should use "F_PROFILE(f,thread,nv)= coeff-(coeff/r2) * ( (pow((x),2))+(pow((y),2)) );'' ,
not ''F_YI(f,thread,nv)= coeff-(coeff/r2) * ( (pow((x),2))+(pow((y),2)) );"

second,
i recommend you to use "compile pattern " not ''interpreted pattern"
__________________
never ever give up
litterfree is offline   Reply With Quote

Old   February 7, 2012, 02:59
Default
  #5
New Member
 
litter
Join Date: May 2011
Posts: 17
Rep Power: 14
litterfree is on a distinguished road
Quote:
Originally Posted by virgy View Post
Sure!! F_YI is a macro for boundary face flow! Thank you so much!
Now, can I ask another question to you?

I want to modify the last UDF in this way: now the profile has to change every time Fluent changes time step (my simulation now is transient with a fixed physical time step = 0.1 s).
I define and initialize an array A. A contains the values (constant) for my profile.
Example:
time step #1 : F_PROFILE=A1;
time step #2 : F_PROFILE=A2;
time step #n : F_PROFILE=An.
I use "RP_Get_Integer" to take the current number of iteration and I put it in the variable "n_iter". I define the profile in this way:
F_PROFILE= A[n_iter];
This UDF works correctly!!
But if the values of array A are taken from an external file .txt with the function fopen, Fluent exit automatically when I press the button "Calculate" (the UDF is correctly interpretated).
Do you know why?

This is my new UDF:


#include "udf.h"

real x;
real y;

real A[5]; // the array with coefficients for my profile of species

FILE *fp; // pointer for the function fopen



DEFINE_PROFILE(mass_fraction_profile, thread, i)
{
int n_iter = RP_Get_Integer ("time-step"); /* every time step, the variable n_iter will contain a new value */
real a[ND_ND];

face_t f;

begin_f_loop(f,thread)
{
F_CENTROID(a,f,thread);


x=a[0];
y=a[1];

fp = fopen ("coefficients", "r"); // coefficients is my file .txt

F_PROFILE(f,thread,i) = A[n_iter];

fclose (fp);
}
end_f_loop (f,thread)
}



My file "coefficients.txt":

A[0]=0.1;
A[1]=0.05;
A[2]=1;
A[3]=0.6;
A[4]=0.3;

Thank you!!
Virgy
look at this line :
fp = fopen ("coefficients", "r"); // coefficients is my file .txt

it just open the your file "coefficients.txt" and return the pointer of your file to the pointer fp. no other use.
it can not read the content of your file.txt .so your code is wrong

you can achieve the function in other simple way.


#include "udf.h"





DEFINE_PROFILE(mass_fraction_profile, thread, i)
{
int n_iter = RP_Get_Integer ("time-step");
if(n_iter<1) {F_PROFILE(f,thread,i) = 0.1; }
if(1<n_iter<2) {F_PROFILE(f,thread,i) = 0.05; }
if(2<n_iter<3) {F_PROFILE(f,thread,i) = 1; }
if(3<n_iter<4) {F_PROFILE(f,thread,i) = 0.6; }
if(4<n_iter<5) {F_PROFILE(f,thread,i) = 0.3; }


}
__________________
never ever give up
litterfree is offline   Reply With Quote

Old   February 7, 2012, 04:20
Smile
  #6
New Member
 
Join Date: Apr 2011
Location: Italy
Posts: 9
Rep Power: 14
virgy is on a distinguished road
Quote:
Originally Posted by litterfree View Post
look at this line :
fp = fopen ("coefficients", "r"); // coefficients is my file .txt

it just open the your file "coefficients.txt" and return the pointer of your file to the pointer fp. no other use.
it can not read the content of your file.txt .so your code is wrong

you can achieve the function in other simple way.


#include "udf.h"





DEFINE_PROFILE(mass_fraction_profile, thread, i)
{
int n_iter = RP_Get_Integer ("time-step");
if(n_iter<1) {F_PROFILE(f,thread,i) = 0.1; }
if(1<n_iter<2) {F_PROFILE(f,thread,i) = 0.05; }
if(2<n_iter<3) {F_PROFILE(f,thread,i) = 1; }
if(3<n_iter<4) {F_PROFILE(f,thread,i) = 0.6; }
if(4<n_iter<5) {F_PROFILE(f,thread,i) = 0.3; }


}






Right! Thank youuu!!
Could you help me again?
My function now is more ardous: at the end it makes the same job of the previous one, but now there isn't only one array, but seven arrays and everyone has 2174 elements. Furthermore my f_profile is more complicated. Fluent correctly interprets the function (why do you suggest me compiler mode?) but, during iterations it gives this error: "chip: invalid opcode".. what kind of mistake I'm making now?
Thank you!!!!
My UDF is:

#include "udf.h"
real x;
real y;
int t;
double A[2173];
double B[2173];
double C[2173];
double D[2173];
double E[2173];
double F[2173];
double G[2173];

DEFINE_PROFILE(mass_fraction_profile, thread, i)
{

int n_iter = RP_Get_Integer ("time-step");
real a[ND_ND];
face_t f;
begin_f_loop(f,thread)
{
F_CENTROID(a,f,thread);
x=a[0];
y=a[1];
/*initialize my arrays*/
A[577]=0.99765443333;
A[578]=58493022717118;
. . .
A[2750]=47392911.04883626;
B[577]=3447372.4947262;
. . .
B[2750];
// the same for C[], D[], E[], F[], G[]


if (n_iter<577)
{F_PROFILE(f,thread,i) =0;}
if (n_iter>2750)
{F_PROFILE(f,thread,i) =1;}
else
{ t=(n_iter-577);
F_PROFILE(f,thread,i) = A[t]*pow(((pow((x+0.0024),2))+(pow((y),2))),6))+ B[t]*pow(((pow((x+0.0024),2))+(pow((y),2))),5))+
C[t]*pow(((pow((x+0.0024),2))+(pow((y),2))),4))+
D[t]*(pow(((pow((x+0.0024),2))+(pow((y),2))),3))+
E[t]*(pow(((pow((x+0.0024),2))+(pow((y),2))),2))+
F[t]*((((x+0.0024),2))+(pow((y),2)))+G[t];}
}
end_f_loop (f,thread)
}
virgy is offline   Reply With Quote

Old   February 7, 2012, 04:37
Default
  #7
New Member
 
litter
Join Date: May 2011
Posts: 17
Rep Power: 14
litterfree is on a distinguished road
Quote:
Originally Posted by virgy View Post
Right! Thank youuu!!
Could you help me again?
My function now is more ardous: at the end it makes the same job of the previous one, but now there isn't only one array, but seven arrays and everyone has 2174 elements. Furthermore my f_profile is more complicated. Fluent correctly interprets the function (why do you suggest me compiler mode?) but, during iterations it gives this error: "chip: invalid opcode".. what kind of mistake I'm making now?
Thank you!!!!
My UDF is:

#include "udf.h"
real x;
real y;
int t;
double A[2173];
double B[2173];
double C[2173];
double D[2173];
double E[2173];
double F[2173];
double G[2173];

DEFINE_PROFILE(mass_fraction_profile, thread, i)
{

int n_iter = RP_Get_Integer ("time-step");
real a[ND_ND];
face_t f;
begin_f_loop(f,thread)
{
F_CENTROID(a,f,thread);
x=a[0];
y=a[1];
/*initialize my arrays*/
A[577]=0.99765443333;
A[578]=58493022717118;
. . .
A[2750]=47392911.04883626;
B[577]=3447372.4947262;
. . .
B[2750];
// the same for C[], D[], E[], F[], G[]


if (n_iter<577)
{F_PROFILE(f,thread,i) =0;}
if (n_iter>2750)
{F_PROFILE(f,thread,i) =1;}
else
{ t=(n_iter-577);
F_PROFILE(f,thread,i) = A[t]*pow(((pow((x+0.0024),2))+(pow((y),2))),6))+ B[t]*pow(((pow((x+0.0024),2))+(pow((y),2))),5))+
C[t]*pow(((pow((x+0.0024),2))+(pow((y),2))),4))+
D[t]*(pow(((pow((x+0.0024),2))+(pow((y),2))),3))+
E[t]*(pow(((pow((x+0.0024),2))+(pow((y),2))),2))+
F[t]*((((x+0.0024),2))+(pow((y),2)))+G[t];}
}
end_f_loop (f,thread)
}
so complicated...
then i recommend you to read the content of"file operate"of"C Programme"

by the way. what is the problem you simulate
__________________
never ever give up
litterfree is offline   Reply With Quote

Old   February 7, 2012, 05:17
Default
  #8
New Member
 
Join Date: Apr 2011
Location: Italy
Posts: 9
Rep Power: 14
virgy is on a distinguished road
Quote:
Originally Posted by litterfree View Post
so complicated...
then i recommend you to read the content of"file operate"of"C Programme"

by the way. what is the problem you simulate

The profile has to change every time Fluent changes time step (my simulation now is transient with a fixed physical time step = 0.9 s).

I'd like to simulate a drug that enters in the pipe only after 8.6 minutes (577*0.9 s). It enters with a profile variabile in time, and after 41.25 minutes (2750*0.9 s) it enters with a constant mass fration=1.

The arrays A, B, C, D, E, F, G contain coefficients to multiply to the raidius of my pipe: ((pow((x+0.0024),2))+(pow((y),2))
the variable t=(n_iter-577) means:
timestep=1 --> t=577-577=0 --> in my f_profile: A[0], B[0], C[0]...G[0].
timestep=2 --> t=578-577=1 --> in my f_profile: A[1], B[1], C[1]...G[1].
...
timestep=2173 --> t=2750-577=2173 --> in my f_profile A[2173], B[2173]...G[2173].

So the profile of mass fraction changes every time step.

In particular: if time step < 577 I'd like the mass fraction is always 0;
if time step > 2750 I'd like the mass fraction is always 1.

P.s. Where I can find "file operate"of"C Programme"?
virgy is offline   Reply With Quote

Old   February 7, 2012, 05:30
Default
  #9
New Member
 
litter
Join Date: May 2011
Posts: 17
Rep Power: 14
litterfree is on a distinguished road
Quote:
Originally Posted by virgy View Post
The profile has to change every time Fluent changes time step (my simulation now is transient with a fixed physical time step = 0.9 s).

I'd like to simulate a drug that enters in the pipe only after 8.6 minutes (577*0.9 s). It enters with a profile variabile in time, and after 41.25 minutes (2750*0.9 s) it enters with a constant mass fration=1.

The arrays A, B, C, D, E, F, G contain coefficients to multiply to the raidius of my pipe: ((pow((x+0.0024),2))+(pow((y),2))
the variable t=(n_iter-577) means:
timestep=1 --> t=577-577=0 --> in my f_profile: A[0], B[0], C[0]...G[0].
timestep=2 --> t=578-577=1 --> in my f_profile: A[1], B[1], C[1]...G[1].
...
timestep=2173 --> t=2750-577=2173 --> in my f_profile A[2173], B[2173]...G[2173].

So the profile of mass fraction changes every time step.

In particular: if time step < 577 I'd like the mass fraction is always 0;
if time step > 2750 I'd like the mass fraction is always 1.

P.s. Where I can find "file operate"of"C Programme"?
your problem is some what like mine. do the pipe absorb the drug?
"file oprate" is the content of C programme ,did you study it at university?
you also can search it on internet.
i have it ,but i am afraid that you can not understand the language.haha...
and what is your email?
__________________
never ever give up
litterfree 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
Error message: Insufficient Catalogue Size Paresh Jain CFX 32 February 3, 2021 04:37
Multiple floating objects CKH OpenFOAM Running, Solving & CFD 14 February 20, 2019 10:08
mass flow in is not equal to mass flow out saii CFX 12 March 19, 2018 06:21
Water subcooled boiling Attesz CFX 7 January 5, 2013 04:32
Define mass fraction for -ve velocity inlet/outlet KKLAU FLUENT 1 June 14, 2004 15:23


All times are GMT -4. The time now is 06:05.