CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   CFX (http://www.cfd-online.com/Forums/cfx/)
-   -   Problem with loop in CFX-Post macro (http://www.cfd-online.com/Forums/cfx/63039-problem-loop-cfx-post-macro.html)

chris_101 March 26, 2009 10:20

Problem with loop in CFX-Post macro
 
Hi everybody!

I am trying to evaluate a frequency-dependent expression inside a loop for different frequency values. A minimum example looks like the following:

!for(my $frequency=100;$frequency<2000;$frequency+=10)
!{
LIBRARY:
CEL:
EXPRESSIONS:
testvalue=$frequency
END
END
END

EXPRESSION EVALUATOR:
Evaluated Expression = testvalue
END
> forceupdate EXPRESSION EVALUATOR

!my ($result,$unit) =evaluate("minVal(testvalue)\@Volume0");
!print "\n $result \t $frequency";
!}

The problem is that the expression 'testvalue' remains at the value 100 which is the starting value of the for-loop. The output of this function is:

100 710
100 720
100 730
100 740
100 750
100 760

Does anybody have an idea how I could force an update of the expression value so that 'testvalue' and 'frequency' are equal while the loop is running? The output I am looking for would be:

710 710
720 720
730 730
740 740
750 750
760 760

Thanks for your help!

LKF March 26, 2009 12:12

CFX Help for the minVal function states: "minVal Returns the minimum value of the specified variable on the specified locator. You should create a User Variable if you want to find the minimum value of an expression."

I belive the following code block will make your simple example work. Whether or not you can modify it to work for your intended purpose I don't know.

Code:


!for($frequency = 100; $frequency <150; $frequency +=10)
!{
USER SCALAR VARIABLE:testvalue
  Boundary Values = Conservative
  Calculate Global Range = Off
  Expression = $frequency
  Recipe = Expression
  Variable to Copy = Pressure
END
!open (MYFILE, '>>.\Out.txt');
!my ($result,$unit) = evaluate("minVal(testvalue)\@Plane1");
!print MYFILE "\n $result \t $frequency";
!close (MYFILE);
!}

I hope that helps.

chris_101 March 26, 2009 12:45

It works
 
I managed to get it work by adding some user variables for every perl variable that's changing inside the loop like you did in your listing.

I think the clue for getting the expression updated every loop-cycle is to store the dependent variable somewhere.

Thanks LKF!

cfdguy March 26, 2009 14:18

Sometimes I have problems with these IsoVolumes. What I usually do, I delete and redefine them at each loop.

For me, this is a POST issue, not a Perl one. ;)


All times are GMT -4. The time now is 20:34.