tools module¶
Jobscript Generation¶
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, alter_table=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 (only when alter_table is set to True),
existing data has NULL in these new columns
- Parameters:
data – see
storeSingle()
orstoreMultiple()
:param tableName name of the table which should be updated :param dbFile name of the sql file which should be written :param 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
- :param alter_table If True the columns of the table will be altered.
Should be called if new columns should be inserted.
- 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.block_decomposition(processes)¶
Compute a 3D factorization of ‘processes’ in a 3 factors returned as tuple
- 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" # noqa: E501
# 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.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.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.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
- 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