50 template<
class TSparseSpace,
54 class EigensolverStrategy
55 :
public ImplicitSolvingStrategy<TSparseSpace, TDenseSpace, TLinearSolver>
92 double MassMatrixDiagonalValue,
93 double StiffnessMatrixDiagonalValue,
94 bool ComputeModalDecomposition =
false
97 mMassMatrixDiagonalValue(MassMatrixDiagonalValue),
98 mStiffnessMatrixDiagonalValue(StiffnessMatrixDiagonalValue),
99 mComputeModalDecompostion(ComputeModalDecomposition)
105 mpBuilderAndSolver = pBuilderAndSolver;
108 mpBuilderAndSolver->SetDofSetIsInitializedFlag(
false);
146 mInitializeWasPerformed = val;
151 return mInitializeWasPerformed;
166 mpBuilderAndSolver = pNewBuilderAndSolver;
171 return mpBuilderAndSolver;
180 return *mpMassMatrix;
189 return *mpStiffnessMatrix;
207 return mpStiffnessMatrix;
243 <<
"Entering Initialize" << std::endl;
245 if (mInitializeWasPerformed ==
false)
249 if (pScheme->SchemeIsInitialized() ==
false)
250 pScheme->Initialize(rModelPart);
252 if (pScheme->ElementsAreInitialized() ==
false)
253 pScheme->InitializeElements(rModelPart);
255 if (pScheme->ConditionsAreInitialized() ==
false)
256 pScheme->InitializeConditions(rModelPart);
260 <<
"Exiting Initialize" << std::endl;
274 pBuilderAndSolver->GetLinearSystemSolver()->Clear();
283 pBuilderAndSolver->SetDofSetIsInitializedFlag(
false);
285 pBuilderAndSolver->Clear();
289 mInitializeWasPerformed =
false;
306 <<
"Entering InitializeSolutionStep" << std::endl;
309 SchemePointerType& pScheme = this->
pGetScheme();
321 if (pBuilderAndSolver->GetDofSetIsInitializedFlag() ==
false ||
322 pBuilderAndSolver->GetReshapeMatrixFlag() ==
true)
326 pBuilderAndSolver->SetUpDofSet(pScheme, rModelPart);
329 << setup_dofs_time << std::endl;
333 pBuilderAndSolver->SetUpSystem(rModelPart);
336 << setup_system_time << std::endl;
343 pBuilderAndSolver->ResizeAndInitializeVectors(
344 pScheme, pMassMatrix, pDx, pb, rModelPart);
347 pBuilderAndSolver->ResizeAndInitializeVectors(
348 pScheme, pStiffnessMatrix, pDx, pb, rModelPart);
351 << system_matrix_resize_time << std::endl;
362 << system_construction_time << std::endl;
367 rStiffnessMatrix, rDx, rb);
374 <<
"Exiting InitializeSolutionStep" << std::endl;
401 TSparseSpace::SetToZero(rMassMatrix);
406 if (master_slave_constraints_defined) {
409 if (matrix_contains_dirichlet_dofs) {
410 this->ApplyDirichletConditions(rMassMatrix, mMassMatrixDiagonalValue);
418 TSparseSpace::SetToZero(rStiffnessMatrix);
420 if (master_slave_constraints_defined) {
424 if (matrix_contains_dirichlet_dofs) {
425 this->ApplyDirichletConditions(rStiffnessMatrix, mStiffnessMatrixDiagonalValue);
447 << system_solve_time << std::endl;
449 if (master_slave_constraints_defined){
450 this->ReconstructSlaveSolution(Eigenvectors);
453 this->AssignVariables(Eigenvalues,Eigenvectors);
456 if (mComputeModalDecompostion) {
457 ComputeModalDecomposition(Eigenvectors);
469 <<
"Entering FinalizeSolutionStep" << std::endl;
477 rStiffnessMatrix, *pDx, *pb);
479 <<
"Exiting FinalizeSolutionStep" << std::endl;
495 <<
"Entering Check" << std::endl;
507 <<
"Exiting Check" << std::endl;
574 bool mInitializeWasPerformed =
false;
576 double mMassMatrixDiagonalValue = 0.0;
577 double mStiffnessMatrixDiagonalValue = 1.0;
579 bool mComputeModalDecompostion =
false;
596 void ReconstructSlaveSolution(
603 const std::size_t number_of_eigenvalues = rEigenvectors.size1();
608 Vector master_dofs_values;
611 for (std::size_t i_eigenvalue = 0; i_eigenvalue < number_of_eigenvalues; ++i_eigenvalue){
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);
622 block_for_each(r_model_part.MasterSlaveConstraints(), TLS(), [&i_eigenvalue, &rEigenvectors, &r_model_part](
const MasterSlaveConstraint& r_master_slave_constraint, TLS& rTLS){
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) {
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());
637 r_master_slave_constraint.GetLocalSystem(rTLS.relation_matrix, rTLS.constant_vector, r_model_part.GetProcessInfo());
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];
644 AtomicAdd(rEigenvectors(i_eigenvalue, r_slave_dofs_vector[
i]->EquationId()), aux);
659 void ApplyDirichletConditions(
660 SparseMatrixType& rA,
665 KRATOS_INFO_IF(
"EigensolverStrategy", BaseType::GetEchoLevel() > 2)
666 <<
"Entering ApplyDirichletConditions" << std::endl;
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());
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;
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());
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)
706 for (std::size_t
j = ColBegin;
j < ColEnd; ++
j)
708 if (AColIndices[
j] !=
k)
714 AValues[
j] *= Factor;
721 for (std::size_t
j = ColBegin;
j < ColEnd; ++
j)
723 AValues[
j] *= ScalingFactors[AColIndices[
j]];
728 KRATOS_INFO_IF(
"EigensolverStrategy", BaseType::GetEchoLevel() > 2)
729 <<
"Exiting ApplyDirichletConditions" << std::endl;
735 void AssignVariables(DenseVectorType& rEigenvalues, DenseMatrixType& rEigenvectors)
737 ModelPart& rModelPart = BaseType::GetModelPart();
738 const std::size_t NumEigenvalues = rEigenvalues.size();
741 rModelPart.GetProcessInfo()[EIGENVALUE_VECTOR] = rEigenvalues;
743 const auto& r_dof_set = this->pGetBuilderAndSolver()->GetDofSet();
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);
754 for (std::size_t
i = 0;
i < NumEigenvalues;
i++) {
755 for (std::size_t
j = 0;
j < NumNodeDofs;
j++)
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());
763 rNodeEigenvectors(
i,
j) = 0.0;
776 void ComputeModalDecomposition(
const DenseMatrixType& rEigenvectors)
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);
782 boost::numeric::ublas::axpy_prod(m_temp,
trans(rEigenvectors),modal_mass_matrix);
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);
788 boost::numeric::ublas::axpy_prod(k_temp,
trans(rEigenvectors),modal_stiffness_matrix);
790 ModelPart& rModelPart = BaseType::GetModelPart();
791 rModelPart.GetProcessInfo()[MODAL_MASS_MATRIX] = modal_mass_matrix;
792 rModelPart.GetProcessInfo()[MODAL_STIFFNESS_MATRIX] = modal_stiffness_matrix;
794 KRATOS_INFO(
"ModalMassMatrix") << modal_mass_matrix << std::endl;
795 KRATOS_INFO(
"ModalStiffnessMatrix") << modal_stiffness_matrix << std::endl;
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
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