Page MenuHomec4science

square_simplified_pod_hermite.py
No OneTemporary

File Metadata

Created
Thu, Sep 26, 09:05

square_simplified_pod_hermite.py

import numpy as np
from rrompy.hfengines.linear_problem.bidimensional import \
HelmholtzSquareSimplifiedDomainProblemEngine as HSSDPE
from rrompy.reduction_methods.centered import RationalPade as RP
from rrompy.reduction_methods.distributed import RationalInterpolant as RI
from rrompy.reduction_methods.centered import RBCentered as RBC
from rrompy.reduction_methods.distributed import RBDistributed as RBD
from rrompy.parameter.parameter_sampling import (QuadratureSampler as QS,
RandomSampler as RS,
ManualSampler as MS)
verb = 0
size = 2
MN = 4
R = (MN + 2) * (MN + 1) // 2
S0 = [3] * 2
S = [25]
assert R < np.prod(S)
samples = "centered"
samples = "distributed"
algo = "rational"
#algo = "RB"
sampling = "quadrature"
#sampling = "random"
if size == 1: # small
mu0 = [4 ** .5, 1.5 ** .5]
mutar = [5 ** .5, 1.75 ** .5]
murange = [[2 ** .5, 1. ** .5], [6 ** .5, 2. ** .5]]
elif size == 2: # medium
mu0 = [4 ** .5, 1.75 ** .5]
mutar = [4.5 ** .5, 1.25 ** .5]
murange = [[1 ** .5, 1. ** .5], [7 ** .5, 2.5 ** .5]]
elif size == 3: # large
mu0 = [6 ** .5, 4 ** .5]
mutar = [2 ** .5, 2.5 ** .5]
murange = [[0 ** .5, 2 ** .5], [12 ** .5, 6 ** .5]]
elif size == 4: # crowded
mu0 = [10 ** .5, 2 ** .5]
mutar = [9 ** .5, 2.25 ** .5]
murange = [[8 ** .5, 1.5 ** .5], [12 ** .5, 2.5 ** .5]]
solver = HSSDPE(kappa = 2.5, theta = np.pi / 3, mu0 = mu0, n = 20,
verbosity = verb)
rescaling = [lambda x: np.power(x, 2.)] * 2
rescalingInv = [lambda x: np.power(x, .5)] * 2
if algo == "rational":
params = {'N':MN, 'M':MN, 'S':S, 'POD':True}
if samples == "distributed":
params['polybasis'] = "CHEBYSHEV"
method = RI
else:
method = RP
else: #if algo == "RB":
params = {'R':R, 'S':S, 'POD':True}
if samples == "distributed":
method = RBD
else:
method = RBC
if samples == "distributed":
if sampling == "quadrature":
sampler0 = QS(murange, "CHEBYSHEV", scaling = rescaling,
scalingInv = rescalingInv)
else: # if sampling == "random":
sampler0 = RS(murange, "SOBOL", scaling = rescaling,
scalingInv = rescalingInv)
S0 = np.prod(S0)
params['sampler'] = MS(murange, points = sampler0.generatePoints(S0))
approx = method(solver, mu0 = mu0, approxParameters = params,
verbosity = verb)
approx.setupApprox()
approx.plotApprox(mutar, name = 'u_app')
approx.plotHF(mutar, name = 'u_HF')
approx.plotErr(mutar, name = 'err')
approx.plotRes(mutar, name = 'res')
appErr, solNorm = approx.normErr(mutar), approx.normHF(mutar)
resNorm, RHSNorm = approx.normRes(mutar), approx.normRHS(mutar)
print(('SolNorm:\t{}\nErr:\t{}\nErrRel:\t{}').format(solNorm, appErr,
np.divide(appErr, solNorm)))
print(('RHSNorm:\t{}\nRes:\t{}\nResRel:\t{}').format(RHSNorm, resNorm,
np.divide(resNorm, RHSNorm)))
if algo == "rational":
from matplotlib import pyplot as plt
mu1 = np.linspace(murange[0][0]**2, murange[1][0]**2, 100)
mu2 = np.linspace(murange[0][1]**2, murange[1][1]**2, 100)
mu1s = np.power(mu1, .5)
mu2s = np.power(mu2, .5)
Mu1, Mu2 = np.meshgrid(mu1, mu2)
mus = [(m1, m2) for m2 in mu2s for m1 in mu1s]
Z = approx.trainedModel.getQVal(mus).reshape(Mu1.shape)
plt.figure(figsize = (15, 7))
p = plt.contourf(Mu1, Mu2, np.log(np.abs(Z)), 50)
plt.contour(Mu1, Mu2, np.real(Z), [0.], linestyles = 'dashed')
plt.contour(Mu1, Mu2, np.imag(Z), [0.], linewidths = 1,
linestyles = 'dotted')
plt.plot(approx.mus(0) ** 2, approx.mus(1) ** 2, 'kx')
plt.colorbar(p)
plt.grid()
plt.show()

Event Timeline