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.
block_builder_and_solver.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosSolidMechanicsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: March 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_BLOCK_BUILDER_AND_SOLVER_H_INCLUDED)
11 #define KRATOS_BLOCK_BUILDER_AND_SOLVER_H_INCLUDED
12 
13 // System includes
14 
15 // External includes
16 
17 // Project includes
19 #include "includes/key_hash.h"
20 
21 #ifdef USE_GOOGLE_HASH
22 #include "sparsehash/dense_hash_set" //included in external libraries
23 #else
24 #include <unordered_set>
25 #endif
26 
27 namespace Kratos
28 {
29 
32 
36 
40 
44 
48 
49 
53 template<class TSparseSpace,
54  class TDenseSpace, //= DenseSpace<double>,
55  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
56  >
57 class BlockBuilderAndSolver : public SolutionBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >
58 {
59  public:
60 
63 
66 
68 
69  typedef typename BaseType::Pointer BasePointerType;
70 
73 
80 
84 
87 
89  {
90  size_t operator()(const Node::DofType::Pointer& it) const
91  {
92  std::size_t seed = 0;
93  HashCombine(seed, it->Id());
94  HashCombine(seed, (it->GetVariable()).Key());
95  return seed;
96  }
97  };
98 
100  {
101  size_t operator()(const Node::DofType::Pointer& it1, const Node::DofType::Pointer& it2) const
102  {
103  return (((it1->Id() == it2->Id() && (it1->GetVariable()).Key())==(it2->GetVariable()).Key()));
104  }
105  };
106 
107 
111 
114  : BaseType(pLinearSystemSolver)
115  {
116  }
117 
120  {
121  }
122 
126 
130 
137  ModelPart& rModelPart,
138  SystemMatrixType& rA) override
139  {
140  KRATOS_TRY
141 
142  SystemVectorType tmp(rA.size1(), 0.0);
143  this->Build(pScheme, rModelPart, rA, tmp);
144 
145  KRATOS_CATCH("")
146  }
147 
153  ModelPart& rModelPart,
154  SystemVectorType& rb) override
155  {
156  KRATOS_TRY
157 
158  BuildRHSNoDirichlet(pScheme,rModelPart,rb);
159 
160  const int ndofs = static_cast<int>(this->mDofSet.size());
161 
162  //NOTE: dofs are assumed to be numbered consecutively in the BlockBuilderAndSolver
163 #pragma omp parallel for firstprivate(ndofs)
164  for (int k = 0; k<ndofs; k++)
165  {
166  typename DofsArrayType::iterator dof_iterator = this->mDofSet.begin() + k;
167  const std::size_t i = dof_iterator->EquationId();
168 
169  if (dof_iterator->IsFixed())
170  rb[i] = 0.0f;
171  }
172 
173  KRATOS_CATCH("")
174 
175  }
176 
181  void Build(SchemePointerType pScheme,
182  ModelPart& rModelPart,
183  SystemMatrixType& rA,
184  SystemVectorType& rb) override
185  {
186  KRATOS_TRY
187 
188  if (!pScheme)
189  KRATOS_ERROR << "No scheme provided!" << std::endl;
190 
191  //getting the elements from the model
192  const int nelements = static_cast<int>(rModelPart.Elements().size());
193 
194  //getting the array of the conditions
195  const int nconditions = static_cast<int>(rModelPart.Conditions().size());
196 
197  ProcessInfo& rCurrentProcessInfo = rModelPart.GetProcessInfo();
198  ModelPart::ElementsContainerType::iterator el_begin = rModelPart.ElementsBegin();
199  ModelPart::ConditionsContainerType::iterator cond_begin = rModelPart.ConditionsBegin();
200 
201  //contributions to the system
202  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
203  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
204 
205  //vector containing the localization in the system of the different terms
207 
208  // assemble all elements
209  // double start_build = OpenMPUtils::GetCurrentTime();
210 
211 #pragma omp parallel firstprivate(nelements,nconditions, LHS_Contribution, RHS_Contribution, EquationId )
212  {
213 # pragma omp for schedule(guided, 512) nowait
214  for (int k = 0; k < nelements; k++)
215  {
216  ModelPart::ElementsContainerType::iterator it = el_begin + k;
217 
218  //detect if the element is active or not. If the user did not make any choice the element
219  //is active by default
220  bool element_is_active = true;
221  if ((it)->IsDefined(ACTIVE))
222  element_is_active = (it)->Is(ACTIVE);
223 
224  if (element_is_active)
225  {
226  //calculate elemental contribution
227  pScheme->CalculateSystemContributions(*(it.base()), LHS_Contribution, RHS_Contribution, EquationId, rCurrentProcessInfo);
228 
229  //assemble the elemental contribution
230 #ifdef USE_LOCKS_IN_ASSEMBLY
231  Assemble(rA, rb, LHS_Contribution, RHS_Contribution, EquationId, mlock_array);
232 #else
233  Assemble(rA, rb, LHS_Contribution, RHS_Contribution, EquationId);
234 #endif
235  // clean local elemental memory
236  pScheme->Clear(*(it.base()));
237  }
238 
239  }
240 
241 
242  //#pragma omp parallel for firstprivate(nconditions, LHS_Contribution, RHS_Contribution, EquationId ) schedule(dynamic, 1024)
243 #pragma omp for schedule(guided, 512)
244  for (int k = 0; k < nconditions; k++)
245  {
246  ModelPart::ConditionsContainerType::iterator it = cond_begin + k;
247 
248  //detect if the condition is active or not. If the user did not make any choice the condition
249  //is active by default
250  bool condition_is_active = true;
251  if ((it)->IsDefined(ACTIVE))
252  condition_is_active = (it)->Is(ACTIVE);
253 
254  if (condition_is_active)
255  {
256  //calculate elemental contribution
257  pScheme->Condition_CalculateSystemContributions(*(it.base()), LHS_Contribution, RHS_Contribution, EquationId, rCurrentProcessInfo);
258 
259  //assemble the elemental contribution
260 #ifdef USE_LOCKS_IN_ASSEMBLY
261  Assemble(rA, rb, LHS_Contribution, RHS_Contribution, EquationId, mlock_array);
262 #else
263  Assemble(rA, rb, LHS_Contribution, RHS_Contribution, EquationId);
264 #endif
265 
266  // clean local elemental memory
267  pScheme->Clear(*(it.base()));
268  }
269  }
270  }
271 
272  // double stop_build = OpenMPUtils::GetCurrentTime();
273  // if (this->mEchoLevel > 2 && rModelPart.GetCommunicator().MyPID() == 0)
274  // KRATOS_INFO("parallel_build_time") << stop_build - start_build << std::endl;
275 
276  // if (this->mEchoLevel > 2 && rModelPart.GetCommunicator().MyPID() == 0){
277  // KRATOS_INFO("parallel_build") << "finished" << std::endl;
278  // }
279 
280  KRATOS_CATCH("")
281 
282  }
283 
288  SystemVectorType& rDx,
289  SystemVectorType& rb) override
290  {
291  KRATOS_TRY
292 
293  double norm_b;
294  if (TSparseSpace::Size(rb) != 0)
295  norm_b = TSparseSpace::TwoNorm(rb);
296  else
297  norm_b = 0.00;
298 
299  if (norm_b != 0.00)
300  {
301  //do solve
302  this->mpLinearSystemSolver->Solve(rA, rDx, rb);
303  }
304  else
305  TSparseSpace::SetToZero(rDx);
306 
307  //prints informations about the current time
308  if (this->mEchoLevel > 1)
309  {
310  KRATOS_INFO("linear_solver") << *(this->mpLinearSystemSolver) << std::endl;
311  }
312 
313  KRATOS_CATCH("")
314  }
315 
321  ModelPart& rModelPart,
322  SystemMatrixType& rA,
323  SystemVectorType& rDx,
324  SystemVectorType& rb) override
325  {
326  KRATOS_TRY
327 
328  // double begin_time = OpenMPUtils::GetCurrentTime();
329  Build(pScheme, rModelPart, rA, rb);
330  // double end_time = OpenMPUtils::GetCurrentTime();
331 
332  // if (this->mEchoLevel > 1 && rModelPart.GetCommunicator().MyPID() == 0)
333  // KRATOS_INFO("system_build_time") << end_time - begin_time << std::endl;
334 
335  ApplyDirichletConditions(pScheme, rModelPart, rA, rDx, rb);
336 
337  if (this->mEchoLevel == 3)
338  {
339  KRATOS_INFO("LHS before solve") << "Matrix = " << rA << std::endl;
340  KRATOS_INFO("Dx before solve") << "Solution = " << rDx << std::endl;
341  KRATOS_INFO("RHS before solve") << "Vector = " << rb << std::endl;
342  }
343 
344  // begin_time = OpenMPUtils::GetCurrentTime();
345  SystemSolveWithPhysics(rA, rDx, rb, rModelPart);
346  // end_time = OpenMPUtils::GetCurrentTime();
347 
348 
349  // if (this->mEchoLevel > 1 && rModelPart.GetCommunicator().MyPID() == 0)
350  // KRATOS_INFO("system_solve_time") << end_time - begin_time << std::endl;
351 
352  if (this->mEchoLevel == 3)
353  {
354  KRATOS_INFO("LHS after solve") << "Matrix = " << rA << std::endl;
355  KRATOS_INFO("Dx after solve") << "Solution = " << rDx << std::endl;
356  KRATOS_INFO("RHS after solve") << "Vector = " << rb << std::endl;
357  }
358 
359  KRATOS_CATCH("")
360  }
361 
367  ModelPart& rModelPart,
368  SystemMatrixType& rA,
369  SystemVectorType& rDx,
370  SystemVectorType& rb) override
371  {
372  KRATOS_TRY
373 
374  BuildRHS(pScheme, rModelPart, rb);
375  SystemSolve(rA, rDx, rb);
376 
377  KRATOS_CATCH("")
378  }
379 
380 
389  ModelPart& rModelPart,
390  SystemMatrixType& rA,
391  SystemVectorType& rDx,
392  SystemVectorType& rb) override
393  {
394  std::size_t system_size = rA.size1();
395  std::vector<double> scaling_factors (system_size, 0.0f);
396 
397  const int ndofs = static_cast<int>(this->mDofSet.size());
398 
399  //NOTE: dofs are assumed to be numbered consecutively in the BlockBuilderAndSolver
400 #pragma omp parallel for firstprivate(ndofs)
401  for(int k = 0; k<ndofs; k++)
402  {
403  typename DofsArrayType::iterator dof_iterator = this->mDofSet.begin() + k;
404  if(dof_iterator->IsFixed())
405  scaling_factors[k] = 0.0f;
406  else
407  scaling_factors[k] = 1.0f;
408 
409  }
410 
411  double* Avalues = rA.value_data().begin();
412  std::size_t* Arow_indices = rA.index1_data().begin();
413  std::size_t* Acol_indices = rA.index2_data().begin();
414 
415  //detect if there is a line of all zeros and set the diagonal to a 1 if this happens
416 #pragma omp parallel for firstprivate(system_size)
417  for(int k = 0; k < static_cast<int>(system_size); ++k)
418  {
419  std::size_t col_begin = Arow_indices[k];
420  std::size_t col_end = Arow_indices[k+1];
421  bool empty = true;
422  for (std::size_t j = col_begin; j < col_end; ++j)
423  {
424  if(Avalues[j] != 0.0)
425  {
426  empty = false;
427  break;
428  }
429  }
430 
431  if(empty == true)
432  {
433  rA(k,k) = 1.0;
434  rb[k] = 0.0;
435  }
436  }
437 
438 #pragma omp parallel for
439  for (int k = 0; k < static_cast<int>(system_size); ++k)
440  {
441  std::size_t col_begin = Arow_indices[k];
442  std::size_t col_end = Arow_indices[k+1];
443  double k_factor = scaling_factors[k];
444  if (k_factor == 0)
445  {
446  // zero out the whole row, except the diagonal
447  for (std::size_t j = col_begin; j < col_end; ++j)
448  if (static_cast<int>(Acol_indices[j]) != k )
449  Avalues[j] = 0.0;
450 
451  // zero out the RHS
452  rb[k] = 0.0;
453  }
454  else
455  {
456  // zero out the column which is associated with the zero'ed row
457  for (std::size_t j = col_begin; j < col_end; ++j)
458  if(scaling_factors[ Acol_indices[j] ] == 0 )
459  Avalues[j] = 0.0;
460  }
461  }
462  }
463 
469  ModelPart& rModelPart) override
470  {
471  KRATOS_TRY
472 
473  if( this->mEchoLevel > 1 && rModelPart.GetCommunicator().MyPID() == 0)
474  {
475  KRATOS_INFO("setting_dofs") << "SetUpDofSet starts" << std::endl;
476  }
477 
478  //Gets the array of elements from the modeler
479  ElementsContainerType& rElements = rModelPart.Elements();
480  const int nelements = static_cast<int>(rElements.size());
481 
482  Element::DofsVectorType ElementalDofList;
483 
484  ProcessInfo& rCurrentProcessInfo = rModelPart.GetProcessInfo();
485 
486  unsigned int nthreads = ParallelUtilities::GetNumThreads();
487 
488 #ifdef USE_GOOGLE_HASH
489  typedef google::dense_hash_set < Node::DofType::Pointer, dof_iterator_hash> set_type;
490 #else
491  typedef std::unordered_set < Node::DofType::Pointer, dof_iterator_hash> set_type;
492 #endif
493 
494  std::vector<set_type> dofs_aux_list(nthreads);
495 
496  if( this->mEchoLevel > 2)
497  {
498  KRATOS_INFO("setting_dofs") << "Number of threads:" << nthreads << std::endl;
499  }
500 
501  for (int i = 0; i < static_cast<int>(nthreads); i++)
502  {
503 #ifdef USE_GOOGLE_HASH
504  dofs_aux_list[i].set_empty_key(Node::DofType::Pointer());
505 #else
506  dofs_aux_list[i].reserve(nelements);
507 #endif
508  }
509 
510  if( this->mEchoLevel > 2)
511  {
512  KRATOS_INFO("setting_dofs") << "initialize_elements" << std::endl;
513  }
514 
515 #pragma omp parallel firstprivate(nelements, ElementalDofList)
516  {
517 #pragma omp for schedule(guided, 512) nowait
518  for (int i = 0; i < nelements; i++)
519  {
520  typename ElementsContainerType::iterator it = rElements.begin() + i;
521  const unsigned int this_thread_id = OpenMPUtils::ThisThread();
522 
523  // gets list of Dof involved on every element
524  pScheme->GetElementalDofList(*(it.base()), ElementalDofList, rCurrentProcessInfo);
525 
526  dofs_aux_list[this_thread_id].insert(ElementalDofList.begin(), ElementalDofList.end());
527  }
528 
529  if( this->mEchoLevel > 2)
530  {
531  KRATOS_INFO("setting_dofs") << "initialize_conditions" << std::endl;
532  }
533 
534  ConditionsContainerType& rConditions = rModelPart.Conditions();
535  const int nconditions = static_cast<int>(rConditions.size());
536 #pragma omp for schedule(guided, 512)
537  for (int i = 0; i < nconditions; i++)
538  {
539  typename ConditionsContainerType::iterator it = rConditions.begin() + i;
540  const unsigned int this_thread_id = OpenMPUtils::ThisThread();
541 
542  // gets list of Dof involved on every condition
543  pScheme->GetConditionDofList(*(it.base()), ElementalDofList, rCurrentProcessInfo);
544  dofs_aux_list[this_thread_id].insert(ElementalDofList.begin(), ElementalDofList.end());
545 
546  }
547  }
548 
549  if( this->mEchoLevel > 2)
550  {
551  KRATOS_INFO("setting_dofs") << "initialize tree reduction" << std::endl;
552  }
553 
554  // Here we do a reduction in a tree so to have everything on thread 0
555  unsigned int old_max = nthreads;
556  unsigned int new_max = ceil(0.5*static_cast<double>(old_max));
557  while (new_max>=1 && new_max != old_max)
558  {
559  if( this->mEchoLevel > 2)
560  {
561  //just for debugging
562  KRATOS_INFO("setting_dofs") << "old_max" << old_max << " new_max:" << new_max << std::endl;
563  for (int i = 0; i < static_cast<int>(new_max); i++)
564  {
565  if (i + new_max < old_max)
566  {
567  KRATOS_INFO("setting_dofs") << i << " - " << i+new_max << std::endl;
568  }
569  }
570  }
571 
572 #pragma omp parallel for
573  for (int i = 0; i < static_cast<int>(new_max); i++)
574  {
575  if (i + new_max < old_max)
576  {
577  dofs_aux_list[i].insert(dofs_aux_list[i+new_max].begin(), dofs_aux_list[i+new_max].end());
578  dofs_aux_list[i+new_max].clear();
579  }
580  }
581 
582  old_max = new_max;
583  new_max = ceil(0.5*static_cast<double>(old_max));
584 
585  }
586 
587  if( this->mEchoLevel > 2)
588  {
589  KRATOS_INFO("setting_dofs") << "initializing ordered array filling" << std::endl;
590  }
591 
592  DofsArrayType Doftemp;
593  this->mDofSet = DofsArrayType();
594 
595  Doftemp.reserve(dofs_aux_list[0].size());
596  for (auto it= dofs_aux_list[0].begin(); it!= dofs_aux_list[0].end(); it++)
597  {
598  Doftemp.push_back( *it );
599  }
600  Doftemp.Sort();
601 
602  this->mDofSet = Doftemp;
603 
604  //Throws an exception if there are no Degrees Of Freedom involved in the analysis
605  if (this->mDofSet.size() == 0)
606  {
607  KRATOS_ERROR << "No degrees of freedom!" << std::endl;
608  }
609  if( this->mEchoLevel > 2)
610  {
611  KRATOS_INFO("Dofs size") << this->mDofSet.size() << std::endl;
612  }
613 
614  if( this->mEchoLevel > 2 && rModelPart.GetCommunicator().MyPID() == 0)
615  {
616  KRATOS_INFO("setting_dofs") << "Finished setting up the dofs" << std::endl;
617  }
618 
619  if( this->mEchoLevel > 2)
620  {
621  KRATOS_INFO("setting_dofs") << "Initializing lock array" << std::endl;
622  }
623 
624 #ifdef _OPENMP
625  if (mlock_array.size() != 0)
626  {
627  for (int i = 0; i < static_cast<int>(mlock_array.size()); i++)
628  {
629  omp_destroy_lock(&mlock_array[i]);
630  }
631  }
632  mlock_array.resize(this->mDofSet.size());
633 
634  for (int i = 0; i < static_cast<int>(mlock_array.size()); i++)
635  {
636  omp_init_lock(&mlock_array[i]);
637  }
638 #endif
639 
640  if( this->mEchoLevel > 2)
641  {
642  KRATOS_INFO("setting_dofs") << "End of setupdofset" << std::endl;
643  }
644 
645  this->Set(LocalFlagType::DOFS_INITIALIZED, true);
646 
647  KRATOS_CATCH("")
648  }
649 
653  void SetUpSystem() override
654  {
655 
656  //int free_id = 0;
657  this->mEquationSystemSize = this->mDofSet.size();
658  int ndofs = static_cast<int>(this->mDofSet.size());
659 
660 #pragma omp parallel for firstprivate(ndofs)
661  for (int i = 0; i < static_cast<int>(ndofs); i++)
662  {
663  typename DofsArrayType::iterator dof_iterator = this->mDofSet.begin() + i;
664  dof_iterator->SetEquationId(i);
665  }
666 
667  }
668 
673  ModelPart& rModelPart,
676  SystemVectorPointerType& pb) override
677  {
678  KRATOS_TRY
679 
680  if (pA == nullptr) //if the pointer is not initialized initialize it to an empty matrix
681  {
682  SystemMatrixPointerType pNewA = Kratos::make_shared<SystemMatrixType>(0, 0);
683  pA.swap(pNewA);
684  }
685  if (pDx == nullptr) //if the pointer is not initialized initialize it to an empty matrix
686  {
687  SystemVectorPointerType pNewDx = Kratos::make_shared<SystemVectorType>(0);
688  pDx.swap(pNewDx);
689  }
690  if (pb == nullptr) //if the pointer is not initialized initialize it to an empty matrix
691  {
692  SystemVectorPointerType pNewb = Kratos::make_shared<SystemVectorType>(0);
693  pb.swap(pNewb);
694  }
695 
696  SystemMatrixType& rA = *pA;
697  SystemVectorType& rDx = *pDx;
698  SystemVectorType& rb = *pb;
699 
700  //resizing the system vectors and matrix
701  if (rA.size1() == 0 || this->mOptions.Is(LocalFlagType::REFORM_DOFS)) //if the matrix is not initialized
702  {
703  rA.resize(this->mEquationSystemSize, this->mEquationSystemSize, false);
704  ConstructMatrixStructure(pScheme, rA, rModelPart.Elements(), rModelPart.Conditions(), rModelPart.GetProcessInfo());
705  }
706  else
707  {
708  if (rA.size1() != this->mEquationSystemSize || rA.size2() != this->mEquationSystemSize)
709  {
710  KRATOS_WARNING("block builder resize") << "it should not come here -> this is SLOW" << std::endl;
711  rA.resize(this->mEquationSystemSize, this->mEquationSystemSize, true);
712  ConstructMatrixStructure(pScheme, rA, rModelPart.Elements(), rModelPart.Conditions(), rModelPart.GetProcessInfo());
713  }
714  }
715  if (rDx.size() != this->mEquationSystemSize)
716  rDx.resize(this->mEquationSystemSize, false);
717  if (rb.size() != this->mEquationSystemSize)
718  rb.resize(this->mEquationSystemSize, false);
719 
720  KRATOS_CATCH("")
721 
722  }
723 
724 
729  void InitializeSolutionStep(SchemePointerType pScheme,
730  ModelPart& rModelPart,
733  SystemVectorPointerType& pb) override
734  {
735  KRATOS_TRY
736 
737  BaseType::InitializeSolutionStep(pScheme, rModelPart, pA, pDx, pb);
738 
739  // // Initialize
740  // pScheme->InitializeSolutionStep(rModelPart);
741 
742  // // Set up the system dofs and shape
743  // if(this->mOptions.Is(LocalFlagType::REFORM_DOFS))
744  // this->SetSystemDofs(pScheme, rModelPart);
745 
746  // // Set up system matrices and vectors
747  // double begin_time = OpenMPUtils::GetCurrentTime();
748  // this->SetUpSystemMatrices(pScheme, pA, pDx, pb);
749  // double end_time = OpenMPUtils::GetCurrentTime();
750 
751  // if (this->mEchoLevel >= 2)
752  // KRATOS_INFO("system_resize_time") << ": system_resize_time : " << end_time - begin_time << "\n" << LoggerMessage::Category::STATISTICS;
753 
754  KRATOS_CATCH("")
755  }
756 
762  ModelPart& rModelPart,
765  SystemVectorPointerType& pb) override
766  {
767  KRATOS_TRY
768 
769  BaseType::FinalizeSolutionStep(pScheme, rModelPart, pA, pDx, pb);
770 
771  KRATOS_CATCH("")
772  }
773 
780  ModelPart& rModelPart,
781  SystemMatrixType& rA,
782  SystemVectorType& rDx,
783  SystemVectorType& rb) override
784  {
785  TSparseSpace::SetToZero(rb);
786 
787  //refresh RHS to have the correct reactions
788  BuildRHSNoDirichlet(pScheme, rModelPart, rb);
789 
790  const int ndofs = static_cast<int>(this->mDofSet.size());
791 
792  //NOTE: dofs are assumed to be numbered consecutively in the BlockBuilderAndSolver
793 #pragma omp parallel for firstprivate(ndofs)
794  for (int k = 0; k<ndofs; k++)
795  {
796  typename DofsArrayType::iterator dof_iterator = this->mDofSet.begin() + k;
797 
798  const int i = (dof_iterator)->EquationId();
799  if ( (dof_iterator)->IsFixed() ) {
800  (dof_iterator)->GetSolutionStepReactionValue() = -rb[i];
801  } else{
802  (dof_iterator)->GetSolutionStepReactionValue() = 0.0;
803  }
804 
805 
806  }
807 
808  }
809 
813  void Clear() override
814  {
815 
816  BaseType::Clear();
817 
818 #ifdef _OPENMP
819  for (int i = 0; i < static_cast<int>(mlock_array.size()); i++)
820  omp_destroy_lock(&mlock_array[i]);
821  mlock_array.resize(0);
822 #endif
823 
824  }
825 
833  int Check(ModelPart& r_mUSE_GOOGLE_HASHodel_part) override
834  {
835  KRATOS_TRY
836 
837  return 0;
838 
839  KRATOS_CATCH("");
840  }
841 
845 
849 
853 
855 
856  protected:
859 
863 
864 #ifdef _OPENMP
865  std::vector< omp_lock_t > mlock_array;
866 #endif
867 
871 
875 
877  SystemVectorType& rDx,
878  SystemVectorType& rb,
879  ModelPart& rModelPart)
880  {
881  KRATOS_TRY
882 
883  double norm_b;
884  if (TSparseSpace::Size(rb) != 0)
885  norm_b = TSparseSpace::TwoNorm(rb);
886  else
887  norm_b = 0.00;
888 
889  if (norm_b != 0.00)
890  {
891  //provide physical data as needed
892  if(this->mpLinearSystemSolver->AdditionalPhysicalDataIsNeeded() )
893  this->mpLinearSystemSolver->ProvideAdditionalData(rA, rDx, rb, this->mDofSet, rModelPart);
894 
895  //do solve
896  this->mpLinearSystemSolver->Solve(rA, rDx, rb);
897  }
898  else
899  {
900  TSparseSpace::SetToZero(rDx);
901  KRATOS_WARNING("RHS") << "ATTENTION! setting the RHS to zero!" << std::endl;
902  }
903 
904  //prints informations about the current time
905  if (this->mEchoLevel > 1)
906  {
907  KRATOS_INFO("LinearSolver") << *(this->mpLinearSystemSolver) << std::endl;
908  }
909 
910  KRATOS_CATCH("")
911 
912  }
913 
915  SystemMatrixType& rA,
916  ElementsContainerType& rElements,
917  ConditionsContainerType& rConditions,
918  ProcessInfo& rCurrentProcessInfo)
919  {
920  //filling with zero the matrix (creating the structure)
921  // double begin_time = OpenMPUtils::GetCurrentTime();
922 
923  const std::size_t equation_size = this->mEquationSystemSize;
924 
925 #ifdef USE_GOOGLE_HASH
926  std::vector<google::dense_hash_set<std::size_t> > indices(equation_size);
927  const std::size_t empty_key = 2*equation_size + 10;
928 #else
929  std::vector<std::unordered_set<std::size_t> > indices(equation_size);
930 #endif
931 
932 #pragma omp parallel for firstprivate(equation_size)
933  for (int iii = 0; iii < static_cast<int>(equation_size); iii++)
934  {
935 #ifdef USE_GOOGLE_HASH
936  indices[iii].set_empty_key(empty_key);
937 #else
938  indices[iii].reserve(40);
939 #endif
940  }
941 
943 
944  const int nelements = static_cast<int>(rElements.size());
945 #pragma omp parallel for firstprivate(nelements, ids)
946  for(int iii=0; iii<nelements; iii++)
947  {
948  typename ElementsContainerType::iterator i_element = rElements.begin() + iii;
949  pScheme->EquationId( *(i_element.base()) , ids, rCurrentProcessInfo);
950  for (std::size_t i = 0; i < ids.size(); i++)
951  {
952 #ifdef _OPENMP
953  omp_set_lock(&mlock_array[ids[i]]);
954 #endif
955  auto& row_indices = indices[ids[i]];
956  row_indices.insert(ids.begin(), ids.end());
957 
958 #ifdef _OPENMP
959  omp_unset_lock(&mlock_array[ids[i]]);
960 #endif
961  }
962 
963  }
964 
965  const int nconditions = static_cast<int>(rConditions.size());
966 #pragma omp parallel for firstprivate(nconditions, ids)
967  for (int iii = 0; iii<nconditions; iii++)
968  {
969  typename ConditionsContainerType::iterator i_condition = rConditions.begin() + iii;
970  pScheme->Condition_EquationId( *(i_condition.base()), ids, rCurrentProcessInfo);
971  for (std::size_t i = 0; i < ids.size(); i++)
972  {
973 #ifdef _OPENMP
974  omp_set_lock(&mlock_array[ids[i]]);
975 #endif
976  auto& row_indices = indices[ids[i]];
977  row_indices.insert(ids.begin(), ids.end());
978 #ifdef _OPENMP
979  omp_unset_lock(&mlock_array[ids[i]]);
980 #endif
981  }
982  }
983 
984  //count the row sizes
985  unsigned int nnz = 0;
986  for (unsigned int i = 0; i < indices.size(); i++)
987  nnz += indices[i].size();
988 
989  rA = boost::numeric::ublas::compressed_matrix<double>(indices.size(), indices.size(), nnz);
990 
991  double* Avalues = rA.value_data().begin();
992  std::size_t* Arow_indices = rA.index1_data().begin();
993  std::size_t* Acol_indices = rA.index2_data().begin();
994 
995  //filling the index1 vector - DO NOT MAKE PARALLEL THE FOLLOWING LOOP!
996  Arow_indices[0] = 0;
997  for (int i = 0; i < static_cast<int>(rA.size1()); i++)
998  Arow_indices[i+1] = Arow_indices[i] + indices[i].size();
999 
1000 
1001 #pragma omp parallel for
1002  for (int i = 0; i < static_cast<int>(rA.size1()); i++)
1003  {
1004  const unsigned int row_begin = Arow_indices[i];
1005  const unsigned int row_end = Arow_indices[i+1];
1006  unsigned int k = row_begin;
1007  for (auto it = indices[i].begin(); it != indices[i].end(); it++)
1008  {
1009  Acol_indices[k] = *it;
1010  Avalues[k] = 0.0;
1011  k++;
1012  }
1013 
1014  indices[i].clear(); //deallocating the memory
1015 
1016  std::sort(&Acol_indices[row_begin], &Acol_indices[row_end]);
1017 
1018  }
1019 
1020  rA.set_filled(indices.size()+1, nnz);
1021 
1022  // double end_time = OpenMPUtils::GetCurrentTime();
1023  // if (this->mEchoLevel >= 2)
1024  // KRATOS_INFO("BlockBuilderAndSolver") << "construct matrix structure time:" << end_time - begin_time << "\n" << LoggerMessage::Category::STATISTICS;
1025 
1026  }
1027 
1028 
1030  LocalSystemMatrixType& rLHS_Contribution,
1031  Element::EquationIdVectorType& rEquationId)
1032  {
1033  unsigned int local_size = rLHS_Contribution.size1();
1034 
1035  for (unsigned int i_local = 0; i_local < local_size; i_local++)
1036  {
1037  unsigned int i_global = rEquationId[i_local];
1038 
1039  for (unsigned int j_local = 0; j_local < local_size; j_local++)
1040  {
1041  unsigned int j_global = rEquationId[j_local];
1042 
1043  rA(i_global, j_global) += rLHS_Contribution(i_local, j_local);
1044  }
1045  }
1046 
1047  }
1048 
1050  LocalSystemVectorType& rRHS_Contribution,
1051  Element::EquationIdVectorType& rEquationId)
1052  {
1053  unsigned int local_size = rRHS_Contribution.size();
1054 
1055  for (unsigned int i_local = 0; i_local < local_size; i_local++)
1056  {
1057  unsigned int i_global = rEquationId[i_local];
1058 
1059  // ASSEMBLING THE SYSTEM VECTOR
1060  double& b_value = rb[i_global];
1061  const double& rhs_value = rRHS_Contribution[i_local];
1062 
1063 #pragma omp atomic
1064  b_value += rhs_value;
1065  }
1066  }
1067 
1069  SystemVectorType& rb,
1070  const LocalSystemMatrixType& rLHS_Contribution,
1071  const LocalSystemVectorType& rRHS_Contribution,
1072  Element::EquationIdVectorType& rEquationId
1073 #ifdef USE_LOCKS_IN_ASSEMBLY
1074  ,std::vector< omp_lock_t >& lock_array
1075 #endif
1076  )
1077  {
1078  unsigned int local_size = rLHS_Contribution.size1();
1079 
1080  for (unsigned int i_local = 0; i_local < local_size; i_local++)
1081  {
1082  unsigned int i_global = rEquationId[i_local];
1083 
1084 #ifdef USE_LOCKS_IN_ASSEMBLY
1085  omp_set_lock(&lock_array[i_global]);
1086  b[i_global] += rRHS_Contribution(i_local);
1087 #else
1088  double& r_a = rb[i_global];
1089  const double& v_a = rRHS_Contribution(i_local);
1090 #pragma omp atomic
1091  r_a += v_a;
1092 #endif
1093 
1094  AssembleRowContribution(rA, rLHS_Contribution, i_global, i_local, rEquationId);
1095 
1096 #ifdef USE_LOCKS_IN_ASSEMBLY
1097  omp_unset_lock(&lock_array[i_global]);
1098 #endif
1099  //note that computation of reactions is not performed here!
1100  }
1101  }
1102 
1106 
1110 
1114 
1116 
1117  private:
1120 
1124 
1128 
1132 
1133  inline void AddUnique(std::vector<std::size_t>& v, const std::size_t& candidate)
1134  {
1135  std::vector<std::size_t>::iterator i = v.begin();
1136  std::vector<std::size_t>::iterator endit = v.end();
1137  while (i != endit && (*i) != candidate)
1138  {
1139  ++i;
1140  }
1141  if (i == endit)
1142  {
1143  v.push_back(candidate);
1144  }
1145 
1146  }
1147 
1148  void BuildRHSNoDirichlet(SchemePointerType pScheme,
1149  ModelPart& rModelPart,
1150  SystemVectorType& rb)
1151  {
1152  KRATOS_TRY
1153 
1154  //Getting the Elements
1155  ElementsContainerType& rElements = rModelPart.Elements();
1156 
1157  //getting the array of the conditions
1158  ConditionsContainerType& ConditionsArray = rModelPart.Conditions();
1159 
1160  ProcessInfo& rCurrentProcessInfo = rModelPart.GetProcessInfo();
1161 
1162  //contributions to the system
1163  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
1164  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
1165 
1166  //vector containing the localization in the system of the different
1167  //terms
1168  Element::EquationIdVectorType EquationId;
1169 
1170  // assemble all elements
1171  //for (typename ElementsContainerType::ptr_iterator it = rElements.ptr_begin(); it != rElements.ptr_end(); ++it)
1172 
1173  const int nelements = static_cast<int>(rElements.size());
1174 #pragma omp parallel firstprivate(nelements, RHS_Contribution, EquationId)
1175  {
1176 #pragma omp for schedule(guided, 512) nowait
1177  for(int i=0; i<nelements; i++)
1178  {
1179  typename ElementsContainerType::iterator it = rElements.begin() + i;
1180  //detect if the element is active or not. If the user did not make any choice the element
1181  //is active by default
1182  bool element_is_active = true;
1183  if( (it)->IsDefined(ACTIVE) )
1184  element_is_active = (it)->Is(ACTIVE);
1185 
1186  if(element_is_active)
1187  {
1188  //calculate elemental Right Hand Side Contribution
1189  pScheme->Calculate_RHS_Contribution(*(it.base()), RHS_Contribution, EquationId, rCurrentProcessInfo);
1190 
1191  //assemble the elemental contribution
1192  AssembleRHS(rb, RHS_Contribution, EquationId);
1193  }
1194  }
1195 
1196  LHS_Contribution.resize(0, 0, false);
1197  RHS_Contribution.resize(0, false);
1198 
1199  // assemble all conditions
1200  //for (typename ConditionsContainerType::ptr_iterator it = ConditionsArray.ptr_begin(); it != ConditionsArray.ptr_end(); ++it)
1201  const int nconditions = static_cast<int>(ConditionsArray.size());
1202  //#pragma omp parallel for firstprivate(nconditions, RHS_Contribution, EquationId) schedule(dynamic, 1024)
1203 #pragma omp for schedule(guided, 512)
1204  for (int i = 0; i<nconditions; i++)
1205  {
1206  auto it = ConditionsArray.begin() + i;
1207  //detect if the element is active or not. If the user did not make any choice the element
1208  //is active by default
1209  bool condition_is_active = true;
1210  if( (it)->IsDefined(ACTIVE) )
1211  condition_is_active = (it)->Is(ACTIVE);
1212 
1213  if(condition_is_active)
1214  {
1215  //calculate elemental contribution
1216  pScheme->Condition_Calculate_RHS_Contribution(*(it.base()), RHS_Contribution, EquationId, rCurrentProcessInfo);
1217 
1218  //assemble the elemental contribution
1219  AssembleRHS(rb, RHS_Contribution, EquationId);
1220  }
1221  }
1222  }
1223 
1224  KRATOS_CATCH("")
1225  }
1226 
1227 
1228  inline void CreatePartition(unsigned int number_of_threads,
1229  const int number_of_rows,
1230  vector<unsigned int>& partitions)
1231  {
1232  partitions.resize(number_of_threads + 1);
1233  int partition_size = number_of_rows / number_of_threads;
1234  partitions[0] = 0;
1235  partitions[number_of_threads] = number_of_rows;
1236  for (unsigned int i = 1; i < number_of_threads; i++)
1237  partitions[i] = partitions[i - 1] + partition_size;
1238  }
1239 
1240  inline void AssembleRowContribution(SystemMatrixType& rA,
1241  const Matrix& rAlocal,
1242  const unsigned int i,
1243  const unsigned int i_local,
1244  Element::EquationIdVectorType& rEquationId)
1245  {
1246  double* values_vector = rA.value_data().begin();
1247  std::size_t* index1_vector = rA.index1_data().begin();
1248  std::size_t* index2_vector = rA.index2_data().begin();
1249 
1250  size_t left_limit = index1_vector[i];
1251  // size_t right_limit = index1_vector[i+1];
1252 
1253  //find the first entry
1254  size_t last_pos = ForwardFind(rEquationId[0],left_limit,index2_vector);
1255  size_t last_found = rEquationId[0];
1256 
1257 #ifndef USE_LOCKS_IN_ASSEMBLY
1258  double& r_a = values_vector[last_pos];
1259  const double& v_a = rAlocal(i_local,0);
1260 #pragma omp atomic
1261  r_a += v_a;
1262 #else
1263  values_vector[last_pos] += rAlocal(i_local,0);
1264 #endif
1265 
1266  //now find all of the other entries
1267  size_t pos = 0;
1268  for(unsigned int j=1; j<rEquationId.size(); j++)
1269  {
1270  unsigned int id_to_find = rEquationId[j];
1271  if(id_to_find > last_found)
1272  pos = ForwardFind(id_to_find,last_pos+1,index2_vector);
1273  else
1274  pos = BackwardFind(id_to_find,last_pos-1,index2_vector);
1275 
1276 #ifndef USE_LOCKS_IN_ASSEMBLY
1277  double& r = values_vector[pos];
1278  const double& v = rAlocal(i_local,j);
1279 #pragma omp atomic
1280  r += v;
1281 #else
1282  values_vector[pos] += rAlocal(i_local,j);
1283 #endif
1284 
1285  last_found = id_to_find;
1286  last_pos = pos;
1287  }
1288  }
1289 
1290  inline unsigned int ForwardFind(const unsigned int id_to_find,
1291  const unsigned int start,
1292  const size_t* index_vector)
1293  {
1294  unsigned int pos = start;
1295  while(id_to_find != index_vector[pos]) pos++;
1296  return pos;
1297  }
1298 
1299  inline unsigned int BackwardFind(const unsigned int id_to_find,
1300  const unsigned int start,
1301  const size_t* index_vector)
1302  {
1303  unsigned int pos = start;
1304  while(id_to_find != index_vector[pos]) pos--;
1305  return pos;
1306  }
1307 
1311 
1315 
1319 
1323 
1325 
1326 }; // Class BlockBuilderAndSolver
1328 
1331 
1335 
1336 
1338 
1340 
1341 } // namespace Kratos
1342 
1343 #endif // KRATOS_BLOCK_BUILDER_AND_SOLVER_H_INCLUDED defined
Solution Buider and Solver based on block matrix.
Definition: block_builder_and_solver.hpp:58
ModelPart::ElementsContainerType ElementsContainerType
Definition: block_builder_and_solver.hpp:82
void InitializeSolutionStep(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixPointerType &pA, SystemVectorPointerType &pDx, SystemVectorPointerType &pb) override
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: block_builder_and_solver.hpp:729
BaseType::SystemVectorType SystemVectorType
Definition: block_builder_and_solver.hpp:75
BaseType::SystemMatrixPointerType SystemMatrixPointerType
Definition: block_builder_and_solver.hpp:76
void SetUpSystemMatrices(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixPointerType &pA, SystemVectorPointerType &pDx, SystemVectorPointerType &pb) override
Resizes and Initializes the system vectors and matrices after SetUpDofSet and SetUpSytem has been cal...
Definition: block_builder_and_solver.hpp:672
void SystemSolveWithPhysics(SystemMatrixType &rA, SystemVectorType &rDx, SystemVectorType &rb, ModelPart &rModelPart)
Definition: block_builder_and_solver.hpp:876
BlockBuilderAndSolver(LinearSolverPointerType pLinearSystemSolver)
Default Constructor.
Definition: block_builder_and_solver.hpp:113
ModelPart::ConditionsContainerType ConditionsContainerType
Definition: block_builder_and_solver.hpp:83
BaseType::LocalFlagType LocalFlagType
Definition: block_builder_and_solver.hpp:71
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: block_builder_and_solver.hpp:78
void SetUpDofSet(SchemePointerType pScheme, ModelPart &rModelPart) override
Builds the list of the DofSets involved in the problem by "asking" to each element and condition its ...
Definition: block_builder_and_solver.hpp:468
void AssembleLHS(SystemMatrixType &rA, LocalSystemMatrixType &rLHS_Contribution, Element::EquationIdVectorType &rEquationId)
Definition: block_builder_and_solver.hpp:1029
BaseType::SystemVectorPointerType SystemVectorPointerType
Definition: block_builder_and_solver.hpp:77
void BuildRHSAndSolve(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixType &rA, SystemVectorType &rDx, SystemVectorType &rb) override
Function to perform the building of the RHS and solving phase at the same time.
Definition: block_builder_and_solver.hpp:366
void BuildAndSolve(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixType &rA, SystemVectorType &rDx, SystemVectorType &rb) override
Function to perform the building and solving phase at the same time.
Definition: block_builder_and_solver.hpp:320
virtual void ConstructMatrixStructure(SchemePointerType pScheme, SystemMatrixType &rA, ElementsContainerType &rElements, ConditionsContainerType &rConditions, ProcessInfo &rCurrentProcessInfo)
Definition: block_builder_and_solver.hpp:914
BaseType::DofsArrayType DofsArrayType
Definition: block_builder_and_solver.hpp:72
BaseType::LinearSolverPointerType LinearSolverPointerType
Definition: block_builder_and_solver.hpp:86
int Check(ModelPart &r_mUSE_GOOGLE_HASHodel_part) override
Definition: block_builder_and_solver.hpp:833
void BuildRHS(SchemePointerType pScheme, ModelPart &rModelPart, SystemVectorType &rb) override
Function to perform the build of the RHS.
Definition: block_builder_and_solver.hpp:152
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: block_builder_and_solver.hpp:79
ModelPart::NodesContainerType NodesContainerType
Definition: block_builder_and_solver.hpp:81
void ApplyDirichletConditions(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixType &rA, SystemVectorType &rDx, SystemVectorType &rb) override
applies the dirichlet conditions.
Definition: block_builder_and_solver.hpp:388
void SetUpSystem() override
organises the dofset in order to speed up the building phase
Definition: block_builder_and_solver.hpp:653
BaseType::SchemePointerType SchemePointerType
Definition: block_builder_and_solver.hpp:85
void FinalizeSolutionStep(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixPointerType &pA, SystemVectorPointerType &pDx, SystemVectorPointerType &pb) override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: block_builder_and_solver.hpp:761
SolutionBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: block_builder_and_solver.hpp:67
void AssembleRHS(SystemVectorType &rb, LocalSystemVectorType &rRHS_Contribution, Element::EquationIdVectorType &rEquationId)
Definition: block_builder_and_solver.hpp:1049
void SystemSolve(SystemMatrixType &rA, SystemVectorType &rDx, SystemVectorType &rb) override
This is a call to the linear system solver.
Definition: block_builder_and_solver.hpp:287
void Clear() override
This function is intended to be called at the end of the solution step to clean up memory storage not...
Definition: block_builder_and_solver.hpp:813
void BuildLHS(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixType &rA) override
Function to perform the building of the LHS,.
Definition: block_builder_and_solver.hpp:136
BaseType::SystemMatrixType SystemMatrixType
Definition: block_builder_and_solver.hpp:74
void Assemble(SystemMatrixType &rA, SystemVectorType &rb, const LocalSystemMatrixType &rLHS_Contribution, const LocalSystemVectorType &rRHS_Contribution, Element::EquationIdVectorType &rEquationId)
Definition: block_builder_and_solver.hpp:1068
BaseType::Pointer BasePointerType
Definition: block_builder_and_solver.hpp:69
void Build(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixType &rA, SystemVectorType &rb) override
Function to perform the building of the LHS and RHS.
Definition: block_builder_and_solver.hpp:181
KRATOS_CLASS_POINTER_DEFINITION(BlockBuilderAndSolver)
Pointer definition of BlockBuilderAndSolver.
void CalculateReactions(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixType &rA, SystemVectorType &rDx, SystemVectorType &rb) override
Calculates system reactions.
Definition: block_builder_and_solver.hpp:779
~BlockBuilderAndSolver() override
Destructor.
Definition: block_builder_and_solver.hpp:119
virtual int MyPID() const
Definition: communicator.cpp:91
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
const VariableData & GetVariable() const
Definition: dof.h:303
IndexType Id() const
Definition: dof.h:292
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
bool IsDefined(Flags const &rOther) const
Definition: flags.h:279
bool Is(Flags const &rOther) const
Definition: flags.h:274
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
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
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
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
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
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector_set.h:95
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
void Sort()
Sort the elements in the set.
Definition: pointer_vector_set.h:753
void push_back(TPointerType x)
Adds a pointer to the end of the set.
Definition: pointer_vector_set.h:544
iterator begin()
Returns an iterator pointing to the beginning of the container.
Definition: pointer_vector_set.h:278
void reserve(int reservedsize)
Reserves memory for a specified number of elements.
Definition: pointer_vector_set.h:733
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Solution Buider and Solver base class.
Definition: solution_builder_and_solver.hpp:63
unsigned int mEquationSystemSize
Definition: solution_builder_and_solver.hpp:479
virtual void Clear()
This function is intended to be called at the end of the solution step to clean up memory storage not...
Definition: solution_builder_and_solver.hpp:305
TSparseSpace::MatrixPointerType SystemMatrixPointerType
Definition: solution_builder_and_solver.hpp:78
TSparseSpace::VectorType SystemVectorType
Definition: solution_builder_and_solver.hpp:76
TDenseSpace::VectorType LocalSystemVectorType
Definition: solution_builder_and_solver.hpp:82
TSparseSpace::MatrixType SystemMatrixType
Definition: solution_builder_and_solver.hpp:75
virtual void FinalizeSolutionStep(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixPointerType &pA, SystemVectorPointerType &pDx, SystemVectorPointerType &pb)
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: solution_builder_and_solver.hpp:281
virtual void InitializeSolutionStep(SchemePointerType pScheme, ModelPart &rModelPart, SystemMatrixPointerType &pA, SystemVectorPointerType &pDx, SystemVectorPointerType &pb)
Performs all the required operations that should be done (for each step) before solving the solution ...
Definition: solution_builder_and_solver.hpp:269
DofsArrayType mDofSet
Definition: solution_builder_and_solver.hpp:473
TDenseSpace::MatrixType LocalSystemMatrixType
Definition: solution_builder_and_solver.hpp:81
TLinearSolver::Pointer LinearSolverPointerType
Definition: solution_builder_and_solver.hpp:87
TSparseSpace::VectorPointerType SystemVectorPointerType
Definition: solution_builder_and_solver.hpp:79
LinearSolverPointerType mpLinearSystemSolver
Definition: solution_builder_and_solver.hpp:470
int mEchoLevel
Definition: solution_builder_and_solver.hpp:482
SchemeType::Pointer SchemePointerType
Definition: solution_builder_and_solver.hpp:85
Solver local flags class definition.
Definition: solution_local_flags.hpp:48
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
void HashCombine(HashType &Seed, const TClassType &Value)
This method creates an "unique" hash for the input value.
Definition: key_hash.h:56
#define KRATOS_INFO(label)
Definition: logger.h:250
#define KRATOS_WARNING(label)
Definition: logger.h:265
start
Definition: DEM_benchmarks.py:17
int seed
Definition: GenerateWind.py:138
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
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
ProcessInfo
Definition: edgebased_PureConvection.py:116
v
Definition: generate_convection_diffusion_explicit_element.py:114
int local_size
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:17
tuple tmp
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:98
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17
Definition: block_builder_and_solver.hpp:100
size_t operator()(const Node::DofType::Pointer &it1, const Node::DofType::Pointer &it2) const
Definition: block_builder_and_solver.hpp:101
Definition: block_builder_and_solver.hpp:89
size_t operator()(const Node::DofType::Pointer &it) const
Definition: block_builder_and_solver.hpp:90