10 #if !defined(KRATOS_RIGID_BODY_UTILITIES_H_INCLUDED )
11 #define KRATOS_RIGID_BODY_UTILITIES_H_INCLUDED
17 #define FIND_MAX(a, b) ((a)>(b)?(a):(b))
28 #include "boost/smart_ptr.hpp"
117 for(
unsigned int i=0;
i<3;
i++)
118 VolumeAcceleration[
i] = rVolumeAcceleration[
i];
139 return VolumeAcceleration;
153 double ElasticModulus = 0;
159 return ElasticModulus;
172 double ModelVolume = 0;
174 bool mAxisymmetric =
false;
181 double two_pi = 6.28318530717958647693;
188 int number_of_threads = omp_get_max_threads();
190 int number_of_threads = 1;
193 if( mParallel ==
false )
194 number_of_threads = 1;
196 vector<unsigned int> element_partition;
197 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
204 ModelPart::ElementsContainerType::iterator ElemBegin = pElements.begin() + element_partition[
k];
205 ModelPart::ElementsContainerType::iterator ElemEnd = pElements.begin() + element_partition[
k + 1];
208 for(ModelPart::ElementsContainerType::const_iterator ie = ElemBegin; ie != ElemEnd; ie++)
211 const unsigned int dimension = ie->GetGeometry().WorkingSpaceDimension();
214 std::cout<<
" Axisymmetric problem with dimension: "<<
dimension<<std::endl;
217 for(
unsigned int i=0;
i<ie->GetGeometry().size();
i++ )
218 radius += ie->GetGeometry()[
i].X();
222 ModelVolumePartition[
k] += ie->GetGeometry().Area() * two_pi *
radius ;
229 for(
int i=0;
i<number_of_threads;
i++)
230 ModelVolume += ModelVolumePartition[
i];
240 int number_of_threads = omp_get_max_threads();
242 int number_of_threads = 1;
245 if( mParallel ==
false )
246 number_of_threads = 1;
248 vector<unsigned int> element_partition;
249 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
256 ModelPart::ElementsContainerType::iterator ElemBegin = pElements.begin() + element_partition[
k];
257 ModelPart::ElementsContainerType::iterator ElemEnd = pElements.begin() + element_partition[
k + 1];
260 for(ModelPart::ElementsContainerType::const_iterator ie = ElemBegin; ie != ElemEnd; ie++)
262 const unsigned int dimension = ie->GetGeometry().WorkingSpaceDimension();
264 ModelVolumePartition[
k] += ie->GetGeometry().Area() * ie->GetProperties()[THICKNESS];
267 ModelVolumePartition[
k] += ie->GetGeometry().Volume();
277 for(
int i=0;
i<number_of_threads;
i++)
278 ModelVolume += ModelVolumePartition[
i];
297 double ModelMass = 0;
299 bool mAxisymmetric =
false;
306 double two_pi = 6.28318530717958647693;
312 int number_of_threads = omp_get_max_threads();
314 int number_of_threads = 1;
317 if( mParallel ==
false )
318 number_of_threads = 1;
320 vector<unsigned int> element_partition;
321 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
328 ModelPart::ElementsContainerType::iterator ElemBegin = pElements.begin() + element_partition[
k];
329 ModelPart::ElementsContainerType::iterator ElemEnd = pElements.begin() + element_partition[
k + 1];
332 for(ModelPart::ElementsContainerType::const_iterator ie = ElemBegin; ie != ElemEnd; ie++)
335 const unsigned int dimension = ie->GetGeometry().WorkingSpaceDimension();
338 std::cout<<
" Axisymmetric problem with dimension: "<<
dimension<<std::endl;
341 for(
unsigned int i=0;
i<ie->GetGeometry().size();
i++ )
342 radius += ie->GetGeometry()[
i].X();
346 ModelMassPartition[
k] += ie->GetGeometry().Area() * two_pi *
radius * ie->GetProperties()[DENSITY];
352 for(
int i=0;
i<number_of_threads;
i++)
353 ModelMass += ModelMassPartition[
i];
363 int number_of_threads = omp_get_max_threads();
365 int number_of_threads = 1;
368 if( mParallel ==
false )
369 number_of_threads = 1;
371 vector<unsigned int> element_partition;
372 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
379 ModelPart::ElementsContainerType::iterator ElemBegin = pElements.begin() + element_partition[
k];
380 ModelPart::ElementsContainerType::iterator ElemEnd = pElements.begin() + element_partition[
k + 1];
383 for(ModelPart::ElementsContainerType::const_iterator ie = ElemBegin; ie != ElemEnd; ie++)
385 const unsigned int dimension = ie->GetGeometry().WorkingSpaceDimension();
387 ModelMassPartition[
k] += ie->GetGeometry().Area() * ie->GetProperties()[THICKNESS] * ie->GetProperties()[DENSITY];
390 ModelMassPartition[
k] += ie->GetGeometry().Volume() * ie->GetProperties()[DENSITY];
399 for(
int i=0;
i<number_of_threads;
i++)
400 ModelMass += ModelMassPartition[
i];
436 double ModelMass = 0;
439 double Thickness = 1;
441 bool mAxisymmetric =
false;
448 double two_pi = 6.28318530717958647693;
455 int number_of_threads = omp_get_max_threads();
457 int number_of_threads = 1;
460 if( mParallel ==
false )
461 number_of_threads = 1;
463 vector<unsigned int> element_partition;
464 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
471 ModelPart::ElementsContainerType::iterator ElemBegin = pElements.begin() + element_partition[
k];
472 ModelPart::ElementsContainerType::iterator ElemEnd = pElements.begin() + element_partition[
k + 1];
475 for(ModelPart::ElementsContainerType::const_iterator ie = ElemBegin; ie != ElemEnd; ie++)
478 const unsigned int dimension = ie->GetGeometry().WorkingSpaceDimension();
481 std::cout<<
" Axisymmetric problem with dimension: "<<
dimension<<std::endl;
484 for(
unsigned int i=0;
i<ie->GetGeometry().size();
i++ )
485 radius += ie->GetGeometry()[
i].X();
489 ModelMassPartition[
k] += ie->GetGeometry().Area() * two_pi *
radius * ie->GetProperties()[DENSITY];
493 for(
int i=0;
i<number_of_threads;
i++)
494 ModelMass += ModelMassPartition[
i];
504 int number_of_threads = omp_get_max_threads();
506 int number_of_threads = 1;
509 if( mParallel ==
false )
510 number_of_threads = 1;
512 vector<unsigned int> element_partition;
513 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
517 std::vector<Vector> CenterOfMassPartition(number_of_threads);
518 for(
int i=0;
i<number_of_threads;
i++)
525 ModelPart::ElementsContainerType::iterator ElemBegin = pElements.begin() + element_partition[
k];
526 ModelPart::ElementsContainerType::iterator ElemEnd = pElements.begin() + element_partition[
k + 1];
529 for(ModelPart::ElementsContainerType::const_iterator ie = ElemBegin; ie != ElemEnd; ie++)
532 const unsigned int dimension = ie->GetGeometry().WorkingSpaceDimension();
535 Thickness = ie->GetProperties()[THICKNESS];
536 ModelMassPartition[
k] += ie->GetGeometry().Area() * Thickness * ie->GetProperties()[DENSITY];
540 ModelMassPartition[
k] += ie->GetGeometry().Volume() * ie->GetProperties()[DENSITY];
547 const unsigned int number_of_nodes = ie->GetGeometry().PointsNumber();
562 for (
unsigned int PointNumber = 0; PointNumber < integration_points.size(); PointNumber++ )
567 double IntegrationWeight = mDetJ * integration_points[PointNumber].Weight() * Thickness;
571 for (
unsigned int i = 0;
i < number_of_nodes;
i++ )
578 CenterOfMassPartition[
k][
j] += IntegrationWeight *
N[
i] * ie->GetProperties()[DENSITY] * CurrentPosition[
j];
587 for(
int i=0;
i<number_of_threads;
i++){
588 ModelMass += ModelMassPartition[
i];
589 CenterOfMass += CenterOfMassPartition[
i];
595 CenterOfMass /= ModelMass;
597 std::cout<<
" [ WARNING: RIGID BODY WITH NO MASS ] "<<std::endl;
629 double ModelMass = 0;
633 for (
unsigned int k = 0;
k < 3;
k++ )
635 CenterOfMass[
k] = Center[
k];
640 double Thickness = 1;
642 bool mAxisymmetric =
false;
649 double two_pi = 6.28318530717958647693;
655 int number_of_threads = omp_get_max_threads();
657 int number_of_threads = 1;
660 if( mParallel ==
false )
661 number_of_threads = 1;
663 vector<unsigned int> element_partition;
664 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
671 ModelPart::ElementsContainerType::iterator ElemBegin = pElements.begin() + element_partition[
k];
672 ModelPart::ElementsContainerType::iterator ElemEnd = pElements.begin() + element_partition[
k + 1];
675 for(ModelPart::ElementsContainerType::const_iterator ie = ElemBegin; ie != ElemEnd; ie++)
678 const unsigned int dimension = ie->GetGeometry().WorkingSpaceDimension();
681 std::cout<<
" Axisymmetric problem with dimension: "<<
dimension<<std::endl;
684 for(
unsigned int i=0;
i<ie->GetGeometry().size();
i++ )
685 radius += ie->GetGeometry()[
i].X();
689 ModelMassPartition[
k] += ie->GetGeometry().Area() * two_pi *
radius * ie->GetProperties()[DENSITY];
693 for(
int i=0;
i<number_of_threads;
i++)
694 ModelMass += ModelMassPartition[
i];
705 int number_of_threads = omp_get_max_threads();
707 int number_of_threads = 1;
710 if( mParallel ==
false )
711 number_of_threads = 1;
713 vector<unsigned int> element_partition;
714 OpenMPUtils::CreatePartition(number_of_threads, pElements.size(), element_partition);
717 std::vector<Matrix> InertiaTensorPartition(number_of_threads);
718 for(
int i=0;
i<number_of_threads;
i++)
725 ModelPart::ElementsContainerType::iterator ElemBegin = pElements.begin() + element_partition[
k];
726 ModelPart::ElementsContainerType::iterator ElemEnd = pElements.begin() + element_partition[
k + 1];
729 for(ModelPart::ElementsContainerType::const_iterator ie = ElemBegin; ie != ElemEnd; ie++)
732 const unsigned int dimension = ie->GetGeometry().WorkingSpaceDimension();
735 Thickness = ie->GetProperties()[THICKNESS];
736 ModelMassPartition[
k] += ie->GetGeometry().Area() * Thickness * ie->GetProperties()[DENSITY];
740 ModelMassPartition[
k] += ie->GetGeometry().Volume() * ie->GetProperties()[DENSITY];
746 const unsigned int number_of_nodes = ie->GetGeometry().PointsNumber();
761 for (
unsigned int PointNumber = 0; PointNumber < integration_points.size(); PointNumber++ )
766 double IntegrationWeight = mDetJ * integration_points[PointNumber].Weight() * Thickness;
775 for (
unsigned int i = 0;
i < number_of_nodes;
i++ )
779 CurrentPositionA -= CenterOfMass;
781 for (
unsigned int j = 0;
j < number_of_nodes;
j++ )
785 CurrentPositionB -= CenterOfMass;
787 MassAB = IntegrationWeight *
N[
i] *
N[
j] * ie->GetProperties()[DENSITY];
789 OuterAB =
outer_prod( CurrentPositionA, CurrentPositionB );
790 InnerAB =
inner_prod( CurrentPositionA, CurrentPositionB );
792 InertiaTensorPartition[
k] += MassAB * ( InnerAB * Identity - OuterAB );
802 for(
int i=0;
i<number_of_threads;
i++){
803 ModelMass += ModelMassPartition[
i];
804 InertiaTensor += InertiaTensorPartition[
i];
811 return InertiaTensor;
832 return InertiaTensor;
849 EigenVectors3x3(InertiaTensor, MainAxes ,MainInertias);
852 for(
unsigned int i=0;
i<3;
i++)
853 InertiaTensor(
i,
i) = MainInertias[
i];
865 for(
unsigned int i=0;
i<mesh_elements.size();
i++) {
866 ElementsContainerType::ptr_iterator pTubeElement = mesh_elements.
ptr_begin()+
i;
867 (rDestinationModelPart.
Elements()).push_back(*pTubeElement);
872 for(
unsigned int i=0;
i<mesh_nodes.size();
i++) {
873 NodesContainerType::ptr_iterator pTubeNode = mesh_nodes.
ptr_begin()+
i;
874 (rDestinationModelPart.
Nodes()).push_back(*pTubeNode);
977 inline void clear_numerical_errors(
Matrix& rMatrix)
982 for(
unsigned int i=0;
i<rMatrix.size1();
i++)
984 for(
unsigned int j=0;
j<rMatrix.size2();
j++)
986 if(Maximum<fabs(rMatrix(
i,
j)))
987 Maximum = fabs(rMatrix(
i,
j));
992 double Critical = Maximum*1
e-5;
994 for(
unsigned int i=0;
i<rMatrix.size1();
i++)
996 for(
unsigned int j=0;
j<rMatrix.size2();
j++)
998 if(fabs(rMatrix(
i,
j))<Critical)
1017 if(
A.size1()!=3 ||
A.size2()!=3)
1018 std::cout<<
" GIVEN MATRIX IS NOT 3x3 eigenvectors calculation "<<std::endl;
1023 for (
int i = 0;
i < 3;
i++) {
1024 for (
int j = 0;
j < 3;
j++) {
1032 for (
int j = 0;
j < 3;
j++) {
1038 for (
int i = 2;
i > 0;
i--) {
1044 for (
int k = 0;
k <
i;
k++) {
1045 scale = scale + fabs(
d[
k]);
1049 for (
int j = 0;
j <
i;
j++) {
1058 for (
int k = 0;
k <
i;
k++) {
1070 for (
int j = 0;
j <
i;
j++) {
1076 for (
int j = 0;
j <
i;
j++) {
1080 for (
int k =
j+1;
k <=
i-1;
k++) {
1087 for (
int j = 0;
j <
i;
j++) {
1091 double hh =
f / (
h +
h);
1092 for (
int j = 0;
j <
i;
j++) {
1095 for (
int j = 0;
j <
i;
j++) {
1098 for (
int k =
j;
k <=
i-1;
k++) {
1110 for (
int i = 0;
i < 2;
i++) {
1115 for (
int k = 0;
k <=
i;
k++) {
1118 for (
int j = 0;
j <=
i;
j++) {
1120 for (
int k = 0;
k <=
i;
k++) {
1123 for (
int k = 0;
k <=
i;
k++) {
1128 for (
int k = 0;
k <=
i;
k++) {
1132 for (
int j = 0;
j < 3;
j++) {
1143 for (
int i = 1;
i < 3;
i++) {
1150 double eps = std::pow(2.0,-52.0);
1151 for (
int l = 0;
l < 3;
l++) {
1158 if (fabs(
e[
m]) <= eps*tst1) {
1175 double p = (
d[
l+1] - g) / (2.0 *
e[
l]);
1176 double r = hypot2(
p,1.0);
1180 d[
l] =
e[
l] / (
p + r);
1181 d[
l+1] =
e[
l] * (
p + r);
1182 double dl1 =
d[
l+1];
1183 double h = g -
d[
l];
1184 for (
int i =
l+2;
i < 3;
i++) {
1195 double el1 =
e[
l+1];
1198 for (
int i =
m-1;
i >=
l;
i--) {
1208 p =
c *
d[
i] - s * g;
1209 d[
i+1] =
h + s * (
c * g + s *
d[
i]);
1213 for (
int k = 0;
k < 3;
k++) {
1219 p = -s * s2 * c3 * el1 *
e[
l] / dl1;
1225 }
while (fabs(
e[
l]) > eps*tst1);
1233 for (
int i = 0;
i < 2;
i++) {
1236 for (
int j =
i+1;
j < 3;
j++) {
1245 for (
int j = 0;
j < 3;
j++) {
1261 static double hypot2(
double x,
double y) {
1262 return std::sqrt(
x*
x+
y*
y);
Base class for all Elements.
Definition: element.h:60
PropertiesType & GetProperties()
Definition: element.h:1024
IntegrationMethod
Definition: geometry_data.h:76
Geometry base class.
Definition: geometry.h:71
std::vector< IntegrationPointType > IntegrationPointsArrayType
Definition: geometry.h:161
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
NodesContainerType & Nodes()
Definition: mesh.h:346
ElementsContainerType & Elements()
Definition: mesh.h:568
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
MeshType & GetMesh(IndexType ThisIndex=0)
Definition: model_part.h:1791
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
TVariableType::Type & FastGetSolutionStepValue(const TVariableType &rThisVariable)
Definition: node.h:435
bool SolutionStepsDataHas(const VariableData &rThisVariable) const
Definition: node.h:427
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
ptr_iterator ptr_begin()
Returns an iterator pointing to the beginning of the underlying data container.
Definition: pointer_vector_set.h:386
Short class definition.
Definition: rigid_body_utilities.hpp:70
Vector CalculateCenterOfMass(ModelPart &rModelPart)
Definition: rigid_body_utilities.hpp:415
double GetElasticModulus(ModelPart &rModelPart)
Definition: rigid_body_utilities.hpp:149
double VolumeCalculation(ModelPart &rModelPart)
Definition: rigid_body_utilities.hpp:168
void TransferRigidBodySkinToModelPart(ModelPart &rSourceModelPart, ModelPart &rDestinationModelPart, const int mesh_id)
Definition: rigid_body_utilities.hpp:861
ModelPart::ElementsContainerType ElementsContainerType
Definition: rigid_body_utilities.hpp:77
Vector CenterOfMassCalculation(ModelPart::MeshType &rMesh)
Definition: rigid_body_utilities.hpp:431
Matrix InertiaTensorCalculation(ModelPart::MeshType &rMesh)
Definition: rigid_body_utilities.hpp:625
RigidBodyUtilities(bool Parallel)
Definition: rigid_body_utilities.hpp:87
double MassCalculation(ModelPart &rModelPart)
Definition: rigid_body_utilities.hpp:293
Vector GetVolumeAcceleration(ModelPart &rModelPart)
Definition: rigid_body_utilities.hpp:107
Matrix CalculateInertiaTensor(ModelPart &rModelPart)
Definition: rigid_body_utilities.hpp:610
ModelPart::MeshType::GeometryType GeometryType
Definition: rigid_body_utilities.hpp:78
ModelPart::NodesContainerType NodesContainerType
Definition: rigid_body_utilities.hpp:76
void InertiaTensorToMainAxes(Matrix &InertiaTensor, Matrix &MainAxes)
Definition: rigid_body_utilities.hpp:843
virtual void SetEchoLevel(int Level)
Definition: rigid_body_utilities.hpp:888
Matrix InertiaTensorMainAxesCalculation(ModelPart &rModelPart, Matrix &MainAxes)
Definition: rigid_body_utilities.hpp:823
RigidBodyUtilities()
Default constructor.
Definition: rigid_body_utilities.hpp:85
int GetEchoLevel()
Definition: rigid_body_utilities.hpp:893
~RigidBodyUtilities()
Destructor.
Definition: rigid_body_utilities.hpp:91
#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
AMatrix::IdentityMatrix< double > IdentityMatrix
Definition: amatrix_interface.h:564
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
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
AMatrix::VectorOuterProductExpression< TExpression1Type, TExpression2Type > outer_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:582
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
y
Other simbols definition.
Definition: generate_axisymmetric_navier_stokes_element.py:54
f
Definition: generate_convection_diffusion_explicit_element.py:112
V
Definition: generate_droplet_dynamics.py:256
h
Definition: generate_droplet_dynamics.py:91
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
float radius
Definition: mesh_to_mdpa_converter.py:18
int d
Definition: ode_solve.py:397
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
J
Definition: sensitivityMatrix.py:58
A
Definition: sensitivityMatrix.py:70
p
Definition: sensitivityMatrix.py:52
N
Definition: sensitivityMatrix.py:29
x
Definition: sensitivityMatrix.py:49
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31
#define FIND_MAX(a, b)
Definition: rigid_body_utilities.hpp:17