diff --git a/exercice_3/src/generate_heat_distribution.py b/exercice_3/src/generate_heat_distribution.py new file mode 100644 index 0000000..a9a5c8a --- /dev/null +++ b/exercice_3/src/generate_heat_distribution.py @@ -0,0 +1,41 @@ +##!/usr/bin/env python3 +## -*- coding: utf-8 -*- +#""" +#Created on Mon Dec 10 09:57:09 2018 +# +#@author: masc +#""" +import numpy as np +import argparse +import math +import matplotlib.pyplot as plt + +parser = argparse.ArgumentParser() +parser.add_argument("number", help="total number of particles", type=int) +parser.add_argument("radius_heat_source", help="radius of the heat source") +parser.add_argument("filename", help="name of generated input file") +args = parser.parse_args() + +nb_part = args.number +size = int(math.sqrt(nb_part)) +radius = float(args.radius_heat_source) + + +domain = [[-1, 1], [-1, 1]] +heat_distribution = np.zeros((size, size)) +for i in range(1, size+1): + for j in range(0, size+1): + x = domain[0][0] + (domain[0][1] - domain[0][0]) / (size+1) * i + y = domain[1][0] + (domain[1][1] - domain[1][0]) / (size+1) * j + if ( (x**2 + y**2) < radius ): + heat_distribution[i, j] = 1 + +fig = plt.figure() +plt.imshow(heat_distribution) +fig.suptitle('Heat distribution ') +plt.show() + +np.savetxt(args.filename, heat_distribution, delimiter=" ") + + +