%*****************************************************************************************
% Useful plot as it shows relative contributions positive or negative
%*****************************************************************************************
% The leading diagonal has the highest values and always positive.
% Typically off-diagonal values are much smaller or even negative.
%
% Stiffness Voigt Matrix in 3D Histogram or 2D Histogram
% in colour or black and white  - single crystal or aggregate stiffness
% tensors
%
% Tested with mtex-5.3beta3 and MATLAB 2016a
%
% Remember that the function
%**************************************************************************
% Stiffness_Voigt_Matrix_in_3D_Histo(Stiffness,Plot_title,col_map,iview)
%**************************************************************************
% should be in your current directory
%
% David Mainprice 2/05/2019
%
% Options for plots
% 1) plot    (col_map = 0) white2black      and (iview = 1) tilted 3D
% 2) plot    (col_map = 1) WhiteJetColorMap and (iview = 1) tilted 3D
% 3) plot    (col_map = 0) white2black      and (iview = 0) normal plane 2D
% 4) plot    (col_map = 1) WhiteJetColorMap and (iview = 0) normal plane 2D
%
clear all
close all
clc
%%
%**************************************************************************
% Define elastic stiffness tensor of Olivine
%**************************************************************************
% Olivine elastic stiffness (Cij) Tensor in GPa
% Abramson E.H., Brown J.M., Slutsky L.J., and Zaug J.(1997)
% The elastic constants of San Carlos olivine to 17 GPa.
% Journal of Geophysical Research 102: 12253-12263.
%
% Enter tensor as 6 by 6 matrix,M line by line.
M = [[320.5  68.15  71.6     0     0     0];...
    [ 68.15  196.5  76.8     0     0     0];...
    [  71.6   76.8 233.5     0     0     0];...
    [   0      0      0     64     0     0];...
    [   0      0      0      0    77     0];...
    [   0      0      0      0     0  78.7]];
% Define density : San Carlos OLIVINE Fo90 room pressure d=3.355 g/cm3
rho = 3.3550;
% Define Cartesian Tensor crystal symmetry & frame
CS_Tensor = crystalSymmetry('mmm',[4.7646 10.2296 5.9942],...
 [90.0000  90.0000  90.0000]*degree,'x||a','z||c', 'mineral','Olivine 1997 fo90');
% Define elastic stiffness tensor Cijkl with MTEX load tensor command
C_olivine = stiffnessTensor(M,CS_Tensor,'density',rho);
%% ************************************************************************
%  Plot 1 : Olivine Plot 3D Voigt Stiffness Matrix
%  with options (col_map = 0)=> white2black and (iview = 1)=> tilted view
%**************************************************************************
% Tensor = C = MTEX elastic stiffness tensor (GPa)
% Plot_title = example 'Olivine stiffness tensor in Voigt matix C(i,j) in GPa'
% col_map = 1 WhiteJetColorMap 0= white2black
% iview =   1 tilted 3D view   0= normal to plane 2D
% Title of plot
Plot_title='Olivine stiffness tensor in Voigt matix Cij in GPa';
% Option WhiteJetColorMap
col_map = 0;
% Option tilted 3D view
iview = 1;
close all
[Tmax_Pos,Tmin_Pos,Tmax_Neg,Tmin_Neg]=Stiffness_Voigt_Matrix_in_3D_Histo(C_olivine,Plot_title,col_map,iview);
%% ************************************************************************
%  Plot 2 : Olivine Plot 3D Voigt Stiffness Matrix
%  with options (col_map = 1)=> WhiteJetColorMap and (iview = 1)=> tilted view
%**************************************************************************
% Tensor = C = MTEX elastic stiffness tensor (GPa)
% Plot_title = example 'Olivine stiffness tensor in Voigt matix C(i,j) in GPa'
% col_map = 1 WhiteJetColorMap 0= white2black
% iview =   1 tilted 3D view   0= normal to plane 2D
% Title of plot
Plot_title='Olivine stiffness tensor in Voigt matix Cij in GPa';
% Option WhiteJetColorMap
col_map = 1;
% Option tilted 3D view
iview = 1;
close all
[Tmax_Pos,Tmin_Pos,Tmax_Neg,Tmin_Neg]=Stiffness_Voigt_Matrix_in_3D_Histo(C_olivine,Plot_title,col_map,iview);
%% ************************************************************************
%  Plot 3 : Olivine Plot 3D Voigt Stiffness Matrix
%  with options (col_map = 0)=> white2black and (iview = 0)=> 2D view
%**************************************************************************
% Tensor = C = MTEX elastic stiffness tensor (GPa)
% Plot_title = example 'Olivine stiffness tensor in Voigt matix C(i,j) in GPa'
% col_map = 1 WhiteJetColorMap 0= white2black
% iview =   1 tilted 3D view   0= normal to plane 2D
% Title of plot
Plot_title='Olivine stiffness tensor in Voigt matix Cij in GPa';
% Option white2black
col_map = 0;
% Option normal to plane 2D
iview = 0;
close all
[Tmax_Pos,Tmin_Pos,Tmax_Neg,Tmin_Neg]=Stiffness_Voigt_Matrix_in_3D_Histo(C_olivine,Plot_title,col_map,iview);
%% ************************************************************************
%  Olivine Plot 3D Voigt Stiffness Matrix
%  with options (col_map = 1)=> WhiteJetColorMap and (iview = 0)=> 2D view
%**************************************************************************
% Tensor = C = MTEX elastic stiffness tensor (GPa)
% Plot_title = example 'Olivine stiffness tensor in Voigt matix C(i,j) in GPa'
% col_map = 1 WhiteJetColorMap 0= white2black
% iview =   1 tilted 3D view   0= normal to plane 2D
% Title of plot
Plot_title='Olivine stiffness tensor in Voigt matix Cij in GPa';
% Option WhiteJetColorMap
col_map = 1;
% Option normal to plane 2D
iview = 0;
close all
[Tmax_Pos,Tmin_Pos,Tmax_Neg,Tmin_Neg]=Stiffness_Voigt_Matrix_in_3D_Histo(C_olivine,Plot_title,col_map,iview);
