CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   using boundary condition in uds (https://www.cfd-online.com/Forums/fluent-udf/203172-using-boundary-condition-uds.html)

sahoo June 20, 2018 05:49

using boundary condition in uds
 
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

`e` June 20, 2018 07:20

Quote:

Originally Posted by sahoo (Post 696605)
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.

sahoo June 20, 2018 08:58

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?

AlexanderZ June 20, 2018 22:22

use DEFINE_SOURCE macros to define J

best regards

sahoo June 21, 2018 09:43

Thanks for your reply. But it was something different and I got it.:)

sahoo June 21, 2018 15:54

While loading the code I am getting the error received a fatal signal (Segmentation fault)
I have also tried to solve this using link https://www.cfd-online.com/Forums/fl...ion-fault.html

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)
}

AlexanderZ June 22, 2018 03:30

Quote:

Originally Posted by sahoo (Post 696782)
Thanks for your reply. But it was something different and I got it.:)

good for you

best regards

`e` June 23, 2018 02:35

Quote:

Originally Posted by sahoo (Post 696806)
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?

luzikato March 9, 2021 06:57

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.

AlexanderZ March 17, 2021 21:13

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)


luzikato March 17, 2021 21:44

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.

AlexanderZ March 17, 2021 23:57

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

luzikato March 18, 2021 01:05

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.

AlexanderZ March 18, 2021 20:50

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

luzikato March 24, 2021 05:12

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.


All times are GMT -4. The time now is 06:44.