Can I create a dynamic Math Script within lua in PostFEKO?
In the following example, a math script is created within the lua script:
app = pf.GetApplication() app:NewProject() app:OpenFile(FEKO_HOME..[[/shared/Resources/Automation/startup.fek]]) -- Create a math script farFieldMathScript = app.MathScripts:Add(pf.Enums.MathScriptTypeEnum.FarField) script = [[ dataSet = pf.FarField.GetDataSet("startup.StandardConfiguration1.FarFields", 51) scale = 2 for freqIndex = 1, #dataSet.Axes["Frequency"] do for thetaIndex = 1, #dataSet.Axes["Theta"] do for phiIndex = 1, #dataSet.Axes["Phi"] do indexedValue = dataSet[freqIndex][thetaIndex][phiIndex] indexedValue.EFieldTheta = indexedValue.EFieldTheta * scale indexedValue.EFieldPhi = indexedValue.EFieldPhi * scale end end end return dataSet ]] farFieldMathScript.Script = script -- Run the math script farFieldMathScript:Run() -- Plot the math script farFieldPlot = app.Views[1].Plots:Add(farFieldMathScript)
Could I use a variable of the main script and introduce it into the math script?
I would like to create "dynamic" math scripts.
If so, what's the syntax?
Thanks
Best Answer
-
Hi Israel
The definition of the math script is simply a block of text. Provided that you are able to pass the numerical value of your variable as a string, it should be possible to include it in the math script.
When concatenating a string with a numerical variable in Lua, the value of the variable is included as a string. For example:
myVariable = 5 myString = "Hello World " .. myVariable print(myString)
should produce:
Hello World 5
In your example you could do the following:
... myScalingVariable = 2.5 -- Create a math script farFieldMathScript = app.MathScripts:Add(pf.Enums.MathScriptTypeEnum.FarField) script = [[ dataSet = pf.FarField.GetDataSet("startup.StandardConfiguration1.FarFields", 51) scale = ]] .. myScalingVariable .. [[ for freqIndex = 1, #dataSet.Axes["Frequency"] do for thetaIndex = 1, #dataSet.Axes["Theta"] do ...
Inside the math script, then line defining the scale variable should then automatically read:
scale = 2.5
Note that the empty line at the start of the second block of text is required to ensure that the following code starts on a new line in the math script.
Kind regards,
Johan H
1
Answers
-
Hi Israel
The definition of the math script is simply a block of text. Provided that you are able to pass the numerical value of your variable as a string, it should be possible to include it in the math script.
When concatenating a string with a numerical variable in Lua, the value of the variable is included as a string. For example:
myVariable = 5 myString = "Hello World " .. myVariable print(myString)
should produce:
Hello World 5
In your example you could do the following:
... myScalingVariable = 2.5 -- Create a math script farFieldMathScript = app.MathScripts:Add(pf.Enums.MathScriptTypeEnum.FarField) script = [[ dataSet = pf.FarField.GetDataSet("startup.StandardConfiguration1.FarFields", 51) scale = ]] .. myScalingVariable .. [[ for freqIndex = 1, #dataSet.Axes["Frequency"] do for thetaIndex = 1, #dataSet.Axes["Theta"] do ...
Inside the math script, then line defining the scale variable should then automatically read:
scale = 2.5
Note that the empty line at the start of the second block of text is required to ensure that the following code starts on a new line in the math script.
Kind regards,
Johan H
1 -
Johan Huysamen_22531 said:
Hi Israel
The definition of the math script is simply a block of text. Provided that you are able to pass the numerical value of your variable as a string, it should be possible to include it in the math script.
When concatenating a string with a numerical variable in Lua, the value of the variable is included as a string. For example:
myVariable = 5 myString = "Hello World " .. myVariable print(myString)
should produce:
Hello World 5
In your example you could do the following:
... myScalingVariable = 2.5 -- Create a math script farFieldMathScript = app.MathScripts:Add(pf.Enums.MathScriptTypeEnum.FarField) script = [[ dataSet = pf.FarField.GetDataSet("startup.StandardConfiguration1.FarFields", 51) scale = ]] .. myScalingVariable .. [[ for freqIndex = 1, #dataSet.Axes["Frequency"] do for thetaIndex = 1, #dataSet.Axes["Theta"] do ...
Inside the math script, then line defining the scale variable should then automatically read:
scale = 2.5
Note that the empty line at the start of the second block of text is required to ensure that the following code starts on a new line in the math script.
Kind regards,
Johan H
Thanks a lot! This will be very helpful.
0