10 #if !defined(KRATOS_RIGID_BODY_ELEMENT_CREATION_UTILITY_H_INCLUDED )
11 #define KRATOS_RIGID_BODY_ELEMENT_CREATION_UTILITY_H_INCLUDED
87 SpatialBoundingBox::Pointer pRigidBodyBox,
94 "element_type": "TranslatoryRigidElement3D1N",
96 "compute_parameters": false,
98 "center_of_gravity": [0.0 ,0.0, 0.0],
100 "main_inertias": [0.0, 0.0, 0.0],
101 "main_axes": [ [1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ]
109 bool BodyIsFixed = CustomParameters[
"constrained"].
GetBool();
118 PropertiesType::Pointer pProperties = Kratos::make_shared<PropertiesType>(NumberOfProperties);
125 bool ComputeBodyParameters = CustomParameters[
"compute_parameters"].
GetBool();
128 if( ComputeBodyParameters ){
130 this->CalculateRigidBodyParameters( rModelPart, CenterOfGravity, InertiaTensor, LocalAxesMatrix, Mass );
134 Parameters BodyParameters = CustomParameters[
"body_parameters"];
136 Mass = BodyParameters[
"mass"].
GetDouble();
138 unsigned int size = BodyParameters[
"main_inertias"].
size();
140 for(
unsigned int i=0;
i<size;
i++ )
142 Parameters LocalAxesRow = BodyParameters[
"main_axes"][
i];
144 CenterOfGravity[
i] = BodyParameters[
"center_of_gravity"][
i].
GetDouble();
145 InertiaTensor(
i,
i) = BodyParameters[
"main_inertias"][
i].
GetDouble();
147 LocalAxesMatrix(0,
i) = LocalAxesRow[0].
GetDouble();
148 LocalAxesMatrix(1,
i) = LocalAxesRow[1].
GetDouble();
149 LocalAxesMatrix(2,
i) = LocalAxesRow[2].
GetDouble();
152 std::cout<<
" [ Mass "<<Mass<<
" ]"<<std::endl;
153 std::cout<<
" [ CenterOfGravity "<<CenterOfGravity<<
" ]"<<std::endl;
154 std::cout<<
" [ InertiaTensor "<<InertiaTensor<<
" ]"<<std::endl;
158 pProperties->SetValue(NODAL_MASS, Mass);
159 pProperties->SetValue(LOCAL_INERTIA_TENSOR, InertiaTensor);
160 pProperties->SetValue(LOCAL_AXES_MATRIX, LocalAxesMatrix);
166 unsigned int LastNodeId = rMainModelPart.
Nodes().back().Id() + 1;
170 NodeType::Pointer NodeCenterOfGravity;
171 this->CreateNode( NodeCenterOfGravity, rMainModelPart, CenterOfGravity, LastNodeId, BodyIsFixed);
174 unsigned int RigidBodyNodeId = rModelPart.
Nodes().back().Id();
177 NodeCenterOfGravity->GetSolutionStepValue(VOLUME_ACCELERATION) = rModelPart.
Nodes().back().GetSolutionStepValue(VOLUME_ACCELERATION);
180 NodeCenterOfGravity->Set(MASTER,
true);
181 NodeCenterOfGravity->Set(RIGID,
true);
184 pRigidBodyBox->SetRigidBodyCenter(NodeCenterOfGravity);
187 unsigned int LastElementId = rMainModelPart.
Elements().back().Id() + 1;
189 std::string ElementName = CustomParameters[
"element_type"].
GetString();
192 GeometryType::Pointer pGeometry;
194 pGeometry = Kratos::make_shared<Point3DType>(NodeCenterOfGravity);
196 pGeometry = Kratos::make_shared<Point2DType>(NodeCenterOfGravity);
198 ModelPart::NodesContainerType::Pointer pNodes = rModelPart.
pNodes();
200 ElementType::Pointer pRigidBodyElement = this->CreateRigidBodyElement(ElementName, LastElementId, pGeometry, pProperties, pNodes);
204 rModelPart.
AddNode(NodeCenterOfGravity);
211 if(i_mp->Is(BOUNDARY)){
212 for(ModelPart::NodesContainerType::iterator i_node = i_mp->NodesBegin(); i_node != i_mp->NodesEnd(); ++i_node)
214 for(ModelPart::NodesContainerType::iterator j_node = rModelPart.
NodesBegin(); j_node != rModelPart.
NodesEnd(); ++j_node)
216 if(i_node->Id() == j_node->Id() || i_node->Id() == RigidBodyNodeId){
217 i_mp->AddNode(NodeCenterOfGravity);
218 std::cout<<
" [ Add CenterOfGravity (node:"<<RigidBodyNodeId<<
") to "<<i_mp->Name()<<
" ]"<<std::endl;
238 if( (i_mp->Is(ACTIVE)) ){
239 std::cout<<
" [ Add Rigid Body to Solving model part ]"<<std::endl;
240 pRigidBodyElement->
Set(ACTIVE,
true);
248 pRigidBodyElement->Set(RIGID,
true);
253 MasterElements.
push_back(pRigidBodyElement);
255 for(ModelPart::NodesContainerType::iterator j_node = rModelPart.
NodesBegin(); j_node != rModelPart.
NodesEnd(); ++j_node)
257 j_node->SetValue(MASTER_ELEMENTS,MasterElements);
260 std::cout<<
" [ "<<ElementName<<
" Created : [NodeId:"<<LastNodeId<<
"] [ElementId:"<<LastElementId<<
"] CG("<<NodeCenterOfGravity->X()<<
","<<NodeCenterOfGravity->Y()<<
","<<NodeCenterOfGravity->Z()<<
") ]"<<std::endl;
275 "condition_type": "RigidBodyPointLinkCondition3D1N",
282 std::vector<Flags> TransferFlags;
283 for(
unsigned int i=0;
i<CustomParameters[
"flags_list"].
size(); ++
i)
290 unsigned int LastConditionId = 1;
292 LastConditionId = rMainModelPart.
Conditions().back().Id() + 1;
294 std::string ConditionName = CustomParameters[
"condition_type"].
GetString();
296 PropertiesType::Pointer pProperties = rModelPart.
pGetProperties(0);
300 unsigned int Id = LastConditionId;
303 ModelPart::NodesContainerType::iterator it_begin = rModelPart.
NodesBegin();
307 ModelPart::NodesContainerType::iterator it = it_begin +
i;
308 if( it->IsNot(MASTER) ){
310 it->Set(SLAVE,
false);
311 if (this->MatchTransferFlags(*(it.base()), TransferFlags))
314 GeometryType::Pointer pGeometry;
316 pGeometry = Kratos::make_shared<Point3DType>(*(it.base()));
318 pGeometry = Kratos::make_shared<Point2DType>(*(it.base()));
321 LinkConditions.push_back(this->CreateRigidBodyLinkCondition(ConditionName, Id, pGeometry, pProperties));
322 LinkConditions.back().Set(INTERACTION);
333 rModelPart.
AddConditions(LinkConditions.begin(),LinkConditions.end());
335 std::cout<<
" Created Link Conditions "<<LinkConditions.size()<<std::endl;
340 if( (i_mp->Is(ACTIVE)) ){
363 virtual std::string
Info()
const
365 return "RigidBodyElementCreationUtility";
371 rOStream <<
"RigidBodyElementCreationUtility";
448 ElementType::Pointer CreateRigidBodyElement(std::string ElementName,
unsigned int& rElementId, GeometryType::Pointer pGeometry, PropertiesType::Pointer pProperties, ModelPart::NodesContainerType::Pointer pNodes)
452 ElementType::Pointer pRigidBodyElement;
455 if( ElementName ==
"RigidBodyElement3D1N" || ElementName ==
"RigidBodyElement2D1N" ){
457 pRigidBodyElement = Kratos::make_intrusive<RigidBodyElement>(rElementId, pGeometry, pProperties, pNodes);
459 else if( ElementName ==
"TranslatoryRigidBodyElement3D1N" || ElementName ==
"TranslatoryRigidBodyElement2D1N"){
462 pRigidBodyElement = Kratos::make_intrusive<TranslatoryRigidBodyElement>(rElementId, pGeometry, pProperties, pNodes);
464 else if( ElementName ==
"RigidBodySegregatedVElement3D1N" || ElementName ==
"RigidBodySegregatedVElement2D1N" ){
466 pRigidBodyElement = Kratos::make_intrusive<RigidBodySegregatedVElement>(rElementId, pGeometry, pProperties, pNodes);
468 else if( ElementName ==
"TranslatoryRigidBodySegregatedVElement3D1N" || ElementName ==
"TranslatoryRigidBodySegregatedVElement2D1N"){
471 pRigidBodyElement = Kratos::make_intrusive<TranslatoryRigidBodySegregatedVElement>(rElementId, pGeometry, pProperties, pNodes);
473 else if( ElementName ==
"RigidBodyEMCElement3D1N" || ElementName ==
"RigidBodyEMCElement2D1N" ){
476 KRATOS_ERROR<<
" There is no rigid body element of the type "<<ElementName<<std::endl;
479 KRATOS_ERROR<<
" There is no rigid body element of the type "<<ElementName<<std::endl;
494 return pRigidBodyElement;
502 ConditionType::Pointer CreateRigidBodyLinkCondition(std::string ConditionName,
unsigned int& rConditionId, GeometryType::Pointer pGeometry, PropertiesType::Pointer pProperties)
506 ConditionType::Pointer pLinkCondition;
509 if( ConditionName ==
"RigidBodyPointLinkCondition3D1N" || ConditionName ==
"RigidBodyPointLinkCondition2D1N" ){
511 pLinkCondition = Kratos::make_intrusive<RigidBodyPointLinkCondition>(rConditionId, pGeometry, pProperties);
513 else if( ConditionName ==
"RigidBodyPointLinkSegregatedVCondition3D1N" || ConditionName ==
"RigidBodyPointLinkSegregatedVCondition2D1N" ){
515 pLinkCondition = Kratos::make_intrusive<RigidBodyPointLinkSegregatedVCondition>(rConditionId, pGeometry, pProperties);
518 KRATOS_ERROR<<
" There is no link condition of the type "<<ConditionName<<std::endl;
520 return pLinkCondition;
528 bool MatchTransferFlags(
const Node::Pointer& pNode,
const std::vector<Flags>& rTransferFlags)
531 for(
unsigned int i = 0;
i<rTransferFlags.size();
i++)
533 if( pNode->IsNot(rTransferFlags[
i]) )
543 void CalculateRigidBodyParameters(ModelPart& rModelPart,
Vector& rCenterOfGravity,
Matrix& rInertiaTensor,
Matrix& rLocalAxesMatrix,
double& rMass)
548 RigidBodyUtilities RigidBodyUtils;
550 rMass = RigidBodyUtils.MassCalculation(rModelPart);
551 rCenterOfGravity = RigidBodyUtils.CalculateCenterOfMass(rModelPart);
552 rInertiaTensor = RigidBodyUtils.CalculateInertiaTensor(rModelPart);
557 Matrix MainInertia = rInertiaTensor;
558 RigidBodyUtils.InertiaTensorToMainAxes(MainInertia, MainAxes);
567 for(
unsigned int i=0;
i<3;
i++)
570 for(
unsigned int j=0;
j<3;
j++)
572 Axis[
j] = MainAxes(
i,
j);
575 double norm =
norm_2(Axis);
579 for(
unsigned int j=0;
j<3;
j++)
581 rLocalAxesMatrix(
j,
i) = Axis[
j];
585 rInertiaTensor = MainInertia;
590 std::cout<<
" [ Mass "<<rMass<<
" ]"<<std::endl;
591 std::cout<<
" [ CenterOfGravity "<<rCenterOfGravity<<
" ]"<<std::endl;
592 std::cout<<
" [ InertiaTensor "<<rInertiaTensor<<
" ]"<<std::endl;
602 void CreateNode (NodeType::Pointer& Node, ModelPart& rModelPart,
const Vector& rPoint,
unsigned int& nodeId,
bool& rBodyIsFixed)
606 Node = rModelPart.CreateNewNode( nodeId, rPoint[0], rPoint[1], rPoint[2]);
608 rModelPart.AddNode( Node );
614 for(NodeType::DofsContainerType::iterator iii = reference_dofs.begin(); iii != reference_dofs.end(); iii++)
617 Node->pAddDof( rDof );
626 for(NodeType::DofsContainerType::iterator iii = new_dofs.begin(); iii != new_dofs.end(); iii++)
638 for(NodeType::DofsContainerType::iterator iii = new_dofs.begin(); iii != new_dofs.end(); iii++)
704 rOStream << std::endl;
Base class for all Conditions.
Definition: condition.h:59
Dof represents a degree of freedom (DoF).
Definition: dof.h:86
void FixDof()
Definition: dof.h:338
void FreeDof()
Definition: dof.h:345
Base class for all Elements.
Definition: element.h:60
void Set(const Flags ThisFlag)
Definition: flags.cpp:33
Geometry base class.
Definition: geometry.h:71
void push_back(TPointerType x)
Definition: global_pointers_vector.h:322
KratosComponents class encapsulates a lookup table for a family of classes in a generic way.
Definition: kratos_components.h:49
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
SubModelPartIterator SubModelPartsEnd()
Definition: model_part.h:1708
PropertiesType::Pointer pGetProperties(IndexType PropertiesId, IndexType MeshIndex=0)
Returns the Properties::Pointer corresponding to it's identifier.
Definition: model_part.cpp:664
SubModelPartIterator SubModelPartsBegin()
Definition: model_part.h:1698
void AddNode(NodeType::Pointer pNewNode, IndexType ThisIndex=0)
Definition: model_part.cpp:211
SizeType NumberOfProperties(IndexType ThisIndex=0) const
Returns the number of properties of the mesh.
Definition: model_part.cpp:575
NodesContainerType::Pointer pNodes(IndexType ThisIndex=0)
Definition: model_part.h:517
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
SubModelPartsContainerType::iterator SubModelPartIterator
Iterator over the sub model parts of this model part.
Definition: model_part.h:258
ConditionsContainerType & Conditions(IndexType ThisIndex=0)
Definition: model_part.h:1381
void AddProperties(PropertiesType::Pointer pNewProperties, IndexType ThisIndex=0)
Inserts a properties in the current mesh.
Definition: model_part.cpp:582
void RemoveConditions(Flags IdentifierFlag=TO_ERASE)
Definition: model_part.cpp:1637
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
ModelPart & GetSubModelPart(std::string const &SubModelPartName)
Definition: model_part.cpp:2029
void AddElement(ElementType::Pointer pNewElement, IndexType ThisIndex=0)
Definition: model_part.cpp:917
void AddConditions(std::vector< IndexType > const &ConditionIds, IndexType ThisIndex=0)
Definition: model_part.cpp:1460
NodeIterator NodesEnd(IndexType ThisIndex=0)
Definition: model_part.h:497
ModelPart & GetParentModelPart()
Definition: model_part.cpp:2124
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
This class defines the node.
Definition: node.h:65
std::vector< std::unique_ptr< Dof< double > >> DofsContainerType
The DoF container type definition.
Definition: node.h:92
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
double GetDouble() const
This method returns the double contained in the current Parameter.
Definition: kratos_parameters.cpp:657
void ValidateAndAssignDefaults(const Parameters &rDefaultParameters)
This function is designed to verify that the parameters under testing match the form prescribed by th...
Definition: kratos_parameters.cpp:1306
SizeType size() const
This method returns the total size of the current array parameter.
Definition: kratos_parameters.cpp:993
std::string GetString() const
This method returns the string contained in the current Parameter.
Definition: kratos_parameters.cpp:684
bool GetBool() const
This method returns the boolean contained in the current Parameter.
Definition: kratos_parameters.cpp:675
Definition: point_2d.h:53
Definition: point_3d.h:53
Properties encapsulates data shared by different Elements or Conditions. It can store any type of dat...
Definition: properties.h:69
Rigid body element build processes in Kratos.
Definition: rigid_body_element_creation_utility.hpp:45
virtual std::string Info() const
Turn back information as a string.
Definition: rigid_body_element_creation_utility.hpp:363
void CreateLinks(ModelPart &rModelPart, Parameters CustomParameters)
Definition: rigid_body_element_creation_utility.hpp:268
GlobalPointersVector< Element > ElementWeakPtrVectorType
Definition: rigid_body_element_creation_utility.hpp:62
virtual ~RigidBodyElementCreationUtility()
Destructor.
Definition: rigid_body_element_creation_utility.hpp:72
ModelPart::PropertiesType PropertiesType
Definition: rigid_body_element_creation_utility.hpp:57
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: rigid_body_element_creation_utility.hpp:375
ElementType::GeometryType GeometryType
Definition: rigid_body_element_creation_utility.hpp:58
KRATOS_CLASS_POINTER_DEFINITION(RigidBodyElementCreationUtility)
Pointer definition of Process.
RigidBodyElementCreationUtility()
Default constructor.
Definition: rigid_body_element_creation_utility.hpp:68
ModelPart::ConditionType ConditionType
Definition: rigid_body_element_creation_utility.hpp:56
Point2D< ModelPart::NodeType > Point2DType
Definition: rigid_body_element_creation_utility.hpp:59
ModelPart::NodeType NodeType
Definition: rigid_body_element_creation_utility.hpp:54
ModelPart::ElementType ElementType
Definition: rigid_body_element_creation_utility.hpp:55
void CreateRigidBody(ModelPart &rModelPart, SpatialBoundingBox::Pointer pRigidBodyBox, Parameters CustomParameters)
Definition: rigid_body_element_creation_utility.hpp:86
Point3D< ModelPart::NodeType > Point3DType
Definition: rigid_body_element_creation_utility.hpp:60
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: rigid_body_element_creation_utility.hpp:369
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR
Definition: exception.h:161
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
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
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
int j
Definition: quadrature.py:648
int nnodes
Definition: sensitivityMatrix.py:24
integer i
Definition: TensorModule.f:17