-
Notifications
You must be signed in to change notification settings - Fork 247
Porting to AMatrix
This page provides a list of common changes for migration from ublas to AMatrix
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
withDenseVector
- Replacing the
boost::numeric::ublas::matrix
withDenseMatrix
- Replacing the
boost::numeric::ublas::bounded_vector
withBoundedVector
- Replacing the
boost::numeric::ublas::bounded_matrix
withBoundedMatrix
- Replacing the
bounded_vector
withBoundedVector
- Replacing the
bounded_matrix
withBoundedMatrix
- Relplacing the
matrix<
withDenseMatrix<
NOTE: the<
character should be included in this step to avoid unnecessary changes - Replacing the
boost::numeric::ublas::prod
withprod
- Replacing the
boost::numeric::ublas::trans
withtrans
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)
tovector.resize(new_size, false)
- Passing false to matrix resize:
matrix.resize(size1,size2)
tomatrix.resize(size1,size2, false)
- There is no constructor with value for matrix and vector. Please use
ScalarMatrix
for that:Matrix m(size1,size2, value)
toMatrix m = ScalarMatrix(size1,size2, value)
-
IdentityMatrix
is only square and accept one size:IdentityMatrix(size,size)
toIdentityMatrix(size)
- The
array_1d
does not have constructor with size:array_1d<double,3> a(3)
toarray_1d<double,3> a
- Changing the ublas
vector<double>
toVector
- Changing the ublas
vector<other_type>
toDenseVector<other_type>
- Amatrix classes does not have
oprator()
and please use the[]
instead:v(i)
tov[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
andLocalSpace::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 withKRATOS_USE_AMATRIX
macro in order to maintain the compatibility to ublas - Replacing the
matrix_row(rVariables.Strain.Eigen.Vectors,i)
withrow((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.
Sometimes you may want to use Matrix
and Vector
types within an Internals
namespace for your class, but the names Kratos::Internals::Matrix
and Kratos::Internals::Vectors
are already taken when you compile Kratos with AMatrix. The name clash may manifest with an error like:
error: invalid use of template-name ‘Kratos::Internals::Matrix’ without an argument list
typedef Matrix MatrixType;
^~~~~~
/home/jcotela/Kratos/kratos/utilities/helper_classes_for_constraint_builder.h:431:13: note: class template argument deduction is only available with -std=c++17 or -std=gnu++17
In file included from /home/jcotela/Kratos/kratos/includes/ublas_interface.h:35,
from /home/jcotela/Kratos/kratos/includes/serializer.h:31,
from /home/jcotela/Kratos/kratos/includes/model_part.h:33,
from /home/jcotela/Kratos/kratos/python/add_strategies_to_python.cpp:25:
/home/jcotela/Kratos/kratos/includes/amatrix_interface.h:39:7: note: ‘template<class TDataType, long unsigned int TSize1, long unsigned int TSize2> class Kratos::Internals::Matrix’ declared here
class Matrix : public AMatrix::MatrixExpression<Matrix<TDataType, TSize1, TSize2>,
^~~~~~
If this happens, declare your local MatrixType using the complete type name:
namespace Kratos
{
namespace Internals
{
//...
typedef Kratos::Matrix MatrixType;
typedef Kratos::Vector VectorType;
//...
}
}
Keep in mind that the SparseSpace type used as template argument to define strategies and builder and solvers still uses ublas types. This means that you will probably need to update the add_whatever_to_python.cpp
files in your application.
If you have a type definition that looks like
typedef UblasSpace<double, CompressedMatrix, Vector > SparseSpaceType;
keep in mind that the Vector
type has been redefined in AMatrix, so you need to point back to the ublas type:
typedef UblasSpace<double, CompressedMatrix, boost::numeric::ublas::vector<double>> SparseSpaceType;
Note that this may require adding an include for "boost/numeric/ublas/matrix.hpp"
.
- Getting Kratos (Last compiled Release)
- Compiling Kratos
- Running an example from GiD
- Kratos input files and I/O
- Data management
- Solving strategies
- Manipulating solution values
- Multiphysics
- Video tutorials
- Style Guide
- Authorship of Kratos files
- Configure .gitignore
- How to configure clang-format
- How to use smart pointer in Kratos
- How to define adjoint elements and response functions
- Visibility and Exposure
- Namespaces and Static Classes
Kratos structure
Conventions
Solvers
Debugging, profiling and testing
- Compiling Kratos in debug mode
- Debugging Kratos using GDB
- Cross-debugging Kratos under Windows
- Debugging Kratos C++ under Windows
- Checking memory usage with Valgind
- Profiling Kratos with MAQAO
- Creating unitary tests
- Using ThreadSanitizer to detect OMP data race bugs
- Debugging Memory with ASAN
HOW TOs
- How to create applications
- Python Tutorials
- Kratos For Dummies (I)
- List of classes and variables accessible via python
- How to use Logger
- How to Create a New Application using cmake
- How to write a JSON configuration file
- How to Access DataBase
- How to use quaternions in Kratos
- How to do Mapping between nonmatching meshes
- How to use Clang-Tidy to automatically correct code
- How to use the Constitutive Law class
- How to use Serialization
- How to use GlobalPointerCommunicator
- How to use PointerMapCommunicator
- How to use the Geometry
- How to use processes for BCs
- How to use Parallel Utilities in futureproofing the code
- Porting to Pybind11 (LEGACY CODE)
- Porting to AMatrix
- How to use Cotire
- Applications: Python-modules
- How to run multiple cases using PyCOMPSs
- How to apply a function to a list of variables
- How to use Kratos Native sparse linear algebra
Utilities
Kratos API
Kratos Structural Mechanics API