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.
mpi_neighbours_calculator.h
Go to the documentation of this file.
1 //
2 // Project Name: Kratos
3 // Last Modified by: $Author: M.Santasusana $
4 // Date: $Date: 2011-6-13 08:56:42 $
5 // Revision: $Revision: 1.5 $
6 //
7 //
8 //README::::look to the key word "VERSION" if you want to find all the points where you have to change
9 //something so that you can pass from a kdtree to a bin data search structure;
10 
11 #if !defined(KRATOS_MPI_NEIGHBOURS_CALCULATOR )
12 #define KRATOS_MPI_NEIGHBOURS_CALCULATOR
13 
14 //M: we are using static bins for objects...
15 
16 #include "includes/define.h"
17 #include "includes/model_part.h"
22 
24 #include "custom_utilities/neighbours_calculator.h"
25 
26 #include "../applications/mpi_search_application/custom_utilities/bins_dynamic_objects_mpi.h"
27 #include "../applications/mpi_search_application/custom_utilities/morton_parallel_partitioner.h"
28 
29 namespace Kratos {
30 
31  template< //pot no compilar en windows aquest tipus d'assignacio per template.
32  class TParticle
33  >
34 
35  class Mpi_Neighbours_Calculator: public Neighbours_Calculator<TParticle> {
36  public:
38 
39  typedef TParticle Particle; // es el objecte
40  typedef typename Particle::Pointer ParticlePointer; // es punter al objecte
42  typedef ParticleVector::iterator ParticleIterator; // es un iterador d'objectes
43 
44  typedef ModelPart::ElementsContainerType ParticlePointerVector; // es un vector de iteradors
45  typedef ParticlePointerVector::iterator ParticlePointerIterator; // es un iterador de punters
46 
51  typedef ConfigureType::IteratorType IteratorType; // iterador de punteros.
55  typedef ConfigureType::ContactPairType ContactPairType;
56  typedef ConfigureType::ContainerContactType ContainerContactType;
57  typedef ConfigureType::IteratorContactType IteratorContactType;
58  typedef ConfigureType::PointerContactType PointerContactType;
60 
64 
65  typedef std::vector<double> DistanceVector;
66  typename DistanceVector::iterator DistanceIterator;
67 
68  typedef std::vector<array_1d<double, 3 > > TangDisplacementsVectorType;
69  typedef TangDisplacementsVectorType::iterator TangDisplacementsIteratorType;
70 
71  typedef BinsObjectDynamicMpi <ConfigureType> Bins;
72  typedef MortonParallelPartitioner <ConfigureType> Part;
73 
75  //KRATOS_CLASS_POINTER_DEFINITION(Neighbours_Calculator); R: necesitu? C: No ho se :S
76 
78  };
79 
80  static void Parallel_partitioning(ModelPart& r_model_part, bool extension_option, int CalculateBoundary)
81  {
83 
84  ContainerType& pLocalElements = r_model_part.GetCommunicator().LocalMesh().ElementsArray();
85 // ContainerType& pGhostElements = r_model_part.GetCommunicator().GhostMesh().ElementsArray();
86 
87  ProcessInfo& rCurrentProcessInfo = r_model_part.GetProcessInfo();
88 
89  double radius_extend = 0.0;
90  if (extension_option) radius_extend = rCurrentProcessInfo[SEARCH_RADIUS_EXTENSION];
91 
92  static double MaxNodeRadius = 0.0f;
93  if(std::abs(MaxNodeRadius) < std::numeric_limits<double>::epsilon()) //TODO
94  for (IteratorType particle_pointer_it = pLocalElements.begin(); particle_pointer_it != pLocalElements.end(); ++particle_pointer_it)
95  {
96  double NodeRaidus = (1.0 + radius_extend) * (*particle_pointer_it)->GetGeometry()[0].GetSolutionStepValue(RADIUS); //TODO: MA: WATCH OUT! The use of SEARCH_RADIUS_EXTENSION might have changed
97  MaxNodeRadius = NodeRaidus > MaxNodeRadius ? NodeRaidus : MaxNodeRadius;
98  }
99 
100  static Part partitioner;
101  partitioner.LloydsBasedPartitioner(r_model_part,MaxNodeRadius,CalculateBoundary);
102 
103  KRATOS_CATCH("")
104  }
105 
106  virtual void Add_To_Modelpart(ModelPart& r_model_part, ResultIteratorType neighbour_it)
107  {
109 
110 // ContainerType& pLocalElements = r_model_part.GetCommunicator().LocalMesh().ElementsArray();
111  ContainerType& pGhostElements = r_model_part.GetCommunicator().GhostMesh().ElementsArray();
112 
113  int NumberOfRanks = r_model_part.GetCommunicator().GetNumberOfColors();
114  int destination = -1;
115 
116  bool IsInGhostMesh = false;
117 // bool IsInLocalMesh = false;
118 
119  for(int i = 0; i < NumberOfRanks; i++)
120  if((*neighbour_it)->GetGeometry()[0].GetSolutionStepValue(PARTITION_INDEX) == communicator_ranks[i])
121  destination = i;
122 
123  if(destination > -1)
124  {
125  for(IteratorType element_it = pGhostElements.begin(); !IsInGhostMesh && element_it != pGhostElements.end(); ++element_it)
126  if((*element_it)->GetGeometry()[0].Id() == (*neighbour_it)->GetGeometry()[0].Id())
127  IsInGhostMesh = true;
128 
129 // for(IteratorType element_it = pLocalElements.begin(); !IsInLocalMesh && element_it != pLocalElements.end(); ++element_it)
130 // if((*element_it)->GetGeometry()[0].Id() == (*neighbour_it)->GetGeometry()[0].Id())
131 // IsInLocalMesh = true;
132 
133  if(!IsInGhostMesh /*&& !IsInLocalMesh*/)
134  {
135  r_model_part.GetCommunicator().GhostMesh().Elements().push_back((*neighbour_it));
136  r_model_part.GetCommunicator().GhostMesh().Nodes().push_back((*neighbour_it)->GetGeometry()(0));
137  }
138 
139  IsInGhostMesh = false;
140 // IsInLocalMesh = false;
141 
142  ContainerType& pMyGhostElements = r_model_part.GetCommunicator().GhostMesh(destination).ElementsArray();
143 // ContainerType& pMyLocalElements = r_model_part.GetCommunicator().LocalMesh(destination).ElementsArray();
144 
145  for(IteratorType element_it = pMyGhostElements.begin(); !IsInGhostMesh && element_it != pMyGhostElements.end(); ++element_it)
146  if((*element_it)->GetGeometry()[0].Id() == (*neighbour_it)->GetGeometry()[0].Id())
147  IsInGhostMesh = true;
148 
149 // for(IteratorType element_it = pMyLocalElements.begin(); !IsInLocalMesh && element_it != pMyLocalElements.end(); ++element_it)
150 // if((*element_it)->GetGeometry()[0].Id() == (*particle_pointer_it)->GetGeometry()[0].Id())
151 // IsInLocalMesh = true;
152 
153  if(!IsInGhostMesh)
154  {
155  r_model_part.GetCommunicator().GhostMesh(destination).Elements().push_back((*neighbour_it));
156  r_model_part.GetCommunicator().GhostMesh(destination).Nodes().push_back((*neighbour_it)->GetGeometry()(0));
157  }
158 
159 // if(!IsInLocalMesh)
160 // {
161 // r_model_part.GetCommunicator().LocalMesh(destination).Elements().push_back((*particle_pointer_it));
162 // r_model_part.GetCommunicator().LocalMesh(destination).Nodes().push_back((*particle_pointer_it)->GetGeometry()(0));
163 // }
164  }
165  }
166 
167  virtual void Clean_Modelpart(ModelPart& r_model_part)
168  {
170 
171  unsigned int NumberOfRanks = r_model_part.GetCommunicator().GetNumberOfColors();
172 
173  ModelPart::ElementsContainerType ETempGhost[NumberOfRanks];
174  ModelPart::ElementsContainerType ETempLocal[NumberOfRanks];
175  ModelPart::NodesContainerType NTempGhost[NumberOfRanks];
176  ModelPart::NodesContainerType NTempLocal[NumberOfRanks];
177 
178  //Clean the ghost(i) and local(i) meshes
179  for(unsigned int i = 0; i < NumberOfRanks; i++)
180  {
181  ETempGhost[i].swap(r_model_part.GetCommunicator().GhostMesh(i).Elements());
182  ETempLocal[i].swap(r_model_part.GetCommunicator().LocalMesh(i).Elements());
183  NTempGhost[i].swap(r_model_part.GetCommunicator().GhostMesh(i).Nodes());
184  NTempLocal[i].swap(r_model_part.GetCommunicator().LocalMesh(i).Nodes());
185  }
186 
187  //Celan the ghost mesh
188  ModelPart::ElementsContainerType ETempGhostGlobal;
189  ModelPart::NodesContainerType NTempGhostGlobal;
190 
191  ETempGhostGlobal.swap(r_model_part.GetCommunicator().GhostMesh().Elements());
192  NTempGhostGlobal.swap(r_model_part.GetCommunicator().GhostMesh().Nodes());
193  }
194 
195  virtual void Sort_Modelpart(ModelPart& r_model_part)
196  {
197  for (unsigned int i = 0; i < r_model_part.GetCommunicator().LocalMeshes().size(); i++)
198  r_model_part.GetCommunicator().LocalMesh(i).Nodes().Unique();
199 
200  for (unsigned int i = 0; i < r_model_part.GetCommunicator().GhostMeshes().size(); i++)
201  r_model_part.GetCommunicator().GhostMesh(i).Nodes().Unique();
202  }
203 
204  virtual ContainerType& Get_Elements(ModelPart& r_model_part)
205  {
206  return r_model_part.GetCommunicator().LocalMesh().ElementsArray();
207  }
208 
209  virtual void SearchNeighbours(ModelPart& r_model_part,
210  ContainerType& pIteratorElements,
211  int NumberOfElements,
212  int MaximumNumberOfResults,
213  std::vector<std::size_t> &NumberOfResults,
214  std::vector<std::vector<PointerType> > &Results,
215  std::vector<std::vector<double> > &ResultsDistances,
216  std::vector<double> &Radius
217  )
218  {
219  Bins particle_bin(pIteratorElements.begin(), pIteratorElements.end());
220  particle_bin.SearchObjectsMpi(r_model_part,pIteratorElements.begin(),NumberOfElements,Radius,Results,ResultsDistances,NumberOfResults,MaximumNumberOfResults,r_model_part.pGetCommunicator());
221  }
222 
223  protected:
224 
225 
226  private:
227 
228  inline void Clear(ModelPart::NodesContainerType::iterator node_it, int step_data_size) {
229  unsigned int buffer_size = node_it->GetBufferSize();
230  for (unsigned int step = 0; step < buffer_size; step++) {
231  //getting the data of the solution step
232  double* step_data = (node_it)->SolutionStepData().Data(step);
233  //copying this data in the position of the vector we are interested in
234  for (int j = 0; j < step_data_size; j++) {
235  step_data[j] = 0.0;
236 
237  }
238 
239  }
240  }
241 
242  inline void ClearVariables(ModelPart::NodesContainerType::iterator node_it, Variable<array_1d<double, 3 > >& rVariable) {
243  /*
244  array_1d<double, 3 > & Aux_var = node_it->FastGetSolutionStepValue(rVariable, 0);
245  noalias(Aux_var) = ZeroVector(3);
246  * */
247  }
248 
249  inline void ClearVariables(ParticleIterator particle_it, Variable<double>& rVariable) {
250  /*
251  double& Aux_var = (particle_it->GetPointerToCenterNode()).FastGetSolutionStepValue(rVariable, 0);
252  Aux_var = 0.0;
253  * */
254  }
255 
256  Mpi_Neighbours_Calculator & operator=(Mpi_Neighbours_Calculator const& rOther);
257 
258  }; // Class Neighbours_calculator
259 
260 
261 } // namespace Kratos.
262 
263 #endif // KRATOS_MPI_NEIGHBOURS_CALCULATOR defined
264 
265 
266 
NeighbourIndicesContainerType & NeighbourIndices()
Definition: communicator.cpp:162
MeshType & GhostMesh()
Returns the reference to the mesh storing all ghost entities.
Definition: communicator.cpp:251
SizeType GetNumberOfColors() const
Definition: communicator.cpp:121
MeshType & LocalMesh()
Returns the reference to the mesh storing all local entities.
Definition: communicator.cpp:245
iterator begin()
Iterator pointing to the beginning of the container.
Definition: data_value_container.h:209
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: global_pointers_vector.h:79
typename TContainerType::iterator ptr_iterator
Definition: global_pointers_vector.h:85
Definition: amatrix_interface.h:41
NodesContainerType & Nodes()
Definition: mesh.h:346
ElementsContainerType::ContainerType & ElementsArray()
Definition: mesh.h:588
ElementsContainerType & Elements()
Definition: mesh.h:568
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
Communicator & GetCommunicator()
Definition: model_part.h:1821
Communicator::Pointer pGetCommunicator()
Definition: model_part.h:1831
ProcessInfo & GetProcessInfo()
Definition: model_part.h:1746
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
Definition: mpi_neighbours_calculator.h:35
ConfigureType::IteratorContactType IteratorContactType
Definition: mpi_neighbours_calculator.h:57
ConfigureType::ContainerType ContainerType
Definition: mpi_neighbours_calculator.h:49
DistanceVector::iterator DistanceIterator
Definition: mpi_neighbours_calculator.h:66
ConfigureType::ResultContainerType ResultContainerType
Definition: mpi_neighbours_calculator.h:52
ConfigureType::ResultIteratorType ResultIteratorType
Definition: mpi_neighbours_calculator.h:54
virtual void Add_To_Modelpart(ModelPart &r_model_part, ResultIteratorType neighbour_it)
Definition: mpi_neighbours_calculator.h:106
virtual void Clean_Modelpart(ModelPart &r_model_part)
Definition: mpi_neighbours_calculator.h:167
ParticlePointerVector::iterator ParticlePointerIterator
Definition: mpi_neighbours_calculator.h:45
virtual ContainerType & Get_Elements(ModelPart &r_model_part)
Definition: mpi_neighbours_calculator.h:204
ConfigureType::PointerContactType PointerContactType
Definition: mpi_neighbours_calculator.h:58
ConfigureType::PointType PointType
Definition: mpi_neighbours_calculator.h:47
MpiDiscreteParticleConfigure< 3 > ConfigureType
Definition: mpi_neighbours_calculator.h:37
ConfigureType::PointerType PointerType
Definition: mpi_neighbours_calculator.h:50
MortonParallelPartitioner< ConfigureType > Part
Definition: mpi_neighbours_calculator.h:72
ConfigureType::IteratorType IteratorType
Definition: mpi_neighbours_calculator.h:51
ConfigureType::ResultPointerType ResultPointerType
Definition: mpi_neighbours_calculator.h:53
ConfigureType::PointerTypeIterator PointerTypeIterator
Definition: mpi_neighbours_calculator.h:59
ConfigureType::ContainerContactType ContainerContactType
Definition: mpi_neighbours_calculator.h:56
ModelPart::ElementsContainerType ParticlePointerVector
Definition: mpi_neighbours_calculator.h:44
ModelPart::ElementsContainerType::ContainerType ParticleVector
Definition: mpi_neighbours_calculator.h:41
virtual void Sort_Modelpart(ModelPart &r_model_part)
Definition: mpi_neighbours_calculator.h:195
GlobalPointersVector< Element > ParticleWeakVector
Definition: mpi_neighbours_calculator.h:61
std::vector< array_1d< double, 3 > > TangDisplacementsVectorType
Definition: mpi_neighbours_calculator.h:68
BinsObjectDynamicMpi< ConfigureType > Bins
Definition: mpi_neighbours_calculator.h:71
ConfigureType::ContactPairType ContactPairType
Definition: mpi_neighbours_calculator.h:55
TParticle Particle
Definition: mpi_neighbours_calculator.h:39
virtual void SearchNeighbours(ModelPart &r_model_part, ContainerType &pIteratorElements, int NumberOfElements, int MaximumNumberOfResults, std::vector< std::size_t > &NumberOfResults, std::vector< std::vector< PointerType > > &Results, std::vector< std::vector< double > > &ResultsDistances, std::vector< double > &Radius)
Definition: mpi_neighbours_calculator.h:209
ConfigureType::DistanceIteratorType DistanceIteratorType
Definition: mpi_neighbours_calculator.h:48
Particle::Pointer ParticlePointer
Definition: mpi_neighbours_calculator.h:40
static void Parallel_partitioning(ModelPart &r_model_part, bool extension_option, int CalculateBoundary)
Definition: mpi_neighbours_calculator.h:80
ParticleWeakVector::ptr_iterator ParticleWeakIteratorType_ptr
Definition: mpi_neighbours_calculator.h:63
virtual ~Mpi_Neighbours_Calculator()
Pointer definition of Neighbour_calculator.
Definition: mpi_neighbours_calculator.h:77
ParticleVector::iterator ParticleIterator
Definition: mpi_neighbours_calculator.h:42
ParticleWeakVector::iterator ParticleWeakIterator
Definition: mpi_neighbours_calculator.h:62
TangDisplacementsVectorType::iterator TangDisplacementsIteratorType
Definition: mpi_neighbours_calculator.h:69
std::vector< double > DistanceVector
Definition: mpi_neighbours_calculator.h:65
Definition: mpi_discrete_particle_configure.h:45
ElementsContainerType::ContainerType ResultContainerType
Definition: mpi_discrete_particle_configure.h:60
ContainerType::value_type PointerType
Definition: mpi_discrete_particle_configure.h:57
std::vector< typename Element::Pointer > ContainerType
Definition: mpi_discrete_particle_configure.h:56
ContainerType::iterator IteratorType
Definition: mpi_discrete_particle_configure.h:58
std::vector< double >::iterator DistanceIteratorType
Definition: mpi_discrete_particle_configure.h:55
ResultContainerType::iterator ResultIteratorType
Definition: mpi_discrete_particle_configure.h:62
std::vector< PointerType >::iterator PointerTypeIterator
Definition: mpi_discrete_particle_configure.h:65
ResultContainerType::value_type ResultPointerType
Definition: mpi_discrete_particle_configure.h:61
Point class.
Definition: point.h:59
boost::indirect_iterator< typename TContainerType::iterator > iterator
Definition: pointer_vector.h:89
void Unique()
Remove duplicate elements from the set.
Definition: pointer_vector_set.h:764
void push_back(TPointerType x)
Adds a pointer to the end of the set.
Definition: pointer_vector_set.h:544
ProcessInfo holds the current value of different solution parameters.
Definition: process_info.h:59
#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
int step
Definition: face_heat.py:88
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247