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

Assigning mass using UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By `e`

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 16, 2015, 01:31
Default Assigning mass using UDF
  #1
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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
Bharadwaj B S is offline   Reply With Quote

Old   March 16, 2015, 02:48
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   March 16, 2015, 03:27
Default Clarification
  #3
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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
Bharadwaj B S is offline   Reply With Quote

Old   March 16, 2015, 04:09
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   March 16, 2015, 04:49
Default Sphere
  #5
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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
Bharadwaj B S is offline   Reply With Quote

Old   March 16, 2015, 05:35
Default
  #6
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   March 16, 2015, 06:56
Default Some changes
  #7
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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
Bharadwaj B S is offline   Reply With Quote

Old   March 16, 2015, 17:00
Default
  #8
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   March 17, 2015, 04:37
Default Thanks a ton
  #9
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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
Bharadwaj B S is offline   Reply With Quote

Old   March 17, 2015, 09:11
Default Not working
  #10
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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
Bharadwaj B S is offline   Reply With Quote

Old   March 17, 2015, 16:20
Default
  #11
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Did you place the global variable declaration outside of the DEFINE_PROFILE macro, and can you provide this code?
`e` is offline   Reply With Quote

Old   March 19, 2015, 01:10
Default UDF-global declaration
  #12
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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)
}
}
}
Bharadwaj B S is offline   Reply With Quote

Old   March 19, 2015, 01:20
Default Only Global
  #13
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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
Bharadwaj B S is offline   Reply With Quote

Old   March 19, 2015, 07:02
Default
  #14
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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);
If there are many faces set with this DEFINE_PROFILE, then perhaps restrict this message to one face to avoid a huge list of messages in the console (or use a very coarse mesh for this development stage).
`e` is offline   Reply With Quote

Old   March 19, 2015, 07:32
Default Thank you
  #15
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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
Bharadwaj B S is offline   Reply With Quote

Old   March 30, 2015, 08:52
Default Solved
  #16
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
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
Bharadwaj B S is offline   Reply With Quote

Old   March 30, 2015, 09:19
Default
  #17
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
No problem, that's great to hear you've managed to resolve the issues.
Bharadwaj B S likes this.
`e` is offline   Reply With Quote

Reply


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


All times are GMT -4. The time now is 17:20.