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.
eigensolver_strategy.hpp
Go to the documentation of this file.
1 // KRATOS ___| | | |
2 // \___ \ __| __| | | __| __| | | __| _` | |
3 // | | | | | ( | | | | ( | |
4 // _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS
5 //
6 // License: BSD License
7 // license: StructuralMechanicsApplication/license.txt
8 //
9 // Main author: Michael Andre, https://github.com/msandre
10 //
11 
12 #pragma once
13 
14 // System includes
15 
16 // External includes
17 
18 // Project includes
23 
24 // Application includes
26 
27 namespace Kratos
28 {
29 
32 
36 
40 
44 
48 
50 template<class TSparseSpace,
51  class TDenseSpace,
52  class TLinearSolver
53  >
54 class EigensolverStrategy
55  : public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
56 {
57 public:
60 
62 
64 
65  typedef typename BaseType::TSchemeType::Pointer SchemePointerType;
66 
67  typedef typename BaseType::TBuilderAndSolverType::Pointer BuilderAndSolverPointerType;
68 
70 
72 
73  typedef TSparseSpace SparseSpaceType;
74 
75  typedef typename TSparseSpace::VectorPointerType SparseVectorPointerType;
76 
77  typedef typename TSparseSpace::MatrixPointerType SparseMatrixPointerType;
78 
80 
82 
86 
89  ModelPart& rModelPart,
90  SchemePointerType pScheme,
91  BuilderAndSolverPointerType pBuilderAndSolver,
92  double MassMatrixDiagonalValue,
93  double StiffnessMatrixDiagonalValue,
94  bool ComputeModalDecomposition = false
95  )
96  : ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart),
97  mMassMatrixDiagonalValue(MassMatrixDiagonalValue),
98  mStiffnessMatrixDiagonalValue(StiffnessMatrixDiagonalValue),
99  mComputeModalDecompostion(ComputeModalDecomposition)
100  {
101  KRATOS_TRY
102 
103  mpScheme = pScheme;
104 
105  mpBuilderAndSolver = pBuilderAndSolver;
106 
107  // ensure initialization of system matrices in InitializeSolutionStep()
108  mpBuilderAndSolver->SetDofSetIsInitializedFlag(false);
109 
110  // default echo level (mute)
111  this->SetEchoLevel(0);
112 
113  // default rebuild level (build at each solution step)
114  this->SetRebuildLevel(1);
115 
116  SparseMatrixType* AuxMassMatrix = new SparseMatrixType;
117  mpMassMatrix = Kratos::shared_ptr<SparseMatrixType>(AuxMassMatrix);
118  SparseMatrixType* AuxStiffnessMatrix = new SparseMatrixType;
119  mpStiffnessMatrix = Kratos::shared_ptr<SparseMatrixType>(AuxStiffnessMatrix);
120 
121  KRATOS_CATCH("")
122  }
123 
125  EigensolverStrategy(const EigensolverStrategy& Other) = delete;
126 
129  {
130  // Clear() controls order of deallocation to avoid invalid memory access
131  // in some special cases.
132  // warning: BaseType::GetModelPart() may be invalid here.
133  this->Clear();
134  }
135 
139 
143 
144  void SetIsInitialized(bool val)
145  {
146  mInitializeWasPerformed = val;
147  }
148 
149  bool GetIsInitialized() const
150  {
151  return mInitializeWasPerformed;
152  }
153 
155  {
156  mpScheme = pScheme;
157  };
158 
160  {
161  return mpScheme;
162  };
163 
165  {
166  mpBuilderAndSolver = pNewBuilderAndSolver;
167  };
168 
170  {
171  return mpBuilderAndSolver;
172  };
173 
175  {
176 // if (mpMassMatrix == nullptr)
177 // {
178 // KRATOS_ERROR << "CHEK YOUR MASS MATRIX PLEASE IS INITIALIZED" << std::endl;
179 // }
180  return *mpMassMatrix;
181  }
182 
184  {
185 // if (mpStiffnessMatrix == nullptr)
186 // {
187 // KRATOS_ERROR << "CHEK YOUR STIFFNESS MATRIX PLEASE IS INITIALIZED" << std::endl;
188 // }
189  return *mpStiffnessMatrix;
190  }
191 
193  {
194 // if (mpMassMatrix == nullptr)
195 // {
196 // KRATOS_ERROR << "CHEK YOUR MASS MATRIX PLEASE IS INITIALIZED" << std::endl;
197 // }
198  return mpMassMatrix;
199  }
200 
202  {
203 // if (mpStiffnessMatrix == nullptr)
204 // {
205 // KRATOS_ERROR << "CHEK YOUR STIFFNESS MATRIX PLEASE IS INITIALIZED" << std::endl;
206 // }
207  return mpStiffnessMatrix;
208  }
209 
211  {
212  this->pGetBuilderAndSolver()->SetReshapeMatrixFlag(flag);
213  }
214 
216  {
217  return this->pGetBuilderAndSolver()->GetReshapeMatrixFlag();
218  }
219 
221 
227  void SetEchoLevel(int Level) override
228  {
229  BaseType::SetEchoLevel(Level);
230  this->pGetBuilderAndSolver()->SetEchoLevel(Level);
231  }
232 
236  void Initialize() override
237  {
238  KRATOS_TRY
239 
240  ModelPart& rModelPart = BaseType::GetModelPart();
241 
242  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
243  << "Entering Initialize" << std::endl;
244 
245  if (mInitializeWasPerformed == false)
246  {
247  SchemePointerType& pScheme = this->pGetScheme();
248 
249  if (pScheme->SchemeIsInitialized() == false)
250  pScheme->Initialize(rModelPart);
251 
252  if (pScheme->ElementsAreInitialized() == false)
253  pScheme->InitializeElements(rModelPart);
254 
255  if (pScheme->ConditionsAreInitialized() == false)
256  pScheme->InitializeConditions(rModelPart);
257  }
258 
259  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
260  << "Exiting Initialize" << std::endl;
261 
262  KRATOS_CATCH("")
263  }
264 
268  void Clear() override
269  {
270  KRATOS_TRY
271 
272  // if the preconditioner is saved between solves, it should be cleared here
273  BuilderAndSolverPointerType& pBuilderAndSolver = this->pGetBuilderAndSolver();
274  pBuilderAndSolver->GetLinearSystemSolver()->Clear();
275 
276  if (this->pGetMassMatrix() != nullptr)
277  this->pGetMassMatrix() = nullptr;
278 
279  if (this->pGetStiffnessMatrix() != nullptr)
280  this->pGetStiffnessMatrix() = nullptr;
281 
282  // Re-setting internal flag to ensure that the dof sets are recalculated
283  pBuilderAndSolver->SetDofSetIsInitializedFlag(false);
284 
285  pBuilderAndSolver->Clear();
286 
287  this->pGetScheme()->Clear();
288 
289  mInitializeWasPerformed = false;
290 
291  KRATOS_CATCH("")
292  }
293 
299  void InitializeSolutionStep() override
300  {
301  KRATOS_TRY
302 
303  ModelPart& rModelPart = BaseType::GetModelPart();
304 
305  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
306  << "Entering InitializeSolutionStep" << std::endl;
307 
308  BuilderAndSolverPointerType& pBuilderAndSolver = this->pGetBuilderAndSolver();
309  SchemePointerType& pScheme = this->pGetScheme();
310  SparseMatrixPointerType& pStiffnessMatrix = this->pGetStiffnessMatrix();
311  SparseMatrixType& rStiffnessMatrix = this->GetStiffnessMatrix();
312 
313  // Initialize dummy vectors
314  SparseVectorPointerType pDx = SparseSpaceType::CreateEmptyVectorPointer();
316  auto& rDx = *pDx;
317  auto& rb = *pb;
318 
319  // Reset solution dofs
320  BuiltinTimer system_construction_time;
321  if (pBuilderAndSolver->GetDofSetIsInitializedFlag() == false ||
322  pBuilderAndSolver->GetReshapeMatrixFlag() == true)
323  {
324  // Set up list of dofs
325  BuiltinTimer setup_dofs_time;
326  pBuilderAndSolver->SetUpDofSet(pScheme, rModelPart);
327 
328  KRATOS_INFO_IF("Setup Dofs Time", BaseType::GetEchoLevel() > 0)
329  << setup_dofs_time << std::endl;
330 
331  // Set global equation ids
332  BuiltinTimer setup_system_time;
333  pBuilderAndSolver->SetUpSystem(rModelPart);
334 
335  KRATOS_INFO_IF("Setup System Time", BaseType::GetEchoLevel() > 0)
336  << setup_system_time << std::endl;
337 
338  // Resize and initialize system matrices
339  BuiltinTimer system_matrix_resize_time;
340  SparseMatrixPointerType& pMassMatrix = this->pGetMassMatrix();
341 
342  // Mass matrix
343  pBuilderAndSolver->ResizeAndInitializeVectors(
344  pScheme, pMassMatrix, pDx, pb, rModelPart);
345 
346  // Stiffness matrix
347  pBuilderAndSolver->ResizeAndInitializeVectors(
348  pScheme, pStiffnessMatrix, pDx, pb, rModelPart);
349 
350  KRATOS_INFO_IF("System Matrix Resize Time", BaseType::GetEchoLevel() > 0)
351  << system_matrix_resize_time << std::endl;
352  }
353  else
354  {
355  SparseSpaceType::Resize(rb, SparseSpaceType::Size1(rStiffnessMatrix));
356  SparseSpaceType::Set(rb, 0.0);
357  SparseSpaceType::Resize(rDx, SparseSpaceType::Size1(rStiffnessMatrix));
358  SparseSpaceType::Set(rDx, 0.0);
359  }
360 
361  KRATOS_INFO_IF("System Construction Time", BaseType::GetEchoLevel() > 0)
362  << system_construction_time << std::endl;
363 
364  // Initial operations ... things that are constant over the solution
365  // step
366  pBuilderAndSolver->InitializeSolutionStep(BaseType::GetModelPart(),
367  rStiffnessMatrix, rDx, rb);
368 
369  // Initial operations ... things that are constant over the solution
370  // step
371  pScheme->InitializeSolutionStep(BaseType::GetModelPart(), rStiffnessMatrix, rDx, rb);
372 
373  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
374  << "Exiting InitializeSolutionStep" << std::endl;
375 
376  KRATOS_CATCH("")
377  }
378 
379  bool SolveSolutionStep() override
380  {
381  KRATOS_TRY;
382 
383  ModelPart& rModelPart = BaseType::GetModelPart();
384 
385  SchemePointerType& pScheme = this->pGetScheme();
386  SparseMatrixType& rMassMatrix = this->GetMassMatrix();
387  SparseMatrixType& rStiffnessMatrix = this->GetStiffnessMatrix();
388 
389  // Initialize dummy rhs vector
390  SparseVectorType b;
392  SparseSpaceType::Set(b,0.0);
393 
394  // if the size of the Matrix is the same as the size of the dofset, then also the dirichlet-dofs are in the matrix
395  // i.e. a BlockBuilder is used
396  const bool matrix_contains_dirichlet_dofs = SparseSpaceType::Size1(rMassMatrix) == this->pGetBuilderAndSolver()->GetDofSet().size();
397 
398  const bool master_slave_constraints_defined = rModelPart.NumberOfMasterSlaveConstraints() != 0;
399 
400  rModelPart.GetProcessInfo()[BUILD_LEVEL] = 1;
401  TSparseSpace::SetToZero(rMassMatrix);
402 
404 
405  this->pGetBuilderAndSolver()->Build(pScheme,rModelPart,rMassMatrix,b);
406  if (master_slave_constraints_defined) {
407  this->pGetBuilderAndSolver()->ApplyConstraints(pScheme, rModelPart, rMassMatrix, b);
408  }
409  if (matrix_contains_dirichlet_dofs) {
410  this->ApplyDirichletConditions(rMassMatrix, mMassMatrixDiagonalValue);
411  }
412 
413  if (BaseType::GetEchoLevel() == 4) {
414  TSparseSpace::WriteMatrixMarketMatrix("MassMatrix.mm", rMassMatrix, false);
415  }
416 
417  rModelPart.GetProcessInfo()[BUILD_LEVEL] = 2;
418  TSparseSpace::SetToZero(rStiffnessMatrix);
419  this->pGetBuilderAndSolver()->Build(pScheme,rModelPart,rStiffnessMatrix,b);
420  if (master_slave_constraints_defined) {
421  this->pGetBuilderAndSolver()->ApplyConstraints(pScheme, rModelPart, rStiffnessMatrix, b);
422  }
423 
424  if (matrix_contains_dirichlet_dofs) {
425  this->ApplyDirichletConditions(rStiffnessMatrix, mStiffnessMatrixDiagonalValue);
426  }
427 
429 
430  if (BaseType::GetEchoLevel() == 4) {
431  TSparseSpace::WriteMatrixMarketMatrix("StiffnessMatrix.mm", rStiffnessMatrix, false);
432  }
433 
434  // Eigenvector matrix and eigenvalue vector are initialized by the solver
435  DenseVectorType Eigenvalues;
436  DenseMatrixType Eigenvectors;
437 
438  // Solve for eigenvalues and eigenvectors
439  BuiltinTimer system_solve_time;
440  this->pGetBuilderAndSolver()->GetLinearSystemSolver()->Solve(
441  rStiffnessMatrix,
442  rMassMatrix,
443  Eigenvalues,
444  Eigenvectors);
445 
446  KRATOS_INFO_IF("System Solve Time", BaseType::GetEchoLevel() > 0)
447  << system_solve_time << std::endl;
448 
449  if (master_slave_constraints_defined){
450  this->ReconstructSlaveSolution(Eigenvectors);
451  }
452 
453  this->AssignVariables(Eigenvalues,Eigenvectors);
454 
455 
456  if (mComputeModalDecompostion) {
457  ComputeModalDecomposition(Eigenvectors);
458  }
459 
460  return true;
461  KRATOS_CATCH("")
462  }
463 
464  void FinalizeSolutionStep() override
465  {
466  KRATOS_TRY;
467 
468  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
469  << "Entering FinalizeSolutionStep" << std::endl;
470 
471  SparseMatrixType& rStiffnessMatrix = this->GetStiffnessMatrix();
472  SparseVectorPointerType pDx = SparseSpaceType::CreateEmptyVectorPointer();
474  pGetBuilderAndSolver()->FinalizeSolutionStep(
475  BaseType::GetModelPart(), rStiffnessMatrix, *pDx, *pb);
476  pGetScheme()->FinalizeSolutionStep(BaseType::GetModelPart(),
477  rStiffnessMatrix, *pDx, *pb);
478  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
479  << "Exiting FinalizeSolutionStep" << std::endl;
480 
481  KRATOS_CATCH("");
482  }
483 
488  int Check() override
489  {
490  KRATOS_TRY
491 
492  ModelPart& rModelPart = BaseType::GetModelPart();
493 
494  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
495  << "Entering Check" << std::endl;
496 
497  // check the model part
498  BaseType::Check();
499 
500  // check the scheme
501  this->pGetScheme()->Check(rModelPart);
502 
503  // check the builder and solver
504  this->pGetBuilderAndSolver()->Check(rModelPart);
505 
506  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
507  << "Exiting Check" << std::endl;
508 
509  return 0;
510 
511  KRATOS_CATCH("")
512  }
513 
517 
521 
525 
527 
528 protected:
531 
535 
539 
543 
547 
551 
555 
557 
558 private:
561 
565 
566  SchemePointerType mpScheme;
567 
568  BuilderAndSolverPointerType mpBuilderAndSolver;
569 
570  SparseMatrixPointerType mpMassMatrix;
571 
572  SparseMatrixPointerType mpStiffnessMatrix;
573 
574  bool mInitializeWasPerformed = false;
575 
576  double mMassMatrixDiagonalValue = 0.0;
577  double mStiffnessMatrixDiagonalValue = 1.0;
578 
579  bool mComputeModalDecompostion = false;
580 
584 
588 
596  void ReconstructSlaveSolution(
597  DenseMatrixType& rEigenvectors
598  )
599  {
600  KRATOS_TRY
601 
602  auto& r_model_part = BaseType::GetModelPart();
603  const std::size_t number_of_eigenvalues = rEigenvectors.size1();
604 
605  struct TLS{
606  Matrix relation_matrix;
607  Vector constant_vector;
608  Vector master_dofs_values;
609  };
610 
611  for (std::size_t i_eigenvalue = 0; i_eigenvalue < number_of_eigenvalues; ++i_eigenvalue){
612 
613  // Reset slave dofs
614  block_for_each(r_model_part.MasterSlaveConstraints(), [&i_eigenvalue, &rEigenvectors](const MasterSlaveConstraint& r_master_slave_constraint){
615  const auto& r_slave_dofs_vector = r_master_slave_constraint.GetSlaveDofsVector();
616  for (const auto& r_slave_dof: r_slave_dofs_vector){
617  AtomicMult(rEigenvectors(i_eigenvalue, r_slave_dof->EquationId()), 0.0);
618  }
619  });
620 
621  // Apply constraints
622  block_for_each(r_model_part.MasterSlaveConstraints(), TLS(), [&i_eigenvalue, &rEigenvectors, &r_model_part](const MasterSlaveConstraint& r_master_slave_constraint, TLS& rTLS){
623  // Detect if the constraint is active or not. If the user did not make any choice the constraint
624  // It is active by default
625  bool constraint_is_active = true;
626  if (r_master_slave_constraint.IsDefined(ACTIVE))
627  constraint_is_active = r_master_slave_constraint.Is(ACTIVE);
628  if (constraint_is_active) {
629  // Saving the master dofs values
630  const auto& r_master_dofs_vector = r_master_slave_constraint.GetMasterDofsVector();
631  const auto& r_slave_dofs_vector = r_master_slave_constraint.GetSlaveDofsVector();
632  rTLS.master_dofs_values.resize(r_master_dofs_vector.size());
633  for (IndexType i = 0; i < r_master_dofs_vector.size(); ++i) {
634  rTLS.master_dofs_values[i] = rEigenvectors(i_eigenvalue, r_master_dofs_vector[i]->EquationId());
635  }
636  // Apply the constraint to the slave dofs
637  r_master_slave_constraint.GetLocalSystem(rTLS.relation_matrix, rTLS.constant_vector, r_model_part.GetProcessInfo());
638  double aux;
639  for (IndexType i = 0; i < rTLS.relation_matrix.size1(); ++i) {
640  aux = rTLS.constant_vector[i];
641  for(IndexType j = 0; j < rTLS.relation_matrix.size2(); ++j) {
642  aux += rTLS.relation_matrix(i,j) * rTLS.master_dofs_values[j];
643  }
644  AtomicAdd(rEigenvectors(i_eigenvalue, r_slave_dofs_vector[i]->EquationId()), aux);
645  }
646  }
647  });
648  }
649 
650  KRATOS_CATCH("")
651  }
652 
654 
659  void ApplyDirichletConditions(
660  SparseMatrixType& rA,
661  double Factor)
662  {
663  KRATOS_TRY
664 
665  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
666  << "Entering ApplyDirichletConditions" << std::endl;
667 
668  const std::size_t SystemSize = rA.size1();
669  std::vector<double> ScalingFactors(SystemSize);
670  auto& rDofSet = this->pGetBuilderAndSolver()->GetDofSet();
671  const int NumDofs = static_cast<int>(rDofSet.size());
672 
673  // NOTE: dofs are assumed to be numbered consecutively
674  IndexPartition(NumDofs).for_each([&rDofSet, &ScalingFactors](std::size_t k){
675  auto dof_iterator = std::begin(rDofSet) + k;
676  ScalingFactors[k] = (dof_iterator->IsFixed()) ? 0.0 : 1.0;
677  });
678 
679  double* AValues = std::begin(rA.value_data());
680  std::size_t* ARowIndices = std::begin(rA.index1_data());
681  std::size_t* AColIndices = std::begin(rA.index2_data());
682 
683  // if there is a line of all zeros, put one on the diagonal
684  // #pragma omp parallel for firstprivate(SystemSize)
685  // for(int k = 0; k < static_cast<int>(SystemSize); ++k)
686  // {
687  // std::size_t ColBegin = ARowIndices[k];
688  // std::size_t ColEnd = ARowIndices[k+1];
689  // bool empty = true;
690  // for (auto j = ColBegin; j < ColEnd; ++j)
691  // if(AValues[j] != 0.0)
692  // {
693  // empty = false;
694  // break;
695  // }
696  // if(empty == true)
697  // rA(k,k) = 1.0;
698  // }
699 
700  IndexPartition(SystemSize).for_each([&](std::size_t k){
701  std::size_t ColBegin = ARowIndices[k];
702  std::size_t ColEnd = ARowIndices[k+1];
703  if (ScalingFactors[k] == 0.0)
704  {
705  // row dof is fixed. zero off-diagonal columns and factor diagonal
706  for (std::size_t j = ColBegin; j < ColEnd; ++j)
707  {
708  if (AColIndices[j] != k)
709  {
710  AValues[j] = 0.0;
711  }
712  else
713  {
714  AValues[j] *= Factor;
715  }
716  }
717  }
718  else
719  {
720  // row dof is not fixed. zero columns associated with fixed dofs
721  for (std::size_t j = ColBegin; j < ColEnd; ++j)
722  {
723  AValues[j] *= ScalingFactors[AColIndices[j]];
724  }
725  }
726  });
727 
728  KRATOS_INFO_IF("EigensolverStrategy", BaseType::GetEchoLevel() > 2)
729  << "Exiting ApplyDirichletConditions" << std::endl;
730 
731  KRATOS_CATCH("")
732  }
733 
735  void AssignVariables(DenseVectorType& rEigenvalues, DenseMatrixType& rEigenvectors)
736  {
737  ModelPart& rModelPart = BaseType::GetModelPart();
738  const std::size_t NumEigenvalues = rEigenvalues.size();
739 
740  // store eigenvalues in process info
741  rModelPart.GetProcessInfo()[EIGENVALUE_VECTOR] = rEigenvalues;
742 
743  const auto& r_dof_set = this->pGetBuilderAndSolver()->GetDofSet();
744 
745  for (ModelPart::NodeIterator itNode = rModelPart.NodesBegin(); itNode!= rModelPart.NodesEnd(); itNode++) {
746  ModelPart::NodeType::DofsContainerType& NodeDofs = itNode->GetDofs();
747  const std::size_t NumNodeDofs = NodeDofs.size();
748  Matrix& rNodeEigenvectors = itNode->GetValue(EIGENVECTOR_MATRIX);
749  if (rNodeEigenvectors.size1() != NumEigenvalues || rNodeEigenvectors.size2() != NumNodeDofs) {
750  rNodeEigenvectors.resize(NumEigenvalues,NumNodeDofs,false);
751  }
752 
753  // fill the EIGENVECTOR_MATRIX
754  for (std::size_t i = 0; i < NumEigenvalues; i++) {
755  for (std::size_t j = 0; j < NumNodeDofs; j++)
756  {
757  const auto itDof = std::begin(NodeDofs) + j;
758  bool is_active = !(r_dof_set.find(**itDof) == r_dof_set.end());
759  if ((*itDof)->IsFree() && is_active) {
760  rNodeEigenvectors(i,j) = rEigenvectors(i,(*itDof)->EquationId());
761  }
762  else {
763  rNodeEigenvectors(i,j) = 0.0;
764  }
765  }
766  }
767  }
768  }
769 
771 
776  void ComputeModalDecomposition(const DenseMatrixType& rEigenvectors)
777  {
778  const SparseMatrixType& rMassMatrix = this->GetMassMatrix();
779  SparseMatrixType m_temp = ZeroMatrix(rEigenvectors.size1(),rEigenvectors.size2());
780  boost::numeric::ublas::axpy_prod(rEigenvectors,rMassMatrix,m_temp,true);
781  Matrix modal_mass_matrix = ZeroMatrix(m_temp.size1(),m_temp.size1());
782  boost::numeric::ublas::axpy_prod(m_temp,trans(rEigenvectors),modal_mass_matrix);
783 
784  const SparseMatrixType& rStiffnessMatrix = this->GetStiffnessMatrix();
785  SparseMatrixType k_temp = ZeroMatrix(rEigenvectors.size1(),rEigenvectors.size2());
786  boost::numeric::ublas::axpy_prod(rEigenvectors,rStiffnessMatrix,k_temp,true);
787  Matrix modal_stiffness_matrix = ZeroMatrix(k_temp.size1(),k_temp.size1());
788  boost::numeric::ublas::axpy_prod(k_temp,trans(rEigenvectors),modal_stiffness_matrix);
789 
790  ModelPart& rModelPart = BaseType::GetModelPart();
791  rModelPart.GetProcessInfo()[MODAL_MASS_MATRIX] = modal_mass_matrix;
792  rModelPart.GetProcessInfo()[MODAL_STIFFNESS_MATRIX] = modal_stiffness_matrix;
793 
794  KRATOS_INFO("ModalMassMatrix") << modal_mass_matrix << std::endl;
795  KRATOS_INFO("ModalStiffnessMatrix") << modal_stiffness_matrix << std::endl;
796  }
797 
801 
805 
807 
808 }; /* Class EigensolverStrategy */
809 
811 
814 
815 
817 
818 } /* namespace Kratos */
Definition: builtin_timer.h:26
Strategy for solving generalized eigenvalue problems.
Definition: eigensolver_strategy.hpp:52
ImplicitSolvingStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: eigensolver_strategy.hpp:63
void SetEchoLevel(int Level) override
Set verbosity level of the solving strategy.
Definition: eigensolver_strategy.hpp:227
BaseType::TSchemeType::Pointer SchemePointerType
Definition: eigensolver_strategy.hpp:65
SparseMatrixPointerType & pGetMassMatrix()
Definition: eigensolver_strategy.hpp:192
BuilderAndSolverType::Pointer & pGetBuilderAndSolver()
Definition: eigensolver_strategy.hpp:291
SparseMatrixType & GetStiffnessMatrix()
Definition: eigensolver_strategy.hpp:183
TDenseSpace::VectorType DenseVectorType
Definition: eigensolver_strategy.hpp:69
int Check() override
Definition: eigensolver_strategy.hpp:488
TSparseSpace::MatrixPointerType SparseMatrixPointerType
Definition: eigensolver_strategy.hpp:77
void Clear() override
Definition: eigensolver_strategy.hpp:209
void SetIsInitialized(bool val)
Definition: eigensolver_strategy.hpp:144
BuilderAndSolverPointerType & pGetBuilderAndSolver()
Definition: eigensolver_strategy.hpp:169
bool SolveSolutionStep() override
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: eigensolver_strategy.hpp:379
TSparseSpace SparseSpaceType
Definition: eigensolver_strategy.hpp:73
SparseMatrixPointerType & pGetStiffnessMatrix()
Definition: eigensolver_strategy.hpp:201
void InitializeSolutionStep() override
Definition: eigensolver_strategy.hpp:299
void Initialize() override
Definition: eigensolver_strategy.hpp:236
TSparseSpace::VectorType SparseVectorType
Definition: eigensolver_strategy.hpp:81
SchemeType::Pointer & pGetScheme()
Definition: eigensolver_strategy.hpp:281
EigensolverStrategy(ModelPart &rModelPart, SchemePointerType pScheme, BuilderAndSolverPointerType pBuilderAndSolver, double MassMatrixDiagonalValue, double StiffnessMatrixDiagonalValue, bool ComputeModalDecomposition=false)
Constructor.
Definition: eigensolver_strategy.hpp:88
void SetScheme(SchemePointerType pScheme)
Definition: eigensolver_strategy.hpp:154
void SetReformDofSetAtEachStepFlag(bool flag)
Definition: eigensolver_strategy.hpp:210
void SetEchoLevel(const int Level) override
This sets the level of echo for the solution strategy.
Definition: eigensolver_strategy.hpp:269
EigensolverStrategy(const EigensolverStrategy &Other)=delete
Deleted copy constructor.
TDenseSpace::MatrixType DenseMatrixType
Definition: eigensolver_strategy.hpp:71
TSparseSpace::VectorPointerType SparseVectorPointerType
Definition: eigensolver_strategy.hpp:75
BaseType::TBuilderAndSolverType::Pointer BuilderAndSolverPointerType
Definition: eigensolver_strategy.hpp:67
void SetBuilderAndSolver(BuilderAndSolverPointerType pNewBuilderAndSolver)
Definition: eigensolver_strategy.hpp:164
SparseMatrixType & GetMassMatrix()
Definition: eigensolver_strategy.hpp:174
bool GetReformDofSetAtEachStepFlag() const
Definition: eigensolver_strategy.hpp:215
bool GetIsInitialized() const
Definition: eigensolver_strategy.hpp:149
~EigensolverStrategy() override
Destructor.
Definition: eigensolver_strategy.hpp:128
TSparseSpace::MatrixType SparseMatrixType
Definition: eigensolver_strategy.hpp:79
KRATOS_CLASS_POINTER_DEFINITION(EigensolverStrategy)
SchemePointerType & pGetScheme()
Definition: eigensolver_strategy.hpp:159
void FinalizeSolutionStep() override
Performs all the required operations that should be done (for each step) after solving the solution s...
Definition: eigensolver_strategy.hpp:464
std::size_t IndexType
Definition: flags.h:74
Implicit solving strategy base class This is the base class from which we will derive all the implici...
Definition: implicit_solving_strategy.h:61
void SetRebuildLevel(int Level) override
This sets the build level.
Definition: implicit_solving_strategy.h:207
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
SizeType NumberOfMasterSlaveConstraints(IndexType ThisIndex=0) const
Definition: model_part.h:649
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
std::vector< std::unique_ptr< Dof< double > >> DofsContainerType
The DoF container type definition.
Definition: node.h:92
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solution_strategy.hpp:243
virtual int Check()
Function to perform expensive checks.
Definition: solution_strategy.hpp:154
virtual void SetEchoLevel(const int Level)
This sets the level of echo for the solution strategy.
Definition: solution_strategy.hpp:190
virtual int GetEchoLevel()
This returns the level of echo for the solution strategy.
Definition: solution_strategy.hpp:206
static void Set(VectorType &rX, TDataType A)
rX = A
Definition: ublas_space.h:553
static void Resize(MatrixType &rA, SizeType m, SizeType n)
Definition: ublas_space.h:558
static IndexType Size1(MatrixType const &rM)
return number of rows of rM
Definition: ublas_space.h:197
static VectorPointerType CreateEmptyVectorPointer()
Definition: ublas_space.h:183
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_INFO(label)
Definition: logger.h:250
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
void FinalizeNonLinearIterationAllEntities(ModelPart &rModelPart)
This method calls FinalizeNonLinearIteration for all the entities (conditions, elements,...
Definition: entities_utilities.cpp:243
void InitializeNonLinearIterationAllEntities(ModelPart &rModelPart)
This method calls InitializeNonLinearIteration for all the entities (conditions, elements,...
Definition: entities_utilities.cpp:232
Vector VectorType
Definition: geometrical_transformation_utilities.h:56
Matrix MatrixType
Definition: geometrical_transformation_utilities.h:55
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void AtomicAdd(TDataType &target, const TDataType &value)
Definition: atomic_utilities.h:55
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
void block_for_each(TIterator itBegin, TIterator itEnd, TFunction &&rFunction)
Execute a functor on all items of a range in parallel.
Definition: parallel_utilities.h:299
std::shared_ptr< T > shared_ptr
Definition: smart_pointers.h:27
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
bool WriteMatrixMarketMatrix(const char *FileName, CompressedMatrixType &M, bool Symmetric)
Definition: matrix_market_interface.h:308
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
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