Пример #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 plot_absmag(self, N):
		figure()
		for i in N:
			T_list = []
			absM_list = []
			for sim in self.simulations:	
				if sim.N == i:
					absM_list.append(sim.absM_end)
					T_list.append(sim.T)
			T_diff = []			
			T_list, absM_list = zip(*sorted(zip(T_list, absM_list)))
			for j in range(len(T_list)-1):
				T_diff.append((absM_list[j+1]-absM_list[j])/(T_list[j+1]-T_list[j-1]))
			T_diff = abs(np.asarray(T_diff))			
			index = T_diff.argmax()
			self.Tc.append((T_list[index+1]+T_list[index])/2.0)
			self.L.append(1./i)
			plot(T_list, absM_list, '-*', legend="N = %d" % i)
			title("Absolute magnetic moment as a function of temperature")
			xlabel("$kT/J$")
			ylabel("$|\mathcal{M}|$")
			hold('on')
		hardcopy(self.figurepath + "absmag.png")
		slope, intercept, tmp1, tmp2, tmp3 = stats.linregress(self.L, self.Tc)
		x = np.linspace(0, 0.05, 20)
		y = intercept + slope*x
		hold("off")
		figure()
		plot(self.L, self.Tc, '*', legend="Data points")
		hold("on")
		plot(x, y, legend="%f $L^{-1}$ + %f" %(slope, intercept))
		xlabel("$1/L$")
		ylabel("$kT_c/J$")
		title("Calculated critical temperature")
		hardcopy(self.figurepath + "calctc.png")
Пример #3
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)])
Пример #4
0
 def plot_velocities(self):
     figure();
     if not self.velocities:
         self.calculate_velocities();
     plot(self.t, self.velocities);
     title(self.filename + ' Velocities');
     xlabel('t[s]');
     ylabel('radial velocity [m/s]');
Пример #5
0
 def plot_velocities(self):
     figure()
     if not self.velocities:
         self.calculate_velocities()
     plot(self.t, self.velocities)
     title(self.filename + ' Velocities')
     xlabel('t[s]')
     ylabel('radial velocity [m/s]')
Пример #6
0
	def plotBySimulation(self):
		for i in range(len(self.simulations)):
			sim = self.simulations[i];
			figure(i);
			for j in range(len(sim.states)):
				plot(sim.rho, sim.states[j]**2, legend=r"$\psi_{%d}, \lambda= %g$" % (j, sim.eigenvalues[j]), xlabel=r'$\frac{1}{\alpha}r$', ylabel=r'$\alpha|\psi_n|^2$')
				title("$\omega = %g$" %sim.omega)
				hold('on')
		raw_input("press enter")
		closefigs()
Пример #7
0
 def plotByOmega(self, omegalimit=0.1):
     for sim in self.simulations:
         for i in range(len(sim.states)):
             if sim.omega >= omegalimit:
                 figure(i)
                 plot(sim.rho, sim.states[i]**2, legend="$\omega= %g, \lambda= %g$" % (sim.omega, sim.eigenvalues[i]), xlabel=r'$\frac{1}{\alpha}r$', \
                   ylabel=r'$\alpha|\psi_n|^2$')
                 title(r"$\psi_{%d}$" % i)
                 hold('on')
     raw_input("press enter")
     closefigs()
Пример #8
0
	def plotByOmega(self, omegalimit = 0.1):
		for sim in self.simulations:
			for i in range(len(sim.states)):
				if sim.omega >= omegalimit:
					figure(i);
					plot(sim.rho, sim.states[i]**2, legend="$\omega= %g, \lambda= %g$" % (sim.omega, sim.eigenvalues[i]), xlabel=r'$\frac{1}{\alpha}r$', \
							ylabel=r'$\alpha|\psi_n|^2$')
					title(r"$\psi_{%d}$" % i);
					hold('on')
		raw_input("press enter")
		closefigs();
Пример #9
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);
Пример #10
0
 def plotBySimulation(self):
     for i in range(len(self.simulations)):
         sim = self.simulations[i]
         figure(i)
         for j in range(len(sim.states)):
             plot(sim.rho,
                  sim.states[j]**2,
                  legend=r"$\psi_{%d}, \lambda= %g$" %
                  (j, sim.eigenvalues[j]),
                  xlabel=r'$\frac{1}{\alpha}r$',
                  ylabel=r'$\alpha|\psi_n|^2$')
             title("$\omega = %g$" % sim.omega)
             hold('on')
     raw_input("press enter")
     closefigs()
Пример #11
0
	def plot_heat_capacity(self, N):
		figure()
		for i in N:
			T_list = []
			hc_list = []
			for sim in self.simulations:	
				if sim.N == i:
					hc_list.append(sim.heat_capacity)
					T_list.append(sim.T)
			T_list, hc_list = zip(*sorted(zip(T_list, hc_list)))
			plot(T_list, hc_list, '-*', legend="N = %d" % i)
			xlabel("$kT/J$")
			ylabel("$C_V/k$")
			title("Heat capacity as a function of temperature")
			hold('on')
		hardcopy(self.figurepath + "heat_capacity.png")
Пример #12
0
	def plot_energies(self, N):
		figure()
		for i in N:
			T_list = []
			E_list = []
			for sim in self.simulations:	
				if sim.N == i:
					E_list.append(sim.E_end)
					T_list.append(sim.T)
			T_list, E_list = zip(*sorted(zip(T_list, E_list)))
			plot(T_list, E_list, '-*', legend="N = %d" % i)
			title("Energy as a function of temperature")
			xlabel("$kT/J$")
			ylabel("$E/J$")
			hold('on')
		hardcopy(self.figurepath + "energy.png")
Пример #13
0
 def plot_energies(self, N):
     figure()
     for i in N:
         T_list = []
         E_list = []
         for sim in self.simulations:
             if sim.N == i:
                 E_list.append(sim.E_end)
                 T_list.append(sim.T)
         T_list, E_list = zip(*sorted(zip(T_list, E_list)))
         plot(T_list, E_list, '-*', legend="N = %d" % i)
         title("Energy as a function of temperature")
         xlabel("$kT/J$")
         ylabel("$E/J$")
         hold('on')
     hardcopy(self.figurepath + "energy.png")
Пример #14
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)
Пример #15
0
 def plot_heat_capacity(self, N):
     figure()
     for i in N:
         T_list = []
         hc_list = []
         for sim in self.simulations:
             if sim.N == i:
                 hc_list.append(sim.heat_capacity)
                 T_list.append(sim.T)
         T_list, hc_list = zip(*sorted(zip(T_list, hc_list)))
         plot(T_list, hc_list, '-*', legend="N = %d" % i)
         xlabel("$kT/J$")
         ylabel("$C_V/k$")
         title("Heat capacity as a function of temperature")
         hold('on')
     hardcopy(self.figurepath + "heat_capacity.png")
Пример #16
0
	def plot_susceptibility(self, N):
		figure()
		legends = []
		for i in N:
			T_list = []
			su_list = []
			#legends.append("N = %d" % i)
			for sim in self.simulations:	
				if sim.N == i:
					su_list.append(sim.susceptibility)
					T_list.append(sim.T)
			T_list, su_list = zip(*sorted(zip(T_list, su_list)))
			plot(T_list, su_list, '-*', legend="N = %d" % i)
			title("Susceptibility as a function of temperature")
			xlabel("$kT/J$")
			ylabel("$\chi J$")
			hold('on')
		hardcopy(self.figurepath + "susceptibility.png")
Пример #17
0
 def plot_susceptibility(self, N):
     figure()
     legends = []
     for i in N:
         T_list = []
         su_list = []
         #legends.append("N = %d" % i)
         for sim in self.simulations:
             if sim.N == i:
                 su_list.append(sim.susceptibility)
                 T_list.append(sim.T)
         T_list, su_list = zip(*sorted(zip(T_list, su_list)))
         plot(T_list, su_list, '-*', legend="N = %d" % i)
         title("Susceptibility as a function of temperature")
         xlabel("$kT/J$")
         ylabel("$\chi J$")
         hold('on')
     hardcopy(self.figurepath + "susceptibility.png")
Пример #18
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"
Пример #19
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"
Пример #20
0
 def plot_absmag(self, N):
     figure()
     for i in N:
         T_list = []
         absM_list = []
         for sim in self.simulations:
             if sim.N == i:
                 absM_list.append(sim.absM_end)
                 T_list.append(sim.T)
         T_diff = []
         T_list, absM_list = zip(*sorted(zip(T_list, absM_list)))
         for j in range(len(T_list) - 1):
             T_diff.append((absM_list[j + 1] - absM_list[j]) /
                           (T_list[j + 1] - T_list[j - 1]))
         T_diff = abs(np.asarray(T_diff))
         index = T_diff.argmax()
         self.Tc.append((T_list[index + 1] + T_list[index]) / 2.0)
         self.L.append(1. / i)
         plot(T_list, absM_list, '-*', legend="N = %d" % i)
         title("Absolute magnetic moment as a function of temperature")
         xlabel("$kT/J$")
         ylabel("$|\mathcal{M}|$")
         hold('on')
     hardcopy(self.figurepath + "absmag.png")
     slope, intercept, tmp1, tmp2, tmp3 = stats.linregress(self.L, self.Tc)
     x = np.linspace(0, 0.05, 20)
     y = intercept + slope * x
     hold("off")
     figure()
     plot(self.L, self.Tc, '*', legend="Data points")
     hold("on")
     plot(x, y, legend="%f $L^{-1}$ + %f" % (slope, intercept))
     xlabel("$1/L$")
     ylabel("$kT_c/J$")
     title("Calculated critical temperature")
     hardcopy(self.figurepath + "calctc.png")
Пример #21
0
eigenvalues = None
rho = None
sqsum = None
for name in os.listdir(path):
    if "eigenvalues" in name:
        eigenvalues = np.fromfile(path + name, dtype=np.float64)
        print eigenvalues

    if "grid" in name:
        print path + name
        rho = np.fromfile(path + name, dtype=np.float64)
        print rho

    if "sqsum" in name:
        sqsum = []
        fileInput = open(path + name)
        for line in fileInput:
            sqsum.append(float(eval(line)))
        sqsum = np.asarray(sqsum)
        figure()
        semilogy(sqsum)
        title("Sum of squared off-diagonal elements")


for name in os.listdir(path):
    if "state" in name:
        plotSolution(path, name, rho, eigenvalues)


raw_input("press enter")
Пример #22
0
 def plot_intensities(self):
     figure();
     plot(self.t, self.intensities);
     xlabel('t[s]');
     ylabel('Relative intensity')
     title(self.filename + ' intensity');
Пример #23
0
sims.load_tree()
N = [20, 30, 40, 60, 80, 100]
sims.plot_heat_capacity(N)#, 40, 60, 80, 100])
sims.plot_susceptibility(N)
sims.plot_absmag(N)
sims.plot_energies(N)
"""

###########################
# Plotting P(E) for L=20 an T = [1, 2.4]
###########################
sim = Simulation(20, 2.4, "/scratch/henriasv/FYS3150/IsingModel_once/N20/T2.4")
sim.set_thermalization(0.2)
sim.calculate_properties()
sim.plot_pe()
title("Probability density function for the energy at T=2.4 (not normalized)")
xlabel("E")
ylabel("Count")
variance = stats.var(sim.e_array)
print "variance = %f" % variance, sim.var_E
hold("on")
sim = Simulation(20, 1, "/scratch/henriasv/FYS3150/IsingModel_once/N20/T1")
sim.set_thermalization(0.2)
sim.calculate_properties()
sim.plot_pe()
title("Probability density function for the energy at T=1 (not normalized)")
xlabel("E")
ylabel("Count")
"""
###########################
# Plotting convergence with ordered or random initialization for T = [1, 2.4]
Пример #24
0
 def plot_frequencies(self):
     figure();
     plot(self.t, self.frequencies);
     xlabel('t[s]');
     ylabel('Wavelength [nm]');
     title(self.filename + ' Wavelength');
Пример #25
0
        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)])


path = "/scratch/henriasv/FYS3150/project1/"
error = []
for name in os.listdir(path):
    if not name.endswith('.txt'):
        plotSolution(path + name, error)
error = np.asarray(error)
error = np.log10(error)
figure()
plot(error[:, 0], error[:, 1], '*')
title('maximum relative error with different step lengths')
xlabel('log(h)')
ylabel('log($\epsilon$)')

raw_input("press enter")
Пример #26
0
sims.load_tree()
N = [20, 30, 40, 60, 80, 100]
sims.plot_heat_capacity(N)#, 40, 60, 80, 100])
sims.plot_susceptibility(N)
sims.plot_absmag(N)
sims.plot_energies(N)
"""

###########################
# Plotting P(E) for L=20 an T = [1, 2.4]
###########################
sim = Simulation(20, 2.4, "/scratch/henriasv/FYS3150/IsingModel_once/N20/T2.4")
sim.set_thermalization(0.2)
sim.calculate_properties()
sim.plot_pe()
title("Probability density function for the energy at T=2.4 (not normalized)")
xlabel("E")
ylabel("Count")
variance = stats.var(sim.e_array)
print "variance = %f" % variance, sim.var_E
hold("on")
sim = Simulation(20, 1, "/scratch/henriasv/FYS3150/IsingModel_once/N20/T1")
sim.set_thermalization(0.2)
sim.calculate_properties()
sim.plot_pe()
title("Probability density function for the energy at T=1 (not normalized)")
xlabel("E")
ylabel("Count")

"""
###########################
Пример #27
0
path = "/scratch/henriasv/FYS3150/project2/" + sys.argv[1]

eigenvalues = None
rho = None
sqsum = None
for name in os.listdir(path):
    if "eigenvalues" in name:
        eigenvalues = np.fromfile(path + name, dtype=np.float64)
        print eigenvalues

    if "grid" in name:
        print path + name
        rho = np.fromfile(path + name, dtype=np.float64)
        print rho

    if "sqsum" in name:
        sqsum = []
        fileInput = open(path + name)
        for line in fileInput:
            sqsum.append(float(eval(line)))
        sqsum = np.asarray(sqsum)
        figure()
        semilogy(sqsum)
        title("Sum of squared off-diagonal elements")

for name in os.listdir(path):
    if "state" in name:
        plotSolution(path, name, rho, eigenvalues)

raw_input("press enter")
Пример #28
0
 def plot_intensities(self):
     figure()
     plot(self.t, self.intensities)
     xlabel('t[s]')
     ylabel('Relative intensity')
     title(self.filename + ' intensity')
Пример #29
0
		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)])

path = "/scratch/henriasv/FYS3150/project1/"
error = [];
for name in os.listdir(path):
	if not name.endswith('.txt'):
		plotSolution(path+name, error)
error = np.asarray(error)
error = np.log10(error)
figure()
plot(error[:, 0], error[:, 1], '*')
title('maximum relative error with different step lengths')
xlabel('log(h)')
ylabel('log($\epsilon$)')


raw_input("press enter")
Пример #30
0
	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":
			prec_gauleg.append([sim.N, sim.cpu_time])
		if sim.ID == "bf_mc":
			prec_bf_mc.append([sim.N, sim.cpu_time])
Пример #31
0
 def plot_frequencies(self):
     figure()
     plot(self.t, self.frequencies)
     xlabel('t[s]')
     ylabel('Wavelength [nm]')
     title(self.filename + ' Wavelength')