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

using boundary condition in uds

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 20, 2018, 06:49
Default using boundary condition in uds
  #1
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
Hello everyone,
I have a problem regarding using the boundary condition in an UDS

I need to make the following equation in UDS0 :-
∇UDS0=-ρ(T)*J
∇J=0
∇[-1/ρ(T) *∇UDS0]=0
Quote:
#include "udf.h"
#include "math.h"

enum
{
teg,
N_REQUIRED_UDS
};

real rho_function(real T)
{
return -3.982e-5 + 2.98e-7*T - 4.685e-10*T*T + 2.51e-12*T*T*T;
}

DEFINE_DIFFUSIVITY(teg_diffusivity, c, t, i)
{
C_UDSI(c,t,teg) = rho_function(C_T(c,t));
return 1./C_UDSI(c,t,teg);
}
I want to include 'J' in this code but 'J' here is the current density(boundary condition) which can be calculated by the following equation:-

∆V=∇UDS0+∇UDS1
I=∆V/R
J=I/(face area)

For which made the code :-

Quote:
#include "udf.h"
#include "math.h"

enum
{
teg,
teg1,
N_REQUIRED_UDS
};

/*DEFINE_EXECUTE_AT_END(execute_at_end)
{
face_t f;
Thread *t;
begin_f_loop(f,t)
{
real voltage_function(f,t)
{
return F_UDSI(f,t,teg) + F_UDSI(f,t,teg1);
}
}
end_f_loop(f,t)
}*/

real voltage_function(f,t)
{
return F_UDSI(f,t,teg) + F_UDSI(f,t,teg1);
}


DEFINE_PROFILE( J, t, p)
{
real A[3] ;
face_t f ;
real At ;
At = 0.0;
begin_f_loop(f,t)
{
F_AREA(A, f, t) ;
At += NV_MAG(A);
}
end_f_loop(f,t)
begin_f_loop(f,t)
{
static real R=2;
F_PROFILE(f, t, p) = (voltage_function(F_T(f,t))/(R*At));
}
end_f_loop(f,t)
}
But it gives error in the voltage_function line.
'voltage_function' must return a value

I wanted to know how to use this 'J' in UDS0 and whats wrong in this code, since it is a boundary condition.
I hope the doubt is understandable. Please suggest me a way to solve this.

Thank you
sahoo is offline   Reply With Quote

Old   June 20, 2018, 08:20
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by sahoo View Post
But it gives error in the voltage_function line.
'voltage_function' must return a value
A couple of errors: you have defined the voltage_function within the face loop, and also defined this function after you want to call it, again.

You do not need to create functions for everything; it appears that creating the functions are complicating things (in particular, you are sending the face temperature to the voltage_function on line 46). Instead, you could write out your equations with one line each. For example, if your equations were:

\Delta V = \textrm{UDS}_0 + \textrm{UDS}_1

I = \Delta V / R

J = I / A_\text{face}

then your code would look like:

Code:
dV = F_UDSI(f,t,0) + F_UDSI(f,t,1);
I = dV/R;
J = I/A;
or on one single line (shorter, but less clear):

Code:
J = (F_UDSI(f,t,0) + F_UDSI(f,t,1))/R/A;
The equation that you listed had the gradients of the UDS (\nabla \textrm{UDS}_0) which are vectors but the left hand side is a scalar, the change in voltage? Remember to declare your variables at the beginning of the code block.
`e` is offline   Reply With Quote

Old   June 20, 2018, 09:58
Default
  #3
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
Yes I think the problem was with the scalar and vector. Now its working .
But my main problem was using this 'J' in UDS0 which I am still not getting.
∇UDS0=-ρ(T)*J
How can I import the J value to UDS0?
sahoo is offline   Reply With Quote

Old   June 20, 2018, 23:22
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
use DEFINE_SOURCE macros to define J

best regards
AlexanderZ is offline   Reply With Quote

Old   June 21, 2018, 10:43
Default
  #5
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
Thanks for your reply. But it was something different and I got it.
sahoo is offline   Reply With Quote

Old   June 21, 2018, 16:54
Default
  #6
New Member
 
Animesh Sahoo
Join Date: May 2018
Posts: 20
Rep Power: 8
sahoo is on a distinguished road
While loading the code I am getting the error received a fatal signal (Segmentation fault)
I have also tried to solve this using link Error: received a fatal signal (Segmentation fault).

But it didnt work. I am still getting the error.
UDF is as follows :-
Quote:
#include "udf.h"
#include "math.h"
#define R 2.0

enum
{
teg,
teg1,
N_REQUIRED_UDS
};

DEFINE_PROFILE( J, t, p)
{
real A[ND_ND],J,At ;
face_t f ;
At=0.0;
begin_f_loop(f,t)
{
F_AREA(A, f, t) ;
At = At + NV_MAG(A);
}
end_f_loop(f,t)

J = (F_UDSI(f,t,teg) + F_UDSI(f,t,teg1))/R/At;

begin_f_loop(f,t)
{
F_PROFILE(f, t, p) = J;
}
end_f_loop(f,t)
}
sahoo is offline   Reply With Quote

Old   June 22, 2018, 04:30
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
Quote:
Originally Posted by sahoo View Post
Thanks for your reply. But it was something different and I got it.
good for you

best regards
AlexanderZ is offline   Reply With Quote

Old   June 23, 2018, 03:35
Default
  #8
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Quote:
Originally Posted by sahoo View Post
While loading the code I am getting the error received a fatal signal (Segmentation fault)
Have you defined at least two UDS? Which line of code is causing the error? Start by removing lines of code until you can determine the cause.

Also, should the evaluation for J (line 24) be within the second face loop? What equation are you applying on the boundary?
`e` is offline   Reply With Quote

Old   March 9, 2021, 07:57
Default
  #9
New Member
 
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7
luzikato is on a distinguished road
Hello guys, I know this thread is a bit old. But I wanted to ask you guys to elaborate on how to implement the J term. As sahoo stated, the J term is a boundary but based on the reference it's a specified flux boundary for UDS0.

Mr. AlexanderZ said that we could use DEFINE_SOURCE macro but since the J term is actually a flux term. I still don't get the idea of how to implement J term in UDS0.

Best regards. Thank you.

Last edited by luzikato; March 9, 2021 at 10:36.
luzikato is offline   Reply With Quote

Old   March 17, 2021, 22:13
Default
  #10
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 specify boundary flux using define_profile macro, as sahoo did.
check his code above.
there could be a lot of reasons, why he had that error, code may not be a problem

the only this to be changed in code:
was
Code:
J = (F_UDSI(f,t,teg) + F_UDSI(f,t,teg1))/R/At;

begin_f_loop(f,t)
{
F_PROFILE(f, t, p) = J;
}
end_f_loop(f,t)
to be

Code:
begin_f_loop(f,t)
{
J = (F_UDSI(f,t,teg) + F_UDSI(f,t,teg1))/R/At;
F_PROFILE(f, t, p) = J;
}
end_f_loop(f,t)
__________________
best regards


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

Old   March 17, 2021, 22:44
Default
  #11
New Member
 
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7
luzikato is on a distinguished road
I was thinking that this thread is not active anymore. I opened another thread with similar topic.

Thank you for your reply. Yes, i figured the code after quite a time. Yes, I also had error like sahoo did. I also figured the solution.

Basically, when it's applied on boundary, the profile udf need to read temperature profile from the boundary which is not exist yet at the initial condition. So to fix the error you need to use standard initialization specifying temperature. After this, the error just gone.

However, I have another question. If I want to specifiy the flux at a boundary like this. Should I use the area of the whole boundary or just the face at every loop? Since the loop is being done on faces.
luzikato is offline   Reply With Quote

Old   March 18, 2021, 00:57
Default
  #12
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
don't really get your question
flux is in unit/m2.
for instance you can apply heat -> flux is W/m2
to get total applied energy you need integral over whole boundary -> W/m2 * m2 = W
__________________
best regards


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

Old   March 18, 2021, 02:05
Default
  #13
New Member
 
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7
luzikato is on a distinguished road
A boundary is consist of multiple faces, right? So I'm thinking that each faces has its own flux value. And total flux on that boundary would be integral of flux values from multiple faces on the boundary.

Let's say a boundary consist of 50 faces with different heat flux values. So total flux on that boundary would be sum of 50 different heat flux values.

Each of those 50 faces has its own flux values. So from what I understand, to calculate flux value from one specific face, we need to divide heat by area of that specific face only, right?

I'm a little bit confused because from the code sahoo made. I think he was trying to divide scalar value with sum of area of the entire boundary on each loop which contradict my understanding on calculating flux.

I hope you understand my point. Nevertheless, thank you for all your reply.
Best regards.
luzikato is offline   Reply With Quote

Old   March 18, 2021, 21:50
Default
  #14
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
as far as I understand, for your case with 50 faces, you should divide total heat flux on total area of boundary (area of all 50 faces), and apply it to each face
__________________
best regards


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

Old   March 24, 2021, 06:12
Default
  #15
New Member
 
Anas Nur Fauzan
Join Date: Oct 2019
Posts: 18
Rep Power: 7
luzikato is on a distinguished road
Okay. I get it now.

I have another question.

So, like sahoo. I'm trying to simulate a thermoelectric generator.
The source term involve Temperature-dependent Seeback Coefficient which defined with a polynomial function below.

Code:
real alpha_function(real T) {
	return 8.439e-4 - 3.81e-6*T + 6.736e-9*pow(T,-9) - 3.934e-12*pow(T,-12);
}
To get this coefficient value, Seeback Coefficient assigned to UDS2. I want to calculate this coefficient by inserting each cell temperature to the function above within the cell loop at the end of iteration. So I made the code.

Code:
real alpha (real T){
	return	8.439e-4 - 3.81e-6*T + 6.736e-9*pow(T,-9) - 3.934e-12*pow(T,-12);
}

DEFINE_EXECUTE_AT_END(CalculateScalarsAtEnd)
{
	cell_t c;
	Thread *t;
	
	begin_c_loop(c, t)
	{		
		C_UDSI(c,t,2) = alpha(C_T(c,t));
		
		C_UDSI(c,t,3) = C_UDSI(c,t,2)*C_T_G(c,t)[0];
		C_UDSI(c,t,4) = C_UDSI(c,t,2)*C_T_G(c,t)[1];
		C_UDSI(c,t,5) = C_UDSI(c,t,2)*C_T_G(c,t)[2];
	}
	end_c_loop(c,t)
}
Since UDS2 is not a generic transport anymore. Is there special consideration I should take? Because in the reference journal also stated,
Quote:
The source terms of Thomson and Peltier in each cell involve the gradient of the Seebeck coefficient \alpha. To express \nabla\alpha for the source term, UDS2 is used to represent the scalar of \alpha. We constitute a transport equation for UDS2,
\nabla \left(- \nabla UDS2\right) = 0
What does "constitute" mean in this case?

Thank you. Best regards.
luzikato 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
mixed inflow/outflow downstream boundary condition question peob OpenFOAM Running, Solving & CFD 3 February 3, 2017 11:54
Basic Nozzle-Expander Design karmavatar CFX 20 March 20, 2016 09:44
UDS problem with wall boundary condition Alex F. FLUENT 15 September 21, 2015 10:28
External Radiation Boundary Condition (Two sided wall), Grid Interface CFD XUE FLUENT 0 July 8, 2010 07:49
vorticity boundary condition bearcharge Main CFD Forum 0 May 14, 2010 12:32


All times are GMT -4. The time now is 18:38.