43 MultValueNoAdd(
const Type& _Val) : Factor(_Val)
49 inline Type operator () (
const Type& elem)
const
63 MultAndAddValue(
const Type& _Val) : Factor(_Val)
69 inline Type operator () (
const Type& elem1,
const Type& elem2)
const
71 return elem1 * Factor + elem2;
83 template <
class TDataType,
class TMatrixType,
class TVectorType>
86 template <
class TDataType>
89 template <
class TDataType>
119 template<
class TDataType,
class TMatrixType,
class TVectorType>
211 template<
typename TColumnType>
214 if (rX.size() != rM.size1())
215 rX.resize(rM.size1(),
false);
217 for (std::size_t
i = 0;
i < rM.size1();
i++) {
223 template<
typename TColumnType>
226 for (std::size_t
i = 0;
i < rM.size1();
i++) {
247 const int size = rX.size();
248 if (rY.size() !=
static_cast<unsigned int>(size))
249 rY.resize(size,
false);
251 #pragma omp parallel for
252 for (
int i = 0;
i < size;
i++)
264 const int size =
static_cast<int>(rX.size());
266 TDataType total = TDataType();
267 #pragma omp parallel for reduction( +: total), firstprivate(size)
268 for(
int i =0;
i<size; ++
i)
269 total += rX[
i]*rY[
i];
280 return std::sqrt(
Dot(rX, rX));
285 TDataType aux_sum = TDataType();
286 #pragma omp parallel for reduction(+:aux_sum)
287 for (
int i=0; i<static_cast<int>(rA.size1()); ++
i) {
288 for (
int j=0; j<static_cast<int>(rA.size2()); ++
j) {
289 aux_sum += std::pow(rA(
i,
j),2);
292 return std::sqrt(aux_sum);
295 static TDataType
TwoNorm(
const compressed_matrix<TDataType> & rA)
297 TDataType aux_sum = TDataType();
299 const auto& r_values = rA.value_data();
301 #pragma omp parallel for reduction(+:aux_sum)
302 for (
int i=0; i<static_cast<int>(r_values.size()); ++
i) {
303 aux_sum += std::pow(r_values[
i] , 2);
305 return std::sqrt(aux_sum);
315 TDataType aux_sum = TDataType();
316 #pragma omp parallel for reduction(+:aux_sum)
317 for (
int i=0; i<static_cast<int>(rA.size1()); ++
i) {
318 for (
int j=0; j<static_cast<int>(rA.size2()); ++
j) {
320 aux_sum += std::abs(rA(
i,
j));
327 static TDataType
JacobiNorm(
const compressed_matrix<TDataType>& rA)
329 TDataType aux_sum = TDataType();
331 typedef typename compressed_matrix<TDataType>::const_iterator1 t_it_1;
332 typedef typename compressed_matrix<TDataType>::const_iterator2 t_it_2;
334 for (t_it_1 it_1 = rA.begin1(); it_1 != rA.end1(); ++it_1) {
335 for (t_it_2 it_2 = it_1.begin(); it_2 != it_1.end(); ++it_2) {
336 if (it_2.index1() != it_2.index2()) {
337 aux_sum += std::abs(*it_2);
346 axpy_prod(rA, rX, rY,
true);
352 axpy_prod(rA, rX, rY,
true);
354 ParallelProductNoAdd(rA, rX, rY);
358 template<
class TOtherMatrixType >
361 boost::numeric::ublas::axpy_prod(rX, rA, rY,
true);
366 typename MatrixType::iterator1 a_iterator =
A.begin1();
367 std::advance(a_iterator,
i);
368 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
369 return ( std::distance(a_iterator.begin(), a_iterator.end()));
371 return ( std::distance(begin(a_iterator, boost::numeric::ublas::iterator1_tag()),
372 end(a_iterator, boost::numeric::ublas::iterator1_tag())));
379 typename MatrixType::iterator1 a_iterator =
A.begin1();
380 std::advance(a_iterator,
i);
381 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
382 for (
typename MatrixType::iterator2 row_iterator = a_iterator.begin();
383 row_iterator != a_iterator.end(); ++row_iterator)
386 for (
typename MatrixType::iterator2 row_iterator = begin(a_iterator,
387 boost::numeric::ublas::iterator1_tag());
388 row_iterator !=
end(a_iterator,
389 boost::numeric::ublas::iterator1_tag()); ++row_iterator)
392 neighbors.push_back(row_iterator.index2());
409 typename VectorType::iterator x_iterator = rX.begin();
410 typename VectorType::iterator end_iterator = rX.end();
411 while (x_iterator != end_iterator)
413 *x_iterator = -*x_iterator;
418 const int size = rX.size();
420 #pragma omp parallel for firstprivate(size)
421 for (
int i = 0;
i < size;
i++)
431 const int size = rX.size();
433 #pragma omp parallel for firstprivate(size)
434 for (
int i = 0;
i < size;
i++)
455 const int size = rY.size();
456 if (rX.size() !=
static_cast<unsigned int>(size) )
457 rX.resize(size,
false);
461 #pragma omp parallel for
462 for (
int i = 0;
i < size;
i++)
467 #pragma omp parallel for
468 for (
int i = 0;
i < size;
i++)
473 #pragma omp parallel for
474 for (
int i = 0;
i < size;
i++)
495 const int size = rY.size();
496 if (rX.size() !=
static_cast<unsigned int>(size) )
497 rX.resize(size,
false);
501 #pragma omp parallel for
502 for (
int i = 0;
i < size;
i++)
507 #pragma omp parallel for
508 for (
int i = 0;
i < size;
i++)
513 #pragma omp parallel for
514 for (
int i = 0;
i < size;
i++)
555 std::fill(rX.begin(), rX.end(),
A);
560 rA.resize(
m,
n,
false);
565 pA->resize(
m,
n,
false);
575 pX->resize(
n,
false);
581 pA->resize(0, 0,
false);
587 pX->resize(0,
false);
590 template<
class TOtherMatrixType>
596 std::fill(rA.begin(), rA.end(), TDataType());
598 DataType* vals = rA.value_data().begin();
599 #pragma omp parallel for firstprivate(m)
600 for(
int i=0; i<static_cast<int>(
m); ++
i)
601 vals[
i] = TDataType();
607 rA.value_data().resize(
m);
609 std::fill(rA.value_data().begin(), rA.value_data().end(), TDataType());
611 TDataType* vals = rA.value_data().begin();
612 #pragma omp parallel for firstprivate(m)
613 for(
int i=0; i<static_cast<int>(
m); ++
i)
614 vals[
i] = TDataType();
622 std::fill(rX.begin(), rX.end(), TDataType());
624 const int size = rX.size();
625 #pragma omp parallel for firstprivate(size)
626 for(
int i=0;
i<size; ++
i)
631 template<
class TOtherMatrixType>
635 std::fill(rA.begin(), rA.end(), TDataType());
637 TDataType* vals = rA.value_data().begin();
638 const int size = rA.value_data().end() - rA.value_data().begin();
639 #pragma omp parallel for firstprivate(size)
640 for(
int i=0;
i<size; ++
i)
641 vals[
i] = TDataType();
645 inline static void SetToZero(compressed_matrix<TDataType>& rA)
648 std::fill(rA.value_data().begin(), rA.value_data().end(), TDataType());
650 TDataType* vals = rA.value_data().begin();
651 const int size = rA.value_data().end() - rA.value_data().begin();
652 #pragma omp parallel for firstprivate(size)
653 for(
int i=0;
i<size; ++
i)
654 vals[
i] = TDataType();
661 std::fill(rX.begin(), rX.end(), TDataType());
663 const int size = rX.size();
664 #pragma omp parallel for firstprivate(size)
665 for(
int i=0;
i<size; ++
i)
670 template<
class TOtherMatrixType,
class TEquationIdVectorType>
673 TOtherMatrixType& LHS_Contribution,
674 TEquationIdVectorType& EquationId
677 unsigned int system_size =
A.size1();
678 unsigned int local_size = LHS_Contribution.size1();
680 for (
unsigned int i_local = 0; i_local <
local_size; i_local++)
682 unsigned int i_global = EquationId[i_local];
683 if (i_global < system_size)
685 for (
unsigned int j_local = 0; j_local <
local_size; j_local++)
687 unsigned int j_global = EquationId[j_local];
688 if (j_global < system_size)
689 A(i_global, j_global) += LHS_Contribution(i_local, j_local);
711 const std::size_t system_size = rA.size1();
713 const double* Avalues = rA.value_data().begin();
714 const std::size_t* Arow_indices = rA.index1_data().begin();
717 const double zero_tolerance = std::numeric_limits<double>::epsilon();
720 const double scale_factor =
GetScaleNorm(rProcessInfo, rA, ScalingDiagonal);
726 const std::size_t col_begin = Arow_indices[
Index];
727 const std::size_t col_end = Arow_indices[
Index + 1];
729 for (std::size_t
j = col_begin;
j < col_end; ++
j) {
730 if(std::abs(Avalues[
j]) > zero_tolerance) {
758 switch (ScalingDiagonal) {
762 KRATOS_ERROR_IF_NOT(rProcessInfo.
Has(BUILD_SCALE_FACTOR)) <<
"Scale factor not defined at process info" << std::endl;
763 return rProcessInfo.
GetValue(BUILD_SCALE_FACTOR);
781 const double* Avalues = rA.value_data().begin();
782 const std::size_t* Arow_indices = rA.index1_data().begin();
783 const std::size_t* Acol_indices = rA.index2_data().begin();
786 const std::size_t col_begin = Arow_indices[
Index];
787 const std::size_t col_end = Arow_indices[
Index+1];
788 for (std::size_t
j = col_begin;
j < col_end; ++
j) {
789 if (Acol_indices[
j] ==
Index ) {
790 return std::pow(Avalues[
j], 2);
796 return std::sqrt(diagonal_norm);
816 const double* Avalues = rA.value_data().begin();
817 const std::size_t* Arow_indices = rA.index1_data().begin();
818 const std::size_t* Acol_indices = rA.index2_data().begin();
821 const std::size_t col_begin = Arow_indices[
Index];
822 const std::size_t col_end = Arow_indices[
Index+1];
823 for (std::size_t
j = col_begin;
j < col_end; ++
j) {
824 if (Acol_indices[
j] ==
Index ) {
825 return std::abs(Avalues[
j]);
828 return std::numeric_limits<double>::lowest();
839 const double* Avalues = rA.value_data().begin();
840 const std::size_t* Arow_indices = rA.index1_data().begin();
841 const std::size_t* Acol_indices = rA.index2_data().begin();
844 const std::size_t col_begin = Arow_indices[
Index];
845 const std::size_t col_end = Arow_indices[
Index+1];
846 for (std::size_t
j = col_begin;
j < col_end; ++
j) {
847 if (Acol_indices[
j] ==
Index ) {
848 return std::abs(Avalues[
j]);
869 virtual std::string
Info()
const
878 rOStream <<
"UBlasSpace";
906 for (std::size_t
i = 0;
i < IndexArray.size();
i++)
907 pValues[
i] =
x[IndexArray[
i]];
912 template<
class TOtherMatrixType >
919 template<
class VectorType >
995 unsigned int number_of_threads = omp_get_max_threads();
996 unsigned int number_of_initialized_rows =
A.filled1() - 1;
997 CreatePartition(number_of_threads, number_of_initialized_rows, partition);
1001 int thread_id = omp_get_thread_num();
1002 int number_of_rows = partition[thread_id + 1] - partition[thread_id];
1003 typename compressed_matrix<TDataType>::index_array_type::const_iterator row_iter_begin =
A.index1_data().begin() + partition[thread_id];
1004 typename compressed_matrix<TDataType>::index_array_type::const_iterator index_2_begin =
A.index2_data().begin()+*row_iter_begin;
1005 typename compressed_matrix<TDataType>::value_array_type::const_iterator value_begin =
A.value_data().begin()+*row_iter_begin;
1009 partial_product_no_add(number_of_rows,
1014 partition[thread_id],
1020 static void CreatePartition(
unsigned int number_of_threads,
const int number_of_rows, DenseVector<unsigned int>& partitions)
1022 partitions.resize(number_of_threads + 1);
1023 int partition_size = number_of_rows / number_of_threads;
1025 partitions[number_of_threads] = number_of_rows;
1026 for (
unsigned int i = 1;
i < number_of_threads;
i++)
1027 partitions[
i] = partitions[
i - 1] + partition_size;
1034 static void partial_product_no_add(
1036 typename compressed_matrix<TDataType>::index_array_type::const_iterator row_begin,
1037 typename compressed_matrix<TDataType>::index_array_type::const_iterator index2_begin,
1038 typename compressed_matrix<TDataType>::value_array_type::const_iterator value_begin,
1040 unsigned int output_begin_index,
1046 int kkk = output_begin_index;
1047 typename MatrixType::index_array_type::const_iterator row_it = row_begin;
1048 for (
int k = 0;
k < number_of_rows;
k++)
1050 row_size = *(row_it + 1)-*row_it;
1052 TDataType
t = TDataType();
1054 for (
int i = 0;
i < row_size;
i++)
1055 t += *value_begin++ * (input_vec[*index2_begin++]);
1057 output_vec[kkk++] =
t;
bool Has(const Variable< TDataType > &rThisVariable) const
Checks if the data container has a value associated with a given variable.
Definition: data_value_container.h:382
TDataType & GetValue(const Variable< TDataType > &rThisVariable)
Gets the value associated with a given variable.
Definition: data_value_container.h:268
Utility class to update the values of degree of freedom (Dof) variables after solving the system.
Definition: dof_updater.h:40
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
Definition: amatrix_interface.h:41
Definition: reduction_utilities.h:128
Definition: reduction_utilities.h:190
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
utility function to do a sum reduction
Definition: reduction_utilities.h:68
A class template for handling data types, matrices, and vectors in a Ublas space.
Definition: ublas_space.h:121
TDataType DataType
The data type considered.
Definition: ublas_space.h:130
static void Set(VectorType &rX, TDataType A)
rX = A
Definition: ublas_space.h:553
typename Kratos::shared_ptr< TVectorType > VectorPointerType
The pointer to the vector type.
Definition: ublas_space.h:148
static void Resize(VectorType &rX, SizeType n)
Definition: ublas_space.h:568
static void Resize(MatrixType &rA, SizeType m, SizeType n)
Definition: ublas_space.h:558
static void Resize(VectorPointerType &pX, SizeType n)
Definition: ublas_space.h:573
std::size_t SizeType
The size type considered.
Definition: ublas_space.h:142
static constexpr bool IsDistributed()
Definition: ublas_space.h:889
static void UnaliasedAdd(VectorType &rX, const double A, const VectorType &rY)
Definition: ublas_space.h:485
static void Copy(VectorType const &rX, VectorType &rY)
rY = rX
Definition: ublas_space.h:241
static void GetColumn(unsigned int j, Matrix &rM, TColumnType &rX)
rXi = rMij
Definition: ublas_space.h:212
static void SetToZero(TOtherMatrixType &rA)
Definition: ublas_space.h:632
static void AssembleLHS(MatrixType &A, TOtherMatrixType &LHS_Contribution, TEquationIdVectorType &EquationId)
Definition: ublas_space.h:671
static void ScaleAndAdd(const double A, const VectorType &rX, const double B, const VectorType &rY, VectorType &rZ)
Definition: ublas_space.h:525
static TDataType TwoNorm(VectorType const &rX)
||rX||2
Definition: ublas_space.h:278
static void ResizeData(compressed_matrix< TDataType > &rA, SizeType m)
Definition: ublas_space.h:605
static TDataType Dot(VectorType const &rX, VectorType const &rY)
rX * rY
Definition: ublas_space.h:259
typename DofUpdaterType::UniquePointer DofUpdaterPointerType
The pointer to the DoF updater type.
Definition: ublas_space.h:154
static void GatherValues(const VectorType &x, const std::vector< std::size_t > &IndexArray, TDataType *pValues)
Definition: ublas_space.h:902
static IndexType Size1(MatrixType const &rM)
return number of rows of rM
Definition: ublas_space.h:197
static void TransposeMult(TOtherMatrixType &rA, VectorType &rX, VectorType &rY)
Definition: ublas_space.h:359
static void SetColumn(unsigned int j, Matrix &rM, TColumnType &rX)
Definition: ublas_space.h:224
static TDataType GetValue(const VectorType &x, std::size_t I)
Definition: ublas_space.h:896
UblasSpace()
Default constructor.
Definition: ublas_space.h:161
static void Mult(const compressed_matrix< TDataType > &rA, VectorType &rX, VectorType &rY)
Definition: ublas_space.h:349
static void ResizeData(VectorType &rX, SizeType m)
Definition: ublas_space.h:618
static double RowDot(unsigned int i, MatrixType &rA, VectorType &rX)
rA[i] * rX
Definition: ublas_space.h:540
static double GetScaleNorm(const ProcessInfo &rProcessInfo, const MatrixType &rA, const SCALING_DIAGONAL ScalingDiagonal=SCALING_DIAGONAL::NO_SCALING)
This method returns the scale norm considering for scaling the diagonal.
Definition: ublas_space.h:752
static bool WriteMatrixMarketVector(const char *pFileName, const VectorType &rV)
Definition: ublas_space.h:920
static bool WriteMatrixMarketMatrix(const char *pFileName, TOtherMatrixType &rM, const bool Symmetric)
Definition: ublas_space.h:913
typename Kratos::shared_ptr< TMatrixType > MatrixPointerType
The pointer to the matrix type.
Definition: ublas_space.h:145
static TDataType TwoNorm(const compressed_matrix< TDataType > &rA)
Definition: ublas_space.h:295
static void ScaleAndAdd(const double A, const VectorType &rX, const double B, VectorType &rY)
Definition: ublas_space.h:531
static void SetToZero(compressed_matrix< TDataType > &rA)
Definition: ublas_space.h:645
static double GetAveragevalueDiagonal(const MatrixType &rA)
This method returns the diagonal max value.
Definition: ublas_space.h:804
static void GraphNeighbors(IndexType i, TMatrixType &A, std::vector< IndexType > &neighbors)
Definition: ublas_space.h:376
static MatrixPointerType CreateEmptyMatrixPointer()
Definition: ublas_space.h:178
virtual ~UblasSpace()
Destructor.
Definition: ublas_space.h:166
static TDataType JacobiNorm(const compressed_matrix< TDataType > &rA)
Definition: ublas_space.h:327
static void SetValue(VectorType &rX, IndexType i, TDataType value)
Definition: ublas_space.h:546
static DofUpdaterPointerType CreateDofUpdater()
Definition: ublas_space.h:926
static void SetToZero(VectorType &rX)
Definition: ublas_space.h:658
KRATOS_CLASS_POINTER_DEFINITION(UblasSpace)
Pointer definition of UblasSpace.
static void Copy(MatrixType const &rX, MatrixType &rY)
rY = rX
Definition: ublas_space.h:234
static void Clear(VectorPointerType &pX)
Definition: ublas_space.h:584
static void Clear(MatrixPointerType &pA)
Definition: ublas_space.h:578
static VectorPointerType CreateEmptyVectorPointer()
Definition: ublas_space.h:183
static void InplaceMult(VectorType &rX, const double A)
Definition: ublas_space.h:400
TMatrixType MatrixType
The matrix type considered.
Definition: ublas_space.h:133
static void Assign(VectorType &rX, const double A, const VectorType &rY)
Definition: ublas_space.h:445
static IndexType Size(VectorType const &rV)
return size of vector rV
Definition: ublas_space.h:190
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: ublas_space.h:876
static TDataType TwoNorm(const Matrix &rA)
Definition: ublas_space.h:283
static double GetMinDiagonal(const MatrixType &rA)
This method returns the diagonal min value.
Definition: ublas_space.h:837
static double GetDiagonalNorm(const MatrixType &rA)
This method returns the diagonal norm considering for scaling the diagonal.
Definition: ublas_space.h:779
static IndexType Size2(MatrixType const &rM)
return number of columns of rM
Definition: ublas_space.h:204
std::size_t IndexType
The index type considered.
Definition: ublas_space.h:139
static double GetMaxDiagonal(const MatrixType &rA)
This method returns the diagonal max value.
Definition: ublas_space.h:814
static SizeType GraphDegree(IndexType i, TMatrixType &A)
Definition: ublas_space.h:364
static constexpr bool IsDistributedSpace()
Check if the UblasSpace is distributed.
Definition: ublas_space.h:937
virtual std::string Info() const
Turn back information as a string.
Definition: ublas_space.h:869
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: ublas_space.h:883
static TDataType JacobiNorm(const Matrix &rA)
Definition: ublas_space.h:313
static void Mult(const Matrix &rA, VectorType &rX, VectorType &rY)
Definition: ublas_space.h:344
static void Resize(MatrixPointerType &pA, SizeType m, SizeType n)
Definition: ublas_space.h:563
TVectorType VectorType
The vector type considered.
Definition: ublas_space.h:136
static void ResizeData(TOtherMatrixType &rA, SizeType m)
Definition: ublas_space.h:591
static double CheckAndCorrectZeroDiagonalValues(const ProcessInfo &rProcessInfo, MatrixType &rA, VectorType &rb, const SCALING_DIAGONAL ScalingDiagonal=SCALING_DIAGONAL::NO_SCALING)
This method checks and corrects the zero diagonal values.
Definition: ublas_space.h:704
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
end
Definition: DEM_benchmarks.py:180
static double max(double a, double b)
Definition: GeometryFunctions.h:79
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
bool WriteMatrixMarketVector(const char *FileName, VectorType &V)
Definition: matrix_market_interface.h:539
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
bool WriteMatrixMarketMatrix(const char *FileName, CompressedMatrixType &M, bool Symmetric)
Definition: matrix_market_interface.h:308
SCALING_DIAGONAL
Definition: ublas_space.h:98
@ CONSIDER_PRESCRIBED_DIAGONAL
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
int local_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:17
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
out
Definition: isotropic_damage_automatic_differentiation.py:200
int t
Definition: ode_solve.py:392
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
A
Definition: sensitivityMatrix.py:70
x
Definition: sensitivityMatrix.py:49
B
Definition: sensitivityMatrix.py:76
integer i
Definition: TensorModule.f:17