calcBKBHex_Lin
| main | Tutorials | Functions | website |
Computes the product B' x K x B for 3D linear hexahedral elements in vectorized manner This is used internally from calcBKB.
Version : 1.0
Author : George Kourakos
email: giorgk@gmail.com
web : http://groundwater.ucdavis.edu/msim
Date 28-Mar-2014
Department of Land Air and Water
University of California Davis
Contents
Usage
BKB = calcBKBHex_Lin(B, K, ii)
Input
B: [Nel x N_sh^2] contains the contributions of each element to the final conductance matrix
K : [Nel x Nanis] Hydraulic conductiviy element values. The number of columns is defined by the anisotropy. Maximum number is 3.
ii : In case of nested assembly this indicates the iteration. In vectorized assembly this is not used
Output
BKB: the product B'*K*B
How to compute
In mSim we avoid by hand computations at all costs, therefore we used the symbolic toolbox to perform the vectorized computations. The following code show how we computed the products.
syms b1 b2 b3 b4 b5 b6 b7 b8 syms b9 b10 b11 b12 b13 b14 b15 b16 syms b17 b18 b19 b20 b21 b22 b23 b24 syms kx ky kz B=[b1 b2 b3 b4 b5 b6 b7 b8;... b9 b10 b11 b12 b13 b14 b15 b16;... b17 b18 b19 b20 b21 b22 b23 b24]; BT=[ b1 b9 b17;... b2 b10 b18;... b3 b11 b19;... b4 b12 b20;... b5 b13 b21;... b6 b14 b22;... b7 b15 b23;... b8 b16 b24]; K=[kx 0 0;... 0 ky 0;... 0 0 kz]; BKB=BT*K*B
BKB = [ kx*b1^2 + ky*b9^2 + kz*b17^2, b1*b2*kx + b9*b10*ky + b17*b18*kz, b1*b3*kx + b9*b11*ky + b17*b19*kz, b1*b4*kx + b9*b12*ky + b17*b20*kz, b1*b5*kx + b9*b13*ky + b17*b21*kz, b1*b6*kx + b9*b14*ky + b17*b22*kz, b1*b7*kx + b9*b15*ky + b17*b23*kz, b1*b8*kx + b9*b16*ky + b17*b24*kz] [ b1*b2*kx + b9*b10*ky + b17*b18*kz, kx*b2^2 + ky*b10^2 + kz*b18^2, b2*b3*kx + b10*b11*ky + b18*b19*kz, b2*b4*kx + b10*b12*ky + b18*b20*kz, b2*b5*kx + b10*b13*ky + b18*b21*kz, b2*b6*kx + b10*b14*ky + b18*b22*kz, b2*b7*kx + b10*b15*ky + b18*b23*kz, b2*b8*kx + b10*b16*ky + b18*b24*kz] [ b1*b3*kx + b9*b11*ky + b17*b19*kz, b2*b3*kx + b10*b11*ky + b18*b19*kz, kx*b3^2 + ky*b11^2 + kz*b19^2, b3*b4*kx + b11*b12*ky + b19*b20*kz, b3*b5*kx + b11*b13*ky + b19*b21*kz, b3*b6*kx + b11*b14*ky + b19*b22*kz, b3*b7*kx + b11*b15*ky + b19*b23*kz, b3*b8*kx + b11*b16*ky + b19*b24*kz] [ b1*b4*kx + b9*b12*ky + b17*b20*kz, b2*b4*kx + b10*b12*ky + b18*b20*kz, b3*b4*kx + b11*b12*ky + b19*b20*kz, kx*b4^2 + ky*b12^2 + kz*b20^2, b4*b5*kx + b12*b13*ky + b20*b21*kz, b4*b6*kx + b12*b14*ky + b20*b22*kz, b4*b7*kx + b12*b15*ky + b20*b23*kz, b4*b8*kx + b12*b16*ky + b20*b24*kz] [ b1*b5*kx + b9*b13*ky + b17*b21*kz, b2*b5*kx + b10*b13*ky + b18*b21*kz, b3*b5*kx + b11*b13*ky + b19*b21*kz, b4*b5*kx + b12*b13*ky + b20*b21*kz, kx*b5^2 + ky*b13^2 + kz*b21^2, b5*b6*kx + b13*b14*ky + b21*b22*kz, b5*b7*kx + b13*b15*ky + b21*b23*kz, b5*b8*kx + b13*b16*ky + b21*b24*kz] [ b1*b6*kx + b9*b14*ky + b17*b22*kz, b2*b6*kx + b10*b14*ky + b18*b22*kz, b3*b6*kx + b11*b14*ky + b19*b22*kz, b4*b6*kx + b12*b14*ky + b20*b22*kz, b5*b6*kx + b13*b14*ky + b21*b22*kz, kx*b6^2 + ky*b14^2 + kz*b22^2, b6*b7*kx + b14*b15*ky + b22*b23*kz, b6*b8*kx + b14*b16*ky + b22*b24*kz] [ b1*b7*kx + b9*b15*ky + b17*b23*kz, b2*b7*kx + b10*b15*ky + b18*b23*kz, b3*b7*kx + b11*b15*ky + b19*b23*kz, b4*b7*kx + b12*b15*ky + b20*b23*kz, b5*b7*kx + b13*b15*ky + b21*b23*kz, b6*b7*kx + b14*b15*ky + b22*b23*kz, kx*b7^2 + ky*b15^2 + kz*b23^2, b7*b8*kx + b15*b16*ky + b23*b24*kz] [ b1*b8*kx + b9*b16*ky + b17*b24*kz, b2*b8*kx + b10*b16*ky + b18*b24*kz, b3*b8*kx + b11*b16*ky + b19*b24*kz, b4*b8*kx + b12*b16*ky + b20*b24*kz, b5*b8*kx + b13*b16*ky + b21*b24*kz, b6*b8*kx + b14*b16*ky + b22*b24*kz, b7*b8*kx + b15*b16*ky + b23*b24*kz, kx*b8^2 + ky*b16^2 + kz*b24^2]
Next to convert the above complex expressions to vectorized expresions we used the following loop and copy the output to an editor and with minimum editing we wrote the final expressions without actually write by hand indices and symbols
cnt=0; for i=1:size(B,2) for j=1:size(B,2) cnt=cnt+1; fprintf(['BKB(:,%d) = ' char(BKB(i,j)) ';\n'],cnt); end end
BKB(:,1) = b1^2*kx + b9^2*ky + b17^2*kz; BKB(:,2) = b1*b2*kx + b9*b10*ky + b17*b18*kz; BKB(:,3) = b1*b3*kx + b9*b11*ky + b17*b19*kz; BKB(:,4) = b1*b4*kx + b9*b12*ky + b17*b20*kz; BKB(:,5) = b1*b5*kx + b9*b13*ky + b17*b21*kz; BKB(:,6) = b1*b6*kx + b9*b14*ky + b17*b22*kz; BKB(:,7) = b1*b7*kx + b9*b15*ky + b17*b23*kz; BKB(:,8) = b1*b8*kx + b9*b16*ky + b17*b24*kz; BKB(:,9) = b1*b2*kx + b9*b10*ky + b17*b18*kz; BKB(:,10) = b2^2*kx + b10^2*ky + b18^2*kz; BKB(:,11) = b2*b3*kx + b10*b11*ky + b18*b19*kz; BKB(:,12) = b2*b4*kx + b10*b12*ky + b18*b20*kz; BKB(:,13) = b2*b5*kx + b10*b13*ky + b18*b21*kz; BKB(:,14) = b2*b6*kx + b10*b14*ky + b18*b22*kz; BKB(:,15) = b2*b7*kx + b10*b15*ky + b18*b23*kz; BKB(:,16) = b2*b8*kx + b10*b16*ky + b18*b24*kz; BKB(:,17) = b1*b3*kx + b9*b11*ky + b17*b19*kz; BKB(:,18) = b2*b3*kx + b10*b11*ky + b18*b19*kz; BKB(:,19) = b3^2*kx + b11^2*ky + b19^2*kz; BKB(:,20) = b3*b4*kx + b11*b12*ky + b19*b20*kz; BKB(:,21) = b3*b5*kx + b11*b13*ky + b19*b21*kz; BKB(:,22) = b3*b6*kx + b11*b14*ky + b19*b22*kz; BKB(:,23) = b3*b7*kx + b11*b15*ky + b19*b23*kz; BKB(:,24) = b3*b8*kx + b11*b16*ky + b19*b24*kz; BKB(:,25) = b1*b4*kx + b9*b12*ky + b17*b20*kz; BKB(:,26) = b2*b4*kx + b10*b12*ky + b18*b20*kz; BKB(:,27) = b3*b4*kx + b11*b12*ky + b19*b20*kz; BKB(:,28) = b4^2*kx + b12^2*ky + b20^2*kz; BKB(:,29) = b4*b5*kx + b12*b13*ky + b20*b21*kz; BKB(:,30) = b4*b6*kx + b12*b14*ky + b20*b22*kz; BKB(:,31) = b4*b7*kx + b12*b15*ky + b20*b23*kz; BKB(:,32) = b4*b8*kx + b12*b16*ky + b20*b24*kz; BKB(:,33) = b1*b5*kx + b9*b13*ky + b17*b21*kz; BKB(:,34) = b2*b5*kx + b10*b13*ky + b18*b21*kz; BKB(:,35) = b3*b5*kx + b11*b13*ky + b19*b21*kz; BKB(:,36) = b4*b5*kx + b12*b13*ky + b20*b21*kz; BKB(:,37) = b5^2*kx + b13^2*ky + b21^2*kz; BKB(:,38) = b5*b6*kx + b13*b14*ky + b21*b22*kz; BKB(:,39) = b5*b7*kx + b13*b15*ky + b21*b23*kz; BKB(:,40) = b5*b8*kx + b13*b16*ky + b21*b24*kz; BKB(:,41) = b1*b6*kx + b9*b14*ky + b17*b22*kz; BKB(:,42) = b2*b6*kx + b10*b14*ky + b18*b22*kz; BKB(:,43) = b3*b6*kx + b11*b14*ky + b19*b22*kz; BKB(:,44) = b4*b6*kx + b12*b14*ky + b20*b22*kz; BKB(:,45) = b5*b6*kx + b13*b14*ky + b21*b22*kz; BKB(:,46) = b6^2*kx + b14^2*ky + b22^2*kz; BKB(:,47) = b6*b7*kx + b14*b15*ky + b22*b23*kz; BKB(:,48) = b6*b8*kx + b14*b16*ky + b22*b24*kz; BKB(:,49) = b1*b7*kx + b9*b15*ky + b17*b23*kz; BKB(:,50) = b2*b7*kx + b10*b15*ky + b18*b23*kz; BKB(:,51) = b3*b7*kx + b11*b15*ky + b19*b23*kz; BKB(:,52) = b4*b7*kx + b12*b15*ky + b20*b23*kz; BKB(:,53) = b5*b7*kx + b13*b15*ky + b21*b23*kz; BKB(:,54) = b6*b7*kx + b14*b15*ky + b22*b23*kz; BKB(:,55) = b7^2*kx + b15^2*ky + b23^2*kz; BKB(:,56) = b7*b8*kx + b15*b16*ky + b23*b24*kz; BKB(:,57) = b1*b8*kx + b9*b16*ky + b17*b24*kz; BKB(:,58) = b2*b8*kx + b10*b16*ky + b18*b24*kz; BKB(:,59) = b3*b8*kx + b11*b16*ky + b19*b24*kz; BKB(:,60) = b4*b8*kx + b12*b16*ky + b20*b24*kz; BKB(:,61) = b5*b8*kx + b13*b16*ky + b21*b24*kz; BKB(:,62) = b6*b8*kx + b14*b16*ky + b22*b24*kz; BKB(:,63) = b7*b8*kx + b15*b16*ky + b23*b24*kz; BKB(:,64) = b8^2*kx + b16^2*ky + b24^2*kz;