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.
node_configure.h
Go to the documentation of this file.
1 //
2 // Author: Miquel Santasusana msantasusana@cimne.upc.edu
3 //
4 
5 
6 
7 #if !defined(KRATOS_NODE_CONFIGURE_INCLUDED)
8 #define KRATOS_NODE_CONFIGURE_INCLUDED
9 
10 // System includes
11 #include <string>
12 #include <iostream>
13 #include <cmath>
14 
15 // Kratos includes
17 
18 /* Timer defines */
19 #include "utilities/timer.h"
20 
21 namespace Kratos
22 {
23 
24 template <std::size_t TDimension>
25 class NodeConfigure
26 {
27 
28 public:
29 
30  enum {
31  Dimension = TDimension,
32  DIMENSION = TDimension,
33  MAX_LEVEL = 16,
34  MIN_LEVEL = 2
35  };
36 
39 
41 
44  typedef SearchType::NodesContainerType NodesContainerType; // * Comentar -> Create_and_destroy.h
45 
47  typedef ContainerType::value_type PointerType;
48  typedef ContainerType::iterator IteratorType;
49 
51 // typedef SearchType::ResultDistanceType::ContainerType ResultDistanceType;
52 
53  typedef ResultContainerType::iterator ResultIteratorType;
54  typedef std::vector<double>::iterator DistanceIteratorType;
55 
57  virtual ~NodeConfigure(){}
58 
59  static void SetDomain(const double domain_min_x, const double domain_min_y, const double domain_min_z,
60  const double domain_max_x, const double domain_max_y, const double domain_max_z)
61  {
62  mDomainMin[0] = domain_min_x;
63  mDomainMin[1] = domain_min_y;
64  mDomainMin[2] = domain_min_z;
65  mDomainMax[0] = domain_max_x;
66  mDomainMax[1] = domain_max_y;
67  mDomainMax[2] = domain_max_z;
68  SetPeriods(domain_max_x - domain_min_x, domain_max_y - domain_min_y, domain_max_z - domain_min_z);
69  mDomainIsPeriodic = (mDomainPeriods[0] >= 0 && mDomainPeriods[1] >= 0 && mDomainPeriods[2] >= 0);
70  }
71 
72  static void SetPeriods(double domain_period_x, double domain_period_y, double domain_period_z)
73  {
74  mDomainPeriods[0] = domain_period_x;
75  mDomainPeriods[1] = domain_period_y;
76  mDomainPeriods[2] = domain_period_z;
77  }
78 
79  static double* GetMinPoint()
80  {
81  return mDomainMin;
82  }
83 
84  static double* GetMaxPoint()
85  {
86  return mDomainMax;
87  }
88 
89  static void GetPeriods(double periods[3])
90  {
91  periods[0] = mDomainPeriods[0];
92  periods[1] = mDomainPeriods[1];
93  periods[2] = mDomainPeriods[2];
94  }
95 
96  static bool GetDomainPeriodicity()
97  {
98  return mDomainIsPeriodic;
99  }
100 
101  static inline void TransformToClosestPeriodicCoordinates(const double target[3], double base_coordinates[3])
102  {
103  TransformToClosestPeriodicCoordinates(target, base_coordinates, mDomainPeriods);
104  }
105 
106  static inline void TransformToClosestPeriodicCoordinates(const array_1d<double,3>& target, array_1d<double,3>& base_coordinates)
107  {
108  TransformToClosestPeriodicCoordinates(target, base_coordinates, mDomainPeriods);
109  }
110 
111  static inline void TransformToClosestPeriodicCoordinates(const double target[3], double base_coordinates[3], const double periods[3])
112  {
113  for (unsigned int i = 0; i < 3; ++i){
114  const double incr_i = target[i] - base_coordinates[i];
115 
116  if (std::abs(incr_i) > 0.5 * periods[i]){
117  base_coordinates[i] += GetSign(incr_i) * periods[i];
118  }
119  }
120  }
121 
122  static inline void TransformToClosestPeriodicCoordinates(const array_1d<double,3>& target, array_1d<double,3>& base_coordinates, const double periods[3])
123  {
124  for (unsigned int i = 0; i < 3; ++i){
125  const double incr_i = target[i] - base_coordinates[i];
126 
127  if (std::abs(incr_i) > 0.5 * periods[i]){
128  base_coordinates[i] += GetSign(incr_i) * periods[i];
129  }
130  }
131  }
132 
133  static inline void GetBoxCenter(double box_center[3], const double min_point[3], const double max_point[3])
134  {
135  for (unsigned int i = 0; i < 3; ++i){
136  box_center[i] = 0.5 * (min_point[i] + max_point[i]);
137 
138  if (min_point[i] > max_point[i]){ // the box is broken by the boundary in this dimension: ] x * [ (outside), ] x [ * (inside)
139  const double& min = mDomainMin[i];
140  const double& max = mDomainMax[i];
141  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 *)
142  if (box_center[i] > max){ // we made a mistake, we should have gone the opposite way
143  box_center[i] -= max - min;
144  }
145  }
146  }
147  }
148 
149  static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint)
150  {
151  noalias(rHighPoint) = *rObject;
152  noalias(rLowPoint) = *rObject;
153  }
154 
155  static inline void CalculateBoundingBox(const PointerType& rObject, PointType& rLowPoint, PointType& rHighPoint, const double& Radius)
156  {
157  for(std::size_t i = 0; i < 3; ++i){
158  rLowPoint[i] = (*rObject)[i] - Radius;
159  rHighPoint[i] = (*rObject)[i] + Radius;
160  }
161  }
162 
163  static inline void CalculateCenter(const PointerType& rObject, PointType& rCenter)
164  {
165  noalias(rCenter) = *rObject;
166  }
167 
168  //******************************************************************************************************************
169 
170  static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2)
171  {
172  return false;
173  }
174 
175  static inline bool Intersection(const PointerType& rObj_1, const PointerType& rObj_2, const double& Radius)
176  {
177  double distance_squared;
178  SquaredDistance(rObj_1, rObj_2, distance_squared);
179  const bool intersect = floatle(distance_squared, std::pow(Radius, 2));
180  return intersect;
181  }
182 
183  static inline bool IntersectionBox(const PointerType& rObject, const PointType& rLowPoint, const PointType& rHighPoint)
184  {
185  return IntersectionBox(rObject, rLowPoint, rHighPoint, 0);
186  }
187 
188  static inline bool IntersectionBox(const PointerType& rObject, const PointType& rLowPoint, const PointType& rHighPoint, const double Radius)
189  {
190  const array_1d<double, 3>& center_of_particle = *rObject;
191 
192  bool intersect;
193 
194  if (mDomainIsPeriodic){
195  double expanded_box_min[3];
196  double expanded_box_max[3];
197 
198  for (unsigned int i = 0; i < 3; ++i){
199  expanded_box_min[i] = rLowPoint[i] - Radius;
200  expanded_box_max[i] = rHighPoint[i] + Radius;
201  }
202 
203  double box_center[3];
204  GetBoxCenter(box_center, expanded_box_min, expanded_box_max);
205  //double box_center[3] = {0.5 * (rLowPoint[0] + rHighPoint[0]), 0.5 * (rLowPoint[1] + rHighPoint[1]), 0.5 * (rLowPoint[2] + rHighPoint[2])};
206  double representative_center_of_particle[3] = {center_of_particle[0],
207  center_of_particle[1],
208  center_of_particle[2]};
209  TransformToClosestPeriodicCoordinates(box_center, representative_center_of_particle);
210 
211  for (unsigned int i = 0; i < 3; ++i){
212  const bool is_broken = rLowPoint[i] > rHighPoint[i];
213 
214  if (is_broken){ // i.e., we have | ] [ | in this direction
215  intersect = floatge(expanded_box_min[i], representative_center_of_particle[i])
216  && floatle(expanded_box_max[i], representative_center_of_particle[i]);
217  }
218 
219  else { // i.e., we have | [ ] | in this direction
220  intersect = floatle(expanded_box_min[i], representative_center_of_particle[i])
221  && floatge(expanded_box_max[i], representative_center_of_particle[i]);
222  }
223  }
224  }
225 
226  else {
227  for (unsigned int i = 0; i < 3; ++i){
228  intersect = floatle(rLowPoint[i] - Radius, center_of_particle[i])
229  && floatge(rHighPoint[i] + Radius, center_of_particle[i]);
230  }
231  }
232  return intersect;
233  }
234 
235  static inline void Distance(const PointerType& rObj_1, const PointerType& rObj_2, double& distance)
236  {
237  SquaredDistance(rObj_1, rObj_2, distance);
238 
239  distance = std::sqrt(distance);
240  }
241 
242  static inline void SquaredDistance(const PointerType& rObj_1, const PointerType& rObj_2, double& squared_distance)
243  {
244  double rObj_2_to_rObj_1[3];
245  PointType& point_1 = *rObj_1;
246  const double coors_1[3] = {point_1[0], point_1[1], point_1[2]};
247  PointType& point_2 = *rObj_2;
248  const double coors_2[3] = {point_2[0], point_2[1], point_2[2]};
249 
250  PeriodicSubstract(coors_1, coors_2, rObj_2_to_rObj_1);
251 
252  squared_distance = DEM_INNER_PRODUCT_3(rObj_2_to_rObj_1, rObj_2_to_rObj_1);
253  }
254 
255  static double mDomainPeriods[3];
256  static double mDomainMin[3];
257  static double mDomainMax[3];
258  static bool mDomainIsPeriodic;
259 
261  virtual std::string Info() const {return " Spatial Containers Configure for Nodes"; }
262 
264  virtual void PrintInfo(std::ostream& rOStream) const {}
265 
267  virtual void PrintData(std::ostream& rOStream) const {}
268 
269 
270 protected:
271 
272 
273 private:
274 
275  static inline int GetSign(const double value)
276  {
277  return (0.0 < value) - (value < 0.0);
278  }
279 
280  static inline void PeriodicSubstract(const double a[3], const double b[3], double c[3])
281  {
282  for (unsigned int i = 0; i < 3; ++i){
283  c[i] = a[i] - b[i];
284  }
285 
286  if (mDomainIsPeriodic){ // Periods have been set (the domain is periodic)
287  for (unsigned int i = 0; i < 3; ++i){
288  if (std::fabs(c[i]) > 0.5 * mDomainPeriods[i]){ // the objects are closer through the boundary
289  c[i] -= GetSign(c[i]) * mDomainPeriods[i];
290  }
291  }
292  }
293  }
294 
295  static inline bool floateq(double a, double b) {
296  return std::fabs(a - b) < std::numeric_limits<double>::epsilon();
297  }
298 
299  static inline bool floatle(double a, double b) {
300  return a < b || std::fabs(a - b) < std::numeric_limits<double>::epsilon();
301  }
302 
303  static inline bool floatge(double a, double b) {
304  return a > b || std::fabs(a - b) < std::numeric_limits<double>::epsilon();
305  }
306 
310 
314 
318 
320  NodeConfigure& operator=(NodeConfigure const& rOther);
321 
323  NodeConfigure(NodeConfigure const& rOther);
324 
326 
327  }; // Class ParticleConfigure
328 
330 
333 
337 
339  template <std::size_t TDimension>
340  inline std::istream& operator >> (std::istream& rIStream, NodeConfigure<TDimension> & rThis){
341  return rIStream;
342  }
343 
345  template <std::size_t TDimension>
346  inline std::ostream& operator << (std::ostream& rOStream, const NodeConfigure<TDimension>& rThis){
347  rThis.PrintInfo(rOStream);
348  rOStream << std::endl;
349  rThis.PrintData(rOStream);
350 
351  return rOStream;
352  }
353 
355 
356 template <std::size_t TDimension>
357 double NodeConfigure<TDimension>::mDomainPeriods[] = {-1.0, -1.0, -1.0};
358 template <std::size_t TDimension>
359 double NodeConfigure<TDimension>::mDomainMin[] = {0.0, 0.0, 0.0};
360 template <std::size_t TDimension>
361 double NodeConfigure<TDimension>::mDomainMax[] = {-1.0, -1.0, -1.0};
362 template <std::size_t TDimension>
364 
365 } // namespace Kratos.
366 #endif /* NODE_CONFIGURE_H */
#define DEM_INNER_PRODUCT_3(a, b)
Definition: DEM_application_variables.h:31
Configuration file for Nodes.
Definition: node_configure.h:56
SpatialSearch SearchType
Definition: node_configure.h:40
static void SetPeriods(double domain_period_x, double domain_period_y, double domain_period_z)
Definition: node_configure.h:72
static double mDomainMax[3]
Definition: node_configure.h:257
ContainerType::iterator IteratorType
Definition: node_configure.h:48
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: node_configure.h:59
static bool IntersectionBox(const PointerType &rObject, const PointType &rLowPoint, const PointType &rHighPoint, const double Radius)
Definition: node_configure.h:188
static constexpr auto Dimension
Definition: node_configure.h:66
KRATOS_CLASS_POINTER_DEFINITION(NodeConfigure)
Pointer definition of SpatialContainersConfigure.
static double mDomainPeriods[3]
Definition: node_configure.h:255
static bool Intersection(const PointerType &rObj_1, const PointerType &rObj_2, const double &Radius)
Definition: node_configure.h:175
static bool mDomainIsPeriodic
Definition: node_configure.h:258
static void GetPeriods(double periods[3])
Definition: node_configure.h:89
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: node_configure.h:267
ObjectType::Pointer PointerType
Definition: node_configure.h:74
ResultContainerType::iterator ResultIteratorType
Definition: node_configure.h:53
NodeConfigure()
Definition: node_configure.h:56
SearchType::NodesContainerType::ContainerType ContainerType
Definition: node_configure.h:43
static void TransformToClosestPeriodicCoordinates(const double target[3], double base_coordinates[3])
Definition: node_configure.h:101
static void GetBoxCenter(double box_center[3], const double min_point[3], const double max_point[3])
Definition: node_configure.h:133
SearchType::NodesContainerType NodesContainerType
Definition: node_configure.h:44
static void SquaredDistance(const PointerType &rObj_1, const PointerType &rObj_2, double &squared_distance)
Definition: node_configure.h:242
static bool GetDomainPeriodicity()
Definition: node_configure.h:96
virtual std::string Info() const
Turn back information as a string.
Definition: node_configure.h:261
static double * GetMinPoint()
Definition: node_configure.h:79
static void TransformToClosestPeriodicCoordinates(const array_1d< double, 3 > &target, array_1d< double, 3 > &base_coordinates)
Definition: node_configure.h:106
SearchType::NodesContainerType::ContainerType ResultContainerType
Definition: node_configure.h:50
SearchType::PointType PointType
Definition: node_configure.h:42
static void CalculateBoundingBox(const PointerType &rObject, PointType &rLowPoint, PointType &rHighPoint, const double &Radius)
Definition: node_configure.h:155
SearchType::NodeType NodeType
Definition: node_configure.h:46
static void Distance(const PointerType &rObj_1, const PointerType &rObj_2, double &distance)
Definition: node_configure.h:235
static void CalculateBoundingBox(const PointerType &rObject, PointType &rLowPoint, PointType &rHighPoint)
Definition: node_configure.h:149
static void CalculateCenter(const PointerType &rObject, PointType &rCenter)
Definition: node_configure.h:163
virtual ~NodeConfigure()
Definition: node_configure.h:57
static double * GetMaxPoint()
Definition: node_configure.h:84
std::vector< double >::iterator DistanceIteratorType
Definition: node_configure.h:54
ContainerType::value_type PointerType
Definition: node_configure.h:47
static double mDomainMin[3]
Definition: node_configure.h:256
static bool Intersection(const PointerType &rObj_1, const PointerType &rObj_2)
Definition: node_configure.h:170
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: node_configure.h:264
static bool IntersectionBox(const PointerType &rObject, const PointType &rLowPoint, const PointType &rHighPoint)
Definition: node_configure.h:183
@ DIMENSION
Definition: node_configure.h:32
@ MAX_LEVEL
Definition: node_configure.h:33
@ MIN_LEVEL
Definition: node_configure.h:34
static void TransformToClosestPeriodicCoordinates(const array_1d< double, 3 > &target, array_1d< double, 3 > &base_coordinates, const double periods[3])
Definition: node_configure.h:122
static void TransformToClosestPeriodicCoordinates(const double target[3], double base_coordinates[3], const double periods[3])
Definition: node_configure.h:111
This class defines the node.
Definition: node.h:65
Point class.
Definition: point.h:59
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
TContainerType ContainerType
Definition: pointer_vector_set.h:90
This class is used to search for elements, conditions and nodes in a given model part.
Definition: spatial_search.h:50
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
integer i
Definition: TensorModule.f:17