Beispiel #1
0
    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
Beispiel #2
0
    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_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)
    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)