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.
nurbs_interval.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Thomas Oberbichler
11 //
12 // Ported from the ANurbs library (https://github.com/oberbichler/ANurbs)
13 //
14 
15 #if !defined(KRATOS_NURBS_INTERVAL_H_INCLUDED )
16 #define KRATOS_NURBS_INTERVAL_H_INCLUDED
17 
18 // System includes
19 #include <algorithm>
20 #include <limits>
21 #include <sstream>
22 
23 // External includes
24 
25 // Project includes
26 
27 namespace Kratos
28 {
29 
31 /*
32 * Provides universal geometrical utiltity functions for the computation of
33 * curve and surface NURBS/ B-Spline shape functions.
34 */
36 {
37 public:
41  {
42  }
43 
44  NurbsInterval(const double T0, const double T1)
45  : mT0(T0)
46  , mT1(T1)
47  {
48  }
49 
50  NurbsInterval(const std::pair<double, double> Bounds)
51  : mT0(Bounds.first)
52  , mT1(Bounds.second)
53  {
54  }
55 
59 
60  double GetT0() const
61  {
62  return mT0;
63  }
64 
65  void SetT0(const double Value)
66  {
67  mT0 = Value;
68  }
69 
70  double GetT1() const
71  {
72  return mT1;
73  }
74 
75  void SetT1(const double Value)
76  {
77  mT1 = Value;
78  }
79 
80  double MinParameter() const
81  {
82  return std::min(mT0, mT1);
83  }
84 
85  double MaxParameter() const
86  {
87  return std::max(mT0, mT1);
88  }
89 
90  double GetDelta() const
91  {
92  return mT1 - mT0;
93  }
94 
95  double GetLength() const
96  {
97  return std::abs(GetDelta());
98  }
99 
103 
104  double GetNormalizedAt(const double Parameter) const
105  {
106  return (Parameter - mT0) / GetLength();
107  }
108 
109  double GetParameterAtNormalized(const double Parameter) const
110  {
111  return mT0 + GetDelta() * Parameter;
112  }
113 
114  static double GetParameterAtNormalized(const double A, const double B,
115  const double Parameter)
116  {
117  return A + (B - A) * Parameter;
118  }
119 
120  NurbsInterval GetNormalizedInterval(const double T0, const double T1) const
121  {
122  double t0Normalized = GetNormalizedAt(T0);
123  double t1Normalized = GetNormalizedAt(T1);
124 
125  return NurbsInterval(t0Normalized, t1Normalized);
126  }
127 
129  {
130  return GetNormalizedInterval(Bounds.mT0, Bounds.mT1);
131  }
132 
136 
137  /*
138  * @brief Detects if ParameterT lays within the limits of this interval.
139  * Keeps the ParameterT or sets it to the value of the insulted
140  * bounding interval limit.
141  * @return true if ParameterT is inside.
142  */
143  bool IsInside(double& ParameterT) const
144  {
145  const double min_parameter = MinParameter();
146  if (ParameterT < min_parameter) {
147  ParameterT = min_parameter;
148  return false;
149  }
150 
151  const double max_parameter = MaxParameter();
152  if (ParameterT > max_parameter) {
153  ParameterT = max_parameter;
154  return false;
155  }
156 
157  return true;
158  }
159 
161 private:
164 
166  double mT0 = 0;
167 
169  double mT1 = 0;
170 
174 
175  friend class Serializer;
176 
177  void save(Serializer& rSerializer) const
178  {
179  rSerializer.save("T0", mT0);
180  rSerializer.save("T1", mT1);
181  }
182 
183  void load(Serializer& rSerializer)
184  {
185  rSerializer.load("T0", mT0);
186  rSerializer.load("T1", mT1);
187  }
188 
190 }; // NurbsInterval
191 
192 } // namespace Kratos
193 
194 #endif // KRATOS_NURBS_INTERVAL_H_INCLUDED defined
Class for optimized use of intervals.
Definition: nurbs_interval.h:36
NurbsInterval(const std::pair< double, double > Bounds)
Definition: nurbs_interval.h:50
NurbsInterval()
Definition: nurbs_interval.h:40
double GetLength() const
Definition: nurbs_interval.h:95
double MaxParameter() const
Definition: nurbs_interval.h:85
NurbsInterval GetNormalizedInterval(const NurbsInterval Bounds) const
Definition: nurbs_interval.h:128
bool IsInside(double &ParameterT) const
Definition: nurbs_interval.h:143
static double GetParameterAtNormalized(const double A, const double B, const double Parameter)
Definition: nurbs_interval.h:114
void SetT1(const double Value)
Definition: nurbs_interval.h:75
double GetDelta() const
Definition: nurbs_interval.h:90
NurbsInterval(const double T0, const double T1)
Definition: nurbs_interval.h:44
NurbsInterval GetNormalizedInterval(const double T0, const double T1) const
Definition: nurbs_interval.h:120
double GetNormalizedAt(const double Parameter) const
Definition: nurbs_interval.h:104
double GetT1() const
Definition: nurbs_interval.h:70
double GetT0() const
Definition: nurbs_interval.h:60
void SetT0(const double Value)
Definition: nurbs_interval.h:65
double MinParameter() const
Definition: nurbs_interval.h:80
double GetParameterAtNormalized(const double Parameter) const
Definition: nurbs_interval.h:109
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
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
def load(f)
Definition: ode_solve.py:307
A
Definition: sensitivityMatrix.py:70
B
Definition: sensitivityMatrix.py:76