KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
amgcl_csr_conversion_utilities.h
Go to the documentation of this file.
1 
2 // | / |
3 // ' / __| _` | __| _ \ __|
4 // . \ | ( | | ( |\__ \.
5 // _|\_\_| \__,_|\__|\___/ ____/
6 // Multi-Physics
7 //
8 // License: BSD License
9 // Kratos default license: kratos/license.txt
10 //
11 // Main authors: Denis Demidov
12 // Riccardo Rossi
13 //
14 //
15 
16 #if !defined(KRATOS_CSR_CONVERSION_UTILITIES_H_INCLUDED)
17 #define KRATOS_CSR_CONVERSION_UTILITIES_H_INCLUDED
18 
19 // System includes
20 
21 // External includes
22 #include <amgcl/backend/builtin.hpp>
23 #include <amgcl/adapter/zero_copy.hpp>
24 #include <span/span.hpp>
25 
26 // Project includes
27 #include "containers/csr_matrix.h"
28 
29 namespace Kratos
30 {
31 
36 {
37 
38 public:
39 
43  template< class TDataType, class TIndexType >
46  {
48  rA.size1(),
49  rA.index1_data().begin(),
50  rA.index2_data().begin(),
51  rA.value_data().begin()
52  );
53  pAmgcl->ncols = rA.size2();
54  pAmgcl->own_data = false;
55 
56  return pAmgcl;
57  }
58 
59 
60  //Note that we deliberately return a unique_ptr as it can be moved to a shared_ptr as needed
61  template< class TDataType, class TIndexType >
63  typename amgcl::backend::builtin<TDataType>::matrix& rA
64  )
65  {
66  auto pAconverted = Kratos::make_unique<CsrMatrix<TDataType, TIndexType>>();
67 
68  if(rA.own_data == false){ //if rA is not the owner, Aconverted cannot be
69  pAconverted->SetIsOwnerOfData(false);
70  }
71  else{ //if rA is the owner, transfer ownership to the csr_matrix
72  rA.own_data = false;
73  pAconverted->SetIsOwnerOfData(true);
74  }
75 
76  pAconverted->SetRowSize(rA.nrows);
77  pAconverted->SetColSize(rA.ncols);
78  pAconverted->AssignIndex1Data((TIndexType*)(rA.ptr), rA.nrows+1);
79  pAconverted->AssignIndex2Data((TIndexType*)(rA.col), rA.nnz);
80  pAconverted->AssignValueData((TDataType*)(rA.val), rA.nnz);
81  return pAconverted;
82  }
83 
84  //Note that we deliberately return a unique_ptr as it can be moved to a shared_ptr as needed
85  template< class TDataType, class TIndexType >
88  )
89  {
90  const auto pAamgcl = ConvertToAmgcl<TDataType,TIndexType>(rA);
91 
92  const auto pAamgcl_transpose = amgcl::backend::transpose(*pAamgcl);
93 
94  return ConvertToCsrMatrix<TDataType,TIndexType>(*pAamgcl_transpose);
95  }
96 
97 };
98 
99 }
100 
101 #endif // KRATOS_CSR_CONVERSION_UTILITIES_H_INCLUDED
Definition: amgcl_csr_conversion_utilities.h:36
static CsrMatrix< TDataType, TIndexType >::Pointer Transpose(CsrMatrix< TDataType, TIndexType > &rA)
Definition: amgcl_csr_conversion_utilities.h:86
static Kratos::shared_ptr< typename amgcl::backend::builtin< TDataType >::matrix > ConvertToAmgcl(const CsrMatrix< TDataType, TIndexType > &rA)
Definition: amgcl_csr_conversion_utilities.h:44
static CsrMatrix< TDataType, TIndexType >::UniquePointer ConvertToCsrMatrix(typename amgcl::backend::builtin< TDataType >::matrix &rA)
Definition: amgcl_csr_conversion_utilities.h:62
This class implements "serial" CSR matrix, including capabilities for FEM assembly.
Definition: csr_matrix.h:60
Kratos::span< TDataType > & value_data()
Definition: csr_matrix.h:273
IndexType size1() const
Definition: csr_matrix.h:240
IndexType size2() const
Definition: csr_matrix.h:245
Kratos::span< IndexType > & index2_data()
Definition: csr_matrix.h:269
Kratos::span< IndexType > & index1_data()
Definition: csr_matrix.h:265
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27