%Load file-plot ebsd
f=fullfile('C:\Users\zgrey\Desktop\Mtex','Ti64.ctf');
ebsd = loadEBSD(f,'convertEuler2SpatialReferenceFrame');
plotx2east %% it turn the map rectangle 90degree
plot(ebsd)
ea=ebsd('Alpha-Ti64');%% define phases individually otherwise it gives phase list error
eb=ebsd('beta');
% define the color key
ipfKey = ipfHSVKey(ea);
ipfKey.inversePoleFigureDirection = zvector; %%% Produce IPFX IPFY IPFZ with changing xvector etc.
% and plot the orientation data
plot(ea,ipfKey.orientation2color(ea.orientations),'micronBar','off','figSize','medium')
%Remove all grains with less then 5 pixels and smooth the grain boundaries
% reconstruct grains
[grains,ea.grainId] = calcGrains(ea,'angle',5*degree);
% remove small grains
ea(grains(grains.grainSize<=5)) = [];
% redo grain reconstruction
[grains,ea.grainId] = calcGrains(ea,'angle',2.5*degree);
% smooth grain boundaries
grains = smooth(grains,5);
hold on
plot(grains.boundary,'linewidth',0.1)
hold off
%Data cleaning
% a key the colorizes according to misorientation angle and axis
ipfKey = axisAngleColorKey(ea);
% set the grain mean orientations as reference orinetations
ipfKey.oriRef = grains(ea('indexed').grainId).meanOrientation;
% plot the data
plot(ea,ipfKey.orientation2color(ea('indexed').orientations),'micronBar','off','figSize','medium')
hold on
plot(grains.boundary,'linewidth',0.1)
hold off
%Denoise Data-SMOOTH the orientation data (It takes a while to run it)
F = halfQuadraticFilter;
F.threshold = 1.5*degree;
F.eps = 1e-2;
F.alpha = 0.01;
ebsd = smooth(ea('indexed'),F,'fill',grains);
% plot the denoised data
figure(2)
ipfKey.oriRef = grains(ebsd('indexed').grainId).meanOrientation
plot(ebsd('indexed'),ipfKey.orientation2color(ebsd('indexed').orientations),'micronBar','off','figSize','medium')
hold on
plot(grains.boundary,'linewidth',0.1)
hold off
%The incomplete curvature tensor-consider only the Ti64(alpha) phase
ebsd = ebsd('indexed').gridify
% compute the curvature tensor
kappa = ebsd.curvature
% one can index the curvature tensors in the same way as the EBSD data.
% E.g. the curvature in pixel (2,3) is
kappa(2,3)
%%%We can access the different components of the curvature tensor with
kappa12 = kappa{1,2};
size(kappa12)
%Visualize the different components of the curvature tensor
mtexFig = newMtexFigure('nrows',3,'ncols',3,'figSize','huge');
plot(ebsd,kappa{1,1},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{1,2},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{1,3},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{2,1},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{2,2},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{2,3},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{3,1},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{3,2},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{3,3},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
% unify the color rage - you may also use setColoRange equal
setColorRange([-0.005,0.005])
drawNow(gcm,'figSize','large')
%DISLOCATION SYSTEM
CS = crystalSymmetry('6/mmm',[2.920,2.920,4.670],'x||a','mineral','Alpha-Ti64', 'color', 'pink')
b=Miller(2,-1,-1,0,CS,'uvtw')
n=Miller(0,1,-1,0,CS,'hkil')
l=Miller(-2,-1,3,0,CS,'uvtw')
sSBasal= slipSystem(b,n)
sSBasal = slipSystem.basal(CS)
sSBasalSym = sSBasal.symmetrise('antipodal')
dS = dislocationSystem(sSBasal)
%ss=symmetrise(sS)
%dS = dislocationSystem(ss)
%The norm of the BURGER VECTOR
% size of the unit cell
a = norm(ea.CS.aAxis)
% for edge dislocations in hcp the norm of the burgers vector is sqrt(6)/3 * a
[norm(dS(1).b), sqrt(6)/3 * a]
% for screw dislocations in hcP the norm of the burgers vector is sqrt(6)/3 * a?? is it same??????????????
[norm(dS(end).b), sqrt(6)/3 * a]
%%Note that the energy of each dislocation system can be stored in the property u
% energy of the edge dislocations
dS(dS.isEdge).u = 1;
% energy of the screw dislocations
dS(dS.isScrew).u = 1 - 0.3;
% Question to everbody: what is the best way to set the enegry? I found
% different formula
%
% E = 1 - poisson ratio
% E = c * G * |b|^2, - G - Schubmodul / Shear Modulus Energy per (unit length)^2
dS(1).tensor
dSRot = ebsd.orientations * dS
ebsd
[rho,factor] = fitDislocationSystems(kappa,dSRot); %% It fits the data takes a while
% the restored dislocation density tensors
alpha = sum(dSRot.tensor .* rho,2);
% we have to set the unit manualy since it is not stored in rho
alpha.opt.unit = '1/um';
% the restored dislocation density tensor for pixel 2
alpha(2)
% the dislocation density dervied from the curvature in pixel 2
kappa(2).dislocationDensity
kappa = alpha.curvature
mtexFig = newMtexFigure('nrows',3,'ncols',3,'figSize','huge');
plot(ebsd,kappa{1,1},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',0.1); hold off
nextAxis
plot(ebsd,kappa{1,2},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{1,3},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{2,1},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{2,2},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{2,3},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{3,1},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{3,2},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
nextAxis
plot(ebsd,kappa{3,3},'micronBar','off')
hold on; plot(grains.boundary,'linewidth',2); hold off
drawNow(gcm,'figSize','large')
setColorRange([-0.005,0.005])
factor
close all
plot(ebsd,factor*sum(abs(rho .* dSRot.u),2),'micronbar','off')
mtexColorMap('hot')
mtexColorbar
set(gca,'ColorScale','log'); % this works only starting with Matlab 2018a
set(gca,'CLim',[1e11 5e14]);
hold on
plot(grains.boundary,'linewidth',0.1)
hold off
gnd = factor*sum(abs(rho .* dSRot.u),2)
meanGND = nanmean(gnd)