Skip to content

Porting to AMatrix

Pooyan Dadvand edited this page Sep 10, 2018 · 16 revisions

This page provides a list of common changes for migration from ublas to AMatrix

Using Kratos vector and matrix aliases

It is recommended to use Kratos vector and matrix aliases instead of ones define by ublas:

  • Using Vector for a dynamic size vector of double
  • Using Matrix for a dynamic size matrix of double
  • Replacing the boost::numeric::ublas::vector with DenseVector
  • Replacing the boost::numeric::ublas::matrix with DenseMatrix
  • Replacing the boost::numeric::ublas::bounded_vector with BoundedVector
  • Replacing the boost::numeric::ublas::bounded_matrix with BoundedMatrix
  • Replacing the bounded_vector with BoundedVector
  • Replacing the bounded_matrix with BoundedMatrix
  • Relplacing the matrix< with DenseMatrix< NOTE: the < character should be included in this step to avoid unnecessary changes
  • Replacing the boost::numeric::ublas::prod with prod
  • Replacing the boost::numeric::ublas::trans with trans

Other common changes

There are differences in interface and also behavior of these to libraries. The most important ones are the resize which does not preserve the values and there is no operator() for vector. Here is the list of common changes:

  • Passing false to vector resize: vector.resize(new_sizse) to vector.resize(new_size, false)
  • Passing false to matrix resize: matrix.resize(size1,size2) to matrix.resize(size1,size2, false)
  • There is no constructor with value for matrix and vector. Please use ScalarMatrix for that: Matrix m(size1,size2, value) to Matrix m = ScalarMatrix(size1,size2, value)
  • IdentityMatrix is only square and accept one size: IdentityMatrix(size,size) to IdentityMatrix(size)
  • The array_1d does not have constructor with size: array_1d<double,3> a(3) to array_1d<double,3> a
  • Changing the ublas vector<double> to Vector
  • Changing the ublas vector<other_type> to DenseVector<other_type>
  • Amatrix classes does not have oprator() and please use the [] instead: v(i) to v[i]
  • data() method returns a raw pointer to the first member and not an iterator
  • when dealing with spaces please take care of using correctly the SparseSpace::DenseVector and LocalSpace::DenseVector as they are different types now.
  • There is no project function in amatrix. Instead there is a SubMatrix expression: AMatrix::SubMatrix<MatrixType>a_sub_matrix(original_matrix, sub_index1, sub_index2, sub_size1, sub_size2); The arguments are different so it might be used with KRATOS_USE_AMATRIX macro in order to maintain the compatibility to ublas
  • Replacing the matrix_row(rVariables.Strain.Eigen.Vectors,i) with row((rVariables.Strain.Eigen.Vectors,i)

In order to maintain the backward compatibility until all applications are migrated a A new KRATOS_USE_AMATRIX macro is added which is used when the AMatrix interface is different than Ublas. The idea is to remove KRATOS_USE_AMATRIX macro after the migration, so please use it wisely and as less as possible.

Project information

Getting Started

Tutorials

Developers

Kratos structure

Conventions

Solvers

Debugging, profiling and testing

HOW TOs

Utilities

Kratos API

Kratos Structural Mechanics API

Clone this wiki locally