.lua script for exporting far field data

mraei047
mraei047 Altair Community Member
edited October 2020 in Community Q&A

Hi, 

I am looking for help with extracting the far field data from FEKO and importing it into HyperStudy. I have tweaked the .lua script which was provided in example I-4 in the Example Guide.  
The attached script seems to run without any errors (dummy value is imported into HyperStudy) if I comment out lines 17 and 24 of the attached code. 

Any help is appreciated :)/emoticons/default_smile.png' srcset='/emoticons/smile@2x.png 2x' title=':)' width='20' /> 
 

 

 


Here is the code is plain text: 

 

--
-- Run into POSTFEKO to fetch results and push the scalar values to a HyperStudy .hstp file
--

HstUtl = require 'hst.hstutl'
local app = pf.GetApplication()
local config = app.Models[1].Configurations[1]

-- Get first far field result
local f_field = pf.FarField.GetDataSet( pf.FarField.GetNames()[1] )
 -- get theta values (x-axis) 
local num_frequencies = f_field.Axes[pf.Enums.DataSetAxisEnum.Theta].Count


--local ffdata={}
for findex = 1,num_frequencies do  
ffdata[findex]=f_field[findex].FarFields[1]:Abs()
end

local dummy=1
-- Create the output file
file = HstUtl.NewOutputFile( )
HstUtl.StoreScalarValue( file, 'dummy', dummy)
HstUtl.StoreScalarList( file, 'ffdata', ffdata)
HstUtl.WriteFile( file )
-- End of file

 





 


 

Unable to find an attachment - read this blog

Tagged:

Answers

  • JIF
    JIF
    Altair Employee
    edited September 2018

    Hello mraei047,

     

    I can see a few mistakes already, but it would help if you could send the model that you are trying to use in HSt. This just makes it easier for me to change the script and check that it works. The alternative would be that I need to create a model to try to get your script to work.

    Problems I can see by just looking at the script:

    • Your variable for 'num_frequencies' is using the Theta axis and thus the value will not be the number of frequencies.
    • You are only indexing into the frequency axis and not the other axes in the FOR loop. This won't work. The manual has an example of how to loop over more axes (repeated below).
     for freqIndex = 1, #myDataSet.Axes['Frequency'] do     for xIndex = 1, #myDataSet.Axes['X'] do         for yIndex = 1, #myDataSet.Axes['Y'] do             for zIndex = 1, #myDataSet.Axes['Z'] do                  indexedValue = myDataSet[freqIndex][xIndex][yIndex][zIndex]                 xValue = indexedValue:AxisValue(pf.Enums.DataSetAxisEnum.X)                 yValue = indexedValue:AxisValue(pf.Enums.DataSetAxisEnum.Y)                 zValue = indexedValue:AxisValue(pf.Enums.DataSetAxisEnum.Z)                 r = math.sqrt((xValue*xValue)+(yValue*yValue)+(zValue*zValue))                 indexedValue.TotalEField = 1/r + j*(1/r)                 indexedValue.Threshold = 1             end         end     end end

     

    There are also more 'clever' ways to loop through all axes using ForAllValues (function) - see 'Iterate Through Elements in a DataSet' section in the manual.

    The rest seems fine (without testing, but just looking at the script).

  • mraei047
    mraei047 Altair Community Member
    edited September 2018

    Hi Jif, 

    Thanks for your response. you are right about the variable 'num_frequencies', it should be 'num_theta' the goal of having this variable is to capture all points on the x-axis. I just forgot to update the variable name when I copied the script. 

    I have attached the (test.cfx) as well as the (test.xml) files for your review. 


    Thanks,

    Unable to find an attachment - read this blog

  • JIF
    JIF
    Altair Employee
    edited September 2018

    Hello

     

    Try the following file. I added some commented out code that you can uncomment in case you want to see other options and contents of some variables. Here I have simply assumed that you are interested in the total gain of the far field and since you were writing a scalar value, I simply picked one (the 5th theta point). If you want to use the maximum or something else, you need to calculate that value and write it. You can also write a list of values and then process the data in HyperStudy.

     -------------------------------------------------------------------------------- -- -- This file is overwritten during the HyperStudy task of 'Write' -- Written: ( 2018-09-27 16:32:58 ) -- From:    ( C:\Users\mraei047\Desktop\test\test.cfx_extract.lua ) -- To:      ( C:\Users\mraei047\Desktop\test\approaches\nom_1\run__00001\m_1\test.cfx_extract.lua ) -- -- Command: ( postfeko <modelname>.fek --run-script SCRIPTFILE ) -- --------------------------------------------------------------------------------  -- -- Run into POSTFEKO to fetch results and push the scalar values to a HyperStudy .hstp file --  HstUtl = require 'hst.hstutl' DR = require('DeriveResults')  local app = pf.GetApplication() local config = app.Models[1].Configurations[1]  -- Get first far field result f_field = config.FarFields[1]:GetDataSet()  -- Calculate Directivity, Gain, etc. from the 'raw' electric field data and factors stored in the FF DataSet -- printlist(DR.Enums.FarFieldQuantityTypeEnum) -- printlist(DR.Enums.FarFieldQuantityComponentEnum) GainTotalDS = DR.FarField.Gain( f_field, 'Total' ) -- DirectivityDS = DR.FarField.Directivity( f_field, 'Theta' )   -- Get theta values local num_theta = GainTotalDS.Axes[pf.Enums.DataSetAxisEnum.Theta].Count  -- print(GainTotalDS) local ffdata={} for ThetaIndex = 1,num_theta do     ffdata[ThetaIndex] = GainTotalDS[1][ThetaIndex][1].Gain end -- printlist(ffdata)  -- Create the output file file = HstUtl.NewOutputFile( ) HstUtl.StoreScalarValue( file, 'ffdata', ffdata[5]) -- If you want a single value (I just picked the 5th angle as an example) -- HstUtl.StoreScalarList( file, 'ffdata', ffdata) -- If you want a list of values (refine in HSt) HstUtl.WriteFile( file ) -- End of file

    Note that I'm aware that figuring out some of this is not easy and we have an issue to improve it and improve the documentation. This is especially true for the HstUtl and DerivedResults modules.