CatmullRomSpline.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "CatmullRomSpline.H"
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
31 (
32  const label segmenti,
33  const scalar segmentLambdaArg
34 ) const
35 {
36  // Quick return if segment index is out of range
37  if (segmenti < 0) return start();
38  if (segmenti >= nSegments()) return end();
39 
40  // Points bounding the segment
41  const point& p0 = knots()[segmenti];
42  const point& p1 = knots()[segmenti + 1];
43 
44  // Points before and after the segment. If at the ends, use reflection.
45  const point pMinus1 =
46  segmenti == 0 ? 2*p0 - p1 : knots()[segmenti - 1];
47  const point p2 =
48  segmenti == nSegments() - 1 ? 2*p1 - p0 : knots()[segmenti + 2];
49 
50  // Clip the argument
51  const scalar segmentLambda =
52  min(max(segmentLambdaArg, scalar(0)), scalar(1));
53 
54  // Evaluate the function and return
55  const vector A = -pMinus1 + 3*p0 - 3*p1 + p2;
56  const vector B = 2*pMinus1 - 5*p0 + 4*p1 - p2;
57  const vector C = -pMinus1 + p1;
58  const vector D = 2*p0;
59  return (segmentLambda*(segmentLambda*(segmentLambda*A + B) + C) + D)/2;
60 }
61 
62 
63 // ************************************************************************* //
Graphite solid properties.
Definition: C.H:51
point position(const label segmenti, const scalar segmentLambda) const
Return the point position corresponding to the segment parameter.
label nSegments() const
Return the number of segments.
Definition: SplineI.H:40
const point & start() const
Return the start point.
Definition: SplineI.H:47
const pointField & knots() const
Access the end points and control points.
Definition: SplineI.H:31
const point & end() const
Return the end point.
Definition: SplineI.H:54
static const coefficient D("D", dimTemperature, 257.14)
static const coefficient B("B", dimless, 18.678)
static const coefficient A("A", dimPressure, 611.21)
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)