def PGsolver(world, ABase, f,k): NWorldFine = world.NWorldFine NWorldCoarse = world.NWorldCoarse NCoarseElement = world.NCoarseElement boundaryConditions = world.boundaryConditions NpFine = np.prod(NWorldFine+1) NpCoarse = np.prod(NWorldCoarse+1) #interpolant IPatchGenerator = lambda i, N: interp.L2ProjectionPatchMatrix(i, N, NWorldCoarse, NCoarseElement, boundaryConditions) #Coefficient (need flatten form) aCoef = coef.coefficientFine(NWorldCoarse, NCoarseElement, ABase) pglod = pg_pert.PerturbedPetrovGalerkinLOD(aCoef, world, k, IPatchGenerator, 0) pglod.originCorrectors(clearFineQuantities=False) KFull = pglod.assembleMsStiffnessMatrix() MFull = fem.assemblePatchMatrix(NWorldCoarse, world.MLocCoarse) free = util.interiorpIndexMap(NWorldCoarse) bFull = MFull*f KFree = KFull[free][:,free] bFree = bFull[free] xFree = sparse.linalg.spsolve(KFree, bFree) basis = fem.assembleProlongationMatrix(NWorldCoarse, NCoarseElement) basisCorrectors = pglod.assembleBasisCorrectors() modifiedBasis = basis - basisCorrectors xFull = np.zeros(NpCoarse) xFull[free] = xFree uLodCoarse = xFull uLodFine = modifiedBasis*xFull return uLodCoarse, uLodFine
NWorldCoarse = world.NWorldCoarse NCoarseElement = world.NCoarseElement boundaryConditions = world.boundaryConditions NpFine = np.prod(NWorldFine+1) NpCoarse = np.prod(NWorldCoarse+1) #interpolant IPatchGenerator = lambda i, N: interp.L2ProjectionPatchMatrix(i, N, NWorldCoarse, NCoarseElement, boundaryConditions) #old Coefficient (need flatten form) Aold = coef.coefficientFine(NWorldCoarse, NCoarseElement, ABase) for k in range(1,6): print(('<<<<<<<<<<<<<<<< ' + str(k) + ' >>>>>>>>>>>>>>>>')) pglod = pg_pert.PerturbedPetrovGalerkinLOD(Aold, world, k, IPatchGenerator, 1) pglod.originCorrectors(clearFineQuantities=False) #new Coefficient ANew = R2.flatten() Anew = coef.coefficientFine(NWorldCoarse, NCoarseElement, ANew) # tolerance = 0 vis, eps = pglod.updateCorrectors(Anew, 0,clearFineQuantities=False, Computing = False) elemente = np.arange(np.prod(NWorldCoarse)) if k==5: plt.figure("Error indicator") plt.plot(elemente,eps,label="e_{u,T}") plt.ylabel('$e_{u,T}$')
#fine-fem f_fine = np.ones(NpFine) uFineFem, AFine, MFine = femsolver.solveFine(world, ABase, f_fine, None, boundaryConditions) #PGLOD #interpolant IPatchGenerator = lambda i, N: interp.L2ProjectionPatchMatrix( i, N, NWorldCoarse, NCoarseElement, boundaryConditions) #Coefficient (need flatten form) aCoef = coef.coefficientFine(NWorldCoarse, NCoarseElement, ABase) k = 4 pglod = pg_pert.PerturbedPetrovGalerkinLOD(aCoef, world, k, IPatchGenerator, 2) pglod.originCorrectors(clearFineQuantities=False) KFull = pglod.assembleMsStiffnessMatrix() MFull = fem.assemblePatchMatrix(NWorldCoarse, world.MLocCoarse) free = util.interiorpIndexMap(NWorldCoarse) bFull = MFull * f KFree = KFull[free][:, free] bFree = bFull[free] xFree = sparse.linalg.spsolve(KFree, bFree) basis = fem.assembleProlongationMatrix(NWorldCoarse, NCoarseElement) basisCorrectors = pglod.assembleBasisCorrectors()