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.
analytic_particle_watcher.h
Go to the documentation of this file.
1 #ifndef ANALYTIC_PARTICLE_WATCHER_H
2 #define ANALYTIC_PARTICLE_WATCHER_H
3 
4 // System includes
5 #include <pybind11/pybind11.h>
6 #include <limits>
7 #include <iostream>
8 #include <iomanip>
9 
10 // Project includes
11 #include "includes/define.h"
12 #include "includes/model_part.h"
14 
15 
16 /* External includes */
17 #ifdef _OPENMP
18 #include <omp.h>
19 #endif
20 
21 namespace Kratos
22 {
24 
25 public:
26 
28 
30 
32 
34 
36 
37 
38 class InterParticleImpactDataOfAllParticlesSingleTimeStep // It holds the historical information gathered in a single time step
39 {
40  public:
41 
42  InterParticleImpactDataOfAllParticlesSingleTimeStep(const double time) : mNImpacts(0)/*, mTime(time)*/{}
44 
46  {
47  return mNImpacts;
48  }
49 
50  void PushBackImpacts(const int id1, const int id2, const double normal_vel, const double tang_vel)
51  {
52  if (ImpactIsNew(id2)){
53  ++mNImpacts;
54  mId1.push_back(id1);
55  mId2.push_back(id2);
56  mRelVelNormal.push_back(normal_vel);
57  mRelVelTangential.push_back(tang_vel);
58  }
59  }
60 
62  {
63  for (int i=0; i<other_list_of_impacts.GetNumberOfImpacts(); i++) {
64  PushBackImpacts(other_list_of_impacts.mId1[i], other_list_of_impacts.mId2[i], other_list_of_impacts.mRelVelNormal[i], other_list_of_impacts.mRelVelTangential[i]);
65  }
66  }
67 
68  void FillUpPythonLists(pybind11::list& ids,
69  pybind11::list& neighbour_ids,
70  pybind11::list& normal_relative_vel,
71  pybind11::list& tangential_relative_vel)
72  {
73  ids.attr("clear")();
74  neighbour_ids.attr("clear")();
75  normal_relative_vel.attr("clear")();
76  tangential_relative_vel.attr("clear")();
77 
78  for (int i = 0; i < mNImpacts; ++i){
79  //std::copy( mId1.begin(), mId1.end(), pybind11::back_inserter( ids ) );
80  //ids.push_back(mId1[i]);
81 
82  ids.append(mId1[i]);
83  neighbour_ids.append(mId2[i]);
84  normal_relative_vel.append(mRelVelNormal[i]);
85  tangential_relative_vel.append(mRelVelTangential[i]);
86  }
87 
88  }
89 
90  private:
91 
92  int mNImpacts;
93  /*double mTime;*/
94  std::vector<int> mId1;
95  std::vector<int> mId2;
96  std::vector<double> mRelVelNormal;
97  std::vector<double> mRelVelTangential;
98 
99 
100  bool ImpactIsNew(const int id_2)
101  {
102  return std::find(mId1.begin(), mId1.end(), id_2) == mId1.end();
103  }
104  };
105 
106 class InterParticleImpactDataOfAllTimeStepsSingleParticle // It holds the historical information gathered for a single particle
107  {
108  public:
109 
111  InterParticleImpactDataOfAllTimeStepsSingleParticle(const int id) : mNImpacts(0)/*, mId(id)*/{}
113 
114  void PushBackImpacts(const double time, const int id2, const double normal_vel, const double tang_vel, const double linear_impulse)
115  {
116  ++mNImpacts;
117  mTimes.push_back(time);
118  mId2.push_back(id2);
119  mRelVelNormal.push_back(normal_vel);
120  mRelVelTangential.push_back(tang_vel);
121  mLinearImpulse.push_back(linear_impulse);
122  }
123 
124  void FillUpPythonLists(pybind11::list& times,
125  pybind11::list& neighbour_ids,
126  pybind11::list& normal_relative_vel,
127  pybind11::list& tangential_relative_vel)
128  {
129  times.attr("clear")();
130  neighbour_ids.attr("clear")();
131  normal_relative_vel.attr("clear")();
132  tangential_relative_vel.attr("clear")();
133 
134  for (int i = 0; i < mNImpacts; ++i){
135  times.append(mTimes[i]);
136  neighbour_ids.append(mId2[i]);
137  normal_relative_vel.append(mRelVelNormal[i]);
138  tangential_relative_vel.append(mRelVelTangential[i]);
139  }
140  }
141 
142  void GetMaxCollidingSpeedFromDatabase(double& db_normal_impact_velocity, double& db_tangential_impact_velocity){
143  if(mRelVelNormal.size()){
144  for(int i=0; i<(int)mRelVelNormal.size(); i++){
145  const double abs_normal_value = std::abs(mRelVelNormal[i]);
146  db_normal_impact_velocity = std::max(db_normal_impact_velocity, abs_normal_value);
147  const double abs_tg_value = std::abs(mRelVelTangential[i]);
148  db_tangential_impact_velocity = std::max(db_tangential_impact_velocity, abs_tg_value);
149  }
150  }
151  else {
152  db_normal_impact_velocity = 0.0;
153  db_tangential_impact_velocity = 0.0;
154  }
155  }
156 
157  void GetMaxLinearImpulseFromDatabase(double& db_linear_impulse){
158  if(mRelVelNormal.size()){
159  db_linear_impulse = std::abs(*(std::max_element(mLinearImpulse.begin(), mLinearImpulse.end())));
160 
161  }
162  else {
163  db_linear_impulse = 0.0;
164 
165  }
166 
167  }
168 
169  private:
170 
171  int mNImpacts;
172  //int mId;
173  std::vector<double> mTimes;
174  std::vector<int> mId2;
175  std::vector<double> mRelVelNormal;
176  std::vector<double> mRelVelTangential;
177  std::vector<double> mLinearImpulse;
178 
179 };
180 
181 
182 
183 
184 // FaceParticleImpactDataOfAllParticlesSingleTimeStep
185 
186 class FaceParticleImpactDataOfAllParticlesSingleTimeStep // It holds the historical information gathered in a single time step against flat walls
187 {
188  public:
189 
190  FaceParticleImpactDataOfAllParticlesSingleTimeStep(const double time) : mNImpacts(0)/*, mTime(time)*/{}
192 
194  {
195  return mNImpacts;
196  }
197 
198  void PushBackImpacts(const int id1, const int id2, const double normal_vel, const double tang_vel)
199  {
200  if (ImpactIsNew(id2)){
201  ++mNImpacts;
202  mId1.push_back(id1);
203  mId2.push_back(id2);
204  mRelVelNormal.push_back(normal_vel);
205  mRelVelTangential.push_back(tang_vel);
206  }
207  }
208 
210  {
211  for (int i=0; i<other_list_of_impacts.GetNumberOfImpacts(); i++) {
212  PushBackImpacts(other_list_of_impacts.mId1[i], other_list_of_impacts.mId2[i], other_list_of_impacts.mRelVelNormal[i], other_list_of_impacts.mRelVelTangential[i]);
213  }
214  }
215 
216  void FillUpPythonLists(pybind11::list& ids,
217  pybind11::list& neighbour_ids,
218  pybind11::list& normal_relative_vel,
219  pybind11::list& tangential_relative_vel)
220  {
221  ids.attr("clear")();
222  neighbour_ids.attr("clear")();
223  normal_relative_vel.attr("clear")();
224  tangential_relative_vel.attr("clear")();
225 
226  for (int i = 0; i < mNImpacts; ++i){
227  ids.append(mId1[i]);
228  neighbour_ids.append(mId2[i]);
229  normal_relative_vel.append(mRelVelNormal[i]);
230  tangential_relative_vel.append(mRelVelTangential[i]);
231  }
232  }
233 
234  private:
235 
236  int mNImpacts;
237  /*double mTime;*/
238  std::vector<int> mId1;
239  std::vector<int> mId2;
240  std::vector<double> mRelVelNormal;
241  std::vector<double> mRelVelTangential;
242 
243  bool ImpactIsNew(const int id_2)
244  {
245  return std::find(mId1.begin(), mId1.end(), id_2) == mId1.end();
246  }
247  };
248 
249 class FaceParticleImpactDataOfAllTimeStepsSingleParticle // It holds the historical information gathered for a single particle against flat walls
250  {
251  public:
252 
254  FaceParticleImpactDataOfAllTimeStepsSingleParticle(const int id) : mNImpacts(0)/*, mId(id)*/{}
256 
257  void PushBackImpacts(const double time, const int id2, const double normal_vel, const double tang_vel)
258  {
259  ++mNImpacts;
260  mTimes.push_back(time);
261  mId2.push_back(id2);
262  mRelVelNormal.push_back(normal_vel);
263  mRelVelTangential.push_back(tang_vel);
264  }
265 
266  void FillUpPythonLists(pybind11::list& times,
267  pybind11::list& neighbour_ids,
268  pybind11::list& normal_relative_vel,
269  pybind11::list& tangential_relative_vel)
270  {
271  times.attr("clear")();
272  neighbour_ids.attr("clear")();
273  normal_relative_vel.attr("clear")();
274  tangential_relative_vel.attr("clear")();
275 
276  for (int i = 0; i < mNImpacts; ++i){
277  times.append(mTimes[i]);
278  neighbour_ids.append(mId2[i]);
279  normal_relative_vel.append(mRelVelNormal[i]);
280  tangential_relative_vel.append(mRelVelTangential[i]);
281  }
282  }
283 
284  void GetMaxCollidingSpeedFromDatabase(double& db_normal_impact_velocity, double& db_tangential_impact_velocity){
285  if(mRelVelNormal.size()){
286  for(int i=0; i<(int)mRelVelNormal.size(); i++){
287  const double abs_normal_value = std::abs(mRelVelNormal[i]);
288  db_normal_impact_velocity = std::max(db_normal_impact_velocity, abs_normal_value);
289  const double abs_tg_value = std::abs(mRelVelTangential[i]);
290  db_tangential_impact_velocity = std::max(db_tangential_impact_velocity, abs_tg_value);
291  }
292  }
293  else {
294  db_normal_impact_velocity = 0.0;
295  db_tangential_impact_velocity = 0.0;
296  }
297 
298  }
299 
300  private:
301 
302  int mNImpacts;
303  //int mId;
304  std::vector<double> mTimes;
305  std::vector<int> mId2;
306  std::vector<double> mRelVelNormal;
307  std::vector<double> mRelVelTangential;
308 };
309 
310 //
311 
312 void GetParticleData(int id,
313  pybind11::list times,
314  pybind11::list neighbour_ids,
315  pybind11::list normal_relative_vel,
316  pybind11::list tangential_relative_vel);
317 
318 void GetAllParticlesData(ModelPart& analytic_model_part,
319  pybind11::list& times,
320  pybind11::list& neighbour_ids,
321  pybind11::list& normal_relative_vel,
322  pybind11::list& tangential_relative_vel);
323 
324 void GetTimeStepsData(pybind11::list& ids,
325  pybind11::list& neighbour_ids,
326  pybind11::list& normal_relative_vel,
327  pybind11::list& tangential_relative_vel);
328 
329 virtual void MakeMeasurements(ModelPart &analytic_model_part);
330 
331 virtual void SetNodalMaxImpactVelocities(ModelPart &analytic_model_part);
332 virtual void SetNodalMaxFaceImpactVelocities(ModelPart &analytic_model_part);
333 virtual void SetNodalMaxLinearImpulse(ModelPart &analytic_model_part);
334 
335 virtual InterParticleImpactDataOfAllTimeStepsSingleParticle& GetParticleDataBase(int id, std::map<int, InterParticleImpactDataOfAllTimeStepsSingleParticle>& data_base);
336 virtual FaceParticleImpactDataOfAllTimeStepsSingleParticle& GetParticleFaceDataBase(int id, std::map<int, FaceParticleImpactDataOfAllTimeStepsSingleParticle>& data_base);
337 
339 virtual std::string Info() const;
340 
342 virtual void PrintInfo(std::ostream& rOStream) const;
343 
345 virtual void PrintData(std::ostream& rOStream) const;
346 
347 
348 private:
349 
350 std::set<int> mSetOfIds;
351 
352 std::vector<InterParticleImpactDataOfAllParticlesSingleTimeStep> mInterParticleImpactDataOfAllParticles;
353 std::map<int, InterParticleImpactDataOfAllTimeStepsSingleParticle> mInterParticleImpactDataOfAllTimeSteps;
354 
355 std::vector<FaceParticleImpactDataOfAllParticlesSingleTimeStep> mFaceParticleImpactDataOfAllParticles;
356 std::map<int, FaceParticleImpactDataOfAllTimeStepsSingleParticle> mFaceParticleImpactDataOfAllTimeSteps;
357 
358 // std::vector<EdgeParticleImpactDataOfAParticle> mEdgeParticleImpactDataOfAllParticles; inactive
359 // std::map<int, EdgeParticleImpactDataOfATimeStep> mEdgeParticleImpactDataOfAllTimeSteps;
360 
361 // std::vector<VertexParticleImpactDataOfAParticle> mVertexParticleImpactDataOfAllParticles; inactive
362 // std::map<int, VertexParticleImpactDataOfATimeStep> mVertexParticleImpactDataOfAllTimeSteps;
363 
365 AnalyticParticleWatcher & operator=(AnalyticParticleWatcher const& rOther);
366 
367 }; // Class AnalyticParticleWatcher
368 
369 } // namespace Kratos.
370 
371 #endif // ANALYTIC_PARTICLE_WATCHER_H
void PushBackImpacts(FaceParticleImpactDataOfAllParticlesSingleTimeStep &other_list_of_impacts)
Definition: analytic_particle_watcher.h:209
FaceParticleImpactDataOfAllParticlesSingleTimeStep(const double time)
Definition: analytic_particle_watcher.h:190
void FillUpPythonLists(pybind11::list &ids, pybind11::list &neighbour_ids, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_particle_watcher.h:216
void PushBackImpacts(const int id1, const int id2, const double normal_vel, const double tang_vel)
Definition: analytic_particle_watcher.h:198
~FaceParticleImpactDataOfAllParticlesSingleTimeStep()
Definition: analytic_particle_watcher.h:191
FaceParticleImpactDataOfAllTimeStepsSingleParticle()
Definition: analytic_particle_watcher.h:253
FaceParticleImpactDataOfAllTimeStepsSingleParticle(const int id)
Definition: analytic_particle_watcher.h:254
void PushBackImpacts(const double time, const int id2, const double normal_vel, const double tang_vel)
Definition: analytic_particle_watcher.h:257
void FillUpPythonLists(pybind11::list &times, pybind11::list &neighbour_ids, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_particle_watcher.h:266
~FaceParticleImpactDataOfAllTimeStepsSingleParticle()
Definition: analytic_particle_watcher.h:255
void GetMaxCollidingSpeedFromDatabase(double &db_normal_impact_velocity, double &db_tangential_impact_velocity)
Definition: analytic_particle_watcher.h:284
void PushBackImpacts(InterParticleImpactDataOfAllParticlesSingleTimeStep &other_list_of_impacts)
Definition: analytic_particle_watcher.h:61
InterParticleImpactDataOfAllParticlesSingleTimeStep(const double time)
Definition: analytic_particle_watcher.h:42
void PushBackImpacts(const int id1, const int id2, const double normal_vel, const double tang_vel)
Definition: analytic_particle_watcher.h:50
void FillUpPythonLists(pybind11::list &ids, pybind11::list &neighbour_ids, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_particle_watcher.h:68
~InterParticleImpactDataOfAllParticlesSingleTimeStep()
Definition: analytic_particle_watcher.h:43
void GetMaxLinearImpulseFromDatabase(double &db_linear_impulse)
Definition: analytic_particle_watcher.h:157
InterParticleImpactDataOfAllTimeStepsSingleParticle(const int id)
Definition: analytic_particle_watcher.h:111
InterParticleImpactDataOfAllTimeStepsSingleParticle()
Definition: analytic_particle_watcher.h:110
void FillUpPythonLists(pybind11::list &times, pybind11::list &neighbour_ids, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_particle_watcher.h:124
void GetMaxCollidingSpeedFromDatabase(double &db_normal_impact_velocity, double &db_tangential_impact_velocity)
Definition: analytic_particle_watcher.h:142
void PushBackImpacts(const double time, const int id2, const double normal_vel, const double tang_vel, const double linear_impulse)
Definition: analytic_particle_watcher.h:114
~InterParticleImpactDataOfAllTimeStepsSingleParticle()
Definition: analytic_particle_watcher.h:112
Definition: analytic_particle_watcher.h:23
virtual FaceParticleImpactDataOfAllTimeStepsSingleParticle & GetParticleFaceDataBase(int id, std::map< int, FaceParticleImpactDataOfAllTimeStepsSingleParticle > &data_base)
Definition: analytic_particle_watcher.cpp:245
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: analytic_particle_watcher.cpp:269
virtual void SetNodalMaxImpactVelocities(ModelPart &analytic_model_part)
Definition: analytic_particle_watcher.cpp:100
virtual std::string Info() const
Turn back information as a string.
Definition: analytic_particle_watcher.cpp:261
void GetParticleData(int id, pybind11::list times, pybind11::list neighbour_ids, pybind11::list normal_relative_vel, pybind11::list tangential_relative_vel)
Definition: analytic_particle_watcher.cpp:159
void GetAllParticlesData(ModelPart &analytic_model_part, pybind11::list &times, pybind11::list &neighbour_ids, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_particle_watcher.cpp:168
virtual InterParticleImpactDataOfAllTimeStepsSingleParticle & GetParticleDataBase(int id, std::map< int, InterParticleImpactDataOfAllTimeStepsSingleParticle > &data_base)
Definition: analytic_particle_watcher.cpp:230
virtual void SetNodalMaxLinearImpulse(ModelPart &analytic_model_part)
Definition: analytic_particle_watcher.cpp:142
KRATOS_CLASS_POINTER_DEFINITION(AnalyticParticleWatcher)
virtual void SetNodalMaxFaceImpactVelocities(ModelPart &analytic_model_part)
Definition: analytic_particle_watcher.cpp:121
virtual ~AnalyticParticleWatcher()
Destructor.
Definition: analytic_particle_watcher.h:35
AnalyticParticleWatcher()
Default constructor.
Definition: analytic_particle_watcher.h:31
void GetTimeStepsData(pybind11::list &ids, pybind11::list &neighbour_ids, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_particle_watcher.cpp:198
virtual void MakeMeasurements(ModelPart &analytic_model_part)
Definition: analytic_particle_watcher.cpp:26
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: analytic_particle_watcher.cpp:266
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
static double max(double a, double b)
Definition: GeometryFunctions.h:79
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
time
Definition: face_heat.py:85
times
Definition: sp_statistics.py:42
integer i
Definition: TensorModule.f:17