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.
effective_stresses_communicator_utility.hpp
Go to the documentation of this file.
1 /*
2  * Author: Miguel Angel Celigueta
3  *
4  * maceli@cimne.upc.edu
5  */
6 
7 #ifndef EFFECTIVE_STRESSES_COMMUNICATOR_UTILITY_H
8 #define EFFECTIVE_STRESSES_COMMUNICATOR_UTILITY_H
9 
10 #include "includes/variables.h"
11 #include <limits>
12 #include <iostream>
13 #include <iomanip>
14 
15 #ifdef _OPENMP
16 #include <omp.h>
17 #endif
18 
19 #include "includes/define.h"
20 #include "includes/condition.h"
21 #include "includes/model_part.h"
23 #include "../../PoromechanicsApplication/poromechanics_application_variables.h"
24 #include "../../DEMApplication/DEM_application_variables.h"
25 
27 
28 namespace Kratos {
29 
31 
32  public:
33 
34  typedef ModelPart::NodesContainerType::ContainerType::iterator NodesIteratorType;
35 
37 
38  EffectiveStressesCommunicatorUtility(ModelPart& r_source_model_part, ModelPart& destination_model_part):mrSourceModelPart(r_source_model_part), mrDestinationModelPart(destination_model_part) {
39  Check();
40  }
41 
43  delete mpSearchStructure;
44  }
45 
46  void Initialize() {
47  mpSearchStructure = new BinBasedFastPointLocator<2>(mrSourceModelPart);
48  mpSearchStructure->UpdateSearchDatabase();
49  InitializeVariablesToZero();
50  }
51 
53 
55 
56  #pragma omp parallel for
57  for (int i=0; i<(int)mrDestinationModelPart.Nodes().size(); i++) {
58  auto node_it = mrDestinationModelPart.NodesBegin() + i;
59  node_it->SetValue(OLD_RADIAL_NORMAL_STRESS_COMPONENT, node_it->GetValue(RADIAL_NORMAL_STRESS_COMPONENT));
60  }
61 
62  KRATOS_CATCH("")
63  }
64 
66 
68  const int max_results = 10000;
69 
70  #pragma omp parallel
71  {
72  Vector N;
73  typename BinBasedFastPointLocator<2>::ResultContainerType results(max_results);
74  typename BinBasedFastPointLocator<2>::ResultIteratorType results_begin = results.begin();
75  Vector unitary_radial_vector = ZeroVector(3);
76 
77  #pragma omp for
78  for (int i = 0; i < (int)mrDestinationModelPart.Nodes().size(); i++) {
79  auto node_it = mrDestinationModelPart.NodesBegin() + i;
80  auto& particle_coordinates = node_it->Coordinates();
81  const double norm = MathUtils<double>::Norm(particle_coordinates);
82  if (norm > std::numeric_limits<double>::epsilon()) {
83  const double inv_norm = 1.0 / norm;
84  unitary_radial_vector[0] = particle_coordinates[0] * inv_norm;
85  unitary_radial_vector[1] = particle_coordinates[1] * inv_norm;
86  unitary_radial_vector[2] = particle_coordinates[2] * inv_norm;
87  }
88  else {
89  continue; //In the DEM walls modelpart there is a node which represents the center of gravity of the solid...
90  //KRATOS_ERROR<<"Radial stresses cannot be trasferred to a point which is in the origin of coordinates."<<std::endl;
91  }
92 
93  bool is_found = false;
94  Element::Pointer shared_p_element;
95  is_found = mpSearchStructure->FindPointOnMesh(particle_coordinates, N, shared_p_element, results_begin, max_results, 0.0);
96  if (is_found) {
97  Matrix interpolated_effective_stress_tensor = ZeroMatrix(3, 3);
98  const auto& geom = shared_p_element->GetGeometry();
99  for (size_t j = 0; j < geom.size(); j++) {
100  const Matrix& tempM = geom[j].FastGetSolutionStepValue(NODAL_EFFECTIVE_STRESS_TENSOR);
101  noalias(interpolated_effective_stress_tensor) += N[j] * tempM;
102  }
103  Vector tempV = prod(interpolated_effective_stress_tensor, unitary_radial_vector);
104  double radial_stress = MathUtils<double>::Dot(tempV, unitary_radial_vector);
105  node_it->SetValue(RADIAL_NORMAL_STRESS_COMPONENT, radial_stress);
106  }
107  }
108  }
109 
110  KRATOS_CATCH("")
111  }
112 
114 
115  KRATOS_TRY
116 
117  #pragma omp parallel
118  {
119  Vector unitary_radial_vector = ZeroVector(2);
120 
121  #pragma omp for
122  for (int i=0; i<(int)mrDestinationModelPart.Nodes().size(); i++) {
123  auto node_it = mrDestinationModelPart.NodesBegin() + i;
124  auto& particle_coordinates = node_it->Coordinates();
125  const double norm = MathUtils<double>::Norm(particle_coordinates);
126  if (norm > std::numeric_limits<double>::epsilon()) {
127  const double inv_norm = 1.0 / norm;
128  unitary_radial_vector[0] = particle_coordinates[0] * inv_norm;
129  unitary_radial_vector[1] = particle_coordinates[1] * inv_norm;
130  }
131  else {
132  continue; //In the DEM walls modelpart there is a node which represents the center of gravity of the solid...
133  //KRATOS_ERROR<<"Radial stresses cannot be trasferred to a point which is in the origin of coordinates."<<std::endl;
134  }
135 
136  Vector tempV = prod(stress_tensor, unitary_radial_vector);
137  double radial_stress = MathUtils<double>::Dot(tempV, unitary_radial_vector);
138  node_it->SetValue(RADIAL_NORMAL_STRESS_COMPONENT, radial_stress);
139  }
140  }
141 
142  KRATOS_CATCH("")
143  }
144 
145  virtual std::string Info() const { return "";}
146 
147  virtual void PrintInfo(std::ostream& rOStream) const {}
148 
149  virtual void PrintData(std::ostream& rOStream) const {}
150 
151  private:
152 
153  ModelPart& mrSourceModelPart;
154  ModelPart& mrDestinationModelPart;
155  BinBasedFastPointLocator<2>* mpSearchStructure;
156 
158 
159  void Check() {
160 
161  }
162 
163  void InitializeVariablesToZero() {
164  KRATOS_TRY
165 
166  #pragma omp parallel for
167  for (int i=0; i<(int)mrDestinationModelPart.Nodes().size(); i++) {
168  auto node_it = mrDestinationModelPart.NodesBegin() + i;
169  node_it->SetValue(OLD_RADIAL_NORMAL_STRESS_COMPONENT, 0.0);
170  node_it->SetValue(RADIAL_NORMAL_STRESS_COMPONENT, 0.0);
171  }
172 
173  KRATOS_CATCH("")
174  }
175 
176  }; // class EffectiveStressesCommunicatorUtility
177 
178 } // namespace Kratos
179 
180 #endif // EFFECTIVE_STRESSES_COMMUNICATOR_UTILITY_H
void UpdateSearchDatabase()
Function to construct or update the search database.
Definition: binbased_fast_point_locator.h:139
Definition: effective_stresses_communicator_utility.hpp:30
void CopyWallCurrentEffectiveStressesToOldEffectiveStresses()
Definition: effective_stresses_communicator_utility.hpp:52
void CommunicateCurrentRadialEffectiveStressesToDemWalls()
Definition: effective_stresses_communicator_utility.hpp:65
EffectiveStressesCommunicatorUtility(ModelPart &r_source_model_part, ModelPart &destination_model_part)
Definition: effective_stresses_communicator_utility.hpp:38
virtual ~EffectiveStressesCommunicatorUtility()
Definition: effective_stresses_communicator_utility.hpp:42
void CommunicateGivenRadialEffectiveStressesToDemWalls(const Matrix stress_tensor)
Definition: effective_stresses_communicator_utility.hpp:113
virtual void PrintData(std::ostream &rOStream) const
Definition: effective_stresses_communicator_utility.hpp:149
ModelPart::NodesContainerType::ContainerType::iterator NodesIteratorType
Definition: effective_stresses_communicator_utility.hpp:34
void Initialize()
Definition: effective_stresses_communicator_utility.hpp:46
KRATOS_CLASS_POINTER_DEFINITION(EffectiveStressesCommunicatorUtility)
virtual std::string Info() const
Definition: effective_stresses_communicator_utility.hpp:145
virtual void PrintInfo(std::ostream &rOStream) const
Definition: effective_stresses_communicator_utility.hpp:147
static double Norm(const Vector &a)
Calculates the norm of vector "a".
Definition: math_utils.h:703
static double Dot(const Vector &rFirstVector, const Vector &rSecondVector)
Performs the dot product of two vectors of arbitrary size.
Definition: math_utils.h:669
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
#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
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
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
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
int j
Definition: quadrature.py:648
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17