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.
discrete_particle_configure.h
Go to the documentation of this file.
1 //
2 // Author: Miquel Santasusana msantasusana@cimne.upc.edu, Guillermo Casas gcasas@cimne.upc.edu
3 //
4 
5 
6 
7 #if !defined(KRATOS_DISCRETE_PARTICLE__CONFIGURE_INCLUDED)
8 #define KRATOS_DISCRETE_PARTICLE__CONFIGURE_INCLUDED
9 
10 // System includes
11 #include <string>
12 #include <iostream>
13 #include <cmath>
14 
15 // Kratos includes
17 #include "includes/dem_variables.h"
20 
21 namespace Kratos
22 {
23 
26 
30 
34 
38 
42 
43 
44 template <std::size_t TDimension>
46 {
47 
48 public:
49 
50  enum {
51  Dimension = TDimension,
52  DIMENSION = TDimension,
53  MAX_LEVEL = 16,
54  MIN_LEVEL = 2
55  };
56 
59 
61 
66 
67  typedef ContainerType::value_type PointerType;
68  typedef ContainerType::iterator IteratorType;
69  typedef ElementsContainerType::iterator ElementIteratorType;
70 
72 // typedef SearchType::ResultDistanceType::ContainerType ResultDistanceType;
73 
74  typedef ResultContainerType::iterator ResultIteratorType;
75  typedef std::vector<double>::iterator DistanceIteratorType;
76 
79  }
80 
81  static void SetDomain(const double domain_min_x, const double domain_min_y, const double domain_min_z,
82  const double domain_max_x, const double domain_max_y, const double domain_max_z)
83  {
84  mDomainMin[0] = domain_min_x;
85  mDomainMin[1] = domain_min_y;
86  mDomainMin[2] = domain_min_z;
87  mDomainMax[0] = domain_max_x;
88  mDomainMax[1] = domain_max_y;
89  mDomainMax[2] = domain_max_z;
90  SetPeriods(domain_max_x - domain_min_x, domain_max_y - domain_min_y, domain_max_z - domain_min_z);
91  mDomainIsPeriodic = (mDomainPeriods[0] >= 0 && mDomainPeriods[1] >= 0 && mDomainPeriods[2] >= 0);
92 
93  }
94 
95  static void SetPeriods(double domain_period_x, double domain_period_y, double domain_period_z)
96  {
97  mDomainPeriods[0] = domain_period_x;
98  mDomainPeriods[1] = domain_period_y;
99  mDomainPeriods[2] = domain_period_z;
100  }
101 
102  static double* GetMinPoint()
103  {
104  return mDomainMin;
105  }
106 
107  static double* GetMaxPoint()
108  {
109  return mDomainMax;
110  }
111 
112  static void GetPeriods(double periods[3])
113  {
114  periods[0] = mDomainPeriods[0];
115  periods[1] = mDomainPeriods[1];
116  periods[2] = mDomainPeriods[2];
117  }
118 
119  static bool GetDomainPeriodicity()
120  {
121  return mDomainIsPeriodic;
122  }
123 
124  static inline void TransformToClosestPeriodicCoordinates(const double target[3], double base_coordinates[3])
125  {
126  TransformToClosestPeriodicCoordinates(target, base_coordinates, mDomainPeriods);
127  }
128 
129  static inline void TransformToClosestPeriodicCoordinates(const array_1d<double,3>& target, array_1d<double,3>& base_coordinates)
130  {
131  TransformToClosestPeriodicCoordinates(target, base_coordinates, mDomainPeriods);
132  }
133 
134  static inline void TransformToClosestPeriodicCoordinates(const double target[3], double base_coordinates[3], const double periods[3])
135  {
136  for (unsigned int i = 0; i < 3; ++i){
137  double incr_i = target[i] - base_coordinates[i];
138 
139  if (fabs(incr_i) > 0.5 * periods[i]){
140  base_coordinates[i] += GetSign(incr_i) * periods[i];
141  }
142  }
143 
144  }
145 
146  static inline void TransformToClosestPeriodicCoordinates(const array_1d<double,3>& target, array_1d<double,3>& base_coordinates, const double periods[3])
147  {
148  for (unsigned int i = 0; i < 3; ++i){
149  double incr_i = target[i] - base_coordinates[i];
150 
151  if (fabs(incr_i) > 0.5 * periods[i]){
152  base_coordinates[i] += GetSign(incr_i) * periods[i];
153  }
154  }
155 
156  }
157 
158  static inline void GetBoxCenter(double box_center[3], const double min_point[3], const double max_point[3])
159  {
160  for (unsigned int i = 0; i < 3; ++i){
161  box_center[i] = 0.5 * (min_point[i] + max_point[i]);
162 
163  if (min_point[i] > max_point[i]){ // the box is broken by the boundary in this dimension: ] x * [ (outside), ] x [ * (inside)
164  const double& min = mDomainMin[i];
165  const double& max = mDomainMax[i];
166  box_center[i] += 0.5 * (max - min); // The center of the box and of its complementary are always half a domain period apart: |..]..x..[...*.| (our bet: we assume we should ADD to go from x to *)
167  if (box_center[i] > max){ // we made a mistake, we should have gone the opposite way
168  box_center[i] -= max - min;
169  }
170  }
171  }
172  }
173 
177 
178 //******************************************************************************************************************
179 
180  static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint)
181  {
182  noalias(rHighPoint) = rObject->GetGeometry()[0];
183  noalias(rLowPoint) = rObject->GetGeometry()[0];
184 
185  SphericParticle* p_particle = static_cast<SphericParticle*>(&*rObject);
186  double radius = p_particle->GetSearchRadius();
187 
188  for(std::size_t i = 0; i < 3; ++i)
189  {
190  rLowPoint[i] += -radius;
191  rHighPoint[i] += radius;
192  }
193  }
194 
195  static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint, const double& Radius)
196  {
197  (void) Radius;
198  CalculateBoundingBox(rObject, rLowPoint, rHighPoint);
199  }
200 
201  static inline void CalculateCenter(const PointerType& rObject, PointType& rCenter)
202  {
203  rCenter = rObject->GetGeometry()[0];
204  }
205 
206  //******************************************************************************************************************
207 
208  static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2)
209  {
210  double rObj_2_to_rObj_1[3];
211  PointType& point_1 = rObj_1->GetGeometry()[0];
212  const double coors_1[3] = {point_1[0], point_1[1], point_1[2]};
213  PointType& point_2 = rObj_2->GetGeometry()[0];
214  const double coors_2[3] = {point_2[0], point_2[1], point_2[2]};
215 
216  PeriodicSubstract(coors_1, coors_2, rObj_2_to_rObj_1);
217 
218  const double distance_2 = DEM_INNER_PRODUCT_3(rObj_2_to_rObj_1, rObj_2_to_rObj_1);
219 
220  SphericParticle* p_particle1 = static_cast<SphericParticle*>(&*rObj_1);
221  SphericParticle* p_particle2 = static_cast<SphericParticle*>(&*rObj_2);
222  const double radius_sum = p_particle1->GetSearchRadius() + p_particle2->GetSearchRadius();
223  const bool intersect = floatle(distance_2, std::pow(radius_sum, 2));
224  return intersect;
225  }
226 
227  static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2, const double& radius_1)
228  {
229  return Intersection(rObj_1, rObj_2);
230  }
231 
232  //******************************************************************************************************************
233 
234  static inline bool IntersectionBox(const PointerType& rObject, const PointType& rLowPoint, const PointType& rHighPoint)
235  {
236  const array_1d<double, 3>& center_of_particle = rObject->GetGeometry()[0];
237 
238  SphericParticle* p_particle = static_cast<SphericParticle*>(&*rObject);
239  const double& radius = p_particle->GetSearchRadius();
240 
241  bool intersect;
242 
243  if (mDomainIsPeriodic){
244  double expanded_box_min[3];
245  double expanded_box_max[3];
246 
247  for (unsigned int i = 0; i < 3; ++i){
248  expanded_box_min[i] = rLowPoint[i] - radius;
249  expanded_box_max[i] = rHighPoint[i] + radius;
250  }
251 
252  double box_center[3];
253  GetBoxCenter(box_center, expanded_box_min, expanded_box_max);
254  //double box_center[3] = {0.5 * (rLowPoint[0] + rHighPoint[0]), 0.5 * (rLowPoint[1] + rHighPoint[1]), 0.5 * (rLowPoint[2] + rHighPoint[2])};
255  double representative_center_of_particle[3] = {center_of_particle[0],
256  center_of_particle[1],
257  center_of_particle[2]};
258  TransformToClosestPeriodicCoordinates(box_center, representative_center_of_particle);
259 
260  for (unsigned int i = 0; i < 3; ++i){
261  const bool is_broken = rLowPoint[i] > rHighPoint[i];
262 
263  if (is_broken){ // i.e., we have | ] [ | in this direction
264  intersect = floatge(expanded_box_min[i], representative_center_of_particle[i])
265  && floatle(expanded_box_max[i], representative_center_of_particle[i]);
266  }
267 
268  else { // i.e., we have | [ ] | in this direction
269  intersect = floatle(expanded_box_min[i], representative_center_of_particle[i])
270  && floatge(expanded_box_max[i], representative_center_of_particle[i]);
271  }
272  }
273  }
274 
275  else {
276  for (unsigned int i = 0; i < 3; ++i){
277  intersect = floatle(rLowPoint[i] - radius, center_of_particle[i])
278  && floatge(rHighPoint[i] + radius, center_of_particle[i]);
279  }
280  }
281 
282  return intersect;
283  }
284 
285  static inline bool IntersectionBox(const PointerType& rObject, const PointType& rLowPoint, const PointType& rHighPoint, const double& Radius)
286  {
287  return IntersectionBox(rObject, rLowPoint, rHighPoint);
288  }
289 
290  static inline void Distance(const PointerType& rObj_1, const PointerType& rObj_2, double& distance)
291  {
292  PointType& point_1 = rObj_1->GetGeometry()[0];
293  const double coors_1[3] = {point_1[0], point_1[1], point_1[2]};
294  PointType& point_2 = rObj_2->GetGeometry()[0];
295  const double coors_2[3] = {point_2[0], point_2[1], point_2[2]};
296  double rObj_2_to_rObj_1[3];
297  PeriodicSubstract(coors_1, coors_2, rObj_2_to_rObj_1);
298  distance = DEM_MODULUS_3(rObj_2_to_rObj_1);
299  }
300 
301  static inline double GetObjectRadius(const PointerType& rObject, const double& Radius)
302  {
303  return GetObjectRadius(rObject);
304  }
305 
306  static inline double GetObjectRadius(const PointerType& rObject)
307  {
308  SphericParticle* p_particle = static_cast<SphericParticle*>(&*rObject);
309  return p_particle->GetSearchRadius();
310  }
311 
312  static double mDomainPeriods[3];
313  static double mDomainMin[3];
314  static double mDomainMax[3];
315  static bool mDomainIsPeriodic;
316 
318  virtual std::string Info() const {return " Spatial Containers Configure for Discrete Particles"; }
319 
321  virtual void PrintInfo(std::ostream& rOStream) const {}
322 
324  virtual void PrintData(std::ostream& rOStream) const {}
325 
330 
331 protected:
334 
335 
339 
343 
347 
351 
355 
359 
361 
362 private:
365 
369 
373 
377 
378  static inline int GetSign(const double value)
379  {
380  return (0.0 < value) - (value < 0.0);
381  }
382 
383  static inline void PeriodicSubstract(const double a[3], const double b[3], double c[3])
384  {
385  for (unsigned int i = 0; i < 3; ++i){
386  c[i] = a[i] - b[i];
387  }
388 
389  if (mDomainIsPeriodic){ // Periods have been set (the domain is periodic)
390  for (unsigned int i = 0; i < 3; ++i){
391  if (std::fabs(c[i]) > 0.5 * mDomainPeriods[i]){ // the objects are closer through the boundary
392  c[i] -= GetSign(c[i]) * mDomainPeriods[i];
393  }
394  }
395  }
396  }
397 
398  static inline bool floateq(double a, double b) {
399  return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
400  }
401 
402  static inline bool floatle(double a, double b) {
403  return a < b || std::fabs(a - b) < std::numeric_limits<double>::epsilon();
404  }
405 
406  static inline bool floatge(double a, double b) {
407  return a > b || std::fabs(a - b) < std::numeric_limits<double>::epsilon();
408  }
409 
413 
417 
421 
423  DiscreteParticleConfigure& operator=(DiscreteParticleConfigure const& rOther);
424 
427 
429 
430  }; // Class ParticleConfigure
431 
433 
436 
440 
442  template <std::size_t TDimension>
443  inline std::istream& operator >> (std::istream& rIStream, DiscreteParticleConfigure<TDimension> & rThis){
444  return rIStream;
445  }
446 
448  template <std::size_t TDimension>
449  inline std::ostream& operator << (std::ostream& rOStream, const DiscreteParticleConfigure<TDimension>& rThis){
450  rThis.PrintInfo(rOStream);
451  rOStream << std::endl;
452  rThis.PrintData(rOStream);
453 
454  return rOStream;
455  }
456 
459 template <std::size_t TDimension>
460 double DiscreteParticleConfigure<TDimension>::mDomainPeriods[] = {-1.0, -1.0, -1.0};
461 template <std::size_t TDimension>
462 double DiscreteParticleConfigure<TDimension>::mDomainMin[] = {0.0, 0.0, 0.0};
463 template <std::size_t TDimension>
464 double DiscreteParticleConfigure<TDimension>::mDomainMax[] = {-1.0, -1.0, -1.0};
465 template <std::size_t TDimension>
467 
468 } // namespace Kratos.
469 #endif /* DISCRETE_PARTICLE_CONFIGURE_H */
#define DEM_MODULUS_3(a)
Definition: DEM_application_variables.h:29
#define DEM_INNER_PRODUCT_3(a, b)
Definition: DEM_application_variables.h:31
Definition: discrete_particle_configure.h:46
ContainerType::iterator IteratorType
Definition: discrete_particle_configure.h:68
SearchType::PointType PointType
Definition: discrete_particle_configure.h:62
SearchType::NodesContainerType NodesContainerType
Definition: discrete_particle_configure.h:65
DiscreteParticleConfigure()
Definition: discrete_particle_configure.h:77
static void Distance(const PointerType &rObj_1, const PointerType &rObj_2, double &distance)
Definition: discrete_particle_configure.h:290
static void TransformToClosestPeriodicCoordinates(const double target[3], double base_coordinates[3], const double periods[3])
Definition: discrete_particle_configure.h:134
@ DIMENSION
Definition: discrete_particle_configure.h:52
@ MAX_LEVEL
Definition: discrete_particle_configure.h:53
@ MIN_LEVEL
Definition: discrete_particle_configure.h:54
@ Dimension
Definition: discrete_particle_configure.h:51
ResultContainerType::iterator ResultIteratorType
Definition: discrete_particle_configure.h:74
static double mDomainPeriods[3]
Definition: discrete_particle_configure.h:312
static double mDomainMax[3]
Definition: discrete_particle_configure.h:314
static void TransformToClosestPeriodicCoordinates(const array_1d< double, 3 > &target, array_1d< double, 3 > &base_coordinates)
Definition: discrete_particle_configure.h:129
static void GetBoxCenter(double box_center[3], const double min_point[3], const double max_point[3])
Definition: discrete_particle_configure.h:158
static void TransformToClosestPeriodicCoordinates(const array_1d< double, 3 > &target, array_1d< double, 3 > &base_coordinates, const double periods[3])
Definition: discrete_particle_configure.h:146
KRATOS_CLASS_POINTER_DEFINITION(DiscreteParticleConfigure)
Pointer definition of SpatialContainersConfigure.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: discrete_particle_configure.h:321
ContainerType::value_type PointerType
Definition: discrete_particle_configure.h:67
static void CalculateBoundingBox(const PointerType &rObject, PointType &rLowPoint, PointType &rHighPoint)
Definition: discrete_particle_configure.h:180
static bool Intersection(const PointerType &rObj_1, const PointerType &rObj_2, const double &radius_1)
Definition: discrete_particle_configure.h:227
std::vector< double >::iterator DistanceIteratorType
Definition: discrete_particle_configure.h:75
static bool GetDomainPeriodicity()
Definition: discrete_particle_configure.h:119
ElementsContainerType::iterator ElementIteratorType
Definition: discrete_particle_configure.h:69
static void CalculateBoundingBox(const PointerType &rObject, PointType &rLowPoint, PointType &rHighPoint, const double &Radius)
Definition: discrete_particle_configure.h:195
static void GetPeriods(double periods[3])
Definition: discrete_particle_configure.h:112
static bool IntersectionBox(const PointerType &rObject, const PointType &rLowPoint, const PointType &rHighPoint, const double &Radius)
Definition: discrete_particle_configure.h:285
static void TransformToClosestPeriodicCoordinates(const double target[3], double base_coordinates[3])
Definition: discrete_particle_configure.h:124
static double GetObjectRadius(const PointerType &rObject, const double &Radius)
Definition: discrete_particle_configure.h:301
virtual ~DiscreteParticleConfigure()
Definition: discrete_particle_configure.h:78
SearchType::ElementsContainerType::ContainerType ContainerType
Definition: discrete_particle_configure.h:63
static bool IntersectionBox(const PointerType &rObject, const PointType &rLowPoint, const PointType &rHighPoint)
Definition: discrete_particle_configure.h:234
static double * GetMinPoint()
Definition: discrete_particle_configure.h:102
static void SetPeriods(double domain_period_x, double domain_period_y, double domain_period_z)
Definition: discrete_particle_configure.h:95
static double GetObjectRadius(const PointerType &rObject)
Definition: discrete_particle_configure.h:306
static bool mDomainIsPeriodic
Definition: discrete_particle_configure.h:315
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: discrete_particle_configure.h:324
static double mDomainMin[3]
Definition: discrete_particle_configure.h:313
SearchType::ElementsContainerType ElementsContainerType
Definition: discrete_particle_configure.h:64
static double * GetMaxPoint()
Definition: discrete_particle_configure.h:107
SpatialSearch SearchType
Definition: discrete_particle_configure.h:60
virtual std::string Info() const
Turn back information as a string.
Definition: discrete_particle_configure.h:318
SearchType::ElementsContainerType::ContainerType ResultContainerType
Definition: discrete_particle_configure.h:71
static bool Intersection(const PointerType &rObj_1, const PointerType &rObj_2)
Definition: discrete_particle_configure.h:208
static void SetDomain(const double domain_min_x, const double domain_min_y, const double domain_min_z, const double domain_max_x, const double domain_max_y, const double domain_max_z)
Definition: discrete_particle_configure.h:81
static void CalculateCenter(const PointerType &rObject, PointType &rCenter)
Definition: discrete_particle_configure.h:201
Point class.
Definition: point.h:59
This class is used to search for elements, conditions and nodes in a given model part.
Definition: spatial_search.h:50
ModelPart::NodesContainerType NodesContainerType
Nodes classes.
Definition: spatial_search.h:80
ModelPart::ElementsContainerType ElementsContainerType
Elements classes.
Definition: spatial_search.h:85
Definition: spheric_particle.h:31
virtual double GetSearchRadius()
Definition: spheric_particle.cpp:2201
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
a
Definition: generate_stokes_twofluid_element.py:77
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
float radius
Definition: mesh_to_mdpa_converter.py:18
distance_2
Definition: sp_statistics.py:71
integer i
Definition: TensorModule.f:17
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247