KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
global_joint_stress_utility.hpp
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Lorenzo Gracia
11 //
12 //
13 
14 #if !defined(KRATOS_GLOBAL_JOINT_STRESS_UTILITIES)
15 #define KRATOS_GLOBAL_JOINT_STRESS_UTILITIES
16 
17 // System includes
18 #include <cmath>
19 
20 // Project includes
21 #include "includes/model_part.h"
23 #include "utilities/openmp_utils.h"
24 #include "utilities/math_utils.h"
25 #include "includes/element.h"
26 
27 // Application includes
29 
30 // How to use it?
31 // The aim of this utility is to obtain the tangential and normal forces at some plane of interest in the joint element.
32 // It can be called from MainKratos.py following next commmands.
33 //
34 // Example of use from python:
35 // import global_joint_stress_utility
36 // global_joint_stress_utility.GlobalJoinStressUtility(main_model_part.GetSubModelPart("Parts_Parts_Auto3")).ComputingGlobalStress()
37 //
38 // The input plane must be introduce in the global_joint_stress_utility.py
39 
40 namespace Kratos
41 {
42 
44 {
45 
46  public:
47  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
48 
51  Parameters rParameters) : mr_model_part(model_part)
52  {
54 
55  // Getting values of the interested plane
56  m_plane_coordinates[0] = rParameters["pmid0_0"].GetDouble();
57  m_plane_coordinates[1] = rParameters["pmid0_1"].GetDouble();
58  m_plane_coordinates[2] = rParameters["pmid0_2"].GetDouble();
59  m_plane_coordinates[3] = rParameters["pmid1_0"].GetDouble();
60  m_plane_coordinates[4] = rParameters["pmid1_1"].GetDouble();
61  m_plane_coordinates[5] = rParameters["pmid1_2"].GetDouble();
62  m_plane_coordinates[6] = rParameters["pmid2_0"].GetDouble();
63  m_plane_coordinates[7] = rParameters["pmid2_1"].GetDouble();
64  m_plane_coordinates[8] = rParameters["pmid2_2"].GetDouble();
65 
66  KRATOS_CATCH("");
67  }
68 
70 
73 
74  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
75 
76  // Transforming local stress vector in global coordinates
78  {
79  const int nelements = static_cast<int>(mr_model_part.Elements().size());
80  ModelPart::ElementsContainerType::iterator el_begin = mr_model_part.ElementsBegin();
81  GeometryData::IntegrationMethod MyIntegrationMethod;
82  const ProcessInfo &CurrentProcessInfo = mr_model_part.GetProcessInfo();
83  BoundedMatrix<double, 3, 3> RotationPlane;
84 
85  //Definition of the plane
86  array_1d<double, 3> point_mid0;
87  array_1d<double, 3> point_mid1;
88  array_1d<double, 3> point_mid2;
89 
90  // Coordinates of interest plane
91  point_mid0[0] = m_plane_coordinates[0];
92  point_mid0[1] = m_plane_coordinates[1];
93  point_mid0[2] = m_plane_coordinates[2];
94 
95  point_mid1[0] = m_plane_coordinates[3];
96  point_mid1[1] = m_plane_coordinates[4];
97  point_mid1[2] = m_plane_coordinates[5];
98 
99  point_mid2[0] = m_plane_coordinates[6];
100  point_mid2[1] = m_plane_coordinates[7];
101  point_mid2[2] = m_plane_coordinates[8];
102 
103  this->CalculateRotationMatrix(RotationPlane, point_mid0, point_mid1, point_mid2);
104  array_1d<double, 3> VectorForceinPlane;
105  array_1d<double, 3> GlobalElementVectorForce = ZeroVector(3);
106 
107  for (int k = 0; k < nelements; k++)
108  {
109  ModelPart::ElementsContainerType::iterator it = el_begin + k;
110  Element::GeometryType &rGeom = it->GetGeometry();
111  BoundedMatrix<double, 3, 3> RotationMatrix;
112 
113  //Define mid-plane points for prism_interface_3d_6
114  noalias(point_mid0) = 0.5 * (rGeom.GetPoint(0) + rGeom.GetPoint(3));
115  noalias(point_mid1) = 0.5 * (rGeom.GetPoint(1) + rGeom.GetPoint(4));
116  noalias(point_mid2) = 0.5 * (rGeom.GetPoint(2) + rGeom.GetPoint(5));
117 
118  this->CalculateRotationMatrix(RotationMatrix, point_mid0, point_mid1, point_mid2);
119  MyIntegrationMethod = it->GetIntegrationMethod();
120  const Element::GeometryType::IntegrationPointsArrayType &IntegrationPoints = rGeom.IntegrationPoints(MyIntegrationMethod);
121  unsigned int NumGPoints = IntegrationPoints.size();
122  std::vector<array_1d<double, 3>> LocalStressVector;
123  array_1d<double, 3> LocalElementStress = ZeroVector(3);
124  array_1d<double, 3> LocalElementVectorForce;
125  it->CalculateOnIntegrationPoints(LOCAL_STRESS_VECTOR, LocalStressVector, CurrentProcessInfo);
126 
127  for (unsigned int GPoint = 0; GPoint < NumGPoints; GPoint++)
128  {
129  noalias(LocalElementStress) += LocalStressVector[GPoint];
130  }
131 
132  // Computing area at mid plane
133  double InvNumGP = 1.0 / static_cast<double>(NumGPoints);
134  LocalElementStress[0] *= InvNumGP;
135  LocalElementStress[1] *= InvNumGP;
136  LocalElementStress[2] *= InvNumGP;
137  double Area;
138  this->AreaMidPlane(Area, point_mid0, point_mid1, point_mid2);
139  noalias(LocalElementVectorForce) = LocalElementStress * Area;
140  noalias(GlobalElementVectorForce) += prod(trans(RotationMatrix), LocalElementVectorForce);
141  }
142 
143  noalias(VectorForceinPlane) = prod(RotationPlane, GlobalElementVectorForce);
144  const double TangentialForce = sqrt(VectorForceinPlane[0] * VectorForceinPlane[0] + VectorForceinPlane[1] * VectorForceinPlane[1]);
145 
146  std::cout << " Tangential Force (N) " << TangentialForce << std::endl;
147  std::cout << " Normal Force (N) " << fabs(VectorForceinPlane[2]) << std::endl;
148  }
149 
151 
152  protected:
156 
157  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
158 
159  //Currently is just working for prism element
160 
162  {
163  KRATOS_TRY
164 
165  //Unitary vector in local x direction
167  noalias(Vx) = point_mid1 - point_mid0;
168  double inv_norm_x = 1.0 / norm_2(Vx);
169  Vx[0] *= inv_norm_x;
170  Vx[1] *= inv_norm_x;
171  Vx[2] *= inv_norm_x;
172 
173  //Unitary vector in local z direction
175  noalias(Vy) = point_mid2 - point_mid0;
178  double inv_norm_z = 1.0 / norm_2(Vz);
179  Vz[0] *= inv_norm_z;
180  Vz[1] *= inv_norm_z;
181  Vz[2] *= inv_norm_z;
182 
183  //Unitary vector in local y direction
185 
186  //Rotation Matrix
187  rRotationMatrix(0, 0) = Vx[0];
188  rRotationMatrix(0, 1) = Vx[1];
189  rRotationMatrix(0, 2) = Vx[2];
190 
191  rRotationMatrix(1, 0) = Vy[0];
192  rRotationMatrix(1, 1) = Vy[1];
193  rRotationMatrix(1, 2) = Vy[2];
194 
195  rRotationMatrix(2, 0) = Vz[0];
196  rRotationMatrix(2, 1) = Vz[1];
197  rRotationMatrix(2, 2) = Vz[2];
198 
199  KRATOS_CATCH("")
200  }
201 
202  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
203 
204  void AreaMidPlane(double &rArea, array_1d<double, 3> &point_mid0, array_1d<double, 3> &point_mid1, array_1d<double, 3> &point_mid2)
205  {
206  KRATOS_TRY
207 
208  //Vector declarations
212 
213  // Computing distances and area
214  noalias(Vx) = point_mid1 - point_mid0;
215  noalias(Vy) = point_mid2 - point_mid0;
217  rArea = sqrt(Vz[0] * Vz[0] + Vz[1] * Vz[1] + Vz[2] * Vz[2]) / 2.0;
218 
219  KRATOS_CATCH("")
220  }
221 
222  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
223 
224 }; //Class
225 
226 } /* namespace Kratos.*/
227 
228 #endif /* KRATOS_GLOBAL_JOINT_STRESS_UTILITIES defined */
IntegrationMethod
Definition: geometry_data.h:76
Geometry base class.
Definition: geometry.h:71
std::vector< IntegrationPointType > IntegrationPointsArrayType
Definition: geometry.h:161
const IntegrationPointsArrayType & IntegrationPoints() const
Definition: geometry.h:2284
TPointType const & GetPoint(const int Index) const
Definition: geometry.h:1816
Definition: global_joint_stress_utility.hpp:44
ModelPart & mr_model_part
Member Variables.
Definition: global_joint_stress_utility.hpp:154
void ComputingGlobalStress()
Definition: global_joint_stress_utility.hpp:77
GlobalJointStressUtility(ModelPart &model_part, Parameters rParameters)
Constructor.
Definition: global_joint_stress_utility.hpp:50
void AreaMidPlane(double &rArea, array_1d< double, 3 > &point_mid0, array_1d< double, 3 > &point_mid1, array_1d< double, 3 > &point_mid2)
Definition: global_joint_stress_utility.hpp:204
array_1d< double, 9 > m_plane_coordinates
Definition: global_joint_stress_utility.hpp:155
~GlobalJointStressUtility()
Destructor.
Definition: global_joint_stress_utility.hpp:72
void CalculateRotationMatrix(BoundedMatrix< double, 3, 3 > &rRotationMatrix, array_1d< double, 3 > &point_mid0, array_1d< double, 3 > &point_mid1, array_1d< double, 3 > &point_mid2)
Definition: global_joint_stress_utility.hpp:161
Definition: amatrix_interface.h:41
static T CrossProduct(const T &a, const T &b)
Performs the vector product of the two input vectors a,b.
Definition: math_utils.h:762
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
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
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
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
#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
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
model_part
Definition: face_heat.py:14
int k
Definition: quadrature.py:595