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()
#Gaussian field with correlation length l p, l = np.inf, 1 #number of terms in expansion k = 20 kernel = Matern(p=p, l=l) #0,1Exponential covariance kernel kle = KLE(mesh, kernel, verbose=True) kle.compute_eigendecomposition(k=k) #20 by default print "eigenvalues:", kle.l plt.close('all') #ploteigenvectors(kle) #Generate realizations noise = kle.realizations() # The markers are stored within the mesh #ffun = MeshFunction("size_t", mesh, 2, mesh.domains()) # The facet function contains some very large number, # so if you want plot it you need to surpress those values #ffun.array()[ffun.array() == max(ffun.array())] = 0 #plot(ffun,mesh, interactive =True)) #plotting the field V = FunctionSpace(mesh, "CG", 1) random_field = Function(V) random_f = np.zeros((mesh.num_vertices()), dtype=float) random_f = noise random_field.vector()[:] = random_f[dof_to_vertex_map(V)] plot(random_field, mesh, interactive=True)
sffmean = Function(model.projection_space) sffstdv = Function(model.projection_space) sffsai1 = Function(model.projection_space) sffsait = Function(model.projection_space) random_field = Function(FunctionSpace(model.mesh, "CG", 1)) # Evaluate model in sample points solves1 = [] solves2 = [] solves3 = [] nnan = 0 for s in nodes.T: alpha_noise = kle.realizations(s) model.update_randomfield( alpha_noise = alpha_noise) pressure = pi while pressure <= pressures[len(pressures)-1]: print "----------------" print "PRESSURE", pressure print "----------------" qoi = model.run(pressure) while np.isnan(qoi[0]) == True: print "WARNING: NaN" newsample = joint.sample(1, rule = "R") model = problem() model.update_params(*newsample.T[0]) nnan = nnan + 1
sffmean = Function(model.projection_space) sffstdv = Function(model.projection_space) sffsai1 = Function(model.projection_space) sffsait = Function(model.projection_space) random_field = Function(FunctionSpace(model.mesh, "CG", 1)) # Evaluate model in sample points solves1 = [] solves2 = [] solves3 = [] nnan, i = 0, 0 model = problem() for s in nodes.T: model = problem() alpha_noise = kle.realizations(s)[dof_to_vertex_map(model.fiber_space)] model.update_randomfield(alpha_noise=alpha_noise) pressure = pi while pressure <= pressures[len(pressures) - 1]: print "----------------" print "PRESSURE", pressure, pressures[len(pressures) - 1] print "----------------" qoi = model.run(pressure) if (i == 0) & (pressure == 0.0): txt_file.write("--------------------------------- \n") txt_file.write("PCE: Random Field \n") txt_file.write("Nkl terms: %i \n" % int(nkl))