# Optimising the Bandpass Filter with HyperStudy Using Scripting

Configure the HyperStudy setup and perform the optimisation. Minimize the reflection coefficient.

1. Copy the files from %FEKO_HOME%/help/feko/example/ExampleGuide_models/Example-I04-HyperStudy_bandpass_filter_optimisation/opt_scripting to a work directory.
Note: Ensure that you have write permissions in the work directory and that the directory is not “read only”.

The provided extraction script bandpassfilter.cfx_extract.lua is preconfigured to calculate s11avg for the filter and write the result to a HyperStudy .hstp file.

-- 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 s-parameter result
local sparam = pf.SParameter.GetDataSet( pf.SParameter.GetNames()[1] )
local s11 = sparam[1][1].SParameter

-- Calculate the average reflection coefficient across the frequency band
local s11avg = 0
local num_frequencies = sparam.Axes[pf.Enums.DataSetAxisEnum.Frequency].Count
for findex = 1,num_frequencies do
s11avg = s11avg + sparam[findex][1].SParameter:Abs()
end
s11avg = s11avg/num_frequencies

-- Create the output file
file = HstUtl.NewOutputFile( )
HstUtl.StoreScalarValue( file, "s11avg", s11avg )
HstUtl.WriteFile( file )
-- End of file
2. Open Altair HyperStudy.
3. Under the Study group, click New.
The Add Study dialog is displayed.
4. [Optional] In the Label field, specify a name for the study.
5. Under Location enter the path to the work directory where the bandpassfilter.cfx is located.
6. Click Setup > Definition > Define models in the Explorer tab.
8. Under Select Type, select FEKO and click OK.
9. Under Resource, browse to bandpassfilter.cfx in the work directory.
Tip: Step 8 and Step 9 can be combined in a simple drag and drop of the bandpassfilter.cfx from the Windows File Explorer into HyperStudy.
Note:
• The solver script is registered automatically. The script is accessible under Edit > Register Solver Script, which offers the possibility to register another solver or version.
• The Solver Input Arguments show \${filebasename} by default. The argument –np can be typed here to specify the number of cores to use.
• The provided file bandpassfilter.cfx_extract.lua is expected to be saved in the same location as the model file.
10. Click Import Variables to import CADFEKO model variables.
11. Click Next.
12. Select which variables to include in the study. Only S1 – S3 should be activated and the default ranges used.
An example of the selected variables is displayed.
13. Click Next.
14. Click Run Definition.
During the Write phase, the bandpassfilter.cfx_extract.lua file was copied to the run directory and executed after the Feko solver was run in the Extract phase. This generated an output file that HyperStudy can process easily.
Note: The script bandpassfilter.cfx_extract.lua is different if a .pfs file was present before importing the variables and will automatically extract the visible traces on a Cartesian graph and polar graph.
See Figure 7 for the completed definition run for the Write, Execute and Extract phases for the initial test run done by HyperStudy.
15. Click Next.
16. Click File Assistant.
The File Assistant dialog is displayed.
17. Browse to ./m_1/hst_output.hstp in the default run directory.
18. Confirm that Altair HyperWorks (HstReaderPdd) is selected and click Next.
19. Confirm that Single Item in a Time Series is selected and click Next.
20. Confirm that s11avg is selected and click Next.
21. In the Label field, enter s11avg to change the name of the response label.
22. Click Finish to close the dialog.
23. Under Goals click to add an optimisation goal.
The following dialog is displayed.
24. Set the goal Type to Minimize and click OK.
25. Click Evaluate to extract the value from the output file.
HyperStudy is now configured to understand which model to use, which variables are available for modification and how to process the output.
26. Right-click on the defined study in the Explorer tab and click Add.
27. Under Select Type, select Optimization and click OK.
The optimisation approach is created in the Explorer tab
28. Click Optimization 1 > Specifications, and select the Adaptive Response Surface Method as the optimiser.
29. Click Apply and click Next.