|
[Sponsors] |
March 16, 2015, 01:31 |
Assigning mass using UDF
|
#1 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Hi all,
I have a sphere inside a cylindrical flow domain of some diameter. The flow domain will be having velocity inlet on one side and pressure outlet on other side. QUESTION: To the sphere at the center I need to assign some mass say 1 kg. Is there any way of assigning "mass" to the sphere using UDF? I know that I can patch some mass after initialization. But since I am going to change that as the time goes by, I need to assign "mass" only with UDF. To be specific, what type of "macro" I should use to provide mass(like DEFINE_SOURCE or any other)?? Any help is of great use for me. Thanks in advance, Bharadwaj B S |
|
March 16, 2015, 02:48 |
|
#2 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Is the sphere another fluid or a solid? Mass can be changed on a cell-by-cell basis by modifying the cell density with a macro: C_R(c,t).
Could the sphere move during the simulation? Otherwise you could add the sphere at the geometry stage and mesh around the sphere if it's stationary. |
|
March 16, 2015, 03:27 |
Clarification
|
#3 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Dear e,
First of all thanks a lot for your speedy reply, the sphere is physically solid, but since I have to assign mass, I changed that to fluid. And the sphere is static. There will not be any movement to it. Thank you, Bharadwaj B S |
|
March 16, 2015, 04:09 |
|
#4 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
If the sphere is solid, then what effect does the mass have on the simulation? Why can't you simply mesh around this sphere?
You can set a density (and subsequently mass) for solid cell types as well. |
|
March 16, 2015, 04:49 |
Sphere
|
#5 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Dear e,
The problem is basically on gasification of wood(biomass). i.e, when the hot air flows over the sphere. The sphere is heated. This wood(sphere) contains some gases, which will be removed from the surface of the sphere. So this mass of gases I want to specify inside the sphere volume. As the time passes with temperature this mass should reduce gradually at some rate. thank you, Bharadwaj B S |
|
March 16, 2015, 05:35 |
|
#6 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Are you wanting to simulate the heating of the sphere with the energy equation, or is the only relevant attribute of the sphere the rate of gas release?
If the gas is released from the sphere surface at a constant rate (or any pre-determined rate and/or not coupled with the temperature of the sphere), you could simply specify a boundary condition flux (with DEFINE_PROFILE) and not mesh the inside of the sphere. Otherwise if you're trying to simulate the transient temperature of the sphere (perhaps from ambient temperature towards the hot air temperature) then you'll need to model it as a solid. Then your UDF could regulate the gas flux from the sphere as a function of its temperature. |
|
March 16, 2015, 06:56 |
Some changes
|
#7 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Dear e,
Mass flow rate is "not" dependent on temperature as such for now. Now my intention is to define some variable in UDF and with the known rate I will reduce that every iteration. Based on the value of this "mass" variable, I have to give whether there should be "mass flow rate" or "not". Eg; I will define in UDF "mass=1.0" and I will reduce that by 0.2 every iteration. So effectively the total number of iterations needed for "mass" to be zero is "5". Now when this "mass" becomes zero, mass flow rate from the surface of the sphere should be zero. (F_PROFILE(f,t,i) should be zero =0.0). Yes as you said I have modeled it as "solid". And trying to apply this condition to the surface. Thank you, Bharadwaj B S |
|
March 16, 2015, 17:00 |
|
#8 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Ok, instead of naming the variable 'mass', maybe call it 'myMassFraction' to avoid confusing it with the mass of the fluid and/or solid. This variable needs to be global and accessible from your DEFINE_PROFILE through time (not reset at each time step as you have currently coded). Here is a thread discussing global variables and if that doesn't work, perhaps you could save the variable to a text file and then read/write it back each time.
|
|
March 17, 2015, 04:37 |
Thanks a ton
|
#9 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Dear e,
Thank you, I will go through the thread and do the necessary changes. I will post the results in the next post. Thanks and regards, Bharadwaj B S |
|
March 17, 2015, 09:11 |
Not working
|
#10 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Dear e,
I tried to run with variables defined globally. Still I was getting mass flow rate from the surface of the sphere for all iterations even though the "mass" value reduced to "zero" (from my calculations for 0.5 decrement and initial value of "mass" being 1.0). In the thread for global declaration, nothing was mentioned for global declaration whether the value declared globally will be used and deleted every time or not. There was only clue that variables specified locally with static declaration will not be used and destroyed. Now is there any other way of declaring globally?? Thank you, Bharadwaj B S |
|
March 17, 2015, 16:20 |
|
#11 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Did you place the global variable declaration outside of the DEFINE_PROFILE macro, and can you provide this code?
|
|
March 19, 2015, 01:10 |
UDF-global declaration
|
#12 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Dear e,
Sorry for replying late. I was busy with experimental works on my project. These are the changes I made. Please go through and suggest me if there are any mistakes. UDF: #include "udf.h" Thread *t; static float mass = 1.0; int j; DEFINE_PROFILE(flux, t, i) { Domain *d; int ID = 13; face_t f; real decrement = 0.2; float flwrt = -0.5; for(j=2;j>0;j=j-1) { mass=mass-(decrement); if(mass>0.0&&mass<1.0) { begin_f_loop(f, t)/*for looping over the required sphere surface*/ { d = Get_Domain(1); t = Lookup_Thread(d, ID); F_PROFILE(f, t, i) = -flwrt; } end_f_loop(f,t) } } } |
|
March 19, 2015, 01:20 |
Only Global
|
#13 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Dear e,
I tried to make only changes for declaration. But still it was giving me "mass flow rate" for all the iterations. And then I have tried writing the values to the data file in the below UDF. But I could not read that as a text file. It was saved as "data file". Do you know any other way of opening this data file as text, so that we could get to know what is happening with the iterations. UDF #include "udf.h" Thread *t; Domain *d; int j=0; real mass; real decrement = 0.5; DEFINE_RW_FILE(reader, fp) { fscanf(fp,"%f",&mass); } DEFINE_PROFILE(flux, t, i) { int ID = 13; face_t f; real flwrt = -0.5; if(mass>0.0&&mass<=1.0) { begin_f_loop(f, t) { d = Get_Domain(1); t = Lookup_Thread(d, ID); F_PROFILE(f, t, i) = -flwrt; } end_f_loop(f,t) } } DEFINE_ADJUST(decrmnt,d) { source=1.0; mass=mass-decrement; } DEFINE_RW_FILE(writer, fp) { fprintf(fp,"%f",mass); } Thank you, Bharadwaj B S |
|
March 19, 2015, 07:02 |
|
#14 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
You can print messages to the Fluent console by using the Message() function, for example (where myid is the process ID and you don't declare this variable):
Code:
Message("%d: The current mass is %e\n",myid,mass); |
|
March 19, 2015, 07:32 |
Thank you
|
#15 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Dear e,
Thanks a lot for your suggestions. I will try message() function and see if the value of mass is getting reduced or not, every iteration. I will post the results soon. Thank you, Bharadwaj B S |
|
March 30, 2015, 08:52 |
Solved
|
#16 |
Member
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11 |
Dear e,
Your suggestion on using Message() was of great help. I was able to debug the program with the Message() function. It took more days but I was able to resolve it very recently. Thank you very much for your valuable time and suggestions. Regards, Bharadwaj B S |
|
March 30, 2015, 09:19 |
|
#17 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
No problem, that's great to hear you've managed to resolve the issues.
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Disappearing mass when using udf inlet profile | divergence | Fluent UDF and Scheme Programming | 5 | January 2, 2021 15:56 |
WILLING TO PAY/ FREELANCER REQUIRED / small UDF coding force loads over body / 6DOF | acasas | CFD Freelancers | 1 | January 23, 2015 08:26 |
Problems regarding mass transfer UDF | Yifan_G | Fluent UDF and Scheme Programming | 8 | December 8, 2014 11:21 |
UDF for Mass Flow at the Outlet: ERROR ACCESS VIOLATION | I-mech | Fluent UDF and Scheme Programming | 1 | May 23, 2014 13:37 |
writing UDF for modelig mass transfer for VOF | ardalan soleymani | FLUENT | 0 | July 11, 2007 02:09 |