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.
trilinos_block_builder_and_solver.h
Go to the documentation of this file.
1 // KRATOS _____ _ _ _
2 // |_ _| __(_) (_)_ __ ___ ___
3 // | || '__| | | | '_ \ / _ \/ __|
4 // | || | | | | | | | | (_) \__
5 // |_||_| |_|_|_|_| |_|\___/|___/ APPLICATION
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 #pragma once
15 
16 // System includes
17 #include <unordered_set>
18 
19 // External includes
20 
21 /* Trilinos includes */
22 #include <Epetra_FECrsGraph.h>
23 #include <Epetra_IntVector.h>
24 
25 // Project includes
26 #include "trilinos_space.h"
29 #include "utilities/timer.h"
32 
33 #if !defined(START_TIMER)
34 #define START_TIMER(label, rank) \
35  if (mrComm.MyPID() == rank) \
36  Timer::Start(label);
37 #endif
38 #if !defined(STOP_TIMER)
39 #define STOP_TIMER(label, rank) \
40  if (mrComm.MyPID() == rank) \
41  Timer::Stop(label);
42 #endif
43 
44 namespace Kratos {
45 
48 
52 
56 
60 
64 
80 template <class TSparseSpace,
81  class TDenseSpace, //= DenseSpace<double>,
82  class TLinearSolver //= LinearSolver<TSparseSpace,TDenseSpace>
83  >
85  : public BuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver> {
86 public:
89 
91  KRATOS_DEFINE_LOCAL_FLAG( SILENT_WARNINGS );
92 
95 
98 
100  using SizeType = std::size_t;
101  using IndexType = std::size_t;
102 
106 
108  using EpetraCommunicatorType = Epetra_MpiComm;
109 
111  using NodeType = Node;
112 
116 
120 
124 
128 
132  explicit TrilinosBlockBuilderAndSolver() = default;
133 
138  int GuessRowSize,
139  typename TLinearSolver::Pointer pNewLinearSystemSolver)
140  : BaseType(pNewLinearSystemSolver),
141  mrComm(rComm),
142  mGuessRowSize(GuessRowSize)
143  {
144  }
145 
150  EpetraCommunicatorType& rComm,
151  typename TLinearSolver::Pointer pNewLinearSystemSolver,
152  Parameters ThisParameters
153  ) : BaseType(pNewLinearSystemSolver),
154  mrComm(rComm)
155  {
156  // Validate and assign defaults
157  ThisParameters = this->ValidateAndAssignParameters(ThisParameters, this->GetDefaultParameters());
158  this->AssignSettings(ThisParameters);
159  }
160 
165 
170 
171  // TODO: In order to create a Create method, the name of the DataCommunicator that is used needs to be passed in the settings (see DistributedImportModelPartUtility). Then an EpetraComm can be constructed from the MPI_Comm in the DataCommunicator
172 
176 
180 
189  void Build(typename TSchemeType::Pointer pScheme,
190  ModelPart& rModelPart,
191  TSystemMatrixType& rA,
192  TSystemVectorType& rb) override
193  {
194  KRATOS_TRY
195 
196  KRATOS_ERROR_IF(!pScheme) << "No scheme provided!" << std::endl;
197 
198  // Resetting to zero the vector of reactions
199  TSparseSpace::SetToZero(*BaseType::mpReactionsVector);
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
206  Element::EquationIdVectorType equation_ids_vector;
207  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
208 
209  BuiltinTimer build_timer;
210 
211  // Assemble all elements
212  for (auto it = rModelPart.Elements().ptr_begin(); it < rModelPart.Elements().ptr_end(); it++) {
213  // Detect if the element is active or not. If the user did not make any choice the element is active by default
214  if ((*it)->IsActive()) {
215  // Calculate elemental contribution
216  pScheme->CalculateSystemContributions(**it, LHS_Contribution, RHS_Contribution, equation_ids_vector, r_current_process_info);
217 
218  // Assemble the elemental contribution
219  TSparseSpace::AssembleLHS(rA, LHS_Contribution, equation_ids_vector);
220  TSparseSpace::AssembleRHS(rb, RHS_Contribution, equation_ids_vector);
221  }
222  }
223 
224  LHS_Contribution.resize(0, 0, false);
225  RHS_Contribution.resize(0, false);
226 
227  // Assemble all conditions
228  for (auto it = rModelPart.Conditions().ptr_begin(); it < rModelPart.Conditions().ptr_end(); it++) {
229  // Detect if the condition is active or not. If the user did not make any choice the condition is active by default
230  if ((*it)->IsActive()) {
231  // Calculate condition contribution
232  pScheme->CalculateSystemContributions(**it, LHS_Contribution, RHS_Contribution, equation_ids_vector, r_current_process_info);
233 
234  // Assemble the condition contribution
235  TSparseSpace::AssembleLHS(rA, LHS_Contribution, equation_ids_vector);
236  TSparseSpace::AssembleRHS(rb, RHS_Contribution, equation_ids_vector);
237  }
238  }
239 
240  // Finalizing the assembly
241  rA.GlobalAssemble();
242  rb.GlobalAssemble();
243 
244  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() >= 1) << "Build time: " << build_timer << std::endl;
245 
246  KRATOS_CATCH("")
247  }
248 
258  void BuildLHS(typename TSchemeType::Pointer pScheme,
259  ModelPart& rModelPart,
260  TSystemMatrixType& rA) override
261  {
262  KRATOS_TRY
263  // Resetting to zero the vector of reactions
264  TSparseSpace::SetToZero(*BaseType::mpReactionsVector);
265 
266  // Contributions to the system
267  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
268  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
269 
270  // Vector containing the localization in the system of the different terms
271  Element::EquationIdVectorType equation_ids_vector;
272  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
273 
274  BuiltinTimer build_timer;
275 
276  // Assemble all elements
277  for (auto it = rModelPart.Elements().ptr_begin(); it < rModelPart.Elements().ptr_end(); it++) {
278  pScheme->CalculateLHSContribution(**it, LHS_Contribution, equation_ids_vector, r_current_process_info);
279 
280  // Assemble the elemental contribution
281  TSparseSpace::AssembleLHS(rA, LHS_Contribution, equation_ids_vector);
282  }
283 
284  LHS_Contribution.resize(0, 0, false);
285 
286  // Assemble all conditions
287  for (auto it = rModelPart.Conditions().ptr_begin(); it < rModelPart.Conditions().ptr_end(); it++) {
288  // calculate elemental contribution
289  pScheme->CalculateLHSContribution(**it, LHS_Contribution, equation_ids_vector, r_current_process_info);
290 
291  // Assemble the elemental contribution
292  TSparseSpace::AssembleLHS(rA, LHS_Contribution, equation_ids_vector);
293  }
294 
295  // Finalizing the assembly
296  rA.GlobalAssemble();
297 
298  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() >= 1) << "Build time LHS: " << build_timer << std::endl;
299 
300  KRATOS_CATCH("")
301  }
302 
314  void BuildLHS_CompleteOnFreeRows(typename TSchemeType::Pointer pScheme,
315  ModelPart& rModelPart,
316  TSystemMatrixType& A) override
317  {
318  KRATOS_ERROR << "Method BuildLHS_CompleteOnFreeRows not implemented in "
319  "Trilinos Builder And Solver"
320  << std::endl;
321  }
322 
330  TSystemMatrixType& rA,
331  TSystemVectorType& rDx,
333  ) override
334  {
335  KRATOS_TRY
336  double norm_b;
337  if (TSparseSpace::Size(rb) != 0) {
338  norm_b = TSparseSpace::TwoNorm(rb);
339  } else {
340  norm_b = 0.0;
341  }
342 
343  if (norm_b != 0.0) {
344  // Do solve
345  BaseType::mpLinearSystemSolver->Solve(rA, rDx, rb);
346  } else {
347  TSparseSpace::SetToZero(rDx);
348  }
349 
350  // Reference to T
352 
353  // If there are master-slave constraints
354  if(TSparseSpace::Size1(r_T) != 0) {
355  // Recover solution of the original problem
356  TSystemVectorType Dxmodified(rDx);
357 
358  // Recover solution of the original problem
359  TSparseSpace::Mult(r_T, Dxmodified, rDx);
360  }
361 
362  // Prints information about the current time
363  KRATOS_INFO_IF("TrilinosResidualBasedBlockBuilderAndSolver", this->GetEchoLevel() > 1) << *(BaseType::mpLinearSystemSolver) << std::endl;
364 
365  KRATOS_CATCH("")
366  }
367 
376  TSystemVectorType& rDx,
377  TSystemVectorType& rb,
378  ModelPart& rModelPart
379  )
380  {
381  KRATOS_TRY
382 
383  // If considering MPC
384  if (rModelPart.GetCommunicator().GlobalNumberOfMasterSlaveConstraints() > 0) {
385  TSystemVectorType Dxmodified(rb);
386 
387  // Initialize the vector
388  TSparseSpace::SetToZero(Dxmodified);
389 
390  InternalSystemSolveWithPhysics(rA, Dxmodified, rb, rModelPart);
391 
392  // Reference to T
394 
395  // Recover solution of the original problem
396  TSparseSpace::Mult(r_T, Dxmodified, rDx);
397  } else {
398  InternalSystemSolveWithPhysics(rA, rDx, rb, rModelPart);
399  }
400 
401  KRATOS_CATCH("")
402  }
403 
412  TSystemVectorType& rDx,
413  TSystemVectorType& rb,
414  ModelPart& rModelPart)
415  {
416  KRATOS_TRY
417 
418  double norm_b;
419  if (TSparseSpace::Size(rb) != 0)
420  norm_b = TSparseSpace::TwoNorm(rb);
421  else
422  norm_b = 0.00;
423 
424  if (norm_b != 0.00) {
425  if (BaseType::mpLinearSystemSolver->AdditionalPhysicalDataIsNeeded()) {
426  BaseType::mpLinearSystemSolver->ProvideAdditionalData(rA, rDx, rb, BaseType::mDofSet, rModelPart);
427  }
428 
429  BaseType::mpLinearSystemSolver->Solve(rA, rDx, rb);
430  } else {
431  TSparseSpace::SetToZero(rDx);
432  KRATOS_WARNING("TrilinosResidualBasedBlockBuilderAndSolver") << "ATTENTION! setting the RHS to zero!" << std::endl;
433  }
434 
435  // Prints informations about the current time
436  KRATOS_INFO_IF("TrilinosResidualBasedBlockBuilderAndSolver", (BaseType::GetEchoLevel() > 1)) << *(BaseType::mpLinearSystemSolver) << std::endl;
437 
438  KRATOS_CATCH("")
439  }
440 
451  void BuildAndSolve(typename TSchemeType::Pointer pScheme,
452  ModelPart& rModelPart,
453  TSystemMatrixType& rA,
454  TSystemVectorType& rDx,
455  TSystemVectorType& rb) override
456  {
457  KRATOS_TRY
458 
459  START_TIMER("Build", 0)
460 
461  Build(pScheme, rModelPart, rA, rb);
462 
463  STOP_TIMER("Build", 0)
464 
466  const auto timer_constraints = BuiltinTimer();
467  START_TIMER("ApplyConstraints", 0)
468  ApplyConstraints(pScheme, rModelPart, rA, rb);
469  STOP_TIMER("ApplyConstraints", 0)
470  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() >=1) << "Constraints build time: " << timer_constraints << std::endl;
471  }
472 
473  // Apply dirichlet conditions
474  ApplyDirichletConditions(pScheme, rModelPart, rA, rDx, rb);
475 
476  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() == 3)
477  << "\nBefore the solution of the system"
478  << "\nSystem Matrix = " << rA << "\nunknowns vector = " << rDx
479  << "\nRHS vector = " << rb << std::endl;
480 
481  START_TIMER("Solve", 0)
482 
483  const auto solve_timer = BuiltinTimer();
484 
485  SystemSolveWithPhysics(rA, rDx, rb, rModelPart);
486 
487  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() >=1) << "System solve time: " << solve_timer << std::endl;
488 
489  STOP_TIMER("Solve", 0)
490 
491  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() == 3)
492  << "\nAfter the solution of the system"
493  << "\nSystem Matrix = " << rA << "\nUnknowns vector = " << rDx
494  << "\nRHS vector = " << rb << std::endl;
495  KRATOS_CATCH("")
496  }
497 
507  void BuildRHSAndSolve(typename TSchemeType::Pointer pScheme,
508  ModelPart& rModelPart,
509  TSystemMatrixType& rA,
510  TSystemVectorType& rDx,
511  TSystemVectorType& rb) override
512  {
513  KRATOS_TRY
514 
515  BuildRHS(pScheme, rModelPart, rb);
516 
518  START_TIMER("ApplyRHSConstraints", 0)
519  ApplyRHSConstraints(pScheme, rModelPart, rb);
520  STOP_TIMER("ApplyRHSConstraints", 0)
521  }
522 
523  const auto solve_timer = BuiltinTimer();
524  START_TIMER("Solve", 0)
525 
526  SystemSolveWithPhysics(rA, rDx, rb, rModelPart);
527 
528  STOP_TIMER("Solve", 0)
529 
530  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() >=1) << "System solve time: " << solve_timer << std::endl;
531 
532  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", ( this->GetEchoLevel() == 3)) << "After the solution of the system" << "\nSystem Matrix = " << rA << "\nUnknowns vector = " << rDx << "\nRHS vector = " << rb << std::endl;
533 
534  KRATOS_CATCH("")
535  }
536 
544  void BuildRHS(typename TSchemeType::Pointer pScheme,
545  ModelPart& rModelPart,
546  TSystemVectorType& rb) override
547  {
548  KRATOS_TRY
549 
550  START_TIMER("BuildRHS ", 0)
551  // Resetting to zero the vector of reactions
552  TSparseSpace::SetToZero(*BaseType::mpReactionsVector);
553 
554  // Contributions to the system
555  LocalSystemMatrixType LHS_Contribution = LocalSystemMatrixType(0, 0);
556  LocalSystemVectorType RHS_Contribution = LocalSystemVectorType(0);
557 
558  // Vector containing the localization in the system of the different terms
559  Element::EquationIdVectorType equation_ids_vector;
560  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
561 
562  // Assemble all elements
563  for (auto it = rModelPart.Elements().ptr_begin(); it < rModelPart.Elements().ptr_end(); it++) {
564  // Calculate elemental Right Hand Side Contribution
565  pScheme->CalculateRHSContribution(**it, RHS_Contribution, equation_ids_vector, r_current_process_info);
566 
567  // Assemble the elemental contribution
568  TSparseSpace::AssembleRHS(rb, RHS_Contribution, equation_ids_vector);
569  }
570 
571  RHS_Contribution.resize(0, false);
572 
573  // Assemble all conditions
574  for (auto it = rModelPart.Conditions().ptr_begin(); it < rModelPart.Conditions().ptr_end(); it++) {
575  // calculate elemental contribution
576  pScheme->CalculateRHSContribution(**it, RHS_Contribution, equation_ids_vector, r_current_process_info);
577 
578  // Assemble the elemental contribution
579  TSparseSpace::AssembleRHS(rb, RHS_Contribution, equation_ids_vector);
580  }
581 
582  // Finalizing the assembly
583  rb.GlobalAssemble();
584 
585  STOP_TIMER("BuildRHS ", 0)
586 
587  KRATOS_CATCH("")
588  }
589 
599  typename TSchemeType::Pointer pScheme,
600  ModelPart& rModelPart
601  ) override
602  {
603  KRATOS_TRY
604 
605  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() > 2) << "Setting up the dofs" << std::endl;
606 
607  using DofsVectorType = Element::DofsVectorType;
608 
609  // Gets the array of elements from the modeler
610  DofsVectorType dof_list, second_dof_list;
611  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
612 
613  DofsArrayType temp_dofs_array;
614  IndexType guess_num_dofs = rModelPart.GetCommunicator().LocalMesh().NumberOfNodes() * 3;
615  temp_dofs_array.reserve(guess_num_dofs);
617 
618  // Taking dofs of elements
619  auto& r_elements_array = rModelPart.GetCommunicator().LocalMesh().Elements();
620  for (auto& r_elem : r_elements_array) {
621  pScheme->GetDofList(r_elem, dof_list, r_current_process_info);
622  for (auto i_dof = dof_list.begin(); i_dof != dof_list.end(); ++i_dof)
623  temp_dofs_array.push_back(*i_dof);
624  }
625 
626  // Taking dofs of conditions
627  auto& r_conditions_array = rModelPart.GetCommunicator().LocalMesh().Conditions();
628  for (auto& r_cond : r_conditions_array) {
629  pScheme->GetDofList(r_cond, dof_list, r_current_process_info);
630  for (auto i_dof = dof_list.begin(); i_dof != dof_list.end(); ++i_dof)
631  temp_dofs_array.push_back(*i_dof);
632  }
633 
634  // Taking dofs of constraints
635  auto& r_constraints_array = rModelPart.GetCommunicator().LocalMesh().MasterSlaveConstraints();
636  for (auto& r_const : r_constraints_array) {
637  r_const.GetDofList(dof_list, second_dof_list, r_current_process_info);
638  for (auto i_dof = dof_list.begin(); i_dof != dof_list.end(); ++i_dof)
639  temp_dofs_array.push_back(*i_dof);
640  for (auto i_dof = second_dof_list.begin(); i_dof != second_dof_list.end(); ++i_dof)
641  temp_dofs_array.push_back(*i_dof);
642  }
643 
644  temp_dofs_array.Unique();
645  BaseType::mDofSet = temp_dofs_array;
646 
647  // Throws an exception if there are no Degrees of freedom involved in
648  // the analysis
649  const SizeType number_of_dofs = rModelPart.GetCommunicator().GetDataCommunicator().SumAll(BaseType::mDofSet.size());
650  KRATOS_ERROR_IF(number_of_dofs == 0) << "No degrees of freedom!" << std::endl;
651 
652 #ifdef KRATOS_DEBUG
653  // If reactions are to be calculated, we check if all the dofs have
654  // reactions defined This is to be done only in debug mode
656  for (auto dof_iterator = BaseType::mDofSet.begin();
657  dof_iterator != BaseType::mDofSet.end(); ++dof_iterator) {
658  KRATOS_ERROR_IF_NOT(dof_iterator->HasReaction())
659  << "Reaction variable not set for the following : " << std::endl
660  << "Node : " << dof_iterator->Id() << std::endl
661  << "Dof : " << (*dof_iterator) << std::endl
662  << "Not possible to calculate reactions." << std::endl;
663  }
664  }
665 #endif
666  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() > 2) << "Number of degrees of freedom:" << number_of_dofs << std::endl;
667 
669 
670  KRATOS_INFO_IF("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() > 2) << "Finished setting up the dofs" << std::endl;
671 
672  KRATOS_CATCH("")
673  }
674 
680  void SetUpSystem(ModelPart& rModelPart) override
681  {
682  int free_size = 0;
683  auto& r_comm = rModelPart.GetCommunicator();
684  const auto& r_data_comm = r_comm.GetDataCommunicator();
685  const int current_rank = r_data_comm.Rank();
686  const int world_size = r_data_comm.Size();
687 
688  // Calculating number of fixed and free dofs
689  for (const auto& r_dof : BaseType::mDofSet) {
690  if (r_dof.GetSolutionStepValue(PARTITION_INDEX) == current_rank) {
691  free_size++;
692  }
693  }
694 
695  // Calculating the total size and required offset
696  int free_offset;
697  int global_size;
698 
699  // The corresponding offset by the sum of the sizes in thread with
700  // inferior current_rank
701  free_offset = r_data_comm.ScanSum(free_size);
702 
703  // The total size by the sum of all size in all threads
704  global_size = r_data_comm.SumAll(free_size);
705 
706  // Finding the offset for the beginning of the partition
707  free_offset -= free_size;
708 
709  // Now setting the equation id with .
710  for (auto& r_dof : BaseType::mDofSet) {
711  if (r_dof.GetSolutionStepValue(PARTITION_INDEX) == current_rank) {
712  r_dof.SetEquationId(free_offset++);
713  }
714  }
715 
716  BaseType::mEquationSystemSize = global_size;
717  mLocalSystemSize = free_size;
718  KRATOS_INFO_IF_ALL_RANKS("TrilinosBlockBuilderAndSolver", BaseType::GetEchoLevel() > 1)
719  << "\n BaseType::mEquationSystemSize = " << BaseType::mEquationSystemSize
720  << "\n mLocalSystemSize = " << mLocalSystemSize
721  << "\n free_offset = " << free_offset << std::endl;
722 
723  // by Riccardo ... it may be wrong!
724  mFirstMyId = free_offset - mLocalSystemSize;
725 
726  // For MPC we fill mFirstMyIds
727  if (r_comm.GlobalNumberOfMasterSlaveConstraints() > 0) {
728  mFirstMyIds.resize(world_size);
729  std::vector<int> send_first_ids(1, mFirstMyId);
730  r_data_comm.AllGather(send_first_ids, mFirstMyIds);
731  }
732 
733  // Synchronize DoFs
734  r_comm.SynchronizeDofs();
735  }
736 
748  typename TSchemeType::Pointer pScheme,
752  ModelPart& rModelPart
753  ) override
754  {
755  KRATOS_TRY
756 
757  // Resizing the system vectors and matrix
758  if (rpA == nullptr || TSparseSpace::Size1(*rpA) == 0 || BaseType::GetReshapeMatrixFlag()) { // If the matrix is not initialized
759  ConstructMatrixStructure(pScheme, rpA, rpDx, rpb, rModelPart);
760  } else if (BaseType::mpReactionsVector == nullptr && this->mCalculateReactionsFlag) {
761  TSystemVectorPointerType pNewReactionsVector = TSystemVectorPointerType(new TSystemVectorType(rpDx->Map()));
762  BaseType::mpReactionsVector.swap(pNewReactionsVector);
763  } else {
764  if (TSparseSpace::Size1(*rpA) == 0 ||
767  KRATOS_ERROR << "It should not come here resizing is not allowed this way!!!!!!!! ... " << std::endl;
768  }
769  }
770 
772 
773  KRATOS_CATCH("")
774  }
775 
785  typename TSchemeType::Pointer pScheme,
786  ModelPart& rModelPart,
787  TSystemMatrixType& rA,
788  TSystemVectorType& rDx,
790  ) override
791  {
792  TSparseSpace::SetToZero(rb);
793 
794  // Refresh RHS to have the correct reactions
795  BuildRHS(pScheme, rModelPart, rb);
796 
797  // Initialize the Epetra importer
798  // TODO: this part of the code has been pasted until a better solution
799  // is found
800  int system_size = TSparseSpace::Size(rb);
801  int number_of_dofs = BaseType::mDofSet.size();
802  std::vector<int> index_array(number_of_dofs);
803 
804  // Filling the array with the global ids
805  int counter = 0;
806  int id = 0;
807  for (const auto& dof : BaseType::mDofSet) {
808  id = dof.EquationId();
809  if (id < system_size) {
810  index_array[counter++] = id;
811  }
812  }
813 
814  std::sort(index_array.begin(), index_array.end());
815  std::vector<int>::iterator NewEnd = std::unique(index_array.begin(), index_array.end());
816  index_array.resize(NewEnd - index_array.begin());
817 
818  int check_size = -1;
819  int tot_update_dofs = index_array.size();
820  rb.Comm().SumAll(&tot_update_dofs, &check_size, 1);
821  KRATOS_ERROR_IF(check_size < system_size)
822  << "Dof count is not correct. There are less dofs than expected.\n"
823  << "Expected number of active dofs = " << system_size
824  << " dofs found = " << check_size << std::endl;
825 
826  // Defining a map as needed
827  Epetra_Map dof_update_map(-1, index_array.size(),
828  &(*(index_array.begin())), 0, rb.Comm());
829 
830  // Defining the importer class
831  Kratos::shared_ptr<Epetra_Import> pDofImporter = Kratos::make_shared<Epetra_Import>(dof_update_map, rb.Map());
832 
833  // Defining a temporary vector to gather all of the values needed
834  Epetra_Vector temp_RHS(pDofImporter->TargetMap());
835 
836  // Importing in the new temp_RHS vector the values
837  int ierr = temp_RHS.Import(rb, *pDofImporter, Insert);
838  KRATOS_ERROR_IF(ierr != 0) << "Epetra failure found - error code: " << ierr << std::endl;
839 
840  double* temp_RHS_values; // DO NOT make delete of this one!!
841  temp_RHS.ExtractView(&temp_RHS_values);
842 
843  rb.Comm().Barrier();
844 
845  const int ndofs = static_cast<int>(BaseType::mDofSet.size());
846 
847  // Store the RHS values in the reaction variable
848  // NOTE: dofs are assumed to be numbered consecutively in the
849  // BlockBuilderAndSolver
850  for (int k = 0; k < ndofs; k++) {
851  auto dof_iterator = BaseType::mDofSet.begin() + k;
852 
853  const int i = (dof_iterator)->EquationId();
854  // (dof_iterator)->GetSolutionStepReactionValue() = -(*b[i]);
855  const double react_val = temp_RHS[pDofImporter->TargetMap().LID(i)];
856  (dof_iterator->GetSolutionStepReactionValue()) = -react_val;
857  }
858  }
859 
873  typename TSchemeType::Pointer pScheme,
874  ModelPart& rModelPart,
875  TSystemMatrixType& rA,
876  TSystemVectorType& rDx,
878  ) override
879  {
880  KRATOS_TRY
881 
882  // loop over all dofs to find the fixed ones
883  std::vector<int> global_ids(BaseType::mDofSet.size());
884  std::vector<int> is_dirichlet(BaseType::mDofSet.size());
885 
886  IndexType i = 0;
887  for (const auto& dof : BaseType::mDofSet) {
888  const int global_id = dof.EquationId();
889  global_ids[i] = global_id;
890  is_dirichlet[i] = dof.IsFixed();
891  ++i;
892  }
893 
894  // here we construct and fill a vector "fixed local" which cont
895  Epetra_Map localmap(-1, global_ids.size(), global_ids.data(), 0, rA.Comm());
896  Epetra_IntVector fixed_local(Copy, localmap, is_dirichlet.data());
897 
898  Epetra_Import dirichlet_importer(rA.ColMap(), fixed_local.Map());
899 
900  // defining a temporary vector to gather all of the values needed
901  Epetra_IntVector fixed(rA.ColMap());
902 
903  // Detect if there is a line of all zeros and set the diagonal to a certain number (1 if not scale, some norms values otherwise) if this happens
904  const auto& r_process_info = rModelPart.GetProcessInfo();
905  mScaleFactor = TSparseSpace::CheckAndCorrectZeroDiagonalValues(r_process_info, rA, rb, mScalingDiagonal);
906 
907  // Importing in the new temp vector the values
908  int ierr = fixed.Import(fixed_local, dirichlet_importer, Insert);
909  KRATOS_ERROR_IF(ierr != 0) << "Epetra failure found" << std::endl;
910 
911  for (int i = 0; i < rA.NumMyRows(); i++) {
912  int numEntries; // Number of non-zero entries
913  double* vals; // Row non-zero values
914  int* cols; // Column indices of row non-zero values
915  rA.ExtractMyRowView(i, numEntries, vals, cols);
916 
917  const int row_gid = rA.RowMap().GID(i);
918  const int row_lid = localmap.LID(row_gid);
919 
920  if (fixed_local[row_lid] == 0) { // Not a dirichlet row
921  for (int j = 0; j < numEntries; j++) {
922  if (fixed[cols[j]] == true)
923  vals[j] = 0.0;
924  }
925  } else { // This IS a dirichlet row
926  // Set to zero the rhs
927  rb[0][i] = 0.0; // note that the index of i is expected to be
928  // coherent with the rows of A
929 
930  // Set to zero the whole row
931  for (int j = 0; j < numEntries; j++) {
932  int col_gid = rA.ColMap().GID(cols[j]);
933  if (col_gid != row_gid)
934  vals[j] = 0.0;
935  }
936  }
937  }
938 
939  KRATOS_CATCH("");
940  }
941 
949  typename TSchemeType::Pointer pScheme,
950  ModelPart& rModelPart,
952  ) override
953  {
954  KRATOS_TRY
955 
956  if (rModelPart.GetCommunicator().GlobalNumberOfMasterSlaveConstraints() > 0) {
957  BuildMasterSlaveConstraints(rModelPart);
958 
959  // Reference to T
961 
962  // Compute T' b
963  const TSystemVectorType copy_b(rb);
964  TSparseSpace::TransposeMult(r_T, copy_b, rb);
965 
966  // Apply diagonal values on slaves
967  IndexPartition<std::size_t>(mSlaveIds.size()).for_each([&](std::size_t Index){
968  const IndexType slave_equation_id = mSlaveIds[Index];
969  if (mInactiveSlaveDofs.find(slave_equation_id) == mInactiveSlaveDofs.end()) {
970  TrilinosAssemblingUtilities::SetGlobalValueWithoutGlobalAssembly(rb, slave_equation_id, 0.0);
971  }
972  });
973 
974  // Global assembly
975  rb.GlobalAssemble();
976  }
977 
978  KRATOS_CATCH("")
979  }
980 
989  typename TSchemeType::Pointer pScheme,
990  ModelPart& rModelPart,
991  TSystemMatrixType& rA,
993  ) override
994  {
995  KRATOS_TRY
996 
997  if (rModelPart.GetCommunicator().GlobalNumberOfMasterSlaveConstraints() > 0) {
998  BuildMasterSlaveConstraints(rModelPart);
999 
1000  // Reference to T
1002 
1003  // Compute T' A T
1004  const TSystemMatrixType copy_A(rA);
1005  TSparseSpace::BtDBProductOperation(rA, copy_A, r_T, true, false, true);
1006 
1007  // Compute T' b
1008  const TSystemVectorType copy_b(rb);
1009  TSparseSpace::TransposeMult(r_T, copy_b, rb);
1010 
1011  // Compute the scale factor value
1012  const auto& r_process_info = rModelPart.GetProcessInfo();
1013  mScaleFactor = TSparseSpace::GetScaleNorm(r_process_info, rA, mScalingDiagonal);
1014 
1015  // Apply diagonal values on slaves
1016  IndexPartition<std::size_t>(mSlaveIds.size()).for_each([&](std::size_t Index){
1017  const IndexType slave_equation_id = mSlaveIds[Index];
1018  if (mInactiveSlaveDofs.find(slave_equation_id) == mInactiveSlaveDofs.end()) {
1019  TrilinosAssemblingUtilities::SetGlobalValueWithoutGlobalAssembly(rA, slave_equation_id, slave_equation_id, mScaleFactor);
1020  TrilinosAssemblingUtilities::SetGlobalValueWithoutGlobalAssembly(rb, slave_equation_id, 0.0);
1021  }
1022  });
1023 
1024  // Global assembly
1025  rb.GlobalAssemble();
1026  rA.GlobalAssemble();
1027  }
1028 
1029  KRATOS_CATCH("")
1030  }
1031 
1035  void Clear() override
1036  {
1037  BaseType::Clear();
1038 
1039  mSlaveIds.clear();
1040  mMasterIds.clear();
1041  mInactiveSlaveDofs.clear();
1042  TSparseSpace::Clear(mpT);
1043  TSparseSpace::Clear(mpConstantVector);
1044  }
1045 
1053  int Check(ModelPart& rModelPart) override
1054  {
1055  KRATOS_TRY
1056 
1057  return 0;
1058  KRATOS_CATCH("");
1059  }
1060 
1066  {
1067  Parameters default_parameters = Parameters(R"(
1068  {
1069  "name" : "trilinos_block_builder_and_solver",
1070  "guess_row_size" : 45,
1071  "block_builder" : true,
1072  "diagonal_values_for_dirichlet_dofs" : "use_max_diagonal",
1073  "silent_warnings" : false
1074  })");
1075 
1076  // Getting base class default parameters
1077  const Parameters base_default_parameters = BaseType::GetDefaultParameters();
1078  default_parameters.RecursivelyAddMissingParameters(base_default_parameters);
1079  return default_parameters;
1080  }
1081 
1086  static std::string Name()
1087  {
1088  return "trilinos_block_builder_and_solver";
1089  }
1090 
1094 
1100  {
1101  auto& r_T = *mpT;
1102  return r_T;
1103  }
1104 
1110  {
1111  auto& r_constant_vector = *mpConstantVector;
1112  return r_constant_vector;
1113  }
1114 
1121  {
1122  return mScaleFactor;
1123  }
1124 
1130  void SetScaleFactor(const double ScaleFactor)
1131  {
1133  }
1134 
1138 
1142 
1144  std::string Info() const override
1145  {
1146  return "TrilinosBlockBuilderAndSolver";
1147  }
1148 
1150  void PrintInfo(std::ostream& rOStream) const override
1151  {
1152  rOStream << Info();
1153  }
1154 
1156  void PrintData(std::ostream& rOStream) const override
1157  {
1158  rOStream << Info();
1159  }
1160 
1164 
1166 protected:
1169 
1173 
1174  /* Base variables */
1181  std::vector<int> mFirstMyIds;
1182 
1183  /* MPC variables */
1186  std::vector<IndexType> mSlaveIds;
1187  std::vector<IndexType> mMasterIds;
1188  std::unordered_set<IndexType> mInactiveSlaveDofs;
1189  double mScaleFactor = 1.0;
1190 
1191  /* Flags */
1194 
1198 
1202 
1209  {
1210  if (rModelPart.GetCommunicator().GlobalNumberOfMasterSlaveConstraints() > 0) {
1211  START_TIMER("ConstraintsRelationMatrixStructure", 0)
1212  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
1213 
1214  // Generate indices database
1215  const IndexType number_of_local_rows = mLocalSystemSize;
1216 
1217  // Generate map - use the "temp" array here
1218  const int temp_size = (number_of_local_rows < 1000) ? 1000 : number_of_local_rows;
1219  std::vector<int> temp_primary(temp_size, 0);
1220  std::vector<int> temp_secondary(temp_size, 0);
1221  for (IndexType i = 0; i != number_of_local_rows; i++) {
1222  temp_primary[i] = mFirstMyId + i;
1223  }
1224  Epetra_Map& r_map = GetEpetraMap();
1225  std::fill(temp_primary.begin(), temp_primary.begin() + number_of_local_rows, 0);
1226 
1227  // The T graph
1228  Epetra_FECrsGraph Tgraph(Copy, r_map, mGuessRowSize);
1229 
1230  // Adding diagonal values
1231  int ierr;
1232  int index_diagonal[1] = {0};
1233  for (IndexType i = 0; i < number_of_local_rows; ++i) {
1234  index_diagonal[0] = mFirstMyId + i;
1235  ierr = Tgraph.InsertGlobalIndices(1, index_diagonal, 1, index_diagonal);
1236  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Graph.InsertGlobalIndices. Error code: " << ierr << std::endl;
1237  }
1238 
1239  // Vector containing indices belonging to slave DoFs, not used for graph, but for master/slave index identification
1240  std::unordered_set<std::size_t> indices;
1241 
1242  // TODO: Check if these should be local constraints
1243  auto& r_constraints_array = rModelPart.MasterSlaveConstraints();
1244 
1245  // Assemble all constraints
1246  Element::EquationIdVectorType slave_equation_ids_vector, master_equation_ids_vector;
1247  for (auto& r_const : r_constraints_array) {
1248  r_const.EquationIdVector(slave_equation_ids_vector, master_equation_ids_vector, r_current_process_info);
1249 
1250  // Filling the list of active global indices (non fixed)
1251  IndexType num_active_slave_indices = 0;
1252  for (auto& r_slave_id : slave_equation_ids_vector) {
1253  temp_primary[num_active_slave_indices] = r_slave_id;
1254  ++num_active_slave_indices;
1255  }
1256  IndexType num_active_master_indices = 0;
1257  for (auto& r_master_id : master_equation_ids_vector) {
1258  temp_secondary[num_active_master_indices] = r_master_id;
1259  ++num_active_master_indices;
1260  }
1261 
1262  // Adding cross master-slave dofs
1263  if (num_active_slave_indices > 0 && num_active_master_indices > 0) {
1264  int slave_index[1] = {0};
1265  for (IndexType i = 0; i < num_active_slave_indices; ++i) {
1266  slave_index[0] = temp_primary[i];
1267  indices.insert(temp_primary[i]);
1268  ierr = Tgraph.InsertGlobalIndices(1, slave_index, num_active_master_indices, temp_secondary.data());
1269  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Graph.InsertGlobalIndices. Error code: " << ierr << std::endl;
1270  }
1271  }
1272  std::fill(temp_primary.begin(), temp_primary.begin() + num_active_slave_indices, 0);
1273  std::fill(temp_secondary.begin(), temp_secondary.begin() + num_active_master_indices, 0);
1274  }
1275 
1276  // Finalizing graph construction
1277  ierr = Tgraph.GlobalAssemble();
1278  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Epetra_FECrsGraph.GlobalAssemble. Error code: " << ierr << std::endl;
1279  ierr = Tgraph.FillComplete();
1280  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Epetra_FECrsGraph.FillComplete. Error code: " << ierr << std::endl;
1281  ierr = Tgraph.OptimizeStorage();
1282  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Epetra_FECrsGraph.OptimizeStorage. Error code: " << ierr << std::endl;
1283 
1284  // Generate a new matrix pointer according to this non-zero values
1286 
1287  // Swap matrix
1288  mpT.swap(p_new_T);
1289 
1290  // Generate the constant vector equivalent
1291  TSystemVectorPointerType p_new_constant_vector = TSystemVectorPointerType(new TSystemVectorType(r_map));
1292  mpConstantVector.swap(p_new_constant_vector);
1293 
1294  /* Fill ids for master/slave */
1295 
1296  // First clear the ones considered
1297  mSlaveIds.clear();
1298  mMasterIds.clear();
1299 
1300  // Now prepare the auxiliary ones
1301  auto& r_comm = rModelPart.GetCommunicator();
1302  const auto& r_data_comm = r_comm.GetDataCommunicator();
1303  const int current_rank = r_data_comm.Rank();
1304  const int world_size = r_data_comm.Size();
1305 
1306  // Auxiliary slave ids
1307  std::vector<std::unordered_set<IndexType>> auxiliary_slave_ids(world_size);
1308  for (auto index : indices) {
1309  const IndexType rank = DeterminePartitionIndex(index);
1310  auxiliary_slave_ids[rank].insert(index);
1311  }
1312  const int tag_sync_slave_id = 0;
1313  for (int i_rank = 0; i_rank < world_size; ++i_rank) {
1314  if (i_rank != current_rank) {
1315  std::vector<IndexType> receive_slave_ids_vector;
1316  r_data_comm.Recv(receive_slave_ids_vector, i_rank, tag_sync_slave_id);
1317  auxiliary_slave_ids[i_rank].insert(receive_slave_ids_vector.begin(), receive_slave_ids_vector.end());
1318  } else {
1319  for (int j_rank = 0; j_rank < world_size; ++j_rank) {
1320  if (j_rank != current_rank) {
1321  const auto& r_slave_ids = auxiliary_slave_ids[j_rank];
1322  std::vector<IndexType> send_slave_ids_vector(r_slave_ids.begin(), r_slave_ids.end());
1323  r_data_comm.Send(send_slave_ids_vector, j_rank, tag_sync_slave_id);
1324  }
1325  }
1326  }
1327  }
1328  mSlaveIds = std::vector<IndexType>(auxiliary_slave_ids[current_rank].begin(), auxiliary_slave_ids[current_rank].end());
1329 
1330  // Master DoFs are complementary
1331  std::unordered_set<IndexType> temp_master_ids;
1332  for (IndexType i = 0; i < number_of_local_rows; ++i) {
1333  temp_master_ids.insert(mFirstMyId + i);
1334  }
1335 
1336  // Remove ids
1337  for (auto id_slave_vector : auxiliary_slave_ids) {
1338  for (auto id_slave : id_slave_vector) {
1339  temp_master_ids.erase(id_slave);
1340  }
1341  }
1342  mMasterIds = std::vector<IndexType>(temp_master_ids.begin(), temp_master_ids.end());
1343 
1344  STOP_TIMER("ConstraintsRelationMatrixStructure", 0)
1345  }
1346  }
1347 
1352  virtual void BuildMasterSlaveConstraints(ModelPart& rModelPart)
1353  {
1354  KRATOS_TRY
1355 
1356  // Reference of the matrix and vector
1357  auto& r_T = GetConstraintRelationMatrix();
1358  auto& r_constant_vector = GetConstraintConstantVector();
1359 
1360  TSparseSpace::SetToZero(r_T);
1361  TSparseSpace::SetToZero(r_constant_vector);
1362 
1363  // The current process info
1364  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
1365 
1366  // Contributions to the system
1367  Matrix transformation_matrix = LocalSystemMatrixType(0, 0);
1368  Vector constant_vector = LocalSystemVectorType(0);
1369 
1370  // Vector containing the localization in the system of the different terms
1371  Element::EquationIdVectorType slave_equation_ids, master_equation_ids;
1372 
1373  // Now prepare the auxiliary ones
1374  auto& r_comm = rModelPart.GetCommunicator();
1375  const auto& r_data_comm = r_comm.GetDataCommunicator();
1376  const int current_rank = r_data_comm.Rank();
1377  const int world_size = r_data_comm.Size();
1378 
1379  // Auxiliary inactive slave ids
1380  std::vector<std::unordered_set<IndexType>> auxiliary_inactive_slave_ids(world_size);
1381 
1382  // We clear the set
1383  mInactiveSlaveDofs.clear();
1384  std::size_t num_inactive_slave_dofs_other_partitions = 0;
1385 
1386  // Iterate over the constraints
1387  for (auto& r_const : rModelPart.MasterSlaveConstraints()) {
1388  r_const.EquationIdVector(slave_equation_ids, master_equation_ids, r_current_process_info);
1389  // Detect if the constraint is active or not. If the user did not make any choice the constraint. It is active by default
1390  if (r_const.IsActive()) {
1391  r_const.CalculateLocalSystem(transformation_matrix, constant_vector, r_current_process_info);
1392 
1393  TrilinosAssemblingUtilities::AssembleRelationMatrixT(r_T, transformation_matrix, slave_equation_ids, master_equation_ids);
1394  TrilinosAssemblingUtilities::AssembleConstantVector(r_constant_vector, constant_vector, slave_equation_ids);
1395  } else { // Taking into account inactive constraints
1396  // Save the auxiliary ids of the the slave inactive DoFs
1397  for (auto slave_id : slave_equation_ids) {
1398  const int index_rank = DeterminePartitionIndex(slave_id);
1399  if (index_rank == current_rank) {
1400  mInactiveSlaveDofs.insert(slave_id);
1401  } else {
1402  auxiliary_inactive_slave_ids[index_rank].insert(slave_id);
1403  ++num_inactive_slave_dofs_other_partitions;
1404  }
1405  }
1406  }
1407  }
1408 
1409  // Compute total number of inactive slave dofs in other partitions
1410  num_inactive_slave_dofs_other_partitions = r_data_comm.SumAll(num_inactive_slave_dofs_other_partitions);
1411 
1412  // Now we pass the info between partitions
1413  if (num_inactive_slave_dofs_other_partitions > 0) {
1414  const int tag_sync_inactive_slave_id = 0;
1415  for (int i_rank = 0; i_rank < world_size; ++i_rank) {
1416  if (i_rank != current_rank) {
1417  std::vector<IndexType> receive_inactive_slave_ids_vector;
1418  r_data_comm.Recv(receive_inactive_slave_ids_vector, i_rank, tag_sync_inactive_slave_id);
1419  mInactiveSlaveDofs.insert(receive_inactive_slave_ids_vector.begin(), receive_inactive_slave_ids_vector.end());
1420  } else {
1421  for (int j_rank = 0; j_rank < world_size; ++j_rank) {
1422  if (j_rank != current_rank) {
1423  const auto& r_inactive_slave_ids = auxiliary_inactive_slave_ids[j_rank];
1424  std::vector<IndexType> send_inactive_slave_ids_vector(r_inactive_slave_ids.begin(), r_inactive_slave_ids.end());
1425  r_data_comm.Send(send_inactive_slave_ids_vector, j_rank, tag_sync_inactive_slave_id);
1426  }
1427  }
1428  }
1429  }
1430  }
1431 
1432  // Setting the master dofs into the T and C system
1433  for (auto eq_id : mMasterIds) {
1436  }
1437 
1438  // Setting inactive slave dofs in the T and C system
1439  for (auto eq_id : mInactiveSlaveDofs) {
1442  }
1443 
1444  // Finalizing the assembly
1445  r_T.GlobalAssemble();
1446  r_constant_vector.GlobalAssemble();
1447 
1448  KRATOS_CATCH("")
1449  }
1450 
1461  typename TSchemeType::Pointer pScheme,
1465  ModelPart& rModelPart
1466  )
1467  {
1468  // Filling with zero the matrix (creating the structure)
1469  START_TIMER("MatrixStructure", 0)
1470 
1471  // TODO: Check if these should be local elements, conditions and constraints
1472  auto& r_elements_array = rModelPart.Elements();
1473  auto& r_conditions_array = rModelPart.Conditions();
1474  auto& r_constraints_array = rModelPart.MasterSlaveConstraints();
1475 
1476  // Number of local dofs
1477  const IndexType number_of_local_rows = mLocalSystemSize;
1478 
1479  // Generate map - use the "temp" array here
1480  const int temp_size = (number_of_local_rows < 1000) ? 1000 : number_of_local_rows;
1481  std::vector<int> temp_primary(temp_size, 0);
1482  std::vector<int> temp_secondary(temp_size, 0);
1483  for (IndexType i = 0; i != number_of_local_rows; i++) {
1484  temp_primary[i] = mFirstMyId + i;
1485  }
1486  Epetra_Map& r_map = GetEpetraMap();
1487  std::fill(temp_primary.begin(), temp_primary.begin() + number_of_local_rows, 0);
1488 
1489  // Create and fill the graph of the matrix --> the temp array is
1490  // reused here with a different meaning
1491  Epetra_FECrsGraph Agraph(Copy, r_map, mGuessRowSize);
1492  Element::EquationIdVectorType equation_ids_vector;
1493  const ProcessInfo& r_current_process_info = rModelPart.GetProcessInfo();
1494 
1495  // Trilinos error int definition
1496  int ierr;
1497 
1498  // Assemble all elements
1499  for (auto& r_elem : r_elements_array) {
1500  pScheme->EquationId(r_elem, equation_ids_vector, r_current_process_info);
1501 
1502  // Filling the list of active global indices (non fixed)
1503  IndexType num_active_indices = 0;
1504  for (auto& r_id : equation_ids_vector) {
1505  temp_primary[num_active_indices] = r_id;
1506  ++num_active_indices;
1507  }
1508 
1509  if (num_active_indices != 0) {
1510  ierr = Agraph.InsertGlobalIndices(num_active_indices, temp_primary.data(), num_active_indices, temp_primary.data());
1511  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Graph.InsertGlobalIndices. Error code: " << ierr << std::endl;
1512  }
1513  std::fill(temp_primary.begin(), temp_primary.begin() + num_active_indices, 0);
1514  }
1515 
1516  // Assemble all conditions
1517  for (auto& r_cond : r_conditions_array) {
1518  pScheme->EquationId(r_cond, equation_ids_vector, r_current_process_info);
1519 
1520  // Filling the list of active global indices (non fixed)
1521  IndexType num_active_indices = 0;
1522  for (auto& r_id : equation_ids_vector) {
1523  temp_primary[num_active_indices] = r_id;
1524  ++num_active_indices;
1525  }
1526 
1527  if (num_active_indices != 0) {
1528  ierr = Agraph.InsertGlobalIndices(num_active_indices, temp_primary.data(), num_active_indices, temp_primary.data());
1529  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Graph.InsertGlobalIndices. Error code: " << ierr << std::endl;
1530  }
1531  std::fill(temp_primary.begin(), temp_primary.begin() + num_active_indices, 0);
1532  }
1533 
1534  // Assemble all constraints
1535  Element::EquationIdVectorType slave_equation_ids_vector, master_equation_ids_vector;
1536  for (auto& r_const : r_constraints_array) {
1537  r_const.EquationIdVector(slave_equation_ids_vector, master_equation_ids_vector, r_current_process_info);
1538 
1539  // Filling the list of active global indices (non fixed)
1540  IndexType num_active_slave_indices = 0;
1541  for (auto& r_slave_id : slave_equation_ids_vector) {
1542  temp_primary[num_active_slave_indices] = r_slave_id;
1543  ++num_active_slave_indices;
1544  }
1545  IndexType num_active_master_indices = 0;
1546  for (auto& r_master_id : master_equation_ids_vector) {
1547  temp_secondary[num_active_master_indices] = r_master_id;
1548  ++num_active_master_indices;
1549  }
1550 
1551  // First adding the pure slave dofs
1552  if (num_active_slave_indices > 0) {
1553  int index[1] = {0};
1554  for (IndexType i = 0; i < num_active_slave_indices; ++i) {
1555  index[0] = temp_primary[i];
1556  ierr = Agraph.InsertGlobalIndices(1, index, 1, index);
1557  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Graph.InsertGlobalIndices. Error code: " << ierr << std::endl;
1558  }
1559  // Now adding cross master-slave dofs
1560  if (num_active_master_indices > 0) {
1561  ierr = Agraph.InsertGlobalIndices(num_active_slave_indices, temp_primary.data(), num_active_master_indices, temp_secondary.data());
1562  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Graph.InsertGlobalIndices. Error code: " << ierr << std::endl;
1563  }
1564  }
1565  // Second adding pure master dofs
1566  if (num_active_master_indices > 0) {
1567  int index[1] = {0};
1568  for (IndexType i = 0; i < num_active_master_indices; ++i) {
1569  index[0] = temp_secondary[i];
1570  ierr = Agraph.InsertGlobalIndices(1, index, 1, index);
1571  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Graph.InsertGlobalIndices. Error code: " << ierr << std::endl;
1572  }
1573  }
1574  std::fill(temp_primary.begin(), temp_primary.begin() + num_active_slave_indices, 0);
1575  std::fill(temp_secondary.begin(), temp_secondary.begin() + num_active_master_indices, 0);
1576  }
1577 
1578  // Finalizing graph construction
1579  ierr = Agraph.GlobalAssemble();
1580  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Epetra_FECrsGraph.GlobalAssemble. Error code: " << ierr << std::endl;
1581  ierr = Agraph.FillComplete();
1582  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Epetra_FECrsGraph.FillComplete. Error code: " << ierr << std::endl;
1583  ierr = Agraph.OptimizeStorage();
1584  KRATOS_ERROR_IF(ierr < 0) << ": Epetra failure in Epetra_FECrsGraph.OptimizeStorage. Error code: " << ierr << std::endl;
1585 
1586  // Generate a new matrix pointer according to this graph
1588  rpA.swap(p_new_A);
1589 
1590  // Generate new vector pointers according to the given map
1591  if (rpb == nullptr || TSparseSpace::Size(*rpb) != BaseType::mEquationSystemSize) {
1593  rpb.swap(p_new_b);
1594  }
1595  if (rpDx == nullptr || TSparseSpace::Size(*rpDx) != BaseType::mEquationSystemSize) {
1597  rpDx.swap(p_new_Dx);
1598  }
1599  // If the pointer is not initialized initialize it to an empty matrix
1600  if (BaseType::mpReactionsVector == nullptr) {
1601  TSystemVectorPointerType pNewReactionsVector = TSystemVectorPointerType(new TSystemVectorType(r_map));
1602  BaseType::mpReactionsVector.swap(pNewReactionsVector);
1603  }
1604 
1605  STOP_TIMER("MatrixStructure", 0)
1606  }
1607 
1612  void AssignSettings(const Parameters ThisParameters) override
1613  {
1614  BaseType::AssignSettings(ThisParameters);
1615 
1616  // Get guess row size
1617  mGuessRowSize = ThisParameters["guess_row_size"].GetInt();
1618 
1619  // Setting flags
1620  const std::string& r_diagonal_values_for_dirichlet_dofs = ThisParameters["diagonal_values_for_dirichlet_dofs"].GetString();
1621 
1622  const std::set<std::string> available_options_for_diagonal = {"no_scaling","use_max_diagonal","use_diagonal_norm","defined_in_process_info"};
1623 
1624  if (available_options_for_diagonal.find(r_diagonal_values_for_dirichlet_dofs) == available_options_for_diagonal.end()) {
1625  std::stringstream msg;
1626  msg << "Currently prescribed diagonal values for dirichlet dofs : " << r_diagonal_values_for_dirichlet_dofs << "\n";
1627  msg << "Admissible values for the diagonal scaling are : 'no_scaling', 'use_max_diagonal', 'use_diagonal_norm', or 'defined_in_process_info'" << "\n";
1628  KRATOS_ERROR << msg.str() << std::endl;
1629  }
1630 
1631  // The first option will not consider any scaling (the diagonal values will be replaced with 1)
1632  if (r_diagonal_values_for_dirichlet_dofs == "no_scaling") {
1634  } else if (r_diagonal_values_for_dirichlet_dofs == "use_max_diagonal") {
1636  } else if (r_diagonal_values_for_dirichlet_dofs == "use_diagonal_norm") { // On this case the norm of the diagonal will be considered
1638  } else { // Otherwise we will assume we impose a numerical value
1640  }
1641  mOptions.Set(SILENT_WARNINGS, ThisParameters["silent_warnings"].GetBool());
1642  }
1643 
1647 
1651 
1655 
1657 private:
1660 
1664 
1668 
1672 
1677  Epetra_Map& GetEpetraMap()
1678  {
1679  if (mpMap == nullptr) {
1680  // Generate map - use the "temp" array here
1681  const int temp_size = (mLocalSystemSize < 1000) ? 1000 : mLocalSystemSize;
1682  std::vector<int> temp_primary(temp_size, 0);
1683  for (IndexType i = 0; i != mLocalSystemSize; i++) {
1684  temp_primary[i] = mFirstMyId + i;
1685  }
1686  mpMap = Kratos::make_shared<Epetra_Map>(-1, mLocalSystemSize, temp_primary.data(), 0, mrComm);
1687  }
1688 
1689  return *mpMap;
1690  }
1691 
1697  IndexType DeterminePartitionIndex(const IndexType Index)
1698  {
1699  IndexType index;
1700  for (index = 0; index < mFirstMyIds.size() - 1; ++index) {
1701  if (Index < static_cast<unsigned int>(mFirstMyIds[index + 1])) {
1702  break;
1703  }
1704  }
1705  return index;
1706  }
1707 
1708  void AssembleLHS_CompleteOnFreeRows(TSystemMatrixType& rA,
1709  LocalSystemMatrixType& rLHS_Contribution,
1710  Element::EquationIdVectorType& rEquationId)
1711  {
1712  KRATOS_ERROR << "This method is not implemented for Trilinos";
1713  }
1714 
1718 
1722 
1726 
1728 }; /* Class TrilinosBlockBuilderAndSolver */
1729 
1731 
1734 
1735 // Here one should use the KRATOS_CREATE_LOCAL_FLAG, but it does not play nice with template parameters
1736 template<class TSparseSpace, class TDenseSpace, class TLinearSolver>
1737 const Kratos::Flags TrilinosBlockBuilderAndSolver<TSparseSpace, TDenseSpace, TLinearSolver>::SILENT_WARNINGS(Kratos::Flags::Create(0));
1738 
1740 
1741 } /* namespace Kratos.*/
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
Scheme< TSparseSpace, TDenseSpace > TSchemeType
Definition of the scheme type.
Definition: builder_and_solver.h:100
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: builder_and_solver.h:767
ModelPart::DofsArrayType DofsArrayType
Definition of the DoF array type.
Definition: builder_and_solver.h:106
virtual void Clear()
This function is intended to be called at the end of the solution step to clean up memory storage not...
Definition: builder_and_solver.h:600
bool GetReshapeMatrixFlag() const
This method returns the flag mReshapeMatrixFlag.
Definition: builder_and_solver.h:220
TDenseSpace::MatrixType LocalSystemMatrixType
The local matrix definition.
Definition: builder_and_solver.h:94
TSparseSpace::VectorPointerType TSystemVectorPointerType
Definition of the pointer to the vector.
Definition: builder_and_solver.h:91
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
SizeType GlobalNumberOfMasterSlaveConstraints() const
Definition: communicator.cpp:116
virtual const DataCommunicator & GetDataCommunicator() const
Definition: communicator.cpp:340
MeshType & LocalMesh()
Returns the reference to the mesh storing all local entities.
Definition: communicator.cpp:245
virtual int Rank() const
Get the parallel rank for this DataCommunicator.
Definition: data_communicator.h:587
std::vector< DofType::Pointer > DofsVectorType
Definition: element.h:100
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
Definition: flags.h:58
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
static Flags Create(IndexType ThisPosition, bool Value=true)
Definition: flags.h:138
This class is useful for index iteration over containers.
Definition: parallel_utilities.h:451
void for_each(TUnaryFunction &&f)
Definition: parallel_utilities.h:514
SizeType NumberOfNodes() const
Definition: mesh.h:259
ConditionsContainerType & Conditions()
Definition: mesh.h:691
MasterSlaveConstraintContainerType & MasterSlaveConstraints()
Definition: mesh.h:802
ElementsContainerType & Elements()
Definition: mesh.h:568
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MasterSlaveConstraintContainerType & MasterSlaveConstraints(IndexType ThisIndex=0)
Definition: model_part.h:654
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
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
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
void Unique()
Remove duplicate elements from the set.
Definition: pointer_vector_set.h:764
ptr_iterator ptr_end()
Returns an iterator pointing to the end of the underlying data container.
Definition: pointer_vector_set.h:404
ptr_iterator ptr_begin()
Returns an iterator pointing to the beginning of the underlying data container.
Definition: pointer_vector_set.h:386
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
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
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
static void AssembleRelationMatrixT(MatrixType &rT, const Matrix &rTContribution, const std::vector< std::size_t > &rSlaveEquationId, const std::vector< std::size_t > &rMasterEquationId)
Assembles the relation matrix T of the system with MPC.
Definition: trilinos_assembling_utilities.h:96
static void AssembleConstantVector(VectorType &rC, const Vector &rConstantContribution, const std::vector< std::size_t > &rSlaveEquationId)
Assembles the Constant vector of the system with MPC.
Definition: trilinos_assembling_utilities.h:150
static void SetGlobalValueWithoutGlobalAssembly(VectorType &rX, IndexType i, const double Value)
Sets a value in a vector.
Definition: trilinos_assembling_utilities.h:213
Current class provides an implementation for trilinos builder and solving operations.
Definition: trilinos_block_builder_and_solver.h:85
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: trilinos_block_builder_and_solver.h:1065
TrilinosBlockBuilderAndSolver(EpetraCommunicatorType &rComm, typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Default constructor. (with parameters)
Definition: trilinos_block_builder_and_solver.h:149
typename BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition of the pointer types.
Definition: trilinos_block_builder_and_solver.h:122
SCALING_DIAGONAL mScalingDiagonal
The manually set scale factor.
Definition: trilinos_block_builder_and_solver.h:1192
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: trilinos_block_builder_and_solver.h:375
std::vector< IndexType > mMasterIds
The equation ids of the slaves.
Definition: trilinos_block_builder_and_solver.h:1187
virtual void ConstructMatrixStructure(typename TSchemeType::Pointer pScheme, TSystemMatrixPointerType &rpA, TSystemVectorPointerType &rpDx, TSystemVectorPointerType &rpb, ModelPart &rModelPart)
Constructs the matrix structure for the given problem.
Definition: trilinos_block_builder_and_solver.h:1460
void Build(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb) override
Function to perform the build the system matrix and the residual vector.
Definition: trilinos_block_builder_and_solver.h:189
double GetScaleFactor()
Retrieves the current scale factor. This function returns the current scale factor value.
Definition: trilinos_block_builder_and_solver.h:1120
void CalculateReactions(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
It computes the reactions of the system.
Definition: trilinos_block_builder_and_solver.h:784
Epetra_MpiComm EpetraCommunicatorType
Epetra definitions.
Definition: trilinos_block_builder_and_solver.h:108
typename BaseType::TSystemMatrixType TSystemMatrixType
Defining the sparse matrices and vectors.
Definition: trilinos_block_builder_and_solver.h:114
std::string Info() const override
Turn back information as a string.
Definition: trilinos_block_builder_and_solver.h:1144
EpetraCommunicatorType & mrComm
Definition: trilinos_block_builder_and_solver.h:1175
Kratos::shared_ptr< Epetra_Map > mpMap
Auxiliary Id (the last row of the local system) // TODO: This can be removed as can be deduced from m...
Definition: trilinos_block_builder_and_solver.h:1180
TrilinosBlockBuilderAndSolver(const TrilinosBlockBuilderAndSolver &rOther)=delete
void ApplyRHSConstraints(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &rb) override
Applies the constraints with master-slave relation matrix (RHS only)
Definition: trilinos_block_builder_and_solver.h:948
void BuildLHS_CompleteOnFreeRows(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &A) override
Build a rectangular matrix of size n*N where "n" is the number of unrestrained degrees of freedom and...
Definition: trilinos_block_builder_and_solver.h:314
void SetScaleFactor(const double ScaleFactor)
Sets the scale factor. This function sets a new value for the scale factor.
Definition: trilinos_block_builder_and_solver.h:1130
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: trilinos_block_builder_and_solver.h:598
void ApplyConstraints(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb) override
Applies the constraints with master-slave relation matrix.
Definition: trilinos_block_builder_and_solver.h:988
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: trilinos_block_builder_and_solver.h:1612
void Clear() override
This function is intended to be called at the end of the solution step to clean up memory storage not...
Definition: trilinos_block_builder_and_solver.h:1035
TSystemVectorPointerType mpConstantVector
This is matrix containing the global relation for the constraints.
Definition: trilinos_block_builder_and_solver.h:1185
double mScaleFactor
The set containing the inactive slave dofs.
Definition: trilinos_block_builder_and_solver.h:1189
void BuildLHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA) override
Function to perform the building of the LHS.
Definition: trilinos_block_builder_and_solver.h:258
Flags mOptions
We identify the scaling considered for the dirichlet dofs.
Definition: trilinos_block_builder_and_solver.h:1193
int mFirstMyId
The local system size.
Definition: trilinos_block_builder_and_solver.h:1178
void BuildRHSAndSolve(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
Corresponds to the previous, but the System's matrix is considered already built and only the RHS is ...
Definition: trilinos_block_builder_and_solver.h:507
void BuildRHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &rb) override
Function to perform the build of the RHS.
Definition: trilinos_block_builder_and_solver.h:544
virtual void ConstructMasterSlaveConstraintsStructure(ModelPart &rModelPart)
Constructs the master-slave constraints structure for the given model part.
Definition: trilinos_block_builder_and_solver.h:1208
TSparseSpace::VectorType & GetConstraintConstantVector() override
This method returns constraint constant vector.
Definition: trilinos_block_builder_and_solver.h:1109
typename BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: trilinos_block_builder_and_solver.h:119
virtual void BuildMasterSlaveConstraints(ModelPart &rModelPart)
Builds the master-slave constraints for the given model part.
Definition: trilinos_block_builder_and_solver.h:1352
KRATOS_DEFINE_LOCAL_FLAG(SILENT_WARNINGS)
Definition of the flags.
void InternalSystemSolveWithPhysics(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb, ModelPart &rModelPart)
This is a call to the linear system solver (taking into account some physical particularities of the ...
Definition: trilinos_block_builder_and_solver.h:411
IndexType mLocalSystemSize
The guess row size.
Definition: trilinos_block_builder_and_solver.h:1177
std::vector< int > mFirstMyIds
The map considered for the different vectors and matrices.
Definition: trilinos_block_builder_and_solver.h:1181
TrilinosBlockBuilderAndSolver & operator=(const TrilinosBlockBuilderAndSolver &rOther)=delete
typename BaseType::LocalSystemMatrixType LocalSystemMatrixType
Defining the local matrices and vectors.
Definition: trilinos_block_builder_and_solver.h:118
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: trilinos_block_builder_and_solver.h:1150
TSystemMatrixPointerType mpT
The ids corresponding to each partition (only used with MPC)
Definition: trilinos_block_builder_and_solver.h:1184
TSparseSpace::MatrixType & GetConstraintRelationMatrix() override
This method returns constraint relation (T) matrix.
Definition: trilinos_block_builder_and_solver.h:1099
int mGuessRowSize
The MPI communicator.
Definition: trilinos_block_builder_and_solver.h:1176
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: trilinos_block_builder_and_solver.h:1086
int mLastMyId
Auxiliary Id (the first row of the local system)
Definition: trilinos_block_builder_and_solver.h:1179
int Check(ModelPart &rModelPart) override
This function is designed to be called once to perform all the checks needed on the input provided....
Definition: trilinos_block_builder_and_solver.h:1053
typename BaseType::DofsArrayType DofsArrayType
Definition: trilinos_block_builder_and_solver.h:105
std::vector< IndexType > mSlaveIds
This is vector containing the rigid movement of the constraint.
Definition: trilinos_block_builder_and_solver.h:1186
TrilinosBlockBuilderAndSolver(EpetraCommunicatorType &rComm, int GuessRowSize, typename TLinearSolver::Pointer pNewLinearSystemSolver)
Default constructor.
Definition: trilinos_block_builder_and_solver.h:137
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: trilinos_block_builder_and_solver.h:451
void ResizeAndInitializeVectors(typename TSchemeType::Pointer pScheme, TSystemMatrixPointerType &rpA, TSystemVectorPointerType &rpDx, TSystemVectorPointerType &rpb, ModelPart &rModelPart) override
Resizes the system matrix and the vector according to the number of dos in the current rModelPart....
Definition: trilinos_block_builder_and_solver.h:747
typename BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: trilinos_block_builder_and_solver.h:123
void SystemSolve(TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
This is a call to the linear system solver.
Definition: trilinos_block_builder_and_solver.h:329
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: trilinos_block_builder_and_solver.h:872
void SetUpSystem(ModelPart &rModelPart) override
Organizes the DoF set in order to speed up the building phase Sets equation id for degrees of freedom...
Definition: trilinos_block_builder_and_solver.h:680
std::size_t IndexType
Definition: trilinos_block_builder_and_solver.h:101
std::unordered_set< IndexType > mInactiveSlaveDofs
The equation ids of the master.
Definition: trilinos_block_builder_and_solver.h:1188
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: trilinos_block_builder_and_solver.h:1156
typename BaseType::TSystemVectorType TSystemVectorType
Definition: trilinos_block_builder_and_solver.h:115
KRATOS_CLASS_POINTER_DEFINITION(TrilinosBlockBuilderAndSolver)
Definition of the pointer.
TrilinosBlockBuilderAndSolver()=default
Default constructor (empty)
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#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_INFO_IF_ALL_RANKS(label, conditional)
Definition: logger.h:261
#define KRATOS_WARNING(label)
Definition: logger.h:265
end
Definition: DEM_benchmarks.py:180
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
TSpaceType::IndexType Size1(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:117
void TransposeMult(SparseSpaceType &dummy, SparseSpaceType::MatrixType &rA, SparseSpaceType::VectorType &rX, SparseSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:104
TSpaceType::IndexType Size2(TSpaceType &dummy, typename TSpaceType::MatrixType const &rM)
Definition: add_strategies_to_python.cpp:123
double TwoNorm(SparseSpaceType &dummy, SparseSpaceType::VectorType &x)
Definition: add_strategies_to_python.cpp:164
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
void Mult(TSpaceType &dummy, typename TSpaceType::MatrixType &rA, typename TSpaceType::VectorType &rX, typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:98
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
SCALING_DIAGONAL
Definition: ublas_space.h:98
ScaleFactor
Definition: generate_frictional_mortar_condition.py:131
def Index()
Definition: hdf5_io_tools.py:38
int dof
Definition: ode_solve.py:393
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int counter
Definition: script_THERMAL_CORRECT.py:218
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17
#define STOP_TIMER(label, rank)
Definition: trilinos_block_builder_and_solver.h:39
#define START_TIMER(label, rank)
Definition: trilinos_block_builder_and_solver.h:34