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

Update Pressure values for unsteady, multiphase, parallel - not updating properly

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 3, 2021, 05:04
Default Update Pressure values for unsteady, multiphase, parallel - not updating properly
  #1
Member
 
Dhayananth
Join Date: Jun 2014
Posts: 37
Rep Power: 12
dhaya400 is on a distinguished road
Hello,

I am working on a unsteady flow problem with multiphase mixture model and run the simulation in Parallel mode.

For my problem, I have written a udf to update the pressure value of face boundary at every time step using the mass flow of the previous time step.

Code:
#include"udf.h"

real Q12; /* current time step flow rate */
#define BCA_ID 63 /* domain id*/
DEFINE_EXECUTE_AT_END(flow_rate_bca)
{
#if !RP_HOST
Domain *d;
real m;
cell_t c;
Thread *t;
face_t f;
d = Get_Domain(1);
t= Lookup_Thread(d, BCA_ID);
/* loop to calculate mass flow rate at outlet */
begin_f_loop(f,t)
{
if (PRINCIPAL_FACE_P(f,t))
{
m += F_FLUX(f,t);
}
}
end_f_loop(f,t)
Q12 = m / 1060.0; /* convert mass flow rate to volume flow rate */
#if RP_NODE
/* Perform node synchronized actions here. Does nothing in Serial */
Q12 = PRF_GRSUM1(Q12);
#endif /* RP_NODE */
m = 0.0;
#endif /* !RP_HOST */
}

DEFINE_PROFILE(pressure_out_bca,t,i)
{
#if !RP_HOST
real Z = 5.1918E+07;
real C = 8.697E-10;
real R = 10.6080E+08;
real ts = CURRENT_TIMESTEP;
face_t f;
begin_f_loop(f,t)
{
if (CURRENT_TIME == 0)
{
F_UDMI(f,t,0) = 13332.2;
F_UDMI(f,t,1) = F_UDMI(f,t,0);
F_UDMI(f,t,2) = 1.22E-05;
}

/* F_UDMI(f,t,0) - previous time step pressure
F_UDMI(f,t,1) - current time step pressure
F_UDMI(f,t,2) - previous time step flow rate
Q12 - current time step flow rate
*/

else
{
F_UDMI(f,t,3) = Q12;
F_UDMI(f,t,1) = ((F_UDMI(f,t,0)*R*C)+(F_UDMI(f,t,3)*R*ts)+(F_UDMI( f,t,3)*Z*ts)+(Z*R*C*F_UDMI(f,t,3))-(Z*R*C*F_UDMI(f,t,2))) / (ts +(R*C));
F_UDMI(f,t,0) = F_UDMI(f,t,1);
F_UDMI(f,t,2) = F_UDMI(f,t,3);
}
}
end_f_loop(f,t)
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = F_UDMI(f,t,1); /* Calculate pressure and apply to outlet*/
}
end_f_loop(f,t)
#endif /* !RP_HOST */
}


Question:
When I physically calculate the pressure values and check with pressure output files from simulation, it is not matching. Is there any error in the code which is causing this problem?
dhaya400 is offline   Reply With Quote

Old   June 3, 2021, 07:29
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
It could also be an error in your own calculation...

How big is the difference? Which values do you get, which values did you calculate? Which equation do you think you are using?
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   June 3, 2021, 09:49
Default
  #3
Member
 
Dhayananth
Join Date: Jun 2014
Posts: 37
Rep Power: 12
dhaya400 is on a distinguished road
Hi Pakk,

Thank you for your reply.

I am using the following equation to calculate the pressure values for the outlet.

P(n+1) = {[P(n)*R*C] + [Q(n+1)*R*ts] + [Q(n+1)*Z*ts] + [Z*R*C*Q(n+1)] - [Z*R*C*Q(n)]} / (ts +(R*C))

F_UDMI(f,t,0) corresponds to P(n)
F_UDMI(f,t,1) corresponds to P(n+1)
F_UDMI(f,t,2) corresponds to Q(n)
F_UDMI(f,t,3) corresponds to Q(n+1)

Initializing, Q(n) = 1.22E-05 , P(n) = 13332.4 for CURRENT_TIME = 0

Result from simulation:
Q (n) Q(n+1) P(n) P(n+1)
1.22E-05 3.266E-05 13332.2 133324.4
3.266E-05 8.902E-05 133324.4 10423.9

Result from physical calculation:
Q (n) Q(n+1) P(n) P(n+1)
1.22E-05 3.266E-05 13332.2 14629.7
3.266E-05 8.902E-05 14629.7 18429.7
dhaya400 is offline   Reply With Quote

Old   June 3, 2021, 23:59
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
you may write to console each term of your equation using Message0("text"); macro

code seems to be correct.
the only thing I would do -> split time step definition with applying the value:
was
real ts = CURRENT_TIMESTEP;
to be
real ts;
ts = CURRENT_TIMESTEP;
dhaya400 likes this.
__________________
best regards


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

Old   June 4, 2021, 01:57
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You update F_UDMI(f,t,1) before you update F_UDMI(f,t,0), which seems wrong. Does not explain your current problem, however.
__________________
"The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform" is NOT the error after compiling. It is the error after loading. To see compiler errors, look at your screen after you click "build".
pakk is offline   Reply With Quote

Old   June 4, 2021, 08:36
Default
  #6
Member
 
Dhayananth
Join Date: Jun 2014
Posts: 37
Rep Power: 12
dhaya400 is on a distinguished road
Hi Alexander and Pakk,

Thank you for your reply.
I have incorporated your suggestions and made few changes in the code for updating the previous time step values.
The following code is moved out of face loop and made separate face loop for the code.
F_UDMI(f,t,0) = F_UDMI(f,t,1);
F_UDMI(f,t,2) = F_UDMI(f,t,3);

Using Message command, I have checked the values of F_UDMI variables with physical calculation, the pressure values are matching. But if I check F_UDMI values with pressure values from the report files it is not matching. Why?
For example, F_UDMI = 16733 Pa, Pressure from report file = 16084 Pa

I want to update the pressure values for mixture domain only. But while printing the values, I come to know that the udf is updating for all the domains. So how to make the define profile macro to update mixture domain alone?

Revised code:

#include"udf.h"
real Q12; /* current time step flow rate */
#define BCA_ID 63 /* domain id*/
DEFINE_EXECUTE_AT_END(flow_rate_bca)
{
#if !RP_HOST
Domain *d;
real m;
cell_t c;
Thread *t;
face_t f;
d = Get_Domain(1);
t= Lookup_Thread(d, BCA_ID);
/* loop to calculate mass flow rate at outlet */
begin_f_loop(f,t)
{
if (PRINCIPAL_FACE_P(f,t))
{
m += F_FLUX(f,t);
}
}
end_f_loop(f,t)
Q12 = m / 1060.0; /* convert mass flow rate to volume flow rate */
#if RP_NODE
/* Perform node synchronized actions here. Does nothing in Serial */
Q12 = PRF_GRSUM1(Q12);
#endif /* RP_NODE */
m = 0.0;
#endif /* !RP_HOST */
}

DEFINE_INIT(init_pressure_bca,d)
{
Thread *t1;
cell_t c;
t1 = Lookup_Thread(d,BCA_ID); // for BCA
real P = 13332.2;
thread_loop_c(t1, d)
{
begin_c_loop_all(c,t1)
{
C_P(c,t1) = P;
}
end_c_loop_all(c, t1)
}
#if RP_HOST
Message("BCA Pressure Initalised\n");
#endif
}

DEFINE_PROFILE(pressure_out_bca,t,i)
{
#if !RP_HOST
real Z = 5.1918E+07;
real C = 8.697E-10;
real R = 10.6080E+08;
real ts;
ts = CURRENT_TIMESTEP;
face_t f;
begin_f_loop(f,t)
{
if (CURRENT_TIME == 0)
{
F_UDMI(f,t,0) = 13332.2;
F_UDMI(f,t,1) = F_UDMI(f,t,0);
F_UDMI(f,t,3) = 1.22E-05;
}
/* F_UDMI(f,t,0) - previous time step pressure
F_UDMI(f,t,1) - current time step pressure
F_UDMI(f,t,2) - prevoius time step flow rate
Q12 - current time step flow rate
*/
else
{
F_UDMI(f,t,3) = fabs (Q12);
F_UDMI(f,t,1) = ((F_UDMI(f,t,0)*R*C)+(F_UDMI(f,t,3)*R*ts)+(F_UDMI( f,t,3)*Z*ts)+(Z*R*C*F_UDMI(f,t,3))-(Z*R*C*F_UDMI(f,t,2))) / (ts +(R*C));
}
}
end_f_loop(f,t)
begin_f_loop(f,t)
{
F_UDMI(f,t,0) = F_UDMI(f,t,1);
F_UDMI(f,t,2) = F_UDMI(f,t,3);
}
end_f_loop(f,t)
begin_f_loop(f,t)
{
F_PROFILE(f,t,i) = F_UDMI(f,t,1); /* Calculate pressure and apply to outlet*/
}
end_f_loop(f,t)
#endif /* !RP_HOST */
}
dhaya400 is offline   Reply With Quote

Old   June 7, 2021, 02:43
Default
  #7
Member
 
Dhayananth
Join Date: Jun 2014
Posts: 37
Rep Power: 12
dhaya400 is on a distinguished road
Hi,

While searching for multiphase -Define profile macro, I cam across the below line from the udf manual:

Quote:
In multiphase cases a DEFINE_PROFILE UDF may be called more than once (particularly if the profile is used in a mixture domain thread). If this needs to be avoided, then add the prefix MP_ to the UDF name. The function will then be called only once even if it is used for more than one profile.
What does this line covey? Can anyone explain with example?
I think.. if I got the answer to this question. I will solve the error in the above post.
dhaya400 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
question regarding LES of pipe flow - pimpleFoam Dan1788 OpenFOAM Running, Solving & CFD 37 December 26, 2017 15:42
Neumann pressure BC and velocity field Antech Main CFD Forum 0 April 25, 2006 03:15
Gas pressure question Dan Moskal Main CFD Forum 0 October 24, 2002 23:02
Hydrostatic pressure in 2-phase flow modeling (CFX4.2) HB &DS CFX 0 January 9, 2000 14:19
Hydrostatic pressure in 2-phase flow modeling (long) DS & HB Main CFD Forum 0 January 8, 2000 16:00


All times are GMT -4. The time now is 09:07.