<jupyter_start><jupyter_text>Compute Profile<jupyter_code># Declare the dictionaries s and d
s = Struct()
d = Struct()
s.something = 1

# find profile solution
s.sol, p.delta = ks_profile(s,p)
d.s = s # record parameters in data structure d
d.p = p # record parameters in data structure d
# Plot the profile solution
plt.plot(s.sol.y[0])
plt.plot(s.sol.y[1])
plt.plot(s.sol.y[2])
plt.show()<jupyter_output><empty_output><jupyter_text>Evans function computations<jupyter_code># Find the L infinity norm of the profile u and u'
x = np.linspace(0,p.X,1000)
temp = s.sol.sol(x)
Linf_bar_u = max(np.abs(temp[0,:]))
Linf_bar_u_prime = max(np.abs(temp[1,:]))
# record the L infinity norms in the data structure
d.Linf_bar_u = Linf_bar_u
d.Linf_bar_u_prime = Linf_bar_u_prime
# STABLAB structuress
s.X = p.X
# s,e,m,c = emcset(s,'periodic',[2,2],'balanced_polar_periodic',A)
s,e,m,c = emcset(s,'periodic',[2,2],'balanced_polar_scaled_periodic',A)
# s,e,m,c = emcset(s,'periodic',[2,2],'regular_periodic',A)
c.ksteps = 100000
c.refine = 'on'
c.stats = 'print'
m['options']['nsteps'] = 500 # max steps between each iteration of the ODE solver
# Determine the HF bound and record it.
R = 0.5*(Linf_bar_u_prime+Linf_bar_u**2+p.delta**2+0.5*(1+2*p.epsilon**2)**2)
R1 = max(R+0.1,2)
R2 = 1
d.R = R
d.R1 = R1
d.R2 = R2
kappa = np.linspace(-np.pi/p.X,np.pi/p.X,1000);
circpnts = 10; imagpnts = 10; innerpnts = 5; spread = 4;
# circpnts=50; imagpnts=50; innerpnts=20; spread=4;
preimage = semicirc2(circpnts,imagpnts,innerpnts,c.ksteps,R1,spread,R2)
preimage = np.concatenate((preimage[0:-1], np.flipud(np.conj(preimage))))<jupyter_output><empty_output><jupyter_text>Compute the Evans function for HF study<jupyter_code>startTime = time.time()
D, preimage2 = periodic_contour(kappa,preimage,c,s,p,m,e)
totTime = time.time() - startTime
# HF study output and statistics
d.D1 = Struct()
d.D1.time = totTime
d.D1.points = len(preimage2)
d.D1.D = D
d.D1.preimage2 = preimage2
# Determine the maximum winding number for different values of kappa
max_wnd = 0
for j in np.arange(1,len(kappa)):
    max_wnd = max(max_wnd,winding_number(D[j-1,:]))
d.D1.max_wnd = max_wnd<jupyter_output><empty_output><jupyter_text>Compute the Taylor Coefficients and find eigenvalue expansion coefficients<jupyter_code>p,s,d,st = ks_taylor(s,p,m,c,e,d)
# Find the maximum value of lambda(k), |k|=R_remainder
c.ksteps = 10000
c.tol = 0.2
c.refine = 'on'
e.evans = 'balanced_polar_periodic'

R_remainder = 0.5
kappa = R_remainder*np.exp(1j*np.linspace(-np.pi,np.pi,1000))

points = 100
R_lambda = 2
preimage = R_lambda*np.exp(1j*
                np.linspace(0,2*np.pi,points+(points-1)*c.ksteps))
print('\nFinding the maximum value of lambda')
# Find max lambda(k) on ball of radius R_remainder
s_time = time.time()
D,preimage2 = periodic_contour(kappa,preimage,c,s,p,m,e)
currTime = (time.time()-s_time)
max_rt = 0
for j in np.arange(1,len(kappa)):
    if winding_number(D[j-1,:]) > 1:
        rts = moments_roots(preimage2,D[j-1,:])
        max_rt = max(max_rt,max(np.abs(rts)))
    else:
        raise ValueError('Contour radius not big enough')
beta1 = d.beta1
beta2 = d.beta2
alpha1 = d.alpha1
alpha2 = d.alpha2
# determine r satisfying the requirements
r1 = -np.real(beta1)*R_remainder**3/(max_rt-R_remainder**2*np.real(beta1))
r2 = -np.real(beta2)*R_remainder**3/(max_rt-R_remainder**2*np.real(beta2))
r3 = -R_remainder**3*np.real(beta1)/(16*max_rt)
r4 = -R_remainder**3*np.real(beta2)/(16*max_rt)
r5 = -np.real(beta1)*R_remainder**3/(R_lambda-R_remainder**2*np.real(beta1))
r6 = -np.real(beta2)*R_remainder**3/(R_lambda-R_remainder**2*np.real(beta2))
r7 = -R_remainder**3*np.real(beta1)/(16*R_lambda)
r8 = -R_remainder**3*np.real(beta2)/(16*R_lambda)
r_remainder = min([r1,r2,r3,r4,r5,r6,r7,r8])
# Raise errors if invalid values are encountered
if r_remainder > 0.5*R_remainder:
    raise ValueError('r bigger than R/2')
if abs(np.imag(alpha1))*r_remainder+np.sqrt(2)*np.abs(beta1)*r_remainder**2 > R2:
    raise ValueError('imaginary part too big')
if abs(np.imag(alpha2))*r_remainder+np.sqrt(2)*np.abs(beta2)*r_remainder**2 > R2:
    raise ValueError('imaginary part too big')
else:
    d.test = ( abs(np.imag(alpha2)) * r_remainder + np.sqrt(2) * np.abs(beta2)
                * r_remainder**2 )
d.max_rt = max_rt
d.lambda_points = len(preimage2)
d.R_remainder = R_remainder
d.r_remainder = r_remainder<jupyter_output><empty_output><jupyter_text>Compute the Evans fucntion on semicircular contour of radius 2R2 for r<|k|<pi/X.<jupyter_code>e.evans = 'balanced_polar_scaled_periodic'
c.ksteps = 10000
c.tol = 0.2
c.refine = 'on'
kappa = np.concatenate([np.linspace(-np.pi/p.X,-r_remainder,500),
                        np.linspace(r_remainder,np.pi/p.X,500)])
circpnts = 20; imagpnts = 20; spread = 4; inner_gap = 10**(-6);
preimage = semicirc(circpnts,imagpnts,c.ksteps,2*R2,spread,inner_gap)
preimage = np.concatenate((preimage[0:-1], np.flipud(np.conj(preimage))))
# Compute the evans function
s_time = time.time()
D,preimage2 = periodic_contour(kappa,preimage,c,s,p,m,e)
currTime = (time.time()-s_time)
# Find the maximum winding number for different values of kappa
max_wnd = 0
for j in np.arange(1,len(kappa)):
    max_wnd = max(max_wnd,winding_number(D[j-1,:]))
# record Evans function output in data structure
d.D2 = Struct()
d.D2.max_wnd = max_wnd
d.D2.points = len(preimage2)
d.D2.preimage2 = preimage2
d.D2.D = D
d.D2.time = currTime<jupyter_output><empty_output><jupyter_text>Compute Evans function for semi-circle shifted left and for |k|<r<jupyter_code>e.evans = 'balanced_polar_periodic'
c.ksteps = 10000
c.tol = 0.2
c.refine = 'on'
kappa = np.linspace(-r_remainder,r_remainder,1000)
shift = 2*max(abs(np.real(beta1)),abs(np.real(beta2)))*r_remainder**2
circpnts = 20; imagpnts = 20; spread = 4; inner_gap = 10**(-6);
preimage = semicirc(circpnts,imagpnts,c.ksteps,2*R2,spread,inner_gap)
preimage = np.concatenate((preimage[0:-1], np.flipud(np.conj(preimage))))
preimage = preimage - shift #np.full(np.shape(preimage), shift)
# compute Evans function
s_time = time.time()
D, preimage2 = periodic_contour(kappa,preimage,c,s,p,m,e)
currTime = time.time() - s_time
# verify the winding number is 2
for j in np.arange(1,len(kappa)):
    if not (winding_number(D[j-1,:]) == 2):
        # raise ValueError('winding number not two')
        print('\n\nWARNING: Winding number is: ',winding_number(D[j-1,:]), '\n\n')

# record Evans function output in data structure
d.shift = shift
d.D3 = Struct()
d.D3.preimage2 = preimage2
d.D3.D = D
d.D3.points = len(preimage2)
d.D3.time = currTime<jupyter_output><empty_output><jupyter_text>Compare the results of all 3 Evans function computations<jupyter_code># You can check out whatever you want here from the structures that we saved
# Look at times
print("Comp. 1:", round(d.D1.time), 's')
print("Comp. 2:", round(d.D2.time), 's')
print("Comp. 3:", round(d.D3.time), 's')
# Plot the image of the Evans function for the first kappa
plt.plot(d.D1.D[:,0].real, d.D1.D[:,0].imag)
# Plot the image of the Evans function for the first kappa
plt.plot(d.D2.D[:,0].real, d.D2.D[:,0].imag)
# Plot the image of the Evans function for all kappas
plt.plot(d.D3.D.real, d.D3.D.imag)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16163016357083448, 'fraction_numerical': 0.03909065705572498, 'mean_word_length': 5.312335958005249, 'pattern_counts': {'":': 0, '<': 32, '<?xml version=': 0, '>': 33, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '527465', 'license': 'MIT', 'n_tokens_mistral': 3199, 'n_tokens_neox': 3035, 'n_words': 592, 'path': 'example_systems/KS/KS.ipynb', 'repo_name': 'nonlinear-waves/stablab_python', 'size': '7214'}