CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   Pass variable from one udf to another (https://www.cfd-online.com/Forums/fluent/220307-pass-variable-one-udf-another.html)

Spyrost September 3, 2019 04:58

Pass variable from one udf to another
 
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!

Comi September 3, 2019 06:24

HI, would'nt be possible to create just one UDF instead of two?

Spyrost September 3, 2019 08:16

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;

}

LuckyTran September 3, 2019 15:49

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

AlexanderZ September 4, 2019 00:50

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

Spyrost September 4, 2019 08:43

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

AlexanderZ September 4, 2019 21:40

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

Spyrost September 5, 2019 12:09

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 September 14, 2019 12:13

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



All times are GMT -4. The time now is 19:56.