def naive_calc(self): result = {} for j in xrange(self.gridSize): HashGridIndex = self.storage.get(j) HashGridIndex.setLeaf(False) print "Point: ", j, " (", HashGridIndex.toString(), ")" for d in xrange(self.dim): print "Dimension: ", d # # Get left and right child # leftChild = HashGridIndex(HashGridIndex) rightChild = HashGridIndex(HashGridIndex) self.storage.left_child(leftChild, d) self.storage.right_child(rightChild, d) # # Check if point is refinable # if self.storage.has_key(leftChild) or self.storage.has_key( rightChild): continue # # Insert children temporarily # self.storage.insert(leftChild) self.storage.insert(rightChild) val1 = self.naive_calc_single(leftChild) print "Left Child: ", val1 val2 = self.naive_calc_single(rightChild) print "Right Child: ", val2 self.storage.deleteLast() self.storage.deleteLast() result[(j, d)] = val1 + val2 print "" return result
def naive_calc(self): result = {} for j in xrange(self.gridSize): HashGridIndex = self.storage.get(j) HashGridIndex.setLeaf(False) print "Point: ", j, " (", HashGridIndex.toString(), ")" for d in xrange(self.dim): print "Dimension: ", d # # Get left and right child # leftChild = HashGridIndex(HashGridIndex) rightChild = HashGridIndex(HashGridIndex) self.storage.left_child(leftChild, d) self.storage.right_child(rightChild, d) # # Check if point is refinable # if self.storage.has_key(leftChild) or self.storage.has_key(rightChild): continue # # Insert children temporarily # self.storage.insert(leftChild) self.storage.insert(rightChild) val1 = self.naive_calc_single(leftChild) print "Left Child: ", val1 val2 = self.naive_calc_single(rightChild) print "Right Child: ", val2 self.storage.deleteLast() self.storage.deleteLast() result[(j, d)] = val1 + val2 print "" return result
def test_freeRefineSubspaceIsotropic(self): """Refine the isotropic middle subspace""" alpha = DataVector(self.grid.getSize()) alpha.setAll(1.0) alpha[12] = 2. #refinement stuff refinement = HashRefinement() decorator = GSGRefinement(refinement) # refine a single grid point each time functor = SurplusRefinementFunctor(alpha,1) decorator.freeRefineSubspace(self.HashGridStorage,functor) for i in xrange(self.grid.getSize()): HashGridIndex = self.HashGridStorage.get(i) print i, HashGridIndex.toString() self.assertEqual(self.grid.getSize(), 15) for i in xrange(self.grid.getSize()): HashGridIndex = self.HashGridStorage.get(i) levelIndex = eval(HashGridIndex.toString()) self.assertFalse(levelIndex[0] == 4 or levelIndex[2] >= 3)
def test_freeRefineSubspaceIsotropic(self): """Refine the isotropic middle subspace""" alpha = DataVector(self.grid.getSize()) alpha.setAll(1.0) alpha[12] = 2. #refinement stuff refinement = HashRefinement() decorator = GSGRefinement(refinement) # refine a single grid point each time functor = SurplusRefinementFunctor(alpha, 1) decorator.freeRefineSubspace(self.HashGridStorage, functor) for i in xrange(self.grid.getSize()): HashGridIndex = self.HashGridStorage.get(i) print i, HashGridIndex.toString() self.assertEqual(self.grid.getSize(), 15) for i in xrange(self.grid.getSize()): HashGridIndex = self.HashGridStorage.get(i) levelIndex = eval(HashGridIndex.toString()) self.assertFalse(levelIndex[0] == 4 or levelIndex[2] >= 3)
def test_freeRefineSubspaceAnisotropic(self): """Refine Anisotropic subspace (x2)""" alpha = DataVector(self.grid.getSize()) alpha.setAll(1.0) for i in [9, 10, 11, 12]: alpha[i] = 2. #refinement stuff refinement = HashRefinement() decorator = SubspaceRefinement(refinement) # refine a single grid point each time functor = SurplusRefinementFunctor(alpha,1) decorator.free_refine(self.HashGridStorage,functor) for i in xrange(self.grid.getSize()): HashGridIndex = self.HashGridStorage.get(i) print i, HashGridIndex.toString() self.assertEqual(self.grid.getSize(), 33) for i in xrange(self.grid.getSize()): HashGridIndex = self.HashGridStorage.get(i) levelIndex = eval(HashGridIndex.toString()) self.assertFalse(levelIndex[0] == 4)
def test_freeRefineSubspaceAnisotropic(self): """Refine Anisotropic subspace (x2)""" alpha = DataVector(self.grid.getSize()) alpha.setAll(1.0) for i in [9, 10, 11, 12]: alpha[i] = 2. #refinement stuff refinement = HashRefinement() decorator = SubspaceRefinement(refinement) # refine a single grid point each time functor = SurplusRefinementFunctor(alpha, 1) decorator.free_refine(self.HashGridStorage, functor) for i in xrange(self.grid.getSize()): HashGridIndex = self.HashGridStorage.get(i) print i, HashGridIndex.toString() self.assertEqual(self.grid.getSize(), 33) for i in xrange(self.grid.getSize()): HashGridIndex = self.HashGridStorage.get(i) levelIndex = eval(HashGridIndex.toString()) self.assertFalse(levelIndex[0] == 4)
def test_1(self): storage = self.grid.getStorage() gridSize = self.grid.getSize() numDim = storage.dim() print "######" print "Expected result:" print "######" expected = {} for j in xrange(gridSize): HashGridIndex = storage.get(j) HashGridIndex.setLeaf(False) print "Point: ", j, " (", HashGridIndex.toString(), ")" for d in xrange(numDim): # # Get left and right child # leftChild = HashGridIndex(HashGridIndex) rightChild = HashGridIndex(HashGridIndex) storage.left_child(leftChild, d) storage.right_child(rightChild, d) # # Check if point is refinable # if storage.has_key(leftChild) or storage.has_key(rightChild): continue # # Insert children temporarily # storage.insert(leftChild) storage.insert(rightChild) val1 = self.calc_indicator_value(leftChild) val2 = self.calc_indicator_value(rightChild) storage.deleteLast() storage.deleteLast() print "Dimension: ", d print "Left Child: ", val1 print "Right Child: ", val2 print "" expected[(j, d)] = val1 + val2 print "" for k, v in expected.iteritems(): print(k, v) print "######" print "Actual result:" print "######" actual = refinement_map({}) self.strategy.collectRefinablePoints(storage, 10, actual) for k, v in actual.iteritems(): print(k, v) # # Assertions # for k, v in expected.iteritems(): self.assertEqual(actual[k], v)