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

UDMI and Define source marcro issue

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 14, 2021, 23:04
Thumbs up UDMI and Define source marcro issue
  #1
New Member
 
Hong P.z
Join Date: Apr 2021
Posts: 3
Rep Power: 5
iorl19 is on a distinguished road
Dear all (espailly Senior Member),

I am quite new with UDF so I am here to seek for some advice. Much appreciated if someone can tell me what is basic problem with my code.

Basically, I am writing an UDF to update the SO2 species sourece in air , then use these variables to calculate the species sourece for a steady case. I use:

1. DEFINE_INIT to set the initial values of variables, save them in UDMI .
2. DEFINE_ADJUST to calculate the vof of dpm , then calculate the absorption of so2 by my formula. Two variables are saved in two UDMI (0,1).
3. DEFINE_SOURCE purpose to calculate the value from UDMI(1).
4.I use fluent 15.0.7 and VS 2015


The code works very well with DEFINE_INIT, DEFINE_ADJUST(individually or combine), but when I hook up DEFINE_SOURCE, this error occurs ( already use compiled ).see q1.jpg
--------------------------------------------------------------------------
Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Error at host: floating point exception

Error at Node 0: floating point exception

Error at Node 1: floating point exception

Error at Node 2: floating point exception

Error at Node 3: floating point exception

Error at Node 4: floating point exception

Error at Node 5: floating point exception

-----------------------------------------------------------------------------------------
Attached MY UDF:
<pre>
#include "udf.h"

#define MW_SO2 64.0 /*Molecular mass of so2*//*[g/mol]*/
#define E_SO2 1.3 /*Enhansment of so2*//*[-]*/
#define c1 3.1016E-004 //MW_SO2 / ( 1.0 / k_SO2_g + H_SO2 / (k_SO2_l * E_SO2) )*[-]*
//#define mem_particle = 0. //UDM of particle vof
//#define mem_so2 = 1. //UDM of particle so2


/* 輸入 */

DEFINE_INIT(udm, domain)
{
Thread* t;
cell_t c;

thread_loop_c(t, domain)
{
begin_c_loop(c, t)
{
C_UDMI(c, t, 0) = 0.0;
C_UDMI(c, t, 1) = 0.0;
C_UDMI(c, t, 2) = 0.0;
C_UDMI(c, t, 3) = 0.0;
C_UDMI(c, t, 4) = 0.0;
C_UDMI(c, t, 5) = 0.0;
}
end_c_loop(c, t)
}
}

DEFINE_ADJUST(dpm_vof, domain)
{
real Rop = 0.;
real yi_so2_g = 0.;
real den_g = 0.;
real T = 0.;
real diam = 0.;
real SO2_absorption = 0.;
real particle_vof = 0.;

cell_t c;
Thread *t;
Particle *p;
Injection *Ilist = Get_dpm_injections();
Injection *I;
loop(I, Ilist)
{
loop(p, I->p)
{
Rop = P_RHO(p);
diam = P_DIAM(p);
}
}

thread_loop_c(t, domain)
{
begin_c_loop(c, t)
{
//dpm_vof saved in a udm
//this macro works as well: C_STORAGE_R(c, t, SV_DPMS_CONCENTRATION)
particle_vof = C_DPMS_CONCENTRATION(c, t) / Rop; //particle vof marcro
C_UDMI(c, t, 0) = particle_vof;
T = C_T(c, t);
/*Temperature of air*/
yi_so2_g = C_YI(c, t, 2); /*mass fraction of so2 in air*/
den_g = C_R(c, t); /*density of air*/
real C_g = yi_so2_g * den_g / MW_SO2; /*molar concentration of so2 in air*//*[kmol/m3]*/
real C_l = 0.; /*molar concentration of so2 in water*//*[kmol/m3]
real A_INT = 6.0 * particle_vof / diam; //unit:m^2/m^3
SO2_absorption -= c1 * A_INT * C_g; //[kmol / m3 * s]
C_UDMI(c, t, 1) = SO2_absorption;
}
end_c_loop(c, t);
}
}

DEFINE_SOURCE(so2_source, c, t, dS, eqn)
{
real source;
source = -C_UDMI(c, t, 1);//if constant it work.
dS[eqn] = 0;

return source;
}
</pre>
Attached Images
File Type: jpg q1.jpg (103.5 KB, 10 views)
iorl19 is offline   Reply With Quote

Old   July 16, 2021, 02:27
Unhappy
  #2
New Member
 
Hong P.z
Join Date: Apr 2021
Posts: 3
Rep Power: 5
iorl19 is on a distinguished road
Dear all ,

I try to modifiy my udf simply, I used #if !RP_HOST to acess the value of C_UDMI(c, t, 0)->C_UDMI(c, t, 2) , and they both has the value.
But when I hook the source term , it give me the warning .

# Divergence detected in AMG solver: species-2 -> Increasing relaxation sweeps!

Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Divergence detected in AMG solver: species-2
Error at Node 0: floating point exception

Error at Node 1: floating point exception

I think something I missed ,Please Help me.



Code:
#include "udf.h"

DEFINE_ADJUST(dpm_vof, domain)
{
#if !RP_HOST
	cell_t c;
	Thread* t;
	Particle* p;
	Injection* Ilist = Get_dpm_injections();
	Injection* I;


	real particle_vof = 0;
	real Rop;
	real diam;



	loop(I, Ilist)
	{
		loop(p, I->p)
		{

			Rop = P_DIAM(p);
			
		}
	}

	thread_loop_c(t, domain)
	{
		begin_c_loop(c, t)


		{

			C_UDMI(c, t, 0) = C_DPMS_CONCENTRATION(c, t);
			C_UDMI(c, t, 1) = Rop;
			C_UDMI(c, t, 2) = C_DPMS_CONCENTRATION(c, t)/ Rop;
		}

		end_c_loop(c, t);
	}
#endif
}


DEFINE_SOURCE(so2_source, c, t, dS, eqn)
{


	real source;

	source = C_UDMI(c, t, 2);
	dS[eqn] = 0;
	return source;

	Message("source= \n", source);

}
iorl19 is offline   Reply With Quote

Old   July 28, 2021, 15:35
Default
  #3
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi iorl19,

I haven't worked through your UDF in detail. I agree with your tactic of trying something much simpler before applying all the detail. Some other advice:
(1) Get it to run in serial before even trying parallel.
(2) Form a really simple test case. In the past, I've built just a simple pipe, with DPM travelling with the flow. Turn off the DPM drag coefficient, and then DPM trajectories have constant speed. Arrange the test case so that you can test mass conservation etc.
(3) Check that the UDF is actually finding DPM particles, and if possible check that it is finding all the particles. I forget the details, but some of the ways of accessing DPM particles do not work for all setups. The documentation is not complete.
(4) Generate the source rates and store them, and then look at them in postprocessing before applying them. Write a UDF to report min and max values.
(5) Put a test on each value of the source term before applying it -- must be >=0, must be <=1 (or whatever -- some reasonable value for your timestep). If the source value does not pass, print a warning and apply zero source.

Good luck!
Ed
obscureed is offline   Reply With Quote

Old   August 2, 2021, 02:30
Thumbs up
  #4
New Member
 
Hong P.z
Join Date: Apr 2021
Posts: 3
Rep Power: 5
iorl19 is on a distinguished road
Quote:
Originally Posted by obscureed View Post
Hi iorl19,

I haven't worked through your UDF in detail. I agree with your tactic of trying something much simpler before applying all the detail. Some other advice:
(1) Get it to run in serial before even trying parallel.
(2) Form a really simple test case. In the past, I've built just a simple pipe, with DPM travelling with the flow. Turn off the DPM drag coefficient, and then DPM trajectories have constant speed. Arrange the test case so that you can test mass conservation etc.
(3) Check that the UDF is actually finding DPM particles, and if possible check that it is finding all the particles. I forget the details, but some of the ways of accessing DPM particles do not work for all setups. The documentation is not complete.
(4) Generate the source rates and store them, and then look at them in postprocessing before applying them. Write a UDF to report min and max values.
(5) Put a test on each value of the source term before applying it -- must be >=0, must be <=1 (or whatever -- some reasonable value for your timestep). If the source value does not pass, print a warning and apply zero source.

Good luck!
Ed
Thanks for your advice.But I over come the problem.
this is the modifiy UDF.

Quote:

#include "udf.h"

DEFINE_DPM_SCALAR_UPDATE(vof,cell,tread,initialize ,p)
{
Injection* I;


Injection* dpm_injections = Get_dpm_injections();


Thread *t;
cell_t c;
Thread* t1;//test
cell_t c1; //test
Particle* p0;

Domain* d = Get_Domain(1);

loop(I, dpm_injections)//ok-best
{
loop(p0, I->p)
{
c = P_CELL(p);
t = P_CELL_THREAD(p);

P_USER_REAL(p, 0) = P_RHO(p);
C_UDMI(c, t, 1) = P_RHO(p);
C_UDMI(c, t, 0) = P_DIAM(p);

}


}
DEFINE_SOURCE(so2_source, c, t, dS, eqn)
{

real source;
real Aint = 0.;
real dpm_concentration = 0.;
real particle_vof = 0.;

real yi_so2_g = C_YI(c, t, 2);
real den_g = C_R(c, t);
real C_g = yi_so2_g * den_g / 64.0;
real c1 = 3.1016E-004;

if (C_UDMI(c, t, 1) == 0.)
{
source = 0.;
}
else
{
dpm_concentration = C_DPMS_CONCENTRATION(c, t);
C_UDMI(c, t, 2) = dpm_concentration;
particle_vof = dpm_concentration / C_UDMI(c, t, 1);

C_UDMI(c, t, 3) = particle_vof;
Aint = 6 * particle_vof / C_UDMI(c, t, 0);
C_UDMI(c, t, 4) = Aint;
source = -c1 * Aint * C_g;
C_UDMI(c, t, 5) = source;
}

return source;
}
Thanks for your advice.But I over come the problem.
this is the modifiy UDF

Here some question are werid .
When I use loop(p, I->p),I->p is to particle structure.But the first p is tracke particle.I do not know Why I->p must to point particle structure.and the Contour is wrong (compare to the pannel in the contour of original dpm)
So I just use loop(p0, I->p) , and the contour is much similiar to the contour of original dpm.
Here is a tip for anyone .
The source and scalar udf define function is work in node solver.
So do not put like if !RP_HOST function in the source term.
The Divide by 0 problem simply use logic function in node solver can fix.
now the only problem is when the dpm iteration the consuming time is little long.
Above is my experience ,hope someone can adjust the wrong part.
iorl19 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
Define Source UDF Problem unred486 FLUENT 0 December 6, 2016 03:00
Uds udf issue solefire FLUENT 0 September 27, 2010 11:52
UDF Scalar Code: HT 1 Greg Perkins FLUENT 8 October 20, 2000 13:40
UDFs for Scalar Eqn - Fluid/Solid HT Greg Perkins FLUENT 0 October 14, 2000 00:03
UDFs for Scalar Eqn - Fluid/Solid HT Greg Perkins FLUENT 0 October 11, 2000 04:43


All times are GMT -4. The time now is 14:37.