# Simulation with UDF for species mass fraction and velocity profile

 Register Blogs Members List Search Today's Posts Mark Forums Read November 18, 2011, 06:19 Simulation with UDF for species mass fraction and velocity profile #1 New Member   Join Date: Apr 2011 Location: Italy Posts: 9 Rep Power: 13 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; y=n; F_YI(f,thread,nv)= coeff-(coeff/r2) * ( (pow((x),2))+(pow((y),2)) ); } end_f_loop (f,thread) } Thanks a lot, Virgy   November 25, 2011, 03:34 #2 New Member   litter Join Date: May 2011 Posts: 17 Rep Power: 13 F_YI(f,thread,nv) ???-----> F_PROFILE(f,thread,nv)??? virgy likes this. __________________ never ever give up    November 25, 2011, 05:37 UDF for profile with fopen function
#3
New Member

Join Date: Apr 2011
Location: Italy
Posts: 9
Rep Power: 13 Quote:
 Originally Posted by litterfree 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; // the array with coefficients for my profile of species

FILE *fp; // pointer for the function fopen

{
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;

{

x=a;
y=a;

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

fclose (fp);
}
}

My file "coefficients.txt":

A=0.1;
A=0.05;
A=1;
A=0.6;
A=0.3;

Thank you!! Virgy   February 7, 2012, 02:34 #4
New Member

litter
Join Date: May 2011
Posts: 17
Rep Power: 13 Quote:
 Originally Posted by virgy 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; y=n; 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    February 7, 2012, 02:59 #5
New Member

litter
Join Date: May 2011
Posts: 17
Rep Power: 13 Quote:
 Originally Posted by virgy 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; // 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; y=a; 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.1; A=0.05; A=1; A=0.6; A=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.

you can achieve the function in other simple way.

#include "udf.h"

{
int n_iter = RP_Get_Integer ("time-step");

}
__________________
never ever give up    February 7, 2012, 04:20 #6
New Member

Join Date: Apr 2011
Location: Italy
Posts: 9
Rep Power: 13 Quote:
 Originally Posted by litterfree 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

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;
double B;
double C;
double D;
double E;
double F;
double G;

{

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

if (n_iter<577)
if (n_iter>2750)
else
{ t=(n_iter-577);
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];}
}
}   February 7, 2012, 04:37 #7
New Member

litter
Join Date: May 2011
Posts: 17
Rep Power: 13 Quote:
 Originally Posted by virgy 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; double B; double C; double D; double E; double F; double G; 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; y=a; /*initialize my arrays*/ A=0.99765443333; A=58493022717118; . . . A=47392911.04883626; B=3447372.4947262; . . . B; // 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    February 7, 2012, 05:17 #8
New Member

Join Date: Apr 2011
Location: Italy
Posts: 9
Rep Power: 13 Quote:
 Originally Posted by litterfree 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, B, C...G.
timestep=2 --> t=578-577=1 --> in my f_profile: A, B, C...G.
...
timestep=2173 --> t=2750-577=2173 --> in my f_profile A, B...G.

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"?   February 7, 2012, 05:30 #9
New Member

litter
Join Date: May 2011
Posts: 17
Rep Power: 13 Quote:
 Originally Posted by virgy 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, B, C...G. timestep=2 --> t=578-577=1 --> in my f_profile: A, B, C...G. ... timestep=2173 --> t=2750-577=2173 --> in my f_profile A, B...G. 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...
__________________
never ever give up   Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Display Modes Linear Mode Switch to Hybrid Mode Switch to Threaded Mode 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 OffTrackbacks are Off Pingbacks are On Refbacks are On Forum Rules Similar Threads Thread Thread Starter Forum Replies Last Post Paresh Jain CFX 32 February 3, 2021 04:37 CKH OpenFOAM Running, Solving & CFD 14 February 20, 2019 10:08 saii CFX 12 March 19, 2018 06:21 Attesz CFX 7 January 5, 2013 04:32 KKLAU FLUENT 1 June 14, 2004 15:23

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