|
Navigation: GeoDict 2025 - User Guide > Automation > GeoPy Scripting > Parameter Studies |
Scroll |
Create Parameter Macro
Transform a simple macro into a parameter macro for a parameter study. For this, learn how to add variables to a recorded macro. Access these variables as parameters in the Macro Execution Control and run a parameter study using Vary parameters.
Note! Since GeoDict 2025 the variables block can be given as a list of dictionaries, one for each variable. This comes with the advantage, that it is not needed anymore to count the variables. |
Know how! You can download the variable_study.py file created in this chapter for inspection. |
Start by recording the simple macro (simple_macro.py) during the generation of a fibrous structure with the default values in FiberGeo. Therefore, start macro recording. We chose the name “simple_macro.py”. Then select Module → FiberGeo and click Record. The default value for Random Seed is 42 and the single value for Object Solid Volume Percentage is 10. ![]() Afterwards, end the recording of the macro, by selecting Macro → End Macro Recording. Check now Macro → Execute Macro / Script …. Click Refresh and, in the Macro Execution Control section, look for simple_macro.py in the pull-down menu list. The description area displays a short report about it. simple_macro.py does not contain any variables at this point and thus, Fixed and Vary are grayed out. ![]() Click Edit… and open simple_macro.py in the text editor of choice (here NotePad++). ![]() No variables are yet defined in simple_macro.py. The Variables block is where they are defined and where they will be modified for the parameter study. The first command is to create a structure (FiberGeo:Create). In the parameter dictionary Create_args_1 first the Domain parameters are given. These parameters are not changed in our example. Among other parameters, now follow the parameters corresponding to overlap mode, stopping criterion, number of objects, random seed, and other options that can be found in FiberGeo under the Create Options tab of the FiberGeo Options dialog. From these parameters, the Solid Volume Percentage, the Random Seed and the Fiber Diameter will be used as variables and their entries in the macro are changed in the next step of this example. |
After opening it in a text editor, start editing the simple_macro.py by adding description information as shown here. This is later displayed in the description area of the Macro Execution Control section. ![]() In the Variables block, (as shown above) uncomment the variable block by deleting the # signs. Copy and paste the default dictionary (the block from "{" to "}") to add a second and third variable element. The first variable is given the Name gd_SVP, the second variable is given the name gd_RandomSeed and the third and last one is given the name gd_FiberDiameter. These names can be chosen as desired, but it is recommended to choose names describing their usage in the macro to improve readability. This is also the only reason for the prefix gd_, marking which variables in the macro are defined from the Parameters dialog and which are defined within the macro. The variables would also work without the prefix and different names, but then the macro code could be harder to understand for others. The first and third variable are type double and the second is type integer ('int'). There are many more available variable types. The starting BuiltinDefault values are 10 (%) for SVF, 42 for Random Seed and 10 (µm) for Fiber Diameter. Some helpful hints on syntax for these variables appear below the variables block. To store the output of the parameter study, change from the project folder to a new folder with the name Variable_Study. For this purpose, add the GeoDict:ChangeProjectFolder command to save the results in the new folder 'Variable_Study'. ![]() Right in the first line of the dictionary, change the ResultFileName from 'FiberGeo.gdr' to: f'FiberGeo_{gd_SVP}_{gd_RandomSeed}_{gd_FiberDiameter}.gdr', to associate the name of the result files (in GDR format) to the outcome of the parameter study. In this way, the result file names indicate the random seed, SVP and diameter values applied to the generated structure. ![]() In the block FiberGeo:Create, the Domain parameters are not modified In the next group of parameters, for SolidVolumePercentage, change the numerical value 10 to gd_SVP and, for RandomSeed, the value of 47 to gd_RandomSeed. gd_SVP and gd_RandomSeed are placeholders for the sets of values to be defined when running the macro (Macro Execution Control dialog box). ![]() Finally, in the block Generator1, more precisely in the subblock DiameterDistribution replace the Value 1e-05 by gd_FiberDiameter * 1e-06. The factor 1e-06 is needed, as the fiber diameters in the dictionary must be given in meter. Thus, the fiber diameter of the first fiber type can be changed in the parameter study, editing the value in microns. ![]() In the editor, save the modified macro as variable_study.py (NotePad++: File → Save As...) |
Back in the Macro Execution Control section, click Refresh to actualize the left panel and select (the just saved) variable_study from it. The text entered under Description in the edited macro is shown in the description area and, since now the macro contains variables, Vary is available to be checked. Check it and click the Parameters button. ![]() The BuiltinDefault values that were specified in the variables block (10, 42 and 10) appear in the boxes for Solid Volume Percentage, Random Seed and Fiber Diameter. The labels of both variables have been taken from the variable_study.py file. ![]() To set the parameter study, enter four values of increasing Solid Volume Percentage (10%, 20%, 30% and 40% SVP), three random seed values (e.g. 47, 48 and 49) and two values for Fiber Diameter (e.g. 10 and 20). Leave the Variation for all three at VARY. ![]() Click OK and, in the Macro Execution Control section, click Run. The execution of the variable_study.py macro takes only a short time and creates three random realizations of a structure for every one of the four SVP values, combined with every fiber diameter value. The outcome is 48 items saved in the project folder Variable_Study: 24 result files (e.g. FiberGeo_10.0_47_10.0.gdr) and 24 folders, each with a structure file (*.gdt) inside (e.g. FiberGeo_10.0_47_10.0). ![]() These 24 result files can be opened in GeoDict, and the Result Viewer offers the possibility to combine some or all results in a plot. See the Result Viewer topic for more details. |
©2025 created by Math2Market GmbH / Imprint / Privacy Policy
