8 #if !defined(KRATOS_MPI_DISCRETE_PARTICLE__CONFIGURE_INCLUDED)
9 #define KRATOS_MPI_DISCRETE_PARTICLE__CONFIGURE_INCLUDED
44 template <std::
size_t TDimension>
91 rHighPoint = rLowPoint = rObject->GetGeometry().GetPoint(0);
92 double radius = rObject->GetGeometry()[0].GetSolutionStepValue(RADIUS);
94 for(std::size_t
i = 0;
i < 3;
i++){
102 rHighPoint = rLowPoint = rObject->GetGeometry().GetPoint(0);
104 for(std::size_t
i = 0;
i < 3;
i++){
105 rLowPoint[
i] += -Radius;
106 rHighPoint[
i] += Radius;
113 rCenter = rObject->GetGeometry().GetPoint(0);
119 array_1d<double, 3> rObj_2_to_rObj_1 = rObj_1->GetGeometry().GetPoint(0) - rObj_2->GetGeometry().GetPoint(0);
122 const double& radius_1 = rObj_1->GetGeometry()[0].GetSolutionStepValue(RADIUS);
123 const double& radius_2 = rObj_2->GetGeometry()[0].GetSolutionStepValue(RADIUS);
124 double radius_sum = radius_1 + radius_2;
125 bool intersect = (
distance_2 - radius_sum * radius_sum) <= 0;
131 array_1d<double, 3> rObj_2_to_rObj_1 = rObj_1->GetGeometry().GetPoint(0) - rObj_2->GetGeometry().GetPoint(0);
136 const double& radius_1 = Radius;
137 const double& radius_2 = rObj_2->GetGeometry()[0].GetSolutionStepValue(RADIUS);
138 double radius_sum = radius_1 + radius_2;
139 bool intersect = (
distance_2 - radius_sum * radius_sum) <= 0;
154 const double&
radius = rObject->GetGeometry()[0].GetSolutionStepValue(RADIUS);
156 bool intersect = (rLowPoint[0] -
radius <= center_of_particle[0] && rLowPoint[1] -
radius <= center_of_particle[1] && rLowPoint[2] -
radius <= center_of_particle[2] &&
157 rHighPoint[0] +
radius >= center_of_particle[0] && rHighPoint[1] +
radius >= center_of_particle[1] && rHighPoint[2] +
radius >= center_of_particle[2]);
169 bool intersect = (rLowPoint[0] -
radius <= center_of_particle[0] && rLowPoint[1] -
radius <= center_of_particle[1] && rLowPoint[2] -
radius <= center_of_particle[2] &&
171 rHighPoint[0] +
radius >= center_of_particle[0] && rHighPoint[1] +
radius >= center_of_particle[1] && rHighPoint[2] +
radius >= center_of_particle[2]);
180 distance = sqrt((center_of_particle1[0] - center_of_particle2[0]) * (center_of_particle1[0] - center_of_particle2[0]) +
181 (center_of_particle1[1] - center_of_particle2[1]) * (center_of_particle1[1] - center_of_particle2[1]) +
182 (center_of_particle1[2] - center_of_particle2[2]) * (center_of_particle1[2] - center_of_particle2[2]) );
186 static inline void ReduceIds(
int& total_elements,
int& first_element)
191 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
192 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
194 std::vector<int> reduceArray(mpi_size+1);
196 MPI_Allgather(&total_elements,1,MPI_INT,&reduceArray[1],1,MPI_INT,MPI_COMM_WORLD);
199 for(
int i = 1;
i <= mpi_size;
i++)
200 reduceArray[
i] += reduceArray[
i-1];
202 first_element = reduceArray[mpi_rank];
205 template<
class TObjectType>
207 std::vector<TObjectType>& SendObjects,
208 std::vector<TObjectType>& RecvObjects,
213 Communicator->AsyncSendAndReceiveNodes(SendObjects,RecvObjects,msgSendSize,msgRecvSize);
217 template<
class TObjectType>
219 std::vector<TObjectType>& RecvObjects,
228 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
229 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
231 std::stringstream * serializer_buffer;
232 std::vector<std::string> buffer(mpi_size);
235 for(
int i = 0;
i < mpi_size;
i++)
240 particleSerializer.
save(
"nodes",SendObjects[
i]);
242 serializer_buffer = (std::stringstream *)particleSerializer.
pGetBuffer();
243 buffer[
i] = std::string(serializer_buffer->str());
244 msgSendSize[
i] = buffer[
i].size();
248 MPI_Alltoall(msgSendSize,1,MPI_INT,msgRecvSize,1,MPI_INT,MPI_COMM_WORLD);
250 int NumberOfCommunicationEvents = 0;
251 int NumberOfCommunicationEventsIndex = 0;
253 char * message[mpi_size];
254 char * mpi_send_buffer[mpi_size];
256 for(
int j = 0;
j < mpi_size;
j++)
258 if(
j != mpi_rank && msgRecvSize[
j]) NumberOfCommunicationEvents++;
259 if(
j != mpi_rank && msgSendSize[
j]) NumberOfCommunicationEvents++;
262 MPI_Request reqs[NumberOfCommunicationEvents];
263 MPI_Status stats[NumberOfCommunicationEvents];
266 for(
int i = 0;
i < mpi_size;
i++)
268 if(
i != mpi_rank && msgRecvSize[
i])
270 message[
i] = (
char *)malloc(
sizeof(
char) * msgRecvSize[
i]);
272 MPI_Irecv(message[
i],msgRecvSize[
i],MPI_CHAR,
i,0,MPI_COMM_WORLD,&reqs[NumberOfCommunicationEventsIndex++]);
275 if(
i != mpi_rank && msgSendSize[
i])
277 mpi_send_buffer[
i] = (
char *)malloc(
sizeof(
char) * msgSendSize[
i]);
278 memcpy(mpi_send_buffer[
i],buffer[
i].c_str(),msgSendSize[
i]);
279 MPI_Isend(mpi_send_buffer[
i],msgSendSize[
i],MPI_CHAR,
i,0,MPI_COMM_WORLD,&reqs[NumberOfCommunicationEventsIndex++]);
283 MPI_Waitall(NumberOfCommunicationEvents, reqs, stats);
285 MPI_Barrier(MPI_COMM_WORLD);
287 for(
int i = 0;
i < mpi_size;
i++)
289 if (
i != mpi_rank && msgRecvSize[
i])
292 std::stringstream * serializer_buffer;
293 serializer_buffer = (std::stringstream *)particleSerializer.
pGetBuffer();
294 serializer_buffer->write(message[
i], msgRecvSize[
i]);
295 particleSerializer.
load(
"nodes",RecvObjects[
i]);
298 MPI_Barrier(MPI_COMM_WORLD);
302 for(
int i = 0;
i < mpi_size;
i++)
304 if(mpi_rank !=
i && msgRecvSize[
i])
307 if(
i != mpi_rank && msgSendSize[
i])
308 free(mpi_send_buffer[
i]);
330 virtual std::string
Info()
const {
return " Spatial Containers Configure for Particles"; }
423 template <std::
size_t TDimension>
429 template <std::
size_t TDimension>
432 rOStream << std::endl;
The Commmunicator class manages communication for distributed ModelPart instances.
Definition: communicator.h:67
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
Definition: mpi_discrete_particle_configure.h:45
ElementsContainerType::ContainerType ResultContainerType
Definition: mpi_discrete_particle_configure.h:60
virtual std::string Info() const
Turn back information as a string.
Definition: mpi_discrete_particle_configure.h:330
static void CalculateBoundingBox(const PointerType &rObject, PointType &rLowPoint, PointType &rHighPoint)
Definition: mpi_discrete_particle_configure.h:89
ContainerType::value_type PointerType
Definition: mpi_discrete_particle_configure.h:57
static bool IntersectionBox(const PointerType &rObject, const PointType &rLowPoint, const PointType &rHighPoint)
Definition: mpi_discrete_particle_configure.h:147
MpiDiscreteParticleConfigure()
Definition: mpi_discrete_particle_configure.h:74
KRATOS_CLASS_POINTER_DEFINITION(MpiDiscreteParticleConfigure)
Pointer definition of SpatialContainersConfigure.
std::vector< typename Element::Pointer > ContainerType
Definition: mpi_discrete_particle_configure.h:56
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: mpi_discrete_particle_configure.h:336
ContainerType::iterator IteratorType
Definition: mpi_discrete_particle_configure.h:58
std::vector< double >::iterator DistanceIteratorType
Definition: mpi_discrete_particle_configure.h:55
static void AsyncSendAndReceive(std::vector< TObjectType > &SendObjects, std::vector< TObjectType > &RecvObjects, int *msgSendSize, int *msgRecvSize)
Definition: mpi_discrete_particle_configure.h:218
ResultContainerType::iterator ResultIteratorType
Definition: mpi_discrete_particle_configure.h:62
virtual ~MpiDiscreteParticleConfigure()
Definition: mpi_discrete_particle_configure.h:75
static void CalculateCenter(const PointerType &rObject, PointType &rCenter)
Definition: mpi_discrete_particle_configure.h:111
@ DIMENSION
Definition: mpi_discrete_particle_configure.h:49
@ MIN_LEVEL
Definition: mpi_discrete_particle_configure.h:51
@ MAX_LEVEL
Definition: mpi_discrete_particle_configure.h:50
@ Dimension
Definition: mpi_discrete_particle_configure.h:48
static bool Intersection(const PointerType &rObj_1, const PointerType &rObj_2, const double &Radius)
Definition: mpi_discrete_particle_configure.h:130
std::vector< PointerType >::iterator PointerTypeIterator
Definition: mpi_discrete_particle_configure.h:65
static void CalculateBoundingBox(const PointerType &rObject, PointType &rLowPoint, PointType &rHighPoint, const double &Radius)
Definition: mpi_discrete_particle_configure.h:100
static void AsyncSendAndReceive(Communicator::Pointer Communicator, std::vector< TObjectType > &SendObjects, std::vector< TObjectType > &RecvObjects, int *msgSendSize, int *msgRecvSize)
Definition: mpi_discrete_particle_configure.h:206
static bool Intersection(const PointerType &rObj_1, const PointerType &rObj_2)
Definition: mpi_discrete_particle_configure.h:118
Point PointType
Definition: mpi_discrete_particle_configure.h:54
ModelPart::ElementsContainerType ElementsContainerType
Definition: mpi_discrete_particle_configure.h:59
ResultContainerType::value_type ResultPointerType
Definition: mpi_discrete_particle_configure.h:61
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: mpi_discrete_particle_configure.h:333
static void Distance(const PointerType &rObj_1, const PointerType &rObj_2, double &distance)
Definition: mpi_discrete_particle_configure.h:175
static bool IntersectionBox(const PointerType &rObject, const PointType &rLowPoint, const PointType &rHighPoint, const double &Radius)
Definition: mpi_discrete_particle_configure.h:163
static void ReduceIds(int &total_elements, int &first_element)
Definition: mpi_discrete_particle_configure.h:186
Point class.
Definition: point.h:59
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
BufferType * pGetBuffer()
Definition: serializer.h:903
static void Start(std::string const &rIntervalName)
This method starts the timer meassures.
Definition: timer.cpp:109
static void Stop(std::string const &rIntervalName)
This method stops the timer meassures.
Definition: timer.cpp:125
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
float radius
Definition: mesh_to_mdpa_converter.py:18
int j
Definition: quadrature.py:648
distance_2
Definition: sp_statistics.py:71
integer i
Definition: TensorModule.f:17
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247