8 #if !defined(KRATOS_EXPLICIT_HAMILTON_BUILDER_AND_SOLVER )
9 #define KRATOS_EXPLICIT_HAMILTON_BUILDER_AND_SOLVER
50 template<
class TSparseSpace,
104 typename TLinearSolver::Pointer pNewLinearSystemSolver)
105 :
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver >(pNewLinearSystemSolver)
127 typename TSchemeType::Pointer pScheme,
139 int number_of_threads = omp_get_max_threads();
141 int number_of_threads = 1;
144 vector<unsigned int> node_partition;
145 OpenMPUtils::CreatePartition(number_of_threads, pNodes.size(), node_partition);
147 vector<unsigned int> element_partition;
148 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
156 for(
int k=0;
k<number_of_threads;
k++)
158 typename NodesArrayType::iterator i_begin=pNodes.ptr_begin()+node_partition[
k];
159 typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[
k+1];
163 double& nodal_mass =
i->FastGetSolutionStepValue(NODAL_MASS);
164 Matrix& nodal_inertia_dyadic =
i->FastGetSolutionStepValue(INERTIA_DYADIC);
175 unsigned int index = 0;
180 typename ElementsArrayType::iterator ElemBegin = pElements.begin() + element_partition[
k];
181 typename ElementsArrayType::iterator ElemEnd = pElements.begin() + element_partition[
k + 1];
183 for (
typename ElementsArrayType::iterator itElem = ElemBegin; itElem != ElemEnd; itElem++)
189 (itElem)->CalculateMassMatrix(MassMatrix, rCurrentProcessInfo);
194 for (
unsigned int i = 0;
i <geometry.
size();
i++)
198 double& mass = geometry(
i)->FastGetSolutionStepValue(NODAL_MASS);
199 Matrix& nodal_inertia_dyadic = geometry(
i)->FastGetSolutionStepValue(INERTIA_DYADIC);
201 geometry(
i)->SetLock();
203 mass += MassMatrix(index,index);
211 geometry(
i)->UnSetLock();
223 for(
int k=0;
k<number_of_threads;
k++)
225 typename NodesArrayType::iterator i_begin=pNodes.
ptr_begin()+node_partition[
k];
226 typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[
k+1];
230 double& nodal_mass =
i->FastGetSolutionStepValue(NODAL_MASS);
231 Matrix& nodal_inertia_dyadic =
i->FastGetSolutionStepValue(INERTIA_DYADIC);
236 nodal_inertia_dyadic /= nodal_mass;
253 typename TSchemeType::Pointer pScheme,
266 int number_of_threads = omp_get_max_threads();
268 int number_of_threads = 1;
271 vector<unsigned int> node_partition;
272 OpenMPUtils::CreatePartition(number_of_threads, pNodes.size(), node_partition);
279 for(
int k=0;
k<number_of_threads;
k++)
281 typename NodesArrayType::iterator i_begin=pNodes.ptr_begin()+node_partition[
k];
282 typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[
k+1];
286 (
i)->FastGetSolutionStepValue(FORCE_RESIDUAL).clear();
287 (
i)->FastGetSolutionStepValue(MOMENT_RESIDUAL).clear();
307 typename TSchemeType::Pointer pScheme,
321 double DeltaTime = rCurrentProcessInfo[DELTA_TIME];
322 double Alpha = rCurrentProcessInfo[ALPHA_TRAPEZOIDAL_RULE];
325 int number_of_threads = omp_get_max_threads();
327 int number_of_threads = 1;
330 vector<unsigned int> node_partition;
331 OpenMPUtils::CreatePartition(number_of_threads, pNodes.size(), node_partition);
334 this->
Build(pScheme, r_model_part,
A,
b);
341 for(
int k=0;
k<number_of_threads;
k++)
343 typename NodesArrayType::iterator i_begin=pNodes.ptr_begin()+node_partition[
k];
344 typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[
k+1];
349 bool node_is_active =
true;
350 if( (
i)->IsDefined(ACTIVE) )
351 node_is_active = (
i)->Is(ACTIVE);
372 double tolerance = 1
e-12;
378 for(
unsigned int j=0;
j<3;
j++)
381 ReferenceResidual[
j] =
Y[
j];
400 double determinant = 0;
402 for(
unsigned int j=0;
j<3;
j++)
404 CurrentStepRotation[
j] = Rotation[
j];
408 while (
residual > tolerance && iter < max_iters )
413 this->
Build(*
i.base(), pScheme, r_model_part,
A,
b);
422 Matrix& LyapunovTangent =
i->FastGetSolutionStepValue(TANGENT_LYAPUNOV);
427 for(
unsigned int j=0;
j<3;
j++)
429 Residual[
j] = ReferenceResidual[
j] - LyapunovResidual[
j];
435 Rotation +=
prod( InverseTangent, Residual );
439 if( (
i->pGetDof(ROTATION_X))->IsFree() )
440 CurrentStepRotation[0] = Rotation[0];
441 if( (
i->pGetDof(ROTATION_Y))->IsFree() )
442 CurrentStepRotation[1] = Rotation[1];
443 if( (
i->pGetDof(ROTATION_Z))->IsFree() )
444 CurrentStepRotation[2] = Rotation[2];
448 bool update_rotations =
false;
450 if( update_rotations ){
456 for(
unsigned int j=0;
j<3;
j++)
458 CurrentRotationVector[
j] = PreviousRotation[
j];
463 QuaternionType CurrentRotationQuaternion = StepRotationQuaternion * ReferenceRotationQuaternion;
469 for(
unsigned int j=0;
j<3;
j++)
471 CurrentRotation[
j] = CurrentRotationVector[
j];
480 std::cout<<
" ("<<iter<<
") : Rotation "<<CurrentStepRotation<<
" Residual norm: "<<
residual<<std::endl;
489 if( iter >= max_iters ){
490 std::cout<<
" Node ["<<
i->Id()<<
"] : LYAPUNOV ROTATION EQUATION NOT CONVERGED, iters:"<<iter<<
", residual: "<<
residual<<
" STEP_ROTATION:"<<Rotation<<std::endl;
494 std::cout<<
" Node ["<<
i->Id()<<
"] (STEP_ROTATION:"<<Rotation<<
") iters: "<<iter<<
" residual "<<
residual<<std::endl;
514 typename TSchemeType::Pointer pScheme,
525 array_1d<double,3>& LyapunovResidual = (pNode)->FastGetSolutionStepValue(RESIDUAL_LYAPUNOV);
526 Matrix& LyapunovTangent = (pNode)->FastGetSolutionStepValue(TANGENT_LYAPUNOV);
528 LyapunovResidual.
clear();
544 for(
auto i_nelem(nElements.
begin()); i_nelem != nElements.
end(); ++i_nelem)
547 pScheme->CalculateSystemContributions(*i_nelem.base(), LHS_Contribution, RHS_Contribution, EquationId, rCurrentProcessInfo);
561 typename TSchemeType::Pointer pScheme,
582 int number_of_threads = omp_get_max_threads();
584 int number_of_threads = 1;
587 vector<unsigned int> node_partition;
588 OpenMPUtils::CreatePartition(number_of_threads, pNodes.size(), node_partition);
595 for(
int k=0;
k<number_of_threads;
k++)
597 typename NodesArrayType::iterator i_begin=pNodes.ptr_begin()+node_partition[
k];
598 typename NodesArrayType::iterator i_end=pNodes.ptr_begin()+node_partition[
k+1];
603 Matrix& LyapunovTangent =
i->FastGetSolutionStepValue(TANGENT_LYAPUNOV);
605 LyapunovResidual.
clear();
613 bool compute_everything =
false;
614 if( compute_everything ){
624 for (
typename ElementsArrayType::ptr_iterator it = pElements.ptr_begin(); it != pElements.ptr_end(); ++it)
627 pScheme->CalculateSystemContributions(*it, LHS_Contribution, RHS_Contribution, EquationId, rCurrentProcessInfo);
630 LHS_Contribution.resize(0, 0,
false);
631 RHS_Contribution.resize(0,
false);
634 for (
typename ConditionsArrayType::ptr_iterator it = pConditions.ptr_begin(); it != pConditions.ptr_end(); ++it)
637 pScheme->Condition_CalculateSystemContributions(*it, LHS_Contribution, RHS_Contribution, EquationId, rCurrentProcessInfo);
660 int number_of_threads = omp_get_max_threads();
662 int number_of_threads = 1;
665 vector<unsigned int> condition_partition;
666 OpenMPUtils::CreatePartition(number_of_threads, pConditions.size(), condition_partition);
669 #pragma omp parallel for
670 for(
int k=0;
k<number_of_threads;
k++)
672 typename ConditionsArrayType::ptr_iterator it_begin=pConditions.ptr_begin()+condition_partition[
k];
673 typename ConditionsArrayType::ptr_iterator it_end=pConditions.ptr_begin()+condition_partition[
k+1];
675 for (
typename ConditionsArrayType::ptr_iterator it= it_begin; it!=it_end; ++it)
683 bool condition_is_active =
true;
684 if( (*it)->IsDefined(ACTIVE) )
685 condition_is_active = (*it)->Is(ACTIVE);
687 if(condition_is_active)
689 pScheme->Condition_Calculate_RHS_Contribution(*it, RHS_Condition_Contribution, EquationId, rCurrentProcessInfo);
713 int number_of_threads = omp_get_max_threads();
715 int number_of_threads = 1;
718 vector<unsigned int> element_partition;
719 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
721 #pragma omp parallel for
722 for(
int k=0;
k<number_of_threads;
k++)
724 typename ElementsArrayType::ptr_iterator it_begin=pElements.ptr_begin()+element_partition[
k];
725 typename ElementsArrayType::ptr_iterator it_end=pElements.ptr_begin()+element_partition[
k+1];
726 for (
typename ElementsArrayType::ptr_iterator it= it_begin; it!=it_end; ++it)
733 bool element_is_active =
true;
734 if( (*it)->IsDefined(ACTIVE) )
735 element_is_active = (*it)->Is(ACTIVE);
737 if(element_is_active)
739 pScheme->Calculate_RHS_Contribution(*it, RHS_Contribution, EquationId, rCurrentProcessInfo);
780 typename TSchemeType::Pointer pScheme,
792 typename TSchemeType::Pointer pScheme,
814 std::cout <<
"ExplicitHamiltonBuilderAndSolver Clear Function called" << std::endl;
Definition: beam_math_utilities.hpp:31
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
TSystemVectorPointerType mpReactionsVector
Definition: builder_and_solver.h:751
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
TSparseSpace::DataType TDataType
Definition of the data type.
Definition: builder_and_solver.h:79
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
int GetEchoLevel() const
It returns the echo level.
Definition: builder_and_solver.h:674
ModelPart::ElementsContainerType ElementsArrayType
Definition: builder_and_solver.h:110
std::vector< std::size_t > EquationIdVectorType
Definition: element.h:98
Definition: explicit_hamilton_builder_and_solver.hpp:55
BaseType::TSystemVectorPointerType TSystemVectorPointerType
Definition: explicit_hamilton_builder_and_solver.hpp:80
virtual int Check(ModelPart &r_model_part)
Definition: explicit_hamilton_builder_and_solver.hpp:825
void ApplyPointLoads(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemVectorType &b)
Definition: explicit_hamilton_builder_and_solver.hpp:791
BaseType::NodesArrayType NodesArrayType
Definition: explicit_hamilton_builder_and_solver.hpp:82
void FinalizeSolutionStep(ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
It applies certain operations at the system of equations at the end of the solution step.
Definition: explicit_hamilton_builder_and_solver.hpp:766
void Build(Node::Pointer pNode, typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &b)
Definition: explicit_hamilton_builder_and_solver.hpp:512
void Build(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &b)
equivalent (but generally faster) then performing BuildLHS and BuildRHS
Definition: explicit_hamilton_builder_and_solver.hpp:560
void BuildRHS(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemVectorType &b)
Function to perform the build of the RHS. The vector could be sized as the total number of dofs or as...
Definition: explicit_hamilton_builder_and_solver.hpp:252
BaseType::ElementsContainerType ElementsContainerType
Definition: explicit_hamilton_builder_and_solver.hpp:88
BaseType::LocalSystemVectorType LocalSystemVectorType
Definition: explicit_hamilton_builder_and_solver.hpp:74
ExplicitHamiltonBuilderAndSolver(typename TLinearSolver::Pointer pNewLinearSystemSolver)
Definition: explicit_hamilton_builder_and_solver.hpp:103
BaseType::TSystemMatrixPointerType TSystemMatrixPointerType
Definition: explicit_hamilton_builder_and_solver.hpp:78
BaseType::DofsArrayType DofsArrayType
Definition: explicit_hamilton_builder_and_solver.hpp:68
void BuildAndSolve(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
Function to perform the building and solving phase at the same time.
Definition: explicit_hamilton_builder_and_solver.hpp:306
void CalculateAndAddConditionsRHS(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part)
Definition: explicit_hamilton_builder_and_solver.hpp:651
BaseType::TSystemMatrixType TSystemMatrixType
Definition: explicit_hamilton_builder_and_solver.hpp:70
BaseType::TSchemeType TSchemeType
Definition: explicit_hamilton_builder_and_solver.hpp:64
void CalculateAndAddElementsRHS(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part)
Definition: explicit_hamilton_builder_and_solver.hpp:704
KRATOS_CLASS_POINTER_DEFINITION(ExplicitHamiltonBuilderAndSolver)
GlobalPointersVector< Element > ElementWeakPtrVectorType
Definition: explicit_hamilton_builder_and_solver.hpp:94
BuilderAndSolver< TSparseSpace, TDenseSpace, TLinearSolver > BaseType
Definition: explicit_hamilton_builder_and_solver.hpp:62
BaseType::LocalSystemMatrixType LocalSystemMatrixType
Definition: explicit_hamilton_builder_and_solver.hpp:76
BaseType::TDataType TDataType
Definition: explicit_hamilton_builder_and_solver.hpp:66
void InitializeSolutionStep(ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
It applies certain operations at the system of equations at the beginning of the solution step.
Definition: explicit_hamilton_builder_and_solver.hpp:753
void Clear()
Definition: explicit_hamilton_builder_and_solver.hpp:802
virtual ~ExplicitHamiltonBuilderAndSolver()
Definition: explicit_hamilton_builder_and_solver.hpp:112
BeamMathUtils< double > BeamMathUtilsType
Definition: explicit_hamilton_builder_and_solver.hpp:90
Quaternion< double > QuaternionType
Definition: explicit_hamilton_builder_and_solver.hpp:92
BaseType::ConditionsArrayType ConditionsArrayType
Definition: explicit_hamilton_builder_and_solver.hpp:86
BaseType::TSystemVectorType TSystemVectorType
Definition: explicit_hamilton_builder_and_solver.hpp:72
void ApplyDirichletConditions(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A, TSystemVectorType &Dx, TSystemVectorType &b)
It applies the dirichlet conditions. This operation may be very heavy or completely unexpensive depen...
Definition: explicit_hamilton_builder_and_solver.hpp:779
BaseType::ElementsArrayType ElementsArrayType
Definition: explicit_hamilton_builder_and_solver.hpp:84
void BuildLHS(typename TSchemeType::Pointer pScheme, ModelPart &r_model_part, TSystemMatrixType &A)
Function to perform the building of the LHS, depending on the implementation chosen the size of the m...
Definition: explicit_hamilton_builder_and_solver.hpp:126
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
ptr_iterator ptr_begin()
Definition: geometry.h:481
SizeType WorkingSpaceDimension() const
Definition: geometry.h:1287
iterator begin()
Definition: global_pointers_vector.h:221
iterator end()
Definition: global_pointers_vector.h:229
static BoundedMatrix< double, TDim, TDim > InvertMatrix(const BoundedMatrix< double, TDim, TDim > &rInputMatrix, double &rInputMatrixDet, const double Tolerance=ZeroTolerance)
Calculates the inverse of a 2x2, 3x3 and 4x4 matrices (using bounded matrix for performance)
Definition: math_utils.h:197
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodeIterator NodeIterator
Definition: model_part.h:134
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
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
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
void ToRotationVector(T &rx, T &ry, T &rz) const
Definition: quaternion.h:262
static Quaternion FromRotationVector(double rx, double ry, double rz)
Definition: quaternion.h:427
This class provides the implementation of the basic tasks that are needed by the solution strategy.
Definition: scheme.h:56
BOOST_UBLAS_INLINE void clear()
Definition: array_1d.h:325
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
residual
Definition: hinsberg_optimization_4.py:433
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
def Alpha(n, j)
Definition: quadrature.py:93
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
A
Definition: sensitivityMatrix.py:70
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31