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

Writing udf regarding adjacent cells

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 1, 2019, 15:26
Lightbulb Writing udf regarding adjacent cells
  #1
New Member
 
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8
vkumar12 is on a distinguished road
I have a problem where a mass source term is dependent on the temperature of the adjacent cells. The equation which i want to put in the udf form is given like this:

Smj = (A * ▲ Tj)/ Vj

Where Smj = Mass source of a species in jth cell
A - constant
▲ Tj - Temperature diff between two adjacent cells
Vj - Volume of Jth cell

I think i understand the basic udf, and I dont know how do i put temperature of two adjacent cells in the udf. If any one help writing a UDF , i would be very grateful

I am trying to write but stuck, It may be simple for those who are experienced in this.

DEFINE_SOURCE(_mass, c, t, dS, eqn)
{
real source;
real temp = C_T(c,t);
if (673<=C_T(c,t)<=1073)
source = -----------------------???
else
source = 0;
dS[eqn] = 0;
return source;
}

Thanks
Varun
vkumar12 is offline   Reply With Quote

Old   July 1, 2019, 22:53
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
I didn't test it. May be it should be something like this:
Code:
#include "udf.h"

DEFINE_ADJUST(calculate_source, d)
{
	face_t f
	cell_t c,c0, c1 = -1;
	Thread *t,*t0, *t1 = NULL;
	real Temp0, Temp1;
	// get temperature
	thread_loop_f (t,domain)
	{
		begin_f_loop (f,t)
		{
			c0 = F_C0(f,t);
			t0 = F_C0_THREAD(f,t);
			if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/
			{
				// you should define something here for case, when there is no more adjusted cells (external boundary)
				Temp0 = C_T(c0,t0);
				Temp1 = 0.0;
			}
			else{	
				c1 = F_C1(f,t); /* Get cell on other side of face */
				t1 = F_C1_THREAD(f,t);
				Temp0 = C_T(c0,t0);
				Temp1 = C_T(c1,t1);
			}
			C_UDMI(c0,t0,0) = Temp0;
			C_UDMI(c1,t1,1) = Temp1;
		}
		end_f_loop (f,t)
	}
	//calculate source
	thread_loop_c (t,domain)
	{
		begin_c_loop (c,t)
		{
			C_UDMI(c,t,2) = C_UDMI(c,t,0) - C_UDMI(c,t,1);
		}
		end_c_loop (c,t)
	}
}

DEFINE_SOURCE(_mass, c, t, dS, eqn)
{
real source;
real temp = C_T(c,t);
if (673<=C_T(c,t)<=1073)
source = C_UDMI(c,t,2);
else 
source = 0;
dS[eqn] = 0;
return source;
}
give your feedback here

best regards
AlexanderZ is offline   Reply With Quote

Old   July 2, 2019, 11:19
Default Structural reference error
  #3
New Member
 
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8
vkumar12 is on a distinguished road
Thank you very much for the help.
However when I tried to interpret the udf, it is giving structure reference not implemented on the following line.

t0 = F_C0_THREAD(f,t);

Any idea why?

Thanks
vkumar12 is offline   Reply With Quote

Old   July 3, 2019, 01:16
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
compile udf

best regards
AlexanderZ is offline   Reply With Quote

Old   July 15, 2019, 17:12
Default
  #5
New Member
 
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8
vkumar12 is on a distinguished road
Thank you for your help
I did download the visual studio and managed to compiled it. It was loaded successfully
I did assign 3 UDM for the memory and then hook the define adjust function in the fluent and ran the calculation, However it is giving me segmentation fault. Not sure why. I think it is to do with UDMI
Any help and input I would appreciate.
I feel I am close, but not there yet.
THank you very much for your time
vkumar12 is offline   Reply With Quote

Old   July 15, 2019, 23:18
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
show your code and output logs always

if you are using code above than there was mistake
Code:
thread_loop_f (t,domain)
to be
Code:
thread_loop_f (t,d)
best regards
AlexanderZ is offline   Reply With Quote

Old   July 16, 2019, 09:49
Default
  #7
New Member
 
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8
vkumar12 is on a distinguished road
Hello
I actually did that change and it is after the fact I am getting the segmentation fault
Here is complete code. The segmentation fault occurs when I ran the calculation with "Define adjust function hook up". If I don't hook the define adjust , it works (at least the iteration parts)




#include "udf.h"
DEFINE_ADJUST(calculate_source, d)
{
face_t f;
cell_t c,c0, c1 = -1;
Thread *t,*t0, *t1 = NULL;
real Temp0, Temp1;
// get temperature
thread_loop_f (t,d)
{
begin_f_loop (f,t)
{
c0 = F_C0(f,t);
t0 = F_C0_THREAD(f,t);
if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/
{
// you should define something here for case, when there is no more adjusted cells (external boundary)
Temp0 = C_T(c0,t0);
Temp1 = 0.0;
}
else{
c1 = F_C1(f,t); /* Get cell on other side of face */
t1 = F_C1_THREAD(f,t);
Temp0 = C_T(c0,t0);
Temp1 = C_T(c1,t1);
}
C_UDMI(c0,t0,0) = Temp0;
C_UDMI(c1,t1,1) = Temp1;
}
end_f_loop (f,t)
}
//calculate source
thread_loop_c (t,d)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,2) = C_UDMI(c,t,0) - C_UDMI(c,t,1);
}
end_c_loop (c,t)
}
}
DEFINE_SOURCE(Ch4_mass, c, t, dS, eqn)
{
real source;
real temp = C_T(c,t);
if (673<=C_T(c,t)<=1073)
source = (-0.000000081917+2*0.00000000011114*C_T(c,t)-3*0.000000000000045649*C_T(c,t)*C_T(c,t))*C_UDMI(c ,t,2)/C_VOLUME(c,t);
else
source = 0;
if (source<0)
source = 0;
else
source = source;
dS[eqn] = 0;
return source;
}


P.S I changed the Define Adjust code, in order to see where the problem is to


Temp0 = C_T(c0,t0);
Temp1 = C_T(c1,t1);
}
}
end_f_loop (f,t)
}
//calculate source
thread_loop_c (t,d)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0) = C_T(c0,t0)-C_T(c1,t1);
}
end_c_loop (c,t)
}
}
And it works but I belive it may be wrong and not doing what it is supposed to ?
Thank you for you time

Last edited by vkumar12; July 16, 2019 at 15:59.
vkumar12 is offline   Reply With Quote

Old   July 16, 2019, 23:08
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
was
Code:
else{ 
c1 = F_C1(f,t); /* Get cell on other side of face */
t1 = F_C1_THREAD(f,t);
Temp0 = C_T(c0,t0);
Temp1 = C_T(c1,t1);
}
C_UDMI(c0,t0,0) = Temp0;
C_UDMI(c1,t1,1) = Temp1;
}
new
Code:
else{ 
c1 = F_C1(f,t); /* Get cell on other side of face */
t1 = F_C1_THREAD(f,t);
Temp0 = C_T(c0,t0);
Temp1 = C_T(c1,t1);
C_UDMI(c1,t1,1) = Temp1;
}
C_UDMI(c0,t0,0) = Temp0;
}
Also you should add initialization macro DEFINE_INIT
Code:
DEFINE_INIT(my_init_func,d)
{
cell_t c;
Thread *t;
/* loop over all cell threads in the domain */
thread_loop_c(t,d)
{
/* loop over all cells */
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;
}
end_c_loop_all(c,t)
}
}
best regards

Last edited by AlexanderZ; July 23, 2019 at 22:43.
AlexanderZ is offline   Reply With Quote

Old   July 23, 2019, 11:51
Default
  #9
New Member
 
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8
vkumar12 is on a distinguished road
Thank you very much for your help.
The new UDF you provide is working and compiled successfully.
P.s I used 2019 VS community version and Ansys 17.1
It was essential to open the Ansys workbench file with VS studio command prompt.

Thank you again for your kind help. I really appreciate.
vkumar12 is offline   Reply With Quote

Old   August 1, 2019, 11:21
Default
  #10
New Member
 
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8
vkumar12 is on a distinguished road
Dear Alexander
I need your help on the same topic. As I mentioned earlier the UDF compiled properly but the values for the adjacent cells temperatures coming to be same and hence the C_UDMI 2 came to be zero and making all the results goes to zero.
I think it would be better if I explain my problem here in detail.
My model contains a solid porous body (fiber) which is 1/8" thick and 100" long and it is heated in a furnace. Fiber is travelling at a speed so I used MRF model to simulate that. Furnace is 7 zones and alls are heated electrically.
What I was trying to do is to calculate the mass fraction of gases coming out of the fiber. See the attached picture for the geometry (attachment 1) and meshing (attachment 2)
And that source term is dependent on how is the rate of fiber heating and hence I need the adjacent cell temperatures. I think I am still confused what are the adjacent cells in my problem and hence I highlighted in the attached picture.

Some observation after I calculation finishes:

When I plot C_UDMI (0) and C_UDMI (1) for the interior fiber with respect to direction of furnace length , it gives me a profile (attached) but only problem is the profile of C_UDMI (0) and C_UDMI (1) are exactly same. and hence C_UDMI 2 which is the difference of adjacent cells gives value of zero.



Thanks in advance for your help.
Attached Images
File Type: jpg Geometry.jpg (36.8 KB, 24 views)
File Type: jpg Meshing picture of fiber porous body.jpg (66.1 KB, 19 views)
File Type: jpg UDMI0 interior fiber temp.jpg (32.2 KB, 23 views)
File Type: png UDMI2 temp.png (11.5 KB, 18 views)
vkumar12 is offline   Reply With Quote

Old   August 2, 2019, 01:28
Default
  #11
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Am I right, that adjusted cells your are interested in are cells of fiber only?

You want to get temperature difference between adjusted cells of fiber?

best regards
AlexanderZ is offline   Reply With Quote

Old   August 2, 2019, 06:50
Default
  #12
New Member
 
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8
vkumar12 is on a distinguished road
Yes that is correct.
vkumar12 is offline   Reply With Quote

Old   August 2, 2019, 09:15
Default
  #13
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
unfortunately have no idea now

best regards
AlexanderZ is offline   Reply With Quote

Old   August 2, 2019, 09:29
Default
  #14
New Member
 
VK
Join Date: Dec 2018
Posts: 9
Rep Power: 8
vkumar12 is on a distinguished road
I think it automatically chooses that domain when I put the source term in cell zone condition of fiber . So I believe it will automatically chooses the fiber domain to calculate the temp of adjacent cells .

In the meshing picture i attached , do you think my assumption of adjacent cell is right , it is the cells adjacent to the face of a particular cell right ?
vkumar12 is offline   Reply With Quote

Old   August 4, 2019, 23:04
Default
  #15
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
you may try to monitor temperatures only in fiber part (make it explicitly)

you should add following In DEFINE_ADJUST macro above begin_f_loop(f, thread){
Code:
int ID = 1;
/* Zone ID for wall-1 zone from Boundary Conditions task page */
Thread *thread = Lookup_Thread(domain, ID);
change 1 to id of interior-fiber in your model.
Go to GUI -> boundary conditions -> select interior-fiber -> under zone window you may check ID

best regards
AlexanderZ 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 about Searching the Adjacent cells: Please help me to find out the error Hotpig1100 Fluent UDF and Scheme Programming 6 July 9, 2018 20:37
Fluent UDF wrong number of cells in parallel - correct in serial dralexpe Fluent UDF and Scheme Programming 7 May 17, 2018 09:26
[snappyHexMesh] No layers in a small gap bobburnquist OpenFOAM Meshing & Mesh Conversion 6 August 26, 2015 10:38
[Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 06:50
UDF: neighbour cells, upwind cells Dmitriy Makarov FLUENT 0 February 18, 2001 14:53


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