tools module

Jobscript Generation

This module can creates job scripts for various supercomputers See :func:createJobscript

waLBerla.tools.jobscripts.createJobscript(*args, **kwargs)
Parameters:
  • machine – Currently supported target machines are supermuc, supermuc_phase2, juqueen and hornet
  • nodes – Number of nodes to run on. You can either specify nodes or cores.
  • cores – specify eiter nodes or cores. If using more than one node the nodes have to be filled completely
  • job_class – optional, the jobclass is usually computed depending on number of nodes and wall_time, this parameter overrides this
  • initial_dir – initial working directory of the job, optional, defaults to home directory
  • job_name – name of the job in the queuing system, defaults to ‘waLBerla’
  • output_file – file where stdout will be redirected to by the queueing system
  • input_file – file where stderr will be redirected to by the queueing system
  • energy_tag – energy tag for SuperMUC[1,2]

Use one of the following options:

Run single program with different parameter files ( mpirun is prepended with correct number of processes )

Parameters:
  • exe_name – executable name, if not specified only the jobscript header is generated
  • parameter_files – list of parameter files to simulate

Run multiple programs:

Parameters:commands – can be either a list of two-tuples with (executableName, configFile), which are then run in this order with mpirun or a list of string which are just appended to the jobscript file

Sqlite3 Helpers

waLBerla.tools.sqlitedb.storeSingle(data, tableName, dbFile='database.sqlite', runId=None)

Stores results of a single simulation run to a sqlite database.

Primary key column ‘runId’ and a timestamp are automatically added.

param data:Dictionary with data to store in sqlite database. The dictionary keys are assumed to be column names.
param tableName:
 name of sqlite table
param dbFile:database file
param runId:override the otherwise manually created runId which serves as primary key
return:runId of inserted run
waLBerla.tools.sqlitedb.storeMultiple(data, tableName, dbFile='database.sqlite', runId=None)

Stores data from multiple simulation runs into the database.

Parameters:
  • data – similar to storeSingle, but each value of the dictionary has to be a list for all keys the values have to be lists of equal length
  • runId – leave this to none if runId is the primary key of this table if this table references a table with primary key runId, you can reference a specific run by passing here the id of the run to reference.
Returns:

primary key of last inserted run, the other runs have runId: returnValue-1, returnValue-2, ...

waLBerla.tools.sqlitedb.checkAndUpdateSchema(data, tableName, dbFile='database.sqlite', referenceRuns=False)

Alters a sqlite table in order to match the given data:

  • if table with given name does not exist yet, it is created
  • keys in the data dictionary correspond to columns
  • columns are added if necessary, existing data has NULL in these new columns
Parameters:
  • data – see storeSingle() or storeMultiple()
  • referenceRuns – if False the table gets an autoincrementing integer column ‘runId’ if True, a normal column runId is created that points into another table with runId as primary key
waLBerla.tools.sqlitedb.mergeSqliteFiles(targetFile, fileToMerge)

Merges sqlite3 database ‘fileToMerge’ into ‘targetFile’ database. Works only if both tables have a ‘runs’ table. Other tables are ignored! If the runs table in one of the databases has more columns, these columns are created in the merged database.

PRM Files

waLBerla.tools.config.fromPrm(fileAsString)

Parses a prm file to a nested python dict

waLBerla.tools.config.toPrm(configDict, level=0)

Returns a prm string from a nested python dict - Inverse of parse

LBM Unit Conversion

class waLBerla.tools.lbm_unitconversion.PintUnitConverter(ureg=<pint.registry.UnitRegistry object>, **kwargs)
__init__(ureg=<pint.registry.UnitRegistry object>, **kwargs)
Possible arguments (all in SI units):
  • l_m (lattice meter, same as dx)
  • l_s (lattice second, same as dt)
  • l_kg (lattice kilogram)
  • same for other SI units
Example:
conv = PintUnitConverter( l_m = 1e-6, l_s = 1e-7 )
conv_config(config)
conv_config_unit_strings(config)
define_lattice_units(**kwargs)

Defines lattice units

to_si_units(value)

SI= Systeme international d’unites, International System of Units

to_si_units_mag(value)
to_sl_units(value)

SL = Lattice System of Units

to_sl_units_mag(value)
waLBerla.tools.lbm_unitconversion.extractLatticeFactors(config, constant=True)

takes config dictionary and extracts lattice factors

waLBerla.tools.lbm_unitconversion.computeLatticeFactors(constant=True, **kwargs)

Computes lattice factors with given physical input values

Parameters:kwargs – dictionary with symbol name as key and the physical value as value
Returns:lattice factors as dictionary with name, value

HTML Reports

This module creates HTML reports based on the Flask and Jinja2 packages.

Attention

This module is not actively developed any more - consider using IPython Notebook instead

It provides custom template markup for generating matplotlib graphs with data from a sqlite3 database. To use this module one first has to write the simulation results to a sqlite3 database e.g. using waLBerla.tools.sqlite

Then create a Jinja2 HTML template. Here is an example using base templates provided by this module:

{% extends "waLBerla/bootstrap_report.html" %}
{% block content %}
<div class="container">
  <div class="text-center">
    <h1> MySetup </h1>
    
    {% matplotlib %}
        # Some SQL query that returns a two column result
        q = "SELECT capillaryNr,shapeFactor FROM runs WHERE yCells=160 AND zCells=160 AND bubbleDiameter=60 ORDER BY capillaryNr"
        # plt is matplotlib.pyplot extended with the custom 'dbplot' function
        plt.dbplot( q, label="sim shapefactor", marker="o" )
        plt.legend( loc='center')
    {% endmatplotlib %}
  </div>
</div>

Then use one of the functions provided by this module to create an HTML page from this template. Either once or run a small webserver that reloads the template if it was changed.

waLBerla.tools.report.runWebserver(context={}, plot_funcs={}, database_file='database.sqlite', open_browser=False, debug=True)

Runs a small local webserver using the flask module ( pip3 install flask ) serving the report. When refreshing in the browser the report is updated.

waLBerla.tools.report.cliFrontend(context={})

Command line interface for above functions

waLBerla.tools.report.generate(context={}, plot_funcs={}, database_file='database.sqlite', input_output_list=None, open_browser=False)

Generates a html report. Uses jinja2 templating engine with custom matplotlib tag, which inserts matplotlib figures as svg graphics

waLBerla.tools.report.setupFlaskApp(app, context={}, plot_funcs={}, database_file='database.sqlite')

Call this function to set up your custom flask app. This is an advanced function, probably you want to use runWebserver instead