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

C_udsi_g

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 27, 2019, 17:51
Default C_udsi_g
  #1
Member
 
Andrea
Join Date: Mar 2018
Posts: 62
Rep Power: 8
Andrea159357 is on a distinguished road
Hello,
i'm trying to calculate the gradient of the WALL SHEAR STRESS but i'm facing a problem.
It's a semicirular domain in 3D with a cylinder in the middle. At the Inlet, the left side, velocity is imposed, Outflow is on the right, Bottom and Cylinder is noslip while top is freeslip.
i used DEFINE_ADJUST macro to calculate WSS of the wall face and then i allocated the WSS in the cell adjacent to that face thanks to UDMI(0).
Then i set UDSI(0) = UDMI(0).
UDMI(1) = UDSI_G(0)[0]
UDMI(2) = UDSI_G(0)[1]

The problem, in my opinion, is that the gradient is affected by numerical error


Here is the code:
----------------------------------------------------------------------------------
#include "udf.h"
#define ID_ground 6


DEFINE_ON_DEMAND(SELECTING_CELL_MEMORY)
{
Domain *d;
Thread *t;
cell_t c;
d=Get_Domain(1);
thread_loop_c(t,d)
{

begin_c_loop(c,t)
{
C_UDMI(c,t,0)=0; /*tau_wall*/
C_UDMI(c,t,1)=0; /*D_SQRT(tau_wall)_DX*/
C_UDMI(c,t,2)=0; /*D_SQRT(tau_wall)_DY*/
}
end_c_loop(c,t)
}

}

DEFINE_ADJUST(UDS0, d)
{
Thread *tc, *t0;
cell_t c0;
face_t f;

tc = Lookup_Thread(d,ID_ground);

begin_f_loop(f,tc)
{
real A[ND_ND];
F_AREA(A,f,tc);
real area = NV_MAG(A);
real tau_wall = NV_MAG(F_STORAGE_R_N3V(f,tc, SV_WALL_SHEAR))/area;

c0=F_C0(f,tc);
t0=THREAD_T0(tc);


C_UDMI(c0,t0,0) = tau_wall;
C_UDSI(c0,t0,0) = C_UDMI(c0,t0,0);
C_UDMI(c0,t0,1) = C_UDSI_G(c0,t0,0)[0];
C_UDMI(c0,t0,2) = C_UDSI_G(c0,t0,0)[1];

}
end_f_loop(f,tc)

}



iThe gradient problem is showed in the following images: WSS, D_WSS_DX, D_WSS_DY:



WSS.jpg

D_WSS_DX.jpg

D_WSS_DY.jpg



Can someone help me?

THANKS
Andrea159357 is offline   Reply With Quote

Old   December 30, 2019, 00:13
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
you've defined UDSI only I 1 cell layer near the wall boundary, isnt it?
__________________
best regards


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

Old   December 30, 2019, 05:25
Default
  #3
Member
 
Andrea
Join Date: Mar 2018
Posts: 62
Rep Power: 8
Andrea159357 is on a distinguished road
Exactly, I'm studing scouring of the seabed. That's the quantity of material removed from the ground by the sea current.
Andrea159357 is offline   Reply With Quote

Old   December 30, 2019, 21:27
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
may be you should define USDI = 0 everywhere first.

also it could be useful to switch off 'node values' in contours, so you can see fields without interpolation
__________________
best regards


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

Old   December 30, 2019, 22:35
Default
  #5
Member
 
Andrea
Join Date: Mar 2018
Posts: 62
Rep Power: 8
Andrea159357 is on a distinguished road
Since UDM=0 is initialized in EXECUTE_ON_DEMAND, UDM(c0,t0) is overwritten in the cell near boundary, UDS is 0 everywhere and has a value just near wall. When i inspect contour i usually turn off nodes value and see just cell values.
Could it be that the gradient is wrong since i didn't assign nodes and faces but just cell value?
Seems strange because i'm not using GreenGaus node based but Least squared.
I really don't know why this behavior.

Have you some experience in DEFINE_UDS_FLUX? maybe i can avoid C_UDSI_G define a new flux function and solving the scalar without assign it in the wall cells
Andrea159357 is offline   Reply With Quote

Old   January 2, 2020, 00:35
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
I don't think you should assign nodes and faces values

Is your simulation is steady state? How do you calculate UDS?
__________________
best regards


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

Old   January 2, 2020, 04:00
Default
  #7
Member
 
Andrea
Join Date: Mar 2018
Posts: 62
Rep Power: 8
Andrea159357 is on a distinguished road
Yes, is a steady state calculation.
I want to solve the divergence of WALL SHEAR STRESS times friction velocity, (div(WSS*U_star)).
First i tryed to allocate the value of (D(tau_wall)/DX * U_star_x + tau_wall*D(U_star_x)/DX + D(tau_wall)/DY * U_star_y + tau_wall*D(U_star_y)/DY) directly into cell C0. Since the gradient of tau_wall through the definition of UDSI = tau_wall suffers of numerical error due to oscillations, i tryed to solve UDS imposing 0 as diffusivity coefficient and redefine UDS flux.
UDS FLUX is defined as:
u_star_x = U/sqrt(U^2+V^2),
u_star_y = V/sqrt(U^2+V^2),
u_star_z = 0, at the c0 cell adjacent to wall and u,v,w= 0 everywhere else but it is not working. When i solve UDSI en error of floating point exception pops up.


!!! C_UDMI(c0,t0,0) = tau_wall !!! define in UDF previously posted

------------------------------------------------------------------------------------------------------------------------------------
#include "udf.h"
#define rho 1000 /* Water Density ; */


DEFINE_UDS_FLUX(UDS1_Q_FLUX,f,t,i)
{
cell_t c0, c1 = -1;
Thread *t0, *t1 = NULL;

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

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*/

NV_DS(psi_vec, =, C_UDMI(c0,t0,0)*F_U(f,t)/sqrt(F_U(f,t)*F_U(f,t) + F_V(f,t)*F_V(f,t)), C_UDMI(c0,t0,0)*F_V(f,t)/sqrt(F_U(f,t)*F_U(f,t) + F_V(f,t)*F_V(f,t)), 0, *, rho);
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_UDMI(c0,t0,0)*C_U(c0,t0)/sqrt(C_U(c0,t0)*C_U(c0,t0) + C_V(c0,t0)*C_V(c0,t0)) , C_UDMI(c0,t0,0)*C_V(c0,t0)/sqrt(C_U(c0,t0)*C_U(c0,t0) + C_V(c0,t0)*C_V(c0,t0)) , 0 ,*,rho);
NV_DS(psi_vec, +=, C_UDMI(c1,t1,0)*C_U(c1,t1)/sqrt(C_U(c1,t1)*C_U(c1,t1) + C_V(c1,t1)*C_V(c1,t1)) , C_UDMI(c0,t0,1)*C_V(c1,t1)/sqrt(C_U(c1,t1)*C_U(c1,t1) + C_V(c1,t1)*C_V(c1,t1)) , 0 ,*,rho);

flux = NV_DOT(psi_vec, A)/2.0; /* Average flux through face */
}


return flux;
}
-----------------------------------------------------------------------------------------------------------------------------

Last edited by Andrea159357; January 2, 2020 at 05:13.
Andrea159357 is offline   Reply With Quote

Old   January 10, 2020, 05:57
Default
  #8
Member
 
Andrea
Join Date: Mar 2018
Posts: 62
Rep Power: 8
Andrea159357 is on a distinguished road
I've found the problem. UDF was not write for parallel usage.
The numerical error of the gradient is located at the interface of the partition of domain passed to the different cores
Andrea159357 is offline   Reply With Quote

Old   January 10, 2020, 06:52
Default
  #9
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
so what did you change?
if loop over faces is embedded into DEFINE_UDS_FLUX(UDS1_Q_FLUX,f,t,i) macro?
__________________
best regards


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

Old   January 10, 2020, 07:34
Default
  #10
Member
 
Andrea
Join Date: Mar 2018
Posts: 62
Rep Power: 8
Andrea159357 is on a distinguished road
No, DEFINE_UDS_FLUX was an alternative to avoid numerical error in DEFINE_ADJUST.
I'm studying how to parallelize my UDF (DEFINE_ADJUST to avoid this problem).
I think that the gradient is counted two times because of mirrores cells at boundary (Exterior cells).
When i will come up with a solution i'll post a parallelized version of the UDF for define Adjust
Andrea159357 is offline   Reply With Quote

Old   January 12, 2020, 19:35
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
you may check ansys fluent customization manual -> parallel consideration
__________________
best regards


******************************
press LIKE if this message was helpful
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



All times are GMT -4. The time now is 20:50.