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.
space_time_rule.h
Go to the documentation of this file.
1 #ifndef KRATOS_SPACE_TIME_RULE_H
2 #define KRATOS_SPACE_TIME_RULE_H
3 // /* External includes */
4 
5 // System includes
6 
7 // Project includes
8 #include "includes/variables.h"
9 
10 /* System includes */
11 #include <limits>
12 #include <iostream>
13 #include <iomanip>
14 
15 /* External includes */
16 #ifdef _OPENMP
17 #include <omp.h>
18 #endif
19 
20 /* Project includes */
21 #include "includes/define.h"
22 #include "utilities/openmp_utils.h"
23 #include "../real_functions.h"
24 #include "../real_field.h"
25 
26 
27 namespace Kratos
28 {
30 {
31 public:
32 
34 
36 
38 
40 
41 virtual ~SpaceTimeRule(){}
42 
43 //***************************************************************************************************************
44 //***************************************************************************************************************
45 
46 virtual bool CheckIfRuleIsMet(const double time, const double coor_x, const double coor_y, const double coor_z){return true;}
47 
48 //***************************************************************************************************************
49 //***************************************************************************************************************
50 
54 
58 
60 
61 virtual std::string Info() const
62 {
63  return "SpaceTimeRule";
64 }
65 
67 
68 virtual void PrintInfo(std::ostream& rOStream) const{}
69 
71 
72 virtual void PrintData(std::ostream& rOStream) const{}
73 
74 
78 
80 
81 protected:
84 
85 
89 
90 
94 
95 
99 
100 
104 
108 
109 
113 
114 
116 
117 private:
118 
121 
122 
126 
130 
134 
135 
139 
140 
144 
145 
149 
151 SpaceTimeRule & operator=(SpaceTimeRule const& rOther);
152 
153 
155 
156 }; // Class SpaceTimeRule
157 
159 {
160 public:
161 
163 {
164  mLowTime = - std::numeric_limits<double>::max();
165  mHighTime = std::numeric_limits<double>::max();
172 }
173 
174 BoundingBoxRule(const double min_time,
175  const double max_time,
176  const double min_x,
177  const double max_x,
178  const double min_y,
179  const double max_y,
180  const double min_z,
181  const double max_z): SpaceTimeRule()
182 {
183  mLowTime = min_time;
184  mHighTime = max_time;
185  mLowX = min_x;
186  mHighX = max_x;
187  mLowY = min_y;
188  mHighY = max_y;
189  mLowZ = min_z;
190  mHighZ = max_z;
191 }
192 
194 
195 void SetTimeBoundingInterval(const double& low, const double& high)
196 {
197  mLowTime = low;
198  mHighTime = high;
199  Check();
200 }
201 
202 void SetXBoundingInterval(const double& low, const double& high)
203 {
204  mLowX = low;
205  mHighX = high;
206  Check();
207 }
208 
209 void SetYBoundingInterval(const double& low, const double& high)
210 {
211  mLowY = low;
212  mHighY = high;
213  Check();
214 }
215 
216 void SetZBoundingInterval(const double& low, const double& high)
217 {
218 mLowZ = low;
219 mHighZ = high;
220 Check();
221 }
222 
224 {
225  mLowTime = low[0];
226  mHighTime = high[0];
227  mLowX = low[1];
228  mHighX = high[1];
229  mLowY = low[2];
230  mHighY = high[2];
231  mLowZ = low[3];
232  mHighZ = high[3];
233  Check();
234 }
235 
236 bool CheckIfRuleIsMet(const double time, const double coor_x, const double coor_y, const double coor_z) override
237 {
238  bool low = time < mLowTime || coor_x < mLowX || coor_y < mLowY || coor_z < mLowZ;
239  bool high = time > mHighTime || coor_x > mHighX || coor_y > mHighY || coor_z > mHighZ;
240 
241  return !(high || low);
242 }
243 
244 virtual std::string Info() const override
245 {
246  std::ostringstream os;
247  os << "Bounding box limits : " << std::endl
248  << "min time: " << mLowTime << std::endl
249  << "max time: " << mHighTime << std::endl
250  << "min x : " << mLowX << std::endl
251  << "max x : " << mHighX << std::endl
252  << "min y : " << mLowY << std::endl
253  << "max y : " << mHighY << std::endl
254  << "min z : " << mLowZ << std::endl
255  << "max z : " << mHighZ << std::endl;
256 
257  std::string info = os.str();
258 
259  return info;
260 }
261 
262 void PrintData( std::ostream& rOStream = std::cout ) const override
263 {
264  rOStream << "Bounding box limits : " << std::endl
265  << "min time: " << mLowTime << std::endl
266  << "max time: " << mHighTime << std::endl
267  << "min x : " << mLowX << std::endl
268  << "max x : " << mHighX << std::endl
269  << "min y : " << mLowY << std::endl
270  << "max y : " << mHighY << std::endl
271  << "min z : " << mLowZ << std::endl
272  << "max z : " << mHighZ << std::endl;
273 }
274 
275 protected:
276 void Check()
277 {
278  KRATOS_TRY
279 
280  KRATOS_ERROR_IF(mHighTime < mLowTime || mHighX < mLowX || mHighY < mLowY || mHighZ < mLowZ) << "Entered low bounds greater than corresponding bounds" << std::endl;
281 
282  KRATOS_CATCH("")
283 }
284 
285 private:
286 
287 double mLowTime;
288 double mHighTime;
289 double mLowX;
290 double mHighX;
291 double mLowY;
292 double mHighY;
293 double mLowZ;
294 double mHighZ;
295 };
296 
297 //***************************************************************************************************************
298 //***************************************************************************************************************
299 
301 {
302 public:
303 
304 MoreThanRule(RealField::Pointer field, const double value)
305  : mValue(value),
306  mpField(field),
307  mpLowField(field),
308  mCase(1){}
309 
310 MoreThanRule(const double value, RealField::Pointer field)
311  : mValue(value),
312  mpField(field),
313  mpLowField(field),
314  mCase(2){}
315 
316 MoreThanRule(RealField::Pointer field_high, RealField::Pointer field_low)
317  : mValue(0.0),
318  mpField(field_high),
319  mpLowField(field_low),
320  mCase(3){}
321 
323 
324 bool CheckIfRuleIsMet(const double time, const double coor_x, const double coor_y, const double coor_z) override
325 {
326  array_1d<double, 3> coor;
327  coor[0] = coor_x;
328  coor[1] = coor_y;
329  coor[2] = coor_z;
330 
331  if (mCase == 1){
332  return mpField->Evaluate(time, coor) > mValue;
333  }
334 
335  else if (mCase == 2){
336  return mpField->Evaluate(time, coor) < mValue;
337  }
338 
339  else {
340  return mpField->Evaluate(time, coor) > mpLowField->Evaluate(time, coor);
341  }
342 }
343 
344 protected:
345 
346 void Check(){}
347 
348 private:
349 
350 double mValue;
351 RealField::Pointer mpField;
352 RealField::Pointer mpLowField;
353 int mCase;
354 };
355 
356 //***************************************************************************************************************
357 //***************************************************************************************************************
358 
360 {
361 public:
362 EqualToRule(RealField::Pointer field, const double value, const double tol)
363  : mValue(value),
364  mTol(tol),
365  mpField1(field),
366  mpField2(field),
367  mCase(1)
368 {
369  this->Check();
370 }
371 
372 EqualToRule(RealField::Pointer field_1, RealField::Pointer field_2, const double tol)
373  : mValue(0.0),
374  mTol(tol),
375  mpField1(field_1),
376  mpField2(field_2),
377  mCase(2)
378 {
379  this->Check();
380 }
381 
383 
384 bool CheckIfRuleIsMet(const double time, const double coor_x, const double coor_y, const double coor_z) override
385 {
386  array_1d<double, 3> coor;
387  coor[0] = coor_x;
388  coor[1] = coor_y;
389  coor[2] = coor_z;
390 
391  double valuation_1 = mpField1->Evaluate(time, coor);
392 
393  if (mCase == 1){
394  return valuation_1 < mValue + mTol && valuation_1 > mValue - mTol;
395  }
396 
397  else {
398  double valuation_2 = mpField2->Evaluate(time, coor);
399  return valuation_1 < valuation_2 + mTol && valuation_1 > valuation_2 - mTol;
400  }
401 }
402 
403 protected:
404 
405 void Check() {
406  KRATOS_TRY
407 
408  KRATOS_ERROR_IF(mTol < 0.0) << "Entered tolerance must be a positive number" << std::endl;
409 
410  KRATOS_CATCH("")
411 }
412 
413 private:
414 
415 double mValue;
416 double mTol;
417 RealField::Pointer mpField1;
418 RealField::Pointer mpField2;
419 int mCase;
420 };
421 
422 //***************************************************************************************************************
423 //***************************************************************************************************************
424 
426 
429 
430 
434 
435 } // namespace Kratos.
436 #endif // KRATOS_SPACE_TIME_RULE_H
Definition: space_time_rule.h:159
~BoundingBoxRule()
Definition: space_time_rule.h:193
BoundingBoxRule()
Definition: space_time_rule.h:162
void SetXBoundingInterval(const double &low, const double &high)
Definition: space_time_rule.h:202
virtual std::string Info() const override
Turn back information as a stemplate<class T, std::size_t dim> tring.
Definition: space_time_rule.h:244
BoundingBoxRule(const double min_time, const double max_time, const double min_x, const double max_x, const double min_y, const double max_y, const double min_z, const double max_z)
Definition: space_time_rule.h:174
void SetYBoundingInterval(const double &low, const double &high)
Definition: space_time_rule.h:209
bool CheckIfRuleIsMet(const double time, const double coor_x, const double coor_y, const double coor_z) override
Definition: space_time_rule.h:236
void PrintData(std::ostream &rOStream=std::cout) const override
Print object's data.
Definition: space_time_rule.h:262
void Check()
Definition: space_time_rule.h:276
void SetTimeBoundingInterval(const double &low, const double &high)
Definition: space_time_rule.h:195
void SetSpaceTimeBoundingBox(const array_1d< double, 4 > &low, const array_1d< double, 4 > &high)
Definition: space_time_rule.h:223
void SetZBoundingInterval(const double &low, const double &high)
Definition: space_time_rule.h:216
Definition: space_time_rule.h:360
EqualToRule(RealField::Pointer field, const double value, const double tol)
Definition: space_time_rule.h:362
bool CheckIfRuleIsMet(const double time, const double coor_x, const double coor_y, const double coor_z) override
Definition: space_time_rule.h:384
~EqualToRule()
Definition: space_time_rule.h:382
EqualToRule(RealField::Pointer field_1, RealField::Pointer field_2, const double tol)
Definition: space_time_rule.h:372
void Check()
Definition: space_time_rule.h:405
Definition: space_time_rule.h:301
bool CheckIfRuleIsMet(const double time, const double coor_x, const double coor_y, const double coor_z) override
Definition: space_time_rule.h:324
~MoreThanRule()
Definition: space_time_rule.h:322
void Check()
Definition: space_time_rule.h:346
MoreThanRule(RealField::Pointer field, const double value)
Definition: space_time_rule.h:304
MoreThanRule(const double value, RealField::Pointer field)
Definition: space_time_rule.h:310
MoreThanRule(RealField::Pointer field_high, RealField::Pointer field_low)
Definition: space_time_rule.h:316
Definition: space_time_rule.h:30
KRATOS_CLASS_POINTER_DEFINITION(SpaceTimeRule)
virtual ~SpaceTimeRule()
Destructor.
Definition: space_time_rule.h:41
SpaceTimeRule()
Default constructor.
Definition: space_time_rule.h:37
virtual std::string Info() const
Turn back information as a stemplate<class T, std::size_t dim> tring.
Definition: space_time_rule.h:61
virtual bool CheckIfRuleIsMet(const double time, const double coor_x, const double coor_y, const double coor_z)
Definition: space_time_rule.h:46
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: space_time_rule.h:68
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: space_time_rule.h:72
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
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
float max_time
Definition: ProjectParameters.py:8
time
Definition: face_heat.py:85
int tol
Definition: hinsberg_optimization.py:138