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.
streamlines_output_3D_utilities.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_STREAMLINES_OUTPUT_3D_UTILITIES)
15 #define KRATOS_STREAMLINES_OUTPUT_3D_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 "custom_utilities/solid_mechanics_math_utilities.hpp"
26 
27 // Application includes
29 
30 namespace Kratos
31 {
32 
34 {
35 
36  public:
37  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
38 
41 
43 
46 
47  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
48 
49  void ComputeOutputStep(ModelPart &r_model_part, const int dimension)
50  {
51 
52  KRATOS_TRY;
53 
54  const int NNodes = static_cast<int>(r_model_part.Nodes().size());
55  ModelPart::NodesContainerType::iterator node_begin = r_model_part.NodesBegin();
56 
58  array_1d<double, 3> S_Sii;
59  array_1d<double, 3> S_Siii;
60  array_1d<double, 3> Tangential_components;
62  array_1d<double, 3> Vsiii;
63  array_1d<double, 3> Vsi_pos;
64  array_1d<double, 3> Vsiii_pos;
66 
67 #pragma omp parallel for
68  for (int i = 0; i < NNodes; i++)
69  {
70 
71  ModelPart::NodesContainerType::iterator itNode = node_begin + i;
72 
73  const Matrix &NodalStress = itNode->FastGetSolutionStepValue(NODAL_CAUCHY_STRESS_TENSOR);
74 
75  Tangential_components[0] = NodalStress(1, 0); // Sxy
76  Tangential_components[1] = NodalStress(2, 0); // Sxz
77  Tangential_components[2] = NodalStress(2, 1); // Syz
78 
79  //We compute the principal Stresses
82 
83  for (unsigned int i = 0; i < 3; i++)
84  {
85  S_Si[i] = NodalStress(i, i) - PrincipalStresses[0];
86  S_Sii[i] = NodalStress(i, i) - PrincipalStresses[1];
87  S_Siii[i] = NodalStress(i, i) - PrincipalStresses[2];
88  }
89 
90  noalias(Vsi) = this->ComputeVaps(Tangential_components, S_Siii, S_Sii, PrincipalStresses);
91  noalias(Vsiii) = this->ComputeVaps(Tangential_components, S_Sii, S_Si, PrincipalStresses);
92 
93  for (unsigned int a = 0; a < 3; a++)
94  {
95  Vsi_pos[a] = Vsi(a) * PrincipalStresses[0];
96  Vsiii_pos[a] = Vsiii(a) * PrincipalStresses[2];
97  }
98  array_1d<double, 3> &StreamlineVi = itNode->FastGetSolutionStepValue(Vi_POSITIVE);
99  noalias(StreamlineVi) = Vsi_pos;
100  array_1d<double, 3> &StreamlineViii = itNode->FastGetSolutionStepValue(Viii_POSITIVE);
101  noalias(StreamlineViii) = Vsiii_pos;
102  }
103 
104  KRATOS_CATCH("");
105  }
106 
108 
109  protected:
111 
112  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
113 
114  array_1d<double, 3> ComputeVaps(const array_1d<double, 3> &Tangential_components, const array_1d<double, 3> &S_Siii, const array_1d<double, 3> &S_Sii, const Vector &PrincipalStresses)
115  {
116 
117  array_1d<double, 3> vap1;
118  array_1d<double, 3> vap2;
119  array_1d<double, 3> vap3;
120  array_1d<double, 3> Result;
121  BoundedMatrix<double, 3, 3> AutovectorMatrix;
122 
123  // Tangential Components
124  const double &Sxy = Tangential_components[0];
125  const double &Sxz = Tangential_components[1];
126  const double &Syz = Tangential_components[2];
127 
128  AutovectorMatrix(0, 0) = S_Sii[0] * S_Siii[0] + Sxy * Sxy + Sxz * Sxz;
129  AutovectorMatrix(1, 1) = S_Sii[1] * S_Siii[1] + Sxy * Sxy + Syz * Syz;
130  AutovectorMatrix(2, 2) = S_Sii[2] * S_Siii[2] + Sxz * Sxz + Syz * Syz;
131  AutovectorMatrix(0, 1) = S_Sii[0] * Sxy + Sxy * S_Siii[1] + Sxz * Syz;
132  AutovectorMatrix(1, 0) = AutovectorMatrix(0, 1);
133  AutovectorMatrix(0, 2) = S_Sii[0] * Sxz + Sxy * Syz + S_Siii[2] * Sxz;
134  AutovectorMatrix(2, 0) = AutovectorMatrix(0, 2);
135  AutovectorMatrix(2, 1) = Sxy * Sxz + S_Sii[1] * Syz + Syz * S_Siii[2];
136  AutovectorMatrix(1, 2) = AutovectorMatrix(2, 1);
137 
138  for (unsigned int j = 0; j < 3; j++)
139  {
140  vap1[j] = AutovectorMatrix(0, j);
141  vap2[j] = AutovectorMatrix(1, j);
142  vap3[j] = AutovectorMatrix(2, j);
143  }
144 
145  // Normalization of the vector
146  const double norm_vap1 = sqrt(vap1[0] * vap1[0] + vap1[1] * vap1[1] + vap1[2] * vap1[2]);
147  const double norm_vap2 = sqrt(vap2[0] * vap2[0] + vap2[1] * vap2[1] + vap2(2) * vap2[2]);
148  const double norm_vap3 = sqrt(vap3[0] * vap3[0] + vap3[1] * vap3[1] + vap3[2] * vap3[2]);
149 
150  if (norm_vap1 > 1.0e-12)
151  {
152  vap1[0] *= 1.0 / norm_vap1;
153  vap1[1] *= 1.0 / norm_vap1;
154  vap1[2] *= 1.0 / norm_vap1;
155  }
156  else
157  {
158  noalias(vap1) = ZeroVector(3);
159  }
160 
161  if (norm_vap2 > 1.0e-12)
162  {
163  vap2[0] *= 1.0 / norm_vap2;
164  vap2[1] *= 1.0 / norm_vap2;
165  vap2[2] *= 1.0 / norm_vap2;
166  }
167  else
168  {
169  noalias(vap2) = ZeroVector(3);
170  }
171 
172  if (norm_vap3 > 1.0e-12)
173  {
174  vap3[0] *= 1.0 / norm_vap3;
175  vap3[1] *= 1.0 / norm_vap3;
176  vap3[2] *= 1.0 / norm_vap3;
177  }
178  else
179  {
180  noalias(vap3) = ZeroVector(3);
181  }
182 
183  // Checking if z-component is positive
184  for (unsigned int l = 0; l < 3; l++)
185  {
186  if (vap1[2] > 0.0)
187  {
188  Result[l] = vap1[l];
189  }
190  else if (vap2[2] > 0.0)
191  {
192  Result[l] = vap2[l];
193  }
194  else if (vap3[2] > 0.0)
195  {
196  Result[l] = vap3[l];
197  }
198  else
199  {
200  Result[l] = vap1[l];
201  }
202  }
203 
204  return Result;
205  }
206 
207  //----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
208 
209 }; //Class
210 
211 } /* namespace Kratos.*/
212 
213 #endif /* KRATOS_STREAMLINES_OUTPUT_3D_UTILITIES defined */
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
static Vector EigenValuesDirectMethod(const Matrix &A)
Definition: solid_mechanics_math_utilities.hpp:243
Definition: streamlines_output_3D_utilities.hpp:34
StreamlinesOutput3DUtilities()
Constructor.
Definition: streamlines_output_3D_utilities.hpp:40
~StreamlinesOutput3DUtilities()
Destructor.
Definition: streamlines_output_3D_utilities.hpp:45
void ComputeOutputStep(ModelPart &r_model_part, const int dimension)
Definition: streamlines_output_3D_utilities.hpp:49
array_1d< double, 3 > ComputeVaps(const array_1d< double, 3 > &Tangential_components, const array_1d< double, 3 > &S_Siii, const array_1d< double, 3 > &S_Sii, const Vector &PrincipalStresses)
Member Variables.
Definition: streamlines_output_3D_utilities.hpp:114
#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
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
a
Definition: generate_stokes_twofluid_element.py:77
int dimension
Definition: isotropic_damage_automatic_differentiation.py:123
PrincipalStresses
Definition: isotropic_damage_automatic_differentiation.py:221
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17