<jupyter_start><jupyter_text>Tutorial 1: The Crystal objectIn this tutorial, we show how to prepare a crystal object and inspect some of it's properties.<jupyter_code>%load_ext autoreload
%autoreload 2
import numpy as np
import matplotlib.pyplot as plt

from custom_poling.core.crystal import Crystal<jupyter_output><empty_output><jupyter_text>Example 1: Unpoled poled crystal<jupyter_code># Create a crystal object

domain_width_1 = 1
number_domains_1 = 100

crystal_1 = Crystal(domain_width_1,number_domains_1,z0=0)
# Print some of the crystal's properties

print(f'Crystal length: {crystal_1.length}')
print(f'Domain wall positions: {crystal_1.domain_walls}')
print(f'Domain wall middles: {crystal_1.domain_middles}')
# Specify and plot the domain configuration

domain_config_1 = [1]*number_domains_1

crystal_1.plot_domains(domain_config_1).show()
# Compute and plot the phase-matching function (PMF) for an unpoled crystal

k_array_1 = np.arange(-5e-1,5e-1,1e-3)

crystal_1.compute_pmf(domain_config_1,k_array_1)
crystal_1.plot_pmf().show()<jupyter_output><empty_output><jupyter_text>Example 2: Periodically-poled crystal with KTP parameters<jupyter_code># Create a crystal object

domain_width_2 = 22.08095e-06
number_domains_2 = 1000

crystal_2 = Crystal(domain_width_2,number_domains_2,z0=0)

# Compute and plot the phase-matching function (PMF) for an unpoled crystal

k0=np.pi/domain_width_2

domain_config_2 = [1,-1]*int(number_domains_2/2)
crystal_2.plot_domains(domain_config_2,n_max=10)


k_array_2 = np.arange(k0-1e3,k0+1e3,1e1)
crystal_2.compute_pmf(domain_config_2,k_array_2)
crystal_2.plot_pmf().show()
# Print some of the crystal's properties

print(f'Crystal length: {crystal_2.length}')
print(f'Domain wall positions: {crystal_2.domain_walls}')
print(f'Domain wall middles: {crystal_2.domain_middles}')
from custom_poling.utils.sellmeier import Sellmeier
from custom_poling.utils.mat_func import mat_func
freqs1 = np.arange(1.32e15,1.37e15,.1e12)
freqs2 = np.arange(1.15e15,1.2e15,.1e12)
sel_y = Sellmeier(3.0065, 0.03901, 0.04547, 0.01408)
sel_z = Sellmeier(3.3134, 0.05694, 0.05658, 0.01692)

c=3e8
kp = lambda w: w * sel_y.n(2*np.pi*c*1e6/w)/c
ks = lambda w: w * sel_y.n(2*np.pi*c*1e6/w)/c
ki = lambda w: w * sel_z.n(2*np.pi*c*1e6/w)/c

delta_k_func = lambda w1,w2:kp(w1+w2)-ks(w1)-ki(w2)
delta_k_mat = np.array(mat_func(delta_k_func,freqs1,freqs2))

pmf_mat = crystal_2.compute_pmf(domain_config_2,delta_k_mat)

plt.matshow(np.abs(pmf_mat),origin='lower',extent=[freqs2[0],freqs2[-1],freqs1[0],freqs1[-1]]);
plt.colorbar()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12437234453456933, 'fraction_numerical': 0.07068366164542295, 'mean_word_length': 7.19620253164557, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '371217', 'license': 'Apache-2.0', 'n_tokens_mistral': 1191, 'n_tokens_neox': 1088, 'n_words': 191, 'path': '.ipynb_checkpoints/Tutorial 1b-checkpoint.ipynb', 'repo_name': 'abranczyk/custom-poling', 'size': '2589'}