|
[Sponsors] |
February 5, 2015, 07:16 |
How to pass variable between macros
|
#1 |
New Member
Andrey Yakovchuk
Join Date: Nov 2012
Posts: 24
Rep Power: 14 |
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) } |
|
February 5, 2015, 07:34 |
|
#2 |
Senior Member
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17 |
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 |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Best way to pass a scalar variable to a runtime selectionnable class? | Yann | OpenFOAM Programming & Development | 0 | October 22, 2014 09:53 |
emag beta feature: charge density | charlotte | CFX | 4 | March 22, 2011 10:14 |
error in COMSOL:'ERROR:6164 Duplicate Variable' | bhushas | COMSOL | 1 | May 30, 2008 05:35 |
Env variable not set | gruber2 | OpenFOAM Installation | 5 | December 30, 2005 05:27 |
Replace periodic by inlet-outlet pair | lego | CFX | 3 | November 5, 2002 21:09 |