diff --git a/homework3/.gitignore b/homework3/.gitignore index 6078dfe..377db1e 100644 --- a/homework3/.gitignore +++ b/homework3/.gitignore @@ -1,7 +1,7 @@ */*~ *~ *.kdev4 build/ cmake-build-debug/ */cmake-build-debug/ -particle.txt +particles.txt diff --git a/homework3/TH_gen.py b/homework3/TH_gen.py index 329937e..9531efe 100644 --- a/homework3/TH_gen.py +++ b/homework3/TH_gen.py @@ -1,110 +1,110 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Thu Dec 13 10:53:07 2018 @author: alessia """ import numpy as np import math as m from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt from matplotlib import cm from matplotlib.ticker import LinearLocator, FormatStrFormatter #======================================================================================== #-------------------------------------- PURPOSE ----------------------------------------- #======================================================================================== # This program generates the initial conditions for Temperature and Heat-rate to # be used to solve the heat-equation with zero homogeneous boundary conditions. # The heat-rate is uniformly distributed within a given radius R and zero elsewhere # The Temperature can either have a zero homogeneous distribution or a Gaussian distrib. #--------------------------------------------------------------------------------------- -N2=100*100 #Number of particles (squared number) +N2=128*128 #Number of particles (squared number) R=0.3 #Radius L=1. #half-lenght of the domain C=1.0 #Constant val for the uniform distrib. of h TGauss=1 #Gaussian initial distr. for T N=int(m.sqrt(N2)) dx=2*L/N x, y = np.mgrid[-L:(L-dx):N*1j, -L:(L-dx):N*1j] xy = np.column_stack([x.flat, y.flat]) if(TGauss == 1): mu = np.array([0.0, 0.0]) sigma = np.array([.15, .15]) covariance = np.diag(sigma**2) T = multivariate_normal.pdf(xy, mean=mu, cov=covariance) #create the trivial initial condition for T else: T = (np.zeros(N2)) #homogeneous distr. for heat-rate within R h = np.zeros(N2) h = UniformR(R, N, L, C) #------------------- Write the output to file: N2 lines 12 columns ---------------------- # (x, y, z, vx, vy, vz, Fx, Fy, Fz, m, T, hrate) # (x, y, 0, 0, 0, 0, 0, 0, 0, 0, T, hrate) zer = np.zeros((N2,8)) z=np.column_stack((xy, zer,T.T,h.T)) col = len(z[i,:]) -out_file = open("particles.txt","w") +out_file = open("particles.csv","w") for i in range (0,N2): out_file.write('\n') for j in range(0,col): out_file.write('%.8f' % z[i,j] + '\t') out_file.close() #---------------------- Visualization of T and h distributions -------------------------- h = h.reshape(x.shape) T = T.reshape(x.shape) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') #surf=ax.plot_surface(x,y,h.T) surf=ax.plot_surface(x,y,T.T,alpha=1) plt.show() #======================================================================================= #---------------------------------------- END ------------------------------------------ #======================================================================================= def UniformR(R, N, L, C): H = np.zeros((N,N)) dx = 2*L/N #Loop over 1/4 of the domain for i in range(0, int(N/2)): x2 = (i*dx-L)**2 for j in range (0, int(N/2)): y2 = (L-j*dx)**2 if(x2+y2<=R): H[i,j] = H[i,N-j-1] = C H[N-i-1,j] = H[N-i-1,N-j-1] = C hh=np.reshape(H,(N*N)) return hh diff --git a/homework3/starting_point/.idea/workspace.xml b/homework3/starting_point/.idea/workspace.xml index 0565141..6d67e45 100644 --- a/homework3/starting_point/.idea/workspace.xml +++ b/homework3/starting_point/.idea/workspace.xml @@ -1,510 +1,469 @@ - + + + - + - + - - - - - - - - - - - - - - - - - - - - - - + - - - + - + - - - - - - - - - - - - - - - - - - - - - true DEFINITION_ORDER