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_elimination_builder_and_solver.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: Riccardo Rossi
11 // Collaborators: Vicente Mataix
12 //
13 //
14 
15 #if !defined(KRATOS_RESIDUAL_BASED_ELIMINATION_BUILDER_AND_SOLVER )
16 #define KRATOS_RESIDUAL_BASED_ELIMINATION_BUILDER_AND_SOLVER
17 
18 /* System includes */
19 #include <set>
20 #include <unordered_set>
21 
22 /* External includes */
23 #ifdef KRATOS_SMP_OPENMP
24 #include <omp.h>
25 #endif
26 
27 /* Project includes */
28 #include "utilities/timer.h"
29 #include "includes/define.h"
30 #include "includes/key_hash.h"
32 #include "includes/model_part.h"
35 #include "spaces/ublas_space.h"
36 
37 namespace Kratos
38 {
39 
42 
46 
50 
54 
58 
70 template<class TSparseSpace,
71  class TDenseSpace, //= DenseSpace<double>,
72  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
73  >
75  : public BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >
76 {
77 public:
80 
83 
86 
89 
91  typedef typename BaseType::SizeType SizeType;
92  typedef typename BaseType::IndexType IndexType;
94  typedef typename BaseType::TDataType TDataType;
102 
106 
108  typedef Node NodeType;
109 
115 
119 
124  {
125  }
126 
131  typename TLinearSolver::Pointer pNewLinearSystemSolver,
132  Parameters ThisParameters
133  ) : BaseType(pNewLinearSystemSolver)
134  {
135  // Validate and assign defaults
136  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
137  this->AssignSettings(ThisParameters);
138  }
139 
144  typename TLinearSolver::Pointer pNewLinearSystemSolver)
145  : BaseType(pNewLinearSystemSolver)
146  {
147  }
148 
152  {
153  }
154 
160  typename BaseType::Pointer Create(
161  typename TLinearSolver::Pointer pNewLinearSystemSolver,
162  Parameters ThisParameters
163  ) const override
164  {
165  return Kratos::make_shared<ClassType>(pNewLinearSystemSolver,ThisParameters);
166  }
167 
171 
175 
184  void Build(
185  typename TSchemeType::Pointer pScheme,
186  ModelPart& rModelPart,
187  TSystemMatrixType& rA,
189  ) override
190  {
191  KRATOS_TRY
192 
193  KRATOS_ERROR_IF(!pScheme) << "No scheme provided!" << std::endl;
194 
195  // Getting the elements from the model
196  ElementsArrayType& r_elements_array = rModelPart.Elements();
197 
198  // Getting the array of the conditions
199  ConditionsArrayType& r_conditions_array = rModelPart.Conditions();
200 
201  // Getting the elements from the model
202  const int nelements = static_cast<int>(r_elements_array.size());
203 
204  // Getting the array of the conditions
205  const int nconditions = static_cast<int>(r_conditions_array.size());
206 
207  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
208  const auto it_elem_begin = r_elements_array.begin();
209  const auto it_cond_begin = r_conditions_array.begin();
210 
211  //contributions to the system
212  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
213  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
214 
215  // Vector containing the localization in the system of the different terms
216  EquationIdVectorType equation_id;
217 
218  // Assemble all elements
219  const auto timer = BuiltinTimer();
220 
221  #pragma omp parallel firstprivate(LHS_Contribution, RHS_Contribution, equation_id )
222  {
223  #pragma omp for schedule(guided, 512) nowait
224  for (int k = 0; k < nelements; ++k) {
225  auto it_elem = it_elem_begin + k;
226 
227  // If the element is active
228  if (it_elem->IsActive()) {
229  // Calculate elemental contribution
230  pScheme->CalculateSystemContributions(*it_elem, LHS_Contribution, RHS_Contribution, equation_id, r_current_process_info);
231 
232  // Assemble the elemental contribution
233 #ifdef USE_LOCKS_IN_ASSEMBLY
234  Assemble(rA, rb, LHS_Contribution, RHS_Contribution, equation_id, mLockArray);
235 #else
236  Assemble(rA, rb, LHS_Contribution, RHS_Contribution, equation_id);
237 #endif
238  }
239  }
240 
241  #pragma omp for schedule(guided, 512)
242  for (int k = 0; k < nconditions; ++k) {
243  auto it_cond = it_cond_begin + k;
244 
245  // If the condition is active
246  if (it_cond->IsActive()) {
247  // Calculate elemental contribution
248  pScheme->CalculateSystemContributions(*it_cond, LHS_Contribution, RHS_Contribution, equation_id, r_current_process_info);
249 
250 #ifdef USE_LOCKS_IN_ASSEMBLY
251  Assemble(rA, rb, LHS_Contribution, RHS_Contribution, equation_id, mLockArray);
252 #else
253  Assemble(rA, rb, LHS_Contribution, RHS_Contribution, equation_id);
254 #endif
255  }
256  }
257  }
258  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() >=1) << "System build time: " << timer.ElapsedSeconds() << std::endl;
259 
260 
261  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 2) << "Finished building" << std::endl;
262 
263 
264  KRATOS_CATCH("")
265  }
266 
274  void BuildLHS(
275  typename TSchemeType::Pointer pScheme,
276  ModelPart& rModelPart,
278  ) override
279  {
280  KRATOS_TRY
281 
282  KRATOS_ERROR_IF(!pScheme) << "No scheme provided!" << std::endl;
283 
284  // Getting the elements from the model
285  ElementsArrayType& r_elements_array = rModelPart.Elements();
286 
287  // Getting the array of the conditions
288  ConditionsArrayType& r_conditions_array = rModelPart.Conditions();
289 
290  // Getting the elements from the model
291  const int nelements = static_cast<int>(r_elements_array.size());
292 
293  // Getting the array of the conditions
294  const int nconditions = static_cast<int>(r_conditions_array.size());
295 
296  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
297  const auto it_elem_begin = r_elements_array.begin();
298  const auto it_cond_begin = r_conditions_array.begin();
299 
300  // Resetting to zero the vector of reactions
301  TSparseSpace::SetToZero(*(BaseType::mpReactionsVector));
302 
303  // Contributions to the system
304  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
305 
306  // Vector containing the localization in the system of the different terms
307  EquationIdVectorType equation_id;
308 
309  #pragma omp parallel firstprivate(LHS_Contribution, equation_id )
310  {
311  #pragma omp for schedule(guided, 512) nowait
312  for (int k = 0; k < nelements; ++k) {
313  auto it_elem = it_elem_begin + k;
314 
315  // If the element is active
316  if (it_elem->IsActive()) {
317  // Calculate elemental contribution
318  pScheme->CalculateLHSContribution(*it_elem, LHS_Contribution, equation_id, r_current_process_info);
319 
320  // Assemble the elemental contribution
321  AssembleLHS(rA, LHS_Contribution, equation_id);
322  }
323  }
324 
325  #pragma omp for schedule(guided, 512)
326  for (int k = 0; k < nconditions; ++k) {
327  auto it_cond = it_cond_begin + k;
328 
329  // If the condition is active
330  if (it_cond->IsActive()) {
331  // Calculate elemental contribution
332  pScheme->CalculateLHSContribution(*it_cond, LHS_Contribution, equation_id, r_current_process_info);
333 
334  // Assemble the elemental contribution
335  AssembleLHS(rA, LHS_Contribution, equation_id);
336  }
337  }
338  }
339 
340  KRATOS_CATCH("")
341  }
342 
353  typename TSchemeType::Pointer pScheme,
354  ModelPart& rModelPart,
356  ) override
357  {
358  KRATOS_TRY
359 
360  KRATOS_ERROR_IF(!pScheme) << "No scheme provided!" << std::endl;
361 
362  // Getting the elements from the model
363  ElementsArrayType& r_elements_array = rModelPart.Elements();
364 
365  // Getting the array of the conditions
366  ConditionsArrayType& r_conditions_array = rModelPart.Conditions();
367 
368  // Getting the elements from the model
369  const int nelements = static_cast<int>(r_elements_array.size());
370 
371  // Getting the array of the conditions
372  const int nconditions = static_cast<int>(r_conditions_array.size());
373 
374  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
375  const auto it_elem_begin = r_elements_array.begin();
376  const auto it_cond_begin = r_conditions_array.begin();
377 
378  // Resetting to zero the vector of reactions
379  TSparseSpace::SetToZero(*(BaseType::mpReactionsVector));
380 
381  // Contributions to the system
382  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
383 
384  // Vector containing the localization in the system of the different terms
385  EquationIdVectorType equation_id;
386 
387  #pragma omp parallel firstprivate(LHS_Contribution, equation_id )
388  {
389  #pragma omp for schedule(guided, 512) nowait
390  for (int k = 0; k < nelements; ++k) {
391  auto it_elem = it_elem_begin + k;
392 
393  // If the element is active
394  if (it_elem->IsActive()) {
395  // Calculate elemental contribution
396  pScheme->CalculateLHSContribution(*it_elem, LHS_Contribution, equation_id, r_current_process_info);
397 
398  // Assemble the elemental contribution
399  AssembleLHSCompleteOnFreeRows(rA, LHS_Contribution, equation_id);
400  }
401  }
402 
403  #pragma omp for schedule(guided, 512)
404  for (int k = 0; k < nconditions; ++k) {
405  auto it_cond = it_cond_begin + k;
406 
407  // If the condition is active
408  if (it_cond->IsActive()) {
409  // Calculate elemental contribution
410  pScheme->CalculateLHSContribution(*it_cond, LHS_Contribution, equation_id, r_current_process_info);
411 
412  // Assemble the elemental contribution
413  AssembleLHSCompleteOnFreeRows(rA, LHS_Contribution, equation_id);
414  }
415  }
416  }
417 
418  KRATOS_CATCH("")
419  }
420 
428  TSystemMatrixType& rA,
429  TSystemVectorType& rDx,
431  ) override
432  {
433  KRATOS_TRY
434 
435  double norm_b;
436  if (TSparseSpace::Size(rb) != 0) {
437  norm_b = TSparseSpace::TwoNorm(rb);
438  } else {
439  norm_b = 0.0;
440  }
441 
442  if (norm_b != 0.0) {
443  // Do solve
444  BaseType::mpLinearSystemSolver->Solve(rA, rDx, rb);
445  } else
446  TSparseSpace::SetToZero(rDx);
447 
448  // Prints information about the current time
449  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 1) << *(BaseType::mpLinearSystemSolver) << std::endl;
450 
451  KRATOS_CATCH("")
452 
453  }
454 
463  TSystemMatrixType& rA,
464  TSystemVectorType& rDx,
465  TSystemVectorType& rb,
466  ModelPart& rModelPart
467  )
468  {
469  KRATOS_TRY
470 
471  double norm_b;
472  if (TSparseSpace::Size(rb) != 0) {
473  norm_b = TSparseSpace::TwoNorm(rb);
474  } else {
475  norm_b = 0.0;
476  }
477 
478  if (norm_b != 0.0) {
479  // Provide physical data as needed
480  if(BaseType::mpLinearSystemSolver->AdditionalPhysicalDataIsNeeded() )
481  BaseType::mpLinearSystemSolver->ProvideAdditionalData(rA, rDx, rb, BaseType::mDofSet, rModelPart);
482 
483  // Do solve
484  BaseType::mpLinearSystemSolver->Solve(rA, rDx, rb);
485  } else {
486  TSparseSpace::SetToZero(rDx);
487  KRATOS_WARNING_IF("ResidualBasedEliminationBuilderAndSolver", rModelPart.GetCommunicator().MyPID() == 0) << "ATTENTION! setting the RHS to zero!" << std::endl;
488  }
489 
490  // Prints information about the current time
491  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 1 && rModelPart.GetCommunicator().MyPID() == 0) << *(BaseType::mpLinearSystemSolver) << std::endl;
492 
493  KRATOS_CATCH("")
494 
495  }
496 
508  typename TSchemeType::Pointer pScheme,
509  ModelPart& rModelPart,
510  TSystemMatrixType& rA,
511  TSystemVectorType& rDx,
513  ) override
514  {
515  KRATOS_TRY
516 
517  Timer::Start("Build");
518 
519  Build(pScheme, rModelPart, rA, rb);
520 
521  Timer::Stop("Build");
522 
523  // Does nothing...dirichlet conditions are naturally dealt with in defining the residual
524  ApplyDirichletConditions(pScheme, rModelPart, rA, rDx, rb);
525 
526  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", ( this->GetEchoLevel() == 3)) << "Before the solution of the system" << "\nSystem Matrix = " << rA << "\nUnknowns vector = " << rDx << "\nRHS vector = " << rb << std::endl;
527 
528  const auto timer = BuiltinTimer();
529  Timer::Start("Solve");
530 
531  SystemSolveWithPhysics(rA, rDx, rb, rModelPart);
532 
533  Timer::Stop("Solve");
534  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() >=1) << "System solve time: " << timer.ElapsedSeconds() << std::endl;
535 
536 
537  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", ( this->GetEchoLevel() == 3)) << "After the solution of the system" << "\nSystem Matrix = " << rA << "\nUnknowns vector = " << rDx << "\nRHS vector = " << rb << std::endl;
538 
539  KRATOS_CATCH("")
540  }
541 
551  typename TSchemeType::Pointer pScheme,
552  ModelPart& rModelPart,
553  TSystemMatrixType& rA,
554  TSystemVectorType& rDx,
556  ) override
557  {
558  KRATOS_TRY
559 
560  BuildRHS(pScheme, rModelPart, rb);
561  SystemSolve(rA, rDx, rb);
562 
563  KRATOS_CATCH("")
564  }
565 
572  void BuildRHS(
573  typename TSchemeType::Pointer pScheme,
574  ModelPart& rModelPart,
576  ) override
577  {
578  KRATOS_TRY
579 
580  // Resetting to zero the vector of reactions
582  TSparseSpace::SetToZero(*(BaseType::mpReactionsVector));
583  }
584 
585  // Getting the Elements
586  ElementsArrayType& r_elements_array = rModelPart.Elements();
587 
588  // Getting the array of the conditions
589  ConditionsArrayType& r_conditions_array = rModelPart.Conditions();
590 
591  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
592 
593  // Contributions to the system
594  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
595 
596  // Vector containing the localization in the system of the different terms
597  EquationIdVectorType equation_id;
598 
599  // Assemble all elements
600  #pragma omp parallel firstprivate( RHS_Contribution, equation_id)
601  {
602  const auto it_elem_begin = r_elements_array.begin();
603  const int nelements = static_cast<int>(r_elements_array.size());
604  #pragma omp for schedule(guided, 512) nowait
605  for (int i = 0; i < nelements; ++i) {
606  auto it_elem = it_elem_begin + i;
607 
608  // If the element is active
609  if (it_elem->IsActive()) {
610  // Calculate elemental Right Hand Side Contribution
611  pScheme->CalculateRHSContribution(*it_elem, RHS_Contribution, equation_id, r_current_process_info);
612 
613  // Assemble the elemental contribution
614  AssembleRHS(rb, RHS_Contribution, equation_id);
615  }
616  }
617 
618  // Assemble all conditions
619  const auto it_cond_begin = r_conditions_array.begin();
620  const int nconditions = static_cast<int>(r_conditions_array.size());
621  #pragma omp for schedule(guided, 512)
622  for (int i = 0; i < nconditions; ++i) {
623  auto it_cond = it_cond_begin + i;
624  // If the condition is active
625  if (it_cond->IsActive()) {
626  // Calculate elemental contribution
627  pScheme->CalculateRHSContribution(*it_cond, RHS_Contribution, equation_id, r_current_process_info);
628 
629  // Assemble the elemental contribution
630  AssembleRHS(rb, RHS_Contribution, equation_id);
631  }
632  }
633  }
634 
635  KRATOS_CATCH("")
636  }
637 
647  typename TSchemeType::Pointer pScheme,
648  ModelPart& rModelPart
649  ) override
650  {
651  KRATOS_TRY;
652 
653  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 1 && rModelPart.GetCommunicator().MyPID() == 0) << "Setting up the dofs" << std::endl;
654 
655  // Gets the array of elements from the modeler
656  ElementsArrayType& r_elements_array = rModelPart.Elements();
657  const int nelements = static_cast<int>(r_elements_array.size());
658 
659  DofsVectorType elemental_dof_list;
660 
661  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
662 
664 
665  typedef std::unordered_set < NodeType::DofType::Pointer, DofPointerHasher> set_type;
666 
667  std::vector<set_type> dofs_aux_list(nthreads);
668 
669  for (int i = 0; i < static_cast<int>(nthreads); ++i) {
670  dofs_aux_list[i].reserve(nelements);
671  }
672 
673  IndexPartition<std::size_t>(nelements).for_each(elemental_dof_list, [&](std::size_t Index, DofsVectorType& tls_elemental_dof_list){
674  auto it_elem = r_elements_array.begin() + Index;
675  const IndexType this_thread_id = OpenMPUtils::ThisThread();
676 
677  // Gets list of Dof involved on every element
678  pScheme->GetDofList(*it_elem, tls_elemental_dof_list, r_current_process_info);
679 
680  dofs_aux_list[this_thread_id].insert(tls_elemental_dof_list.begin(), tls_elemental_dof_list.end());
681  });
682 
683  ConditionsArrayType& r_conditions_array = rModelPart.Conditions();
684  const int nconditions = static_cast<int>(r_conditions_array.size());
685 
686  IndexPartition<std::size_t>(nconditions).for_each(elemental_dof_list, [&](std::size_t Index, DofsVectorType& tls_elemental_dof_list){
687  auto it_cond = r_conditions_array.begin() + Index;
688  const IndexType this_thread_id = OpenMPUtils::ThisThread();
689 
690  // Gets list of Dof involved on every element
691  pScheme->GetDofList(*it_cond, tls_elemental_dof_list, r_current_process_info);
692  dofs_aux_list[this_thread_id].insert(tls_elemental_dof_list.begin(), tls_elemental_dof_list.end());
693  });
694 
695  // Here we do a reduction in a tree so to have everything on thread 0
696  SizeType old_max = nthreads;
697  SizeType new_max = ceil(0.5*static_cast<double>(old_max));
698  while (new_max >= 1 && new_max != old_max) {
699  IndexPartition<std::size_t>(new_max).for_each([&](std::size_t Index){
700  if (Index + new_max < old_max) {
701  dofs_aux_list[Index].insert(dofs_aux_list[Index + new_max].begin(), dofs_aux_list[Index + new_max].end());
702  dofs_aux_list[Index + new_max].clear();
703  }
704  });
705 
706  old_max = new_max;
707  new_max = ceil(0.5*static_cast<double>(old_max));
708  }
709 
710  DofsArrayType dof_temp;
712 
713  dof_temp.reserve(dofs_aux_list[0].size());
714  for (auto it = dofs_aux_list[0].begin(); it != dofs_aux_list[0].end(); ++it) {
715  dof_temp.push_back(*it);
716  }
717  dof_temp.Sort();
718 
719  BaseType::mDofSet = dof_temp;
720 
721  // Throws an exception if there are no Degrees of freedom involved in the analysis
722  KRATOS_ERROR_IF(BaseType::mDofSet.size() == 0) << "No degrees of freedom!" << std::endl;
723 
725 
726  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 2 && rModelPart.GetCommunicator().MyPID() == 0) << "Finished setting up the dofs" << std::endl;
727 
728 #ifdef USE_LOCKS_IN_ASSEMBLY
729  if (mLockArray.size() != 0) {
730  for (int i = 0; i < static_cast<int>(mLockArray.size()); i++)
731  omp_destroy_lock(&mLockArray[i]);
732  }
733 
734  mLockArray.resize(BaseType::mDofSet.size());
735 
736  for (int i = 0; i < static_cast<int>(mLockArray.size()); i++)
737  omp_init_lock(&mLockArray[i]);
738 #endif
739 
740  // If reactions are to be calculated, we check if all the dofs have reactions defined
741  // This is tobe done only in debug mode
742 #ifdef KRATOS_DEBUG
744  for(auto dof_iterator = BaseType::mDofSet.begin(); dof_iterator != BaseType::mDofSet.end(); ++dof_iterator) {
745  KRATOS_ERROR_IF_NOT(dof_iterator->HasReaction()) << "Reaction variable not set for the following : " << std::endl
746  << "Node : " << dof_iterator->Id() << std::endl
747  << "Dof : " << (*dof_iterator) << std::endl << "Not possible to calculate reactions." << std::endl;
748  }
749  }
750 #endif
751 
752  KRATOS_CATCH("");
753  }
754 
759  void SetUpSystem(ModelPart& rModelPart) override
760  {
761  // Set equation id for degrees of freedom
762  // the free degrees of freedom are positioned at the beginning of the system,
763  // while the fixed one are at the end (in opposite order).
764  //
765  // that means that if the EquationId is greater than "mEquationSystemSize"
766  // the pointed degree of freedom is restrained
767  //
768  int free_id = 0;
769  int fix_id = BaseType::mDofSet.size();
770 
771  for (auto dof_iterator = BaseType::mDofSet.begin(); dof_iterator != BaseType::mDofSet.end(); ++dof_iterator)
772  if (dof_iterator->IsFixed())
773  dof_iterator->SetEquationId(--fix_id);
774  else
775  dof_iterator->SetEquationId(free_id++);
776 
778 
779  }
780 
789  typename TSchemeType::Pointer pScheme,
793  ModelPart& rModelPart
794  ) override
795  {
796  KRATOS_TRY
797 
798  if (pA == nullptr) { // If the pointer is not initialized initialize it to an empty matrix
799 
801  pA.swap(pNewA);
802  }
803  if (pDx == nullptr) { // If the pointer is not initialized initialize it to an empty matrix
804 
806  pDx.swap(pNewDx);
807  }
808  if (pb == nullptr) { // If the pointer is not initialized initialize it to an empty matrix
809 
811  pb.swap(pNewb);
812  }
813  if (BaseType::mpReactionsVector == nullptr) { // If the pointer is not initialized initialize it to an empty matrix
814 
816  BaseType::mpReactionsVector.swap(pNewReactionsVector);
817  }
818 
819  TSystemMatrixType& rA = *pA;
820  TSystemVectorType& rDx = *pDx;
821  TSystemVectorType& rb = *pb;
822 
823  // Resizing the system vectors and matrix
824  if (rA.size1() == 0 || BaseType::GetReshapeMatrixFlag()) { // If the matrix is not initialized
826  ConstructMatrixStructure(pScheme, rA, rModelPart);
827  } else {
828  if (rA.size1() != BaseType::mEquationSystemSize || rA.size2() != BaseType::mEquationSystemSize) {
829  KRATOS_ERROR <<"The equation system size has changed during the simulation. This is not permitted."<<std::endl;
831  ConstructMatrixStructure(pScheme, rA, rModelPart);
832  }
833  }
834  if (rDx.size() != BaseType::mEquationSystemSize) {
835  rDx.resize(BaseType::mEquationSystemSize, false);
836  }
837  TSparseSpace::SetToZero(rDx);
838  if (rb.size() != BaseType::mEquationSystemSize) {
839  rb.resize(BaseType::mEquationSystemSize, false);
840  }
841  TSparseSpace::SetToZero(rb);
842 
843  //if needed resize the vector for the calculation of reactions
844  if (BaseType::mCalculateReactionsFlag == true) {
845  const std::size_t reactions_vector_size = BaseType::mDofSet.size() - BaseType::mEquationSystemSize;
846  if (BaseType::mpReactionsVector->size() != reactions_vector_size)
847  BaseType::mpReactionsVector->resize(reactions_vector_size, false);
848  }
849 
850  KRATOS_CATCH("")
851  }
852 
853 
863  typename TSchemeType::Pointer pScheme,
864  ModelPart& rModelPart,
865  TSystemMatrixType& rA,
866  TSystemVectorType& rDx,
868  ) override
869  {
870  //refresh RHS to have the correct reactions
871  BuildRHS(pScheme, rModelPart, rb);
872 
873  // Updating variables
874  std::size_t i;
875  TSystemVectorType& r_reactions_vector = *BaseType::mpReactionsVector;
876  for (auto it2 = BaseType::mDofSet.ptr_begin(); it2 != BaseType::mDofSet.ptr_end(); ++it2) {
877  i = (*it2)->EquationId();
880  (*it2)->GetSolutionStepReactionValue() = -r_reactions_vector[i];
881  }
882 
883  }
884  }
885 
898  typename TSchemeType::Pointer pScheme,
899  ModelPart& rModelPart,
900  TSystemMatrixType& rA,
901  TSystemVectorType& rDx,
903  ) override
904  {
905  // Detect if there is a line of all zeros and set the diagonal to a 1 if this happens
906  mScaleFactor = TSparseSpace::CheckAndCorrectZeroDiagonalValues(rModelPart.GetProcessInfo(), rA, rb, mScalingDiagonal);
907  }
908 
912  void Clear() override
913  {
914  this->mDofSet = DofsArrayType();
915  this->mpReactionsVector.reset();
916 // this->mReactionsVector = TSystemVectorType();
917 
918  this->mpLinearSystemSolver->Clear();
919 
920  KRATOS_INFO_IF("ResidualBasedEliminationBuilderAndSolver", this->GetEchoLevel() > 1) << "Clear Function called" << std::endl;
921  }
922 
930  int Check(ModelPart& rModelPart) override
931  {
932  KRATOS_TRY
933 
934  return 0;
935  KRATOS_CATCH("");
936  }
937 
943  {
944  Parameters default_parameters = Parameters(R"(
945  {
946  "name" : "elimination_builder_and_solver",
947  "block_builder" : false,
948  "diagonal_values_for_dirichlet_dofs" : "use_max_diagonal"
949  })");
950 
951  // Getting base class default parameters
952  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
953  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
954  return default_parameters;
955  }
956 
961  static std::string Name()
962  {
963  return "elimination_builder_and_solver";
964  }
965 
969 
973 
977 
979  std::string Info() const override
980  {
981  return "ResidualBasedEliminationBuilderAndSolver";
982  }
983 
985  void PrintInfo(std::ostream& rOStream) const override
986  {
987  rOStream << Info();
988  }
989 
991  void PrintData(std::ostream& rOStream) const override
992  {
993  rOStream << Info();
994  }
995 
999 
1001 
1002 protected:
1005 
1009 
1010 #ifdef USE_LOCKS_IN_ASSEMBLY
1011  std::vector<omp_lock_t> mLockArray;
1012 #endif
1013 
1014  double mScaleFactor = 1.0;
1015 
1017 
1018 
1022 
1026 
1037  void Assemble(
1038  TSystemMatrixType& rA,
1039  TSystemVectorType& rb,
1040  const LocalSystemMatrixType& rLHSContribution,
1041  const LocalSystemVectorType& rRHSContribution,
1042  const Element::EquationIdVectorType& rEquationId
1043 #ifdef USE_LOCKS_IN_ASSEMBLY
1044  ,std::vector< omp_lock_t >& rLockArray
1045 #endif
1046  )
1047  {
1048  const SizeType local_size = rLHSContribution.size1();
1049 
1050  for (IndexType i_local = 0; i_local < local_size; ++i_local) {
1051  const IndexType i_global = rEquationId[i_local];
1052 
1053  if (i_global < BaseType::mEquationSystemSize) {
1054 #ifdef USE_LOCKS_IN_ASSEMBLY
1055  omp_set_lock(&rLockArray[i_global]);
1056  rb[i_global] += rRHSContribution(i_local);
1057 #else
1058  double& r_a = rb[i_global];
1059  const double& v_a = rRHSContribution(i_local);
1060  AtomicAdd(r_a, v_a);
1061 #endif
1062  AssembleRowContributionFreeDofs(rA, rLHSContribution, i_global, i_local, rEquationId);
1063 
1064 #ifdef USE_LOCKS_IN_ASSEMBLY
1065  omp_unset_lock(&rLockArray[i_global]);
1066 #endif
1067  }
1068  //note that computation of reactions is not performed here!
1069  }
1070  }
1071 
1079  typename TSchemeType::Pointer pScheme,
1080  TSystemMatrixType& rA,
1081  ModelPart& rModelPart
1082  )
1083  {
1084  // Filling with zero the matrix (creating the structure)
1085  Timer::Start("MatrixStructure");
1086 
1087  const SizeType equation_size = BaseType::mEquationSystemSize;
1088 
1089  std::vector<std::unordered_set<IndexType> > indices(equation_size);
1090 
1091  block_for_each(indices, [](std::unordered_set<IndexType>& rIndices){
1092  rIndices.reserve(40);
1093  });
1094 
1096 
1097  #pragma omp parallel firstprivate(ids)
1098  {
1099  // The process info
1100  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
1101 
1102  // We repeat the same declaration for each thead
1103  std::vector<std::unordered_set<IndexType> > temp_indexes(equation_size);
1104 
1105  #pragma omp for
1106  for (int index = 0; index < static_cast<int>(equation_size); ++index)
1107  temp_indexes[index].reserve(30);
1108 
1109  // Getting the size of the array of elements from the model
1110  const int number_of_elements = static_cast<int>(rModelPart.Elements().size());
1111 
1112  // Element initial iterator
1113  const auto it_elem_begin = rModelPart.ElementsBegin();
1114 
1115  // We iterate over the elements
1116  #pragma omp for schedule(guided, 512) nowait
1117  for (int i_elem = 0; i_elem<number_of_elements; ++i_elem) {
1118  auto it_elem = it_elem_begin + i_elem;
1119  pScheme->EquationId( *it_elem, ids, r_current_process_info);
1120 
1121  for (auto& id_i : ids) {
1122  if (id_i < BaseType::mEquationSystemSize) {
1123  auto& row_indices = temp_indexes[id_i];
1124  for (auto& id_j : ids)
1125  if (id_j < BaseType::mEquationSystemSize)
1126  row_indices.insert(id_j);
1127  }
1128  }
1129  }
1130 
1131  // Getting the size of the array of the conditions
1132  const int number_of_conditions = static_cast<int>(rModelPart.Conditions().size());
1133 
1134  // Condition initial iterator
1135  const auto it_cond_begin = rModelPart.ConditionsBegin();
1136 
1137  // We iterate over the conditions
1138  #pragma omp for schedule(guided, 512) nowait
1139  for (int i_cond = 0; i_cond<number_of_conditions; ++i_cond) {
1140  auto it_cond = it_cond_begin + i_cond;
1141  pScheme->EquationId( *it_cond, ids, r_current_process_info);
1142 
1143  for (auto& id_i : ids) {
1144  if (id_i < BaseType::mEquationSystemSize) {
1145  auto& row_indices = temp_indexes[id_i];
1146  for (auto& id_j : ids)
1147  if (id_j < BaseType::mEquationSystemSize)
1148  row_indices.insert(id_j);
1149  }
1150  }
1151  }
1152 
1153  // Merging all the temporal indexes
1154  #pragma omp critical
1155  {
1156  for (int i = 0; i < static_cast<int>(temp_indexes.size()); ++i) {
1157  indices[i].insert(temp_indexes[i].begin(), temp_indexes[i].end());
1158  }
1159  }
1160  }
1161 
1162  // Count the row sizes
1163  SizeType nnz = 0;
1164  for (IndexType i = 0; i < indices.size(); ++i)
1165  nnz += indices[i].size();
1166 
1167  rA = TSystemMatrixType(indices.size(), indices.size(), nnz);
1168 
1169  double* Avalues = rA.value_data().begin();
1170  std::size_t* Arow_indices = rA.index1_data().begin();
1171  std::size_t* Acol_indices = rA.index2_data().begin();
1172 
1173  // Filling the index1 vector - DO NOT MAKE PARALLEL THE FOLLOWING LOOP!
1174  Arow_indices[0] = 0;
1175  for (IndexType i = 0; i < rA.size1(); ++i)
1176  Arow_indices[i + 1] = Arow_indices[i] + indices[i].size();
1177 
1178  IndexPartition<std::size_t>(rA.size1()).for_each([&](std::size_t Index){
1179  const IndexType row_begin = Arow_indices[Index];
1180  const IndexType row_end = Arow_indices[Index + 1];
1181  IndexType k = row_begin;
1182  for (auto it = indices[Index].begin(); it != indices[Index].end(); ++it) {
1183  Acol_indices[k] = *it;
1184  Avalues[k] = 0.0;
1185  ++k;
1186  }
1187 
1188  std::sort(&Acol_indices[row_begin], &Acol_indices[row_end]);
1189  });
1190 
1191  rA.set_filled(indices.size() + 1, nnz);
1192 
1193  Timer::Stop("MatrixStructure");
1194  }
1195 
1203  TSystemMatrixType& rA,
1204  LocalSystemMatrixType& rLHSContribution,
1205  EquationIdVectorType& rEquationId
1206  )
1207  {
1208  const SizeType local_size = rLHSContribution.size1();
1209 
1210  for (IndexType i_local = 0; i_local < local_size; ++i_local) {
1211  const IndexType i_global = rEquationId[i_local];
1212  if (i_global < BaseType::mEquationSystemSize) {
1213  for (IndexType j_local = 0; j_local < local_size; ++j_local) {
1214  const IndexType j_global = rEquationId[j_local];
1215  if (j_global < BaseType::mEquationSystemSize) {
1216  rA(i_global, j_global) += rLHSContribution(i_local, j_local);
1217  }
1218  }
1219  }
1220  }
1221  }
1222 
1228  TSystemMatrixType& rA,
1229  const Matrix& rALocal,
1230  const IndexType i,
1231  const IndexType i_local,
1232  const Element::EquationIdVectorType& EquationId
1233  )
1234  {
1235  double* values_vector = rA.value_data().begin();
1236  IndexType* index1_vector = rA.index1_data().begin();
1237  IndexType* index2_vector = rA.index2_data().begin();
1238 
1239  const IndexType left_limit = index1_vector[i];
1240 
1241  // Find the first entry
1242  // We iterate over the equation ids until we find the first equation id to be considered
1243  // We count in which component we find an ID
1244  IndexType last_pos = 0;
1245  IndexType last_found = 0;
1246  IndexType counter = 0;
1247  for(IndexType j=0; j < EquationId.size(); ++j) {
1248  ++counter;
1249  const IndexType j_global = EquationId[j];
1250  if (j_global < BaseType::mEquationSystemSize) {
1251  last_pos = ForwardFind(j_global,left_limit,index2_vector);
1252  last_found = j_global;
1253  break;
1254  }
1255  }
1256 
1257  // If the counter is equal to the size of the EquationID vector that means that only one dof will be considered, if the number is greater means that all the dofs are fixed. If the number is below means that at we have several dofs free to be considered
1258  if (counter <= EquationId.size()) {
1259 #ifndef USE_LOCKS_IN_ASSEMBLY
1260  double& r_a = values_vector[last_pos];
1261  const double& v_a = rALocal(i_local,counter - 1);
1262  AtomicAdd(r_a, v_a);
1263 #else
1264  values_vector[last_pos] += rALocal(i_local,counter - 1);
1265 #endif
1266  // Now find all of the other entries
1267  IndexType pos = 0;
1268  for(IndexType j = counter; j < EquationId.size(); ++j) {
1269  IndexType id_to_find = EquationId[j];
1270  if (id_to_find < BaseType::mEquationSystemSize) {
1271  if(id_to_find > last_found)
1272  pos = ForwardFind(id_to_find,last_pos+1,index2_vector);
1273  else if(id_to_find < last_found)
1274  pos = BackwardFind(id_to_find,last_pos-1,index2_vector);
1275  else
1276  pos = last_pos;
1277 
1278 #ifndef USE_LOCKS_IN_ASSEMBLY
1279  double& r = values_vector[pos];
1280  const double& v = rALocal(i_local,j);
1281  AtomicAdd(r, v);
1282 #else
1283  values_vector[pos] += rALocal(i_local,j);
1284 #endif
1285  last_found = id_to_find;
1286  last_pos = pos;
1287  }
1288  }
1289  }
1290  }
1291 
1292  inline IndexType ForwardFind(const IndexType id_to_find,
1293  const IndexType start,
1294  const IndexType* index_vector)
1295  {
1296  IndexType pos = start;
1297  while(id_to_find != index_vector[pos]) pos++;
1298  return pos;
1299  }
1300 
1301  inline IndexType BackwardFind(const IndexType id_to_find,
1302  const IndexType start,
1303  const IndexType* index_vector)
1304  {
1305  IndexType pos = start;
1306  while(id_to_find != index_vector[pos]) pos--;
1307  return pos;
1308  }
1309 
1314  void AssignSettings(const Parameters ThisParameters) override
1315  {
1316  BaseType::AssignSettings(ThisParameters);
1317 
1318  // Setting flags<
1319  const std::string& r_diagonal_values_for_dirichlet_dofs = ThisParameters["diagonal_values_for_dirichlet_dofs"].GetString();
1320 
1321  std::set<std::string> available_options_for_diagonal = {"no_scaling","use_max_diagonal","use_diagonal_norm","defined_in_process_info"};
1322 
1323  if (available_options_for_diagonal.find(r_diagonal_values_for_dirichlet_dofs) == available_options_for_diagonal.end()) {
1324  std::stringstream msg;
1325  msg << "Currently prescribed diagonal values for dirichlet dofs : " << r_diagonal_values_for_dirichlet_dofs << "\n";
1326  msg << "Admissible values for the diagonal scaling are : no_scaling, use_max_diagonal, use_diagonal_norm, or defined_in_process_info" << "\n";
1327  KRATOS_ERROR << msg.str() << std::endl;
1328  }
1329 
1330  // The first option will not consider any scaling (the diagonal values will be replaced with 1)
1331  if (r_diagonal_values_for_dirichlet_dofs == "no_scaling") {
1333  } else if (r_diagonal_values_for_dirichlet_dofs == "use_max_diagonal") {
1335  } else if (r_diagonal_values_for_dirichlet_dofs == "use_diagonal_norm") { // On this case the norm of the diagonal will be considered
1337  } else { // Otherwise we will assume we impose a numerical value
1339  }
1340  }
1341 
1345 
1349 
1353 
1355 
1356 private:
1359 
1363 
1367 
1371 
1375  inline void AddUnique(std::vector<std::size_t>& v, const std::size_t& candidate)
1376  {
1377  std::vector<std::size_t>::iterator i = v.begin();
1378  std::vector<std::size_t>::iterator endit = v.end();
1379  while (i != endit && (*i) != candidate) {
1380  i++;
1381  }
1382  if (i == endit) {
1383  v.push_back(candidate);
1384  }
1385 
1386  }
1387 
1394  void AssembleRHS(
1395  TSystemVectorType& rb,
1396  const LocalSystemVectorType& rRHSContribution,
1397  const EquationIdVectorType& rEquationId
1398  )
1399  {
1400  SizeType local_size = rRHSContribution.size();
1401 
1402  if (BaseType::mCalculateReactionsFlag == false) {
1403  for (IndexType i_local = 0; i_local < local_size; ++i_local) {
1404  const IndexType i_global = rEquationId[i_local];
1405 
1406  if (i_global < BaseType::mEquationSystemSize) { // Free dof
1407  // ASSEMBLING THE SYSTEM VECTOR
1408  double& b_value = rb[i_global];
1409  const double& rhs_value = rRHSContribution[i_local];
1410 
1411  AtomicAdd(b_value, rhs_value);
1412  }
1413  }
1414  } else {
1415  TSystemVectorType& r_reactions_vector = *BaseType::mpReactionsVector;
1416  for (IndexType i_local = 0; i_local < local_size; ++i_local) {
1417  const IndexType i_global = rEquationId[i_local];
1418 
1419  if (i_global < BaseType::mEquationSystemSize) { //free dof
1420  // ASSEMBLING THE SYSTEM VECTOR
1421  double& b_value = rb[i_global];
1422  const double& rhs_value = rRHSContribution[i_local];
1423 
1424  AtomicAdd(b_value, rhs_value);
1425  } else { // Fixed dof
1426  double& b_value = r_reactions_vector[i_global - BaseType::mEquationSystemSize];
1427  const double& rhs_value = rRHSContribution[i_local];
1428 
1429  AtomicAdd(b_value, rhs_value);
1430  }
1431  }
1432  }
1433  }
1434 
1441  void AssembleLHSCompleteOnFreeRows(
1442  TSystemMatrixType& rA,
1443  LocalSystemMatrixType& rLHSContribution,
1444  EquationIdVectorType& rEquationId
1445  )
1446  {
1447  const SizeType local_size = rLHSContribution.size1();
1448  for (IndexType i_local = 0; i_local < local_size; ++i_local) {
1449  const IndexType i_global = rEquationId[i_local];
1450  if (i_global < BaseType::mEquationSystemSize) {
1451  for (IndexType j_local = 0; j_local < local_size; ++j_local) {
1452  const IndexType j_global = rEquationId[j_local];
1453  rA(i_global, j_global) += rLHSContribution(i_local, j_local);
1454  }
1455  }
1456  }
1457  }
1458 
1462 
1466 
1470 
1474 
1476 
1477 }; /* Class ResidualBasedEliminationBuilderAndSolver */
1478 
1480 
1483 
1485 
1486 } /* namespace Kratos.*/
1487 
1488 #endif /* KRATOS_RESIDUAL_BASED_ELIMINATION_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
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 void AssignSettings(const Parameters ThisParameters)
This method assigns settings to member variables.
Definition: builder_and_solver.h:780
TSystemVectorPointerType mpReactionsVector
Definition: builder_and_solver.h:751
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: builder_and_solver.h:767
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
bool mCalculateReactionsFlag
Flag taking care if the dof set was initialized ot not.
Definition: builder_and_solver.h:745
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
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
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
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
Communicator & GetCommunicator()
Definition: model_part.h:1821
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
This class defines the node.
Definition: node.h:65
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
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
ptr_iterator ptr_end()
Returns an iterator pointing to the end of the underlying data container.
Definition: pointer_vector_set.h:404
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 elimination builder and solving operations.
Definition: residualbased_elimination_builder_and_solver.h:76
Element::DofsVectorType DofsVectorType
Definition: residualbased_elimination_builder_and_solver.h:105
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_elimination_builder_and_solver.h:462
void SystemSolve(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
This is a call to the linear system solver.
Definition: residualbased_elimination_builder_and_solver.h:427
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: residualbased_elimination_builder_and_solver.h:991
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: residualbased_elimination_builder_and_solver.h:985
BaseType::ElementsContainerType ElementsContainerType
Definition: residualbased_elimination_builder_and_solver.h:114
IndexType ForwardFind(const IndexType id_to_find, const IndexType start, const IndexType *index_vector)
Definition: residualbased_elimination_builder_and_solver.h:1292
void CalculateReactions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
This method computes the reactions.
Definition: residualbased_elimination_builder_and_solver.h:862
void BuildLHS_CompleteOnFreeRows(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA) override
Build a rectangular matrix of size n*N where "n" is the number of unrestrained degrees of freedom and...
Definition: residualbased_elimination_builder_and_solver.h:352
void BuildRHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &rb) override
Function to perform the build of the RHS.
Definition: residualbased_elimination_builder_and_solver.h:572
ResidualBasedEliminationBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: residualbased_elimination_builder_and_solver.h:130
SCALING_DIAGONAL mScalingDiagonal
The manually set scale factor.
Definition: residualbased_elimination_builder_and_solver.h:1016
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition of the base class.
Definition: residualbased_elimination_builder_and_solver.h:85
BaseType::IndexType IndexType
Definition: residualbased_elimination_builder_and_solver.h:92
~ResidualBasedEliminationBuilderAndSolver() override
Definition: residualbased_elimination_builder_and_solver.h:151
BaseType::Pointer Create(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters) const override
Create method.
Definition: residualbased_elimination_builder_and_solver.h:160
void AssembleRowContributionFreeDofs(TSystemMatrixType &rA, const Matrix &rALocal, const IndexType i, const IndexType i_local, const Element::EquationIdVectorType &EquationId)
This function is equivalent to the AssembleRowContribution of the block builder and solver.
Definition: residualbased_elimination_builder_and_solver.h:1227
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: residualbased_elimination_builder_and_solver.h:100
ResidualBasedEliminationBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > ClassType
The definition of the current class.
Definition: residualbased_elimination_builder_and_solver.h:88
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_elimination_builder_and_solver.h:507
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: residualbased_elimination_builder_and_solver.h:101
Element::EquationIdVectorType EquationIdVectorType
Definition of the equation id vector.
Definition: residualbased_elimination_builder_and_solver.h:104
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_elimination_builder_and_solver.h:184
IndexType BackwardFind(const IndexType id_to_find, const IndexType start, const IndexType *index_vector)
Definition: residualbased_elimination_builder_and_solver.h:1301
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_elimination_builder_and_solver.h:897
BaseType::TSchemeType TSchemeType
Definition: residualbased_elimination_builder_and_solver.h:93
double mScaleFactor
Definition: residualbased_elimination_builder_and_solver.h:1014
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedEliminationBuilderAndSolver)
Pointer definition of ResidualBasedEliminationBuilderAndSolverWithConstraints.
void ResizeAndInitializeVectors(typename TSchemeType::Pointer pScheme, TSystemMatrixPointerType &pA, TSystemVectorPointerType &pDx, TSystemVectorPointerType &pb, ModelPart &rModelPart) override
This method resize and initializes the system of euqations.
Definition: residualbased_elimination_builder_and_solver.h:788
ResidualBasedEliminationBuilderAndSolver()
Default constructor.
Definition: residualbased_elimination_builder_and_solver.h:123
BaseType::TDataType TDataType
Definition: residualbased_elimination_builder_and_solver.h:94
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_elimination_builder_and_solver.h:97
std::string Info() const override
Turn back information as a string.
Definition: residualbased_elimination_builder_and_solver.h:979
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_elimination_builder_and_solver.h:98
void AssembleLHS(TSystemMatrixType &rA, LocalSystemMatrixType &rLHSContribution, EquationIdVectorType &rEquationId)
This method assembles the LHS of the system.
Definition: residualbased_elimination_builder_and_solver.h:1202
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_elimination_builder_and_solver.h:942
BaseType::DofsArrayType DofsArrayType
Definition: residualbased_elimination_builder_and_solver.h:95
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_elimination_builder_and_solver.h:550
BaseType::SizeType SizeType
Definition of the classes from the base class.
Definition: residualbased_elimination_builder_and_solver.h:91
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_elimination_builder_and_solver.h:646
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_elimination_builder_and_solver.h:99
BaseType::NodesArrayType NodesArrayType
Containers definition.
Definition: residualbased_elimination_builder_and_solver.h:111
BaseType::ConditionsArrayType ConditionsArrayType
Definition: residualbased_elimination_builder_and_solver.h:113
void Assemble(TSystemMatrixType &rA, TSystemVectorType &rb, const LocalSystemMatrixType &rLHSContribution, const LocalSystemVectorType &rRHSContribution, const Element::EquationIdVectorType &rEquationId)
This method assembles the system.
Definition: residualbased_elimination_builder_and_solver.h:1037
ResidualBasedEliminationBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver)
Constructor.
Definition: residualbased_elimination_builder_and_solver.h:143
void BuildLHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA) override
Function to perform the building of the LHS.
Definition: residualbased_elimination_builder_and_solver.h:274
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_elimination_builder_and_solver.h:912
Node NodeType
Node definition.
Definition: residualbased_elimination_builder_and_solver.h:108
BaseType::ElementsArrayType ElementsArrayType
Definition: residualbased_elimination_builder_and_solver.h:112
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residualbased_elimination_builder_and_solver.h:961
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_elimination_builder_and_solver.h:1314
virtual void ConstructMatrixStructure(typename TSchemeType::Pointer pScheme, TSystemMatrixType &rA, ModelPart &rModelPart)
This method constructs the relationship between the DoF.
Definition: residualbased_elimination_builder_and_solver.h:1078
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_elimination_builder_and_solver.h:96
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_elimination_builder_and_solver.h:930
void SetUpSystem(ModelPart &rModelPart) override
Organises the dofset in order to speed up the building phase.
Definition: residualbased_elimination_builder_and_solver.h:759
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
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
#define KRATOS_WARNING_IF(label, conditional)
Definition: logger.h:266
start
Definition: DEM_benchmarks.py:17
end
Definition: DEM_benchmarks.py:180
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
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
int local_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:17
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
integer i
Definition: TensorModule.f:17
Definition: timer.py:1