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.
stress_failure_check_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: Ignasi de Pouplana
11 //
12 
13 
14 #ifndef KRATOS_STRESS_FAILURE_CHECK_UTILITIES
15 #define KRATOS_STRESS_FAILURE_CHECK_UTILITIES
16 
17 // System includes
18 #include <fstream>
19 #include <iostream>
20 #include <cmath>
21 
22 // Project includes
23 #include "geometries/geometry.h"
24 #include "includes/define.h"
25 #include "includes/model_part.h"
27 #include "utilities/openmp_utils.h"
29 
30 // Application includes
31 #include "custom_utilities/AuxiliaryFunctions.h"
33 
35 
36 
37 namespace Kratos
38 {
39 
41 
43 {
44 
45 public:
46 
48 
50 
52  Parameters& rParameters
53  ) :
54  mrModelPart(rModelPart)
55 {
57 
58  Parameters default_parameters( R"(
59  {
60  "cylinder_center": [0.0,0.0,0.0],
61  "min_radius": 0.00381,
62  "max_radius": 0.00481
63  } )" );
64 
65  // Now validate agains defaults -- this also ensures no type mismatch
66  rParameters.ValidateAndAssignDefaults(default_parameters);
67 
68  mCylinderCenter[0] = rParameters["cylinder_center"][0].GetDouble();
69  mCylinderCenter[1] = rParameters["cylinder_center"][1].GetDouble();
70  mCylinderCenter[2] = rParameters["cylinder_center"][2].GetDouble();
71  mMinRadius = rParameters["min_radius"].GetDouble();
72  mMaxRadius = rParameters["max_radius"].GetDouble();
73 
74  KRATOS_CATCH("");
75 }
76 
78 
80 
81 //***************************************************************************************************************
82 //***************************************************************************************************************
83 
85 {
86  std::vector<double> ThreadSigma1(ParallelUtilities::GetNumThreads(), 0.0);
87  // std::vector<double> ThreadSigma2(ParallelUtilities::GetNumThreads(), 0.0);
88  std::vector<double> ThreadSigma3(ParallelUtilities::GetNumThreads(), 0.0);
89  std::vector<int> ThreadNParticles(ParallelUtilities::GetNumThreads(), 0);
90 
92 
93  #pragma omp parallel
94  {
95  int k = OpenMPUtils::ThisThread();
96 
97  #pragma omp for
98  for (int i = 0; i < (int)rElements.size(); i++) {
99 
100  ModelPart::ElementsContainerType::ptr_iterator ptr_itElem = rElements.ptr_begin() + i;
101 
102  const array_1d<double,3> DemPosition = (*ptr_itElem)->GetGeometry()[0].Coordinates();
103  const double Distance2 = std::pow(DemPosition[0] - mCylinderCenter[0], 2) + std::pow(DemPosition[1] - mCylinderCenter[1], 2);
104 
105  Element* p_element = ptr_itElem->get();
106  SphericContinuumParticle* pDemElem = dynamic_cast<SphericContinuumParticle*>(p_element);
107 
108  if ((pDemElem->IsNot(DEMFlags::STICKY)) && (Distance2 >= std::pow(mMinRadius,2)) && (Distance2 <= std::pow(mMaxRadius,2))) {
109 
110  BoundedMatrix<double, 3, 3> stress_tensor = (*(pDemElem->mSymmStressTensor));
111  Vector principal_stresses(3);
112  noalias(principal_stresses) = AuxiliaryFunctions::EigenValuesDirectMethod(stress_tensor);
113  const double max_stress = *std::max_element(principal_stresses.begin(), principal_stresses.end());
114  const double min_stress = *std::min_element(principal_stresses.begin(), principal_stresses.end());
115  ThreadSigma1[k] += max_stress;
116  ThreadSigma3[k] += min_stress;
117  ThreadNParticles[k] += 1;
118  }
119  }
120  }
121 
122  double Sigma1Average = 0.0;
123  double Sigma3Average = 0.0;
124  int NParticles = 0;
125  for (int k = 0; k < ParallelUtilities::GetNumThreads(); k++) {
126  Sigma1Average += ThreadSigma1[k];
127  Sigma3Average += ThreadSigma3[k];
128  NParticles += ThreadNParticles[k];
129  }
130 
131  if (NParticles > 0) {
132  Sigma1Average = Sigma1Average / NParticles;
133  Sigma3Average = Sigma3Average / NParticles;
134  }
135 
136  double CurrentTime = mrModelPart.GetProcessInfo()[TIME];
137  mrModelPart.GetProcessInfo()[SIGMA_3_AVERAGE] = Sigma3Average;
138 
139  // Note: These two files are written in the "problemname_Graphs" folder. They are erased at the beginning of the simulation.
140  std::fstream Sigma1File;
141  std::fstream Sigma3File;
142 
143  Sigma1File.open("sigma1average_t.txt", std::fstream::out | std::fstream::app);
144  Sigma1File.precision(12);
145  Sigma1File << CurrentTime << " " << Sigma1Average << std::endl;
146  Sigma1File.close();
147 
148  Sigma3File.open("sigma3average_t.txt", std::fstream::out | std::fstream::app);
149  Sigma3File.precision(12);
150  Sigma3File << CurrentTime << " " << Sigma3Average << std::endl;
151  Sigma3File.close();
152 }
153 
154 
155 
156 //***************************************************************************************************************
157 //***************************************************************************************************************
158 
162 
163 
167 
169 
170 virtual std::string Info() const
171 {
172  return "";
173 }
174 
176 
177 virtual void PrintInfo(std::ostream& rOStream) const
178 {
179 }
180 
182 
183 virtual void PrintData(std::ostream& rOStream) const
184 {
185 }
186 
187 
191 
193 
194 protected:
197 
200  double mMinRadius;
201  double mMaxRadius;
202 
206 
207 
211 
212 
216 
217 
221 
225 
226 
230 
231 
233 
234 private:
235 
238 
239 
246 
250 
251 
255 
256 
260 
261 
265 
268 
269 
271 
272 }; // Class StressFailureCheckUtilities
273 
274 } // namespace Python.
275 
276 #endif // KRATOS_STRESS_FAILURE_CHECK_UTILITIES
MeshType & LocalMesh()
Returns the reference to the mesh storing all local entities.
Definition: communicator.cpp:245
Base class for all Elements.
Definition: element.h:60
bool IsNot(Flags const &rOther) const
Definition: flags.h:291
Definition: amatrix_interface.h:41
iterator end()
Definition: amatrix_interface.h:243
iterator begin()
Definition: amatrix_interface.h:241
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
Communicator & GetCommunicator()
Definition: model_part.h:1821
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
static int ThisThread()
Wrapper for omp_get_thread_num().
Definition: openmp_utils.h:108
static int GetNumThreads()
Returns the current number of threads.
Definition: parallel_utilities.cpp:34
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
Definition: spheric_continuum_particle.h:26
BoundedMatrix< double, 3, 3 > * mSymmStressTensor
Definition: spheric_particle.h:267
Note: For the moment this only works for cylindrical probes with its axis oriented in Z direction.
Definition: stress_failure_check_utilities.hpp:43
array_1d< double, 3 > mCylinderCenter
Definition: stress_failure_check_utilities.hpp:199
ModelPart & mrModelPart
Definition: stress_failure_check_utilities.hpp:198
virtual ~StressFailureCheckUtilities()
Destructor.
Definition: stress_failure_check_utilities.hpp:79
void ExecuteFinalizeSolutionStep()
Definition: stress_failure_check_utilities.hpp:84
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: stress_failure_check_utilities.hpp:177
StressFailureCheckUtilities(ModelPart &rModelPart, Parameters &rParameters)
Default constructor.
Definition: stress_failure_check_utilities.hpp:51
double mMaxRadius
Definition: stress_failure_check_utilities.hpp:201
KRATOS_CLASS_POINTER_DEFINITION(StressFailureCheckUtilities)
virtual std::string Info() const
Turn back information as a stemplate<class T, std::size_t dim> tring.
Definition: stress_failure_check_utilities.hpp:170
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: stress_failure_check_utilities.hpp:183
double mMinRadius
Definition: stress_failure_check_utilities.hpp:200
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
static Vector EigenValuesDirectMethod(const BoundedMatrix< double, 3, 3 > &A)
Definition: AuxiliaryFunctions.h:264
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
out
Definition: isotropic_damage_automatic_differentiation.py:200
int k
Definition: quadrature.py:595
integer i
Definition: TensorModule.f:17