Skip to content
Snippets Groups Projects
Commit ca17591e authored by Matthew Collins's avatar Matthew Collins
Browse files

sunday push

parent caef6f0b
No related branches found
No related tags found
1 merge request!369Feature/add python bindings
......@@ -8,6 +8,7 @@ from dune.generator.generator import SimpleGenerator
from dune.common.hashit import hashIt
generator = SimpleGenerator("BCRSMatrix","Dune::Python")
generatorvec = SimpleGenerator("BlockVector","Dune::Python")
generatormatrixindexset = SimpleGenerator("MatrixIndexSet","Dune::Python")
def load(includes ,typeName ,constructors=None, methods=None):
......@@ -25,18 +26,36 @@ def loadvec(includes ,typeName ,constructors=None, methods=None):
typeHash = "istlbvector_" + hashIt(typeName)
return generatorvec.load(includes ,typeName ,typeHash ,constructors ,methods)
def loadmatrixindexset(includes ,typeName ,constructors=None, methods=None):
includes = includes + ["dune/python/istl/matrixindexset.hh"]
#this contains the registration functions for the class
typeHash = "matrixindexset_" + hashIt(typeName)
return generatormatrixindexset.load(includes ,typeName ,typeHash ,constructors ,methods)
def MatrixIndexSet(rows, cols):
includes = ["dune/istl/matrixindexset.hh"]
typeName = "Dune::MatrixIndexSet"
return loadmatrixindexset(includes, typeName).MatrixIndexSet(rows,cols)
def BCRSMatrix(blockSize):
if blockSize[0] == blockSize[1] == 1:
print("returning singular object")
return BCRSMatrix11
typeName = "Dune::BCRSMatrix< Dune::FieldMatrix< double,"\
+ str(blockSize[0]) + "," + str(blockSize[1]) \
+ " > >"
includes = ["dune/istl/bcrsmatrix.hh"]
print("returning bigger object")
# todo: provide other constructors
return load(includes, typeName).BCRSMatrix
#if a fieldmatrix has been passed instead of blocksize use as template parameter
# if blockSize._typeName[0]=="F":
try:
typeName = "Dune::BCRSMatrix<Dune::" + blockSize._typeName + " >"
print("typename is fieldmatrix")
return load(includes,typeName).BCRSMatrix(blockSize)
except AttributeError:
#check whether blocksize is 1,1
if blockSize[0] == blockSize[1] == 1:
return BCRSMatrix11
typeName = "Dune::BCRSMatrix< Dune::FieldMatrix< double,"\
+ str(blockSize[0]) + "," + str(blockSize[1]) \
+ " > >"
# todo: provide other constructors
return load(includes, typeName).BCRSMatrix
def BlockVector(blockSize):
......@@ -45,6 +64,5 @@ def BlockVector(blockSize):
typeName = "Dune::BlockVector< Dune::FieldVector< double," + str(blockSize) + " > >"
includes = ["dune/istl/bvector.hh"]
includes = includes + ["dune/common/fmatrix.hh"]
print("bindings for bigger than 1 blocksize")
# todo: provide other constructors
return loadvec(includes, typeName).BlockVector
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