How to reduce the parameter space in pyFoam: a simple solution

This how-to describes how to reduce the number of cases generated by pyFoamRunParameterVariation.py by brute force: by executing case creation for each chosen individual case from the cartesian product of parameter vectors.

Step-by-step guide

  1. Call the pyFoamRunParameterVariation.py with the list parameter option and from the output to examine the variations you are interested in.
  2. Call the pyFoamRunParameterVariation.py within the loop over all interesting variations with the option to create an individual variation.

Step 1: list variations

A list of all variations can be generated by the following command:

 ?> pyFoamRunParameterVariation.py --list-variations cavity cavity.parameter
 
 
===============================
30 variations with 2 parameters
===============================
 
 
==================
Listing variations
==================
 
Variation 0 : {'U': 1, 'N': 4}
Variation 1 : {'U': 1, 'N': 8}
Variation 2 : {'U': 1, 'N': 16}
Variation 3 : {'U': 1, 'N': 32}
Variation 4 : {'U': 1, 'N': 64}
Variation 5 : {'U': 2, 'N': 4}
Variation 6 : {'U': 2, 'N': 8}
Variation 7 : {'U': 2, 'N': 16}
Variation 8 : {'U': 2, 'N': 32}
Variation 9 : {'U': 2, 'N': 64}
Variation 10 : {'U': 3, 'N': 4}
Variation 11 : {'U': 3, 'N': 8}
Variation 12 : {'U': 3, 'N': 16}
 
...

From this list, a sub-set of variations can be selected. In this simplest example, even variations are selected.

Step 2: generate a sub-set of cases for selected variations

Run the pyFoamRunParameterVariation.py in the following way:

 #!/usr/bin/env bash
 
CASE=$1
PARAMETERS=$2
STUDY_NAME=$3
 
 
for i in 2 4 6 8 10;
do
    pyFoamRunParameterVariation.py --every-variant-one-case-execution \
        --create-database \
        --no-execute-solver \
        --no-server-process \
        --cloned-case-prefix=$STUDY_NAME \
        --single-variation=$i \
        $CASE \
        $PARAMETERS
done

You can find this script also in the example code repository.

This is the most simple possible solution and it works well for small parameter sets and simple rules of excluding variations. A more advanced way of achieving this would be to read the created database and use SQL queries to select the variations based on a criterion.

See also