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

UDF for DPM modelling to simulate ammonia absorption into water droplets

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 31, 2021, 07:52
Default UDF for DPM modelling to simulate ammonia absorption into water droplets
  #1
New Member
 
Join Date: Mar 2021
Posts: 25
Rep Power: 5
Jack0210Jack is on a distinguished road
Hi,

I am new to udf and c programming. Currently I am working on a project to simulate ammonia absorption into water droplets using two-film theory and DPM. I have read the udf manuals and researching online for examples to come up with codes below:

Code:
#include "udf.h"

DEFINE_DPM_HEAT_MASS(nh3absorption, tp, Cp, hgas, hvap, cvap_surf, Z, dydt, dzdt)
{
	int is;
	int nc = TP_N_COMPONENTS(tp); /*number of particle components*/
	real gas_index;
	printf("\n######");
	for (is = 0; is < nc; is++)
	{
		int gas_index = TP_COMPONENT_INDEX_I(tp, is); /* index of vaporizing component in the gas phase */
		printf(" gas_index=%d is=%d TP_COMPONENT_I=%e ", gas_index, is, TP_COMPONENT_I(tp, is));
	}
	printf("#######$\n");
	Thread* t0 = P_CELL_THREAD(tp); /*thread where the particle is in*/
	Material* gas_mix = THREAD_MATERIAL(DPM_THREAD(t0, tp)); /*gas mixture material*/
	Material* cond_mix = P_MATERIAL(tp); /*particle mixture material*/
	cphase_state_t** c0 = &(tp->cphase); /*cell information of particle location*/

	real yi_NH3_l; /*mass fraction of ammonia in particle*/
	for (yi_NH3_l = 0; yi_NH3_l < 1; ++TP_COMPONENT_I(tp, is))
	{
		Domain* d; /* Get domain pointer */
		real T; /*Temperature*//*[K]*/
		real yi_NH3_g;
		real den_g;
		Thread* t;
		cell_t c;
		int i;
		d = Get_Domain(1);
		/* Loop over all cell threads in domain */
		thread_loop_c(t, d)
		{
			/* Loop over all cells */
			begin_c_loop(c, t)
			{
				{
					T = C_T(c, t);
					yi_NH3_g = C_YI(c, gas_index, 4); /*mass fraction of ammonia in air*/
					den_g = C_R(c, gas_index); /*density of air*/
				}
			}
			end_c_loop(c, t);
		}

		real MW_NH3 = 17.031e-3; /*Molecular mass of ammonia*//*[kg/mol]*/

		real C_g = yi_NH3_g * den_g / MW_NH3; /*molar concentration of NH3 in air*//*[mol/m3]*/
		real P_g = C_g * 8.314 * T; /*partial pressure of ammonia in air*/

		real den_l = P_RHO(tp); /*density of particle*/
		real C_l = yi_NH3_l * den_l / MW_NH3; /*molar concentration of ammonia in water droplet*//*[mol/m3]*/

		real H = 0.59 * exp(4200 * ((1 / T) - 1 / (298.15)));	/*Henry Constant*//*[mol/(m3*Pa)]*/

		real mp = P_MASS(tp); /* particle mass */
		real Dp = DPM_DIAM_FROM_VOL(mp / P_RHO(tp)); /* particle diameter */
		real Ap = DPM_AREA(Dp); /*particle surface area*/
		real v = NV_MAG(P_VEL(tp)); /*water droplet velocity*/
		real vg = 15.69e-6;	/*kinematic viscosity of air*//*[m2/s]*/
		real Re = Dp * v / vg;

		real D = 1.64e-7; /*molecular diffusivity coefficient*//*[m/s]*/
		real Sc = vg / D;

		real ky = 2.0 + 0.6 * sqrt(Re) * pow(Sc, 1. / 3.); /*mass transfer coefficient in liquid phase*/

		real NA = ky * (P_g - H * C_l); /*Mass transfer flux of ammonia*/
		dydt[2] = NA;
	}
	return;
}
After compiling it in Fluent, 2 error messages pop up:

Quote:
..\..\src\nh3absorption.c(39): error C2223: left of '->storage' must point to struct/union
..\..\src\nh3absorption.c(40): error C2223: left of '->storage' must point to struct/union
Does anyone know how should I fix it? Thanks.

Quote:
The idea of this project is to simulate the ammonia absorption into water droplet. Water droplet will be injected via DPM and ammonia absorption will be added via udf. When the ammonia mass fraction in water droplet is less than 1, the ammonia will be absorbed into the water droplet and the mass transfer rate is based on the mass fraction of ammonia in water droplet.
Jack0210Jack is offline   Reply With Quote

Old   March 31, 2021, 13:26
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You added a loop over all cells. But you use only info from the last cell, which is chosen by fluent. It makes no sense.

Go back to your old udf, replace c by c0, and you will use the gas density at the location of the particle.
If you want the gas density somewhere else (why would you?) explain what you want.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   March 31, 2021, 13:42
Default
  #3
New Member
 
Join Date: Mar 2021
Posts: 25
Rep Power: 5
Jack0210Jack is on a distinguished road
Thanks. I think I have more understanding on this. Initially I assumed c0 is where the cell that has particle and the particle = cell. Now if I'm not wrong, c0
is the cell that holds the particle and the spaces surrounding the particle.

So based on your suggestions, I changed it to
Code:
real T = C_T(c0, t0); /*Temperature*//*[K]*/
real yi_NH3_g = C_YI(c0, t0, 4); /*mass fraction of ammonia in air*/
real den_g = C_R(c0, t0); /*density of air*/
and removed the Get_Domain functions.

However, here comes new errors
Quote:
error C2107: illegal index, indirection not allowed
for these 3 lines.

btw, I have changed this line
Code:
cphase_state_t** c0 = &(tp->cphase); /*cell information of particle location*/
into
Code:
cphase_state_t* c0 = &(tp->cphase); /*cell information of particle location*/
as suggested even though I'm receiving this warning
Quote:
warning C4047: 'initializing': 'cphase_state_t *' differs in levels of indirection from 'cphase_state_t **'
Hopefully the warning can be ignored.

Thanks.
Jack0210Jack is offline   Reply With Quote

Old   March 31, 2021, 14:52
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You first had
Code:
cell_t c0 = P_CELL(tp); /*cell where the particle is in*/
As definition for c0. What's wrong with that? Why change it?
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   March 31, 2021, 15:00
Default
  #5
New Member
 
Join Date: Mar 2021
Posts: 25
Rep Power: 5
Jack0210Jack is on a distinguished road
Oh gawd, no more error now.

At first due to that misunderstanding I thought that line was useless and I changed "cphase_state_t** c" into "cphase_state_t** c0" since I wanted to use "c" variable in Get_Domain below. Thanks for reminding me those lines have been modified when I rearrange the codes.

Now only left this error to be solved which I think it is related to Environment Variables
Quote:
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
Your help is very much appreciated. Thank you.
Jack0210Jack is offline   Reply With Quote

Old   March 31, 2021, 15:26
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Hmm, that one is probably Fluent installation/configuration. Don't know much about that, sorry...
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   March 31, 2021, 16:15
Default
  #7
New Member
 
Join Date: Mar 2021
Posts: 25
Rep Power: 5
Jack0210Jack is on a distinguished road
No worries. You and others have helped me a lot. Hopefully I can get the results I want from this udf.

Thank you.
Jack0210Jack is offline   Reply With Quote

Old   April 1, 2021, 07:38
Default
  #8
New Member
 
Join Date: Mar 2021
Posts: 25
Rep Power: 5
Jack0210Jack is on a distinguished road
Hi, I need helps again.

So after all those editing, the file shows no error after I "build". But when I want to load the codes, it shows

Quote:
LINK : fatal error LNK1104: cannot open file 'kernel32.lib'
Some people said it is related to SDKs path or compability or environmental variables. I then checked a few solutions and decided to install VS 2012 (that time I was using VS 2019). Which means I had 2 VS at that time.

By installing VS 2012, the LINK error has been solved. But it came up another error:

Quote:
the udf library you are trying to load (libudf) is not compiled for parallel use
I then try anything I could think of and find, like using series instead of parallel, etc. But after I uninstalled both VS and reinstalled VS 2012 only, suddenly errors appears:

Quote:
error C2275: 'Thread' : illegal use of this type as an expression
error C2065: 't0' : undeclared identifier
Quote:
error C2275: 'cell_t' : illegal use of this type as an expression
error C2146: syntax error : missing ';' before identifier 'c0'
error C2065: 'c0' : undeclared identifier
Quote:
error C2275: 'Material' : illegal use of this type as an expression
error C2065: 'gas_mix' : undeclared identifier
error C2065: 't0' : undeclared identifier
error C2223: left of '->sub_threads' must point to struct/union
fatal error C1903: unable to recover from previous error(s); stopping compilation
which refer to lines below
Code:
Thread* t0 = P_CELL_THREAD(tp); /*thread where the particle is in*/
Code:
cell_t c0 = P_CELL(tp); /*cell where the particle is in*/
Code:
Material* gas_mix = THREAD_MATERIAL(DPM_THREAD(t0, tp)); /*gas mixture material*/
I have not change anything in the udf and I saw some people mention they have this issue when they use diff VS, so I reinstalled VS 2019 too, but the errors still persist. Besides, the last error (fatal error C1903) seems like telling me the compiler cannot compile lines after line 16.

I have tried with another code which I copied from udf manual and this code shows no errors like the the above mentioned (Thread, LINK, ...not compiled for parallel use)
Code:
#include "udf.h"
DEFINE_ADJUST(my_adjust, d)
{
	Thread* t;
	/* Integrate dissipation. */
	real sum_diss = 0.;
	cell_t c;
	thread_loop_c(t, d)
	{
		begin_c_loop(c, t)
			sum_diss += C_D(c, t) *
			C_VOLUME(c, t);
		end_c_loop(c, t)
	}
	printf("Volume integral of turbulent dissipation: %g\n", sum_diss);
}
If you may, please guide me once again. Thank you.
Jack0210Jack is offline   Reply With Quote

Old   April 1, 2021, 09:16
Default
  #9
New Member
 
Join Date: Mar 2021
Posts: 25
Rep Power: 5
Jack0210Jack is on a distinguished road
UPDATE

I think the issue lies within the compiler. So I tried with Ansys 2020 R2 and it doesn't show any errors I mentioned above now.

Once again, thank you.
Jack0210Jack is offline   Reply With Quote

Old   December 28, 2023, 02:36
Default
  #10
New Member
 
Zain
Join Date: Dec 2023
Posts: 1
Rep Power: 0
hanzain is on a distinguished road
Hi guys, I am just wondering with this udf what species transport model and multiphase model has been used? Do we define any reactions with it. Thank you
hanzain 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
mass flow in is not equal to mass flow out saii CFX 12 March 19, 2018 06:21
Need help to Simulate Phase change of Water liquid after mixing with Hot Air Stream diineshns FLUENT 0 March 17, 2018 07:14
Modelling free falling water into a air filled duct? sandmike_83 CFX 4 August 24, 2010 04:27
Constant velocity of the material Sas CFX 15 July 13, 2010 09:56
Modelling of bubble merging submerge on water Carlos Main CFD Forum 0 October 26, 2005 10:30


All times are GMT -4. The time now is 01:42.