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

[!267] Geometry objects in Lambdas

Merge branch 'feature/lambda-generation-with-more-geometry' into 'master'

Target: normal-dependent constraints assembly.

See merge request [dominic/dune-perftool!267]

  [dominic/dune-perftool!267]: gitlab.dune-project.org/dominic/dune-perftool/merge_requests/267
parents dfdbf11b 1a78e5aa
No related branches found
No related tags found
No related merge requests found
from dune.perftool.generation import (global_context, from dune.perftool.generation import (get_counted_variable,
global_context,
include_file, include_file,
preamble, preamble,
) )
...@@ -52,12 +53,10 @@ def assemble_constraints(name): ...@@ -52,12 +53,10 @@ def assemble_constraints(name):
def name_bctype_function(element, is_dirichlet): def name_bctype_function(element, is_dirichlet):
if isinstance(element, (VectorElement, TensorElement)): # Note: Previously, there was a separate code branch for VectorElement here,
subel = element.sub_elements()[0] # which was implemented through PDELabs Power constraints concept.
child = name_bctype_function(subel, is_dirichlet[:subel.value_size()]) # However this completely fails if you have different constraints for
name = "{}_pow{}bctype".format(child, element.num_sub_elements()) # the children of a VectorElement. We therefore omit this branch completely.
define_power_bctype_function(element, name, child)
return name
if isinstance(element, MixedElement): if isinstance(element, MixedElement):
k = 0 k = 0
childs = [] childs = []
...@@ -69,7 +68,7 @@ def name_bctype_function(element, is_dirichlet): ...@@ -69,7 +68,7 @@ def name_bctype_function(element, is_dirichlet):
return name return name
else: else:
assert isinstance(element, (FiniteElement, TensorProductElement)) assert isinstance(element, (FiniteElement, TensorProductElement))
name = "{}_bctype".format(FEM_name_mangling(element).lower()) name = get_counted_variable("bctype")
define_bctype_function(element, is_dirichlet[0], name) define_bctype_function(element, is_dirichlet[0], name)
return name return name
...@@ -85,12 +84,6 @@ def define_bctype_function(element, is_dirichlet, name): ...@@ -85,12 +84,6 @@ def define_bctype_function(element, is_dirichlet, name):
) )
@preamble(section="constraints")
def define_power_bctype_function(element, name, subgfs):
include_file('dune/pdelab/constraints/common/constraintsparameters.hh', filetag='driver')
return "Dune::PDELab::PowerConstraintsParameters<decltype({}), {}> {}({});".format(subgfs, element.num_sub_elements(), name, subgfs)
@preamble(section="constraints") @preamble(section="constraints")
def define_composite_bctype_function(element, is_dirichlet, name, subgfs): def define_composite_bctype_function(element, is_dirichlet, name, subgfs):
include_file('dune/pdelab/constraints/common/constraintsparameters.hh', filetag='driver') include_file('dune/pdelab/constraints/common/constraintsparameters.hh', filetag='driver')
...@@ -115,7 +108,7 @@ def define_intersection_lambda(name, func): ...@@ -115,7 +108,7 @@ def define_intersection_lambda(name, func):
return "auto {} = [&](const auto& x){{ return {}; }};".format(name, float(func)) return "auto {} = [&](const auto& x){{ return {}; }};".format(name, float(func))
elif isinstance(func, Expr): elif isinstance(func, Expr):
from dune.perftool.pdelab.driver.visitor import ufl_to_code from dune.perftool.pdelab.driver.visitor import ufl_to_code
return "auto {} = [&](const auto& x){{ return {}; }};".format(name, ufl_to_code(func)) return "auto {} = [&](const auto& is, const auto& xl){{ {} }};".format(name, ufl_to_code(func))
raise ValueError("Expression not understood") raise ValueError("Expression not understood")
......
...@@ -95,10 +95,7 @@ def define_boundary_lambda(name, boundary): ...@@ -95,10 +95,7 @@ def define_boundary_lambda(name, boundary):
if isinstance(boundary, (int, float)): if isinstance(boundary, (int, float)):
return "auto {} = [&](const auto& x){{ return {}; }};".format(name, float(boundary)) return "auto {} = [&](const auto& x){{ return {}; }};".format(name, float(boundary))
elif isinstance(boundary, Expr): elif isinstance(boundary, Expr):
from dune.perftool.loopy.target import type_floatingpoint
from dune.perftool.pdelab.driver.visitor import ufl_to_code from dune.perftool.pdelab.driver.visitor import ufl_to_code
return "auto {} = [&](const auto& x){{ return ({}){}; }};".format(name, return "auto {} = [&](const auto& is, const auto& xl){{ {}; }};".format(name, ufl_to_code(boundary))
type_floatingpoint(),
ufl_to_code(boundary))
else: else:
raise NotImplementedError("What is this?") raise NotImplementedError("What is this?")
...@@ -4,11 +4,6 @@ from dune.perftool.ufl.visitor import UFL2LoopyVisitor ...@@ -4,11 +4,6 @@ from dune.perftool.ufl.visitor import UFL2LoopyVisitor
import pymbolic.primitives as prim import pymbolic.primitives as prim
@preamble(section="init")
def driver_using_statement(what):
return "using {};".format(what)
@preamble(section="gridoperator") @preamble(section="gridoperator")
def set_lop_to_starting_time(): def set_lop_to_starting_time():
from dune.perftool.pdelab.driver import get_form_ident from dune.perftool.pdelab.driver import get_form_ident
...@@ -23,17 +18,24 @@ class DriverUFL2PymbolicVisitor(UFL2LoopyVisitor): ...@@ -23,17 +18,24 @@ class DriverUFL2PymbolicVisitor(UFL2LoopyVisitor):
UFL2LoopyVisitor.__init__(self, PDELabInterface(), "exterior_facet", {}) UFL2LoopyVisitor.__init__(self, PDELabInterface(), "exterior_facet", {})
def __call__(self, expr): def __call__(self, expr):
return self._call(expr, False) self.preambles = []
ret = self._call(expr, False)
return set(self.preambles), ret
def facet_normal(self, o):
self.preambles.append("auto n=is.unitOuterNormal(xl);")
return prim.Variable("n")
def spatial_coordinate(self, o): def spatial_coordinate(self, o):
self.preambles.append("auto x=is.geometry().global(xl);")
return prim.Variable("x") return prim.Variable("x")
def max_value(self, o): def max_value(self, o):
driver_using_statement("std::max") self.preambles.append("using std::max;")
return UFL2LoopyVisitor.max_value(self, o) return UFL2LoopyVisitor.max_value(self, o)
def min_value(self, o): def min_value(self, o):
driver_using_statement("std::min") self.preambles.append("using std::min;")
return UFL2LoopyVisitor.min_value(self, o) return UFL2LoopyVisitor.min_value(self, o)
def coefficient(self, o): def coefficient(self, o):
...@@ -55,5 +57,5 @@ def ufl_to_code(expr, boundary=True): ...@@ -55,5 +57,5 @@ def ufl_to_code(expr, boundary=True):
visitor = DriverUFL2PymbolicVisitor() visitor = DriverUFL2PymbolicVisitor()
from pymbolic.mapper.c_code import CCodeMapper from pymbolic.mapper.c_code import CCodeMapper
ccm = CCodeMapper() ccm = CCodeMapper()
vis = visitor(expr) preambles, vis_expr = visitor(expr)
return ccm(vis) return "{} return {};".format("".join(preambles), ccm(vis_expr))
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