Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 6 13:17:28 2022
@author: stefan
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import codecs
import re
import json
def energy(kappa,alpha,Q,B) :
G=kappa*np.array([[np.cos(alpha)**2],[np.sin(alpha)**2],[np.sqrt(2)*np.cos(alpha)*np.sin(alpha)]])-B
return np.matmul(np.transpose(G),np.matmul(Q,G))[0,0]
def xytokappaalpha(x,y):
if y>0:
return [np.sqrt(x**2+y**2), np.abs(np.arctan2(y,x))]
else:
return [-np.sqrt(x**2+y**2), np.abs(np.arctan2(y,x))]
# Read effective quantites
def ReadEffectiveQuantities(QFilePath, BFilePath):
# Read Output Matrices (effective quantities)
# From Cell-Problem output Files : ../outputs/Qmatrix.txt , ../outputs/Bmatrix.txt
# -- Read Matrix Qhom
X = []
# with codecs.open(path + '/outputs/QMatrix.txt', encoding='utf-8-sig') as f:
with codecs.open(QFilePath, encoding='utf-8-sig') as f:
for line in f:
s = line.split()
X.append([float(s[i]) for i in range(len(s))])
Q = np.array([[X[0][2], X[1][2], X[2][2]],
[X[3][2], X[4][2], X[5][2]],
[X[6][2], X[7][2], X[8][2]] ])
# -- Read Beff (as Vector)
X = []
# with codecs.open(path + '/outputs/BMatrix.txt', encoding='utf-8-sig') as f:
with codecs.open(BFilePath, encoding='utf-8-sig') as f:
for line in f:
s = line.split()
X.append([float(s[i]) for i in range(len(s))])
B = np.array([X[0][2], X[1][2], X[2][2]])
return Q, B
# Number of experiments / folders
number=7
show_plot = False
#--- Choose wether to perforate upper (passive) or lower (active) layer
perforatedLayer = 'upper'
# perforatedLayer = 'lower'
dataset_numbers = [0, 1, 2, 3, 4, 5]
# dataset_numbers = [0]
for dataset_number in dataset_numbers:
kappa=np.zeros(number)
for n in range(0,number):
# Read from Date
print(str(n))
DataPath = './experiment/perforated-bilayer_square/results_' + perforatedLayer + '_' + str(dataset_number) + '/' +str(n)
QFilePath = DataPath + '/QMatrix.txt'
BFilePath = DataPath + '/BMatrix.txt'
ParameterPath = DataPath + '/parameter.txt'
# Read Thickness from parameter file (needed for energy scaling)
with open(ParameterPath , 'r') as file:
parameterFile = file.read()
thickness = float(re.findall(r'(?m)h = (\d?\d?\d?\.?\d+[Ee]?[+\-]?\d?\d?)',parameterFile)[0])
Q, B = ReadEffectiveQuantities(QFilePath,BFilePath)
# Q=0.5*(np.transpose(Q)+Q) # symmetrize
B=np.transpose([B])
#
N=500
length=5
r, theta = np.meshgrid(np.linspace(0,length,N),np.radians(np.linspace(0, 360, N)))
E=np.zeros(np.shape(r))
for i in range(0,N):
for j in range(0,N):
if theta[i,j]<np.pi:
E[i,j]=energy(r[i,j],theta[i,j],Q,B) * (thickness**2)
else:
E[i,j]=energy(-r[i,j],theta[i,j],Q,B) * (thickness**2)
# Compute Minimizer
[imin,jmin]=np.unravel_index(E.argmin(),(N,N))
kappamin=r[imin,jmin]
alphamin=theta[imin,jmin]
kappa[n]=kappamin
fig, ax = plt.subplots(figsize=(6,6),subplot_kw=dict(projection='polar'))
levs=np.geomspace(E.min(),E.max(),400)
pcm=ax.contourf(theta, r, E, levs, norm=colors.PowerNorm(gamma=0.2), cmap='brg')
ax.set_xticks([0,np.pi/2])
ax.set_yticks([kappamin])
colorbarticks=np.linspace(E.min(),E.max(),6)
cbar = plt.colorbar(pcm, extend='max', ticks=colorbarticks, pad=0.1)
cbar.ax.tick_params(labelsize=6)
if (show_plot):
plt.show()
# Save Figure as .pdf
width = 5.79
height = width / 1.618 # The golden ratio.
fig.set_size_inches(width, height)
fig.savefig('PerforatedBilayer_dataset_' +str(dataset_number) + '_exp' +str(n) + '.pdf')
f = open("./experiment/perforated-bilayer_square/results_" + perforatedLayer + '_' + str(dataset_number) + "/kappa_simulation.txt", "w")
f.write(str(kappa.tolist())[1:-1])
f.close()