def KLE1D(a=1, c=1, k=10): from kle import KLE mesh = UnitInterval(1000) mesh.coordinates()[:] = 2. * a * mesh.coordinates()[:] - a def kernel(R): return np.exp(-c * R) kle = KLE(mesh, kernel) from time import time start = time() la, va = kle.compute_eigendecomposition(k=k) la = la[::-1] va = va[:, ::-1] print "Time for arpack %g " % (time() - start) return la, va
def KLE1D(a = 1, c = 1, k = 10): from kle import KLE mesh = UnitInterval(1000) mesh.coordinates()[:] = 2.*a*mesh.coordinates()[:] - a def kernel(R): return np.exp(-c*R) kle = KLE(mesh,kernel) from time import time start = time() la, va = kle.compute_eigendecomposition(k = k) la = la[::-1] va = va[:,::-1] print "Time for arpack %g " %(time()-start) return la, va
fig.colorbar(im, cax = cbar_ax) plt.savefig('figs/square.png') plt.show() return if __name__ == '__main__': from dolfin import * mesh = UnitSquare(20,20) #really a 101 x 101 grid mesh.coordinates()[:] = 2.*mesh.coordinates()-1. print mesh.coordinates() kernel = Matern(p = 0, l = 1.) #Exponential covariance kernel kle = KLE(mesh, kernel, verbose = True) kle.compute_eigendecomposition(k = 20) print kle.l import matplotlib.pyplot as plt plt.close('all') ploteigenvectors(kle)
fig.suptitle('Eigenvectors of KLE', fontsize=20) fig.subplots_adjust(right=0.8) cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7]) fig.colorbar(im, cax=cbar_ax) plt.savefig('figs/square.png') plt.show() return if __name__ == '__main__': from dolfin import * mesh = UnitSquare(20, 20) #really a 101 x 101 grid mesh.coordinates()[:] = 2. * mesh.coordinates() - 1. kernel = Matern(p=0, l=1.) #Exponential covariance kernel kle = KLE(mesh, kernel, verbose=True) kle.compute_eigendecomposition(k=20) print kle.l import matplotlib.pyplot as plt plt.close('all') #ploteigenvectors(kle) #Generate realizations real = kle.realizations()
Polynomials = cp.orth_ttr(order, joint_KL) # Generate samples by quasi-random samples qmc_scheme = "H" nnodes = 2*len(Polynomials) nodes = joint_KL.sample(nnodes, qmc_scheme) # Regression method in Point Collocation rgm_rule ="T" #Orthogonal Matching Pursuit#"LS" # Random Field p , l = np.inf, 1 k = nkl kernel = Matern(p = p,l = l) #0,1Exponential covariance kernel kle = KLE(model.mesh, kernel, verbose = True) kle.compute_eigendecomposition(k = k)#20 by default #real = kle.realizations(epsilon) # range of pressure pi = 0.0 pf = 0.03 dp = 0.01 pressures = np.arange(pi, pf+dp, dp) print "---------------------------------" print "PCE-Random Field" print "Nkl terms:", int(nkl) print "Order:", order print "Sampling Method:", qmc_scheme print "Number of nodes:", nnodes
from kle import KLE from covariance import Matern from dolfin import * import numpy as np def view(kle): #Write in pvd format. Can be opened in Paraview or MayaVi file = File("figs/kle.pvd","compressed") v = Function(kle.V) for i in np.arange(kle.l.size): v.vector()[:] = np.copy(kle.v[:,i]) file << (v,float(i)) return if __name__ == '__main__': mesh = Mesh("meshes/aneurysm.xml.gz") kernel = Matern(p = 2, l = 20.) kle = KLE(mesh, kernel, verbose = True) kle.compute_eigendecomposition(k = 6) view(kle)
order = 3 Polynomials = cp.orth_ttr(order, joint_KL) # Generate samples by quasi-random samples qmc_scheme = "S" # "H" nnodes = 3 * len(Polynomials) nodes = joint_KL.sample(nnodes, qmc_scheme) # Regression method in Point Collocation rgm_rule = "T" # Orthogonal Matching Pursuit#"LS" # Random Field sigma = 0.5 # 10.*np.pi/180. p, l = np.inf, 10 k = nkl kernel = Matern(p=p, l=l, s=sigma) # 0,1Exponential covariance kernel kle = KLE(model.mesh, kernel, verbose=True) kle.compute_eigendecomposition(k=k) # 20 by default # real = kle.realizations(epsilon) # range of pressure pi = 0.0 pf = 2.0 dp = 0.05 pressures = np.arange(pi, pf + dp, dp) print "---------------------------------" print "PCE-Random Field" print "Nkl terms:", int(nkl)