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_2D_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_2D_UTILITIES )
16 #define KRATOS_NONLOCAL_DAMAGE_2D_UTILITIES
17 
18 // Application includes
21 
22 namespace Kratos
23 {
24 
26 {
27 
28 public:
29 
32 
34 
35 private:
36 
37  struct Utility2DVariables
38  {
39  double X_max, X_min, Y_max, Y_min;
40  int NRows, NColumns;
41  double RowSize, ColumnSize;
42 
43  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 2D utility") << "Starting non-local search of neighbours ..." << std::endl;
65 
66  // Define necessary variables
67  Utility2DVariables 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 2D utility") << "... search of neighbours completed." << std::endl;
75  }
76 
78 
79 protected:
80 
82 
84 
86  Utility2DVariables& 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++) rAuxVariables.GaussPointCellMatrix[i].resize(rAuxVariables.NColumns);
95 
96  // Locate GaussPoints inside CellMatrix
97  unsigned int NGPoints = 0;
98  GeometryData::IntegrationMethod MyIntegrationMethod;
99  const ProcessInfo& CurrentProcessInfo = rModelPart.GetProcessInfo();
100  array_1d<double,3> AuxGlobalCoordinates;
101  array_1d<double,3> AuxLocalCoordinates;
102 
103  Parameters& rParameters = *pParameters;
104  unsigned int NumBodySubModelParts = rParameters["body_domain_sub_model_part_list"].size();
105 
106  // Loop through all BodySubModelParts
107  for(unsigned int i = 0; i < NumBodySubModelParts; i++)
108  {
109  ModelPart& BodySubModelPart = rModelPart.GetSubModelPart(rParameters["body_domain_sub_model_part_list"][i].GetString());
110 
111  int NElems = static_cast<int>(BodySubModelPart.Elements().size());
112  ModelPart::ElementsContainerType::iterator el_begin = BodySubModelPart.ElementsBegin();
113 
114  // Loop through all body elements
115  #pragma omp parallel for private(MyIntegrationMethod,AuxGlobalCoordinates,AuxLocalCoordinates)
116  for(int j = 0; j < NElems; j++)
117  {
118  ModelPart::ElementsContainerType::iterator itElem = el_begin + j;
119 
120  Element::GeometryType& rGeom = itElem->GetGeometry();
121  MyIntegrationMethod = itElem->GetIntegrationMethod();
122  const Element::GeometryType::IntegrationPointsArrayType& IntegrationPoints = rGeom.IntegrationPoints(MyIntegrationMethod);
123  unsigned int NumGPoints = IntegrationPoints.size();
124  Vector detJContainer(NumGPoints);
125  rGeom.DeterminantOfJacobian(detJContainer,MyIntegrationMethod);
126  std::vector<ConstitutiveLaw::Pointer> ConstitutiveLawVector(NumGPoints);
127  itElem->CalculateOnIntegrationPoints(CONSTITUTIVE_LAW,ConstitutiveLawVector,CurrentProcessInfo);
128  int Row;
129  int Column;
130 
131  // Loop through GaussPoints
132  for ( unsigned int GPoint = 0; GPoint < NumGPoints; GPoint++ )
133  {
134  // MyGaussPoint Coordinates
135  AuxLocalCoordinates[0] = IntegrationPoints[GPoint][0];
136  AuxLocalCoordinates[1] = IntegrationPoints[GPoint][1];
137  AuxLocalCoordinates[2] = IntegrationPoints[GPoint][2];
138  rGeom.GlobalCoordinates(AuxGlobalCoordinates,AuxLocalCoordinates); //Note: these are the CURRENT global coordinates
139 
140  // MyGaussPoint Weight
141  double Weight = detJContainer[GPoint]*IntegrationPoints[GPoint].Weight();
142 
143  // MyGaussPoint Row and Column
144  Row = int((rAuxVariables.Y_max-AuxGlobalCoordinates[1])/rAuxVariables.RowSize);
145  Column = int((AuxGlobalCoordinates[0]-rAuxVariables.X_min)/rAuxVariables.ColumnSize);
146 
147  #pragma omp critical
148  {
149  // Push Back GaussPoint (Heap)
150  mGaussPointList.push_back( new GaussPoint(ConstitutiveLawVector[GPoint],AuxGlobalCoordinates,Weight) );
151  rAuxVariables.GaussPointCellMatrix[Row][Column].push_back(mGaussPointList[NGPoints]);
152  NGPoints++;
153  }
154  }
155  }
156  }
157  }
158 
160 
162  Utility2DVariables& rAuxVariables,
163  Parameters* pParameters,
164  ModelPart& rModelPart)
165  {
166  int NGPoints = static_cast<int>(mGaussPointList.size());
167  double CharacteristicLength = (*pParameters)["characteristic_length"].GetDouble();
168 
169  // Loop through all Gauss Points
170  #pragma omp parallel for
171  for(int i = 0; i < NGPoints; i++)
172  {
173  GaussPoint& rMyGaussPoint = *(mGaussPointList[i]);
174 
175  double X_left = rMyGaussPoint.Coordinates[0] - CharacteristicLength;
176  double X_right = rMyGaussPoint.Coordinates[0] + CharacteristicLength;
177  double Y_top = rMyGaussPoint.Coordinates[1] + CharacteristicLength;
178  double Y_bot = rMyGaussPoint.Coordinates[1] - CharacteristicLength;
179 
180  int Column_left = int((X_left-rAuxVariables.X_min)/rAuxVariables.ColumnSize);
181  int Column_right = int((X_right-rAuxVariables.X_min)/rAuxVariables.ColumnSize);
182  int Row_top = int((rAuxVariables.Y_max-Y_top)/rAuxVariables.RowSize);
183  int Row_bot = int((rAuxVariables.Y_max-Y_bot)/rAuxVariables.RowSize);
184 
185  if(Column_left < 0) Column_left = 0;
186  if(Column_right >= rAuxVariables.NColumns) Column_right = rAuxVariables.NColumns-1;
187  if(Row_top < 0) Row_top = 0;
188  if(Row_bot >= rAuxVariables.NRows) Row_bot = rAuxVariables.NRows-1;
189 
190  // Search GaussPoints neighbours
191  for(int j = Row_top; j <= Row_bot; j++)
192  {
193  for(int k = Column_left; k <= Column_right; k++)
194  {
195  for(unsigned int l = 0; l < rAuxVariables.GaussPointCellMatrix[j][k].size(); l++)
196  {
197  if ( (&rMyGaussPoint) != rAuxVariables.GaussPointCellMatrix[j][k][l] )
198  {
199  GaussPoint& rMyNeighbourPoint = *(rAuxVariables.GaussPointCellMatrix[j][k][l]);
200 
201  double Distance = sqrt((rMyNeighbourPoint.Coordinates[0]-rMyGaussPoint.Coordinates[0])*(rMyNeighbourPoint.Coordinates[0]-rMyGaussPoint.Coordinates[0]) +
202  (rMyNeighbourPoint.Coordinates[1]-rMyGaussPoint.Coordinates[1])*(rMyNeighbourPoint.Coordinates[1]-rMyGaussPoint.Coordinates[1]));
203 
204  if(Distance <= CharacteristicLength)
205  {
206  #pragma omp critical
207  {
208  rMyGaussPoint.NeighbourPoints.push_back(&rMyNeighbourPoint);
209  }
210  }
211  }
212  }
213  }
214  }
215  }
216  }
217 
219 
221  double& rDistance,
222  const GaussPoint& ReceiverPoint,
223  const GaussPoint& SourcePoint) override
224  {
225  rDistance = sqrt((SourcePoint.Coordinates[0]-ReceiverPoint.Coordinates[0])*(SourcePoint.Coordinates[0]-ReceiverPoint.Coordinates[0]) +
226  (SourcePoint.Coordinates[1]-ReceiverPoint.Coordinates[1])*(SourcePoint.Coordinates[1]-ReceiverPoint.Coordinates[1]));
227  }
228 
230 
231 private:
232 
233  void ComputeCellMatrixDimensions(
234  Utility2DVariables& rAuxVariables,
235  ModelPart& rModelPart)
236  {
237  // Compute X and Y limits of the current geometry
238  unsigned int NumThreads = ParallelUtilities::GetNumThreads();
239  std::vector<double> X_max_partition(NumThreads);
240  std::vector<double> X_min_partition(NumThreads);
241  std::vector<double> Y_max_partition(NumThreads);
242  std::vector<double> Y_min_partition(NumThreads);
243 
244  const int NNodes = static_cast<int>(rModelPart.Nodes().size());
245  ModelPart::NodesContainerType::iterator node_begin = rModelPart.NodesBegin();
246 
247  #pragma omp parallel
248  {
249  int k = OpenMPUtils::ThisThread();
250 
251  X_max_partition[k] = node_begin->X();
252  X_min_partition[k] = X_max_partition[k];
253  Y_max_partition[k] = node_begin->Y();
254  Y_min_partition[k] = Y_max_partition[k];
255 
256  double X_me, Y_me;
257 
258  #pragma omp for
259  for(int i = 0; i < NNodes; i++)
260  {
261  ModelPart::NodesContainerType::iterator itNode = node_begin + i;
262 
263  X_me = itNode->X();
264  Y_me = itNode->Y();
265 
266  if( X_me > X_max_partition[k] ) X_max_partition[k] = X_me;
267  else if( X_me < X_min_partition[k] ) X_min_partition[k] = X_me;
268 
269  if( Y_me > Y_max_partition[k] ) Y_max_partition[k] = Y_me;
270  else if( Y_me < Y_min_partition[k] ) Y_min_partition[k] = Y_me;
271  }
272  }
273 
274  rAuxVariables.X_max = X_max_partition[0];
275  rAuxVariables.X_min = X_min_partition[0];
276  rAuxVariables.Y_max = Y_max_partition[0];
277  rAuxVariables.Y_min = Y_min_partition[0];
278 
279  for(unsigned int i=1; i < NumThreads; i++)
280  {
281  if(X_max_partition[i] > rAuxVariables.X_max) rAuxVariables.X_max = X_max_partition[i];
282  if(X_min_partition[i] < rAuxVariables.X_min) rAuxVariables.X_min = X_min_partition[i];
283  if(Y_max_partition[i] > rAuxVariables.Y_max) rAuxVariables.Y_max = Y_max_partition[i];
284  if(Y_min_partition[i] < rAuxVariables.Y_min) rAuxVariables.Y_min = Y_min_partition[i];
285  }
286 
287  // Calculate Average Element Length
288  double AverageElementLength = 0.0;
289 
290  int NElems = static_cast<int>(rModelPart.Elements().size());
291  ModelPart::ElementsContainerType::iterator el_begin = rModelPart.ElementsBegin();
292 
293  #pragma omp parallel for reduction(+:AverageElementLength)
294  for(int i = 0; i < NElems; i++)
295  {
296  ModelPart::ElementsContainerType::iterator itElem = el_begin + i;
297 
298  AverageElementLength += itElem->GetGeometry().Length();
299  }
300 
301  AverageElementLength = AverageElementLength/NElems;
302 
303  // Compute CellMatrix dimensions
304  rAuxVariables.NRows = int((rAuxVariables.Y_max-rAuxVariables.Y_min)/(AverageElementLength));
305  rAuxVariables.NColumns = int((rAuxVariables.X_max-rAuxVariables.X_min)/(AverageElementLength));
306  if(rAuxVariables.NRows <= 0) rAuxVariables.NRows = 1;
307  if(rAuxVariables.NColumns <= 0) rAuxVariables.NColumns = 1;
308  rAuxVariables.RowSize = (rAuxVariables.Y_max-rAuxVariables.Y_min)/rAuxVariables.NRows;
309  rAuxVariables.ColumnSize = (rAuxVariables.X_max-rAuxVariables.X_min)/rAuxVariables.NColumns;
310  }
311 
312 }; // Class NonlocalDamage2DUtilities
313 
314 } // namespace Kratos.
315 
316 #endif /* KRATOS_NONLOCAL_DAMAGE_2D_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_2D_utilities.hpp:26
void SearchGaussPointsNeighbours(Parameters *pParameters, ModelPart &rModelPart) override
Definition: nonlocal_damage_2D_utilities.hpp:62
void InitializeNonlocalSearch(Utility2DVariables &rAuxVariables, Parameters *pParameters, ModelPart &rModelPart)
Member Variables.
Definition: nonlocal_damage_2D_utilities.hpp:85
KRATOS_CLASS_POINTER_DEFINITION(NonlocalDamage2DUtilities)
~NonlocalDamage2DUtilities() override
Destructor.
Definition: nonlocal_damage_2D_utilities.hpp:58
std::vector< GaussPoint * > mGaussPointList
Member Variables.
Definition: nonlocal_damage_utilities.hpp:125
void SearchNeighbours(Utility2DVariables &rAuxVariables, Parameters *pParameters, ModelPart &rModelPart)
Definition: nonlocal_damage_2D_utilities.hpp:161
void ComputeNeighbourDistance(double &rDistance, const GaussPoint &ReceiverPoint, const GaussPoint &SourcePoint) override
Definition: nonlocal_damage_2D_utilities.hpp:220
NonlocalDamageUtilities::GaussPoint GaussPoint
Definition: nonlocal_damage_2D_utilities.hpp:30
NonlocalDamage2DUtilities()
Default Constructor.
Definition: nonlocal_damage_2D_utilities.hpp:53
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
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