Grid Frames

The degrees of freedom are as follows, 
(Subscript[d, n x']), (Subscript[d, n y']), (Subscript[d, n z']), (Subscript[d, f x']), (Subscript[d, f y']), (Subscript[d, f z']) as shown in the figure and the corresponding forces with d replaced with q.

The local stiffness matrix connection connects q and d.
(({{(Subscript[q, n x'])}, {(Subscript[q , n y'])}, {(Subscript[q, n z'])}, {(Subscript[q, f x'])}, {(Subscript[q , f y'])}, {(Subscript[q, f x'])}})) = (({{(GJ/L), 0, 0, -(GJ/L), 0, 0}, {0, ((12 EI)/(L^3)), ((6 EI)/(L^2)), 0, -((12 EI)/(L^3)), ((6 EI)/(L^2))}, {0, ((6 EI)/(L^2)), ((4 EI)/L), 0, -((6 EI)/(L^2)), ((2 EI)/L)}, {-(GJ/L), 0, 0, (GJ/L), 0, 0}, {0, -((12 EI)/(L^3)), -((6 EI)/(L^2)), 0, ((12 EI)/(L^3)), -((6 EI)/(L^2))}, {0, ((6 EI)/(L^2)), ((2 EI)/L), 0, -((6 EI)/(L^2)), ((4 EI)/L)}}))(({{(Subscript[d, n x'])}, {(Subscript[d , n y'])}, {(Subscript[d, n z'])}, {(Subscript[d, f x'])}, {(Subscript[d , f y'])}, {(Subscript[d, f x'])}}))

k[GJ_, EI_, L_] = {{(GJ/L), 0, 0, -(GJ/L), 0,0}, {0,((12 EI)/(L^3)), ((6 EI)/(L^2)), 0,  -((12 EI)/(L^3)), ((6 EI)/(L^2))}, {0, ((6 EI)/(L^2)), ((4 EI)/L), 0,  -((6 EI)/(L^2)), ((2 EI)/L)},{-(GJ/L), 0, 0,  (GJ/L), 0, 0}, 
{0, -((12 EI)/(L^3)), - ((6 EI)/(L^2)), 0,  ((12 EI)/(L^3)),- ((6 EI)/(L^2))}, {0,((6 EI)/(L^2)),   ((2 EI)/L),0,  -((6 EI)/(L^2)),((4 EI)/L)}};
MatrixForm[k[GJ, EI, L]]

T[λx_, λz_] = {{λx, 0, λz, 0, 0, 0}, {0, 1, 0, 0, 0, 0}, {-λz, 0, λx, 0, 0, 0}, {0, 0, 0, λx, 0, λz}, {0, 0, 0, 0, 1,0}, {0, 0, 0, -λz,0,λx}};
T[λx, λz]//MatrixForm

The basic transformation rules are as follows:
{d} = [T] {D}
{Q} = (([T])^T){q}
{q} = [k]{d}
{Q} =[K]{D}, where
[K] =  (([T])^T)[k] [T] 

[K] is obtained as

K = Transpose[T[λx, λz]].k[GJ, EI, L]. T[λx, λz];
MatrixForm[K]

The global stiffness matrix is:
(({{((GJ ((λx)^2))/L)+((4 EI ((λz)^2))/L), -((6 EI λz)/(L^2)), -((4 EI λx λz)/L)+((GJ λx λz)/L), -((GJ ((λx)^2))/L)+((2 EI ((λz)^2))/L), ((6 EI λz)/(L^2)), -((2 EI λx λz)/L)-((GJ λx λz)/L)}, {-((6 EI λz)/(L^2)), ((12 EI)/(L^3)), ((6 EI λx)/(L^2)), -((6 EI λz)/(L^2)), -((12 EI)/(L^3)), ((6 EI λx)/(L^2))}, {-((4 EI λx λz)/L)+((GJ λx λz)/L), ((6 EI λx)/(L^2)), ((4 EI ((λx)^2))/L)+((GJ ((λz)^2))/L), -((2 EI λx λz)/L)-((GJ λx λz)/L), -((6 EI λx)/(L^2)), ((2 EI ((λx)^2))/L)-((GJ ((λz)^2))/L)}, {-((GJ ((λx)^2))/L)+((2 EI ((λz)^2))/L), -((6 EI λz)/(L^2)), -((2 EI λx λz)/L)-((GJ λx λz)/L), ((GJ ((λx)^2))/L)+((4 EI ((λz)^2))/L), ((6 EI λz)/(L^2)), -((4 EI λx λz)/L)+((GJ λx λz)/L)}, {((6 EI λz)/(L^2)), -((12 EI)/(L^3)), -((6 EI λx)/(L^2)), ((6 EI λz)/(L^2)), ((12 EI)/(L^3)), -((6 EI λx)/(L^2))}, {-((2 EI λx λz)/L)-((GJ λx λz)/L), ((6 EI λx)/(L^2)), ((2 EI ((λx)^2))/L)-((GJ ((λz)^2))/L), -((4 EI λx λz)/L)+((GJ λx λz)/L), -((6 EI λx)/(L^2)), ((4 EI ((λx)^2))/L)+((GJ ((λz)^2))/L)}}))

Problems

For members 12, 23, 45, 56
	I = 27.34 (10^9)(mm^4)
J = 18.77 (10^9)(mm^4)
L = 6 (10^(3 ))mm
E = 12 kN/(mm^2)
G = 5 kN/(mm^2)
for member 25
	I = 18.23 (10^9)(mm^4)
J = 6.4 (10^9)(mm^4)
L = 3 (10^(3 ))mm
E = 12 kN/(mm^2)
G = 5 kN/(mm^2)
At every node there are three degrees of freedom. So in total there are 18 degrees of freedom.

(* Members 1(12), 2(23), 3(45), 4(56) *)
n1 = {1, 2, 3, 4, 5, 6};
n2 = {4, 5, 6, 7, 8, 9};
n3 = {10, 11, 12, 13, 14, 15};
n4 = {13, 14, 15, 16, 17, 18};
vals = {EI->12 27.34 (10^9) (10^(-6)), GJ->5 18.77 (10^9) (10^(-6)) ,L-> 6, λx->((-1)/2), λz->((Sqrt[3])/2)};
vals = {EI->12 27.34 (10^9) (10^(-6)), GJ->5 18.77 (10^9) (10^(-6)) ,L-> 6, λx->0, λz->-1};
(* Member 1, 2, 3, 4 *)
K= Transpose[T[λx, λz]].k[GJ, EI, L]. T[λx, λz]/.vals;
(* Member 5 (25) *)
n5 = {4, 5, 6, 13, 14, 15};
vals1 = {EI->12 *18.23 (10^9)(10^(-6)), GJ->5  * 6.4 (10^9) (10^(-6)), L-> 3, λx->-1, λz->0};
K1= Transpose[T[λx, λz]].k[GJ, EI, L]. T[λx, λz]/.vals1;
(* Full Stiffness Matrix *)
Kg = ConstantArray[0, {18, 18}];
(* Assemble stiffness matrix *)
Kg[[n1, n1]] = Kg[[n1, n1]] + K;
Kg[[n2, n2]] = Kg[[n2, n2]] + K;
Kg[[n3, n3]] = Kg[[n3, n3]] + K;
Kg[[n4, n4]]  = Kg[[n4, n4]] + K;
Kg[[n5, n5]] = Kg[[n5, n5]] + K1;

MatrixForm[Kg]

Now extracting the stiffness matrix (Subscript[K, 11])

nu = {4, 5, 6, 13, 14, 15};
Kg11 = Kg[[nu, nu]];
MatrixForm[% (10^(-5))]//FullSimplify

nmod = {5, 4, 6, 14, 13, 15};
Kg[[nmod, nmod]];
MatrixForm[% (10^(-5))]

nmod = {5, 4, 6, 14, 13, 15};
Kg[[nmod, nmod]];
MatrixForm[% (10^(-5))]

Tutorial problem

(* connectivity *)
n1 = {1, 2, 3, 4, 5, 6};
n2 = { 7, 8, 9, 4, 5, 6};

(* material properties and geometry *)
val1 = {EI->200 500, GJ-> (200/(2 (1+0.3)))200 ,L-> 7.5, λx->0.8, λz->0.6};
val2 = {EI->200 500, GJ-> (200/(2 (1+0.3)))200 ,L-> 4.5, λx->0, λz->1};

(* stiffness matrices *)
k1 = Transpose[T[λx, λz]].k[GJ, EI, L].T[λx, λz]/.val1;
k2 =  Transpose[T[λx, λz]].k[GJ, EI, L].T[λx, λz]/.val2;
K = ConstantArray[0, {9, 9}];

(* Assembling the matrix *)
K[[n1, n1]] = K[[n1, n1]] + k1;
K[[n2, n2]] = K[[n2,n2]] + k2;

(* Extracting the k11 matrix *)
nu = {4, 5, 6};
k11 = K[[nu, nu]];
MatrixForm[k11]

(* known load *)
Qk = {0, -30, 0};
Du = LinearSolve[k11,Qk]

(* support reactions *)
nk = {1, 2, 3, 7, 8, 9};
k21 = K[[nk, nu]];
Qu = k21.Du