Blitz logo

Blitz Support :

From: Navneet Dalal (Navneet.Dalal_at_[hidden])
Date: 2003-11-17 10:57:00


Hi Ben,

I would try to answer to the extent I know about blitz. If I am wrong, it
would be nice if someone can correct me.

> I have created a nested homogeneous array as such:
> blitz::Array<blitz::TinyMatrix<double,6,6>,3> c_model;
> and then resized such that
> c_model.resize(nx,ny,nz);

TIP: you can also initalize the matrix in one go (if you want to)
for e.g.

blitz::Array<blitz::TinyMatrix<double,6,6>,3> c_model(nx,ny,nz);

> *** 1. *** I am sure there is a simple way to initialize (or perform
> other functions with) the TinyMatrices, I have searched the manual, and
> the examples, and the support mailings, and cant figure it. Here is
> intuitive code for what I am trying to do (which does work, though it is
> not the prettiest and may not make use of blitz-optimization):
>
> for(int i=0;i<nx;i++){
> for(int j=0;j<ny;j++){
> for(int k=0;k<nz;k++){
> //(c11 etc are all type double values)
> c_model(i,j,k) =
> c11,c12,c13,c14,c15,c16,
> 0.0,c22,c23,c24,c25,c26,
> 0.0,0.0,c33,c34,c35,c36,
> 0.0,0.0,0.0,c44,c45,c46,
> 0.0,0.0,0.0,0.0,c55,c56,
> 0.0,0.0,0.0,0.0,0.0,c66;
> }
> }
> }

Iterators should work.
for e.g. try this

typedef blitz::Array<blitz::TinyMatrix<double,6,6>,3> Array3DOfMatrix;
Array3DOfMatrix c_model(nx,ny,nz);
for (Array3DOfMatrix::iterator iter= c_model.begin();
        iter != c_model.end(); ++iter)
{
        *iter = c11,c12,c13,c14,c15,c16,
                      0.0,c22,c23,c24,c25,c26,
                      0.0,0.0,c33,c34,c35,c36,
                      0.0,0.0,0.0,c44,c45,c46,
                      0.0,0.0,0.0,0.0,c55,c56,
                      0.0,0.0,0.0,0.0,0.0,c66;
}

> I have tried other methods like
> blitz::Range I(0,nx-1), J(0,ny-1), K(0,nz-1);
> c_model(I,J,K) = etc....

This code will not work. Because, c_model(I,J,K) returns a sub array.
Now Arrays themservles also have , operators overloaded. So I think the
compiler
try to apply , operator of Arrays. What you want is , operators of
TinyMatrix.

It may be a better idea to create a class for initialization. You can
overload operator()
for initalization. And use std C++ for_each algorithm (you can search
google with keywords "for_each" and functors" for detailed techniques)

Another idea can be: You create a TinyMatrix<double,6,6> object and
initialize it.
for e.g.
TinyMatrix<double,6,6> initObj;
// initalize it
then
c_model = initObj;
or
c_model(/* some range */) = initObj;

However, I am not sure about how efficient it would be for large arrays?

> *** 2. *** How is matrix arithmetic conducted for nested arrays of
> TinyMatrix? For example, given
> Array<TinyMatrix<double,2,2>,3> A(50,50,50), B(50,50,50), C(50,50,50);
> is the following expression legitimate
> C = A + B;
> and will it make C a 50*50*50 array of TinyMatrices such that the
> C(0,0,0)TinyMatrix = B(0,0,0)TinyMatrix + B(0,0,0)TinyMatrix;
> C(0,0,1)TinyMatrix = B(0,0,1)TinyMatrix + B(0,0,1)TinyMatrix;
> C(0,0,2)TinyMatrix = ....etc, ie, calculated truly ELEMENT-WISE?
> If not, how is this accomplished? I feel sure that if this is once
> clarified, most people (like me) will be able to extend this to other
> cases (like A*B, pow2(),...).

This will be calculated ELMENT-WISE.
As far as Array class is concerned:
this code is equaivalent to
for (int i=A.lbound(0); i<A.ubound(0); ++i)
// for j
// for k
C(i, j, k) = A(i,j,k) + B(i,j,k);

Now, if you has defined + operator for TinyMatrix class, it should work.
If you want to use, *, you should have * operator defined for TinyMatrix.

If you want to define your own math functions, look for
BZ_DECLARE_FUNCTION

documentation.

>
> Thanks,
> Ben.

-- 
Navneet DALAL               http://www.inrialpes.fr/lear/people/Dalal
INRIA Rhone-Alpes                       Ph(work): +33 (0)476 61 54 97
ZIRST-655, av. de l'Europe - 38334      FAX     : +33 (0)476 61 54 54
Montbonnot St. Martin, France           Mobile  : +33 (0)677 54 33 33