14 #if !defined(KRATOS_DEFLATION_UTILS )
15 #define KRATOS_DEFLATION_UTILS
111 std::vector< std::vector<int> > index_list(rNodes.
size());
113 std::size_t total_size = 0;
124 in!=rNodes.
end(); in++)
126 index_i = (in)->Id()-1;
127 auto& neighb_nodes = in->GetValue(NEIGHBOUR_NODES);
129 std::vector<int>& indices = index_list[index_i];
130 indices.reserve(neighb_nodes.size()+1);
133 indices.push_back(index_i);
134 for(
auto i = neighb_nodes.begin();
135 i != neighb_nodes.end();
i++)
138 int index_j =
i->Id()-1;
139 indices.push_back(index_j);
143 std::sort(indices.begin(),indices.end());
144 std::vector<int>::iterator new_end = std::unique(indices.begin(),indices.end());
146 indices.erase(new_end,indices.end());
148 total_size += indices.size();
152 A.reserve(total_size,
false);
155 for(
unsigned int i=0;
i<
A.size1();
i++)
157 std::vector<int>& indices = index_list[
i];
158 for(
unsigned int j=0;
j<indices.size();
j++)
160 A.push_back(
i,indices[
j] , 0.00);
166 std::vector<int>
w(rNodes.
size());
174 in->FastGetSolutionStepValue(rVariable) =
w[
counter++];
185 std::size_t full_size = rA.size1();
186 w.resize(full_size,0);
189 std::size_t reduced_size = standard_aggregation<int>(rA.size1(),rA.index1_data().begin(), rA.index2_data().begin(), &
w[0]);
195 std::vector<std::set<std::size_t> > deflatedANZ(reduced_size);
198 SparseMatrixType::iterator1 a_iterator = rA.begin1();
200 for (std::size_t
i = 0;
i < full_size;
i++)
202 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
203 for (SparseMatrixType::iterator2 row_iterator = a_iterator.begin() ;
204 row_iterator != a_iterator.end() ; ++row_iterator)
207 for (
typename SparseMatrixType::iterator2 row_iterator = begin(a_iterator,
208 boost::numeric::ublas::iterator1_tag());
209 row_iterator !=
end(a_iterator,
210 boost::numeric::ublas::iterator1_tag()); ++row_iterator )
213 deflatedANZ[
w[a_iterator.index1()]].insert(
w[row_iterator.index2()]);
223 for (std::size_t
i = 0;
i < reduced_size;
i++)
224 NZ += deflatedANZ[
i].size();
231 for(std::size_t
i = 0 ;
i < reduced_size ;
i++)
233 for(std::set<std::size_t>::iterator
j = deflatedANZ[
i].begin() ;
j != deflatedANZ[
i].end() ;
j++)
235 deflatedA.push_back(
i,*
j, 0.00);
240 if(reduced_size > max_reduced_size)
243 std::vector<int> wsmaller;
246 ConstructW(max_reduced_size, deflatedA, wsmaller, Areduced);
249 for(
unsigned int i=0;
i<full_size;
i++)
252 int new_color = wsmaller[
color];
256 deflatedA = Areduced;
258 reduced_size = wsmaller.size();
283 KRATOS_THROW_ERROR(std::logic_error,
"the number of rows is not a multiple of block_size. Can not use the block deflation",
"")
285 KRATOS_THROW_ERROR(std::logic_error,
"the number of non zeros is not a multiple of block_size. Can not use the block deflation",
"")
289 ConstructScalarMatrix(rA.size1(),
block_size,rA.index1_data().begin(), rA.index2_data().begin(), Ascalar);
293 std::vector<int> wscalar;
299 for(std::size_t
i=0;
i<wscalar.size();
i++)
311 ExpandScalarMatrix(rA.size1(),
block_size,rA.index1_data().begin(), rA.index2_data().begin(), deflatedA);
326 #pragma omp parallel for
327 for(
int i=0; i<static_cast<int>(
w.size());
i++)
341 #pragma omp parallel for
342 for(
int i=0; i<static_cast<int>(
y.size());
i++)
346 #if(_MSC_FULL_VER == 190023506)
347 for(
int i=0; i<static_cast<int>(
w.size());
i++)
353 #pragma omp parallel for
354 for(
int i=0; i<static_cast<int>(
w.size());
i++) {
366 double* abegin = Ah.value_data().begin();
367 int size = Ah.value_data().size();
368 #pragma omp parallel for
369 for (
int i = 0;
i < size;
i++)
376 SparseMatrixType::const_iterator1 a_iterator = rA.begin1();
377 int full_size = rA.size1();
379 for (
int i = 0;
i < full_size;
i++)
381 #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
382 for (SparseMatrixType::const_iterator2 row_iterator = a_iterator.begin() ;
383 row_iterator != a_iterator.end() ; ++row_iterator)
386 for (
typename SparseMatrixType::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 Ah(
w[a_iterator.index1()],
w[row_iterator.index2()]) += *row_iterator;
460 static I standard_aggregation(
const I n_row,
461 const std::size_t Ap[],
462 const std::size_t Aj[],
466 std::fill(
x,
x + n_row, 0);
468 I next_aggregate = 1;
471 for(I
i = 0;
i < n_row;
i++)
478 const I row_start = Ap[
i];
479 const I row_end = Ap[
i+1];
482 bool has_aggregated_neighbors =
false;
483 bool has_neighbors =
false;
484 for(I jj = row_start; jj < row_end; jj++)
489 has_neighbors =
true;
492 has_aggregated_neighbors =
true;
503 else if (!has_aggregated_neighbors)
506 x[
i] = next_aggregate;
507 for(I jj = row_start; jj < row_end; jj++)
509 x[Aj[jj]] = next_aggregate;
517 for(I
i = 0;
i < n_row;
i++)
524 for(I jj =
static_cast<I
>(Ap[
i]); jj < static_cast<I>(Ap[
i+1]); jj++)
540 for(I
i = 0;
i < n_row;
i++)
549 else if(xi == -n_row)
557 const I row_start = Ap[
i];
558 const I row_end = Ap[
i+1];
560 x[
i] = next_aggregate;
562 for(I jj = row_start; jj < row_end; jj++)
568 x[
j] = next_aggregate;
575 return next_aggregate;
581 static void ConstructScalarMatrix(
const std::size_t n_row,
const std::size_t
block_size,
582 const std::size_t Ap[],
583 const std::size_t Aj[],
589 Ascalar.reserve(scalar_size);
591 for(std::size_t
i = 0;
i < n_row;
i++)
596 const std::size_t row_start = Ap[
i];
597 const std::size_t row_end = Ap[
i+1];
599 for(std::size_t jj = row_start; jj < row_end; jj++)
601 const std::size_t
j = Aj[jj];
605 Ascalar.push_back(iscalar,jscalar,0.0);
612 static void ExpandScalarMatrix(
const std::size_t n_row,
const std::size_t
block_size,
613 const std::size_t Ap[],
614 const std::size_t Aj[],
620 Aexpanded.reserve(expanded_size);
622 for(std::size_t
i = 0;
i < n_row;
i++)
624 const std::size_t row_start = Ap[
i];
625 const std::size_t row_end = Ap[
i+1];
627 for(std::size_t isub=0; isub<
block_size; isub++)
630 for(std::size_t jj = row_start; jj < row_end; jj++)
632 const std::size_t
j = Aj[jj];
634 for(std::size_t jsub=0; jsub<
block_size; jsub++)
637 Aexpanded.push_back(iexpanded,jexpanded,0.0);
Definition: deflation_utils.h:79
static void FillDeflatedMatrix(const SparseMatrixType &rA, std::vector< int > &w, SparseMatrixType &Ah)
Definition: deflation_utils.h:362
static void ApplyW(const std::vector< int > &w, const SparseVectorType &x, SparseVectorType &y)
Definition: deflation_utils.h:324
void VisualizeAggregates(ModelPart::NodesContainerType &rNodes, Variable< double > &rVariable, const int max_reduced_size)
Definition: deflation_utils.h:105
static void ApplyWtranspose(const std::vector< int > &w, const SparseVectorType &x, SparseVectorType &y)
Definition: deflation_utils.h:338
static void ConstructW(const int max_reduced_size, SparseMatrixType &rA, std::vector< int > &w, SparseMatrixType &deflatedA, const std::size_t block_size)
block version of ConstructW. To be used when multiple DOFS are associated to the same node.
Definition: deflation_utils.h:273
boost::numeric::ublas::compressed_matrix< double > SparseMatrixType
Definition: deflation_utils.h:83
boost::numeric::ublas::vector< double > SparseVectorType
Definition: deflation_utils.h:85
static void ConstructW(const std::size_t max_reduced_size, SparseMatrixType &rA, std::vector< int > &w, SparseMatrixType &deflatedA)
Definition: deflation_utils.h:181
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
end
Definition: DEM_benchmarks.py:180
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void AtomicAdd(TDataType &target, const TDataType &value)
Definition: atomic_utilities.h:55
color
Definition: all_t_win_vs_m_fixed_error.py:230
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
w
Definition: generate_convection_diffusion_explicit_element.py:108
int block_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:16
int j
Definition: quadrature.py:648
int counter
Definition: script_THERMAL_CORRECT.py:218
A
Definition: sensitivityMatrix.py:70
x
Definition: sensitivityMatrix.py:49
integer i
Definition: TensorModule.f:17