Page MenuHomec4science

symmetric_disk.py
No OneTemporary

File Metadata

Created
Wed, May 1, 09:18

symmetric_disk.py

import numpy as np
from symmetric_disk_engine import SymmetricDiskEngine as engine
from rrompy.sampling import SamplingEngineStandard as SES
from rrompy.reduction_methods import (
NearestNeighbor as NN, RationalInterpolant as RI, ReducedBasis as RB,
RationalInterpolantGreedy as RIG, ReducedBasisGreedy as RBG)
from rrompy.parameter.parameter_sampling import QuadratureSampler as QS
ks = [10., 20.]
k0, n = np.mean(np.power(ks, 2.)) ** .5, 150
solver = engine(k0, n)
k = 12.
for method in ["RI", "RB", "RI_GREEDY", "RB_GREEDY"]:
print("Testing {} method".format(method))
if method == "RI":
params = {'S':40, 'POD':True, 'polybasis':"CHEBYSHEV",
'sampler':QS(ks, "CHEBYSHEV", scalingExp = 2.)}
algo = RI
if method == "RB":
params = {'S':40, 'POD':True,
'sampler':QS(ks, "CHEBYSHEV", scalingExp = 2.)}
algo = RB
if method == "RI_GREEDY":
params = {'S':10, 'POD':True, 'polybasis':"LEGENDRE", 'greedyTol':1e-2,
'sampler':QS(ks, "UNIFORM", scalingExp = 2.),
'errorEstimatorKind':"DISCREPANCY",
'trainSetGenerator':QS(ks, "CHEBYSHEV", scalingExp = 2.)}
algo = RIG
if method == "RB_GREEDY":
params = {'S':10, 'POD':True, 'greedyTol':1e-2,
'sampler':QS(ks, "UNIFORM", scalingExp = 2.),
'trainSetGenerator':QS(ks, "CHEBYSHEV", scalingExp = 2.)}
algo = RBG
approx = algo(solver, mu0 = k0, approx_state = True,
approxParameters = params, verbosity = 20)
if len(method) == 2:
approx.setupApprox()
else:
approx.setupApprox("LAST")
print("--- Approximant ---")
approx.plotApprox(k, name = 'u_app')
approx.plotHF(k, name = 'u_HF')
approx.plotErr(k, name = 'err_app')
approx.plotRes(k, name = 'res_app')
normErr = approx.normErr(k)[0]
normSol = approx.normHF(k)[0]
normRes = approx.normRes(k)[0]
normRHS = approx.normRHS(k)[0]
print("SolNorm:\t{:.5e}\nErr_app: \t{:.5e}\nErrRel_app:\t{:.5e}".format(
normSol, normErr, normErr / normSol))
print("RHSNorm:\t{:.5e}\nRes_app: \t{:.5e}\nResRel_app:\t{:.5e}".format(
normRHS, normRes, normRes / normRHS))
print("--- Closest snapshot ---")
eng = SES(solver, verbosity = 0)
approxNN = NN(solver, mu0 = k0, approx_state = True, verbosity = 0,
approxParameters = {'S':approx.S, 'POD':True})
approxNN.setSamples(approx.samplingEngine)
approxNN.plotApprox(k, name = 'u_close')
approxNN.plotHF(k, name = 'u_HF')
approxNN.plotErr(k, name = 'err_close')
approxNN.plotRes(k, name = 'res_close')
normErr = approxNN.normErr(k)[0]
normSol = approxNN.normHF(k)[0]
normRes = approxNN.normRes(k)[0]
normRHS = approxNN.normRHS(k)[0]
print("SolNorm:\t{:.5e}\nErr_close:\t{:.5e}\nErrRel_close:\t{:.5e}".format(
normSol, normErr, normErr / normSol))
print("RHSNorm:\t{:.5e}\nRes_close:\t{:.5e}\nResRel_close:\t{:.5e}".format(
normRHS, normRes, normRes / normRHS))
if method[:2] == "RI":
poles, residues = approx.getResidues()
if method[:2] == "RB":
poles = approx.getPoles()
print("Poles:\n{}".format(poles))
if method[:2] == "RI":
for pol, res in zip(poles, residues):
solver.plot(res)
print("pole = {:.5e}".format(pol))
print("\n")

Event Timeline