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)
def trivariate(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]) # Add "Parameter" into "ParameterContainer" pc = ParameterContainer() pc.addParameter(c) pc.addParameter(k) pc.addParameter(m) 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
""" f = np.pi spr = Spring(k) u = spr.solve(0, f) E = spr.F(u) 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 #######################################################################
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)
print "\nevaluate function using sampling\n" import sys 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():
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 ######################################################################