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

Pass variable from one udf to another

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 3, 2019, 05:58
Default Pass variable from one udf to another
  #1
New Member
 
Spyros
Join Date: Jul 2019
Posts: 6
Rep Power: 7
Spyrost is on a distinguished road
Hello everyone! I have created a UDF that calculates the velocity (variable name vel) from a heat transfer function. I need to pass this variable (vel) which changes value every time step to another UDF in order to link that UDF with the movement of a interface.

Is there any way I can make this?
I know that with UDM one can store a value to a memory slot but dont know if I can retrieve it and use it in another UDF.
Any help would be much appreciated!
Spyrost is offline   Reply With Quote

Old   September 3, 2019, 07:24
Default
  #2
Member
 
Mattia
Join Date: Mar 2018
Posts: 45
Rep Power: 8
Comi is on a distinguished road
HI, would'nt be possible to create just one UDF instead of two?
Comi is offline   Reply With Quote

Old   September 3, 2019, 09:16
Default
  #3
New Member
 
Spyros
Join Date: Jul 2019
Posts: 6
Rep Power: 7
Spyrost is on a distinguished road
I dont think so.. Look at the codes that I am attaching. In the first one both interfaces move with the same speed. But in the second code only one interface moves and not the other. IDK if it is some kind of mistake I do when writing the code. I need to calculate from some heat function the vel[1] for the one thread (one side of the interface) and then make the other thread (other side of that interface) move with the same vel[1] but in opposite direction so that the 2 are always connected.
Thanks in advance.



CODE1


/* moving grid */

#include "udf.h"

DEFINE_CG_MOTION(interf_move, dt, vel, omega, time, dtime)
{

int tid;
double velocity;

face_t face;
Thread *thread = DT_THREAD (dt);
tid = THREAD_ID (thread);


if (THREAD_ID (thread) == 9)

{
velocity=-0.4*(time/10);
}

if (THREAD_ID (thread) == 10)
{
velocity=-0.4*(time/10);
}

vel[1]=velocity;

}


CODE2


#include "udf.h"

DEFINE_CG_MOTION(interf_move, dt, vel, omega, time, dtime)
{

int tid;
double velocity;


face_t face;
Thread *thread = DT_THREAD (dt);
tid = THREAD_ID (thread);


if (THREAD_ID (thread) == 9)
{
velocity=-0.4*(time/10);
}

if (THREAD_ID (thread) == 10)
{
velocity=-velocity;
}


vel[1]=velocity;

}
Spyrost is offline   Reply With Quote

Old   September 3, 2019, 16:49
Default
  #4
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,761
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
I can't follow the logic of what you are trying to do to tell you how to do it (sorry I just can't make sense out of it).

You can certainly have more than one DEFINE macro in a single UDF.

You can also access a UDM using the C_UDMI(c,t,0) or F_UDMI(f,t,0) macros (where the 0 is the 0th or first UDM).
LuckyTran is offline   Reply With Quote

Old   September 4, 2019, 01:50
Default
  #5
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 LuckyTran mentioned

Code:
/* moving grid */

#include "udf.h"

DEFINE_CG_MOTION(interf_move_1, dt, vel, omega, time, dtime)
{
double velocity;
{...}
vel[1]=velocity;
}

DEFINE_CG_MOTION(interf_move_2, dt, vel, omega, time, dtime)
{
double velocity;
{...}
vel[1]=-velocity; // negative, because you want to move OPPOSITE direction
}
best regards
AlexanderZ is offline   Reply With Quote

Old   September 4, 2019, 09:43
Default
  #6
New Member
 
Spyros
Join Date: Jul 2019
Posts: 6
Rep Power: 7
Spyrost is on a distinguished road
Let me elaborate on my problem
I have a fluid domain and a solid body and the interface between them is coupled, from a heat transfer function [velocity=f(boundary_heat_flux)] ,I calculate the velocity with which the solid side interface should move and need to move the fluid side of the interface with the same velocity so that they always remain in contact. I understand that I don't need to have 2 separate UDFs and I also found out that since the interface would move down (negative Y axis) the whole sign convention doesn't need to be taken into account, both sides must move with negative velocity with respect to the global coordinate system.
So the variable velocity should be calculated only in the first DEFINE_CG_MOTION (interf_move1, ..) and then passed to the second DEFINE_CG_MOTION (interf_move2, ..) in order to move the latter with the same velocity.
I think this is the best way to explain it.

I've tried the code provided by AlexanderZ but fluent warms me that the variable vel[1] is not used in the second DEFINE MACRO and as unticipated one side of the interface is not moving
Spyrost is offline   Reply With Quote

Old   September 4, 2019, 22:40
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
wall between fluid and solid has coupled boundary condition, does it really needed to move both of them separately?

regarding your request
Code:
/* moving grid */

#include "udf.h"
double velocity;
DEFINE_CG_MOTION(interf_move_1, dt, vel, omega, time, dtime)
{
{...}
vel[1]=velocity;
}

DEFINE_CG_MOTION(interf_move_2, dt, vel, omega, time, dtime)
{
{...}
vel[1]=velocity;
}
best regards
AlexanderZ is offline   Reply With Quote

Old   September 5, 2019, 13:09
Default
  #8
New Member
 
Spyros
Join Date: Jul 2019
Posts: 6
Rep Power: 7
Spyrost is on a distinguished road
Yes because either wise the one side of the interface moves and not both. I will provide the code and explain the procedure I am following
Spyrost is offline   Reply With Quote

Old   September 14, 2019, 13:13
Default
  #9
New Member
 
Spyros
Join Date: Jul 2019
Posts: 6
Rep Power: 7
Spyrost is on a distinguished road
I've tried 2 tests. First one works ok but the second doesn't and I can't understand why.
The first one is a simple udf assigning a constant velocity for both sides of the interface and works great.
The second udf calculates the average temperature and heat flux across the entire face of the interface of the solid and calculates the velocity of the motion when the temperature has exceeded a temperature value. The simulation crashes every time with the second udf the moment the temperature is reached and the mesh is to be moved with the calculated velocity.


In the dynamic mesh zones window I set rigid body motion,motion attributes->interface_move1 for zone1 (the solid side of the interface) and for zone2 (the fluid side of the interface), rigid body motion, motion attributes->interface_move2.


Any assistance would be much appreciated


The codes are provided below.


TEST1

#include "udf.h"

double velocity;

DEFINE_CG_MOTION(interface_move1, dt, vel, omega, time, dtime)
{

{
velocity=-0.04;
}

vel[1]=velocity;

}


DEFINE_CG_MOTION(interface_move2, dt, vel, omega, time, dtime)
{


vel[1]=velocity;

}


TEST2

#include "udf.h"

double velocity;
double T_SUBL = 400.0;
double H_SUBL = 27250.0;
double HTC = 32.0;
double dens = 2000.0;
double area[ND_ND];
double areamag;
double noface = 0.0;
double BHFavg = 0.0;
double BHFsum = 0.0;
double tavg = 0.0;
double tsum = 0.0;
int tid;

DEFINE_CG_MOTION(interface_move1, dt, vel, omega, time, dtime)
{
face_t face;
Thread *thread = DT_THREAD(dt);
tid = THREAD_ID(thread);

begin_f_loop(face, thread)
{
noface++;
F_AREA(area, face, thread);
areamag = NV_MAG(area);
BHFsum += (BOUNDARY_HEAT_FLUX(face, thread));
tsum += F_T(face, thread);
}
end_f_loop(face, thread);

tavg = tsum / noface;
BHFavg = BHFsum / areamag;

if (tavg <= T_SUBL)
{
velocity = 0;
}
if (tavg > T_SUBL)
{

velocity = BHFavg / (dens*H_SUBL);
}

vel[1] = -velocity;

Message(" THREAD=%i\n", THREAD_ID(thread));
Message(" BHF on surface=%g\n", BHFavg);
Message(" AVG Temp=%g\n", tavg);
Message(" vel=%g\n", vel[1]);
Message(" velocity=%g\n", velocity);

}


DEFINE_CG_MOTION(interface_move2, dt, vel, omega, time, dtime)
{
vel[1] = -velocity;
}

Spyrost is offline   Reply With Quote

Reply

Tags
dynamic mesh, fluent, udf, udm


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
Fluent UDF urgent! Variable reaction rate natantyt Fluent UDF and Scheme Programming 8 October 17, 2021 04:35
Store a UDF variable wadezaza Fluent UDF and Scheme Programming 6 January 10, 2020 04:42
Can I change the variable in UDF via Fluent console or window without compiling? swtbkim FLUENT 0 July 12, 2017 23:15
List of variable using in UDF Tleja Fluent UDF and Scheme Programming 4 July 31, 2014 12:57
how to access a variable in DPM within a UDF patrick FLUENT 13 September 15, 2010 09:38


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