| 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 dune.generator.generator import SimpleGenerator |
| 5 |
from dune.common.hashit import hashIt |
| 6 |
|
| 7 |
|
| 8 |
# A subspace basis for some descendent node, can be obtained |
| 9 |
# by passing the indices of the corresponding tree path |
| 10 |
# as individual arguments. Passing a tree path at once is |
| 11 |
# currently not supported. |
| 12 |
# |
| 13 |
# Netsed calls to subspaceBasis(subspaceBasis(basis, i), j) |
| 14 |
# will create a nested subspace basis. This works fine, but |
| 15 |
# is slightly inconsistent with C++ where this is automatically |
| 16 |
# resolved to subspaceBasis(basis, i, j). |
| 17 |
def subspaceBasis(basis, *args): |
| 18 |
includes = [] |
| 19 |
includes += list(basis.cppIncludes) |
| 20 |
includes += ["dune/functions/functionspacebases/subspacebasis.hh"] |
| 21 |
includes += ["dune/python/functions/subspacebasis.hh"] |
| 22 |
|
| 23 |
# In contrast to C++, the generated wrapper of SubspaceBasis |
| 24 |
# is only constructed from the root basis and no tree path |
| 25 |
# is passed. This is possible, because we only use fully |
| 26 |
# static tree path types that can be default constructed. |
| 27 |
prefixPathTypeName = "Dune::TypeTree::TreePath<" |
| 28 |
prefixPathTypeName += ",".join("Dune::index_constant<"+str(i)+">" for i in args) |
| 29 |
prefixPathTypeName += ">" |
| 30 |
|
| 31 |
typeName = "Dune::Functions::SubspaceBasis< " + basis.cppTypeName+ "," + prefixPathTypeName + " >" |
| 32 |
|
| 33 |
generator = SimpleGenerator("SubspaceBasis", "Dune::Python") |
| 34 |
|
| 35 |
moduleName = "subspaceBasis_" + hashIt(typeName) |
| 36 |
module = generator.load(includes, typeName, moduleName) |
| 37 |
return module.SubspaceBasis(basis) |