19 #include <unordered_set>
22 #ifdef KRATOS_SMP_OPENMP
82 template <
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
165 const auto nelements =
static_cast<int>(rModelPart.
Elements().
size());
168 const auto nconditions =
static_cast<int>(rModelPart.
Conditions().size());
171 ModelPart::ElementsContainerType::iterator el_begin = rModelPart.
ElementsBegin();
172 ModelPart::ConditionsContainerType::iterator cond_begin = rModelPart.
ConditionsBegin();
190 #pragma omp parallel firstprivate(nelements, nconditions, lhs_contribution, mass_contribution, \
191 damping_contribution, rhs_contribution, equation_ids)
193 #pragma omp for schedule(guided, 512) nowait
194 for (
int k = 0;
k < nelements;
k++) {
195 auto it_elem = el_begin +
k;
197 if (it_elem->IsActive()) {
199 pScheme->CalculateSystemContributions(*it_elem, lhs_contribution, rhs_contribution,
200 equation_ids, r_current_process_info);
203 it_elem->CalculateMassMatrix(mass_contribution, r_current_process_info);
204 it_elem->CalculateDampingMatrix(damping_contribution, r_current_process_info);
206 if (mass_contribution.size1() != 0) {
209 if (damping_contribution.size1() != 0) {
218 #pragma omp for schedule(guided, 512)
219 for (
int k = 0;
k < nconditions;
k++) {
220 auto it_cond = cond_begin +
k;
222 if (it_cond->IsActive()) {
224 pScheme->CalculateSystemContributions(*it_cond, lhs_contribution, rhs_contribution,
225 equation_ids, r_current_process_info);
228 it_cond->CalculateMassMatrix(mass_contribution, r_current_process_info);
229 it_cond->CalculateDampingMatrix(damping_contribution, r_current_process_info);
231 if (mass_contribution.size1() != 0) {
234 if (damping_contribution.size1() != 0) {
245 <<
"Build time: " <<
timer.ElapsedSeconds() << std::endl;
247 KRATOS_INFO_IF(
"ResidualBasedBlockBuilderAndSolverWithMassAndDamping",
249 <<
"Finished parallel building" << std::endl;
274 Build(pScheme, rModelPart, rA, rb);
289 <<
"Constraints build time: " << timer_constraints.ElapsedSeconds() << std::endl;
297 <<
"Before the solution of the system"
298 <<
"\nSystem Matrix = " << rA <<
"\nUnknowns vector = " << rDx
299 <<
"\nRHS vector = " << rb << std::endl;
308 <<
"System solve time: " <<
timer.ElapsedSeconds() << std::endl;
311 <<
"After the solution of the system"
312 <<
"\nSystem Matrix = " << rA <<
"\nUnknowns vector = " << rDx
313 <<
"\nRHS vector = " << rb << std::endl;
346 <<
"Before the solution of the system"
347 <<
"\nSystem Matrix = " << rA <<
"\nUnknowns vector = " << rDx
348 <<
"\nRHS vector = " << rb << std::endl;
357 <<
"System solve time: " <<
timer.ElapsedSeconds() << std::endl;
360 <<
"After the solution of the system"
361 <<
"\nSystem Matrix = " << rA <<
"\nUnknowns vector = " << rDx
362 <<
"\nRHS vector = " << rb << std::endl;
384 const std::size_t i = r_dof.EquationId();
402 "name" : "block_builder_and_solver_with_mass_and_damping",
403 "block_builder" : true,
404 "diagonal_values_for_dirichlet_dofs" : "use_max_diagonal",
405 "silent_warnings" : false
411 return default_parameters;
418 static std::string
Name() {
return "block_builder_and_solver_with_mass_and_damping"; }
433 std::string
Info()
const override
435 return "ResidualBasedBlockBuilderAndSolverWithMassAndDamping";
465 if (rNode.IsActive()) {
466 GetDerivativesForVariable(DISPLACEMENT_X, rNode, rFirstDerivativeVector, rSecondDerivativeVector);
467 GetDerivativesForVariable(DISPLACEMENT_Y, rNode, rFirstDerivativeVector, rSecondDerivativeVector);
469 const std::vector<const Variable<double>*> optional_variables = {
470 &ROTATION_X, &ROTATION_Y, &ROTATION_Z, &DISPLACEMENT_Z};
472 for (const auto p_variable : optional_variables) {
473 GetDerivativesForOptionalVariable(*p_variable, rNode, rFirstDerivativeVector,
474 rSecondDerivativeVector);
486 GetDerivativesForVariable(rVariable, rNode, rFirstDerivativeVector, rSecondDerivativeVector);
524 const int nelements =
static_cast<int>(r_elements.size());
525 #pragma omp parallel firstprivate(nelements, rhs_contribution, equation_ids)
527 #pragma omp for schedule(guided, 512) nowait
528 for (
int i = 0;
i < nelements;
i++) {
529 typename ElementsArrayType::iterator it = r_elements.begin() +
i;
531 if (it->IsActive()) {
533 it->CalculateRightHandSide(rhs_contribution, r_current_process_info);
534 it->EquationIdVector(equation_ids, r_current_process_info);
537 BaseType::AssembleRHS(rb, rhs_contribution, equation_ids);
541 rhs_contribution.resize(0,
false);
544 const int nconditions =
static_cast<int>(r_conditions.size());
545 #pragma omp for schedule(guided, 512)
546 for (
int i = 0;
i < nconditions;
i++) {
547 auto it = r_conditions.begin() +
i;
549 if (it->IsActive()) {
550 it->CalculateRightHandSide(rhs_contribution, r_current_process_info);
551 it->EquationIdVector(equation_ids, r_current_process_info);
554 BaseType::AssembleRHS(rb, rhs_contribution, equation_ids);
559 AddMassAndDampingToRhs(rModelPart, rb);
565 TSystemMatrixType mMassMatrix;
566 TSystemMatrixType mDampingMatrix;
568 void InitializeDynamicMatrix(TSystemMatrixType& rMatrix,
569 unsigned int MatrixSize,
570 typename TSchemeType::Pointer pScheme,
573 rMatrix.resize(MatrixSize, MatrixSize,
false);
574 BaseType::ConstructMatrixStructure(pScheme, rMatrix, rModelPart);
575 TSparseSpace::SetToZero(rMatrix);
578 void CalculateAndAddDynamicContributionToRhs(TSystemVectorType& rSolutionVector,
579 TSystemMatrixType& rGlobalMatrix,
580 TSystemVectorType& rb)
582 TSystemVectorType contribution;
583 contribution.resize(BaseType::mEquationSystemSize,
false);
584 TSparseSpace::SetToZero(contribution);
598 void AddMassAndDampingToRhs(ModelPart& rModelPart, TSystemVectorType& rb)
601 TSystemVectorType first_derivative_vector =
ZeroVector(BaseType::mEquationSystemSize);
602 TSystemVectorType second_derivative_vector =
ZeroVector(BaseType::mEquationSystemSize);
603 GetFirstAndSecondDerivativeVector(first_derivative_vector, second_derivative_vector, rModelPart);
606 CalculateAndAddDynamicContributionToRhs(second_derivative_vector, mMassMatrix, rb);
607 CalculateAndAddDynamicContributionToRhs(first_derivative_vector, mDampingMatrix, rb);
618 template <
class TSparseSpace,
class TDenseSpace,
class TLinearSolver>
619 const Kratos::Flags ResidualBasedBlockBuilderAndSolverWithMassAndDamping<TSparseSpace, TDenseSpace, TLinearSolver>::SILENT_WARNINGS(
Current class provides an implementation for the base builder and solving operations.
Definition: builder_and_solver.h:64
TSparseSpace::VectorType TSystemVectorType
Definition of the vector size.
Definition: builder_and_solver.h:85
ModelPart::NodesContainerType NodesArrayType
The containers of the entities.
Definition: builder_and_solver.h:109
TSparseSpace::MatrixType TSystemMatrixType
Definition of the sparse matrix.
Definition: builder_and_solver.h:82
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: builder_and_solver.h:111
virtual Parameters ValidateAndAssignParameters(Parameters ThisParameters, const Parameters DefaultParameters) const
This method validate and assign default parameters.
Definition: builder_and_solver.h:767
TDenseSpace::MatrixType LocalSystemMatrixType
The local matrix definition.
Definition: builder_and_solver.h:94
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
int GetEchoLevel() const
It returns the echo level.
Definition: builder_and_solver.h:674
unsigned int mEquationSystemSize
Flag taking in account if it is needed or not to calculate the reactions.
Definition: builder_and_solver.h:747
ModelPart::ElementsContainerType ElementsArrayType
Definition: builder_and_solver.h:110
Definition: builtin_timer.h:26
virtual int MyPID() const
Definition: communicator.cpp:91
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
bool IsFixed() const
Definition: dof.h:376
EquationIdType EquationId() const
Definition: dof.h:324
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
static Flags Create(IndexType ThisPosition, bool Value=true)
Definition: flags.h:138
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
MasterSlaveConstraintContainerType & MasterSlaveConstraints(IndexType ThisIndex=0)
Definition: model_part.h:654
ConditionIterator ConditionsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1361
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
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
const DofType & GetDof(TVariableType const &rDofVariable, int pos) const
Get dof with a given position. If not found it is search.
Definition: node.h:649
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
bool HasDofFor(const VariableData &rDofVariable) const
Definition: node.h:887
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
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
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
size_type size() const
Returns the number of elements in the container.
Definition: pointer_vector_set.h:502
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
Current class provides an implementation for standard builder and solving operations.
Definition: residualbased_block_builder_and_solver.h:82
BaseType::TSystemVectorType TSystemVectorType
Definition: residualbased_block_builder_and_solver.h:108
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: residualbased_block_builder_and_solver.h:940
BaseType::ElementsArrayType ElementsArrayType
Definition: residualbased_block_builder_and_solver.h:114
virtual 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: residualbased_block_builder_and_solver.h:408
void AssignSettings(const Parameters ThisParameters) override
This method assigns settings to member variables.
Definition: residualbased_block_builder_and_solver.h:1666
Element::EquationIdVectorType EquationIdVectorType
Definition: residualbased_block_builder_and_solver.h:119
BaseType::TSystemMatrixType TSystemMatrixType
Definition: residualbased_block_builder_and_solver.h:107
void AssembleLHS(TSystemMatrixType &rA, const LocalSystemMatrixType &rLHSContribution, Element::EquationIdVectorType &rEquationId)
Definition: residualbased_block_builder_and_solver.h:1589
BaseType::ConditionsArrayType ConditionsArrayType
Definition: residualbased_block_builder_and_solver.h:115
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: residualbased_block_builder_and_solver.h:109
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_block_builder_and_solver.h:1111
void ApplyConstraints(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb) override
Applies the constraints with master-slave relation matrix.
Definition: residualbased_block_builder_and_solver.h:1035
void Assemble(TSystemMatrixType &A, TSystemVectorType &b, const LocalSystemMatrixType &LHS_Contribution, const LocalSystemVectorType &RHS_Contribution, Element::EquationIdVectorType &EquationId)
Definition: residualbased_block_builder_and_solver.h:1566
BaseType::NodesArrayType NodesArrayType
Definition: residualbased_block_builder_and_solver.h:113
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: residualbased_block_builder_and_solver.h:110
void ApplyRHSConstraints(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &rb) override
Applies the constraints with master-slave relation matrix (RHS only)
Definition: residualbased_block_builder_and_solver.h:997
BaseType::TSchemeType TSchemeType
Definition of the classes from the base class.
Definition: residualbased_block_builder_and_solver.h:104
Current class provides an implementation for builder and solving operations, while the global mass an...
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:85
ResidualBasedBlockBuilderAndSolverWithMassAndDamping()=default
Default constructor.
void BuildRHSNoDirichlet(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &rb)
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:503
ResidualBasedBlockBuilderAndSolverWithMassAndDamping(typename TLinearSolver::Pointer pNewLinearSystemSolver, Parameters ThisParameters)
Constructor. (with parameters)
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:125
void GetDerivativesForVariable(const Variable< double > &rVariable, const Node &rNode, TSystemVectorType &rFirstDerivativeVector, TSystemVectorType &rSecondDerivativeVector) const
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:490
void BuildRHS(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemVectorType &rb) override
Function to perform the build of the RHS.
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:373
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: residualbased_block_builder_and_solver_with_mass_and_damping.h:264
Parameters GetDefaultParameters() const override
This method provides the defaults parameters to avoid conflicts between the different constructors.
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:398
void GetFirstAndSecondDerivativeVector(TSystemVectorType &rFirstDerivativeVector, TSystemVectorType &rSecondDerivativeVector, ModelPart &rModelPart)
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:460
void GetDerivativesForOptionalVariable(const Variable< double > &rVariable, const Node &rNode, TSystemVectorType &rFirstDerivativeVector, TSystemVectorType &rSecondDerivativeVector) const
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:480
KRATOS_CLASS_POINTER_DEFINITION(ResidualBasedBlockBuilderAndSolverWithMassAndDamping)
Definition of the pointer.
static std::string Name()
Returns the name of the class as used in the settings (snake_case format)
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:418
~ResidualBasedBlockBuilderAndSolverWithMassAndDamping() override=default
KRATOS_DEFINE_LOCAL_FLAG(SILENT_WARNINGS)
Definition of the flags.
std::string Info() const override
Turn back information as a string.
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:433
void Build(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rb) override
Function to perform the build of the RHS. The vector could be sized as the total number of dofs or as...
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:158
void BuildRHSAndSolve(typename TSchemeType::Pointer pScheme, ModelPart &rModelPart, TSystemMatrixType &rA, TSystemVectorType &rDx, TSystemVectorType &rb) override
Corresponds to the previews, but the System's matrix is considered already built and only the RHS is ...
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:327
ResidualBasedBlockBuilderAndSolverWithMassAndDamping(typename TLinearSolver::Pointer pNewLinearSystemSolver)
Constructor.
Definition: residualbased_block_builder_and_solver_with_mass_and_damping.h:137
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
static void Start(std::string const &rIntervalName)
This method starts the timer meassures.
Definition: timer.cpp:109
static void Stop(std::string const &rIntervalName)
This method stops the timer meassures.
Definition: timer.cpp:125
const VariableType & GetTimeDerivative() const
This method returns the time derivative variable.
Definition: variable.h:336
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_INFO_IF(label, conditional)
Definition: logger.h:251
void Mult(TSpaceType &dummy, typename TSpaceType::MatrixType &rA, typename TSpaceType::VectorType &rX, typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:98
void UnaliasedAdd(TSpaceType &dummy, typename TSpaceType::VectorType &x, const double A, const typename TSpaceType::VectorType &rY)
Definition: add_strategies_to_python.cpp:170
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
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
int k
Definition: quadrature.py:595
integer i
Definition: TensorModule.f:17