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.
nonlocal_damage_3D_utilities.hpp
Go to the documentation of this file.
1 
2 // | / |
3 // ' / __| _` | __| _ \ __|
4 // . \ | ( | | ( |\__ `
5 // _|\_\_| \__,_|\__|\___/ ____/
6 // Multi-Physics
7 //
8 // License: BSD License
9 // Kratos default license: kratos/license.txt
10 //
11 // Main authors: Ignasi de Pouplana
12 //
13 
14 
15 #if !defined(KRATOS_NONLOCAL_DAMAGE_3D_UTILITIES )
16 #define KRATOS_NONLOCAL_DAMAGE_3D_UTILITIES
17 
18 // Application includes
21 
22 namespace Kratos
23 {
24 
26 {
27 
28 public:
29 
32 
34 
35 private:
36 
37  struct Utility3DVariables
38  {
39  double X_max, X_min, Y_max, Y_min, Z_max, Z_min;
40  int NRows, NColumns, NSections;
41  double RowSize, ColumnSize, SectionSize;
42 
43  std::vector< std::vector< std::vector< std::vector<GaussPoint*> > > > GaussPointCellMatrix;
44  };
45 
47 
48 public:
49 
51 
54 
56 
59 
61 
62  void SearchGaussPointsNeighbours (Parameters* pParameters, ModelPart& rModelPart) override
63  {
64  KRATOS_INFO("Nonlocal Damage 3D utility") << "Starting non-local search of neighbours ..." << std::endl;
65 
66  // Define necessary variables
67  Utility3DVariables AuxVariables;
68 
69  //Set GaussPoints inside CellMatrix
70  this->InitializeNonlocalSearch(AuxVariables,pParameters,rModelPart);
71 
72  this->SearchNeighbours(AuxVariables,pParameters,rModelPart);
73 
74  KRATOS_INFO("Nonlocal Damage 3D utility") << "... search of neighbours completed." << std::endl;
75  }
76 
78 
79 protected:
80 
82 
84 
86  Utility3DVariables& rAuxVariables,
87  Parameters* pParameters,
88  ModelPart& rModelPart)
89  {
90  // Compute GaussPointsCells dimensions
91  this->ComputeCellMatrixDimensions(rAuxVariables,rModelPart);
92 
93  rAuxVariables.GaussPointCellMatrix.resize(rAuxVariables.NRows);
94  for(int i = 0; i < rAuxVariables.NRows; i++)
95  rAuxVariables.GaussPointCellMatrix[i].resize(rAuxVariables.NColumns);
96  for(int i = 0; i < rAuxVariables.NRows; i++)
97  {
98  for(int j = 0; j < rAuxVariables.NColumns; j++)
99  rAuxVariables.GaussPointCellMatrix[i][j].resize(rAuxVariables.NSections);
100  }
101 
102  // Locate GaussPoints inside CellMatrix
103  unsigned int NGPoints = 0;
104  GeometryData::IntegrationMethod MyIntegrationMethod;
105  const ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo();
106  array_1d<double,3> AuxGlobalCoordinates;
107  array_1d<double,3> AuxLocalCoordinates;
108 
109  Parameters& rParameters = *pParameters;
110  unsigned int NumBodySubModelParts = rParameters["body_domain_sub_model_part_list"].size();
111 
112  // Loop through all BodySubModelParts
113  for(unsigned int i = 0; i < NumBodySubModelParts; i++)
114  {
115  ModelPart& BodySubModelPart = rModelPart.GetSubModelPart(rParameters["body_domain_sub_model_part_list"][i].GetString());
116 
117  int NElems = static_cast<int>(BodySubModelPart.Elements().size());
118  ModelPart::ElementsContainerType::iterator el_begin = BodySubModelPart.ElementsBegin();
119 
120  // Loop through all body elements
121  #pragma omp parallel for private(MyIntegrationMethod,AuxGlobalCoordinates,AuxLocalCoordinates)
122  for(int j = 0; j < NElems; j++)
123  {
124  ModelPart::ElementsContainerType::iterator itElem = el_begin + j;
125 
126  Element::GeometryType& rGeom = itElem->GetGeometry();
127  MyIntegrationMethod = itElem->GetIntegrationMethod();
128  const Element::GeometryType::IntegrationPointsArrayType& IntegrationPoints = rGeom.IntegrationPoints(MyIntegrationMethod);
129  unsigned int NumGPoints = IntegrationPoints.size();
130  Vector detJContainer(NumGPoints);
131  rGeom.DeterminantOfJacobian(detJContainer,MyIntegrationMethod);
132  std::vector<ConstitutiveLaw::Pointer> ConstitutiveLawVector(NumGPoints);
133  itElem->CalculateOnIntegrationPoints(CONSTITUTIVE_LAW,ConstitutiveLawVector,CurrentProcessInfo);
134  int Row;
135  int Column;
136  int Section;
137 
138  // Loop through GaussPoints
139  for ( unsigned int GPoint = 0; GPoint < NumGPoints; GPoint++ )
140  {
141  // MyGaussPoint Coordinates
142  AuxLocalCoordinates[0] = IntegrationPoints[GPoint][0];
143  AuxLocalCoordinates[1] = IntegrationPoints[GPoint][1];
144  AuxLocalCoordinates[2] = IntegrationPoints[GPoint][2];
145  rGeom.GlobalCoordinates(AuxGlobalCoordinates,AuxLocalCoordinates); //Note: these are the CURRENT global coordinates
146 
147  // MyGaussPoint Weight
148  double Weight = detJContainer[GPoint]*IntegrationPoints[GPoint].Weight();
149 
150  // MyGaussPoint Row, Column and Section
151  Row = int((rAuxVariables.Y_max-AuxGlobalCoordinates[1])/rAuxVariables.RowSize);
152  Column = int((AuxGlobalCoordinates[0]-rAuxVariables.X_min)/rAuxVariables.ColumnSize);
153  Section = int((AuxGlobalCoordinates[2]-rAuxVariables.Z_min)/rAuxVariables.SectionSize);
154 
155  #pragma omp critical
156  {
157  // Push Back GaussPoint (Heap)
158  mGaussPointList.push_back( new GaussPoint(ConstitutiveLawVector[GPoint],AuxGlobalCoordinates,Weight) );
159  rAuxVariables.GaussPointCellMatrix[Row][Column][Section].push_back(mGaussPointList[NGPoints]);
160  NGPoints++;
161  }
162  }
163  }
164  }
165  }
166 
168 
170  Utility3DVariables& rAuxVariables,
171  Parameters* pParameters,
172  ModelPart& rModelPart)
173  {
174  int NGPoints = static_cast<int>(mGaussPointList.size());
175  double CharacteristicLength = (*pParameters)["characteristic_length"].GetDouble();
176 
177  // Loop through all Gauss Points
178  #pragma omp parallel for
179  for(int i = 0; i < NGPoints; i++)
180  {
181  GaussPoint& rMyGaussPoint = *(mGaussPointList[i]);
182 
183  double X_left = rMyGaussPoint.Coordinates[0] - CharacteristicLength;
184  double X_right = rMyGaussPoint.Coordinates[0] + CharacteristicLength;
185  double Y_top = rMyGaussPoint.Coordinates[1] + CharacteristicLength;
186  double Y_bot = rMyGaussPoint.Coordinates[1] - CharacteristicLength;
187  double Z_back = rMyGaussPoint.Coordinates[2] - CharacteristicLength;
188  double Z_front = rMyGaussPoint.Coordinates[2] + CharacteristicLength;
189 
190  int Column_left = int((X_left-rAuxVariables.X_min)/rAuxVariables.ColumnSize);
191  int Column_right = int((X_right-rAuxVariables.X_min)/rAuxVariables.ColumnSize);
192  int Row_top = int((rAuxVariables.Y_max-Y_top)/rAuxVariables.RowSize);
193  int Row_bot = int((rAuxVariables.Y_max-Y_bot)/rAuxVariables.RowSize);
194  int Section_back = int((Z_back-rAuxVariables.Z_min)/rAuxVariables.SectionSize);
195  int Section_front = int((Z_front-rAuxVariables.Z_min)/rAuxVariables.SectionSize);
196 
197  if(Column_left < 0) Column_left = 0;
198  if(Column_right >= rAuxVariables.NColumns) Column_right = rAuxVariables.NColumns-1;
199  if(Row_top < 0) Row_top = 0;
200  if(Row_bot >= rAuxVariables.NRows) Row_bot = rAuxVariables.NRows-1;
201  if(Section_back < 0) Section_back = 0;
202  if(Section_front >= rAuxVariables.NSections) Section_front = rAuxVariables.NSections-1;
203 
204  // Search GaussPoints neighbours
205  for(int s = Section_back; s <= Section_front; s++)
206  {
207  for(int k = Row_top; k <= Row_bot; k++)
208  {
209  for(int l = Column_left; l <= Column_right; l++)
210  {
211  for(unsigned int m = 0; m < rAuxVariables.GaussPointCellMatrix[k][l][s].size(); m++)
212  {
213  if ( (&rMyGaussPoint) != rAuxVariables.GaussPointCellMatrix[k][l][s][m] )
214  {
215  GaussPoint& rMyNeighbourPoint = *(rAuxVariables.GaussPointCellMatrix[k][l][s][m]);
216 
217  double Distance = sqrt((rMyNeighbourPoint.Coordinates[0]-rMyGaussPoint.Coordinates[0])*(rMyNeighbourPoint.Coordinates[0]-rMyGaussPoint.Coordinates[0]) +
218  (rMyNeighbourPoint.Coordinates[1]-rMyGaussPoint.Coordinates[1])*(rMyNeighbourPoint.Coordinates[1]-rMyGaussPoint.Coordinates[1]) +
219  (rMyNeighbourPoint.Coordinates[2]-rMyGaussPoint.Coordinates[2])*(rMyNeighbourPoint.Coordinates[2]-rMyGaussPoint.Coordinates[2]));
220 
221  if(Distance <= CharacteristicLength)
222  {
223  #pragma omp critical
224  {
225  rMyGaussPoint.NeighbourPoints.push_back(&rMyNeighbourPoint);
226  }
227  }
228  }
229  }
230  }
231  }
232  }
233  }
234  }
235 
237 
239  double& rDistance,
240  const GaussPoint& ReceiverPoint,
241  const GaussPoint& SourcePoint) override
242  {
243  rDistance = sqrt((SourcePoint.Coordinates[0]-ReceiverPoint.Coordinates[0])*(SourcePoint.Coordinates[0]-ReceiverPoint.Coordinates[0]) +
244  (SourcePoint.Coordinates[1]-ReceiverPoint.Coordinates[1])*(SourcePoint.Coordinates[1]-ReceiverPoint.Coordinates[1]) +
245  (SourcePoint.Coordinates[2]-ReceiverPoint.Coordinates[2])*(SourcePoint.Coordinates[2]-ReceiverPoint.Coordinates[2]));
246  }
247 
249 
250 private:
251 
252  void ComputeCellMatrixDimensions(
253  Utility3DVariables& rAuxVariables,
254  ModelPart& rModelPart)
255  {
256  // Compute X, Y and Z limits of the current geometry
257  unsigned int NumThreads = ParallelUtilities::GetNumThreads();
258  std::vector<double> X_max_partition(NumThreads);
259  std::vector<double> X_min_partition(NumThreads);
260  std::vector<double> Y_max_partition(NumThreads);
261  std::vector<double> Y_min_partition(NumThreads);
262  std::vector<double> Z_max_partition(NumThreads);
263  std::vector<double> Z_min_partition(NumThreads);
264 
265  const int NNodes = static_cast<int>(rModelPart.Nodes().size());
266  ModelPart::NodesContainerType::iterator node_begin = rModelPart.NodesBegin();
267 
268  #pragma omp parallel
269  {
270  int k = OpenMPUtils::ThisThread();
271 
272  X_max_partition[k] = node_begin->X();
273  X_min_partition[k] = X_max_partition[k];
274  Y_max_partition[k] = node_begin->Y();
275  Y_min_partition[k] = Y_max_partition[k];
276  Z_max_partition[k] = node_begin->Z();
277  Z_min_partition[k] = Z_max_partition[k];
278 
279  double X_me, Y_me, Z_me;
280 
281  #pragma omp for
282  for(int i = 0; i < NNodes; i++)
283  {
284  ModelPart::NodesContainerType::iterator itNode = node_begin + i;
285 
286  X_me = itNode->X();
287  Y_me = itNode->Y();
288  Z_me = itNode->Z();
289 
290  if( X_me > X_max_partition[k] ) X_max_partition[k] = X_me;
291  else if( X_me < X_min_partition[k] ) X_min_partition[k] = X_me;
292 
293  if( Y_me > Y_max_partition[k] ) Y_max_partition[k] = Y_me;
294  else if( Y_me < Y_min_partition[k] ) Y_min_partition[k] = Y_me;
295 
296  if( Z_me > Z_max_partition[k] ) Z_max_partition[k] = Z_me;
297  else if( Z_me < Z_min_partition[k] ) Z_min_partition[k] = Z_me;
298  }
299  }
300 
301  rAuxVariables.X_max = X_max_partition[0];
302  rAuxVariables.X_min = X_min_partition[0];
303  rAuxVariables.Y_max = Y_max_partition[0];
304  rAuxVariables.Y_min = Y_min_partition[0];
305  rAuxVariables.Z_max = Z_max_partition[0];
306  rAuxVariables.Z_min = Z_min_partition[0];
307 
308  for(unsigned int i=1; i < NumThreads; i++)
309  {
310  if(X_max_partition[i] > rAuxVariables.X_max) rAuxVariables.X_max = X_max_partition[i];
311  if(X_min_partition[i] < rAuxVariables.X_min) rAuxVariables.X_min = X_min_partition[i];
312  if(Y_max_partition[i] > rAuxVariables.Y_max) rAuxVariables.Y_max = Y_max_partition[i];
313  if(Y_min_partition[i] < rAuxVariables.Y_min) rAuxVariables.Y_min = Y_min_partition[i];
314  if(Z_max_partition[i] > rAuxVariables.Z_max) rAuxVariables.Z_max = Z_max_partition[i];
315  if(Z_min_partition[i] < rAuxVariables.Z_min) rAuxVariables.Z_min = Z_min_partition[i];
316  }
317 
318  // Calculate Average Element Length
319  double AverageElementLength = 0.0;
320 
321  int NElems = static_cast<int>(rModelPart.Elements().size());
322  ModelPart::ElementsContainerType::iterator el_begin = rModelPart.ElementsBegin();
323 
324  #pragma omp parallel for reduction(+:AverageElementLength)
325  for(int i = 0; i < NElems; i++)
326  {
327  ModelPart::ElementsContainerType::iterator itElem = el_begin + i;
328 
329  AverageElementLength += itElem->GetGeometry().Length();
330  }
331 
332  AverageElementLength = AverageElementLength/NElems;
333 
334  // Compute CellMatrix dimensions
335  rAuxVariables.NRows = int((rAuxVariables.Y_max-rAuxVariables.Y_min)/AverageElementLength);
336  rAuxVariables.NColumns = int((rAuxVariables.X_max-rAuxVariables.X_min)/AverageElementLength);
337  rAuxVariables.NSections = int((rAuxVariables.Z_max-rAuxVariables.Z_min)/AverageElementLength);
338  if(rAuxVariables.NRows <= 0) rAuxVariables.NRows = 1;
339  if(rAuxVariables.NColumns <= 0) rAuxVariables.NColumns = 1;
340  if(rAuxVariables.NSections <= 0) rAuxVariables.NSections = 1;
341  rAuxVariables.RowSize = (rAuxVariables.Y_max-rAuxVariables.Y_min)/rAuxVariables.NRows;
342  rAuxVariables.ColumnSize = (rAuxVariables.X_max-rAuxVariables.X_min)/rAuxVariables.NColumns;
343  rAuxVariables.SectionSize = (rAuxVariables.Z_max-rAuxVariables.Z_min)/rAuxVariables.NSections;
344  }
345 
346 }; // Class NonlocalDamage3DUtilities
347 
348 } // namespace Kratos.
349 
350 #endif /* KRATOS_NONLOCAL_DAMAGE_3D_UTILITIES defined */
IntegrationMethod
Definition: geometry_data.h:76
Geometry base class.
Definition: geometry.h:71
virtual CoordinatesArrayType & GlobalCoordinates(CoordinatesArrayType &rResult, CoordinatesArrayType const &LocalCoordinates) const
Definition: geometry.h:2377
std::vector< IntegrationPointType > IntegrationPointsArrayType
Definition: geometry.h:161
Vector & DeterminantOfJacobian(Vector &rResult) const
Definition: geometry.h:3154
const IntegrationPointsArrayType & IntegrationPoints() const
Definition: geometry.h:2284
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
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
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
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
Definition: nonlocal_damage_3D_utilities.hpp:26
NonlocalDamageUtilities::GaussPoint GaussPoint
Definition: nonlocal_damage_3D_utilities.hpp:30
KRATOS_CLASS_POINTER_DEFINITION(NonlocalDamage3DUtilities)
void ComputeNeighbourDistance(double &rDistance, const GaussPoint &ReceiverPoint, const GaussPoint &SourcePoint) override
Definition: nonlocal_damage_3D_utilities.hpp:238
void SearchGaussPointsNeighbours(Parameters *pParameters, ModelPart &rModelPart) override
Definition: nonlocal_damage_3D_utilities.hpp:62
void InitializeNonlocalSearch(Utility3DVariables &rAuxVariables, Parameters *pParameters, ModelPart &rModelPart)
Member Variables.
Definition: nonlocal_damage_3D_utilities.hpp:85
std::vector< GaussPoint * > mGaussPointList
Member Variables.
Definition: nonlocal_damage_utilities.hpp:125
void SearchNeighbours(Utility3DVariables &rAuxVariables, Parameters *pParameters, ModelPart &rModelPart)
Definition: nonlocal_damage_3D_utilities.hpp:169
NonlocalDamage3DUtilities()
Default Constructor.
Definition: nonlocal_damage_3D_utilities.hpp:53
~NonlocalDamage3DUtilities() override
Destructor.
Definition: nonlocal_damage_3D_utilities.hpp:58
Definition: nonlocal_damage_utilities.hpp:36
std::vector< GaussPoint * > mGaussPointList
Member Variables.
Definition: nonlocal_damage_utilities.hpp:125
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
SizeType size() const
This method returns the total size of the current array parameter.
Definition: kratos_parameters.cpp:993
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
#define KRATOS_INFO(label)
Definition: logger.h:250
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
REACTION_CHECK_STIFFNESS_FACTOR int
Definition: contact_structural_mechanics_application_variables.h:75
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17
def RowSize(_A)
Definition: custom_math.py:54
Definition: nonlocal_damage_utilities.hpp:41
std::vector< GaussPoint * > NeighbourPoints
Definition: nonlocal_damage_utilities.hpp:59
array_1d< double, 3 > Coordinates
Definition: nonlocal_damage_utilities.hpp:57