def pentavariate(dmax): # Create "Parameter" using "Parameter Factory" object pfactory = ParameterFactory() c = pfactory.createNormalParameter('c', dict(mu=4.0, sigma=0.50), dmax[0]) k = pfactory.createExponentialParameter('k', dict(mu=4.0, beta=0.50), dmax[1]) m = pfactory.createUniformParameter('m', dict(a=-5.0, b=4.0), dmax[2]) d = pfactory.createUniformParameter('m', dict(a=-5.0, b=4.0), dmax[3]) e = pfactory.createExponentialParameter('k', dict(mu=4.0, beta=0.50), dmax[4]) # Add "Parameter" into "ParameterContainer" pc = ParameterContainer() pc.addParameter(c) pc.addParameter(k) pc.addParameter(m) pc.addParameter(d) pc.addParameter(e) pc.initialize() test(pc)
def getCollocationPoints(self, ymean): # Create random parameters pfactory = ParameterFactory() a1 = pfactory.createNormalParameter('a1', dict(mu=ymean[0], sigma=0.15), 1) a2 = pfactory.createNormalParameter('a2', dict(mu=ymean[1], sigma=0.15), 1) h = pfactory.createNormalParameter('h', dict(mu=ymean[2], sigma=0.10), 1) # Add random parameters into a container and initialize pc = ParameterContainer() pc.addParameter(a1) pc.addParameter(a2) pc.addParameter(h) pc.initialize() # Number of collocation points (quadrature points) along each # parameter dimension qmap = pc.getQuadraturePointsWeights({0: 5, 1: 5, 2: 5}) return qmap
def univariate(dmax): # Create "Parameter" using "Parameter Factory" object pfactory = ParameterFactory() c = pfactory.createNormalParameter('c', dict(mu=4.0, sigma=0.50), dmax[0]) # Add "Parameter" into "ParameterContainer" pc = ParameterContainer() pc.addParameter(c) pc.initialize() test(pc)
dRdk = spr.dRdk(u) dFdk = spr.dFdk(u) dRdq = spr.dRdq(u) dFdq = spr.dFdq(u) lam = spr.adjoint_solve(u) DFDx = dFdk + lam * dRdk return E, DFDx # Create random parameters pfactory = ParameterFactory() K = pfactory.createNormalParameter( 'K', dict(mu=np.pi / 2., sigma=0.1 * (np.pi / 2.)), 7) # Add random parameters into a container and initialize pc = ParameterContainer() pc.addParameter(K) pc.initialize() # Create deterministic and stochastic spring elements dspr = Spring(k=np.pi / 2.) sspr = StochasticSpring(dspr, pc) ####################################################################### # Test the system ####################################################################### # Assemble stochastic force vector from deterministic vector f = np.pi U = sspr.solve(0, f) # E = dspr.F(uhat)
import sys from os import path sys.path.append( path.dirname( path.dirname( path.abspath(__file__) ) ) ) import numpy as np from pspace.core import ParameterFactory, ParameterContainer # Create "Parameter" using "Parameter Factory" object pfactory = ParameterFactory() c = pfactory.createNormalParameter('c', dict(mu=-4.0, sigma=0.50), 5) k = pfactory.createUniformParameter('k', dict(a=-5.0, b=4.0), 5) m = pfactory.createExponentialParameter('m', dict(mu=6.0, beta=1.0), 5) d = pfactory.createUniformParameter('d', dict(a=-5.0, b=4.0), 5) e = pfactory.createExponentialParameter('e', dict(mu=6.0, beta=1.0), 5) # Add "Parameter" into "ParameterContainer" pc = ParameterContainer() pc.addParameter(c) pc.addParameter(k) pc.addParameter(m) pc.addParameter(d) pc.addParameter(e) pc.initialize() pc.initializeQuadrature({0:5,1:5,2:5,3:5,4:5}) N = pc.getNumStochasticBasisTerms() print N for k in range(N): pids = pc.getParameters().keys() for q in pc.quadrature_map.keys(): pc.evalOrthoNormalBasis(k,q)
from os import path sys.path.append(path.dirname(path.dirname(path.abspath(__file__)))) import numpy as np from collections import Counter from timeit import default_timer as timer from pspace.core import ParameterFactory, ParameterContainer from pspace.plotter import plot_jacobian # Create "Parameter" using "Parameter Factory" object pfactory = ParameterFactory() alpha = pfactory.createNormalParameter('alpha', dict(mu=1.0, sigma=0.10), 4) # Add "Parameter" into "ParameterContainer" pc = ParameterContainer() pc.addParameter(alpha) pc.initialize() param_nqpts_map = {0: 10} quadmap = pc.getQuadraturePointsWeights(param_nqpts_map) # Solve deterministic ODE at each y flist = [] nsamples = 0 for qindex in quadmap.keys(): nsamples += 1 # Get weights and nodes for this point in Y/Z-domain yq = quadmap[qindex]['Y'] wq = quadmap[qindex]['W']
if __name__ == '__main__': """ """ start = timer() # Create "Parameter" using "Parameter Factory" object pfactory = ParameterFactory() c = pfactory.createNormalParameter('c', dict(mu=-4.0, sigma=0.50), 4) k = pfactory.createExponentialParameter('k', dict(mu=6.0, beta=1.0), 5) m = pfactory.createUniformParameter('m', dict(a=-5.0, b=4.0), 6) d = pfactory.createUniformParameter('d', dict(a=-5.0, b=4.0), 3) # Add "Parameter" into "ParameterContainer" pc = ParameterContainer() pc.addParameter(c) pc.addParameter(k) pc.addParameter(m) pc.addParameter(d) pc.initialize() suffix = 'eee' # rename for readability w = lambda q: pc.W(q) psiz = lambda i, q: pc.evalOrthoNormalBasis(i, q) def fy(q): ymap = pc.Y(q)
from pspace.core import ParameterFactory, ParameterContainer # Create "Parameter" using "Parameter Factory" object pfactory = ParameterFactory() c = pfactory.createNormalParameter('c', dict(mu=-4.0, sigma=0.50), 4) m = pfactory.createUniformParameter('m', dict(a=-5.0, b=4.0), 4) k = pfactory.createExponentialParameter('k', dict(mu=6.0, beta=1.0), 5) K = pfactory.createExponentialParameter('k', dict(mu=6.0, beta=1.0), 5) #C = pfactory.createNormalParameter('c', dict(mu=-4.0, sigma=0.50), 9) # Add "Parameter" into "ParameterContainer" pc = ParameterContainer() pc.addParameter(c) pc.addParameter(m) pc.addParameter(k) pc.addParameter(K) #pc.addParameter(C) pc.initialize() N = pc.getNumStochasticBasisTerms() #zmap = {0:1.01, 1:1.00,2 :1.0001} zmap = {0: 1.01, 1: 1.00, 2: 1.0001, 3: 2.0} #, 4:0.231312} ## for k in range(N): ## k+1, pc.psi(k,zmap) for k in range(N): # Initialize quadrature with number of gauss points # necessary for i-th basis entry nqpts_map = pc.getNumQuadraturePointsFromDegree(
return ks def maxdispks(t, yqq, ksweight): return maxKS(ksweight, t, yqq) ###################################################################### # Setup ParameterContainer to UQ with Sampling and Galerkin Methods ###################################################################### '''Create "Parameter" using "Parameter Factory" object''' pfactory = ParameterFactory() alpha = pfactory.createNormalParameter('alpha', dict(mu=1.0, sigma=0.30), NTERMS) '''Add "Parameters" into "ParameterContainer"''' pc = ParameterContainer() pc.addParameter(alpha) pc.initialize() ###################################################################### # Sampling ###################################################################### print("\nevaluate KS function using sampling : nsamples = %d \n" % NSAMPLES) '''Set number of quadrature points to do deterministic evaluation''' param_nqpts_map = {0: NSAMPLES} quadmap = pc.getQuadraturePointsWeights(param_nqpts_map) ''' Solve deterministic ODE at each y ''' flist = [] nsamples = 0 for qindex in quadmap.keys():
from __future__ import print_function import matplotlib.pyplot as plt import numpy as np from pspace.core import ParameterFactory, ParameterContainer N = 30 # Create random parameters pfactory = ParameterFactory() xi1 = pfactory.createUniformParameter('xi1', dict(a=0.0, b=1.0), 1) xi2 = pfactory.createUniformParameter('xi2', dict(a=0.0, b=1.0), 1) # Add random parameters into a container and initialize pc = ParameterContainer() pc.addParameter(xi1) pc.addParameter(xi2) pc.initialize() # Get the Gaussian Quadrature points in 2d Y = np.zeros((N*N,2)) quadmap = pc.getQuadraturePointsWeights({0:N,1:N}) for q in quadmap.keys(): yq = quadmap[q]['Y'] wq = quadmap[q]['W'] Y[q,0] = yq[0] Y[q,1] = yq[1] ###################################################################### # plot results ######################################################################