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

Can you check my code of writing UDF?

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By AlexanderZ
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 11, 2020, 04:23
Default Can you check my code of writing UDF?
  #1
New Member
 
THA SEANGHAI
Join Date: Aug 2020
Location: Cambodia
Posts: 25
Rep Power: 6
THA SEANGHAI is on a distinguished road
Hello!I am writing a code in C-programming to make UDF for my problem. Of course, I do not know about the code at all, but I just look at some examples in the ANSYS UDF Manual,then I wrote this follow the manual. My purpose is to input mass flux(0.5 kg/m²s) of a species and diffusion coefficient(3E-05m²/s) of a species on a wall boundary, so can you check my code and correct it? Because I cannot compile this code to the Fluent. I am really struggling with this kind of code, because I never studied or wrote code before. Please help me. I will appreciate your help. My codes are as the following:

#include “udf.h”
DEFINE_UDS_FLUX(my_uds_flux,f,t,i)
{
cell_t c0, c1=-1;
Thread *t0, t1=NULL;


real NV_VEC(psi_vec), NV_VEC(A), flux = 0.5;

c0 = F_C0(f,t);
t0 = F_C0_THREAD(f,t);
F_AREA(A, f, t);

/* If face lies at domain boundary, use face values; */
/* If face lies IN the domain, use average of adjacent cells. */
if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/
{
real dens;

/* Depending on its BC, density may not be set on face thread*/
if (NNULLP(THREAD_STORAGE(t,SV_DENSITY)))
dens = F_R(f,t); /* Set dens to face value if available */
else
dens = C_R(c0,t0); /* else, set dens to cell value */

NV_DS(psi_vec, =, F_U(f,t), F_V(f,t), F_W(f,t), *, dens);

flux = NV_DOT(psi_vec, A); /* flux through Face */
}
else
{
c1=F_C1(f,t); /* Get cell on other side of face*/
t1=F_C1_THREAD(f,t);
NV_DS(psi_vec, =, C_U(c0,t0),C_V(c0,t0),C_W(c0,t0),*,C_R(c0,t0));
NV_DS(psi_vec, =, C_U(c1,t1),C_V(c1,t1),C_W(c1,t1),*,C_R(c1,t1));
flux=NV_DOT(psi_vec, A)/2.0; /* Average flux through face*/
}

/* ANSYS FLUENT will multiply the returned value by phi_f (the scalar's
value at the face) to get the "complete'' advective term. */

return flux;
}
DEFINE_DEFFUSIVITY(tri_diff,c,t,i)
{
return C_R(c,t)*3.0e-05+C_MU_EFF(c,t)/0.7;
}
THA SEANGHAI is offline   Reply With Quote

Old   August 12, 2020, 09:28
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
code is this
Code:
#include "udf.h"

DEFINE_UDS_FLUX(my_uds_flux,f,t,i)
{
	cell_t c0,c1=-1;
	Thread *t0,*t1=NULL;
	real NV_VEC(psi_vec), NV_VEC(A), flux = 0.5;
	c0 = F_C0(f,t);
	t0 = F_C0_THREAD(f,t);
	F_AREA(A,f,t);
	if (BOUNDARY_FACE_THREAD_P(t))
	{
		real dens;
		if (NNULLP(THREAD_STORAGE(t,SV_DENSITY)))
			dens = F_R(f,t);
		else
			dens = C_R(c0,t0);
		NV_DS(psi_vec,=,F_U(f,t),F_V(f,t),F_W(f,t),*,dens);
		flux = NV_DOT(psi_vec,A);
	}
	else
	{
		c1 = F_C1(f,t);
		t1 = F_C1_THREAD(f,t);
		NV_DS(psi_vec, = ,C_U(c0,t),C_V(c0,t),C_W(c0,t),*,C_R(c0,t0));
		NV_DS(psi_vec, = ,C_U(c1,t),C_V(c1,t),C_W(c1,t),*,C_R(c1,t1));
		flux = NV_DOT(psi_vec,A)/2.0;
	}
	return flux;
}

DEFINE_DIFFUSIVITY(tru_diff,c,t,i)
{
	return C_R(c,t)*3.0e-05+C_MU_EFF(c,t)/0.7;;
}

but you don't need it, as it was made to calculate user defined scalar equation.

in addition you have constant flux so you don't need UDF at all

How the mass can get into your domain without any velocity? I can hardly imagine.
I have no experience in this kind of simulations.
THA SEANGHAI likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   August 12, 2020, 10:30
Default Is it possible to input mass flux without velocity in UDF?
  #3
New Member
 
THA SEANGHAI
Join Date: Aug 2020
Location: Cambodia
Posts: 25
Rep Power: 6
THA SEANGHAI is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
code is this
Code:
#include "udf.h"

DEFINE_UDS_FLUX(my_uds_flux,f,t,i)
{
	cell_t c0,c1=-1;
	Thread *t0,*t1=NULL;
	real NV_VEC(psi_vec), NV_VEC(A), flux = 0.5;
	c0 = F_C0(f,t);
	t0 = F_C0_THREAD(f,t);
	F_AREA(A,f,t);
	if (BOUNDARY_FACE_THREAD_P(t))
	{
		real dens;
		if (NNULLP(THREAD_STORAGE(t,SV_DENSITY)))
			dens = F_R(f,t);
		else
			dens = C_R(c0,t0);
		NV_DS(psi_vec,=,F_U(f,t),F_V(f,t),F_W(f,t),*,dens);
		flux = NV_DOT(psi_vec,A);
	}
	else
	{
		c1 = F_C1(f,t);
		t1 = F_C1_THREAD(f,t);
		NV_DS(psi_vec, = ,C_U(c0,t),C_V(c0,t),C_W(c0,t),*,C_R(c0,t0));
		NV_DS(psi_vec, = ,C_U(c1,t),C_V(c1,t),C_W(c1,t),*,C_R(c1,t1));
		flux = NV_DOT(psi_vec,A)/2.0;
	}
	return flux;
}

DEFINE_DIFFUSIVITY(tru_diff,c,t,i)
{
	return C_R(c,t)*3.0e-05+C_MU_EFF(c,t)/0.7;;
}

but you don't need it, as it was made to calculate user defined scalar equation.

in addition you have constant flux so you don't need UDF at all

How the mass can get into your domain without any velocity? I can hardly imagine.
I have no experience in this kind of simulations.
Thank you for your reply! And yes, I want this code to be used for UDS equation. Of course, I also think that mass flux should be made with the velocity, without velocity flux is zero. I am really confused about this point, that I saw in the formula of mass flux, it also depends on the diffusion coefficient times concentration gradient if there is no velocity. m=(density*velocity)-(diffusion coefficient of a species*concentration gradient). So it is possible? I am not sure about this!
I think that in Fluent, if there is no velocity, flux will be automatically zero.
If you are available, can I contact you through E-mail? Because I am a new user of this group, thus I do not know how to upload pictures to show my problem, I really want to show the boundary that I want to input mass flux of a species to you, it will make you more easily to know my problem. I think that I can input only the concentration in the expression instead of mass fraction of a species without writing code, then I can check my mass flux on that boundary by equation m=-(D*(dc/dy)), I really appreciate your help! @AlexanderZ: My Email: thaseanghai@gmail.com
I just want to talk to you to get some opinions. Thank again!
THA SEANGHAI is offline   Reply With Quote

Old   August 12, 2020, 23:07
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
the thing is, I have no experience in this kind of simulations, so most likely, Im not able to help you.

try to continue this thread.
to share pictures here upload it on any online storage, for example https://upload.photobox.com/en/

and put link in your message
THA SEANGHAI likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   August 13, 2020, 02:46
Default Anyway, thank for your reply! I will try to upload my problem figure here
  #5
New Member
 
THA SEANGHAI
Join Date: Aug 2020
Location: Cambodia
Posts: 25
Rep Power: 6
THA SEANGHAI is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
the thing is, I have no experience in this kind of simulations, so most likely, Im not able to help you.

try to continue this thread.
to share pictures here upload it on any online storage, for example https://upload.photobox.com/en/

and put link in your message
Thank you for your reply, @AlexanderZ! I will try to upload the picture of my problem here, so when you have time, can you look at it? i will try to detail the information about this problem. Of course, the info. that I told you in the above message is not enough to understand, therefore it can make you confused and hardly to imagine. Of course, in my problem, it has velocity from the inlet and I want to input mass flux at the wall boundary.I will detail in the next reply message.
THA SEANGHAI is offline   Reply With Quote

Old   August 13, 2020, 03:24
Default Here are the boundary's names.
  #6
New Member
 
THA SEANGHAI
Join Date: Aug 2020
Location: Cambodia
Posts: 25
Rep Power: 6
THA SEANGHAI is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
the thing is, I have no experience in this kind of simulations, so most likely, Im not able to help you.

try to continue this thread.
to share pictures here upload it on any online storage, for example https://upload.photobox.com/en/

and put link in your message
1. https://www.photobox.co.uk/my/photo/...d=503161121731

2. https://www.photobox.co.uk/my/photo/...d=503161122047

3. https://www.photobox.co.uk/my/photo/...d=503161121568

4. https://www.photobox.co.uk/my/photo/...d=503161121848



You can see the 4 above pictures and I will describe all the info. about each boundary as the following:
1. Inlet: at the inlet, I input only X-velocity of air(1m/s).
2. Outlet: just work in the atmospheric pressure.(101325Pa)
3. Species-wall: on the species wall, I want to input mass flux of a species without velocity, but I realized that on the species wall, there are X-velocities coming from the inlet and Y-velocity is zero. I am curious about this point, can X-velocity coming from the inlet create the mass flux on the species wall? For my test without writing code, I just enable the species model and use it, at the species wall, I input the only concentration(kmol/m³), not mass flux(kg/m2s), then can ANSYS Fluent calculate mass flux from the concentration which I input?
4. Wall: Stationary wall, specified shear stress=0 Pa, and i input zero diffusivity to this boundary.
Therefore, what I am curious about is number 3. Species wall. Thank you and I hope you will look at it and if you have any suggestion, please tell me.
THA SEANGHAI 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
How to Mix AIR and WATER Elvis1991 FLUENT 12 December 1, 2016 13:28
having problem in writing a UDF for specific heat in fluent 14.0 nands_bullwalker Fluent UDF and Scheme Programming 1 June 29, 2013 11:32
critical error during installation of openfoam Fabio88 OpenFOAM Installation 21 June 2, 2010 04:01
correct UDF code for unsteady pressure boundary James W FLUENT 0 November 2, 2005 12:38
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 16:56


All times are GMT -4. The time now is 16:43.