% script test_assemble_matrix_etu_0
%
% Author: E.Darrigrand
% Date: 9/10/2014
%
%  Test assemble matrix on very simple meshes, isoparametric P_1 configuration.  
%
% How to use: uncomment the lines "coord_ ..." and "triangles_ ..." corresponding to the mesh you want to try. 
%             for Example 7, uncomment also the line "ccx = ...".
%
clear all
close all
%
% EXPLE 1
%
% coords_ = [0,0;1,0;0,1;1,1];
% triangles_ = [1,2,4;1,3,4];
%
%  where Mass and Stiffness matrices should be 
%    
% Mass (deg_quad = 3) =
% 
% 0.16667   0.04167   0.04167   0.08333
% 0.04167   0.08333   0.00000   0.04167
% 0.04167   0.00000   0.08333   0.04167
% 0.08333   0.04167   0.04167   0.16667
% 
% Mass (deg_quad = 1) =
% 
% 0.33333   0.00000   0.00000   0.00000
% 0.00000   0.16667   0.00000   0.00000
% 0.00000   0.00000   0.16667   0.00000
% 0.00000   0.00000   0.00000   0.33333
% 
% Rigid =
% 
%  1.00000  -0.50000  -0.50000   0.00000
% -0.50000   1.00000   0.00000  -0.50000
% -0.50000   0.00000   1.00000  -0.50000
%  0.00000  -0.50000  -0.50000   1.00000
% 
%
% EXPLE 2
%
% coords_ = [0,0;1,0;0,1;1,1.3];
% triangles_ = [1,2,4;1,3,4];
%
%  where Mass and Stiffness matrices should be 
%    
% Mass (deg_quad = 3) =
% 
% 0.19167   0.05417   0.04167   0.09583
% 0.05417   0.10833   0.00000   0.05417
% 0.04167   0.00000   0.08333   0.04167
% 0.09583   0.05417   0.04167   0.19167
% 
% Mass (deg_quad = 1) =
% 
% 0.38333   0.00000   0.00000   0.00000
% 0.00000   0.21667   0.00000   0.00000
% 0.00000   0.00000   0.16667   0.00000
% 0.00000   0.00000   0.00000   0.38333
% 
% Rigid =
% 
%  1.19500  -0.65000  -0.69500   0.15000
% -0.65000   1.03462   0.00000  -0.38462
% -0.69500   0.00000   1.34500  -0.65000
%  0.15000  -0.38462  -0.65000   0.88462
% 
%
% EXPLE 3
%
% coords_ = [0,0;0.5,0;1,0;0,0.5;0.5,0.5;1,0.5;0,1;0.5,1;1,1];
% triangles_ = [1,2,4;2,5,4;2,3,5;3,6,5;4,5,7;5,8,7;5,6,8;6,9,8];
%
%  where Mass and Stiffness matrices should be 
%    
% Mass =
% 
% 0.02083   0.01042   0.00000	0.01042   0.00000   0.00000   0.00000	0.00000   0.00000
% 0.01042   0.06250   0.01042	0.02083   0.02083   0.00000   0.00000	0.00000   0.00000
% 0.00000   0.01042   0.04167	0.00000   0.02083   0.01042   0.00000	0.00000   0.00000
% 0.01042   0.02083   0.00000	0.06250   0.02083   0.00000   0.01042	0.00000   0.00000
% 0.00000   0.02083   0.02083	0.02083   0.12500   0.02083   0.02083	0.02083   0.00000
% 0.00000   0.00000   0.01042	0.00000   0.02083   0.06250   0.00000	0.02083   0.01042
% 0.00000   0.00000   0.00000	0.01042   0.02083   0.00000   0.04167	0.01042   0.00000
% 0.00000   0.00000   0.00000	0.00000   0.02083   0.02083   0.01042	0.06250   0.01042
% 0.00000   0.00000   0.00000	0.00000   0.00000   0.01042   0.00000	0.01042   0.02083
%
%
% Rigid =
% 
%  1.00000  -0.50000   0.00000  -0.50000   0.00000   0.00000   0.00000   0.00000   0.00000
% -0.50000   2.00000  -0.50000   0.00000  -1.00000   0.00000   0.00000   0.00000   0.00000 
%  0.00000  -0.50000   1.00000   0.00000   0.00000  -0.50000   0.00000   0.00000   0.00000
% -0.50000   0.00000   0.00000   2.00000  -1.00000   0.00000  -0.50000   0.00000   0.00000
%  0.00000  -1.00000   0.00000  -1.00000   4.00000  -1.00000   0.00000  -1.00000   0.00000 
%  0.00000   0.00000  -0.50000   0.00000  -1.00000   2.00000   0.00000   0.00000  -0.50000
%  0.00000   0.00000   0.00000  -0.50000   0.00000   0.00000   1.00000  -0.50000   0.00000
%  0.00000   0.00000   0.00000   0.00000  -1.00000   0.00000  -0.50000   2.00000  -0.50000
%  0.00000   0.00000   0.00000   0.00000   0.00000  -0.50000   0.00000  -0.50000   1.00000
%
%
% EXPLE 4
%
% coords_ = [1,0;0,1;0,0];     %  triangle de reference
% triangles_ = [1,2,3];        %  triangle de reference
% 
% Mass =
% 
% 0.083333   0.041667   0.041667       note Mass_Ref (1/24)* 2   1   1
% 0.041667   0.083333   0.041667                             1   2   1
% 0.041667   0.041667   0.083333                             1   1   2
% 
% Rigid =
% 
%  0.50000   0.00000  -0.50000          note Rigid_Ref
%  0.00000   0.50000  -0.50000
% -0.50000  -0.50000   1.00000
%
%
% EXPLE 5
%
% coords_ = [0.5,0;0,0.5;0,0];  %  triangle (0,0 ; 0.5,0 ; 0,0.5)
% triangles_ = [1,2,3];         %  triangle (0,0 ; 0.5,0 ; 0,0.5)
%
% Mass =
% 
% 0.020833   0.010417   0.010417      =  Mass_Ref * 2 * aire(ce_triangle)
% 0.010417   0.020833   0.010417
% 0.010417   0.010417   0.020833
% 
% Rigid =
% 
%  0.50000   0.00000  -0.50000         =  Rigid_Ref
%  0.00000   0.50000  -0.50000
% -0.50000  -0.50000   1.00000
% 
%
% EXPLE 6
% 
% coords_ = [-0.5,0;0.5,0;0,0.5*sqrt(3)];     %  triangle equilateral
% triangles_ = [1,2,3];                       %  triangle equilateral
%
% Mass =
% 
% 0.072169   0.036084   0.036084      =   Mass_Ref * 2 * aire(triangle_equilateral)
% 0.036084   0.072169   0.036084
% 0.036084   0.036084   0.072169
% 
% Rigid =
% 
%  0.57735  -0.28868  -0.28868         = 
% -0.28868   0.57735  -0.28868
% -0.28868  -0.28868   0.57735
% 
%  =    1.00000  -0.50000  -0.50000    *  (1/sqrt(3))
%      -0.50000   1.00000  -0.50000
%      -0.50000  -0.50000   1.00000
%
%
% EXPLE 7, d''approximation d''un disque avec 6 tr equilateraux)
%
% ccx = 0.5; ccy = 0.5*sqrt(3); 
% coords_ = [-ccx,-ccy;ccx,-ccy;-1,0;0,0;1,0;-ccx,ccy;ccx,ccy];  %  test disc6
% triangles_ = [1,2,4 ;2,5,4 ; 5,7,4; 7,6,4; 6,3,4; 3,1,4];      %  test disc6
% 
% Mass =
% 
% 0.14434   0.03608   0.03608   0.07217   0.00000   0.00000   0.00000
% 0.03608   0.14434   0.00000   0.07217   0.03608   0.00000   0.00000
% 0.03608   0.00000   0.14434   0.07217   0.00000   0.03608   0.00000
% 0.07217   0.07217   0.07217   0.43301   0.07217   0.07217   0.07217
% 0.00000   0.03608   0.00000   0.07217   0.14434   0.00000   0.03608
% 0.00000   0.00000   0.03608   0.07217   0.00000   0.14434   0.03608
% 0.00000   0.00000   0.00000   0.07217   0.03608   0.03608   0.14434
% 
% = (1/(16*sqrt(3))) * 
% 4.00000    1.00000    1.00000    2.00000    0.00000    0.00000    0.00000
% 1.00000    4.00000    0.00000    2.00000    1.00000    0.00000    0.00000
% 1.00000    0.00000    4.00000    2.00000    0.00000    1.00000    0.00000
% 2.00000    2.00000    2.00000   12.00000    2.00000    2.00000    2.00000
% 0.00000    1.00000    0.00000    2.00000    4.00000    0.00000    1.00000
% 0.00000    0.00000    1.00000    2.00000    0.00000    4.00000    1.00000
% 0.00000    0.00000    0.00000    2.00000    1.00000    1.00000    4.00000
% 
% 
% 
% Rigid =
% 
%  1.15470  -0.28868  -0.28868  -0.57735   0.00000   0.00000   0.00000
% -0.28868   1.15470   0.00000  -0.57735  -0.28868   0.00000   0.00000
% -0.28868   0.00000   1.15470  -0.57735   0.00000  -0.28868   0.00000
% -0.57735  -0.57735  -0.57735   3.46410  -0.57735  -0.57735  -0.57735
%  0.00000  -0.28868   0.00000  -0.57735   1.15470   0.00000  -0.28868
%  0.00000   0.00000  -0.28868  -0.57735   0.00000   1.15470  -0.28868
%  0.00000   0.00000   0.00000  -0.57735  -0.28868  -0.28868   1.15470
% 
% = (1/sqrt(3)) *
%  2.00000  -0.50000  -0.50000  -1.00000   0.00000   0.00000   0.00000
% -0.50000   2.00000   0.00000  -1.00000  -0.50000   0.00000   0.00000
% -0.50000   0.00000   2.00000  -1.00000   0.00000  -0.50000   0.00000
% -1.00000  -1.00000  -1.00000   6.00000  -1.00000  -1.00000  -1.00000
%  0.00000  -0.50000   0.00000  -1.00000   2.00000   0.00000  -0.50000
%  0.00000   0.00000  -0.50000  -1.00000   0.00000   2.00000  -0.50000
%  0.00000   0.00000   0.00000  -1.00000  -0.50000  -0.50000   2.00000
%
%
my_mesh = mesh_new('TheCurrentTest',coords_,triangles_);
mesh_plot(my_mesh,true);
%
Mass = assemble_matrix('Id', 'Id', 'f_one', my_mesh, 1, 1, 3)
Rigid1 = assemble_matrix('D1', 'D1', 'f_one', my_mesh, 1, 1, 1);
Rigid2 = assemble_matrix('D2', 'D2', 'f_one', my_mesh, 1, 1, 1);
Rigid = Rigid1 + Rigid2
%
%

