10 #if !defined(KRATOS_EIGENSOLVER_STRATEGY_H_INCLUDED)
11 #define KRATOS_EIGENSOLVER_STRATEGY_H_INCLUDED
46 template<
class TSparseSpace,
87 typename SchemeType::Pointer pScheme,
88 typename BuilderAndSolverType::Pointer pBuilderAndSolver,
90 bool ComputeModalContribution =
false)
91 :
SolutionStrategy<TSparseSpace, TDenseSpace, TLinearSolver>(rModelPart, rOptions)
97 mpBuilderAndSolver = pBuilderAndSolver;
100 mComputeModalContribution = ComputeModalContribution;
102 mpMassMatrix = Kratos::make_shared<SparseMatrixType>(0,0);
103 mpStiffnessMatrix = Kratos::make_shared<SparseMatrixType>(0,0);
105 mpBuilderAndSolver->SetEchoLevel(this->
mEchoLevel);
138 if(this->
IsNot(LocalFlagType::INITIALIZED))
145 this->SetSystemDofs();
148 this->SetSystemMatrices(pDx,pb);
151 mpBuilderAndSolver->InitializeSolutionStep(mpScheme,
BaseType::GetModelPart(), mpStiffnessMatrix, pDx, pb);
175 TSparseSpace::SetToZero((*mpMassMatrix));
176 mpBuilderAndSolver->Build(mpScheme,this->
GetModelPart(),(*mpMassMatrix),(*pb));
177 this->ApplyDirichletConditions((*mpMassMatrix), 1.0);
182 TSparseSpace::SetToZero((*mpStiffnessMatrix));
183 mpBuilderAndSolver->Build(mpScheme,this->
GetModelPart(),(*mpStiffnessMatrix),(*pb));
184 ApplyDirichletConditions((*mpStiffnessMatrix), -1.0);
191 mpBuilderAndSolver->GetLinearSystemSolver()->Solve((*mpStiffnessMatrix),
196 this->AssignVariables(Eigenvalues,Eigenvectors);
198 if( mComputeModalContribution ==
true )
199 this->ComputeModalContribution((*mpMassMatrix),Eigenvalues,Eigenvectors);
214 mpBuilderAndSolver->GetLinearSystemSolver()->Clear();
226 mpBuilderAndSolver->Clear();
272 mpBuilderAndSolver->SetEchoLevel(Level);
288 mpBuilderAndSolver = pBuilderAndSolver;
293 return mpBuilderAndSolver;
298 return *mpMassMatrix;
303 return *mpStiffnessMatrix;
313 return mpStiffnessMatrix;
350 if(mpScheme->IsNot(LocalFlagType::INITIALIZED))
354 this->SetSystemDofs();
356 this->
Set(LocalFlagType::INITIALIZED,
true);
383 typename SchemeType::Pointer mpScheme;
385 typename BuilderAndSolverType::Pointer mpBuilderAndSolver;
391 bool mComputeModalContribution;
409 mpBuilderAndSolver->SetUpSystemMatrices(mpScheme, this->
GetModelPart(), mpMassMatrix, pDx, pb);
412 mpBuilderAndSolver->SetUpSystemMatrices(mpScheme, this->
GetModelPart(), mpStiffnessMatrix, pDx, pb);
425 KRATOS_INFO(
" Reform Dofs ") <<
" Flag = " <<this->
mOptions.
Is(LocalFlagType::REFORM_DOFS) << std::endl;
431 mpBuilderAndSolver->SetUpDofSet(mpScheme, this->
GetModelPart());
438 mpBuilderAndSolver->SetUpSystem();
456 const std::size_t SystemSize = rA.size1();
457 std::vector<double> ScalingFactors(SystemSize);
459 const int NumDofs =
static_cast<int>(rDofSet.size());
462 #pragma omp parallel for firstprivate(NumDofs)
463 for(
int k = 0;
k<NumDofs;
k++)
465 auto dof_iterator = std::begin(rDofSet) +
k;
466 ScalingFactors[
k] = (dof_iterator->IsFixed()) ? 0.0 : 1.0;
469 double* AValues = std::begin(rA.value_data());
470 std::size_t* ARowIndices = std::begin(rA.index1_data());
471 std::size_t* AColIndices = std::begin(rA.index2_data());
490 #pragma omp parallel for
491 for (
int k = 0; k < static_cast<int>(SystemSize); ++
k)
493 std::size_t ColBegin = ARowIndices[
k];
494 std::size_t ColEnd = ARowIndices[
k+1];
495 if(ScalingFactors[
k] == 0.0)
498 for (std::size_t
j = ColBegin;
j < ColEnd; ++
j)
500 if(
static_cast<int>(AColIndices[
j]) !=
k)
506 AValues[
j] *= Factor;
513 for (std::size_t
j = ColBegin;
j < ColEnd; ++
j)
515 AValues[
j] *= ScalingFactors[AColIndices[
j]];
528 const std::size_t NumEigenvalues = rEigenvalues.size();
536 const std::size_t NumNodeDofs = NodeDofs.size();
537 Matrix& rNodeEigenvectors = itNode->GetValue(EIGENVECTOR_MATRIX);
538 if(rNodeEigenvectors.size1() != NumEigenvalues || rNodeEigenvectors.size2() != NumNodeDofs)
540 rNodeEigenvectors.
resize(NumEigenvalues,NumNodeDofs,
false);
551 for (std::size_t
i = 0;
i < NumEigenvalues;
i++)
552 for (std::size_t
j = 0;
j < NumNodeDofs;
j++)
554 auto itDof = std::begin(NodeDofs) +
j;
555 rNodeEigenvectors(
i,
j) = rEigenvectors(
i,(*itDof)->EquationId());
568 const auto num_eigen_values = rEigenValues.size();
569 const auto system_size = rMassMatrix.size1();
570 Matrix mass(num_eigen_values,num_eigen_values);
572 Vector mode_contribution(num_eigen_values);
574 Vector ratio_mass_mode_contribution(num_eigen_values);
576 Matrix eigen_contribution(num_eigen_values, system_size);
579 double total_mass= 0.0;
580 for (std::size_t
i = 0;
i < system_size;
i++)
582 for (std::size_t
j = 0;
j < system_size;
j++)
584 total_mass += rMassMatrix(
i,
j);
588 noalias(eigen_contribution) =
prod(rEigenVectors,rMassMatrix);
590 double total_mass_contribution =0.0;
592 for (std::size_t
i = 0;
i < num_eigen_values;
i++)
594 for (std::size_t
j = 0;
j < system_size;
j++)
596 mode_contribution[
i] += eigen_contribution(
i,
j);
599 ratio_mass_mode_contribution[
i] = (mode_contribution[
i]*mode_contribution[
i])/(mass(
i,
i)*total_mass)*100.0;
600 total_mass_contribution += ratio_mass_mode_contribution[
i];
Strategy for solving generalized eigenvalue problems.
Definition: eigensolver_strategy.hpp:52
BaseType::LocalFlagType LocalFlagType
Definition: eigensolver_strategy.hpp:61
SparseMatrixPointerType & pGetMassMatrix()
Definition: eigensolver_strategy.hpp:306
BuilderAndSolverType::Pointer & pGetBuilderAndSolver()
Definition: eigensolver_strategy.hpp:291
SparseMatrixType & GetStiffnessMatrix()
Definition: eigensolver_strategy.hpp:301
TDenseSpace::VectorType DenseVectorType
Definition: eigensolver_strategy.hpp:67
int Check() override
Definition: eigensolver_strategy.hpp:237
TSparseSpace::MatrixPointerType SparseMatrixPointerType
Definition: eigensolver_strategy.hpp:75
void Clear() override
Definition: eigensolver_strategy.hpp:209
bool SolveSolutionStep() override
Solves the current step. This function returns true if a solution has been found, false otherwise.
Definition: eigensolver_strategy.hpp:163
TSparseSpace SparseSpaceType
Definition: eigensolver_strategy.hpp:71
SparseMatrixPointerType & pGetStiffnessMatrix()
Definition: eigensolver_strategy.hpp:311
BaseType::SchemeType SchemeType
Definition: eigensolver_strategy.hpp:65
void InitializeSolutionStep() override
Definition: eigensolver_strategy.hpp:134
void Initialize() override
Definition: eigensolver_strategy.hpp:345
TSparseSpace::VectorType SparseVectorType
Definition: eigensolver_strategy.hpp:79
SchemeType::Pointer & pGetScheme()
Definition: eigensolver_strategy.hpp:281
void SetEchoLevel(const int Level) override
This sets the level of echo for the solution strategy.
Definition: eigensolver_strategy.hpp:269
void SetBuilderAndSolver(typename BuilderAndSolverType::Pointer pBuilderAndSolver)
Definition: eigensolver_strategy.hpp:286
EigensolverStrategy(const EigensolverStrategy &Other)=delete
Deleted copy constructor.
SolutionStrategy< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: eigensolver_strategy.hpp:59
TDenseSpace::MatrixType DenseMatrixType
Definition: eigensolver_strategy.hpp:69
void SetScheme(typename SchemeType::Pointer pScheme)
Definition: eigensolver_strategy.hpp:276
TSparseSpace::VectorPointerType SparseVectorPointerType
Definition: eigensolver_strategy.hpp:73
SparseMatrixType & GetMassMatrix()
Definition: eigensolver_strategy.hpp:296
BaseType::BuilderAndSolverType BuilderAndSolverType
Definition: eigensolver_strategy.hpp:63
EigensolverStrategy(ModelPart &rModelPart, typename SchemeType::Pointer pScheme, typename BuilderAndSolverType::Pointer pBuilderAndSolver, Flags &rOptions, bool ComputeModalContribution=false)
Constructor.
Definition: eigensolver_strategy.hpp:86
~EigensolverStrategy() override
Destructor.
Definition: eigensolver_strategy.hpp:114
TSparseSpace::MatrixType SparseMatrixType
Definition: eigensolver_strategy.hpp:77
KRATOS_CLASS_POINTER_DEFINITION(EigensolverStrategy)
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
bool Is(Flags const &rOther) const
Definition: flags.h:274
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
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
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
std::vector< std::unique_ptr< Dof< double > >> DofsContainerType
The DoF container type definition.
Definition: node.h:92
Solution strategy base class.
Definition: solution_strategy.hpp:52
SolverLocalFlags LocalFlagType
Definition: solution_strategy.hpp:57
SolutionScheme< TSparseSpace, TDenseSpace > SchemeType
Definition: solution_strategy.hpp:65
ModelPart & GetModelPart()
Operations to get the pointer to the model.
Definition: solution_strategy.hpp:243
Flags mOptions
Definition: solution_strategy.hpp:267
virtual int Check()
Function to perform expensive checks.
Definition: solution_strategy.hpp:154
SolutionBuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BuilderAndSolverType
Definition: solution_strategy.hpp:66
virtual void SetEchoLevel(const int Level)
This sets the level of echo for the solution strategy.
Definition: solution_strategy.hpp:190
int mEchoLevel
Definition: solution_strategy.hpp:270
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
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
Internals::Matrix< double, AMatrix::dynamic, 1 > Vector
Definition: amatrix_interface.h:472
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17