Skip to content
Snippets Groups Projects
Commit 8b9121bd authored by René Heß's avatar René Heß
Browse files

Global imports in compile.py

parent 81d066bb
No related branches found
No related tags found
No related merge requests found
...@@ -4,24 +4,46 @@ The methods to run the parts of the form compiler ...@@ -4,24 +4,46 @@ The methods to run the parts of the form compiler
Should also contain the entrypoint methods. Should also contain the entrypoint methods.
""" """
from __future__ import absolute_import from __future__ import absolute_import
from os.path import splitext from os.path import basename, splitext
# Disable loopy caching before we do anything else!
import loopy import loopy
from ufl.algorithms import compute_form_data, read_ufl_file
from ufl.algorithms.formfiles import interpret_ufl_namespace
from dune.perftool.generation import delete_cache_items, global_context
from dune.perftool.interactive import start_interactive_session
from dune.perftool.options import get_option
from dune.perftool.pdelab.driver import generate_driver
from dune.perftool.pdelab.localoperator import (generate_localoperator_basefile,
generate_localoperator_file,
generate_localoperator_kernels,
name_localoperator_file)
from dune.perftool.ufl.preprocess import preprocess_form
# Disable loopy caching before we do anything else!
loopy.CACHING_ENABLED = False loopy.CACHING_ENABLED = False
def read_ufl(uflfile): def read_ufl(uflfile):
from ufl.algorithms.formfiles import read_ufl_file, interpret_ufl_namespace """Read uflfile file, extract and preprocess forms
from ufl.algorithms import compute_form_data
Arguments:
----------
uflfile: Path to ufl file.
Returns:
--------
formdatas: List of formdatas found in uflfile.
forms: List of forms found in uflfile.
"""
# Read the given ufl file and execute it # Read the given ufl file and execute it
uflcode = read_ufl_file(uflfile) uflcode = read_ufl_file(uflfile)
namespace = globals() namespace = globals()
try: try:
exec("from dune.perftool.ufl.execution import *\n" + uflcode, namespace) exec("from dune.perftool.ufl.execution import *\n" + uflcode, namespace)
except: except:
import os
basename = os.path.splitext(os.path.basename(uflfile))[0] basename = os.path.splitext(os.path.basename(uflfile))[0]
basename = "{}_debug".format(basename) basename = "{}_debug".format(basename)
pyname = "{}.py".format(basename) pyname = "{}.py".format(basename)
...@@ -31,12 +53,11 @@ def read_ufl(uflfile): ...@@ -31,12 +53,11 @@ def read_ufl(uflfile):
f.write(pycode) f.write(pycode)
raise SyntaxError("Not a valid ufl file, dumped a debug script: {}".format(pyname)) raise SyntaxError("Not a valid ufl file, dumped a debug script: {}".format(pyname))
# Extract the form from the given data # Extract and preprocess the forms
data = interpret_ufl_namespace(namespace) data = interpret_ufl_namespace(namespace)
formdatas = [] formdatas = []
forms = data.forms forms = data.forms
for index, form in enumerate(forms): for index, form in enumerate(forms):
from dune.perftool.ufl.preprocess import preprocess_form
formdatas.append(preprocess_form(form)) formdatas.append(preprocess_form(form))
forms[index] = formdatas[index].preprocessed_form forms[index] = formdatas[index].preprocessed_form
...@@ -48,40 +69,32 @@ def read_ufl(uflfile): ...@@ -48,40 +69,32 @@ def read_ufl(uflfile):
# This function is the entrypoint of the ufl2pdelab executable # This function is the entrypoint of the ufl2pdelab executable
def compile_form(): def compile_form():
from dune.perftool.options import get_option
formdatas, data = read_ufl(get_option("uflfile")) formdatas, data = read_ufl(get_option("uflfile"))
from dune.perftool.generation import global_context
with global_context(data=data, formdatas=formdatas): with global_context(data=data, formdatas=formdatas):
# Generate driver file # Generate driver file
if get_option("driver_file"): if get_option("driver_file"):
from dune.perftool.pdelab.driver import generate_driver
generate_driver(formdatas, data) generate_driver(formdatas, data)
# In case of multiple forms: Genarate one file that includes all localoperator files # In case of multiple forms: Genarate one file that includes all localoperator files
if len(formdatas) > 1: if len(formdatas) > 1:
from dune.perftool.pdelab.localoperator import generate_localoperator_basefile
generate_localoperator_basefile(formdatas, data) generate_localoperator_basefile(formdatas, data)
# Generate local operator files # Generate local operator files
for formdata in formdatas: for formdata in formdatas:
with global_context(data=data, formdata=formdata): with global_context(data=data, formdata=formdata):
# Make sure cache is empty # Make sure cache is empty
from dune.perftool.generation import delete_cache_items
delete_cache_items() delete_cache_items()
# Create localoperator kernels
if get_option("operator_file"): if get_option("operator_file"):
from dune.perftool.pdelab.localoperator import generate_localoperator_kernels
kernels = generate_localoperator_kernels(formdata, data) kernels = generate_localoperator_kernels(formdata, data)
# TODO insert sophisticated analysis/feedback loops here # TODO insert sophisticated analysis/feedback loops here
if get_option("interactive"): if get_option("interactive"):
from dune.perftool.interactive import start_interactive_session
start_interactive_session(kernels) start_interactive_session(kernels)
# Create c++ file from kernels
if get_option("operator_file"): if get_option("operator_file"):
from dune.perftool.pdelab.localoperator import name_localoperator_file
filename = name_localoperator_file(formdata, data) filename = name_localoperator_file(formdata, data)
from dune.perftool.pdelab.localoperator import generate_localoperator_file
generate_localoperator_file(formdata, kernels, filename) generate_localoperator_file(formdata, kernels, filename)
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