Skip to content
Snippets Groups Projects
Commit 86f7c332 authored by Dominic Kempf's avatar Dominic Kempf
Browse files

Add some compiler infrastructure

parent 53079ad5
No related branches found
No related tags found
No related merge requests found
"""
The methods to run the parts of the form compiler
Should also contain the entrypoint methods.
"""
def read_ufl(uflfile=None):
assert uflfile
from ufl.algorithms.formfiles import read_ufl_file, interpret_ufl_namespace
from ufl.algorithms import compute_form_data
uflcode = read_ufl_file(uflfile)
namespace = {}
uflcode = "from dune.perftool.runtime_ufl import *\n" + uflcode
exec uflcode in namespace
data = interpret_ufl_namespace(namespace)
formdata = compute_form_data(data.forms[0])
return formdata
def write_driver(formdata=None, filename=None):
assert formdata
assert filename
# The driver module uses a global variable for ease of use
import dune.perftool.driver
dune.perftool.driver._formdata = formdata
# The vtkoutput is the generating method that triggers all others.
# Alternatively, one could use the `solve` method.
from dune.perftool.driver import vtkoutput
vtkoutput()
from dune.perftool.generation import cache_preambles, cache_includes
includes = cache_includes()
# Get all preambles for the driver and sort them.
driver_content = [i[1] for i in sorted(cache_preambles(), key=lambda x : x[0])]
# And flatten out those, that conained nested lists
def flatjoin(l):
if isinstance(l, str):
return "\n" + l
return "".join(flatjoin(i) for i in l)
from cgen import LiteralBlock, FunctionDeclaration
driver = LiteralBlock(flatjoin(driver_content))
# Write the file.
f = open(filename, 'w')
f.write("\n".join(cache_includes()))
f.write("\nvoid driver(int argc, char** argv)\n")
f.write("\n".join(driver.generate()))
def write_localoperator():
pass
def compile_form():
pass
""" A module that manages the command line options to the form compiler executable """
from pytools import memoize
@memoize
def get_form_compiler_arguments():
from argparse import ArgumentParser
parser = ArgumentParser(description="Compile UFL files to PDELab C++ code", epilog="Please report bugs to dominic.kempf@iwr.uni-heidelberg.de")
parser.add_argument("uflfile", type=str, nargs=1, help="the UFL file to compile")
# parser.add_argument("--numerical-jacobian", action="store_true", help="use numerical jacobians (only makes sense, if uflpdelab for some reason fails to generate analytic jacobians)")
# parser.add_argument('--version', action='version', version='%(prog)s 0.0')
# parser.add_argument("--operator-file", type=str, help="The filename for the generated local operator header")
# parser.add_argument("--driver-file", type=str, help="The filename for the generated driver header")
# parser.add_argument("--param-class-file", type=str, help="The filename for the generated parameter class header")
# parser.add_argument("--export-trafo-graphs", action="store_true", help="export expression graphs after the application of each single transformation")
# parser.add_argument("--parameter-tree", action="store_true", help="have the generated local operate take a Dune::ParameterTree as constructor argument")
# parser.add_argument("--inifile", type=str, help="The inifile that this program's driver should be hardcoded to. Omit to use a commandline argument ini file")
return vars(parser.parse_args)
def get_option(key):
return get_form_compiler_arguments()(key)
\ No newline at end of file
......@@ -32,4 +32,9 @@ setup(name='dune.perftool',
packages=['dune.perftool'],
install_requires=[],
tests_require=['pytest'],
cmdclass={'test': PyTest})
cmdclass={'test': PyTest},
entry_points = {
"console_scripts": [
"ufl2pdelab = dune.perftool.compiler:compile_form",
]
})
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment