FlowAroundCylinderPerformance.py 6.66 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import waLBerla as wlb
import os
import sys
import sqlite3
import numpy as np
from waLBerla.tools.sqlitedb import sequenceValuesToScalars, checkAndUpdateSchema, storeSingle

from lbmpy.relaxationrates import relaxation_rate_from_lattice_viscosity

def safe_int(some_float):
    assert int(some_float) == some_float, f"{some_float} is not an integer. :("
    return int(some_float)

class FlowAroundCylinderScenario:
Frederik Hennig's avatar
Frederik Hennig committed
15
    def __init__(self, domainSize, cylinderCenter, cylinderRadius, cylinderRadius_coarsest_LU,
16
17
18
19
                 cellsPerBlock,
                 peakInflowVelocity_LU, reynoldsNumber, walls,
                 refinementProfile, refinementDepth,
                 refinementRadii=(0,0,0), refinementTailLengths=(0,0,0),
Frederik Hennig's avatar
Frederik Hennig committed
20
                 useUniformPackInfo=False,
21
                 runs=10, steps_per_run=1000, outputFrequency=0,
Frederik Hennig's avatar
Frederik Hennig committed
22
                 db_file='benchmark.sqlite', db_table='runs', vtkOutputFolder='vtk_out'):
23

Frederik Hennig's avatar
Frederik Hennig committed
24
        dx_coarsest = cylinderRadius / cylinderRadius_coarsest_LU
25
26
27
28
29
30
31
32
33
        totalCells_coarsest = tuple(safe_int(ds / dx_coarsest) for ds in domainSize)
        rootBlocks = tuple(safe_int(c / cpb) for c, cpb in zip(totalCells_coarsest, cellsPerBlock))

        cylinderRadius_coarsest_LU = cylinderRadius / dx_coarsest

        lattice_viscosity = (2 * cylinderRadius_coarsest_LU * peakInflowVelocity_LU) / reynoldsNumber
        omega_shear = relaxation_rate_from_lattice_viscosity(lattice_viscosity)

        self.db_file = db_file
Frederik Hennig's avatar
Frederik Hennig committed
34
        self.db_table = db_table
35
36
37
38
39
40
41
42

        self.params = {
            'domainSize': domainSize,
            'rootBlocks': rootBlocks,
            'cellsPerBlock': cellsPerBlock,
            'periodic': (0, 0 if walls else 1, 1),

            'vtkWriteFrequency': outputFrequency,
Frederik Hennig's avatar
Frederik Hennig committed
43
            "vtkBaseFolder": vtkOutputFolder,
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

            'runs': runs,
            'stepsPerRun': steps_per_run,

            'setup': 'FlowAroundCylinder',

            'cylCenter': cylinderCenter,
            'cylRadius': cylinderRadius,

            'omegaShear': omega_shear,

            'peakInflowVelocity': peakInflowVelocity_LU,
            'inflowParabolicProfile': 1 if walls else 0,
            'walls': walls,

            'refinementProfile': refinementProfile,
            'refinementDepth': refinementDepth,
            'refinementRadii': refinementRadii,
Frederik Hennig's avatar
Frederik Hennig committed
62
63
            'refinementTailLengths': refinementTailLengths,
            'useUniformPackInfo': useUniformPackInfo
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
        }

    @wlb.member_callback
    def config(self, **kwargs):
        config_dict = {
            "Parameters": self.params
        }

        wlb.log_info_on_root(f"Running with Parameters:\n{config_dict}")
        return config_dict

    @wlb.member_callback
    def results_callback(self, **kwargs):
        result = dict()

        #   Parameters
        result.update(self.params)

        #   Build Information
        result['compile_flags'] = wlb.build_info.compiler_flags
        result['walberla_version'] = wlb.build_info.version
        result['build_machine'] = wlb.build_info.build_machine

        #   Run Information
        result['executable'] = sys.argv[0]

        #   MPI processes and OMP threads come by kwargs

        #   Environment Information
        result['num_nodes'] = int(os.environ.get('NUM_NODES', -1))
        result['virtual_cores_per_node'] = int(os.environ.get('VIRTUAL_CORES_PER_NODE', -1))
        result['processes_per_node'] = int(os.environ.get('PROCESSES_PER_NODE', -1))

        #   Codegen Setup and Results
        result.update(kwargs)

        wlb.log_info_on_root(f"Storing Results:\n{result}")

        sequenceValuesToScalars(result)
        num_tries = 4
        # check multiple times e.g. may fail when multiple benchmark processes are running
        for num_try in range(num_tries):
            try:
Frederik Hennig's avatar
Frederik Hennig committed
107
108
                checkAndUpdateSchema(result, self.db_table, self.db_file)
                storeSingle(result, self.db_table, self.db_file)
109
110
111
112
113
114
115
                break
            except sqlite3.OperationalError as e:
                wlb.log_warning("Sqlite DB writing failed: try {}/{}  {}".format(num_try + 1, num_tries, str(e)))

def run_flow_around_cylinder(db_file):
    manager = wlb.ScenarioManager()

Frederik Hennig's avatar
Frederik Hennig committed
116
117
    cells_per_block = 8

118
    manager.add(FlowAroundCylinderScenario(
Frederik Hennig's avatar
Frederik Hennig committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
        domainSize=(18, 8, 1),
        cylinderCenter=(4, 4, 0),
        cylinderRadius=1,
        cylinderRadius_coarsest_LU=16,
        cellsPerBlock=(cells_per_block, cells_per_block, cells_per_block),
        peakInflowVelocity_LU=0.05,
        reynoldsNumber=100,
        walls=False,
        refinementProfile='refineEverywhere',
        refinementDepth=0,
        refinementRadii=(2, 1.5, 1.125), refinementTailLengths=(10, 8, 6),
        useUniformPackInfo=True,
        runs=1, steps_per_run=101, outputFrequency=100,
        db_file=db_file
133
134
    ))

Frederik Hennig's avatar
Frederik Hennig committed
135

Frederik Hennig's avatar
Frederik Hennig committed
136
def run_flow_around_cylinder_emmy():
Frederik Hennig's avatar
Frederik Hennig committed
137
138
139
    manager = wlb.ScenarioManager()

    cylinderRadiusCoarseLU = 64
Frederik Hennig's avatar
Frederik Hennig committed
140
141
142
    
    ppn = os.environ['PROCESSES_PER_NODE']
    
Frederik Hennig's avatar
Frederik Hennig committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    refinementSetups = [
        {'refinementProfile': 'refineEverywhere',
         'refinementDepth': 0,
         'useUniformPackInfo': True},
        {'refinementProfile': 'refineEverywhere',
         'refinementDepth': 0,
         'useUniformPackInfo': False},
        {'refinementProfile': 'ConcentricCylinderWake',
         'refinementDepth': 3,
         'refinementRadii': (2, 1.5, 1.125),
         'refinementTailLengths': (10, 8, 6)}
    ]

    for cells_per_block in [64, 32, 16, 8]:
        for i, setup in enumerate(refinementSetups):
Frederik Hennig's avatar
Frederik Hennig committed
158
            output = f"CylinderOutput_{ppn}ppn_{cells_per_block}cells_{i}"
Frederik Hennig's avatar
Frederik Hennig committed
159
160
161
162
163
164
165
166
167
168
169

            manager.add(FlowAroundCylinderScenario(
                domainSize=(18, 8, 1),
                cylinderCenter=(4, 4, 0),
                cylinderRadius=1,
                cylinderRadius_coarsest_LU=cylinderRadiusCoarseLU,
                cellsPerBlock=(cells_per_block, cells_per_block, cells_per_block),
                peakInflowVelocity_LU=0.05,
                reynoldsNumber=100,
                walls=False,
                runs=10, steps_per_run=10, outputFrequency=0,
Frederik Hennig's avatar
Frederik Hennig committed
170
171
                db_file=f"CylinderBenchmark.sqlite",
                db_table=f"setup{i}",
Frederik Hennig's avatar
Frederik Hennig committed
172
173
174
175
176
                vtkOutputFolder=output,
                **setup
            ))


177
178
if __name__ == '__main__':
    # make runscript
Frederik Hennig's avatar
Frederik Hennig committed
179
    from makeEmmyRunscript import get_script_d3q19_esotwist_True
180
181
182
    scenario_script = "FlowAroundCylinderPerformance.py"
    scripts_dir = 'cylinderrun'
    os.makedirs(scripts_dir, exist_ok=True)
Frederik Hennig's avatar
Frederik Hennig committed
183
    for num_nodes in [64]:
184
185
        filename = f'{scripts_dir}/flowAroundCylinderBM_{num_nodes}nodes.sh'
        with open(filename, 'w') as shfile:
Frederik Hennig's avatar
Frederik Hennig committed
186
            shfile.write(get_script_d3q19_esotwist_True(num_nodes, [1, 5, 10], scenario_script, walltime="03:00:00"))
187
else:
Frederik Hennig's avatar
Frederik Hennig committed
188
    run_flow_around_cylinder_emmy()