<jupyter_start><jupyter_text>Mesh convergence of protein sensor (sphere) with protein at 1 nm of distance in the `z` direction.<jupyter_code>import numpy
from matplotlib import pyplot, rcParams
%matplotlib inline
num_elements = numpy.array([512, 2048, 8192, 32768])
C_ext= numpy.array([8803.26457, 7287.06185, 6923.79145, 6831.05972])

c1 = [14.97378, 11.56435, 10.78605, 10.59058]
it = [146, 141, 127, 136]
times = [8045.2, 8506.3, 7555.5, 9759.6 ]
ord_conv = numpy.log((C_ext[1] - C_ext[2])/(C_ext[2] -C_ext[3]))/numpy.log(4)
print(ord_conv)
def richardson_extrapolation(array):
    """
    Performs an estimate of the exact solution using
    Richardson extrapolation, given by

    f_ex = (f_1 * f_3 - f_2^2) / (f_3 - 2*f_2+f_1)

    where f_1 is a result from the finest grid and f_3 is from the coarsest.
    The grids f_1, f_2, f_3 should have the same refinement ratio (e.g. 4 -> 8 -> 16)

    Arguments:
    ----------
    array: contains C_ext

    Returns:
    --------
    f_ex : float, richardson_extrapolation estimated exact solution.  
    """
    
    f1 = array[3] 
    f2 = array[2]
    f3 = array[1]

    f_ex = (f1 * f3 - f2**2) / (f3 - 2 * f2 + f1)

    return f_ex 

rich_ext = richardson_extrapolation(C_ext)
print(rich_ext)
rel_error = abs((C_ext - rich_ext)/rich_ext)
print('percentage error', rel_error*100)
def plot_sph_complex_convergence(N, error):
    pyplot.figure(figsize=(8,5))

    rcParams['font.family'] = 'serif'
    rcParams['font.size'] = 16
    rcParams['xtick.top'] = True
    rcParams['ytick.right'] = True
    rcParams['axes.linewidth'] = 2

    asymp = N[-2]*error[-2]/N

    pyplot.loglog(N, error, ls='',marker='o', c='k', mew=1.5, mfc='w', ms=10, label='sphere_sensor')
    pyplot.loglog(N, asymp, c='k', marker='None', ls=':', lw=2, label=None)

    loc = (3*N[-2]+N[-1])/4

    tex_loc = numpy.array((loc,N[-2]*error[-2]/loc))
    
    pyplot.text(tex_loc[0], tex_loc[1],'N$^{-1}$', fontsize=12,
                rotation=-35,rotation_mode='anchor')

    pyplot.xlabel('N')
    pyplot.ylabel('Relative error')
    pyplot.tick_params(axis='both', length=10, width=1, which='major', direction='in')
    pyplot.tick_params(axis='both', length=5, width=1, which='minor', direction='in')
    #pyplot.ylim(1e-4,1)
    #pyplot.xlim(1e2,1e5)
    pyplot.legend(loc='best')
    pyplot.grid(True, which="both")
plot_sph_complex_convergence(num_elements, rel_error)<jupyter_output><empty_output><jupyter_text>Params used for convergence analysis: ```Precision   doubleK           4Nk          9  K_fine      37thresold    0.5BSZ         128restart     100tolerance   1e-5max_iter    1000P           15eps         1e-12NCRIT       500theta       0.5   GPU         1```  Relaxation of parameters: ```k_fine = 19P = 6```<jupyter_code>C_ext_relax = 6756.10550
rel_error_relax = abs((C_ext_relax - rich_ext)/rich_ext)
print('percentage error', rel_error_relax*100)
time_Cext_relax = 1741.98 #sec (29 min)<jupyter_output><empty_output><jupyter_text>relaxation + using density 1 on protein mesh<jupyter_code>C_ext_rel_d1 = 6756.24798

rel_error_rel_d1 = abs((C_ext_rel_d1 - rich_ext)/rich_ext)
print('percentage error', rel_error_rel_d1*100)

time_Cext_relax = 660.05 #sec (11 min)<jupyter_output>percentage error 0.632808155001<jupyter_text>relaxation + using density 1 on protein mesh and tol 1e-4 (original is with 1e-5)<jupyter_code>C_ext_d1_tol4 = 6756.24953

rel_error_d1_tol4 = abs((C_ext_d1_tol4 - rich_ext)/rich_ext)
print('percentage error', rel_error_d1_tol4*100)

time_Cext_d1_tol4 = 583.2 #sec (9.7 min)<jupyter_output>percentage error 0.632785358451<jupyter_text>tol 1e-3<jupyter_code>C_ext_d1_tol3 = 6755.85061

rel_error_d1_tol3 = abs((C_ext_d1_tol3 - rich_ext)/rich_ext)
print('percentage error', rel_error_d1_tol3*100)

time_Cext_d1_tol4 = 438.2 #sec (7.3 min)<jupyter_output>percentage error 0.638652455142
{'fraction_non_alphanumeric': 0.14345006485084305, 'fraction_numerical': 0.09546044098573281, 'mean_word_length': 4.053735255570118, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 20, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '106485', 'license': 'CC-BY-3.0', 'n_tokens_mistral': 1772, 'n_tokens_neox': 1539, 'n_words': 301, 'path': 'analysis_notebooks/BSA_sensor_convergence_analysis.ipynb', 'repo_name': 'barbagroup/pygbe_lspr', 'size': '3855'}