kill(all)$

fluid : divergence of tensor ,version 1.0,part 2
peter.vlasschaert@gmail.com,22/05/2019

website 
=======

see :part 1,fluid : divergence of tensor ,version 1.0

nabla : operator  (grad operator on a tensor).
======================================
x:1  - direction
y:1  - direction
z:1  - direction

cartesian coordinates.
===================

p1:grad(m):=e3*('diff(m,z,1))+e2*('diff(m,y,1))+e1*('diff(m,x,1));

Vector : V=V(u,v,w)
================

p2: V= u*e1+v*e2+w*e3;

coef : e1,e2,e3 from  V
----------------------------------

p2a:ratcoef(rhs(p2),e1);
p2b:ratcoef(rhs(p2),e2);
p2c:ratcoef(rhs(p2),e3);

p2d:args(rhs(p2));

Tensor : Tij  {i,j  = 1,2,3}
=====================
t: tensor , 9 components
=>  tTij

rule :scalar product ( kronecker delta function)
------------------------------

p3: [e1*e1=1,e2*e2=1,e3*e3=1,e1*e2=0,e2*e3=0,e1*e3 = 0];

given : tensor 
============

1e)  simp : by default   'true'
-----------------------------------------

simp;

change  'simp' 
----------------------

simp:false;

2e)  tensor representation
-----------------------------------------

a1:T11*e1*e1+T12*e1*e2+T13*e1*e3;
a2:T21*e2*e1+T22*e2*e2+T23*e2*e3;
a3:T31*e3*e1+T32*e3*e2+T33*e3*e3;

rem : don't use simp :false ?
------------------------------------------
ei*ei = (ei)^2

p3a:tTij =a1+ a2+a3;

lhs :tensor
=========

p3b1:lhs(p3a);

rhs :tensor
=========

p3b2a:rhs(p3a);

p3b2b:args(p3b2a);

p3b2b1:p3b2b[1];
p3b2b2:v2=p3b2b[2];
p3b2b3:v3=p3b2b[3];

p3b2b1a:part(p3b2b[1],1);
p3b2b2a:part(p3b2b[1],2);
p3b2b3a:part(p3b2b[1],3);

p4: part(part(p3b2b[1],1),2)*part(part(p3b2b[1],1),1)*part(part(p3b2b[1],1),3);

matrix : tensor representation
=========================

p4a :matrix(
 [T11*e1*e1,T12*e1*e2,T13*e1*e3], 
 [T21*e2*e1,T22*e2*e2,T23*e2*e3], 
 [T31*e3*e1,T32*e3*e2,T33*e3*e3]
);

to find element matrix : 'p4a'
------------------------------------------

p4b1:p4a[1][1];

p4c:flatten(args(p4a));

first element :p4c 'parts'
------------------------------------

p4c1:part(p4c,1,1);
p4c2:part(p4c,1,2);
p4c3:part(p4c,1,3);

convert :  list to set
-----------------------------

p4c4:setify(p4c);

vector representation
==================

p5:p2d;

convert :  list to set
-----------------------------

p5a:setify(p5);

make :cartesian_product(p5a,p4c4)

p6:cartesian_product(p5a,p4c4);

back to:list
==========

p6a:listify(p6);

p6a1:p6a[1];

p6a11:part(p6a,2);

p6a2:p6a1[1];
p6a2a:part(p6a11,1);
p6a2a1:part(part(p6a,1),1);
p6a3:p6a1[2];
p6a2b:part(p6a11,2);
p6a2b1:part(part(p6a,1),2);

p6a31:part(p6a3,1);
p6a32:part(p6a3,2);
p6a33:part(p6a3,3);

p6a:part(p6a2,1);
p6b:part(p6a3,2);
p6c:p6a*p6b;
p6d:ev(subst(p3,p6c),simp);

simp;

p4a[1][1];

p7:matrix(
 [0,0,0], 
 [0,0,0], 
 [0,0,0]
);

how to refill matrix  , 

simp :true;

for i:1 thru 3 
 do(
 for j:1 thru 3
     do(                    
   ev(p7[i][j] : part(p4a,i,j),simp:false)
    ));

false : doesn't work , because full evaluation.

simp;

p7;

tensor : representation.
====================
maxima : representation for tTij

simp :false;

p8a:matrix(
 [e1*T11*e1,e1*T12*e2,e1*T13*e3], 
 [e2*T21*e1,e2*T22*e2,e2*T23*e3], 
 [e3*T31*e1,e3*T32*e2,e3*T33*e3]
);

p8b::matrix(
 [e1,e1,e1], 
 [e2,e2,e2], 
 [e3,e3,e3]
);

vector : representation
===================

p9a:matrix([e1*u,e2*v,e3*w]);
p9b:matrix([e1,e2,e3]);

 multiplication:vector with tensor.
============================

1e)  matrix  to  list.
---------------------------

p10a:flatten(args(p9b));
p10b:flatten(args(p8b));

2e) list to set.
-------------------------
use : cartesian_product(,)

p10a1:setify(p10a);
p10b1:setify(p10b);

p10c1:cartesian_product(p10a1,p10b1);

3e)  set to list
---------------------

p11a:listify(p10c1);

p11b:length(p11a);

p11a1:p11a[1];
p11a2:p11a[1][1];
p11a3:p11a[1][2];

4e)  rule matrix
----------------------
see : 'p3'

empty list 'h'
-------------------

h:[];

simp:true;

for i:1 thru p11b
 do(  if p11a[i][1] = p11a[i][2]  then
             h:endcons(p11a[i][1],h)
         else
            h:endcons(0,h)
         );

h;

h[3];

simp:true;

h2:[];

for i:1 thru length(h)
do( if h[i] ≠ 0 then
         h2:endcons(h[i],h2)
      );

h2;

make list from entries of a matrix.
--------------------------------------------------

simp:false;

p12a:list_matrix_entries(p8a);

5e) division list by list
-------------------------------------------

c:ev(p12a/h2,simp);

c[1];

d:ev(p9a/p9b,simp);

d[1][1];

6) create list  h1
------------------------

simp:true;

for i:1  thru length(h2)
do(
    if h2[i]=e1 then c[i]:c[i]*d[1][1],
    if h2[i]=e2 then c[i]:c[i]*d[1][2],
    if h2[i]=e3 then c[i]:c[i]*d[1][3]
);

p13:c;

final result : scalar product (vector,tensor).
----------------------------------------------------------------

several methods for a sum of list
============================

use : sum 'list'

p14a:sum(c[i],i,1,length(c));

use: apply  'list'

p14b:apply("+",c);

use : lsum  'list'

p14c:lsum(i,i,c);