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

Best practices to transfer variable between two DEFINE_FUNCTION

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 28, 2020, 02:27
Default Best practices to transfer variable between two DEFINE_FUNCTION
  #1
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Hello everyone,

I would like to know the best practices for transferring a variables between two define functions with UDM in parallel mode. Why is it so hard ? Most of the time I receive segmentation fault. What is the proper procedure when UDMs are used? Example, should i define memory first, initialize and then load UDF or I can load UDF and then initialize. I would like to learn the nuances as it is very depressing and boring when we get segmentation fault.
arunraj is offline   Reply With Quote

Old   June 30, 2020, 00:35
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
Quote:
Originally Posted by arunraj View Post
Hello everyone,

I would like to know the best practices for transferring a variables between two define functions with UDM in parallel mode. Why is it so hard ? Most of the time I receive segmentation fault. What is the proper procedure when UDMs are used? Example, should i define memory first, initialize and then load UDF or I can load UDF and then initialize. I would like to learn the nuances as it is very depressing and boring when we get segmentation fault.
sequence depends on your case and logic of UDF.
what are you trying to do?
Start with single-core
__________________
best regards


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

Old   June 30, 2020, 00:55
Default THREAD_SHADOW and F_SHADOW for shadow velocity inlet
  #3
Senior Member
 
Arun raj.S
Join Date: Jul 2011
Posts: 194
Rep Power: 14
arunraj is on a distinguished road
Dear Alexander,

Thank you for your reply. Indeed, I made a logical error. I would like to access the call face and thread of one velocity inlet inside another. I used tle=THREAD_SHADOW(tve); fle=F_SHADOW(fve,tve); for this purpose. le- liquid evaporator and ve - vapor evaporator. They are shadow to each other but velocity inlet boundary as I am simulating liquid-vapor interface in heat pipe where I need to assign radial velocity and temperature. I am receiving the following error.

D:\leonard validation\libudfaabvvvbcccddaa\src\pipe.c(19) : warning C4700: uninitialized local variable 'fve' used
D:\leonard validation\libudfaabvvvbcccddaa\src\pipe.c(125) : warning C4700: uninitialized local variable 'fve' used

Is there a workaround for this problem to access the cell face id and thread id of another shadow boundary (not wall)?

I have attached my UDF. your help would be greatly appreciated.

#include "udf.h"

Thread *tve;
Thread *tle;
Thread *t0;
Thread *t0_s;

DEFINE_INIT(my_init_udf,d)
{
#if !RP_HOST
face_t fve;
face_t fle;
cell_t c0;
cell_t c0_s;
{
begin_c_loop(c0,t0)
{
tve=Lookup_Thread(Get_Domain(1),20);
c0 = F_C0(fve,tve);
t0 = F_C0_THREAD(fve,tve);
C_UDMI(c0,t0,0) = 0.0;
Message("first udmi is %g\n", C_UDMI(c0,t0,0));
}
end_c_loop(c0, t0);
}

{

begin_c_loop(c0_s,t0_s)
{
tve=Lookup_Thread(Get_Domain(1),20);
tle=THREAD_SHADOW(tve);
fle=F_SHADOW(fve,tve);
c0_s = F_C0(fle,tle);
t0_s = F_C0_THREAD(fle,tle);
C_UDMI(c0_s,t0_s,1) = 0.0;
Message("first udmi is %g\n", C_UDMI(c0_s,t0_s,1));
}
end_c_loop(c0_s, t0_s);
}
# endif
}

DEFINE_ADJUST(pipe, domain)
{
#if !RP_HOST
face_t fve;
face_t fle;
cell_t c0;
cell_t c0_s;
real temp_cell_ve, press_cell_ve, rho_cell_ve;
real rho_cell_le;
real hfg = 2360000.0;
real R = 8314.0;
real M = 18.015;
real RR;
real s = 0.03;
real po = 101325.0;
real to = 373.0;
real ti = 324.7278;
real p_op = 13450.0;
real a1, a2, a3;
real mdot;
real pi;
real vel_ve, vel_le;

begin_f_loop(fve, tve)
{
tve=Lookup_Thread(Get_Domain(1),20);
tle=THREAD_SHADOW(tve);
fle=F_SHADOW(fve,tve);
c0 = F_C0(fve,tve);
t0 = F_C0_THREAD(fve,tve);
c0_s = F_C0(fle,tle);
t0_s = F_C0_THREAD(fle,tle);
temp_cell_ve = C_T(c0,t0);
press_cell_ve = C_P(c0,t0);
rho_cell_ve = C_R(c0,t0);
rho_cell_le = C_R(c0_s,t0_s);
RR = R/M;
pi = po*exp((hfg/RR)*((1/to)-(1/ti)));
a1 = (2.0*s)/(2.0-s);
a2 = 1/sqrt(2*M_PI*RR);
a3 = ((p_op+press_cell_ve)/sqrt(temp_cell_ve))-(pi/sqrt(ti));
mdot = a1*a2*a3;
vel_ve=mdot/rho_cell_ve;
vel_le=mdot/rho_cell_le;
C_UDMI(c0,t0,0)=vel_ve;
C_UDMI(c0_s,t0_s,1)=-vel_le;
Message("vel_ve is %g\n", C_UDMI(c0,t0,0));
Message("vel_le is %g\n", C_UDMI(c0_s,t0_s,0));
}
end_f_loop(fve, tve)
#endif
}

DEFINE_PROFILE(vaporside_velocity, t, i)
{
#if !RP_HOST
face_t fve;
face_t fle;
cell_t c0;
begin_f_loop(fve, tve)
{
tve=Lookup_Thread(Get_Domain(1),20);
c0 = F_C0(fve,tve);
t0 = F_C0_THREAD(fve,tve);
F_PROFILE(fve, tve, i) = C_UDMI(c0,t0,0);
Message("vel_ve profile is %g\n", C_UDMI(c0,t0,0));
}
end_f_loop(fve, tve)
#endif
}

DEFINE_PROFILE(liquidside_velocity, t, i)
{
#if !RP_HOST
face_t fve;
face_t fle;
cell_t c0_s;
begin_f_loop(fle, tle)
{
tve=Lookup_Thread(Get_Domain(1),20);
tle=THREAD_SHADOW(tve);
fle=F_SHADOW(fve,tve);
c0_s = F_C0(fle,tle);
t0_s = F_C0_THREAD(fle,tle);
F_PROFILE(fle, tle, i) = C_UDMI(c0_s,t0_s,1);
Message("vel_le profile is %g\n", C_UDMI(c0_s,t0_s,1));
}
end_f_loop(fle, tle)
#endif
}
arunraj 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
Difficulty In Setting Boundary Conditions Moinul Haque CFX 4 November 25, 2014 17:30
Convective / Conductive Heat Transfer in Hypersonic flows enigma Main CFD Forum 2 November 1, 2009 22:53
Env variable not set gruber2 OpenFOAM Installation 5 December 30, 2005 04:27
additional variable mass transfer in CFX5.6 john CFX 1 February 14, 2004 00:30
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 20:09


All times are GMT -4. The time now is 12:59.