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

Help with unsteady calculation with source/sink UDF

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 8, 2016, 06:03
Default Help with unsteady calculation with source/sink UDF
  #1
New Member
 
Rob Vervoort
Join Date: Nov 2015
Posts: 23
Rep Power: 11
RobV is on a distinguished road
Hello everyone,

i am experiencing some problems with a UDF related to species transport in Fluent.

The goal of my simulation is to model the effect of a filter unit, which filters out a certain concentration of species in the mixture template (with a certain efficiency).

The filter unit does not have to be simulated as a whole, therefore I simplified the simulation by making a channel with a sink term in it.

I made the following UDF for the sink term (also attached to the thread).

#include "udf.h"
/* UDF for sink term PM10 */
/*---------------------------------------------------------------------*/
DEFINE_SOURCE(filter_pm10,c,t,dS,eqn) /* function name, thread and variable number */
/*In fluent, concentrations of the species are given as mass fraction or parts per million */
/*Source term has to be specified in kg/m3-s, calculations have to be performed for the transformation */
{
real x[ND_ND];
int source;
real U_f = 3.0; /* Fill in the velocity of the inlet channel */
/* real h_f = 0.6; /* Fill in the height of the filter unit */
/* real f_f = h_f * U_f; /* Calculate the volume flow of the filter unit */
real l_icz = 0.0655; /* Fill in the length of the inlet cell zone */
real l_f = 1.8; /* Fill in the length of the filter unit */
real f_t = (l_f-l_icz) / U_f; /* Calculation of the duration of the flow through the filter unit */
real PM10_eff = 1.0; /* Fill in the efficiency of the flter*/
real rho = C_R(c,t); /* Obtaining the density of the fluid */
real YI = C_YI(c,t,0); /* Obtaining the mass fraction of the species - index 0 -> pm10*/
real YI_PPM = YI * (1*10^6); /* Converting the mass fraction of the species into PPM */
/* PPM = mass species x [mg] / mass species total [kg]*/
/* PPM = concentration species x [mg/m3] / density species total [kg/m3]*/
/* concentration species x [mg/m3] = PPM * density species total [kg/m3]*/
/* concentration species x [kg/m3] = concentration species x [mg/m3] * 10^-6 */
real YI_kg_m3 = (YI_PPM * rho) * (10^(-6)); /* Converting the mass fraction/PPM of the species into concentration [kg/m3] */
/* Air moves through the filter within a certain time and has a certain efficiency for that time*/
/* source term requires the input unit kg/m3-s*/
/* Calculating the concentration that moves through the unit per second*/
real YI_kg_m3_s = YI_kg_m3 / f_t; /*obtained unit kg/m3-s*/
C_CENTROID(x,c,t);
source = -1* (YI_kg_m3_s * PM10_eff); /*source term in kg/m3-s (results in a negative number = sink) */
dS[eqn] = 0;
/*message("The density of the fluid: %d\n", rho);
message("The mass fraction of pm10: %d\n", YI);
message("pm10 PPM: %d\n", YI_PPM);
message("concentration pm10 [kg/m3]: %d\n", YI_kg_m3);
message("concentration pm10 through the filter [kg/m3-s]: %d\n", YI_kg_m3_s);
message("filtered amount of pm10 based on efficiency [kg/m3-s]: %d", source); */
printf("filtered amount of pm10 based on efficiency [kg/m3-s]: %d\n", source);
 
return source;
}


How it should work:

The sink term has to be based on the instantenous species concentrations in each time step of the simulation in the channel that was modelled. Imagine a PM10 concentration of 'x' at timestep 't', the sink term has to be 'x' times the efficiency of the filter. The sink term has to be updated at each time step 't'.

I did some test simulations with the UDF and I noticed that the decay of the concentrations is linear. I modelled a closed volume with a fixed concentration at t=0 and subsequently I plotted the decay of the concentraions.

I expected the decay to be exponential since when the concentrations become lower, also a lower amount of species is filtered out of the domain.

To check if all the variables (in the UDF) that are used in the calculation are correct, I wanted to print the values of these variables in the fluent console at each time step (using printf or message as visible in the .c file). The values that are printed in the console are Always '0'.

Could anyone help me with my UDF? Is this the correct way to make a UDF for a unsteady RANS simulation? Why is the printing of the variables used in the UDF going wrong?

Thank you in advance,

Rob
Attached Files
File Type: c source_terms_filter.c (6.2 KB, 9 views)
RobV is offline   Reply With Quote

Old   March 8, 2016, 06:33
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
The printed values are always zero because you print them in the wrong way.

You use:
Code:
message("The density of the fluid: %d\n", rho);
Because you use "%d", an integer will be printed. The value is between zero and one, so it will be truncated to zero.
Instead, use for example
Code:
message("The density of the fluid: %f\n", rho);
The "%f" will make it a float, and then you get the true value of rho. Likewise for the other lines.

I did not look at the other aspects of your code.
pakk is offline   Reply With Quote

Old   March 8, 2016, 08:17
Default
  #3
New Member
 
Rob Vervoort
Join Date: Nov 2015
Posts: 23
Rep Power: 11
RobV is on a distinguished road
Thank you for your reply.
The printing works now, the UDF uses the instantenous values which is good.
However, the filter is not yet represented in a good manner.

At the inlet of the channel with dimension x*y (in this case 2D 1.8 * 0.6 m2) a cell zone is created with a fixed velocity based on the volume flow of the filter unit.
Behind the cell zone with the fixed velocity, there is a cell zone with a source term. This cell zone has the dimensions of the entire channel.



In my domain there is a mixture of four species, 3 pollutants and air. The filter unit has a certain efficiency for the removal of the 3 pollutants (e.g. 100-50-20%).
The goal is that over the length of the channel, the concentrations of the pollutants are reduced with the given efficiency.

How can I create this UDF in an efficient way? I attached my updated version of the UDF, since I worked with cell based values, I think this is not the correct way to model the filter.
Are there any suggestions?

Thank you in advance,
Rob
Attached Files
File Type: c source_terms_filter.c (6.7 KB, 7 views)

Last edited by RobV; March 8, 2016 at 12:43.
RobV is offline   Reply With Quote

Old   March 10, 2016, 04:45
Default
  #4
New Member
 
Rob Vervoort
Join Date: Nov 2015
Posts: 23
Rep Power: 11
RobV is on a distinguished road
UPDATE:

to see whether the UDF works correctly in the simulation I plotted some results. These results only regard the PM10 part of the udf.

In the UDF the concentration of the species, that has to leave to domain per second at the sink term, is calculated. For the PM10 species, it is specified that all of the species has to be removed from the domain (PM10_eff = 1).

When I plot the mass fraction of pm10 over the filter channel (visible in the figure below), the decay is clearly visible. The efficiency based on the simulation is calculated by dividing the mass fraction at the outlet by the mass fraction at the inlet. It is clearly visible that the efficiency remains constant over all time steps, which is good.




However, the specified efficiency is 1 and not 0.62 as calculated from the simulation results. Therefore I thought something was wrong with the value of the sink term. According to the simulation, to obtain a efficiency of 1, the value of the sink term has to be increased with a factor 1/0.62.

I ran the simulation with the new value of the sink term and the results were not as I expected (figure below).



Again the efficiency in the figure was calculated by dividing the mass fraction of the species at the outlet by the mass fraction of the species at the inlet.

What I would like to get in my simulation is that the instantenous mass fractions of the species (at the inlet) are used to obtain a decay of concentration from the inlet to the outlet of the channel (using a sink term) with a certain factor (efficiency). For now it is just a 2D simulation but eventually it has to become a 3D simulation.

Could someone help me out with this problem?

Last edited by RobV; March 10, 2016 at 06:27.
RobV 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
UDF Unsteady velocity parabolic profile Rashad FLUENT 3 October 1, 2018 16:27
UDF to update C_T(c,t) with Unsteady Flamelet Values clarkie_49 Fluent UDF and Scheme Programming 5 September 19, 2013 18:27
unsteady statistics for UDF Luis FLUENT 0 April 16, 2008 16:45
unsteady calculation and Nusselt averaging elyyan FLUENT 0 August 4, 2006 15:32
UDF :Unsteady concentration profile umesh FLUENT 4 July 13, 2003 18:07


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