10 #if !defined(KRATOS_SPLINE_CURVE_UTILITIES_H_INCLUDED )
11 #define KRATOS_SPLINE_CURVE_UTILITIES_H_INCLUDED
23 #include "boost/smart_ptr.hpp"
110 NodesContainerType::iterator nodes_begin = rGeneratrixPoints.begin();
112 double X = 2.0 * nodes_begin->X() - (nodes_begin + 1)->
X();
113 double Y = 2.0 * nodes_begin->Y() - (nodes_begin + 1)->
Y();
114 double Z = 2.0 * nodes_begin->Z() - (nodes_begin + 1)->
Z();
117 rKnotsList.push_back( KnotPoint );
121 for(NodePointerTypeVector::iterator in = rGeneratrixPoints.begin(); in!=rGeneratrixPoints.end(); in++)
124 rKnotsList.push_back( KnotPoint );
130 NodesContainerType::iterator nodes_end = rGeneratrixPoints.end()-1;
132 X = 2.0 * (nodes_end)->
X() - (nodes_end - 1)->
X();
133 Y = 2.0 * (nodes_end)->
Y() - (nodes_end - 1)->
Y();
134 Z = 2.0 * (nodes_end)->
Z() - (nodes_end - 1)->
Z();
137 rKnotsList.push_back( KnotPoint );
144 double TotalLength = 0;
145 std::vector<double> SegmentArchLengths;
149 int size = rKnotsList.size()-2;
153 for(
int i=1;
i<size;
i++)
164 SegmentArchLengths.push_back(
S);
171 int n_segments = SegmentArchLengths.size();
176 double Length = TotalLength /
double(
m);
180 nodes_begin = rKnotsList.begin();
183 X = nodes_begin->X();
184 Y = nodes_begin->Y();
185 Z = nodes_begin->Z();
188 NewKnotsList.push_back( KnotPoint );
191 X = (nodes_begin + 1)->
X();
192 Y = (nodes_begin + 1)->
Y();
193 Z = (nodes_begin + 1)->
Z();
196 NewKnotsList.push_back( KnotPoint );
199 for(
int i=1;
i <
m;
i++)
205 for(
int k = 0;
k < n_segments;
k++)
207 S += SegmentArchLengths[
k];
211 S -= SegmentArchLengths[
k];
217 if( (
i*Length -
S) < 0 )
218 std::cout<<
" Something is wrong in the index search KNOT["<<
j<<
"]: length "<<
i*Length<<
" S "<<
S<<std::endl;
227 double tolerance = (
i*Length -
S) * 1
e-3;
228 double error = tolerance * 10;
248 while ( fabs(
error) > tolerance && iters < max_iters )
250 middle = 0.5 * (
left + right);
257 if( (DeltaS) < (
i*Length -
S) ){
264 error = (DeltaS) - (
i*Length -
S);
274 if( fabs(
error) > tolerance || iters == max_iters )
275 std::cout<<
" max iters reached in Bisection "<<iters<<
" error: "<<
error<<
" ["<<tolerance<<
"]"<<std::endl;
287 NewKnotsList.push_back( KnotPoint );
297 nodes_end = rKnotsList.end()-2;
299 X = (nodes_end)->
X();
300 Y = (nodes_end)->
Y();
301 Z = (nodes_end)->
Z();
306 NewKnotsList.push_back( KnotPoint );
310 nodes_end = NewKnotsList.end()-1;
312 X = 2.0 * (nodes_end)->
X() - (nodes_end - 1)->
X();
313 Y = 2.0 * (nodes_end)->
Y() - (nodes_end - 1)->
Y();
314 Z = 2.0 * (nodes_end)->
Z() - (nodes_end - 1)->
Z();
319 NewKnotsList.push_back( KnotPoint );
323 nodes_end = NewKnotsList.end()-1;
325 X = 2.0 * (nodes_end)->
X() - (nodes_end - 1)->
X();
326 Y = 2.0 * (nodes_end)->
Y() - (nodes_end - 1)->
Y();
327 Z = 2.0 * (nodes_end)->
Z() - (nodes_end - 1)->
Z();
332 NewKnotsList.push_back( KnotPoint );
335 nodes_begin = NewKnotsList.begin() + 1;
337 X = 2.0 * nodes_begin->X() - (nodes_begin + 1)->
X();
338 Y = 2.0 * nodes_begin->Y() - (nodes_begin + 1)->
Y();
339 Z = 2.0 * nodes_begin->Z() - (nodes_begin + 1)->
Z();
347 NewKnotsList.front() = KnotPoint;
355 rKnotsList.swap(NewKnotsList);
362 for(
unsigned int i=0;
i<rKnotsList.size();
i++){
363 rKnotsList[
i]->SetId(
i);
382 double tolerance =
S * 1
e-2;
383 double error = tolerance * 10;
388 std::vector<SplineType> Intervals;
389 Intervals.push_back(rSpline);
391 while( fabs(
error) > tolerance && iters < max_iters )
410 if( fabs(
error) > tolerance || iters == max_iters )
411 std::cout<<
" max iters reached in Adaptive Integration "<<iters<<
" error: "<<
error<<
" ["<<tolerance<<
"]"<<std::endl;
433 for(
int i=0;
i<
n+1;
i++)
467 double IntegralValue = 0;
469 double h = (
b -
a) /
n;
474 for(
int i=1;
i<
n;
i+=2)
481 for(
int i=2;
i<
n-1;
i+=2)
488 IntegralValue = (s *
h / 3.0);
490 return IntegralValue;
512 rOutputSpline.
id = rInputSpline.
id;
514 rOutputSpline.
P0 = rInputSpline.
P0;
515 rOutputSpline.
P1 = rInputSpline.
P1;
516 rOutputSpline.
P2 = rInputSpline.
P2;
517 rOutputSpline.
P3 = rInputSpline.
P3;
543 rSpline.
P0[0] = rKnotsList[
id-1]->X();
544 rSpline.
P0[1] = rKnotsList[
id-1]->Y();
545 rSpline.
P0[2] = rKnotsList[
id-1]->Z();
548 rSpline.
P1[0] = rKnotsList[id]->X();
549 rSpline.
P1[1] = rKnotsList[id]->Y();
550 rSpline.
P1[2] = rKnotsList[id]->Z();
553 rSpline.
P2[0] = rKnotsList[
id+1]->X();
554 rSpline.
P2[1] = rKnotsList[
id+1]->Y();
555 rSpline.
P2[2] = rKnotsList[
id+1]->Z();
558 rSpline.
P3[0] = rKnotsList[
id+2]->X();
559 rSpline.
P3[1] = rKnotsList[
id+2]->Y();
560 rSpline.
P3[2] = rKnotsList[
id+2]->Z();
572 double PointDistance = 0;
574 int id = rKnotsList.front()->Id();
586 rPointProjection =
PointOnCurve(rPointProjection,Spline,Sk);
590 return rPointProjection;
601 NodeType WorkPoint(0,rPoint[0],rPoint[1],rPoint[2]);
607 return NearestPoint->Id();
643 double Sk = Spredict;
644 int max_iters = iters;
648 int segment_iter = 0;
649 while( ((Sk < -0.1 || Sk >1) && segment_iter<max_iters) || segment_iter == 0 )
654 int new_id = rSpline.
id - 1;
669 int new_id = rSpline.
id + 1;
671 if( new_id > (
int)rKnotsList.size()-3 )
672 new_id = rKnotsList.size()-3;
685 double tolerance = 1
e-7;
688 double distance = tolerance*10;
690 while( iter<dist_iters && distance>=tolerance )
700 distance = fabs(distance);
708 if( distance > tolerance ){
709 std::cout<<
"BBX Tube Contact Search [Point:"<<rPoint<<
",Distance:"<<distance<<
",Tol:"<<tolerance<<
"] ERROR"<<std::endl;
710 if( distance > 1e3*tolerance )
711 KRATOS_THROW_ERROR( std::logic_error,
" TUBE BBX::NewmarksMethod HAS NOT REACHED CONVERGENCE ", 0)
723 if( Sk < 0 && Sk > -0.1)
736 int max_iters = iters;
739 int segment_iter = 0;
740 while( ((Skj < 0 || Skj >1) && segment_iter<max_iters) || segment_iter == 0 )
745 int new_id = rSpline.
id - 1;
756 int new_id = rSpline.
id + 1;
758 if( new_id > (
int)rKnotsList.size()-3 )
759 new_id = rKnotsList.size()-3;
791 double tolerance = 1
e-7;
792 double distance = tolerance * 10;
797 while( iter < max_iters && distance >= tolerance )
814 Skj = 0.5 * (SquareDifference[1]*Function[0] + SquareDifference[2]*Function[1] + SquareDifference[0]*Function[2]);
815 Skj /= (Difference[1]*Function[0] + Difference[2]*Function[1] + Difference[0]*Function[2]);
823 double larger_distance = fabs(InterpolatedDistance[0]);
826 for(
unsigned int i=1;
i<3;
i++)
828 if(larger_distance<fabs(InterpolatedDistance[
i])){
829 larger_distance = fabs(InterpolatedDistance[
i]);
834 if(fabs(InterpolatedDistance[largest])>distance)
836 Estimates[largest] = Skj;
841 distance = fabs(Skj-Ski);
874 double PolynomialValue = PolynomialBasis[0]*rFunction[0] + PolynomialBasis[1]*rFunction[1] + PolynomialBasis[2]*rFunction[2];
876 return PolynomialValue;
884 rDifference[0] = rEstimates[0]-rEstimates[1];
885 rDifference[1] = rEstimates[1]-rEstimates[2];
886 rDifference[2] = rEstimates[2]-rEstimates[0];
896 rSquareDifference[0] = rEstimates[0] * rEstimates[0] - rEstimates[1] * rEstimates[1];
897 rSquareDifference[1] = rEstimates[1] * rEstimates[1] - rEstimates[2] * rEstimates[2];
898 rSquareDifference[2] = rEstimates[2] * rEstimates[2] - rEstimates[0] * rEstimates[0];
900 return rSquareDifference;
910 rPolynomialBasis[0] = (rValue-rEstimates[1]) * (rValue-rEstimates[2]) / ((rEstimates[0]-rEstimates[1]) * (rEstimates[0]-rEstimates[2]));
911 rPolynomialBasis[1] = (rValue-rEstimates[0]) * (rValue-rEstimates[2]) / ((rEstimates[1]-rEstimates[0]) * (rEstimates[1]-rEstimates[2]));
912 rPolynomialBasis[2] = (rValue-rEstimates[0]) * (rValue-rEstimates[1]) / ((rEstimates[2]-rEstimates[0]) * (rEstimates[2]-rEstimates[1]));
914 return rPolynomialBasis;
929 SplinePoint -= rPoint;
930 double Distance =
inner_prod(SplinePoint,SplinePoint);
944 SplinePoint -= rPoint;
949 double Distance = 2.0 *
inner_prod(SplinePoint,SplinePointFirstDerivative);
964 SplinePoint -= rPoint;
972 double Distance =
inner_prod(SplinePointFirstDerivative,SplinePointFirstDerivative);
973 Distance +=
inner_prod(SplinePoint,SplinePointSecondDerivative);
993 rPoint = Basis[0] * rSpline.
P0 + Basis[1] * rSpline.
P1 + Basis[2] * rSpline.
P2 + Basis[3] * rSpline.
P3;
1012 PointType Result = Basis[0] * rSpline.
P0 + Basis[1] * rSpline.
P1 + Basis[2] * rSpline.
P2 + Basis[3] * rSpline.
P3;
1030 PointType Result = Basis[0] * rSpline.
P0 + Basis[1] * rSpline.
P1 + Basis[2] * rSpline.
P2 + Basis[3] * rSpline.
P3;
1044 if( rCoefficients.size() != 4 )
1045 rCoefficients.resize(4);
1047 rCoefficients[0] = (rSpline.
P2 - rSpline.
P0) * s + rSpline.
P1 * (2.0 - s) + rSpline.
P1 * (s - 2.0);
1048 rCoefficients[1] = (2.0 * rSpline.
P0 - rSpline.
P2) * s + rSpline.
P1 * (s - 3.0) + rSpline.
P1 * (3.0 - 2.0 * s);
1049 rCoefficients[2] = (rSpline.
P1 - rSpline.
P0) * s;
1050 rCoefficients[3] = rSpline.
P0;
1052 return rCoefficients;
1064 if( Basis.size() != 4 )
1067 Basis[0] = ((-
t + 2.0) *
t - 1.0) *
t * s;
1068 Basis[1] = ((((2.0/s - 1.0) *
t + (1.0 - 3.0/s)) *
t) *
t + 1.0/s) * s;
1069 Basis[2] = (((1.0 - 2.0/s) *
t + (3.0/s - 2.0)) *
t + 1.0) *
t * s;
1070 Basis[3] = ((
t - 1.0) *
t *
t) * s;
1084 if( Basis.size() != 4 )
1087 Basis[0] = ((-3.0 *
t + 4.0) *
t - 1.0) * s;
1088 Basis[1] = (((6.0/s - 3.0) *
t + (2.0 - 6.0/s)) *
t) * s;
1089 Basis[2] = (((3.0 - 6.0/s) *
t + (6.0/s - 4.0)) *
t + 1.0) * s;
1090 Basis[3] = (3.0 *
t - 2.0) *
t * s;
1103 if( Basis.size() != 4 )
1106 Basis[0] = (-6.0 *
t + 4.0) * s;
1107 Basis[1] = ((12.0/s - 6.0) *
t + (2.0 - 6.0/s)) * s;
1108 Basis[2] = ((6.0 - 12.0/s) *
t + (6.0/s - 4.0)) * s;
1109 Basis[3] = (6.0 *
t - 2.0) * s;
Short class definition.
Definition: bucket.h:57
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
This class defines the node.
Definition: node.h:65
Point class.
Definition: point.h:59
Short class definition.
Definition: spline_curve_utilities.hpp:44
double SquareDistancePointToSpline(const PointType &rPoint, const SplineType &rSpline, double &t)
Definition: spline_curve_utilities.hpp:922
Tree< KDTreePartition< BucketType > > KdtreeType
Definition: spline_curve_utilities.hpp:62
double ArchLengthGeometricIntegration(SplineType &rSpline, double &a, double &b)
Definition: spline_curve_utilities.hpp:448
double QuadraticMinimizationMethod(const PointType &rPoint, const NodePointerTypeVector &rKnotsList, SplineType &rSpline, double iters, double s=0.5)
Definition: spline_curve_utilities.hpp:733
std::vector< double >::iterator DistanceIterator
Definition: spline_curve_utilities.hpp:60
PointType PointOnCurveFirstDerivative(const SplineType &rSpline, double &t, double s=0.5)
Definition: spline_curve_utilities.hpp:1006
static Vector & SplineBasis(Vector &Basis, double &t, double s=0.5)
Definition: spline_curve_utilities.hpp:1062
void SetSpline(SplineType &rOutputSpline, const SplineType &rInputSpline)
Definition: spline_curve_utilities.hpp:509
ModelPart::NodesContainerType NodesContainerType
Definition: spline_curve_utilities.hpp:50
void SetSpline(SplineType &rSpline, const PointType &P0, const PointType &P1, const PointType &P2, const PointType &P3)
Definition: spline_curve_utilities.hpp:523
NodePointerTypeVector::iterator NodePointerIterator
Definition: spline_curve_utilities.hpp:58
static std::vector< Vector > & SplineCoefficients(const SplineType &rSpline, std::vector< Vector > &rCoefficients, double s=0.5)
Definition: spline_curve_utilities.hpp:1042
PointType PointOnCurveSecondDerivative(const SplineType &rSpline, double &t, double s=0.5)
Definition: spline_curve_utilities.hpp:1024
NodeType::Pointer NodePointerType
Definition: spline_curve_utilities.hpp:55
PointType & CalculatePointProjection(const PointType &rPoint, KdtreeType &rKnotsKdtree, const NodePointerTypeVector &rKnotsList, PointType &rPointProjection)
Definition: spline_curve_utilities.hpp:567
double IntegrateSubInterval(SplineType &rSpline, int n=0)
Definition: spline_curve_utilities.hpp:424
PointType & PointOnCurve(PointType &rPoint, const SplineType &rSpline, double &t, double s=0.5)
Definition: spline_curve_utilities.hpp:987
double SecondDerivativeSquareDistancePointToSpline(const PointType &rPoint, const SplineType &rSpline, double &t)
Definition: spline_curve_utilities.hpp:958
SplineCurveUtilities()
Default constructor.
Definition: spline_curve_utilities.hpp:80
void SetSpline(SplineType &rSpline, const NodePointerTypeVector &rKnotsList, int &id)
Definition: spline_curve_utilities.hpp:537
SplineCurveUtilities(bool Parallel)
Definition: spline_curve_utilities.hpp:82
double SimpsonRuleIntegration(SplineType &rSpline, double &a, double &b, double n=1)
Definition: spline_curve_utilities.hpp:464
double AdaptiveIntegration(SplineType &rSpline)
Definition: spline_curve_utilities.hpp:371
~SplineCurveUtilities()
Destructor.
Definition: spline_curve_utilities.hpp:85
std::vector< double > DistanceVector
Definition: spline_curve_utilities.hpp:59
std::vector< NodePointerType > NodePointerTypeVector
Definition: spline_curve_utilities.hpp:56
double FirstDerivativeSquareDistancePointToSpline(const PointType &rPoint, const SplineType &rSpline, double &t)
Definition: spline_curve_utilities.hpp:938
static Vector & FirstDerivativeSplineBasis(Vector &Basis, double &t, double s=0.5)
Definition: spline_curve_utilities.hpp:1082
Vector & CalculateSquareArchLengthDifferences(Vector &rSquareDifference, const Vector &rEstimates)
Definition: spline_curve_utilities.hpp:894
Bucket< 3, NodeType, NodePointerTypeVector, NodePointerType, NodePointerIterator, DistanceIterator > BucketType
Definition: spline_curve_utilities.hpp:61
void CreateParametrizedCurve(NodePointerTypeVector &rGeneratrixPoints, NodePointerTypeVector &rKnotsList, int m)
Definition: spline_curve_utilities.hpp:101
double EvaluateDistancePolynomial(const Vector &rFunction, const Vector &rEstimates, double &Sk)
Definition: spline_curve_utilities.hpp:867
array_1d< double, 3 > PointType
Definition: spline_curve_utilities.hpp:53
Node NodeType
Definition: spline_curve_utilities.hpp:54
double NewtonsMethod(const PointType &rPoint, const NodePointerTypeVector &rKnotsList, SplineType &rSpline, double Spredict=0, double iters=20, double s=0.5)
Definition: spline_curve_utilities.hpp:639
Vector & CalculateArchLengthDifferences(Vector &rDifference, const Vector &rEstimates)
Definition: spline_curve_utilities.hpp:882
double CombinedMethod(const PointType &rPoint, const NodePointerTypeVector &rKnotsList, SplineType &rSpline, double s=0.5)
Definition: spline_curve_utilities.hpp:614
static Vector & SecondDerivativeSplineBasis(Vector &Basis, double &t, double s=0.5)
Definition: spline_curve_utilities.hpp:1101
int GetClosestKnotId(const PointType &rPoint, KdtreeType &rKnotsKdtree, double &rPointDistance)
Definition: spline_curve_utilities.hpp:598
Vector & CalculateDistancePolynomialBasis(Vector &rPolynomialBasis, const Vector &rEstimates, double &rValue)
Definition: spline_curve_utilities.hpp:908
std::vector< NodeType > NodeTypeVector
Definition: spline_curve_utilities.hpp:57
double SplineGeometricLength(SplineType &rSpline, double &t)
Definition: spline_curve_utilities.hpp:496
A generic tree data structure for spatial partitioning.
Definition: tree.h:190
PointerType SearchNearestPoint(PointType const &ThisPoint, CoordinateType &rResultDistance)
Search for the nearest point to a given point.
Definition: tree.h:391
#define KRATOS_THROW_ERROR(ExceptionType, ErrorMessage, MoreInfo)
Definition: define.h:77
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
float error
Definition: PecletTest.py:102
left
Definition: exact_hinsberg_test.py:140
h
Definition: generate_droplet_dynamics.py:91
a
Definition: generate_stokes_twofluid_element.py:77
S
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:39
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
int t
Definition: ode_solve.py:392
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
int m
Definition: run_marine_rain_substepping.py:8
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31
Definition: spline_curve_utilities.hpp:66
PointType P0
Definition: spline_curve_utilities.hpp:68
PointType P1
Definition: spline_curve_utilities.hpp:69
int id
Definition: spline_curve_utilities.hpp:67
PointType P3
Definition: spline_curve_utilities.hpp:71
PointType P2
Definition: spline_curve_utilities.hpp:70