예제 #1
0
def computeKmsij(TInd, a, IPatch):
    patch = lod_periodic.PatchPeriodic(world, k, TInd)
    aPatch = lod_periodic.localizeCoefficient(patch, a, periodic=True)

    correctorsList = lod.computeBasisCorrectors(patch, IPatch, aPatch)
    csi = lod.computeBasisCoarseQuantities(patch, correctorsList, aPatch)
    return patch, correctorsList, csi.Kmsij, csi
예제 #2
0
def computeKmsij(TInd):
    patch = Patch(world, k, TInd)
    IPatch = lambda: interp.L2ProjectionPatchMatrix(patch, boundaryConditions)
    aPatch = lambda: coef.localizeCoefficient(patch, aFine_ref)

    correctorsList = lod.computeBasisCorrectors(patch, IPatch, aPatch)
    csi = lod.computeBasisCoarseQuantities(patch, correctorsList, aPatch)
    return patch, correctorsList, csi.Kmsij, csi
예제 #3
0
def real_computeKmsij(TInd):
    print('.', end='', flush=True)
    patch = Patch(world, k, TInd)
    IPatch = lambda: interp.L2ProjectionPatchMatrix(patch, boundaryConditions)
    aPatch = lambda: coef.localizeCoefficient(patch, a_Fine_to_be_approximated)

    correctorsList = lod.computeBasisCorrectors(patch, IPatch, aPatch)
    csi = lod.computeBasisCoarseQuantities(patch, correctorsList, aPatch)
    return patch, correctorsList, csi.Kmsij, csi
예제 #4
0
    def UpdateCorrectors(TInd):
        rPatch = lambda: lod_periodic.localizeCoefficient(
            patchT[TInd], aPert, periodic=True)

        correctorsList = lod.computeBasisCorrectors(patchT[TInd], IPatch,
                                                    rPatch)
        csi = lod.computeBasisCoarseQuantities(patchT[TInd], correctorsList,
                                               rPatch)

        return patchT[TInd], correctorsList, csi.Kmsij
예제 #5
0
    def computeKmsij(TInd, aPatch, k, boundaryConditions):
        tic = time.perf_counter()
        patch = lod_periodic.PatchPeriodic(world, k, TInd)
        if dim == 1:
            IPatch = lambda: interp.nodalPatchMatrix(patch)
        else:
            IPatch = lambda: interp.L2ProjectionPatchMatrix(
                patch, boundaryConditions)

        correctorsList = lod.computeBasisCorrectors(patch, IPatch, aPatch)
        csi = lod.computeBasisCoarseQuantities(patch, correctorsList, aPatch)
        toc = time.perf_counter()
        return patch, correctorsList, csi.Kmsij, csi.muTPrime, toc - tic
예제 #6
0
    def test_testCsi_Kmsij(self):
        NWorldCoarse = np.array([4, 5, 6])
        NCoarseElement = np.array([5, 2, 3])
        world = World(NWorldCoarse, NCoarseElement)
        d = np.size(NWorldCoarse)
        
        k = 1
        iElementWorldCoarse = np.array([2, 1, 2])
        TInd = util.convertpCoordIndexToLinearIndex(NWorldCoarse, iElementWorldCoarse)
        patch = Patch(world, k, TInd)
        
        IPatch = interp.L2ProjectionPatchMatrix(patch)
        
        NtPatch = patch.NtFine
        np.random.seed(1)
        aPatch = np.random.rand(NtPatch)
        basisCorrectorsList = lod.computeBasisCorrectors(patch, IPatch, aPatch)
        csi = lod.computeBasisCoarseQuantities(patch, basisCorrectorsList, aPatch)

        TFinetIndexMap   = util.extractElementFine(patch.NPatchCoarse,
                                                   NCoarseElement,
                                                   patch.iElementPatchCoarse,
                                                   extractElements=True)
        TFinepIndexMap   = util.extractElementFine(patch.NPatchCoarse,
                                                   NCoarseElement,
                                                   patch.iElementPatchCoarse,
                                                   extractElements=False)
        TCoarsepIndexMap   = util.extractElementFine(patch.NPatchCoarse,
                                                     np.ones_like(NCoarseElement),
                                                     patch.iElementPatchCoarse,
                                                     extractElements=False)

        APatchFine      = fem.assemblePatchMatrix(patch.NPatchFine, world.ALocFine, aPatch)
        AElementFine    = fem.assemblePatchMatrix(NCoarseElement, world.ALocFine, aPatch[TFinetIndexMap])
        basisPatch      = fem.assembleProlongationMatrix(patch.NPatchCoarse, NCoarseElement)
        correctorsPatch = np.column_stack(basisCorrectorsList)

        localBasis = world.localBasis

        KmsijShouldBe = -basisPatch.T*(APatchFine*(correctorsPatch))
        KmsijShouldBe[TCoarsepIndexMap,:] += np.dot(localBasis.T, AElementFine*localBasis)
        
        self.assertTrue(np.isclose(np.max(np.abs(csi.Kmsij-KmsijShouldBe)), 0))
    def UpdateCorrectors(self, TInd):
        # print(" UPDATING {}".format(TInd))
        patch = Patch(self.world, self.k, TInd)
        IPatch = lambda: interp.L2ProjectionPatchMatrix(
            patch, self.boundaryConditions)
        rPatch = lambda: coef.localizeCoefficient(
            patch, self.a_Fine_to_be_approximated)

        MRhsList = [
            self.f_trans[util.extractElementFine(self.world.NWorldCoarse,
                                                 self.world.NCoarseElement,
                                                 patch.iElementWorldCoarse,
                                                 extractElements=False)]
        ]

        correctorsList = lod.computeBasisCorrectors(patch, IPatch, rPatch)
        csi = lod.computeBasisCoarseQuantities(patch, correctorsList, rPatch)

        correctorRhs = lod.computeElementCorrector(patch, IPatch, rPatch, None,
                                                   MRhsList)[0]
        Rmsij = lod.computeRhsCoarseQuantities(patch, correctorRhs, rPatch)

        return patch, correctorsList, csi.Kmsij, Rmsij, correctorRhs
예제 #8
0
    def test_computeSingleT(self):
        NWorldCoarse = np.array([4, 5, 6])
        NCoarseElement = np.array([5, 2, 3])
        world = World(NWorldCoarse, NCoarseElement)
        d = np.size(NWorldCoarse)
        
        k = 1
        iElementWorldCoarse = np.array([2, 1, 2])
        TInd = util.convertpCoordIndexToLinearIndex(NWorldCoarse, iElementWorldCoarse)
        patch = Patch(world, k, TInd)

        IPatch = interp.L2ProjectionPatchMatrix(patch)
        
        NtPatch = patch.NtFine

        aPatch = np.ones(NtPatch)
        basisCorrectorsList = lod.computeBasisCorrectors(patch, IPatch, aPatch)

        correctorSum = reduce(np.add, basisCorrectorsList)
        self.assertTrue(np.allclose(correctorSum, 0))

        csi = lod.computeBasisCoarseQuantities(patch, basisCorrectorsList, aPatch)
        # Test that the matrices have the constants in their null space
        #self.assertTrue(np.allclose(np.sum(ec.csi.LTPrimeij, axis=1), 0))
        #self.assertTrue(np.allclose(np.sum(ec.csi.LTPrimeij, axis=2), 0))

        self.assertTrue(np.allclose(np.sum(csi.Kij, axis=0), 0))
        self.assertTrue(np.allclose(np.sum(csi.Kij, axis=1), 0))
        self.assertTrue(np.allclose(np.sum(csi.Kmsij, axis=0), 0))
        self.assertTrue(np.allclose(np.sum(csi.Kmsij, axis=1), 0))

        # I had difficulties come up with test cases here. This test
        # verifies that most "energy" is in the element T.
        elementTIndex = util.convertpCoordIndexToLinearIndex(patch.NPatchCoarse-1, patch.iElementPatchCoarse)
        self.assertTrue(np.all(csi.muTPrime[elementTIndex] >= csi.muTPrime))
        self.assertTrue(not np.all(csi.muTPrime[elementTIndex+1] >= csi.muTPrime))