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

How to pass variable between macros

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 5, 2015, 07:16
Default How to pass variable between macros
  #1
New Member
 
Andrey Yakovchuk
Join Date: Nov 2012
Posts: 24
Rep Power: 14
einandr is on a distinguished road
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)
}
einandr is offline   Reply With Quote

Old   February 5, 2015, 07:34
Default
  #2
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17
macfly is on a distinguished road
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
macfly 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
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


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