import math
from scipy.special import erfinv
# Variables
D = 1.28*10**(-11); #diffusion coefficient of carbon in given steel in m2/s
c_s = 0.9; #Surface concentration of diffusion element in the surface
c_o = 0.2; #Initial uniform concentration of the element in the solid
c_x = 0.4; #Concentration of the diffusing element at a distance x from thesurface
x = 0.5*10**(-3); #depth from the surface in m
# Calculation
#(c_s-c_x)/(c_s-c_o) = erf(x/(2*(D*t)**(1/2)))
t = (x/(2*erfinv((c_s-c_x)/(c_s-c_o))*D**(1./2)))**2; #time required for carburization(in sec)
# Results
print 'time required for carburization in %.1f min'%(t/60)
import math
from scipy.special import erfinv
# Variables
D = 4*10**(-17); #diffusion coefficient of carbon in given steel in m2/s
c_s = 3*10**26; #Surface concentration of boron atoms in the surface
c_1 = 0; #Initial uniform concentration of the element in the solid
c_x = 10**23; #Concentration of the diffusing element at a distance x from thesurface
x = 2*10**(-6); #depth from the surface in m
# Calculation and Results
#(c_s-c_x)/(c_s-c_1) = erf(x/(2*(D*t)**(1/2)))
a = (erfinv((c_s-c_x)/(c_s-c_1)));
print ' C1 = ',a
t = (x**2/(D*4*(2.55)**2)); #time required to get a boron content of 1023 atoms per m3 at a depth of 2 micro meter
print 'time required to get a boron content of 1023 atoms per m3 at a depth of 2 micro meter is = %.0f sec'%t
import math
# Variables
t_1 = 736.; #Temperature in °C
t_2 = 782.; #Temperature in °C
T_1 = t_1+273; #Temperature in K
T_2 = t_2+273; #Temperature in K
D_1 = 2.*10**(-13); #Coefficient of diffusion at T_1 (in m2/s)
D_2 = 5.*10**(-13); #Coefficient of diffusion at T_2 (in m2/s)
k = 1.38*10**(-23); #in J/K
# Calculation and Results
#math.log(d_1) = math.log(d_o)-E/(k*T_1)
#math.log(d_2) = math.log(d_o)-E/(k*T_2)
E = (math.log(D_1)-math.log(D_2))/((1/(k*T_1))-(1/(k*T_2))); #
print 'activation energy = %.2e J'%-E
D_o = 2.*10**(-13)/math.exp(E/(k*T_1));
print 'constant of the equation = %.2e m2/s'%D_o
t_4 = 500.; #Temperature in °C
T_4 = t_4+273; #Temperature in °K
D_4 = D_o*math.exp(E/(k*T_4)); #diffusion coefficient at 500°C
print 'diffusion coefficient at 500°C = %.2e m2/s'%D_4
# rounding off error
import math
# Variables
D_500 = 4.8*10**(-14); #Diffusion coefficient for copper in aluminimum at 500*C(in m**2/s)
D_600 = 5.3*10**(-13); #Diffusion coefficient for copper in aluminimum at 600*C(in m**2/s)
t_600 = 10; #time of diffussion at 600*C(in Hours)
# Calculation
#D_500*t_500 = D_600*t_600
t_500 = D_600*t_600/D_500; #time of diffussion at 500*C
# Results
print 'Time at 500*C that will produce the same diffusion as in 600*C in %.1f Hours'%t_500