| 1 |
# SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file AUTHORS.md |
| 2 |
# SPDX-License-Identifier: LicenseRef-GPL-2.0-only-with-DUNE-exception OR LGPL-3.0-or-later |
| 3 |
|
| 4 |
from .tree import Composite, DG, Lagrange, Nedelec, Power, RaviartThomas, Tree |
| 5 |
|
| 6 |
duneFunctionsLayouts = {"lexicographic": "Lexicographic", "interleaved": "Interleaved"} |
| 7 |
|
| 8 |
def indexMergingStrategy(blocked, layout): |
| 9 |
return "Dune::Functions::BasisFactory::" + ("Blocked" if blocked else "Flat") + duneFunctionsLayouts[layout] |
| 10 |
|
| 11 |
|
| 12 |
def preBasisTypeName(tree, gridViewTypeName): |
| 13 |
assert isinstance(tree, Tree) |
| 14 |
if isinstance(tree, Lagrange): |
| 15 |
return "Dune::Functions::LagrangePreBasis< " + gridViewTypeName + " , " + str(tree.order) + " >" |
| 16 |
elif isinstance(tree, DG): |
| 17 |
raise Exception(repr(tree) + " not supported by dune-functions.") |
| 18 |
elif isinstance(tree, Nedelec): |
| 19 |
return "Dune::Functions::NedelecPreBasis< " + gridViewTypeName + ", double, " + str(tree.kind) + ", " + str(tree.order) + " >" |
| 20 |
elif isinstance(tree, RaviartThomas): |
| 21 |
return "Dune::Functions::RaviartThomasPreBasis< " + gridViewTypeName + ", " + str(tree.order) + " >" |
| 22 |
elif isinstance(tree, Composite): |
| 23 |
IMS = indexMergingStrategy(tree.blocked, tree.layout) |
| 24 |
ChildPreBases = " , ".join(preBasisTypeName(c, gridViewTypeName) for c in tree.children) |
| 25 |
return "Dune::Functions::CompositePreBasis< " + IMS + " , " + ChildPreBases + " >" |
| 26 |
elif isinstance(tree, Power): |
| 27 |
IMS = indexMergingStrategy(tree.blocked, tree.layout) |
| 28 |
ChildPreBasis = preBasisTypeName(tree.children[0], gridViewTypeName) |
| 29 |
return "Dune::Functions::PowerPreBasis< " + IMS + " , " + ChildPreBasis + " , " + str(tree.exponent) + " >" |
| 30 |
else: |
| 31 |
raise Exception("Unknown type of tree: " + repr(tree)) |
| 32 |
|
| 33 |
|
| 34 |
def defaultGlobalBasis(gridView, tree): |
| 35 |
from dune.functions import load |
| 36 |
|
| 37 |
headers = ["powerbasis", "compositebasis", "lagrangebasis", "nedelecbasis", "raviartthomasbasis", "subspacebasis", "defaultglobalbasis"] |
| 38 |
|
| 39 |
includes = [] |
| 40 |
includes += list(gridView.cppIncludes) |
| 41 |
includes += ["dune/functions/functionspacebases/" + h + ".hh" for h in headers] |
| 42 |
|
| 43 |
typeName = "Dune::Functions::DefaultGlobalBasis< " + preBasisTypeName(tree, gridView.cppTypeName) + " >" |
| 44 |
|
| 45 |
return load(includes, typeName).GlobalBasis(gridView) |