Skip to content

Commit

Permalink
Implementing gradient in different directions
Browse files Browse the repository at this point in the history
  • Loading branch information
anufrievroman committed May 11, 2023
1 parent 34f6b43 commit 81eb823
Show file tree
Hide file tree
Showing 22 changed files with 3,487 additions and 50 deletions.
1 change: 0 additions & 1 deletion examples/animated_corrugated_nanowire.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
OUTPUT_SCATTERING_MAP = False
OUTPUT_RAW_THERMAL_MAP = True
NUMBER_OF_LENGTH_SEGMENTS = 10
HOT_SIDE_ANGLE_DISTRIBUTION = 'random'


# Animation parameters:
Expand Down
74 changes: 74 additions & 0 deletions examples/anisotropy_study_horizontal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Config file to simulate a membrane with a staggered lattice of rectangular slits"""

import numpy as np


# General parameters:
OUTPUT_FOLDER_NAME = 'Anisotropy study horizontal'
NUMBER_OF_PHONONS = 1000
NUMBER_OF_TIMESTEPS = 30000
NUMBER_OF_NODES = 400
TIMESTEP = 1e-12
T = 4.0

# Map & profiles parameters:
NUMBER_OF_PIXELS_X = 100
NUMBER_OF_PIXELS_Y = 100
NUMBER_OF_TIMEFRAMES = 6

# Material parameters:
MEDIA = 'Si'
SPECIFIC_HEAT_CAPACITY = 0.0176 # [J/kg/K] for Si at 4 K


# System dimensions [m]:
THICKNESS = 150e-9
WIDTH = 1300e-9
LENGTH = 1300e-9

# STRUCTURE:

# ---->
#-------------------
#
# H C
#
#-------------------

INCLUDE_RIGHT_SIDEWALL = False
INCLUDE_LEFT_SIDEWALL = False
INCLUDE_TOP_SIDEWALL = True
INCLUDE_BOTTOM_SIDEWALL = True

# Hot and cold sides [m]:
COLD_SIDE_POSITION = 'right'
HOT_SIDE_POSITION = 'left'
HOT_SIDE_X = -WIDTH/2
HOT_SIDE_Y = LENGTH/2
HOT_SIDE_WIDTH_X = 0
HOT_SIDE_WIDTH_Y = LENGTH
HOT_SIDE_ANGLE_DISTRIBUTION = 'random_right'


# Hole array parameters [m]:
INCLUDE_HOLES = True
CIRCULAR_HOLE_DIAMETER = 0
RECTANGULAR_HOLE_SIDE_X = 200e-9
RECTANGULAR_HOLE_SIDE_Y = 100e-9
PERIOD_X = 300e-9
PERIOD_Y = 300e-9


# Staggered attice of holes:
FIRST_HOLE_COORDINATE = 200e-9
NUMBER_OF_PERIODS_X = 4
NUMBER_OF_PERIODS_Y = 4
HOLE_COORDINATES = np.zeros((NUMBER_OF_PERIODS_X * NUMBER_OF_PERIODS_Y, 3))
HOLE_SHAPES = ['rectangle' for x in range(HOLE_COORDINATES.shape[0])]
hole_number = 0
for i in range(NUMBER_OF_PERIODS_Y):
for j in range(NUMBER_OF_PERIODS_X):
HOLE_COORDINATES[hole_number, 0] = -(NUMBER_OF_PERIODS_X - 1) * PERIOD_X / 2 + j * PERIOD_X
HOLE_COORDINATES[hole_number, 1] = FIRST_HOLE_COORDINATE + i * PERIOD_Y
HOLE_COORDINATES[hole_number, 2] = 0
hole_number += 1
74 changes: 74 additions & 0 deletions examples/anisotropy_study_vertical.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""Config file to simulate a membrane with a staggered lattice of rectangular slits
Here we impose thermal gradient in vertical direction"""

import numpy as np


# General parameters:
OUTPUT_FOLDER_NAME = 'Anisotropy study vertical'
NUMBER_OF_PHONONS = 1000
NUMBER_OF_TIMESTEPS = 30000
NUMBER_OF_NODES = 400
TIMESTEP = 1e-12
T = 4.0

# Map & profiles parameters:
NUMBER_OF_PIXELS_X = 100
NUMBER_OF_PIXELS_Y = 100
NUMBER_OF_TIMEFRAMES = 6

# Material parameters:
MEDIA = 'Si'
SPECIFIC_HEAT_CAPACITY = 0.0176 # [J/kg/K] for Si at 4 K


# System dimensions [m]:
THICKNESS = 150e-9
WIDTH = 1300e-9
LENGTH = 1300e-9

# STRUCTURE:

# | C |
# | | ^
# | | |
# | | |
# | H |

INCLUDE_RIGHT_SIDEWALL = True
INCLUDE_LEFT_SIDEWALL = True
INCLUDE_TOP_SIDEWALL = False
INCLUDE_BOTTOM_SIDEWALL = False

# Hot and cold sides [m]:
COLD_SIDE_POSITION = 'top'
HOT_SIDE_POSITION = 'bottom'
HOT_SIDE_X = 0
HOT_SIDE_Y = 0
HOT_SIDE_WIDTH_X = WIDTH
HOT_SIDE_WIDTH_Y = 0
HOT_SIDE_ANGLE_DISTRIBUTION = 'random_up'

# Hole array parameters [m]:
INCLUDE_HOLES = True
CIRCULAR_HOLE_DIAMETER = 0
RECTANGULAR_HOLE_SIDE_X = 200e-9
RECTANGULAR_HOLE_SIDE_Y = 100e-9
PERIOD_X = 300e-9
PERIOD_Y = 300e-9


# Staggered attice of holes:
FIRST_HOLE_COORDINATE = 200e-9
NUMBER_OF_PERIODS_X = 4
NUMBER_OF_PERIODS_Y = 4
HOLE_COORDINATES = np.zeros((NUMBER_OF_PERIODS_X * NUMBER_OF_PERIODS_Y, 3))
HOLE_SHAPES = ['rectangle' for x in range(HOLE_COORDINATES.shape[0])]
hole_number = 0
for i in range(NUMBER_OF_PERIODS_Y):
for j in range(NUMBER_OF_PERIODS_X):
HOLE_COORDINATES[hole_number, 0] = -(NUMBER_OF_PERIODS_X - 1) * PERIOD_X / 2 + j * PERIOD_X
HOLE_COORDINATES[hole_number, 1] = FIRST_HOLE_COORDINATE + i * PERIOD_Y
HOLE_COORDINATES[hole_number, 2] = 0
hole_number += 1

1 change: 0 additions & 1 deletion examples/fishbone_nanowire.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
OUTPUT_RAW_THERMAL_MAP = True
OUTPUT_TRAJECTORIES_OF_FIRST = 30
NUMBER_OF_LENGTH_SEGMENTS = 10
HOT_SIDE_ANGLE_DISTRIBUTION = 'random'


# Map & profiles parameters:
Expand Down
2 changes: 1 addition & 1 deletion examples/parabolic_lens_focusing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
OUTPUT_RAW_THERMAL_MAP = True
OUTPUT_TRAJECTORIES_OF_FIRST = 30
NUMBER_OF_LENGTH_SEGMENTS = 10
HOT_SIDE_ANGLE_DISTRIBUTION = 'directional'


# Map & profiles parameters:
Expand Down Expand Up @@ -43,6 +42,7 @@
COLD_SIDE_POSITION = 'top'
HOT_SIDE_X = 0.0
HOT_SIDE_WIDTH_X = WIDTH
HOT_SIDE_ANGLE_DISTRIBUTION = 'directional'

# Roughness [m]:
SIDE_WALL_ROUGHNESS = 2e-9
Expand Down
1 change: 0 additions & 1 deletion examples/phononic_crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
OUTPUT_RAW_THERMAL_MAP = True
OUTPUT_TRAJECTORIES_OF_FIRST = 30
NUMBER_OF_LENGTH_SEGMENTS = 10
HOT_SIDE_ANGLE_DISTRIBUTION = 'random'


# Map & profiles parameters:
Expand Down
1 change: 0 additions & 1 deletion examples/simple_nanowire.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
OUTPUT_RAW_THERMAL_MAP = True
OUTPUT_TRAJECTORIES_OF_FIRST = 30
NUMBER_OF_LENGTH_SEGMENTS = 10
HOT_SIDE_ANGLE_DISTRIBUTION = 'random'


# Map & profiles parameters:
Expand Down
1 change: 0 additions & 1 deletion examples/slits_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
OUTPUT_RAW_THERMAL_MAP = True
OUTPUT_TRAJECTORIES_OF_FIRST = 30
NUMBER_OF_LENGTH_SEGMENTS = 10
HOT_SIDE_ANGLE_DISTRIBUTION = 'random'


# Map & profiles parameters:
Expand Down
1 change: 0 additions & 1 deletion examples/triangles_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
OUTPUT_RAW_THERMAL_MAP = True
OUTPUT_TRAJECTORIES_OF_FIRST = 30
NUMBER_OF_LENGTH_SEGMENTS = 10
HOT_SIDE_ANGLE_DISTRIBUTION = 'random'


# Map & profiles parameters:
Expand Down
4 changes: 2 additions & 2 deletions freepaths/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import freepaths.main_tracing
import freepaths.main_mfp_sampling

__version__ = "1.2.2"
__version__ = "1.3"

# Parse user arguments:
parser = argparse.ArgumentParser(
prog = 'FreePATHS',
description = 'Monte Carlo simulator',
epilog = 'For more information, visit: https://github.com/anufrievroman/freepaths'
epilog = 'For more information, visit: https://anufrievroman.gitbook.io/freepaths'
)
parser.add_argument('input_file', nargs='?', default=None, help='The input file')
parser.add_argument("-s", "--sampling", help="Run in MFP sampling mode", action="store_true")
Expand Down
9 changes: 9 additions & 0 deletions freepaths/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,18 @@ def generate_animation_xy():
filenames = os.listdir("Frames/")
for filename in filenames:
images.append(imageio.imread(f"Frames/{filename}"))

# Create a GIF file:
imageio.mimsave("Animated paths XY.gif", images,
fps=cf.output_animation_fps, subrectangles=True)

# Create an MP4 file:
# writer = imageio.get_writer('Animated paths XY.mp4', fps=cf.output_animation_fps)

# for im in images:
# writer.append_data(imageio.imread(im))
# writer.close()


def delete_frames():
"""Delete frames after creating the animation"""
Expand Down
97 changes: 97 additions & 0 deletions freepaths/animation__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
"""Module that creates animations from recorded phonon paths"""

import sys
import os
import shutil
import imageio
import numpy as np
import matplotlib.pyplot as plt

from freepaths.config import cf
from freepaths.output_structure import draw_structure


def generate_frames_xy():
"""Generate animation frames with phonon paths"""

data = np.genfromtxt("Data/Phonon paths.csv",
unpack=False,
delimiter=',',
skip_header=1,
encoding='utf-8')

# Create XY plots for each timestep where all phonon shown at the same time:
number_of_steps = np.shape(data)[0]
number_of_phonons = np.shape(data)[1]//3

for step in range(1, number_of_steps):
fig, ax = plt.subplots()

# Draw the structure:
patches = draw_structure(cf)
for patch in patches:
ax.add_patch(patch)

# Draw the paths:
for phonon_num in range(number_of_phonons):
x_coords = np.trim_zeros(data[:, 3 * phonon_num], trim='b')
y_coords = np.trim_zeros(data[:, 3 * phonon_num + 1], trim='b')
ax.plot(x_coords[:step], y_coords[:step], linewidth=0.5)

# Plot settings:
ax.set_xlim([-0.55*cf.width*1e6, 0.55*cf.width*1e6])
ax.set_ylim([0, cf.length*1e6])
ax.set_aspect('equal')
ax.axis('off')
for spine in ['top', 'right', 'left', 'bottom']:
ax.spines[spine].set_visible(False)
fig.savefig(f"Frames/frame_{step:0>6}.png", dpi=600, bbox_inches="tight")
plt.close(fig)

# Progress:
sys.stdout.write(f"\rAnimation: {step}/{number_of_steps - 1} frames")

# Create XY plots for each step for each phonon one by one:
# cmap = plt.get_cmap("tab10")
# frame_number = 0
# number_of_phonons = np.shape(data)[1]//3
# for phonon_num in range(number_of_phonons):
# x_coords = np.trim_zeros(data[:, 3 * phonon_num], trim='b')
# y_coords = np.trim_zeros(data[:, 3 * phonon_num + 1], trim='b')
# steps = np.shape(x_coords)[0]
# for step in range(1, steps):
# fig, ax = plt.subplots()
# ax.plot(x_coords[:step], y_coords[:step], color=cmap(phonon_num), linewidth=0.5)
# ax.axis('off')
# for spine in ['top', 'right', 'left', 'bottom']:
# ax.spines[spine].set_visible(False)
# ax.set_xlim([-0.55*cf.width*1e6, 0.55*cf.width*1e6])
# ax.set_ylim([0, cf.length*1e6])
# ax.set_aspect('equal')
# fig.savefig(f"Frames/frame_{frame_number:0>6}.png", dpi=600, bbox_inches="tight")
# plt.close(fig)
# frame_number += 1


def generate_animation_xy():
"""Generate animation of phonon path in XY plane"""
sys.stdout.write(f"\rAnimation: creating animation file")
images = []
filenames = os.listdir("Frames/")
for filename in filenames:
images.append(imageio.imread(f"Frames/{filename}"))
imageio.mimsave("Animated paths XY.gif", images,
fps=cf.output_animation_fps, subrectangles=True)


def delete_frames():
"""Delete frames after creating the animation"""
folder_path = "Frames/"
shutil.rmtree(folder_path)


def create_animation():
"""Main function that creates the animation"""
generate_frames_xy()
generate_animation_xy()
delete_frames()
Loading

0 comments on commit 81eb823

Please sign in to comment.