18 #include <unordered_set>
21 #ifdef KRATOS_SMP_OPENMP
76 template<
class TSparseSpace,
143 typename TLinearSolver::Pointer pNewLinearSystemSolver,
145 ) :
BaseType(pNewLinearSystemSolver)
172 typename TLinearSolver::Pointer pNewLinearSystemSolver,
176 return Kratos::make_shared<ClassType>(pNewLinearSystemSolver,ThisParameters);
196 typename TSchemeType::Pointer pScheme,
206 const int nelements =
static_cast<int>(rModelPart.
Elements().
size());
209 const int nconditions =
static_cast<int>(rModelPart.
Conditions().size());
226 #pragma omp parallel firstprivate(nelements,nconditions, LHS_Contribution, RHS_Contribution, EquationId )
228 # pragma omp for schedule(guided, 512) nowait
229 for (
int k = 0;
k < nelements;
k++) {
230 auto it_elem = el_begin +
k;
232 if (it_elem->IsActive()) {
234 pScheme->CalculateSystemContributions(*it_elem, LHS_Contribution, RHS_Contribution, EquationId, CurrentProcessInfo);
237 Assemble(
A,
b, LHS_Contribution, RHS_Contribution, EquationId);
242 #pragma omp for schedule(guided, 512)
243 for (
int k = 0;
k < nconditions;
k++) {
244 auto it_cond = cond_begin +
k;
246 if (it_cond->IsActive()) {
248 pScheme->CalculateSystemContributions(*it_cond, LHS_Contribution, RHS_Contribution, EquationId, CurrentProcessInfo);
251 Assemble(
A,
b, LHS_Contribution, RHS_Contribution, EquationId);
272 typename TSchemeType::Pointer pScheme,
282 const int nelements =
static_cast<int>(rModelPart.
Elements().
size());
285 const int nconditions =
static_cast<int>(rModelPart.
Conditions().size());
300 #pragma omp parallel firstprivate(nelements, nconditions, lhs_contribution, equation_id )
302 # pragma omp for schedule(guided, 512) nowait
303 for (
int k = 0;
k < nelements; ++
k) {
304 auto it_elem = it_elem_begin +
k;
307 if (it_elem->IsActive()) {
309 pScheme->CalculateLHSContribution(*it_elem, lhs_contribution, equation_id, r_current_process_info);
316 #pragma omp for schedule(guided, 512)
317 for (
int k = 0;
k < nconditions; ++
k) {
318 auto it_cond = it_cond_begin +
k;
321 if (it_cond->IsActive()) {
323 pScheme->CalculateLHSContribution(*it_cond, lhs_contribution, equation_id, r_current_process_info);
333 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", this->
GetEchoLevel() > 2) <<
"Finished parallel building LHS" << std::endl;
348 typename TSchemeType::Pointer pScheme,
355 this->
Build(pScheme, rModelPart,
A,
tmp);
384 TSparseSpace::SetToZero(rDx);
387 if(
mT.size1() != 0) {
419 TSparseSpace::SetToZero(Dxmodified);
452 if (norm_b != 0.00) {
480 typename TSchemeType::Pointer pScheme,
490 Build(pScheme, rModelPart,
A,
b);
499 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", this->
GetEchoLevel() >=1) <<
"Constraints build time: " << timer_constraints << std::endl;
504 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", ( this->
GetEchoLevel() == 3)) <<
"Before the solution of the system" <<
"\nSystem Matrix = " << A <<
"\nUnknowns vector = " << Dx <<
"\nRHS vector = " <<
b << std::endl;
514 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", ( this->
GetEchoLevel() == 3)) <<
"After the solution of the system" <<
"\nSystem Matrix = " << A <<
"\nUnknowns vector = " << Dx <<
"\nRHS vector = " <<
b << std::endl;
530 typename TSchemeType::Pointer pScheme,
543 <<
"The buffer size needs to be at least 2 in order to use \n"
544 <<
"BuildAndSolveLinearizedOnPreviousIteration \n"
545 <<
"current buffer size for modelpart: " << rModelPart.
Name() << std::endl
547 <<
" Please set IN THE STRATEGY SETTINGS "
548 <<
" UseOldStiffnessInFirstIteration=false " << std::endl;
583 this->
Build(pScheme, rModelPart, rA, rb);
588 TSparseSpace::InplaceMult(dx_prediction, -1.0);
603 for(
auto&
dof : fixed_dofs)
611 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", this->
GetEchoLevel() >=1) <<
"Constraints build time: " << timer_constraints << std::endl;
615 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", ( this->
GetEchoLevel() == 3)) <<
"Before the solution of the system" <<
"\nSystem Matrix = " << rA <<
"\nUnknowns vector = " << rDx <<
"\nRHS vector = " << rb << std::endl;
626 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", ( this->
GetEchoLevel() == 3)) <<
"After the solution of the system" <<
"\nSystem Matrix = " << rA <<
"\nUnknowns vector = " << rDx <<
"\nRHS vector = " << rb << std::endl;
638 typename TSchemeType::Pointer pScheme,
657 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", ( this->
GetEchoLevel() == 3)) <<
"Before the solution of the system" <<
"\nSystem Matrix = " << rA <<
"\nUnknowns vector = " << rDx <<
"\nRHS vector = " << rb << std::endl;
667 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", ( this->
GetEchoLevel() == 3)) <<
"After the solution of the system" <<
"\nSystem Matrix = " << rA <<
"\nUnknowns vector = " << rDx <<
"\nRHS vector = " << rb << std::endl;
679 typename TSchemeType::Pointer pScheme,
711 typename TSchemeType::Pointer pScheme,
721 const int number_of_elements =
static_cast<int>(r_elements_array.
size());
727 typedef std::unordered_set < NodeType::DofType::Pointer, DofPointerHasher> set_type;
729 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", ( this->
GetEchoLevel() > 2)) <<
"Number of threads" << nthreads <<
"\n" << std::endl;
731 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", ( this->
GetEchoLevel() > 2)) <<
"Initializing element loop" << std::endl;
738 set_type dof_global_set;
739 dof_global_set.reserve(number_of_elements*20);
741 #pragma omp parallel firstprivate(dof_list, second_dof_list)
746 set_type dofs_tmp_set;
747 dofs_tmp_set.reserve(20000);
750 #pragma omp for schedule(guided, 512) nowait
751 for (
int i = 0;
i < number_of_elements; ++
i) {
752 auto it_elem = r_elements_array.
begin() +
i;
755 pScheme->GetDofList(*it_elem, dof_list, r_current_process_info);
756 dofs_tmp_set.insert(dof_list.begin(), dof_list.end());
761 const int number_of_conditions =
static_cast<int>(r_conditions_array.
size());
762 #pragma omp for schedule(guided, 512) nowait
763 for (
int i = 0;
i < number_of_conditions; ++
i) {
764 auto it_cond = r_conditions_array.
begin() +
i;
767 pScheme->GetDofList(*it_cond, dof_list, r_current_process_info);
768 dofs_tmp_set.insert(dof_list.begin(), dof_list.end());
773 const int number_of_constraints =
static_cast<int>(r_constraints_array.size());
774 #pragma omp for schedule(guided, 512) nowait
775 for (
int i = 0;
i < number_of_constraints; ++
i) {
776 auto it_const = r_constraints_array.begin() +
i;
779 it_const->GetDofList(dof_list, second_dof_list, r_current_process_info);
780 dofs_tmp_set.insert(dof_list.begin(), dof_list.end());
781 dofs_tmp_set.insert(second_dof_list.begin(), second_dof_list.end());
787 dof_global_set.insert(dofs_tmp_set.begin(), dofs_tmp_set.end());
791 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolver", ( this->
GetEchoLevel() > 2)) <<
"Initializing ordered array filling\n" << std::endl;
796 Doftemp.
reserve(dof_global_set.size());
797 for (
auto it= dof_global_set.begin(); it!= dof_global_set.end(); it++)
819 KRATOS_ERROR_IF_NOT(dof_iterator->HasReaction()) <<
"Reaction variable not set for the following : " <<std::endl
820 <<
"Node : "<<dof_iterator->Id()<< std::endl
821 <<
"Dof : "<<(*dof_iterator)<<std::endl<<
"Not possible to calculate reactions."<<std::endl;
842 dof_iterator->SetEquationId(
Index);
850 typename TSchemeType::Pointer pScheme,
888 KRATOS_ERROR <<
"The equation system size has changed during the simulation. This is not permitted."<<std::endl;
895 TSparseSpace::SetToZero(Dx);
899 TSparseSpace::SetToZero(
b);
910 typename TSchemeType::Pointer pScheme,
916 TSparseSpace::SetToZero(
b);
941 typename TSchemeType::Pointer pScheme,
948 const std::size_t system_size = rA.size1();
949 Vector scaling_factors (system_size);
955 auto it_dof_iterator = it_dof_iterator_begin +
Index;
956 if (it_dof_iterator->IsFixed()) {
957 scaling_factors[Index] = 0.0;
959 scaling_factors[Index] = 1.0;
966 double* Avalues = rA.value_data().begin();
967 std::size_t* Arow_indices = rA.index1_data().begin();
968 std::size_t* Acol_indices = rA.index2_data().begin();
971 const std::size_t col_begin = Arow_indices[
Index];
972 const std::size_t col_end = Arow_indices[
Index+1];
973 const double k_factor = scaling_factors[
Index];
974 if (k_factor == 0.0) {
976 for (std::size_t
j = col_begin;
j < col_end; ++
j)
977 if (Acol_indices[
j] !=
Index )
984 for (std::size_t
j = col_begin;
j < col_end; ++
j)
985 if(scaling_factors[ Acol_indices[
j] ] == 0 )
998 typename TSchemeType::Pointer pScheme,
1010 SparseMatrixMultiplicationUtility::TransposeMatrix<TSystemMatrixType, TSystemMatrixType>(T_transpose_matrix,
mT, 1.0);
1014 TSparseSpace::Copy(b_modified, rb);
1020 rb[slave_equation_id] = 0.0;
1036 typename TSchemeType::Pointer pScheme,
1049 SparseMatrixMultiplicationUtility::TransposeMatrix<TSystemMatrixType, TSystemMatrixType>(T_transpose_matrix,
mT, 1.0);
1053 TSparseSpace::Copy(b_modified, rb);
1057 T_transpose_matrix.resize(0, 0,
false);
1060 auxiliar_A_matrix.resize(0, 0,
false);
1069 rA(slave_equation_id, slave_equation_id) = mScaleFactor;
1070 rb[slave_equation_id] = 0.0;
1088 mT.resize(0,0,
false);
1115 "name" : "block_builder_and_solver",
1116 "block_builder" : true,
1117 "diagonal_values_for_dirichlet_dofs" : "use_max_diagonal",
1118 "silent_warnings" : false
1124 return default_parameters;
1133 return "block_builder_and_solver";
1189 return "ResidualBasedBlockBuilderAndSolver";
1237 typename TSchemeType::Pointer pScheme,
1262 const int nelements =
static_cast<int>(pElements.size());
1263 #pragma omp parallel firstprivate(nelements, RHS_Contribution, EquationId)
1265 #pragma omp for schedule(guided, 512) nowait
1266 for (
int i=0;
i<nelements;
i++) {
1269 if(it->IsActive()) {
1271 pScheme->CalculateRHSContribution(*it, RHS_Contribution, EquationId, CurrentProcessInfo);
1278 LHS_Contribution.resize(0, 0,
false);
1279 RHS_Contribution.resize(0,
false);
1282 const int nconditions =
static_cast<int>(ConditionsArray.
size());
1283 #pragma omp for schedule(guided, 512)
1284 for (
int i = 0;
i<nconditions;
i++) {
1285 auto it = ConditionsArray.
begin() +
i;
1287 if(it->IsActive()) {
1289 pScheme->CalculateRHSContribution(*it, RHS_Contribution, EquationId, CurrentProcessInfo);
1311 std::vector<LockObject> lock_array(indices.size());
1313 #pragma omp parallel
1317 std::unordered_map<IndexType, std::unordered_set<IndexType>> temp_indices;
1319 #pragma omp for schedule(guided, 512) nowait
1320 for (
int i_const = 0; i_const < static_cast<int>(rModelPart.
MasterSlaveConstraints().size()); ++i_const) {
1321 auto it_const = it_const_begin + i_const;
1322 it_const->EquationIdVector(slave_ids, master_ids, r_current_process_info);
1325 for (
auto &id_i : slave_ids) {
1326 temp_indices[id_i].insert(master_ids.begin(), master_ids.end());
1331 for (
auto& pair_temp_indices : temp_indices) {
1332 lock_array[pair_temp_indices.first].lock();
1333 indices[pair_temp_indices.first].insert(pair_temp_indices.second.begin(), pair_temp_indices.second.end());
1334 lock_array[pair_temp_indices.first].unlock();
1340 for (
int i = 0; i < static_cast<int>(indices.size()); ++
i) {
1341 if (indices[
i].size() == 0)
1345 indices[
i].insert(
i);
1349 const std::size_t nnz = block_for_each<SumReduction<std::size_t>>(indices, [](
auto& rIndices) {
return rIndices.size();});
1354 double *Tvalues =
mT.value_data().begin();
1355 IndexType *Trow_indices =
mT.index1_data().begin();
1356 IndexType *Tcol_indices =
mT.index2_data().begin();
1359 Trow_indices[0] = 0;
1360 for (
int i = 0; i < static_cast<int>(
mT.size1());
i++)
1361 Trow_indices[
i + 1] = Trow_indices[
i] + indices[
i].size();
1367 for (
auto it = indices[
Index].begin(); it != indices[
Index].end(); ++it) {
1368 Tcol_indices[
k] = *it;
1373 indices[
Index].clear();
1375 std::sort(&Tcol_indices[row_begin], &Tcol_indices[row_end]);
1378 mT.set_filled(indices.size() + 1, nnz);
1380 Timer::Stop(
"ConstraintsRelationMatrixStructure");
1388 TSparseSpace::SetToZero(
mT);
1406 #pragma omp parallel firstprivate(transformation_matrix, constant_vector, slave_equation_ids, master_equation_ids)
1408 std::unordered_set<IndexType> auxiliar_inactive_slave_dofs;
1410 #pragma omp for schedule(guided, 512)
1411 for (
int i_const = 0; i_const < number_of_constraints; ++i_const) {
1413 it_const->EquationIdVector(slave_equation_ids, master_equation_ids, r_current_process_info);
1416 if (it_const->IsActive()) {
1417 it_const->CalculateLocalSystem(transformation_matrix, constant_vector, r_current_process_info);
1419 for (
IndexType i = 0;
i < slave_equation_ids.size(); ++
i) {
1420 const IndexType i_global = slave_equation_ids[
i];
1426 const double constant_value = constant_vector[
i];
1431 auxiliar_inactive_slave_dofs.insert(slave_equation_ids.begin(), slave_equation_ids.end());
1436 #pragma omp critical
1438 mInactiveSlaveDofs.insert(auxiliar_inactive_slave_dofs.begin(), auxiliar_inactive_slave_dofs.end());
1445 mT(eq_id, eq_id) = 1.0;
1451 mT(eq_id, eq_id) = 1.0;
1458 typename TSchemeType::Pointer pScheme,
1469 std::vector< LockObject > lock_array(equation_size);
1471 std::vector<std::unordered_set<std::size_t> > indices(equation_size);
1473 block_for_each(indices, [](std::unordered_set<std::size_t>& rIndices){
1474 rIndices.reserve(40);
1480 pScheme->EquationId(rElem, rIdsTLS, CurrentProcessInfo);
1481 for (std::size_t i = 0; i < rIdsTLS.size(); i++) {
1482 lock_array[rIdsTLS[i]].lock();
1483 auto& row_indices = indices[rIdsTLS[i]];
1484 row_indices.insert(rIdsTLS.begin(), rIdsTLS.end());
1485 lock_array[rIdsTLS[i]].unlock();
1490 pScheme->EquationId(rCond, rIdsTLS, CurrentProcessInfo);
1491 for (std::size_t i = 0; i < rIdsTLS.size(); i++) {
1492 lock_array[rIdsTLS[i]].lock();
1493 auto& row_indices = indices[rIdsTLS[i]];
1494 row_indices.insert(rIdsTLS.begin(), rIdsTLS.end());
1495 lock_array[rIdsTLS[i]].unlock();
1499 if (rModelPart.MasterSlaveConstraints().size() != 0) {
1507 block_for_each(rModelPart.MasterSlaveConstraints(), tls, [&](MasterSlaveConstraint& rConst, TLS& rTls){
1508 rConst.EquationIdVector(rTls.slave_ids, rTls.master_ids, CurrentProcessInfo);
1510 for (std::size_t i = 0; i < rTls.slave_ids.size(); i++) {
1511 lock_array[rTls.slave_ids[i]].lock();
1512 auto& row_indices = indices[rTls.slave_ids[i]];
1513 row_indices.insert(rTls.slave_ids[i]);
1514 lock_array[rTls.slave_ids[i]].unlock();
1517 for (std::size_t
i = 0;
i < rTls.master_ids.size();
i++) {
1518 lock_array[rTls.master_ids[
i]].lock();
1519 auto& row_indices = indices[rTls.master_ids[
i]];
1520 row_indices.insert(rTls.master_ids[
i]);
1521 lock_array[rTls.master_ids[
i]].unlock();
1528 lock_array = std::vector< LockObject >();
1531 const std::size_t nnz = block_for_each<SumReduction<std::size_t>>(indices, [](
auto& rIndices) {
return rIndices.size();});
1533 A = CompressedMatrixType(indices.size(), indices.size(), nnz);
1535 double* Avalues =
A.value_data().begin();
1536 std::size_t* Arow_indices =
A.index1_data().begin();
1537 std::size_t* Acol_indices =
A.index2_data().begin();
1540 Arow_indices[0] = 0;
1541 for (
int i = 0; i < static_cast<int>(
A.size1());
i++) {
1542 Arow_indices[
i+1] = Arow_indices[
i] + indices[
i].size();
1545 IndexPartition<std::size_t>(
A.size1()).for_each([&](std::size_t
i){
1546 const unsigned int row_begin = Arow_indices[
i];
1547 const unsigned int row_end = Arow_indices[
i+1];
1548 unsigned int k = row_begin;
1549 for (
auto it = indices[
i].begin(); it != indices[
i].end(); it++) {
1550 Acol_indices[
k] = *it;
1557 std::sort(&Acol_indices[row_begin], &Acol_indices[row_end]);
1561 A.set_filled(indices.size()+1, nnz);
1563 Timer::Stop(
"MatrixStructure");
1574 unsigned int local_size = LHS_Contribution.size1();
1576 for (
unsigned int i_local = 0; i_local <
local_size; i_local++) {
1577 unsigned int i_global = EquationId[i_local];
1579 double& r_a =
b[i_global];
1580 const double& v_a = RHS_Contribution(i_local);
1583 AssembleRowContribution(
A, LHS_Contribution, i_global, i_local, EquationId);
1598 const IndexType i_global = rEquationId[i_local];
1599 AssembleRowContribution(rA, rLHSContribution, i_global, i_local, rEquationId);
1611 unsigned int local_size = RHS_Contribution.size();
1613 for (
unsigned int i_local = 0; i_local <
local_size; i_local++) {
1614 unsigned int i_global = EquationId[i_local];
1617 double& b_value =
b[i_global];
1618 const double& rhs_value = RHS_Contribution[i_local];
1626 double* values_vector =
A.value_data().begin();
1627 std::size_t* index1_vector =
A.index1_data().begin();
1628 std::size_t* index2_vector =
A.index2_data().begin();
1630 size_t left_limit = index1_vector[
i];
1634 size_t last_pos = ForwardFind(EquationId[0],left_limit,index2_vector);
1635 size_t last_found = EquationId[0];
1637 double& r_a = values_vector[last_pos];
1638 const double& v_a = Alocal(i_local,0);
1643 for (
unsigned int j=1;
j<EquationId.size();
j++) {
1644 unsigned int id_to_find = EquationId[
j];
1645 if(id_to_find > last_found) {
1646 pos = ForwardFind(id_to_find,last_pos+1,index2_vector);
1647 }
else if(id_to_find < last_found) {
1648 pos = BackwardFind(id_to_find,last_pos-1,index2_vector);
1653 double& r = values_vector[pos];
1654 const double&
v = Alocal(i_local,
j);
1657 last_found = id_to_find;
1668 BaseType::AssignSettings(ThisParameters);
1671 const std::string& r_diagonal_values_for_dirichlet_dofs = ThisParameters[
"diagonal_values_for_dirichlet_dofs"].
GetString();
1673 std::set<std::string> available_options_for_diagonal = {
"no_scaling",
"use_max_diagonal",
"use_diagonal_norm",
"defined_in_process_info"};
1675 if (available_options_for_diagonal.find(r_diagonal_values_for_dirichlet_dofs) == available_options_for_diagonal.end()) {
1676 std::stringstream msg;
1677 msg <<
"Currently prescribed diagonal values for dirichlet dofs : " << r_diagonal_values_for_dirichlet_dofs <<
"\n";
1678 msg <<
"Admissible values for the diagonal scaling are : no_scaling, use_max_diagonal, use_diagonal_norm, or defined_in_process_info" <<
"\n";
1683 if (r_diagonal_values_for_dirichlet_dofs ==
"no_scaling") {
1684 mScalingDiagonal = SCALING_DIAGONAL::NO_SCALING;
1685 }
else if (r_diagonal_values_for_dirichlet_dofs ==
"use_max_diagonal") {
1686 mScalingDiagonal = SCALING_DIAGONAL::CONSIDER_MAX_DIAGONAL;
1687 }
else if (r_diagonal_values_for_dirichlet_dofs ==
"use_diagonal_norm") {
1688 mScalingDiagonal = SCALING_DIAGONAL::CONSIDER_NORM_DIAGONAL;
1690 mScalingDiagonal = SCALING_DIAGONAL::CONSIDER_PRESCRIBED_DIAGONAL;
1692 mOptions.
Set(SILENT_WARNINGS, ThisParameters[
"silent_warnings"].GetBool());
1725 inline void AddUnique(std::vector<std::size_t>&
v,
const std::size_t& candidate)
1727 std::vector<std::size_t>::iterator
i =
v.begin();
1728 std::vector<std::size_t>::iterator endit =
v.end();
1729 while (
i != endit && (*
i) != candidate) {
1733 v.push_back(candidate);
1740 inline void CreatePartition(
unsigned int number_of_threads,
const int number_of_rows, DenseVector<unsigned int>& partitions)
1742 partitions.resize(number_of_threads + 1);
1743 int partition_size = number_of_rows / number_of_threads;
1745 partitions[number_of_threads] = number_of_rows;
1746 for (
unsigned int i = 1;
i < number_of_threads;
i++) {
1747 partitions[
i] = partitions[
i - 1] + partition_size;
1751 inline unsigned int ForwardFind(
const unsigned int id_to_find,
1752 const unsigned int start,
1753 const size_t* index_vector)
1755 unsigned int pos =
start;
1756 while(id_to_find != index_vector[pos]) pos++;
1760 inline unsigned int BackwardFind(
const unsigned int id_to_find,
1761 const unsigned int start,
1762 const size_t* index_vector)
1764 unsigned int pos =
start;
1765 while(id_to_find != index_vector[pos]) pos--;
1795 template<
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
std::size_t IndexType
Definition of the index type.
Definition: builder_and_solver.h:76
bool mDofSetIsInitialized
If the matrix is reshaped each step.
Definition: builder_and_solver.h:743
TSparseSpace::VectorType TSystemVectorType
Definition of the vector size.
Definition: builder_and_solver.h:85
bool GetCalculateReactionsFlag() const
This method returns the flag mCalculateReactionsFlag.
Definition: builder_and_solver.h:184
TSparseSpace::MatrixType TSystemMatrixType
Definition of the sparse matrix.
Definition: builder_and_solver.h:82
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: builder_and_solver.h:767
virtual void Clear()
This function is intended to be called at the end of the solution step to clean up memory storage not...
Definition: builder_and_solver.h:600
bool GetReshapeMatrixFlag() const
This method returns the flag mReshapeMatrixFlag.
Definition: builder_and_solver.h:220
TDenseSpace::MatrixType LocalSystemMatrixType
The local matrix definition.
Definition: builder_and_solver.h:94
TSparseSpace::VectorPointerType TSystemVectorPointerType
Definition of the pointer to the vector.
Definition: builder_and_solver.h:91
TSparseSpace::DataType TDataType
Definition of the data type.
Definition: builder_and_solver.h:79
TLinearSolver::Pointer mpLinearSystemSolver
Definition: builder_and_solver.h:737
DofsArrayType mDofSet
Pointer to the linear solver.
Definition: builder_and_solver.h:739
TDenseSpace::VectorType LocalSystemVectorType
The local vector definition.
Definition: builder_and_solver.h:97
TSparseSpace::MatrixPointerType TSystemMatrixPointerType
Definition of the pointer to the sparse matrix.
Definition: builder_and_solver.h:88
std::size_t SizeType
Definition of the size type.
Definition: builder_and_solver.h:73
int GetEchoLevel() const
It returns the echo level.
Definition: builder_and_solver.h:674
virtual Parameters GetDefaultParameters() const
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: builder_and_solver.h:628
unsigned int mEquationSystemSize
Flag taking in account if it is needed or not to calculate the reactions.
Definition: builder_and_solver.h:747
Definition: builtin_timer.h:26
virtual int MyPID() const
Definition: communicator.cpp:91
Base class for all Conditions.
Definition: condition.h:59
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
bool IsFixed() const
Definition: dof.h:376
EquationIdType EquationId() const
Definition: dof.h:324
TDataType & GetSolutionStepValue(IndexType SolutionStepIndex=0)
Definition: dof.h:256
TDataType & GetSolutionStepReactionValue(IndexType SolutionStepIndex=0)
Definition: dof.h:278
Base class for all Elements.
Definition: element.h:60
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
static Flags Create(IndexType ThisPosition, bool Value=true)
Definition: flags.h:138
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
MasterSlaveConstraintContainerType & MasterSlaveConstraints(IndexType ThisIndex=0)
Definition: model_part.h:654
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
Communicator & GetCommunicator()
Definition: model_part.h:1821
std::string & Name()
Definition: model_part.h:1811
IndexType GetBufferSize() const
This method gets the suffer size of the model part database.
Definition: model_part.h:1876
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
void RecursivelyAddMissingParameters(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing contain at least all parameters...
Definition: kratos_parameters.cpp:1457
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
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
void Sort()
Sort the elements in the set.
Definition: pointer_vector_set.h:753
void push_back(TPointerType x)
Adds a pointer to the end of the set.
Definition: pointer_vector_set.h:544
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
void reserve(int reservedsize)
Reserves memory for a specified number of elements.
Definition: pointer_vector_set.h:733
iterator end()
Returns an iterator pointing to the end of the container.
Definition: pointer_vector_set.h:314
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Current class provides an implementation for standard builder and solving operations.
Definition: residualbased_block_builder_and_solver.h:82
void Clear() override
This function is intended to be called at the end of the solution step to clean up memory storage not...
Definition: residualbased_block_builder_and_solver.h:1081
ResidualBasedBlockBuilderAndSolver()
Default constructor.
Definition: residualbased_block_builder_and_solver.h:135
BaseType::TDataType TDataType
Definition: residualbased_block_builder_and_solver.h:105
TSparseSpace::MatrixType & GetConstraintRelationMatrix() override
This method returns constraint relation (T) matrix.
Definition: residualbased_block_builder_and_solver.h:1144
KRATOS_DEFINE_LOCAL_FLAG(SILENT_WARNINGS)
Definition of the flags.
void BuildAndSolve(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
Function to perform the building and solving phase at the same time.
Definition: residualbased_block_builder_and_solver.h:479
PointerVectorSet< Element, IndexedObject > ElementsContainerType
Additional definitions.
Definition: residualbased_block_builder_and_solver.h:118
double mScaleFactor
The set containing the inactive slave dofs.
Definition: residualbased_block_builder_and_solver.h:1223
void SetScaleFactor(const double ScaleFactor)
Sets the scale factor. This function sets a new value for the scale factor.
Definition: residualbased_block_builder_and_solver.h:1173
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_block_builder_and_solver.h:108
void BuildLHS_CompleteOnFreeRows(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A) override
Build a rectangular matrix of size n*N where "n" is the number of unrestrained degrees of freedom and...
Definition: residualbased_block_builder_and_solver.h:347
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residualbased_block_builder_and_solver.h:1193
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: residualbased_block_builder_and_solver.h:111
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition of the base class.
Definition: residualbased_block_builder_and_solver.h:94
TSparseSpace::VectorType & GetConstraintConstantVector() override
This method returns constraint constant vector.
Definition: residualbased_block_builder_and_solver.h:1153
double GetScaleFactor()
Retrieves the current scale factor. This function returns the current scale factor value.
Definition: residualbased_block_builder_and_solver.h:1163
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedBlockBuilderAndSolver)
Definition of the pointer.
void ApplyDirichletConditions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
Applies the dirichlet conditions. This operation may be very heavy or completely unexpensive dependin...
Definition: residualbased_block_builder_and_solver.h:940
std::size_t IndexType
Definition: residualbased_block_builder_and_solver.h:101
std::vector< IndexType > mSlaveIds
This is vector containing the rigid movement of the constraint.
Definition: residualbased_block_builder_and_solver.h:1220
std::unordered_set< IndexType > mInactiveSlaveDofs
The equation ids of the master.
Definition: residualbased_block_builder_and_solver.h:1222
void AssembleRowContribution(TSystemMatrixType &A, const Matrix &Alocal, const unsigned int i, const unsigned int i_local, Element::EquationIdVectorType &EquationId)
Definition: residualbased_block_builder_and_solver.h:1624
ResidualBasedBlockBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: residualbased_block_builder_and_solver.h:142
std::string Info() const override
Turn back information as a string.
Definition: residualbased_block_builder_and_solver.h:1187
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: residualbased_block_builder_and_solver.h:112
virtual void BuildMasterSlaveConstraints(ModelPart &rModelPart)
Definition: residualbased_block_builder_and_solver.h:1384
BaseType::ElementsArrayType ElementsArrayType
Definition: residualbased_block_builder_and_solver.h:114
void BuildRHSNoDirichlet(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &b)
Definition: residualbased_block_builder_and_solver.h:1236
void AssembleRHS(TSystemVectorType &b, LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId)
Definition: residualbased_block_builder_and_solver.h:1605
SCALING_DIAGONAL mScalingDiagonal
The manually set scale factor.
Definition: residualbased_block_builder_and_solver.h:1225
virtual void SystemSolveWithPhysics(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb, ModelPart &rModelPart)
This is a call to the linear system solver (taking into account some physical particularities of the ...
Definition: residualbased_block_builder_and_solver.h:408
~ResidualBasedBlockBuilderAndSolver() override
Definition: residualbased_block_builder_and_solver.h:162
BaseType::Pointer Create(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters) const override
Create method.
Definition: residualbased_block_builder_and_solver.h:171
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_block_builder_and_solver.h:1666
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residualbased_block_builder_and_solver.h:1131
DofType::Pointer DofPointerType
Definition: residualbased_block_builder_and_solver.h:126
void SetUpDofSet(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart) override
Builds the list of the DofSets involved in the problem by "asking" to each element and condition its ...
Definition: residualbased_block_builder_and_solver.h:710
Element::EquationIdVectorType EquationIdVectorType
Definition: residualbased_block_builder_and_solver.h:119
TSystemMatrixType mT
Definition: residualbased_block_builder_and_solver.h:1218
virtual void ConstructMasterSlaveConstraintsStructure(ModelPart &rModelPart)
Definition: residualbased_block_builder_and_solver.h:1301
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_block_builder_and_solver.h:107
void InternalSystemSolveWithPhysics(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb, ModelPart &rModelPart)
This is a call to the linear system solver (taking into account some physical particularities of the ...
Definition: residualbased_block_builder_and_solver.h:437
void SetUpSystem(ModelPart &rModelPart) override
Organises the dofset in order to speed up the building phase.
Definition: residualbased_block_builder_and_solver.h:833
ResidualBasedBlockBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > ClassType
The definition of the current class.
Definition: residualbased_block_builder_and_solver.h:97
void AssembleLHS(TSystemMatrixType &rA, const LocalSystemMatrixType &rLHSContribution, Element::EquationIdVectorType &rEquationId)
Definition: residualbased_block_builder_and_solver.h:1589
virtual void ConstructMatrixStructure(typename TSchemeType::Pointer pScheme, TSystemMatrixType &A, ModelPart &rModelPart)
Definition: residualbased_block_builder_and_solver.h:1457
BaseType::ConditionsArrayType ConditionsArrayType
Definition: residualbased_block_builder_and_solver.h:115
Element::DofsVectorType DofsVectorType
Definition: residualbased_block_builder_and_solver.h:120
void BuildLHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA) override
Function to perform the building of the LHS.
Definition: residualbased_block_builder_and_solver.h:271
TSystemVectorType mConstantVector
This is matrix containing the global relation for the constraints.
Definition: residualbased_block_builder_and_solver.h:1219
Node NodeType
DoF types definition.
Definition: residualbased_block_builder_and_solver.h:124
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residualbased_block_builder_and_solver.h:1199
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_block_builder_and_solver.h:109
void BuildRHSAndSolve(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
Corresponds to the previews, but the System's matrix is considered already built and only the RHS is ...
Definition: residualbased_block_builder_and_solver.h:637
void SystemSolve(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
This is a call to the linear system solver.
Definition: residualbased_block_builder_and_solver.h:366
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_block_builder_and_solver.h:106
void Build(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &b) override
Function to perform the build of the RHS. The vector could be sized as the total number of dofs or as...
Definition: residualbased_block_builder_and_solver.h:195
NodeType::DofType DofType
Definition: residualbased_block_builder_and_solver.h:125
ResidualBasedBlockBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver)
Default constructor.
Definition: residualbased_block_builder_and_solver.h:155
boost::numeric::ublas::compressed_matrix< double > CompressedMatrixType
Definition: residualbased_block_builder_and_solver.h:121
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_block_builder_and_solver.h:1111
void ApplyConstraints(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb) override
Applies the constraints with master-slave relation matrix.
Definition: residualbased_block_builder_and_solver.h:1035
void Assemble(TSystemMatrixType &A, TSystemVectorType &b, const LocalSystemMatrixType &LHS_Contribution, const LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId)
Definition: residualbased_block_builder_and_solver.h:1566
int Check(ModelPart &rModelPart) override
This function is designed to be called once to perform all the checks needed on the input provided....
Definition: residualbased_block_builder_and_solver.h:1099
BaseType::NodesArrayType NodesArrayType
Definition: residualbased_block_builder_and_solver.h:113
std::size_t SizeType
Definition: residualbased_block_builder_and_solver.h:100
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_block_builder_and_solver.h:110
void BuildAndSolveLinearizedOnPreviousIteration(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb, const bool MoveMesh) override
Function to perform the building and solving phase at the same time Linearizing with the database at ...
Definition: residualbased_block_builder_and_solver.h:529
void ApplyRHSConstraints(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &rb) override
Applies the constraints with master-slave relation matrix (RHS only)
Definition: residualbased_block_builder_and_solver.h:997
BaseType::TSchemeType TSchemeType
Definition of the classes from the base class.
Definition: residualbased_block_builder_and_solver.h:104
void CalculateReactions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b) override
It computes the reactions of the system.
Definition: residualbased_block_builder_and_solver.h:909
Flags mOptions
We identify the scaling considered for the dirichlet dofs.
Definition: residualbased_block_builder_and_solver.h:1226
void ResizeAndInitializeVectors(typename TSchemeType::Pointer pScheme, TSystemMatrixPointerType &pA, TSystemVectorPointerType &pDx, TSystemVectorPointerType &pb, ModelPart &rModelPart) override
This method initializes and resizes the system of equations.
Definition: residualbased_block_builder_and_solver.h:849
std::vector< IndexType > mMasterIds
The equation ids of the slaves.
Definition: residualbased_block_builder_and_solver.h:1221
void BuildRHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &b) override
Function to perform the build of the RHS.
Definition: residualbased_block_builder_and_solver.h:678
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
static void MatrixMultiplication(const AMatrix &rA, const BMatrix &rB, CMatrix &rC)
Matrix-matrix product C = A·B @detail This method uses a template for each matrix.
Definition: sparse_matrix_multiplication_utility.h:117
static void Start(std::string const &rIntervalName)
This method starts the timer meassures.
Definition: timer.cpp:109
static void Stop(std::string const &rIntervalName)
This method stops the timer meassures.
Definition: timer.cpp:125
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void UpdateCurrentPosition(const ModelPart::NodesContainerType &rNodes, const ArrayVarType &rUpdateVariable=DISPLACEMENT, const IndexType BufferPosition=0)
This method updates the current coordinates For each node, this method takes the value of the provide...
Definition: variable_utils.cpp:273
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF_NOT(conditional)
Definition: exception.h:163
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
start
Definition: DEM_benchmarks.py:17
double TwoNorm(SparseSpaceType &dummy, SparseSpaceType::VectorType &x)
Definition: add_strategies_to_python.cpp:164
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
void MoveMesh(Scheme< SparseSpaceType, LocalSpaceType > &dummy, ModelPart::NodesContainerType &rNodes)
Definition: add_strategies_to_python.cpp:175
void Mult(TSpaceType &dummy, typename TSpaceType::MatrixType &rA, typename TSpaceType::VectorType &rX, typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:98
void UnaliasedAdd(TSpaceType &dummy, typename TSpaceType::VectorType &x, const double A, const typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:170
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
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
SCALING_DIAGONAL
Definition: ublas_space.h:98
v
Definition: generate_convection_diffusion_explicit_element.py:114
ScaleFactor
Definition: generate_frictional_mortar_condition.py:131
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
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
int dof
Definition: ode_solve.py:393
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17