示例#1
0
    Ions1 = [Ion(c_Na, DNa, zNa, '$Na^+$'),
             Ion(c_Cl, DCl, zCl, '$Cl^-$')]  # correct diffusion coefficients
    Ions2 = [Ion(c_Na, D, zNa, '$Na^+$'),
             Ion(c_Cl, D, zCl, '$Cl^-$')]  # same diffusion coefficient

    # make exact solution of diffusion equation
    c_exact_of_t = np.zeros((N_x, N_t))
    for i in range(1, N_t + 1):
        c_exact_of_t[:, i - 1] = c_0 + delta_c * np.exp(-i * delta_t / tau)

#	plt.plot(x*1000, c_exact_of_t[:,N_t-1], label = 'c_exact1')
#	plt.plot(Ions[1].c, label = 'Cl1')

#	plotIons(Ions, x, 'two_ions1')
    Phi_of_t1, c_of_t1 = solveEquation(Ions1, lambda_n, N_t, delta_t, N_x,
                                       delta_x)
    Phi_of_t2, c_of_t2 = solveEquation(Ions2, lambda_n, N_t, delta_t, N_x,
                                       delta_x)
    Phi_of_t1 = Phi_of_t1 * Psi * 1000
    Phi_of_t2 = Phi_of_t2 * Psi * 1000
    #	plotIons(Ions, x, 'two_ions2')

    #	plt.plot(x*1000, c_of_t1[:,N_t-1], label = 'Na')
    #	plt.plot(x*1000, Ions[1].c, label = 'Cl')
    #	plt.legend()
    #	plt.show()

    print(c_of_t2[:, N_t - 1] == Ions2[1].c)
    print(c_of_t1[:, N_t - 1] - Ions1[1].c)
    print(delta_t,
          np.amax(np.abs(c_of_t1[N_x // 2, :] - c_of_t2[N_x // 2, :])))
示例#2
0
                                      'Gratiy2017')

    # 3 Nicholson1987
    #	Gratiy2017 = ConcentrationProfile([0,5,10,15,20,25,30,35,40,45,50,60,70,75], [0,4.4,4.0,3.0,2.3, 1.7,1.3,1.,1.2,1.0, 0.8, 0.7,0.5, 0], delta_x, 150, 3, 'Nicholson1987')

    for i in [0, 1, 10, 20, 50, 150, 250]:  # set time constants here
        Ions = [
            Ion(Gratiy2017.c_Na, DNa, zNa, '$Na^+$'),
            Ion(Gratiy2017.c_K, DK, zK, '$K^+$'),
            Ion(Gratiy2017.c_Cl, DCl, zCl, '$Cl^-$')
        ]

        Phi_of_t, c_of_t = solveEquation(Ions,
                                         lambda_n,
                                         N_t,
                                         delta_t,
                                         Gratiy2017.N_x,
                                         delta_x,
                                         tau=i)
        Phi_of_t = Phi_of_t * Psi * 1000

        #		plotPhi(Phi_of_t, [N_t, delta_t, Gratiy2017.N_x, delta_x], 'tau')
        #	parameters = [N_t, delta_t, N_x, delta_x]

        el_sum = electroneutrality(
            Ions, Gratiy2017.N_x)  # true = 'true' if you want to plot
        assert np.amax(el_sum) < 1.e-13  # unit test

        f, psd, location = makePSD(Phi_of_t, N_t, delta_t)
        if i == 0:  # tau = 0 corresponds to the electrodiffusive model
            plt.plot(np.log10(f[1:-1]),
示例#3
0
	t,x = makeAkses(parameters)
# -----------------------------------------------------------------------------

# initialize ions
	Ions = [Ion(Profiles[choose_profile].c_Na,DNa,zNa,'$Na^+$'),Ion(Profiles[choose_profile].c_K, DK, zK,'$K^+$' ),Ion(Profiles[choose_profile].c_Cl, DCl, zCl,'$Cl^-$' )]

# check electroneutrality
	el_sum = electroneutrality(Ions, N_x) # plot = 'true' if you want to plot 
	assert np.amax(el_sum) < 1.e-14       # unit test

# plot initial ion concentration
	print(Profiles[choose_profile].c_values)
	plotIons(Ions, x, Profiles[choose_profile].name,  Profiles[choose_profile].c_values, Profiles[choose_profile].x_values/100)
	
# solve the equation
	Phi_of_t, c_of_t = solveEquation(Ions, lambda_n, N_t, delta_t, N_x, delta_x)

# Phi_of_t is dimensionless, needs to be multiplied with Psi = RT/F = 0.0267 V
# to get Phi_of_t in mV: *1000

	Phi_of_t = Phi_of_t*1000*Psi

# Check electroneutrality
	el_sum = electroneutrality(Ions, N_x, plot = 'true') # true = 'true' if you want to plot
	assert np.amax(el_sum) < 1.e-13       # unit test

# plot final ion concentration
#	plotIons(Ions, x, Profiles[choose_profile].name + '_final')

# save Phi(x,t) 
	np.save( Profiles[choose_profile].name + "_Phi_of_t.npy" , Phi_of_t)