Page MenuHomec4science

laplaceGaussianTaylor.py
No OneTemporary

File Metadata

Created
Mon, Nov 25, 04:05

laplaceGaussianTaylor.py

import numpy as np
from rrompy.hfengines.scipy import LaplaceDiskGaussian as LDG
from rrompy.reduction_methods.taylor import ApproximantTaylorPade as Pade
from rrompy.reduction_methods.taylor import ApproximantTaylorRB as RB
from rrompy.utilities.parameter_sweeper import ParameterSweeper as Sweeper
from operator import itemgetter
def subdict(d, ks):
return dict(zip(ks, itemgetter(*ks)(d)))
testNo = 3
verb = 0
if testNo == 1:
mu = 4.
solver = LDG(n = 40, verbosity = verb)
uh = solver.solve(mu)
solver.plotmesh()
print(solver.norm(uh))
solver.plot(uh)
############
if testNo == 2:
params = {'N':8, 'M':8, 'E':8, 'sampleType':'Arnoldi', 'POD':True}
# params = {'N':8, 'M':8, 'E':8, 'sampleType':'Krylov', 'POD':True}
mu0 = 0.
solver = LDG(n = 20, degree_threshold = 15, verbosity = verb)
approxP = Pade(solver, mu0 = mu0, approxParameters = params,
verbosity = verb)
paramsRB = subdict(params, ['E', 'sampleType', 'POD'])
approxR = RB(solver, mu0 = mu0, approxParameters = paramsRB,
verbosity = verb)
approxP.setupApprox()
approxR.setupApprox()
# approxP.plotSamples()
mutar = 3.25
approxP.plotHF(mutar, name = 'u_HF')
approxP.plotApp(mutar, name = 'u_Pade''')
approxR.plotApp(mutar, name = 'u_RB')
approxP.plotErr(mutar, name = 'err_Pade''')
approxR.plotErr(mutar, name = 'err_RB')
solNorm = approxP.normHF(mutar)
appPErr = approxP.normErr(mutar)
appRErr = approxR.normErr(mutar)
print(('SolNorm:\t{}\nErrRelP:\t{}\nErrRelR:\t{}').format(solNorm,
appPErr / solNorm, appRErr / solNorm))
############
elif testNo == 3:
mu0 = 0.
mutars = np.linspace(0., 4., 60)
solver = LDG(n = 10, degree_threshold = 15, verbosity = verb)
shift = 2
nsets = 6
stride = 2
Emax = stride * (nsets - 1) + shift
params = {'Emax':Emax, 'sampleType':'Arnoldi', 'POD':True}
params = {'Emax':Emax, 'sampleType':'Krylov', 'POD':False}
paramsSetsPade = [None] * nsets
paramsSetsRB = [None] * nsets
paramsSetsPoly = [None] * nsets
for i in range(nsets):
paramsSetsPade[i] = {'N':stride*i+shift, 'M':stride*i+shift,
'E':stride*i+shift}
paramsSetsRB[i] = {'E':stride*i+shift}
paramsSetsPoly[i] = {'N':0, 'M':stride*i+shift,
'E':stride*i+shift}
approxPade = Pade(solver, mu0 = mu0, approxParameters = params,
verbosity = verb)
approxRB = RB(solver, mu0 = mu0, approxParameters = params,
verbosity = verb)
approxPoly = Pade(solver, mu0 = mu0, approxParameters = params,
verbosity = verb)
filenamebase = '../data/output/LapGTaylor'
sweeper = Sweeper(mutars = mutars, mostExpensive = 'Approx')
sweeper.ROMEngine = approxPade
sweeper.params = paramsSetsPade
filenamePade = sweeper.sweep(filenamebase + 'Pade.dat')
sweeper.ROMEngine = approxRB
sweeper.params = paramsSetsRB
filenameRB = sweeper.sweep(filenamebase + 'RB.dat')
sweeper.ROMEngine = approxPoly
sweeper.params = paramsSetsPoly
filenamePoly = sweeper.sweep(filenamebase + 'Poly.dat')
sweeper.plotCompare([filenamePade, filenameRB, filenamePoly], ['muRe'],
['normHF', 'normApp'], ['E'], onePlot = True,
save = filenamebase + 'Norm',
saveFormat = "png", labels = ["Pade'", "RB", "Poly"])
sweeper.plotCompare([filenamePade, filenameRB, filenamePoly], ['muRe'],
['normResRel'], ['E'], save = filenamebase + 'Res',
saveFormat = "png", labels = ["Pade'", "RB", "Poly"])
sweeper.plotCompare([filenamePade, filenameRB, filenamePoly], ['muRe'],
['normErrRel'], ['E'], save = filenamebase + 'Err',
saveFormat = "png", labels = ["Pade'", "RB", "Poly"])

Event Timeline