# calcBKBPrism_Lin

Computes the product B' x K x B for 3D linear prism elements in vectorized manner This is used internally from calcBKB.

Version : 1.0

Author : George Kourakos

email: giorgk@gmail.com

Date 28-Mar-2014

Department of Land Air and Water

University of California Davis

## Usage

BKB = calcBKBPrism_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
syms b7 b8 b9 b10 b11 b12
syms b13 b14 b15 b16 b17 b18
syms kx ky kz
B=[b1 b2 b3 b4 b5 b6;b7 b8 b9 b10 b11 b12;b13 b14 b15 b16 b17 b18];
BT=[b1 b7 b13;b2 b8 b14;b3 b9 b15;b4 b10 b16;b5 b11 b17;b6 b12 b18];
K=[kx 0 0;0 ky 0;0 0 kz];
BKB=BT*K*B
```
```
BKB =

[      kx*b1^2 + ky*b7^2 + kz*b13^2,  b1*b2*kx + b7*b8*ky + b13*b14*kz,  b1*b3*kx + b7*b9*ky + b13*b15*kz,  b1*b4*kx + b7*b10*ky + b13*b16*kz,  b1*b5*kx + b7*b11*ky + b13*b17*kz,  b1*b6*kx + b7*b12*ky + b13*b18*kz]
[  b1*b2*kx + b7*b8*ky + b13*b14*kz,      kx*b2^2 + ky*b8^2 + kz*b14^2,  b2*b3*kx + b8*b9*ky + b14*b15*kz,  b2*b4*kx + b8*b10*ky + b14*b16*kz,  b2*b5*kx + b8*b11*ky + b14*b17*kz,  b2*b6*kx + b8*b12*ky + b14*b18*kz]
[  b1*b3*kx + b7*b9*ky + b13*b15*kz,  b2*b3*kx + b8*b9*ky + b14*b15*kz,      kx*b3^2 + ky*b9^2 + kz*b15^2,  b3*b4*kx + b9*b10*ky + b15*b16*kz,  b3*b5*kx + b9*b11*ky + b15*b17*kz,  b3*b6*kx + b9*b12*ky + b15*b18*kz]
[ b1*b4*kx + b7*b10*ky + b13*b16*kz, b2*b4*kx + b8*b10*ky + b14*b16*kz, b3*b4*kx + b9*b10*ky + b15*b16*kz,      kx*b4^2 + ky*b10^2 + kz*b16^2, b4*b5*kx + b10*b11*ky + b16*b17*kz, b4*b6*kx + b10*b12*ky + b16*b18*kz]
[ b1*b5*kx + b7*b11*ky + b13*b17*kz, b2*b5*kx + b8*b11*ky + b14*b17*kz, b3*b5*kx + b9*b11*ky + b15*b17*kz, b4*b5*kx + b10*b11*ky + b16*b17*kz,      kx*b5^2 + ky*b11^2 + kz*b17^2, b5*b6*kx + b11*b12*ky + b17*b18*kz]
[ b1*b6*kx + b7*b12*ky + b13*b18*kz, b2*b6*kx + b8*b12*ky + b14*b18*kz, b3*b6*kx + b9*b12*ky + b15*b18*kz, b4*b6*kx + b10*b12*ky + b16*b18*kz, b5*b6*kx + b11*b12*ky + b17*b18*kz,      kx*b6^2 + ky*b12^2 + kz*b18^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 + b7^2*ky + b13^2*kz;
BKB(:,2) = b1*b2*kx + b7*b8*ky + b13*b14*kz;
BKB(:,3) = b1*b3*kx + b7*b9*ky + b13*b15*kz;
BKB(:,4) = b1*b4*kx + b7*b10*ky + b13*b16*kz;
BKB(:,5) = b1*b5*kx + b7*b11*ky + b13*b17*kz;
BKB(:,6) = b1*b6*kx + b7*b12*ky + b13*b18*kz;
BKB(:,7) = b1*b2*kx + b7*b8*ky + b13*b14*kz;
BKB(:,8) = b2^2*kx + b8^2*ky + b14^2*kz;
BKB(:,9) = b2*b3*kx + b8*b9*ky + b14*b15*kz;
BKB(:,10) = b2*b4*kx + b8*b10*ky + b14*b16*kz;
BKB(:,11) = b2*b5*kx + b8*b11*ky + b14*b17*kz;
BKB(:,12) = b2*b6*kx + b8*b12*ky + b14*b18*kz;
BKB(:,13) = b1*b3*kx + b7*b9*ky + b13*b15*kz;
BKB(:,14) = b2*b3*kx + b8*b9*ky + b14*b15*kz;
BKB(:,15) = b3^2*kx + b9^2*ky + b15^2*kz;
BKB(:,16) = b3*b4*kx + b9*b10*ky + b15*b16*kz;
BKB(:,17) = b3*b5*kx + b9*b11*ky + b15*b17*kz;
BKB(:,18) = b3*b6*kx + b9*b12*ky + b15*b18*kz;
BKB(:,19) = b1*b4*kx + b7*b10*ky + b13*b16*kz;
BKB(:,20) = b2*b4*kx + b8*b10*ky + b14*b16*kz;
BKB(:,21) = b3*b4*kx + b9*b10*ky + b15*b16*kz;
BKB(:,22) = b4^2*kx + b10^2*ky + b16^2*kz;
BKB(:,23) = b4*b5*kx + b10*b11*ky + b16*b17*kz;
BKB(:,24) = b4*b6*kx + b10*b12*ky + b16*b18*kz;
BKB(:,25) = b1*b5*kx + b7*b11*ky + b13*b17*kz;
BKB(:,26) = b2*b5*kx + b8*b11*ky + b14*b17*kz;
BKB(:,27) = b3*b5*kx + b9*b11*ky + b15*b17*kz;
BKB(:,28) = b4*b5*kx + b10*b11*ky + b16*b17*kz;
BKB(:,29) = b5^2*kx + b11^2*ky + b17^2*kz;
BKB(:,30) = b5*b6*kx + b11*b12*ky + b17*b18*kz;
BKB(:,31) = b1*b6*kx + b7*b12*ky + b13*b18*kz;
BKB(:,32) = b2*b6*kx + b8*b12*ky + b14*b18*kz;
BKB(:,33) = b3*b6*kx + b9*b12*ky + b15*b18*kz;
BKB(:,34) = b4*b6*kx + b10*b12*ky + b16*b18*kz;
BKB(:,35) = b5*b6*kx + b11*b12*ky + b17*b18*kz;
BKB(:,36) = b6^2*kx + b12^2*ky + b18^2*kz;
```