From ca17591ee782e4a2a748cdb1ce4bc609d977295a Mon Sep 17 00:00:00 2001 From: Matthew Collins <m.t.collins@warwick.ac.uk> Date: Sun, 26 Nov 2017 13:07:46 +0000 Subject: [PATCH] sunday push --- __init__.py | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/__init__.py b/__init__.py index 305561791..bbe9ce5cc 100644 --- a/__init__.py +++ b/__init__.py @@ -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 -- GitLab