示例#1
0
def plotSolution(path, error):
    """
	Definition space of the solution is assumed to be [0, 1)
	Length of loaded array is assumed to be N = N_sim+2, where 2 comes 
	from adding the boundaries after calculations.
	h = 1/(N_sim+1) = 1/(N-1)
	Plotting only solutions with high steplength to avoid crash of gnuplot
	"""
    dataSolution = np.fromfile(path, dtype=np.float64)
    N = len(dataSolution)
    h = 1.0 / (N - 1)
    x = np.linspace(0, 1, N)
    solution = analytic_solution(x)
    if N < 10000:
        figure()
        plot(x, dataSolution, 'o')
        hold('on')
        plot(x, solution)
        title('Solution to -u\'\'=f(x), h=%6.2g' % h)
        xlabel('x')
        ylabel('u(x)')
        legend('Approximation', 'Analytic solution')

    error_array = solution - dataSolution
    error_array = np.abs(error_array / solution)
    error_array[0] = 0
    error_array[len(error_array) - 1] = 0

    error.append([h, np.max(error_array)])
示例#2
0
def plotSolution(path, error):
	"""
	Definition space of the solution is assumed to be [0, 1)
	Length of loaded array is assumed to be N = N_sim+2, where 2 comes 
	from adding the boundaries after calculations.
	h = 1/(N_sim+1) = 1/(N-1)
	Plotting only solutions with high steplength to avoid crash of gnuplot
	"""
	dataSolution = np.fromfile(path, dtype=np.float64);
	N = len(dataSolution);
	h = 1.0/(N-1);
	x = np.linspace(0, 1, N);
	solution = analytic_solution(x);
	if N<10000:
		figure()
		plot(x, dataSolution, 'o');
		hold('on');
		plot(x, solution);
		title('Solution to -u\'\'=f(x), h=%6.2g' %h)
		xlabel('x')
		ylabel('u(x)')
		legend('Approximation', 'Analytic solution')
	
	error_array = solution-dataSolution
	error_array = np.abs(error_array/solution)
	error_array[0] = 0;
	error_array[len(error_array)-1] =0;
	
	error.append([h, np.max(error_array)])
示例#3
0
 def plot_fitted_velocities(self, destination = False):
     if self.P == 0:
         self.fit_velocities();
     data = self.model.modelFunction([self.v_mean, self.v_r, self.P, self.t_0], self.t);
     figure();
     plot(self.t, self.velocities, '--r');
     hold('on');
     plot(self.t, data, '-b')
     title("Least square modeled velocities");
     xlabel('t [s]');
     ylabel('v [m/s]');
     legend('v_mean=%g \n v_r=%g \n P=%g \n t_0=%g' % (self.v_mean, self.v_r, self.P, self.t_0));
     if destination:
         hardcopy(destination);
示例#4
0
 def plot_fitted_velocities(self, destination=False):
     if self.P == 0:
         self.fit_velocities()
     data = self.model.modelFunction(
         [self.v_mean, self.v_r, self.P, self.t_0], self.t)
     figure()
     plot(self.t, self.velocities, '--r')
     hold('on')
     plot(self.t, data, '-b')
     title("Least square modeled velocities")
     xlabel('t [s]')
     ylabel('v [m/s]')
     legend('v_mean=%g \n v_r=%g \n P=%g \n t_0=%g' %
            (self.v_mean, self.v_r, self.P, self.t_0))
     if destination:
         hardcopy(destination)
示例#5
0
def plotSolution(path, name, rho, eigenvalues):
    dataSolution = np.fromfile(path + name, dtype=np.float64)
    N = len(dataSolution)
    x = rho
    dataSolution = dataSolution / np.sqrt(trapz(dataSolution ** 2 / x ** 2, x))
    state_number = round(float((name.strip(".bin").strip("state"))))
    integral = trapz(dataSolution ** 2 / x ** 2, x)
    print state_number
    if N < 10000:
        figure()
        plot(x, dataSolution ** 2 / x ** 2)
        hold("on")
        xlabel(r"$\rho$")
        ylabel(r"$R^2(\rho)$")
        title(name.strip(".bin") + ", " + "$\lambda =$ %g" % eigenvalues[state_number])
        legend("integral = %g" % integral)
    else:
        print "Stopped plot, N>10000"
示例#6
0
def plotSolution(path, name, rho, eigenvalues):
    dataSolution = np.fromfile(path + name, dtype=np.float64)
    N = len(dataSolution)
    x = rho
    dataSolution = dataSolution / np.sqrt(trapz(dataSolution**2 / x**2, x))
    state_number = round(float((name.strip(".bin").strip("state"))))
    integral = trapz(dataSolution**2 / x**2, x)
    print state_number
    if N < 10000:
        figure()
        plot(x, dataSolution**2 / x**2)
        hold('on')
        xlabel(r'$\rho$')
        ylabel(r'$R^2(\rho)$')
        title(
            name.strip('.bin') + ", " +
            '$\lambda =$ %g' % eigenvalues[state_number])
        legend("integral = %g" % integral)
    else:
        print "Stopped plot, N>10000"
示例#7
0
	prec_gauleg = np.asarray(prec_gauleg)
	prec_is_mc = np.asarray(prec_is_mc)
	prec_bf_mc = np.asarray(prec_bf_mc)
	sort_data(prec_gaulag)
	sort_data(prec_gauleg)
	sort_data(prec_is_mc)
	sort_data(prec_bf_mc)

	figure()
	loglog(prec_gaulag[:,0], prec_gaulag[:,1])
	hold("all")
	loglog(prec_gauleg[:,0], prec_gauleg[:,1])
	loglog(prec_bf_mc[:,0], prec_bf_mc[:,1])
	loglog(prec_is_mc[:,0], prec_is_mc[:,1])

	legend("Gauss Laguerre", "Gauss Legendre", "Brute force Monte Carlo", "Importance sampling Monte Carlo")
	xlabel("Number of function evaluations")
	ylabel("Relative error")
	title("Relative error vs number of calculations for different methods")
	hold("off")

	# Plotting function evaluations and cpu_time
	prec_gaulag = []
	prec_gauleg = []
	prec_is_mc  = []
	prec_bf_mc  = []

	for sim in simulations:
		if sim.ID == "gaulag":
			prec_gaulag.append([sim.N, sim.cpu_time])
		if sim.ID == "gauleg":