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.
residualbased_block_builder_and_solver_with_lagrange_multiplier.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Vicente Mataix
11 //
12 //
13 #if !defined(KRATOS_RESIDUAL_BASED_BLOCK_BUILDER_AND_SOLVER_WITH_LAGRANGE_MULTIPLIER )
14 #define KRATOS_RESIDUAL_BASED_BLOCK_BUILDER_AND_SOLVER_WITH_LAGRANGE_MULTIPLIER
15 
16 /* System includes */
17 
18 /* External includes */
19 
20 /* Project includes */
23 
24 namespace Kratos
25 {
26 
29 
33 
37 
41 
45 
63 template<class TSparseSpace,
64  class TDenseSpace, //= DenseSpace<double>,
65  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
66  >
68  : public ResidualBasedBlockBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >
69 {
70 public:
73 
75  KRATOS_DEFINE_LOCAL_FLAG( DOUBLE_LAGRANGE_MULTIPLIER );
76  KRATOS_DEFINE_LOCAL_FLAG( TRANSFORMATION_MATRIX_COMPUTED );
77 
78  // Constraint enum
81 
84 
88 
91 
92  // The size_t types
93  typedef std::size_t SizeType;
94  typedef std::size_t IndexType;
95 
98  typedef typename BaseType::TDataType TDataType;
109 
114 
116  typedef Node NodeType;
117  typedef typename NodeType::DofType DofType;
119 
123 
128  {
129  }
130 
135  typename TLinearSolver::Pointer pNewLinearSystemSolver,
136  Parameters ThisParameters
137  ) : BaseType(pNewLinearSystemSolver)
138  {
139  // Validate and assign defaults
140  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
141  this->AssignSettings(ThisParameters);
142  }
143 
147  explicit ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier(typename TLinearSolver::Pointer pNewLinearSystemSolver)
148  : BaseType(pNewLinearSystemSolver)
149  {
150  // Setting flags
152  BaseType::mOptions.Set(BaseType::SILENT_WARNINGS, false);
155  BaseType::mOptions.Set(DOUBLE_LAGRANGE_MULTIPLIER, true);
156  BaseType::mOptions.Set(TRANSFORMATION_MATRIX_COMPUTED, false);
157  }
158 
162  {
163  }
164 
170  typename BaseBuilderAndSolverType::Pointer Create(
171  typename TLinearSolver::Pointer pNewLinearSystemSolver,
172  Parameters ThisParameters
173  ) const override
174  {
175  return Kratos::make_shared<ClassType>(pNewLinearSystemSolver,ThisParameters);
176  }
177 
186  void Build(
187  typename TSchemeType::Pointer pScheme,
188  ModelPart& rModelPart,
189  TSystemMatrixType& rA,
191  ) override
192  {
193  KRATOS_TRY
194 
195  // Resize again the system to the original size
196  if (rA.size1() != BaseType::mEquationSystemSize || rA.size2() != BaseType::mEquationSystemSize) {
198  BaseType::ConstructMatrixStructure(pScheme, rA, rModelPart);
199  }
200 
201  // Base build
202  BaseType::Build(pScheme, rModelPart, rA, rb);
203 
204  KRATOS_CATCH("")
205  }
206 
214  TSystemMatrixType& rA,
215  TSystemVectorType& rDx,
217  ) override
218  {
219  KRATOS_TRY
220 
221  // Compute the norm
222  const double norm_b = (TSparseSpace::Size(rb) != 0) ? TSparseSpace::TwoNorm(rb) : 0.0;
223  if (norm_b < std::numeric_limits<double>::epsilon()) {
224  // Do solve
225  BaseType::mpLinearSystemSolver->Solve(rA, rDx, rb);
226  } else {
227  TSparseSpace::SetToZero(rDx);
228  }
229 
230  // Prints information about the current time
231  KRATOS_INFO_IF("ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier", this->GetEchoLevel() > 1) << *(BaseType::mpLinearSystemSolver) << std::endl;
232 
233  KRATOS_CATCH("")
234  }
235 
244  TSystemMatrixType& rA,
245  TSystemVectorType& rDx,
246  TSystemVectorType& rb,
247  ModelPart& rModelPart
248  ) override
249  {
250  BaseType::InternalSystemSolveWithPhysics(rA, rDx, rb, rModelPart);
251  }
252 
264  typename TSchemeType::Pointer pScheme,
265  ModelPart& rModelPart,
266  TSystemMatrixType& rA,
267  TSystemVectorType& rDx,
269  ) override
270  {
271  KRATOS_TRY
272 
273  // Resize to the proper size
274  const SizeType total_system_size = (BaseType::mOptions.Is(DOUBLE_LAGRANGE_MULTIPLIER)) ? BaseType::mEquationSystemSize + 2 * BaseType::mSlaveIds.size() : BaseType::mEquationSystemSize + BaseType::mSlaveIds.size();
275  if (rDx.size() != total_system_size) {
276  rDx.resize(total_system_size, false);
277  TSparseSpace::SetToZero(rDx);
278  }
279 
280  // Base build and solve
281  BaseType::BuildAndSolve(pScheme, rModelPart, rA, rDx, rb);
282 
283  // Update the Lagrange multiplier solution
284  IndexPartition<std::size_t>(BaseType::mSlaveIds.size()).for_each([&, this](std::size_t Index){
286  });
287 
288  KRATOS_CATCH("")
289  }
290 
300  typename TSchemeType::Pointer pScheme,
301  ModelPart& rModelPart,
302  TSystemMatrixType& rA,
303  TSystemVectorType& rDx,
305  ) override
306  {
307  KRATOS_TRY
308 
309  // Resize to the proper size
310  const SizeType total_system_size = (BaseType::mOptions.Is(DOUBLE_LAGRANGE_MULTIPLIER)) ? BaseType::mEquationSystemSize + 2 * BaseType::mSlaveIds.size() : BaseType::mEquationSystemSize + BaseType::mSlaveIds.size();
311  if (rDx.size() != total_system_size) {
312  rDx.resize(total_system_size, false);
313  TSparseSpace::SetToZero(rDx);
314  }
315 
316  // Base build and solve
317  BaseType::BuildRHSAndSolve(pScheme, rModelPart, rA, rDx, rb);
318 
319  // Update the Lagrange multiplier solution
320  IndexPartition<std::size_t>(BaseType::mSlaveIds.size()).for_each([&, this](std::size_t Index){
322  });
323 
324  KRATOS_CATCH("")
325  }
326 
334  void BuildRHS(
335  typename TSchemeType::Pointer pScheme,
336  ModelPart& rModelPart,
338  ) override
339  {
340  KRATOS_TRY
341 
342  // Resize again the system to the original size
343  if (rb.size() != BaseType::mEquationSystemSize) {
344  rb.resize(BaseType::mEquationSystemSize, false);
345  }
346 
347  // Build the base RHS
348  BaseType::BuildRHS(pScheme, rModelPart, rb);
349 
350  KRATOS_CATCH("")
351  }
352 
362  typename TSchemeType::Pointer pScheme,
363  ModelPart& rModelPart,
364  TSystemMatrixType& rA,
365  TSystemVectorType& rDx,
367  ) override
368  {
369  TSparseSpace::SetToZero(rb);
370 
371  // Refresh RHS to have the correct reactions
372  BaseType::BuildRHSNoDirichlet(pScheme, rModelPart, rb);
373 
374  // First iterator
375  const auto it_dof_begin = BaseType::mDofSet.begin();
376 
377  //NOTE: dofs are assumed to be numbered consecutively in the BlockBuilderAndSolver
379  if (rDof.IsFixed()) {
380  rDof.GetSolutionStepReactionValue() = -rb[rDof.EquationId()];
381  }
382  });
383 
384  // NOTE: The constraints reactions are already computed when solving the dofs
385  IndexPartition<std::size_t>(BaseType::mSlaveIds.size()).for_each([&, this](std::size_t Index){
386  const IndexType equation_id = this->mSlaveIds[Index];
387  auto it_dof = it_dof_begin + equation_id;
388  it_dof->GetSolutionStepReactionValue() = mLagrangeMultiplierVector[mCorrespondanceDofsSlave[equation_id]];
389  });
390  }
391 
404  typename TSchemeType::Pointer pScheme,
405  ModelPart& rModelPart,
406  TSystemMatrixType& rA,
407  TSystemVectorType& rDx,
409  ) override
410  {
411  const std::size_t system_size = rA.size1();
412  Vector scaling_factors (system_size);
413 
414  const auto it_dof_iterator_begin = BaseType::mDofSet.begin();
415  const std::size_t ndofs = BaseType::mDofSet.size();
416 
417  // NOTE: dofs are assumed to be numbered consecutively in the BlockBuilderAndSolver
418  IndexPartition<std::size_t>(ndofs).for_each([&](std::size_t Index){
419  auto it_dof_iterator = it_dof_iterator_begin + Index;
420  if (it_dof_iterator->IsFixed()) {
421  scaling_factors[Index] = 0.0;
422  } else {
423  scaling_factors[Index] = 1.0;
424  }
425  });
426 
427  // Filling with ones the LM dofs
428  const std::size_t loop_size = system_size - ndofs;
429 
430  IndexPartition<std::size_t>(loop_size).for_each([&](std::size_t Index){
431  scaling_factors[ndofs + Index] = 1.0;
432  });
433 
434 
435  double* Avalues = rA.value_data().begin();
436  std::size_t* Arow_indices = rA.index1_data().begin();
437  std::size_t* Acol_indices = rA.index2_data().begin();
438 
439  // Define zero value tolerance
440  const double zero_tolerance = std::numeric_limits<double>::epsilon();
441 
442  // The diagonal considered
443  BaseType::mScaleFactor = TSparseSpace::GetScaleNorm(rModelPart.GetProcessInfo(), rA, BaseType::mScalingDiagonal);
444 
445  // Detect if there is a line of all zeros and set the diagonal to a 1 if this happens
446  IndexPartition<std::size_t>(system_size).for_each([&](std::size_t Index){
447  std::size_t col_begin = 0, col_end = 0;
448  bool empty = true;
449 
450  col_begin = Arow_indices[Index];
451  col_end = Arow_indices[Index + 1];
452  empty = true;
453  for (std::size_t j = col_begin; j < col_end; ++j) {
454  if(std::abs(Avalues[j]) > zero_tolerance) {
455  empty = false;
456  break;
457  }
458  }
459 
460  if(empty) {
461  rA(Index, Index) = this->mScaleFactor;
462  rb[Index] = 0.0;
463  }
464  });
465 
466  IndexPartition<std::size_t>(system_size).for_each([&](std::size_t Index){
467  const std::size_t col_begin = Arow_indices[Index];
468  const std::size_t col_end = Arow_indices[Index+1];
469  const double k_factor = scaling_factors[Index];
470  if (k_factor == 0.0) {
471  // Zero out the whole row, except the diagonal
472  for (std::size_t j = col_begin; j < col_end; ++j)
473  if (Acol_indices[j] != Index )
474  Avalues[j] = 0.0;
475 
476  // Zero out the RHS
477  rb[Index] = 0.0;
478  } else {
479  // Zero out the column which is associated with the zero'ed row
480  for (std::size_t j = col_begin; j < col_end; ++j)
481  if(scaling_factors[ Acol_indices[j] ] == 0 )
482  Avalues[j] = 0.0;
483  }
484  });
485  }
486 
494  typename TSchemeType::Pointer pScheme,
495  ModelPart& rModelPart,
497  ) override
498  {
499  KRATOS_TRY
500 
501  if (rModelPart.MasterSlaveConstraints().size() != 0) {
502  // First we check if CONSTRAINT_SCALE_FACTOR is defined
505  BaseType::ConstructMatrixStructure(pScheme, A, rModelPart);
506  this->BuildLHS(pScheme, rModelPart, A);
507  const double constraint_scale_factor = mConstraintFactorConsidered == CONSTRAINT_FACTOR::CONSIDER_NORM_DIAGONAL_CONSTRAINT_FACTOR ? TSparseSpace::GetMaxDiagonal(A) : TSparseSpace::GetDiagonalNorm(A);
508  mConstraintFactor = constraint_scale_factor;
509  }
510 
511  // Check T has been computed
515  }
516 
517  // If not previously computed we compute
518  if (BaseType::mOptions.IsNot(TRANSFORMATION_MATRIX_COMPUTED)) {
519  BuildMasterSlaveConstraints(rModelPart);
520  }
521 
522  // Extend with the LM constribution
523  const SizeType number_of_slave_dofs = TSparseSpace::Size1(BaseType::mT);
524 
525  // Definition of the total size of the system
526  const SizeType total_size_of_system = BaseType::mEquationSystemSize + (BaseType::mOptions.Is(DOUBLE_LAGRANGE_MULTIPLIER) ? 2 * number_of_slave_dofs : number_of_slave_dofs);
527  TSystemVectorType b_modified(total_size_of_system);
528 
529  // Copy the RHS
531  b_modified[Index] = rb[Index];
532  });
533 
534  const SizeType loop_size = total_size_of_system - BaseType::mEquationSystemSize;
535  const SizeType start_index = BaseType::mEquationSystemSize;
536 
537  // Fill with zeros
538  IndexPartition<std::size_t>(loop_size).for_each([&](std::size_t Index){
539  b_modified[start_index + Index] = 0.0;
540  });
541 
542  rb.resize(total_size_of_system, false);
543 
544  // Compute LM contributions
545  TSystemVectorType b_lm(total_size_of_system);
546  ComputeRHSLMContributions(b_lm, mConstraintFactor);
547 
548  // Fill auxiliar vector
549  TSparseSpace::UnaliasedAdd(b_modified, 1.0, b_lm);
550 
551  // Finally reassign
552  TSparseSpace::Copy(b_modified, rb);
553  }
554 
555  KRATOS_CATCH("")
556  }
557 
566  typename TSchemeType::Pointer pScheme,
567  ModelPart& rModelPart,
568  TSystemMatrixType& rA,
570  ) override
571  {
572  KRATOS_TRY
573 
574  if (rModelPart.MasterSlaveConstraints().size() != 0) {
575  // Getting process info
576  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
577 
578  // First build the relation matrix
579  BuildMasterSlaveConstraints(rModelPart);
580 
581  // Copy the LHS to avoid memory errors
582  TSystemMatrixType copy_of_A;
583  copy_of_A.swap(rA);
584 
585  TSystemMatrixType copy_of_T(BaseType::mT);
587  SparseMatrixMultiplicationUtility::TransposeMatrix<TSystemMatrixType, TSystemMatrixType>(transpose_of_T, BaseType::mT);
588 
589  // Some common values
590  const SizeType number_of_slave_dofs = TSparseSpace::Size1(BaseType::mT);
591 
592  // Definition of the total size of the system
593  const SizeType total_size_of_system = BaseType::mEquationSystemSize + (BaseType::mOptions.Is(DOUBLE_LAGRANGE_MULTIPLIER) ? 2 * number_of_slave_dofs : number_of_slave_dofs);
594  TSystemVectorType b_modified(total_size_of_system);
595 
596  // Copy the RHS
598  b_modified[Index] = rb[Index];
599  });
600 
601  auto loop_size = static_cast<int>(total_size_of_system) - static_cast<int>(BaseType::mEquationSystemSize);
602  auto start_index = BaseType::mEquationSystemSize;
603 
604  // Fill with zeros
605  IndexPartition<std::size_t>(loop_size).for_each([&](std::size_t Index){
606  b_modified[start_index + Index] = 0.0;
607  });
608  rb.resize(total_size_of_system, false);
609 
610  // Definition of the number of blocks
611  const SizeType number_of_blocks = BaseType::mOptions.Is(DOUBLE_LAGRANGE_MULTIPLIER) ? 3 : 2;
612 
613  // Create blocks
614  DenseMatrix<TSystemMatrixType*> matrices_p_blocks(number_of_blocks, number_of_blocks);
615  DenseMatrix<double> contribution_coefficients(number_of_blocks, number_of_blocks);
616  DenseMatrix<bool> transpose_blocks(number_of_blocks, number_of_blocks);
617 
618  // Definition of the auxiliar values
619  const bool has_constraint_scale_factor = mConstraintFactorConsidered == CONSTRAINT_FACTOR::CONSIDER_PRESCRIBED_CONSTRAINT_FACTOR ? true : false;
620  KRATOS_ERROR_IF(has_constraint_scale_factor && !r_current_process_info.Has(CONSTRAINT_SCALE_FACTOR)) << "Constraint scale factor not defined at process info" << std::endl;
621  const double constraint_scale_factor = has_constraint_scale_factor ? r_current_process_info.GetValue(CONSTRAINT_SCALE_FACTOR) : mConstraintFactorConsidered == CONSTRAINT_FACTOR::CONSIDER_NORM_DIAGONAL_CONSTRAINT_FACTOR ? TSparseSpace::GetDiagonalNorm(copy_of_A) : TSparseSpace::GetAveragevalueDiagonal(copy_of_A);
622  mConstraintFactor = constraint_scale_factor;
623 
624  /* Fill common blocks */
625  // Fill blocks
626  matrices_p_blocks(0,0) = &copy_of_A;
627  matrices_p_blocks(0,1) = &transpose_of_T;
628  matrices_p_blocks(1,0) = &copy_of_T;
629 
630  // Fill coefficients
631  contribution_coefficients(0, 0) = 1.0;
632  contribution_coefficients(0, 1) = mConstraintFactor;
633  contribution_coefficients(1, 0) = mConstraintFactor;
634 
635  // Fill transpose positions
636  for (IndexType i = 0; i < number_of_blocks; ++i) {
637  for (IndexType j = 0; j < number_of_blocks; ++j) {
638  transpose_blocks(i, j) = false;
639  }
640  }
641 
642  // Assemble the blocks
643  if (BaseType::mOptions.Is(DOUBLE_LAGRANGE_MULTIPLIER)) {
644  // Definition of the build scale factor auxiliar value
645  const bool has_auxiliar_constraint_scale_factor = mAuxiliarConstraintFactorConsidered == AUXILIAR_CONSTRAINT_FACTOR::CONSIDER_PRESCRIBED_CONSTRAINT_FACTOR ? true : false;
646  KRATOS_ERROR_IF(has_auxiliar_constraint_scale_factor && !r_current_process_info.Has(AUXILIAR_CONSTRAINT_SCALE_FACTOR)) << "Auxiliar constraint scale factor not defined at process info" << std::endl;
647  const double auxiliar_constraint_scale_factor = has_auxiliar_constraint_scale_factor ? r_current_process_info.GetValue(AUXILIAR_CONSTRAINT_SCALE_FACTOR) : mAuxiliarConstraintFactorConsidered == AUXILIAR_CONSTRAINT_FACTOR::CONSIDER_NORM_DIAGONAL_CONSTRAINT_FACTOR ? TSparseSpace::GetDiagonalNorm(copy_of_A) : TSparseSpace::GetAveragevalueDiagonal(copy_of_A);
648  mAuxiliarConstraintFactor = auxiliar_constraint_scale_factor;
649 
650  // Create auxiliar identity matrix
651  TSystemMatrixType identity_matrix(number_of_slave_dofs, number_of_slave_dofs);
652  for (IndexType i = 0; i < number_of_slave_dofs; ++i) {
653  identity_matrix.push_back(i, i, 1.0);
654  }
655 
656  KRATOS_ERROR_IF_NOT(identity_matrix.nnz() == number_of_slave_dofs) << "Inconsistent number of non-zero values in the identity matrix: " << number_of_slave_dofs << " vs " << identity_matrix.nnz() << std::endl;
657 
658  // Fill blocks
659  matrices_p_blocks(0,2) = &transpose_of_T;
660  matrices_p_blocks(2,0) = &copy_of_T;
661  matrices_p_blocks(1,1) = &identity_matrix;
662  matrices_p_blocks(1,2) = &identity_matrix;
663  matrices_p_blocks(2,1) = &identity_matrix;
664  matrices_p_blocks(2,2) = &identity_matrix;
665 
666  // Fill coefficients
667  contribution_coefficients(0, 2) = mConstraintFactor;
668  contribution_coefficients(2, 0) = mConstraintFactor;
669  contribution_coefficients(1, 1) = -mAuxiliarConstraintFactor;
670  contribution_coefficients(1, 2) = mAuxiliarConstraintFactor;
671  contribution_coefficients(2, 1) = mAuxiliarConstraintFactor;
672  contribution_coefficients(2, 2) = -mAuxiliarConstraintFactor;
673 
674  // Assemble the matrix (NOTE: Like the identity matrix is created inside the condition must be used meanwhile is alive, so inside the condition)
675  SparseMatrixMultiplicationUtility::AssembleSparseMatrixByBlocks(rA, matrices_p_blocks, contribution_coefficients, transpose_blocks);
676  } else {
677  // Create auxiliar zero matrix
678  TSystemMatrixType zero_matrix(number_of_slave_dofs, number_of_slave_dofs);
679 
680  // Fill blocks
681  matrices_p_blocks(1,1) = &zero_matrix;
682 
683  // Fill coefficients
684  contribution_coefficients(1, 1) = 0.0;
685 
686  // Assemble the matrix (NOTE: Like the zero matrix is created inside the condition must be used meanwhile is alive, so inside the condition)
687  SparseMatrixMultiplicationUtility::AssembleSparseMatrixByBlocks(rA, matrices_p_blocks, contribution_coefficients, transpose_blocks);
688  }
689 
690  // Compute LM contributions
691  TSystemVectorType b_lm(total_size_of_system);
692  ComputeRHSLMContributions(b_lm, constraint_scale_factor);
693 
694  // Fill auxiliar vector
695  TSparseSpace::UnaliasedAdd(b_modified, 1.0, b_lm);
696 
697  // Finally reassign
698  TSparseSpace::Copy(b_modified, rb);
699  }
700 
701  KRATOS_CATCH("")
702  }
703 
707  void Clear() override
708  {
709  BaseType::Clear();
710 
711  // Clear member variables
712  mCorrespondanceDofsSlave.clear();
713  mLagrangeMultiplierVector.resize(0,false);
714 
715  // Reset flag
716  BaseType::mOptions.Set(TRANSFORMATION_MATRIX_COMPUTED, false);
717  }
718 
726  int Check(ModelPart& rModelPart) override
727  {
728  KRATOS_TRY
729 
730  return BaseType::Check(rModelPart);
731 
732  KRATOS_CATCH("");
733  }
734 
740  {
741  Parameters default_parameters = Parameters(R"(
742  {
743  "name" : "ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier",
744  "consider_lagrange_multiplier_constraint_resolution" : "double",
745  "constraint_scale_factor" : "use_mean_diagonal",
746  "auxiliar_constraint_scale_factor" : "use_mean_diagonal"
747  })");
748 
749  // Getting base class default parameters
750  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
751  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
752  return default_parameters;
753  }
754 
759  static std::string Name()
760  {
761  return "block_builder_and_solver_with_lagrange_multiplier";
762  }
763 
767 
771 
775 
777  std::string Info() const override
778  {
779  return "ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier";
780  }
781 
783  void PrintInfo(std::ostream& rOStream) const override
784  {
785  rOStream << Info();
786  }
787 
789  void PrintData(std::ostream& rOStream) const override
790  {
791  rOStream << Info();
792  }
793 
797 
799 
800 protected:
803 
807 
808  std::unordered_map<IndexType, IndexType> mCorrespondanceDofsSlave;
810  double mConstraintFactor = 0.0;
812 
815 
819 
823 
829  {
830  KRATOS_TRY
831 
832  if (rModelPart.MasterSlaveConstraints().size() > 0) {
833  Timer::Start("ConstraintsRelationMatrixStructure");
834  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
835 
836  // Vector containing the localization in the system of the different terms
837  DofsVectorType slave_dof_list, master_dof_list;
838 
839  // Constraint initial iterator
840  const auto it_const_begin = rModelPart.MasterSlaveConstraints().begin();
841 
842  const std::size_t size_indices = BaseType::mDofSet.size();
843  std::vector<std::unordered_set<IndexType>> indices(size_indices);
844 
845  std::vector<LockObject> lock_array(size_indices);
846 
847  #pragma omp parallel firstprivate(slave_dof_list, master_dof_list)
848  {
849  Element::EquationIdVectorType slave_ids(3);
850  Element::EquationIdVectorType master_ids(3);
851  std::unordered_map<IndexType, std::unordered_set<IndexType>> temp_indices;
852 
853  #pragma omp for schedule(guided, 512) nowait
854  for (int i_const = 0; i_const < static_cast<int>(rModelPart.MasterSlaveConstraints().size()); ++i_const) {
855  auto it_const = it_const_begin + i_const;
856 
857  // If the constraint is active
858  if(it_const->IsActive()) {
859  it_const->EquationIdVector(slave_ids, master_ids, r_current_process_info);
860 
861  // Slave DoFs
862  for (auto &id_i : slave_ids) {
863  temp_indices[id_i].insert(id_i);
864  temp_indices[id_i].insert(master_ids.begin(), master_ids.end());
865  }
866  }
867  }
868 
869  // Merging all the temporal indexes
870  for (int i = 0; i < static_cast<int>(temp_indices.size()); ++i) {
871  lock_array[i].lock();
872  indices[i].insert(temp_indices[i].begin(), temp_indices[i].end());
873  lock_array[i].unlock();
874  }
875  }
876 
877  IndexType counter = 0;
878  mCorrespondanceDofsSlave.clear();
879  BaseType::mSlaveIds.clear();
880  BaseType::mMasterIds.clear();
881  for (int i = 0; i < static_cast<int>(size_indices); ++i) {
882  if (indices[i].size() == 0) { // Master dof!
883  BaseType::mMasterIds.push_back(i);
884  } else { // Slave dof
885  BaseType::mSlaveIds.push_back(i);
886  mCorrespondanceDofsSlave.insert(std::pair<IndexType, IndexType>(i, counter));
887  ++counter;
888  }
889  }
890 
891  // The slave size
892  const std::size_t slave_size = BaseType::mSlaveIds.size();
893 
894  // Count the row sizes
895  std::size_t nnz = 0;
896  nnz = IndexPartition<std::size_t>(slave_size).for_each<SumReduction<std::size_t>>([&, this](std::size_t Index){
897  return indices[this->mSlaveIds[Index]].size();
898  });
899 
900  BaseType::mT = TSystemMatrixType(slave_size, size_indices, nnz);
901  BaseType::mConstantVector.resize(slave_size, false);
902  mLagrangeMultiplierVector.resize(slave_size, false);
903  TSparseSpace::SetToZero(mLagrangeMultiplierVector);
904 
905  double *Tvalues = BaseType::mT.value_data().begin();
906  IndexType *Trow_indices = BaseType::mT.index1_data().begin();
907  IndexType *Tcol_indices = BaseType::mT.index2_data().begin();
908 
909  // Filling the index1 vector - DO NOT MAKE PARALLEL THE FOLLOWING LOOP!
910  Trow_indices[0] = 0;
911  for (int i = 0; i < static_cast<int>(slave_size); ++i) {
912  Trow_indices[i + 1] = Trow_indices[i] + indices[BaseType::mSlaveIds[i]].size();
913  }
914 
915  IndexPartition<std::size_t>(slave_size).for_each([&, this](std::size_t Index){
916  const IndexType row_begin = Trow_indices[Index];
917  const IndexType row_end = Trow_indices[Index + 1];
918  IndexType k = row_begin;
919  const IndexType i_slave = this->mSlaveIds[Index];
920  for (auto it = indices[i_slave].begin(); it != indices[i_slave].end(); ++it) {
921  Tcol_indices[k] = *it;
922  Tvalues[k] = 0.0;
923  ++k;
924  }
925 
926  indices[i_slave].clear(); //deallocating the memory
927 
928  std::sort(&Tcol_indices[row_begin], &Tcol_indices[row_end]);
929  });
930 
931  BaseType::mT.set_filled(slave_size + 1, nnz);
932 
933  // Reset flag
934  BaseType::mOptions.Set(TRANSFORMATION_MATRIX_COMPUTED, false);
935 
936  Timer::Stop("ConstraintsRelationMatrixStructure");
937  }
938 
939  KRATOS_CATCH("")
940  }
941 
946  void BuildMasterSlaveConstraints(ModelPart& rModelPart) override
947  {
948  KRATOS_TRY
949 
950  TSparseSpace::SetToZero(BaseType::mT);
951  TSparseSpace::SetToZero(BaseType::mConstantVector);
952 
953  // The current process info
954  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
955 
956  // Vector containing the localization in the system of the different terms
957  DofsVectorType slave_dof_list, master_dof_list;
958 
959  // Contributions to the system
960  Matrix transformation_matrix = LocalSystemMatrixType(0, 0);
961  Vector constant_vector = LocalSystemVectorType(0);
962 
963  // Vector containing the localization in the system of the different terms
964  Element::EquationIdVectorType slave_equation_ids, master_equation_ids;
965 
966  const int number_of_constraints = static_cast<int>(rModelPart.MasterSlaveConstraints().size());
967 
968  #pragma omp parallel firstprivate(transformation_matrix, constant_vector, slave_equation_ids, master_equation_ids)
969  {
970  #pragma omp for schedule(guided, 512)
971  for (int i_const = 0; i_const < number_of_constraints; ++i_const) {
972  auto it_const = rModelPart.MasterSlaveConstraints().begin() + i_const;
973 
974  // If the constraint is active
975  if (it_const->IsActive()) {
976  it_const->CalculateLocalSystem(transformation_matrix, constant_vector, r_current_process_info);
977  it_const->EquationIdVector(slave_equation_ids, master_equation_ids, r_current_process_info);
978 
979  for (IndexType i = 0; i < slave_equation_ids.size(); ++i) {
980  const IndexType i_global = mCorrespondanceDofsSlave[slave_equation_ids[i]];
981 
982  // Assemble matrix row
983  BaseType::AssembleRowContribution(BaseType::mT, - transformation_matrix, i_global, i, master_equation_ids);
984 
985  // Assemble constant vector
986  const double constant_value = constant_vector[i];
987  double& r_value = BaseType::mConstantVector[i_global];
988  AtomicAdd(r_value, constant_value);
989  }
990  }
991  }
992  }
993 
994  // Setting the slave dofs into the T system
995  for (auto eq_id : BaseType::mSlaveIds) {
996  BaseType::mT(mCorrespondanceDofsSlave[eq_id], eq_id) = 1.0;
997  }
998 
999  // Set flag
1000  BaseType::mOptions.Set(TRANSFORMATION_MATRIX_COMPUTED, true);
1001 
1002  KRATOS_CATCH("")
1003  }
1004 
1012  Parameters ThisParameters,
1013  const Parameters DefaultParameters
1014  ) const override
1015  {
1016  ThisParameters.RecursivelyValidateAndAssignDefaults(DefaultParameters);
1017  return ThisParameters;
1018  }
1019 
1024  void AssignSettings(const Parameters ThisParameters) override
1025  {
1026  BaseType::AssignSettings(ThisParameters);
1027 
1028  // Auxiliar set for constraints
1029  std::set<std::string> available_options_for_constraints_scale = {"use_mean_diagonal","use_diagonal_norm","defined_in_process_info"};
1030 
1031  // Definition of the constraint scale factor
1032  const std::string& r_constraint_scale_factor = ThisParameters["constraint_scale_factor"].GetString();
1033 
1034  // Check the values
1035  if (available_options_for_constraints_scale.find(r_constraint_scale_factor) == available_options_for_constraints_scale.end()) {
1036  std::stringstream msg;
1037  msg << "Currently prescribed constraint scale factor : " << r_constraint_scale_factor << "\n";
1038  msg << "Admissible values for the constraint scale factor are : use_mean_diagonal, use_diagonal_norm, or defined_in_process_info" << "\n";
1039  KRATOS_ERROR << msg.str() << std::endl;
1040  }
1041 
1042  // This case will consider the mean value in the diagonal as a scaling value
1043  if (r_constraint_scale_factor == "use_mean_diagonal") {
1045  } else if (r_constraint_scale_factor == "use_diagonal_norm") { // On this case the norm of the diagonal will be considered
1047  } else { // Otherwise we will assume we impose a numerical value
1049  }
1050 
1051  // Definition of the auxiliar constraint scale factor
1052  const std::string& r_auxiliar_constraint_scale_factor = ThisParameters["auxiliar_constraint_scale_factor"].GetString();
1053 
1054  // Check the values
1055  if (available_options_for_constraints_scale.find(r_auxiliar_constraint_scale_factor) == available_options_for_constraints_scale.end()) {
1056  std::stringstream msg;
1057  msg << "Currently prescribed constraint scale factor : " << r_auxiliar_constraint_scale_factor << "\n";
1058  msg << "Admissible values for the constraint scale factor are : use_mean_diagonal, use_diagonal_norm, or defined_in_process_info" << "\n";
1059  KRATOS_ERROR << msg.str() << std::endl;
1060  }
1061 
1062  // This case will consider the mean value in the diagonal as a scaling value
1063  if (r_auxiliar_constraint_scale_factor == "use_mean_diagonal") {
1065  } else if (r_auxiliar_constraint_scale_factor == "use_diagonal_norm") { // On this case the norm of the diagonal will be considered
1067  } else { // Otherwise we will assume we impose a numerical value
1069  }
1070 
1071  // Type of LM
1072  if (ThisParameters["consider_lagrange_multiplier_constraint_resolution"].GetString() == "double") {
1073  BaseType::mOptions.Set(DOUBLE_LAGRANGE_MULTIPLIER, true);
1074  } else {
1075  BaseType::mOptions.Set(DOUBLE_LAGRANGE_MULTIPLIER, false);
1076  }
1077 
1078  // Initialize flag
1079  BaseType::mOptions.Set(TRANSFORMATION_MATRIX_COMPUTED, false);
1080  }
1081 
1085 
1089 
1093 
1095 
1096 private:
1099 
1103 
1107 
1111 
1117  void ComputeRHSLMContributions(
1118  TSystemVectorType& rbLM,
1119  const double ScaleFactor = 1.0
1120  )
1121  {
1122  KRATOS_TRY
1123 
1124  const auto it_dof_begin = BaseType::mDofSet.begin();
1125  const int ndofs = static_cast<int>(BaseType::mDofSet.size());
1126 
1127  // Our auxiliar vector
1128  const SizeType number_of_slave_dofs = TSparseSpace::Size1(BaseType::mT);
1129  const SizeType total_size_of_system = BaseType::mEquationSystemSize + (BaseType::mOptions.Is(DOUBLE_LAGRANGE_MULTIPLIER) ? 2 * number_of_slave_dofs : number_of_slave_dofs);
1130  if (TSparseSpace::Size(rbLM) != total_size_of_system)
1131  rbLM.resize(total_size_of_system, false);
1132  TSystemVectorType aux_lm_rhs_contribution(number_of_slave_dofs);
1133  TSystemVectorType aux_whole_dof_vector(ndofs);
1134 
1135  // NOTE: dofs are assumed to be numbered consecutively in the BlockBuilderAndSolver
1136  IndexPartition<std::size_t>(ndofs).for_each([&](std::size_t Index){
1137  auto it_dof = it_dof_begin + Index;
1138  aux_whole_dof_vector[Index] = it_dof->GetSolutionStepValue();
1139  });
1140 
1141  // Compute auxiliar contribution
1142  TSystemVectorType aux_slave_dof_vector(number_of_slave_dofs);
1143  TSparseSpace::Mult(BaseType::mT, aux_whole_dof_vector, aux_slave_dof_vector);
1144 
1145  // Finally compute the RHS LM contribution
1146  noalias(aux_lm_rhs_contribution) = ScaleFactor * (BaseType::mConstantVector - aux_slave_dof_vector);
1147 
1148  if (BaseType::mOptions.Is(DOUBLE_LAGRANGE_MULTIPLIER)) {
1149  IndexPartition<std::size_t>(number_of_slave_dofs).for_each([&](std::size_t Index){
1150  rbLM[ndofs + Index] = aux_lm_rhs_contribution[Index];
1151  rbLM[ndofs + number_of_slave_dofs + Index] = aux_lm_rhs_contribution[Index];
1152  });
1153  } else {
1154  IndexPartition<std::size_t>(number_of_slave_dofs).for_each([&](std::size_t Index){
1155  rbLM[ndofs + Index] = aux_lm_rhs_contribution[Index];
1156  });
1157  }
1158 
1159  // We compute the transposed matrix of the global relation matrix
1160  TSystemMatrixType T_transpose_matrix(ndofs, number_of_slave_dofs);
1161  SparseMatrixMultiplicationUtility::TransposeMatrix<TSystemMatrixType, TSystemMatrixType>(T_transpose_matrix, BaseType::mT, -ScaleFactor);
1162 
1163  TSparseSpace::Mult(T_transpose_matrix, mLagrangeMultiplierVector, aux_whole_dof_vector);
1164  IndexPartition<std::size_t>(ndofs).for_each([&](std::size_t Index){
1165  rbLM[Index] = aux_whole_dof_vector[Index];
1166  });
1167 
1168  KRATOS_CATCH("")
1169  }
1170 
1174 
1178 
1182 
1186 
1188 
1189 }; /* Class ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier */
1190 
1192 
1195 
1196 // Here one should use the KRATOS_CREATE_LOCAL_FLAG, but it does not play nice with template parameters
1197 template<class TSparseSpace, class TDenseSpace, class TLinearSolver>
1198 const Kratos::Flags ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier<TSparseSpace, TDenseSpace, TLinearSolver>::DOUBLE_LAGRANGE_MULTIPLIER(Kratos::Flags::Create(1));
1199 template<class TSparseSpace, class TDenseSpace, class TLinearSolver>
1200 const Kratos::Flags ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier<TSparseSpace, TDenseSpace, TLinearSolver>::TRANSFORMATION_MATRIX_COMPUTED(Kratos::Flags::Create(2));
1201 
1203 
1204 } /* namespace Kratos.*/
1205 
1206 #endif /* KRATOS_RESIDUAL_BASED_BLOCK_BUILDER_AND_SOLVER defined */
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
TSparseSpace::VectorType TSystemVectorType
Definition of the vector size.
Definition: builder_and_solver.h:85
TSparseSpace::MatrixType TSystemMatrixType
Definition of the sparse matrix.
Definition: builder_and_solver.h:82
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
unsigned int mEquationSystemSize
Flag taking in account if it is needed or not to calculate the reactions.
Definition: builder_and_solver.h:747
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
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
bool IsFixed() const
Definition: dof.h:376
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
Definition: flags.h:58
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
bool Is(Flags const &rOther) const
Definition: flags.h:274
static Flags Create(IndexType ThisPosition, bool Value=true)
Definition: flags.h:138
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
MasterSlaveConstraintContainerType & MasterSlaveConstraints(IndexType ThisIndex=0)
Definition: model_part.h:654
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
This class defines the node.
Definition: node.h:65
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
void RecursivelyValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1389
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
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
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
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
double mScaleFactor
The set containing the inactive slave dofs.
Definition: residualbased_block_builder_and_solver.h:1223
std::vector< IndexType > mSlaveIds
This is vector containing the rigid movement of the constraint.
Definition: residualbased_block_builder_and_solver.h:1220
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
void BuildRHSNoDirichlet(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &b)
Definition: residualbased_block_builder_and_solver.h:1236
SCALING_DIAGONAL mScalingDiagonal
The manually set scale factor.
Definition: residualbased_block_builder_and_solver.h:1225
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_block_builder_and_solver.h:1666
TSystemMatrixType mT
Definition: residualbased_block_builder_and_solver.h:1218
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
virtual void ConstructMatrixStructure(typename TSchemeType::Pointer pScheme, TSystemMatrixType &A, ModelPart &rModelPart)
Definition: residualbased_block_builder_and_solver.h:1457
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
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 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
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
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
Flags mOptions
We identify the scaling considered for the dirichlet dofs.
Definition: residualbased_block_builder_and_solver.h:1226
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
Current class provides an implementation for standard builder and solving operations.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:69
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:1024
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_with_lagrange_multiplier.h:299
Element::EquationIdVectorType EquationIdVectorType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:112
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseBuilderAndSolverType
Definition of the base class.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:86
BaseType::ConditionsArrayType ConditionsArrayType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:108
Element::DofsVectorType DofsVectorType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:113
std::size_t SizeType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:93
NodeType::DofType DofType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:117
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:783
void SystemSolveWithPhysics(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb, ModelPart &rModelPart) override
This is a call to the linear system solver (taking into account some physical particularities of the ...
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:243
void CalculateReactions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
This method computes the reactions of the system.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:361
AUXILIAR_CONSTRAINT_FACTOR mAuxiliarConstraintFactorConsidered
The value considered for the constraint factor.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:814
ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier(typename TLinearSolver::Pointer pNewLinearSystemSolver)
Default constructor.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:147
void Build(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb) 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_with_lagrange_multiplier.h:186
ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier()
Default constructor.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:127
AUXILIAR_CONSTRAINT_FACTOR
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:80
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:789
ResidualBasedBlockBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:87
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier)
Definition of the pointer.
void BuildAndSolve(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
Function to perform the building and solving phase at the same time.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:263
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:102
void ConstructMasterSlaveConstraintsStructure(ModelPart &rModelPart) override
This method constructs the master slaeve constraint structure.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:828
ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:134
BaseType::ElementsArrayType ElementsArrayType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:107
std::string Info() const override
Turn back information as a string.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:777
KRATOS_DEFINE_LOCAL_FLAG(DOUBLE_LAGRANGE_MULTIPLIER)
Definition of the flags.
ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier< TSparseSpace, TDenseSpace, TLinearSolver > ClassType
The definition of the current class.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:90
~ResidualBasedBlockBuilderAndSolverWithLagrangeMultiplier() override
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:161
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_with_lagrange_multiplier.h:726
DofType::Pointer DofPointerType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:118
void SystemSolve(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
This is a call to the linear system solver.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:213
std::size_t IndexType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:94
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:739
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:100
double mAuxiliarConstraintFactor
The constraint scale factor.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:811
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:105
BaseBuilderAndSolverType::Pointer Create(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters) const override
Create method.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:170
void BuildRHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &rb) override
Function to perform the build of the RHS.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:334
void BuildMasterSlaveConstraints(ModelPart &rModelPart) override
This method builds the master slave relation matrix and vector.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:946
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:759
Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const override
This method validate and assign default parameters.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:1011
BaseType::TDataType TDataType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:98
TSystemVectorType mLagrangeMultiplierVector
A map of the correspondance between the slave dofs.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:809
BaseType::NodesArrayType NodesArrayType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:106
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_with_lagrange_multiplier.h:565
BaseType::TSchemeType TSchemeType
Definition of the classes from the base class.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:97
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_with_lagrange_multiplier.h:493
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:99
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:104
CONSTRAINT_FACTOR
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:79
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:101
CONSTRAINT_FACTOR mConstraintFactorConsidered
The auxiliar constraint scale factor.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:813
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_with_lagrange_multiplier.h:403
PointerVectorSet< Element, IndexedObject > ElementsContainerType
Additional definitions.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:111
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_with_lagrange_multiplier.h:707
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:103
Node NodeType
DoF types definition.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:116
double mConstraintFactor
This is vector containing the Lagrange multiplier solution.
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:810
std::unordered_map< IndexType, IndexType > mCorrespondanceDofsSlave
Definition: residualbased_block_builder_and_solver_with_lagrange_multiplier.h:808
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
static void AssembleSparseMatrixByBlocks(CompressedMatrix &rMatrix, const DenseMatrix< CompressedMatrix * > &rMatricespBlocks, DenseMatrix< double > ContributionCoefficients=DenseMatrix< double >(0, 0), DenseMatrix< bool > TransposeBlocks=DenseMatrix< bool >(0, 0))
This method assembles several sparse matrices into one large sparse matrix.
Definition: sparse_matrix_multiplication_utility.h:695
utility function to do a sum reduction
Definition: reduction_utilities.h:68
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
#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
TSpaceType::IndexType Size1(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:117
TSpaceType::IndexType Size2(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:123
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 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
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
ScaleFactor
Definition: generate_frictional_mortar_condition.py:131
def Index()
Definition: hdf5_io_tools.py:38
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int counter
Definition: script_THERMAL_CORRECT.py:218
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17