Some aspects of programing
Begin to understand a code is sometimes a headache. However, we will settle for only understand the mathematical key aspects.
In Kratos many mathematical operations and operations with variable use the library UBLAS.
for exemple, if i want to this operation or another operation:
A[a,b]=B[c][d].
X+=Y.
where A an B are matrices and a, b, c d are integers. The word "noalias" is necesary because make the operations faster.
you should use it in all matrix operations. For example
noalias(A) = B.
noalias(X) += Y.
noalias(Y) = prod(A,x).
noalias(Y) = prod(trans(A),x).
prod: Matrix Products trans:Transposed a matrix my_matrix.resize: set the matrix with a new dimension
Other operation that we can do is to size a matrix. when we put " false" we are setting all values of the matrix o vector to be zero. The best way is for exemple:
if( A.size1()!=3 || A.size2()!=3) A.resize( 3,3,false)
where A can be a matrix or a vector.
We can initialize with a null matrix or vector
for exemple
noalias(A)=ZeroVector(3)
noalias(A)=ZeroMatrix(4,4)
Some operations with vectors
Let see the follow exemple:
- include <boost/numeric/ublas/vector.hpp>
int main () {
using namespace boost::numeric::ublas; vector<double> v1 (3), v2(3) ; for (unsigned i = 0; i < v.size (); ++ i) v1 (i) = i; v2 (i) = i+1;
std::cout << sum (v) << std::endl; std::cout << norm_1 (v) << std::endl; std::cout << norm_2 (v) << std::endl; std::cout <<inner_prod (v1, v2)<<std::endl; std::cout <<outer_prod (v1, v2)<<std::endl;
}
sum: It is the sum of each component of the vector norm1: It is the root of sum of each component of the vector inner_prod : scalar product outer_product: tensor product. Only for vectors
Remember put the world Noalias in any operations
Some operations with Matrix
There are too many oparations that we can do. If you want to learn more visit the page
http://www.boost.org/doc/libs/1_35_0/libs/numeric/ublas/doc/index.htmLink title
here are the most importants operations that you will use in Kratos.
Don't forget to type noalias in the left of the opertions.