![]() |
Blitz Support : |
From: Ben McLean \(finlaylabs\) (bmclean_at_[hidden])
Date: 2003-11-15 07:17:36
Blitz seems to be providing a relatively mature class, but I am having trouble with some of the basics of implementation. Some areas are not covered very completely in the docs or examples... Here are a couple of questions which I cannot find nor can I figure out, despite hours of random code-writing :-). Many basic operations may be simple and are well explained for the case of scalar arrays, but my questions mainly relate to how to do the same basic operations with nested TinyMatrix arrays.
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);
*** 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;
}
}
}
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....
but I cannot seem to find something that works, except by using for() loops, but I guess this is not the most elegant or efficient solution. I have found the
Array<T,N>::iterator begin();
section of the manual, but I cannot make heads or tails of it in the context of nested arrays (sadly I am still quite new to C++, but working on my knowlege every day...). Could someone please give me a couple of short code examples for how to accomplish the above, for every TinyMatrix of c_model, or for a lesser range of c_model?
*** 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(),...).
Thanks,
Ben.