Example #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
Example #2
0
    def computeIndicator(TInd):
        aPatch = lambda: lod_periodic.localizeCoefficient(
            patchT[TInd], aPert, periodic=True)  # true coefficient
        E_vh = lod.computeErrorIndicatorCoarseFromCoefficients(
            patchT[TInd], muTPrimeRef, aRef, aPatch)

        return E_vh
Example #3
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
Example #4
0
    def compute_errorHarmT(TInd):
        rPatch = lambda: lod_periodic.localizeCoefficient(
            patchT[TInd], aPert, periodic=True)

        alphaT = np.zeros(len(aHarmList))
        NFineperEpsilon = world.NWorldFine // Nepsilon
        alphaT[:len(alphaT) - 1] = (rPatch()[np.arange(len(aHarmList) - 1) *
                                             np.prod(NFineperEpsilon)] -
                                    alpha) / (beta - alpha)
        alphaT[len(alphaT) - 1] = 1. - np.sum(alphaT[:len(alphaT) - 1])

        aharmT_combined = np.dot(alphaT, aHarmList)
        aharmT = computeAharm(TInd, aPert)

        return np.abs(aharmT - aharmT_combined)
Example #5
0
def computeAharm(TInd, a):
    assert (dim == 1)
    patch = lod_periodic.PatchPeriodic(world, 0, TInd)
    aPatch = lod_periodic.localizeCoefficient(patch, a, periodic=True)
    aPatchHarm = np.sum(1. / aPatch)
    return world.NWorldFine / (world.NWorldCoarse * aPatchHarm)
Example #6
0
    def compute_combinedT(TInd):
        rPatch = lambda: lod_periodic.localizeCoefficient(
            patchT[TInd], aPert, periodic=True)

        #direct determination of alpha without optimization
        assert (model['name'] in [
            'check', 'incl', 'inclvalue', 'inclfill', 'inclshift', 'inclLshape'
        ])

        if model['name'] == 'check':
            alphaT = np.zeros(len(aRefList))
            alpha = model['alpha']
            beta = model['beta']
            NFineperEpsilon = world.NWorldFine // Nepsilon
            NEpsilonperPatchCoarse = patchT[TInd].NPatchCoarse * (
                Nepsilon // world.NWorldCoarse)
            if dim == 2:
                tmp_indx = np.array([
                    np.arange(len(aRefList) - 1) // NEpsilonperPatchCoarse[0],
                    np.arange(len(aRefList) - 1) % NEpsilonperPatchCoarse[0]
                ])
                indx = tmp_indx[0] * NFineperEpsilon[1] * patchT[
                    TInd].NPatchFine[0] + tmp_indx[1] * NFineperEpsilon[0]
                alphaT[:len(alphaT) -
                       1] = (rPatch()[indx] - alpha) / (beta - alpha)
            elif dim == 1:
                alphaT[:len(alphaT) -
                       1] = (rPatch()[np.arange(len(aRefList) - 1) *
                                      np.prod(NFineperEpsilon)] -
                             alpha) / (beta - alpha)
            alphaT[len(alphaT) - 1] = 1. - np.sum(alphaT[:len(alphaT) - 1])
        elif model['name'] == 'incl':
            alphaT = np.zeros(len(aRefList))
            bgval = model['bgval']
            inclval = model['inclval']
            blx = model['left'][0]
            bly = model['left'][1]
            NFineperEpsilon = world.NWorldFine // Nepsilon
            NEpsilonperPatchCoarse = patchT[TInd].NPatchCoarse * (
                Nepsilon // world.NWorldCoarse)
            tmp_indx = np.array([
                np.arange(len(aRefList) - 1) // NEpsilonperPatchCoarse[0] +
                blx,
                np.arange(len(aRefList) - 1) % NEpsilonperPatchCoarse[0] + bly
            ])
            indx = (tmp_indx[0] * NFineperEpsilon[1] * patchT[TInd].NPatchFine[0]).astype(int) \
                    + (tmp_indx[1] * NFineperEpsilon[0]).astype(int)
            alphaT[:len(alphaT) -
                   1] = (inclval - rPatch()[indx]) / (inclval - bgval)
            alphaT[len(alphaT) - 1] = 1. - np.sum(alphaT[:len(alphaT) - 1])
        elif model['name'] == 'inclvalue':
            alphaT = np.zeros(len(aRefList))
            defval = model['defval']
            inclval = model['inclval']
            blx = model['left'][0]
            bly = model['left'][1]
            NFineperEpsilon = world.NWorldFine // Nepsilon
            NEpsilonperPatchCoarse = patchT[TInd].NPatchCoarse * (
                Nepsilon // world.NWorldCoarse)
            tmp_indx = np.array([
                np.arange(len(aRefList) - 1) // NEpsilonperPatchCoarse[0] +
                blx,
                np.arange(len(aRefList) - 1) % NEpsilonperPatchCoarse[0] + bly
            ])
            indx = (tmp_indx[0] * NFineperEpsilon[1] * patchT[TInd].NPatchFine[0]).astype(int) \
                   + (tmp_indx[1] * NFineperEpsilon[0]).astype(int)
            alphaT[:len(alphaT) -
                   1] = (inclval - rPatch()[indx]) / (inclval - defval)
            alphaT[len(alphaT) - 1] = 1. - np.sum(alphaT[:len(alphaT) - 1])
        elif model['name'] == 'inclfill':
            alphaT = np.zeros(len(aRefList))
            bgval = model['bgval']
            inclval = model['inclval']
            NFineperEpsilon = world.NWorldFine // Nepsilon
            NEpsilonperPatchCoarse = patchT[TInd].NPatchCoarse * (
                Nepsilon // world.NWorldCoarse)
            tmp_indx = np.array([
                np.arange(len(aRefList) - 1) // NEpsilonperPatchCoarse[0],
                np.arange(len(aRefList) - 1) % NEpsilonperPatchCoarse[0]
            ])
            indx = (tmp_indx[0] * NFineperEpsilon[1] * patchT[TInd].NPatchFine[0]).astype(int) \
                    + (tmp_indx[1] * NFineperEpsilon[0]).astype(int)
            alphaT[:len(alphaT) -
                   1] = (bgval - rPatch()[indx]) / (bgval - inclval)
            alphaT[len(alphaT) - 1] = 1. - np.sum(alphaT[:len(alphaT) - 1])
        elif model['name'] == 'inclshift':
            alphaT = np.zeros(len(aRefList))
            bgval = model['bgval']
            inclval = model['inclval']
            NFineperEpsilon = world.NWorldFine // Nepsilon
            NEpsilonperPatchCoarse = patchT[TInd].NPatchCoarse * (
                Nepsilon // world.NWorldCoarse)
            assert (model['def_bl'][0] < model['left'][0]
                    or model['def_bl'][1] < model['left'][1]
                    or model['def_bl'][0] >= model['right'][0]
                    or model['def_bl'][1] >= model['right'][1])
            # other cases not yet implemented
            blx = model['def_bl'][0]
            bly = model['def_bl'][1]
            tmp_indx = np.array([
                np.arange(len(aRefList) - 1) // NEpsilonperPatchCoarse[0] +
                blx,
                np.arange(len(aRefList) - 1) % NEpsilonperPatchCoarse[0] + bly
            ])
            indx = (tmp_indx[0] * NFineperEpsilon[1] * patchT[TInd].NPatchFine[0]).astype(int) \
                + (tmp_indx[1] * NFineperEpsilon[0]).astype(int)
            alphaT[:len(alphaT) -
                   1] = (bgval - rPatch()[indx]) / (bgval - inclval)
            alphaT[len(alphaT) - 1] = 1. - np.sum(alphaT[:len(alphaT) - 1])
        elif model['name'] == 'inclLshape':
            alphaT = np.zeros(len(aRefList))
            bgval = model['bgval']
            inclval = model['inclval']
            blx = model['def_bl'][0]
            bly = model['def_bl'][1]
            NFineperEpsilon = world.NWorldFine // Nepsilon
            NEpsilonperPatchCoarse = patchT[TInd].NPatchCoarse * (
                Nepsilon // world.NWorldCoarse)
            tmp_indx = np.array([
                np.arange(len(aRefList) - 1) // NEpsilonperPatchCoarse[0] +
                blx,
                np.arange(len(aRefList) - 1) % NEpsilonperPatchCoarse[0] + bly
            ])
            indx = (tmp_indx[0] * NFineperEpsilon[1] * patchT[TInd].NPatchFine[0]).astype(int) \
                    + (tmp_indx[1] * NFineperEpsilon[0]).astype(int)
            alphaT[:len(alphaT) -
                   1] = (inclval - rPatch()[indx]) / (inclval - bgval)
            alphaT[len(alphaT) - 1] = 1. - np.sum(alphaT[:len(alphaT) - 1])

        if compute_indicator:
            assert (correctorsList is not None)
            indicatorValue = indicator.computeErrorIndicatorFineMultiple(
                patchT[TInd], correctorsList, aRefList, alphaT)
            defects = np.sum(alphaT[:len(alphaT) - 1])
            indicatorT = [indicatorValue, defects]
        else:
            indicatorT = None

        if compute_correc:
            assert (correctorsList is not None)
            correctorsT = np.einsum('i, ijk -> jk', alphaT, correctorsList)
        else:
            correctorsT = None

        KmsijT = np.einsum('i, ijk -> jk', alphaT, KmsijList)

        return KmsijT, indicatorT, correctorsT