CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   How to pass variable between macros (https://www.cfd-online.com/Forums/fluent-udf/148151-how-pass-variable-between-macros.html)

einandr February 5, 2015 06:16

How to pass variable between macros
 
Hi! I am trying to implement PID controller in FAN-model and SIX-DOF solver. I use DEFINE_PROFILE macro to simulate time-varying thrust from fans, which depends on current centre of gravity position. So, I want to take from DEFINE_SDOF_PROPERTIES macro the centre of gravity and pass it to DEFINE_PROFILE macro, whithing wich the controller is to be implemented.

How do I ecxhange variables between macros? I try using pointer, it compiles well but crashes on initialisation with SEGMENTATION VIOLATION error. Maybe I need UDMs? If so, how do I implement it? I attach the code. Guys, please help! I have not enough experience in programming, so maybe it is simple issue.

#include "udf.h"
real *pY=0;

DEFINE_SDOF_PROPERTIES(PID_kopter, prop, dt, time, dtime)
{
real Y;

prop[SDOF_MASS] = 5;
prop[SDOF_IXX] = 10;
prop[SDOF_IYY] = 10;
prop[SDOF_IZZ] = 10;

Y = DT_CG(dt)[1];
pY=&Y;
printf ("\nPID_kopter: updated 6DOF properties, Y position: %f" Y );
}

DEFINE_PROFILE(fan_profile, t, i)
{
real x[ND_ND], VFAN, y;
face_t f;
y = *pY;
begin_f_loop(f,t)
{
F_CENTROID(x,f,t);

VFAN = 1;
if (y <= 0.6)
{
F_PROFILE(f,t,i) = -500*VFAN + 4500;
}
else
{
F_PROFILE(f,t,i) = 0;
}
}
end_f_loop(f,t)
}

macfly February 5, 2015 06:34

Hi,

Instead of declaring a pointer, define a global variable that will be visible to all macros: https://www.sharcnet.ca/Software/Flu...Variables.html


All times are GMT -4. The time now is 21:27.