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_face_watcher.h
Go to the documentation of this file.
1 // $Author: Guillermo Casas
2 #ifndef ANALYTIC_FACE_WATCHER_H
3 #define ANALYTIC_FACE_WATCHER_H
4 
5 #include <pybind11/pybind11.h>
6 
7 // System includes
8 
9 #include <limits>
10 #include <iostream>
11 #include <iomanip>
12 #include <list>
13 
14 // Project includes
15 #include "includes/define.h"
16 #include "includes/model_part.h"
18 
19 /* External includes */
20 #ifdef _OPENMP
21 #include <omp.h>
22 #endif
23 
24 namespace Kratos
25 {
27 
28 public:
29 
31 
33 
35 
37 
39 
40 template<typename T>
41 static inline int Sign(T x)
42 {
43  return (T(0) < x) - (x < T(0));
44 }
45 
46 class CrossingsTimeStepDataBase // It holds the historical information gathered in a single time step
47 {
48  public:
49 
50  CrossingsTimeStepDataBase(const double time) : mNCrossings(0), mNSignedCrossings(0), mTime(time), mMass(0.0){}
52 
54  {
55  return mNCrossings;
56  }
57 
58  void PushBackCrossings(const int id1, const int id2, const double mass, const double normal_vel, const double tang_vel)
59  {
60  ++mNCrossings;
61  mNSignedCrossings += Sign(id2);
62  mMass += mass*Sign(id2);
63  mRelVelNormalxMass += mass*normal_vel;
64  mRelVelTangentialxMass += mass*tang_vel;
65  mMasses.push_back(mass);
66  mId1.push_back(id1);
67  mId2.push_back(std::abs(id2));
68  mRelVelNormal.push_back(normal_vel);
69  mRelVelTangential.push_back(tang_vel);
70  }
71 
73  {
74  return mNSignedCrossings;
75  }
76 
78  {
79  return mMass;
80  }
81 
82  double GetTime()
83  {
84  return mTime;
85  }
86 
88  {
89  return mRelVelNormalxMass;
90  }
91 
93  {
94  return mRelVelTangentialxMass;
95  }
96 
97 
98  void FillUpPythonLists(pybind11::list& ids,
99  pybind11::list& neighbour_ids,
100  pybind11::list& masses,
101  pybind11::list& normal_relative_vel,
102  pybind11::list& tangential_relative_vel)
103  {
104  ids.attr("clear")();
105  neighbour_ids.attr("clear")();
106  masses.attr("clear")();
107  normal_relative_vel.attr("clear")();
108  tangential_relative_vel.attr("clear")();
109 
110  for (int i = 0; i < mNCrossings; ++i){
111  //ids.push_back(mId1[i]);
112  ids.append(mId1[i]);
113  neighbour_ids.append(mId2[i]);
114  masses.append(mMasses[i]);
115  normal_relative_vel.append(mRelVelNormal[i]);
116  tangential_relative_vel.append(mRelVelTangential[i]);
117  }
118  }
119 
120  private:
121 
122  int mNCrossings;
123  int mNSignedCrossings;
124  double mTime;
125  double mMass;
126  std::vector<double> mMasses;
127  std::vector<int> mId1;
128  std::vector<int> mId2;
129  std::vector<double> mRelVelNormal;
130  std::vector<double> mRelVelTangential;
131  double mRelVelNormalxMass;
132  double mRelVelTangentialxMass;
133 
134  };
135 
136 class FaceHistoryDatabase // It holds the historical information gathered for a single face
137  {
138  public:
139 
140  FaceHistoryDatabase(): mNCrossings(0), mNSignedCrossings(0), /*mId(0),*/ mMass(0.0){}
141  FaceHistoryDatabase(const int id): mNCrossings(0), mNSignedCrossings(0), /*mId(id),*/ mMass(0.0){}
143 
144  void PushBackCrossings(const double time, const int id2, const double mass, const double normal_vel, const double tang_vel)
145  {
146  ++mNCrossings;
147  mNSignedCrossings += Sign(id2);
148  mMass += mass * Sign(normal_vel);
149  mTimes.push_back(time);
150  mId2.push_back(std::abs(id2));
151  mMasses.push_back(mass * Sign(normal_vel));
152  mRelVelNormal.push_back(normal_vel);
153  mRelVelTangential.push_back(tang_vel);
154  }
155 
157  {
158  return mNSignedCrossings;
159  }
160 
162  {
163  return mMass;
164  }
165 
166  void FillUpPythonLists(pybind11::list& times,
167  pybind11::list& neighbour_ids,
168  pybind11::list& masses,
169  pybind11::list& normal_relative_vel,
170  pybind11::list& tangential_relative_vel)
171  {
172 
173  times.attr("clear")();
174  neighbour_ids.attr("clear")();
175  masses.attr("clear")();
176  normal_relative_vel.attr("clear")();
177  tangential_relative_vel.attr("clear")();
178 
179  for (int i = 0; i < mNCrossings; ++i){
180  //times.push_back(mTimes[i]);
181  times.append(mTimes[i]);
182  neighbour_ids.append(mId2[i]);
183  masses.append(mMasses[i]);
184  normal_relative_vel.append(mRelVelNormal[i]);
185  tangential_relative_vel.append(mRelVelTangential[i]);
186  }
187  }
188 
189  private:
190 
191  int mNCrossings;
192  int mNSignedCrossings;
193  //int mId;
194  double mMass;
195  std::vector<double> mTimes;
196  std::vector<double> mMasses;
197  std::vector<int> mId2;
198  std::vector<double> mRelVelNormal;
199  std::vector<double> mRelVelTangential;
200 };
201 
202 void ClearData();
203 
204 void GetFaceData(int id,
205  pybind11::list times,
206  pybind11::list neighbour_ids,
207  pybind11::list masses,
208  pybind11::list normal_relative_vel,
209  pybind11::list tangential_relative_vel);
210 
211 void GetAllFacesData(ModelPart& analytic_model_part,
212  pybind11::list& times,
213  pybind11::list& neighbour_ids,
214  pybind11::list& masses,
215  pybind11::list& normal_relative_vel,
216  pybind11::list& tangential_relative_vel);
217 
218 void GetTimeStepsData(pybind11::list& ids,
219  pybind11::list& neighbour_ids,
220  pybind11::list& masses,
221  pybind11::list& normal_relative_vel,
222  pybind11::list& tangential_relative_vel);
223 
224 void GetTotalFlux(pybind11::list &times,
225  pybind11::list &n_particles,
226  pybind11::list &mass,
227  pybind11::list &normal_relative_vel,
228  pybind11::list &tangential_relative_vel);
229 
230 virtual void MakeMeasurements();
231 
232 virtual FaceHistoryDatabase& GetFaceDataBase(int id);
233 
235 virtual std::string Info() const;
236 
238 virtual void PrintInfo(std::ostream& rOStream) const;
239 
241 virtual void PrintData(std::ostream& rOStream) const;
242 
243 
244 private:
245 
246 ModelPart& mrModelPart;
247 std::set<int> mSetOfIds;
248 std::vector<CrossingsTimeStepDataBase> mVectorOfTimeStepDatabases;
249 std::map<int, FaceHistoryDatabase> mMapOfFaceHistoryDatabases;
250 
252 AnalyticFaceWatcher & operator=(AnalyticFaceWatcher const& rOther);
253 
254 }; // Class AnalyticFaceWatcher
255 
256 } // namespace Kratos.
257 
258 #endif // ANALYTIC_FACE_WATCHER_H
Definition: analytic_face_watcher.h:47
void FillUpPythonLists(pybind11::list &ids, pybind11::list &neighbour_ids, pybind11::list &masses, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_face_watcher.h:98
double GetTotalMassThroughput()
Definition: analytic_face_watcher.h:77
double GetTime()
Definition: analytic_face_watcher.h:82
~CrossingsTimeStepDataBase()
Definition: analytic_face_watcher.h:51
double GetRelVelTangentialxMass()
Definition: analytic_face_watcher.h:92
int GetNumberOfCrossings()
Definition: analytic_face_watcher.h:53
void PushBackCrossings(const int id1, const int id2, const double mass, const double normal_vel, const double tang_vel)
Definition: analytic_face_watcher.h:58
double GetRelVelNormalxMass()
Definition: analytic_face_watcher.h:87
CrossingsTimeStepDataBase(const double time)
Definition: analytic_face_watcher.h:50
int GetTotalThroughput()
Definition: analytic_face_watcher.h:72
Definition: analytic_face_watcher.h:137
FaceHistoryDatabase()
Definition: analytic_face_watcher.h:140
double GetTotalMassThroughput()
Definition: analytic_face_watcher.h:161
FaceHistoryDatabase(const int id)
Definition: analytic_face_watcher.h:141
~FaceHistoryDatabase()
Definition: analytic_face_watcher.h:142
void FillUpPythonLists(pybind11::list &times, pybind11::list &neighbour_ids, pybind11::list &masses, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_face_watcher.h:166
int GetTotalThroughput()
Definition: analytic_face_watcher.h:156
void PushBackCrossings(const double time, const int id2, const double mass, const double normal_vel, const double tang_vel)
Definition: analytic_face_watcher.h:144
Definition: analytic_face_watcher.h:26
virtual void MakeMeasurements()
Definition: analytic_face_watcher.cpp:36
static int Sign(T x)
Definition: analytic_face_watcher.h:41
KRATOS_CLASS_POINTER_DEFINITION(AnalyticFaceWatcher)
void GetTimeStepsData(pybind11::list &ids, pybind11::list &neighbour_ids, pybind11::list &masses, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_face_watcher.cpp:105
virtual ~AnalyticFaceWatcher()
Destructor.
Definition: analytic_face_watcher.h:38
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: analytic_face_watcher.cpp:175
virtual FaceHistoryDatabase & GetFaceDataBase(int id)
Definition: analytic_face_watcher.cpp:159
void ClearData()
Definition: analytic_face_watcher.cpp:29
virtual std::string Info() const
Turn back information as a string.
Definition: analytic_face_watcher.cpp:170
void GetFaceData(int id, pybind11::list times, pybind11::list neighbour_ids, pybind11::list masses, pybind11::list normal_relative_vel, pybind11::list tangential_relative_vel)
Definition: analytic_face_watcher.cpp:61
AnalyticFaceWatcher(ModelPart &model_part)
Default constructor.
Definition: analytic_face_watcher.h:34
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: analytic_face_watcher.cpp:178
void GetAllFacesData(ModelPart &analytic_model_part, pybind11::list &times, pybind11::list &neighbour_ids, pybind11::list &masses, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_face_watcher.cpp:71
void GetTotalFlux(pybind11::list &times, pybind11::list &n_particles, pybind11::list &mass, pybind11::list &normal_relative_vel, pybind11::list &tangential_relative_vel)
Definition: analytic_face_watcher.cpp:142
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
time
Definition: face_heat.py:85
model_part
Definition: face_heat.py:14
x
Definition: sensitivityMatrix.py:49
times
Definition: sp_statistics.py:42
float masses
Definition: sp_statistics.py:89
integer i
Definition: TensorModule.f:17