MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::KnotVector Class Reference

A vector of knots in one dimension, with B-spline basis functions of a prescribed order. More...

#include <nurbs.hpp>

Collaboration diagram for mfem::KnotVector:
[legend]

Public Member Functions

 KnotVector ()=default
 Collocation matrix inverse.
 
 KnotVector (std::istream &input)
 Create a KnotVector by reading data from stream input. Two integers are read, for order and number of control points.
 
 KnotVector (int order, int NCP=-1)
 Create a KnotVector with order order. When NCP is not provided the number of control points is set to order + 1, and the first order + 1 knots are set to 0 and last order + 1 knots are set to 1. When NCP is given number of control points is NCP and the knots are initialized to -1)
 
 KnotVector (int order, const Vector &k)
 Create a KnotVector with order order and knots knot. If k has the correct number of repeated knots at the begin and end, then this constructor will copy the knots as provided. Otherwise, the knot vector will be extended by repeating the end knots (order + 1) times. Internal knots will retain the multiplicity as given in the input.
 
 KnotVector (int order, const Vector &intervals, const Array< int > &continuity)
 Create a KnotVector by passing in a degree, a Vector of interval lengths of length n, and a list of continuity of length n + 1. The intervals refer to spans between unique knot values (not counting zero-size intervals at repeated knots), and the continuity values should be >= -1 (discontinuous) and <= order-1 (maximally-smooth for the given polynomial degree). Periodicity is not supported.
 
 KnotVector (const KnotVector &kv)
 Copy constructor.
 
KnotVectoroperator= (const KnotVector &kv)
 
int GetNE () const
 Return the number of elements, defined by distinct knots.
 
int GetNCP () const
 Return the number of control points.
 
int GetOrder () const
 Return the order.
 
int Size () const
 Return the number of knots, including multiplicities.
 
void GetElements ()
 Count the number of elements.
 
bool isElement (int i) const
 Return whether the knot index Order plus i is the beginning of an element.
 
int GetNKS () const
 Return the number of control points minus the order. This is not the number of knot spans, but it gives the number of knots to be checked with isElement for non-empty knot spans (elements).
 
bool inSpan (real_t u, int ni) const
 Return whether knot location u is in a given span ni.
 
int GetSpan (real_t u) const
 Return the index of the knot span containing parameter u.
 
real_t GetRefPoint (real_t u, int ni) const
 Return the reference coordinate in [0,1] for parameter u in the element beginning at knot ni.
 
real_t GetKnotLocation (real_t xi, int ni) const
 Return the knot location for element reference coordinate xi in [0,1], for the element beginning at knot ni.
 
MFEM_DEPRECATED real_t getKnotLocation (real_t xi, int ni) const
 Return the parameter for element reference coordinate xi in [0,1], for the element beginning at knot ni.
 
MFEM_DEPRECATED int findKnotSpan (real_t u) const
 Return the index of the knot span containing parameter u.
 
real_t GetGreville (int i) const
 
void GetGreville (Vector &xi) const
 
real_t GetBotella (int i) const
 
void GetBotella (Vector &xi) const
 
real_t GetDemko (int i) const
 
void GetDemko (Vector &xi) const
 
void CalcShape (Vector &shape, int i, real_t xi) const
 Calculate the nonvanishing shape function values in shape for the element corresponding to knot index i and element reference coordinate xi.
 
void CalcDShape (Vector &grad, int i, real_t xi) const
 Calculate derivatives of the nonvanishing shape function values in grad for the element corresponding to knot index i and element reference coordinate xi.
 
void CalcDnShape (Vector &gradn, int n, int i, real_t xi) const
 Calculate n-th derivatives (order n) of the nonvanishing shape function values in grad for the element corresponding to knot index i and element reference coordinate xi.
 
void CalcD2Shape (Vector &grad2, int i, real_t xi) const
 Calculate second-order shape function derivatives, using CalcDnShape.
 
MFEM_DEPRECATED void FindMaxima (Array< int > &ks, Vector &xi, Vector &u) const
 Gives the locations of the maxima of the KnotVector in reference space. The function gives the knot span ks, the coordinate in the knot span xi, and the coordinate of the maximum in parameter space u. The main purpose of this function is its use in FindInterpolant. Use GetBotella instead for each shape function separately, perhaps in conjunction with GetSpan and GetRefPoint.
 
MFEM_DEPRECATED void FindInterpolant (Array< Vector * > &x, bool reuse_inverse)
 Global curve interpolation through the points x (overwritten). x is an array with the length of the spatial dimension containing vectors with spatial coordinates. The control points of the interpolated curve are returned in x in the same form. Use GetInterpolant instead. For the knot location one can use either GetBotella, GetDemko or GetGreville. FindInterpolant uses the Botella points, however, the Demko points might be more appropriate.
 
void GetInterpolant (Array< Vector * > &x, const Vector &u, bool reuse_inverse=false) const
 Global curve interpolation through the points x (overwritten) at the knot location u. The control points of the interpolated curve are returned in x in the same form. For the knot location one can use for instance GetBotella, GetDemko or GetGreville. The Demko points might be most appropriate.
 
void GetInterpolant (const Vector &x, const Vector &u, Vector &a, bool reuse_inverse=false) const
 Different interface to same routine.
 
void Difference (const KnotVector &kv, Vector &diff) const
 
void UniformRefinement (Vector &new_knots, int rf) const
 Uniformly refine by factor rf, by inserting knots in each span.
 
void Refinement (Vector &new_knots, int rf) const
 Refine with refinement factor rf.
 
int GetCoarseningFactor () const
 
Vector GetFineKnots (const int cf) const
 
KnotVectorDegreeElevate (int t) const
 Return a new KnotVector with elevated degree by repeating the endpoints of the KnotVector.
 
void Flip ()
 Reverse the knots.
 
void Print (std::ostream &os) const
 Print the order, number of control points, and knots.
 
void PrintFunctions (std::ostream &os, int samples=11) const
 Prints the non-zero shape functions and their first and second derivatives associated with the KnotVector per element. Use GetElements() to count the elements before using this function. samples is the number of samples of the shape functions per element.
 
void PrintFunction (std::ostream &os, const Vector &a, int samples=11) const
 
void PrintFunction (std::ostream &os, int i, int samples=11) const
 
 ~KnotVector ()
 Destroys KnotVector.
 
real_toperator[] (int i)
 Access function to knot i.
 
const real_toperator[] (int i) const
 Const access function to knot i.
 
KnotVectorFullyCoarsen ()
 Coarsen to a single element.
 

Public Attributes

std::shared_ptr< SpacingFunctionspacing
 Function to define the distribution of knots for any number of knot spans.
 
bool coarse
 Flag to indicate whether the KnotVector has been coarsened, which means it is ready for non-nested refinement.
 

Protected Member Functions

void ComputeDemko () const
 Compute all the Demko points.
 

Protected Attributes

Vector knot
 Stores the values of all knots.
 
int Order
 Order of the B-spline basis functions.
 
int NumOfControlPoints
 Number of control points.
 
int NumOfElements
 Number of elements, defined by distinct knots.
 
Vector demko
 
DenseMatrix fact_AB
 
Array< int > fact_ipiv
 Banded matrix factorization.
 
DenseMatrix A_coll_inv
 Row pivot indices.
 

Static Protected Attributes

static const int MaxOrder = 10
 

Detailed Description

A vector of knots in one dimension, with B-spline basis functions of a prescribed order.

Note
Order is defined in the sense of "The NURBS book" - 2nd ed - Piegl and Tiller, cf. section 2.2.

Definition at line 37 of file nurbs.hpp.

Constructor & Destructor Documentation

◆ KnotVector() [1/6]

mfem::KnotVector::KnotVector ( )
default

Collocation matrix inverse.

Create an empty KnotVector.

◆ KnotVector() [2/6]

mfem::KnotVector::KnotVector ( std::istream & input)

Create a KnotVector by reading data from stream input. Two integers are read, for order and number of control points.

Definition at line 35 of file nurbs.cpp.

◆ KnotVector() [3/6]

mfem::KnotVector::KnotVector ( int order,
int NCP = -1 )

Create a KnotVector with order order. When NCP is not provided the number of control points is set to order + 1, and the first order + 1 knots are set to 0 and last order + 1 knots are set to 1. When NCP is given number of control points is NCP and the knots are initialized to -1)

Definition at line 44 of file nurbs.cpp.

◆ KnotVector() [4/6]

mfem::KnotVector::KnotVector ( int order,
const Vector & k )

Create a KnotVector with order order and knots knot. If k has the correct number of repeated knots at the begin and end, then this constructor will copy the knots as provided. Otherwise, the knot vector will be extended by repeating the end knots (order + 1) times. Internal knots will retain the multiplicity as given in the input.

Definition at line 72 of file nurbs.cpp.

◆ KnotVector() [5/6]

mfem::KnotVector::KnotVector ( int order,
const Vector & intervals,
const Array< int > & continuity )

Create a KnotVector by passing in a degree, a Vector of interval lengths of length n, and a list of continuity of length n + 1. The intervals refer to spans between unique knot values (not counting zero-size intervals at repeated knots), and the continuity values should be >= -1 (discontinuous) and <= order-1 (maximally-smooth for the given polynomial degree). Periodicity is not supported.

Definition at line 119 of file nurbs.cpp.

◆ KnotVector() [6/6]

mfem::KnotVector::KnotVector ( const KnotVector & kv)
inline

Copy constructor.

Definition at line 103 of file nurbs.hpp.

◆ ~KnotVector()

mfem::KnotVector::~KnotVector ( )
inline

Destroys KnotVector.

Definition at line 301 of file nurbs.hpp.

Member Function Documentation

◆ CalcD2Shape()

void mfem::KnotVector::CalcD2Shape ( Vector & grad2,
int i,
real_t xi ) const
inline

Calculate second-order shape function derivatives, using CalcDnShape.

Definition at line 214 of file nurbs.hpp.

◆ CalcDnShape()

void mfem::KnotVector::CalcDnShape ( Vector & gradn,
int n,
int i,
real_t xi ) const

Calculate n-th derivatives (order n) of the nonvanishing shape function values in grad for the element corresponding to knot index i and element reference coordinate xi.

Definition at line 813 of file nurbs.cpp.

◆ CalcDShape()

void mfem::KnotVector::CalcDShape ( Vector & grad,
int i,
real_t xi ) const

Calculate derivatives of the nonvanishing shape function values in grad for the element corresponding to knot index i and element reference coordinate xi.

Definition at line 755 of file nurbs.cpp.

◆ CalcShape()

void mfem::KnotVector::CalcShape ( Vector & shape,
int i,
real_t xi ) const

Calculate the nonvanishing shape function values in shape for the element corresponding to knot index i and element reference coordinate xi.

Definition at line 728 of file nurbs.cpp.

◆ ComputeDemko()

void mfem::KnotVector::ComputeDemko ( ) const
protected

Compute all the Demko points.

Definition at line 299 of file nurbs.cpp.

◆ DegreeElevate()

KnotVector * mfem::KnotVector::DegreeElevate ( int t) const

Return a new KnotVector with elevated degree by repeating the endpoints of the KnotVector.

Note
The returned object should be deleted by the caller.

Definition at line 403 of file nurbs.cpp.

◆ Difference()

void mfem::KnotVector::Difference ( const KnotVector & kv,
Vector & diff ) const

Set diff, comprised of knots in kv not contained in this KnotVector. kv must be of the same order as this KnotVector. The current implementation is not well defined, and the function may have undefined behavior, as diff may have unset entries at the end.

Definition at line 1219 of file nurbs.cpp.

◆ FindInterpolant()

void mfem::KnotVector::FindInterpolant ( Array< Vector * > & x,
bool reuse_inverse )

Global curve interpolation through the points x (overwritten). x is an array with the length of the spatial dimension containing vectors with spatial coordinates. The control points of the interpolated curve are returned in x in the same form. Use GetInterpolant instead. For the knot location one can use either GetBotella, GetDemko or GetGreville. FindInterpolant uses the Botella points, however, the Demko points might be more appropriate.

Definition at line 975 of file nurbs.cpp.

◆ findKnotSpan()

int mfem::KnotVector::findKnotSpan ( real_t u) const

Return the index of the knot span containing parameter u.

Definition at line 1190 of file nurbs.cpp.

◆ FindMaxima()

void mfem::KnotVector::FindMaxima ( Array< int > & ks,
Vector & xi,
Vector & u ) const

Gives the locations of the maxima of the KnotVector in reference space. The function gives the knot span ks, the coordinate in the knot span xi, and the coordinate of the maximum in parameter space u. The main purpose of this function is its use in FindInterpolant. Use GetBotella instead for each shape function separately, perhaps in conjunction with GetSpan and GetRefPoint.

Definition at line 914 of file nurbs.cpp.

◆ Flip()

void mfem::KnotVector::Flip ( )

Reverse the knots.

Definition at line 617 of file nurbs.cpp.

◆ FullyCoarsen()

KnotVector * mfem::KnotVector::FullyCoarsen ( )

Coarsen to a single element.

Definition at line 1254 of file nurbs.cpp.

◆ GetBotella() [1/2]

real_t mfem::KnotVector::GetBotella ( int i) const

Gives the knot location where the i shape function is maximum. Reverts to the Greville point if knot is repeated Order +1 times. For background see:

Olivier Botella and Karim Shariff. "B-spline methods in fluid dynamics." International Journal of Computational Fluid Dynamics 17.2 (2003): 133-149.

Points are found using Newton iteration, with the Greville point as the starting value.

Definition at line 230 of file nurbs.cpp.

◆ GetBotella() [2/2]

void mfem::KnotVector::GetBotella ( Vector & xi) const

Definition at line 271 of file nurbs.cpp.

◆ GetCoarseningFactor()

int mfem::KnotVector::GetCoarseningFactor ( ) const

Returns the coarsening factor needed for non-nested nonuniform spacing functions, to result in a single element from which refinement can be done. The return value is 1 if uniform or nested spacing is used.

Definition at line 453 of file nurbs.cpp.

◆ GetDemko() [1/2]

real_t mfem::KnotVector::GetDemko ( int i) const

Gives the knot location of the i extremum of the Chebyshev spline. For background see:

Stephen Demko "On the existence of interpolating projections onto spline spaces." Journal of approximation theory 43.2 (1985): 151-156.

Points are found using Remez iteration:

  • Find interpolant, given by a, through given points, given by Demko
  • Find extrema of this polynomial and update Demko points
  • Repeat until converged
  • Use the Greville point as starting point

Definition at line 281 of file nurbs.cpp.

◆ GetDemko() [2/2]

void mfem::KnotVector::GetDemko ( Vector & xi) const

Definition at line 290 of file nurbs.cpp.

◆ GetElements()

void mfem::KnotVector::GetElements ( )

Count the number of elements.

Definition at line 605 of file nurbs.cpp.

◆ GetFineKnots()

Vector mfem::KnotVector::GetFineKnots ( const int cf) const

For a given coarsening factor cf, find the fine knots between the coarse knots.

Definition at line 472 of file nurbs.cpp.

◆ GetGreville() [1/2]

real_t mfem::KnotVector::GetGreville ( int i) const

Gives the i average knot location. Average is taken over Order number of knots.

Definition at line 213 of file nurbs.cpp.

◆ GetGreville() [2/2]

void mfem::KnotVector::GetGreville ( Vector & xi) const

Definition at line 220 of file nurbs.cpp.

◆ GetInterpolant() [1/2]

void mfem::KnotVector::GetInterpolant ( Array< Vector * > & x,
const Vector & u,
bool reuse_inverse = false ) const

Global curve interpolation through the points x (overwritten) at the knot location u. The control points of the interpolated curve are returned in x in the same form. For the knot location one can use for instance GetBotella, GetDemko or GetGreville. The Demko points might be most appropriate.

Definition at line 1092 of file nurbs.cpp.

◆ GetInterpolant() [2/2]

void mfem::KnotVector::GetInterpolant ( const Vector & x,
const Vector & u,
Vector & a,
bool reuse_inverse = false ) const

Different interface to same routine.

Definition at line 1080 of file nurbs.cpp.

◆ GetKnotLocation()

real_t mfem::KnotVector::GetKnotLocation ( real_t xi,
int ni ) const
inline

Return the knot location for element reference coordinate xi in [0,1], for the element beginning at knot ni.

Definition at line 148 of file nurbs.hpp.

◆ getKnotLocation()

MFEM_DEPRECATED real_t mfem::KnotVector::getKnotLocation ( real_t xi,
int ni ) const
inline

Return the parameter for element reference coordinate xi in [0,1], for the element beginning at knot ni.

Definition at line 153 of file nurbs.hpp.

◆ GetNCP()

int mfem::KnotVector::GetNCP ( ) const
inline

Return the number of control points.

Definition at line 111 of file nurbs.hpp.

◆ GetNE()

int mfem::KnotVector::GetNE ( ) const
inline

Return the number of elements, defined by distinct knots.

Definition at line 108 of file nurbs.hpp.

◆ GetNKS()

int mfem::KnotVector::GetNKS ( ) const
inline

Return the number of control points minus the order. This is not the number of knot spans, but it gives the number of knots to be checked with isElement for non-empty knot spans (elements).

Definition at line 129 of file nurbs.hpp.

◆ GetOrder()

int mfem::KnotVector::GetOrder ( ) const
inline

Return the order.

Definition at line 114 of file nurbs.hpp.

◆ GetRefPoint()

real_t mfem::KnotVector::GetRefPoint ( real_t u,
int ni ) const
inline

Return the reference coordinate in [0,1] for parameter u in the element beginning at knot ni.

Definition at line 143 of file nurbs.hpp.

◆ GetSpan()

int mfem::KnotVector::GetSpan ( real_t u) const

Return the index of the knot span containing parameter u.

Definition at line 175 of file nurbs.cpp.

◆ inSpan()

bool mfem::KnotVector::inSpan ( real_t u,
int ni ) const
inline

Return whether knot location u is in a given span ni.

Definition at line 132 of file nurbs.hpp.

◆ isElement()

bool mfem::KnotVector::isElement ( int i) const
inline

Return whether the knot index Order plus i is the beginning of an element.

Definition at line 124 of file nurbs.hpp.

◆ operator=()

KnotVector & mfem::KnotVector::operator= ( const KnotVector & kv)

Definition at line 163 of file nurbs.cpp.

◆ operator[]() [1/2]

real_t & mfem::KnotVector::operator[] ( int i)
inline

Access function to knot i.

Definition at line 304 of file nurbs.hpp.

◆ operator[]() [2/2]

const real_t & mfem::KnotVector::operator[] ( int i) const
inline

Const access function to knot i.

Definition at line 307 of file nurbs.hpp.

◆ Print()

void mfem::KnotVector::Print ( std::ostream & os) const

Print the order, number of control points, and knots.

The output is formatted for writing a mesh to file. This function is called by NURBSPatch::Print.

Definition at line 632 of file nurbs.cpp.

◆ PrintFunction() [1/2]

void mfem::KnotVector::PrintFunction ( std::ostream & os,
const Vector & a,
int samples = 11 ) const

Prints the function with basis function coefficient a, and its first and second derivatives associated with the KnotVector per element. Use GetElements() to count the elements before using this function. samples is the number of samples of the shape functions per element.

Definition at line 669 of file nurbs.cpp.

◆ PrintFunction() [2/2]

void mfem::KnotVector::PrintFunction ( std::ostream & os,
int i,
int samples = 11 ) const

Prints the i-th function and its first and second derivatives associated with the KnotVector per element. Use GetElements() to count the elements before using this function. samples is the number of samples of the shape functions per element.

Definition at line 717 of file nurbs.cpp.

◆ PrintFunctions()

void mfem::KnotVector::PrintFunctions ( std::ostream & os,
int samples = 11 ) const

Prints the non-zero shape functions and their first and second derivatives associated with the KnotVector per element. Use GetElements() to count the elements before using this function. samples is the number of samples of the shape functions per element.

Definition at line 638 of file nurbs.cpp.

◆ Refinement()

void mfem::KnotVector::Refinement ( Vector & new_knots,
int rf ) const

Refine with refinement factor rf.

Definition at line 540 of file nurbs.cpp.

◆ Size()

int mfem::KnotVector::Size ( ) const
inline

Return the number of knots, including multiplicities.

Definition at line 117 of file nurbs.hpp.

◆ UniformRefinement()

void mfem::KnotVector::UniformRefinement ( Vector & new_knots,
int rf ) const

Uniformly refine by factor rf, by inserting knots in each span.

Definition at line 432 of file nurbs.cpp.

Member Data Documentation

◆ A_coll_inv

DenseMatrix mfem::KnotVector::A_coll_inv
mutableprotected

Row pivot indices.

Definition at line 65 of file nurbs.hpp.

◆ coarse

bool mfem::KnotVector::coarse

Flag to indicate whether the KnotVector has been coarsened, which means it is ready for non-nested refinement.

Definition at line 317 of file nurbs.hpp.

◆ demko

Vector mfem::KnotVector::demko
mutableprotected

Definition at line 55 of file nurbs.hpp.

◆ fact_AB

DenseMatrix mfem::KnotVector::fact_AB
mutableprotected

Definition at line 62 of file nurbs.hpp.

◆ fact_ipiv

Array<int> mfem::KnotVector::fact_ipiv
mutableprotected

Banded matrix factorization.

Definition at line 63 of file nurbs.hpp.

◆ knot

Vector mfem::KnotVector::knot
protected

Stores the values of all knots.

Definition at line 43 of file nurbs.hpp.

◆ MaxOrder

const int mfem::KnotVector::MaxOrder = 10
staticprotected

Definition at line 40 of file nurbs.hpp.

◆ NumOfControlPoints

int mfem::KnotVector::NumOfControlPoints
protected

Number of control points.

Definition at line 49 of file nurbs.hpp.

◆ NumOfElements

int mfem::KnotVector::NumOfElements
protected

Number of elements, defined by distinct knots.

Definition at line 52 of file nurbs.hpp.

◆ Order

int mfem::KnotVector::Order
protected

Order of the B-spline basis functions.

Definition at line 46 of file nurbs.hpp.

◆ spacing

std::shared_ptr<SpacingFunction> mfem::KnotVector::spacing

Function to define the distribution of knots for any number of knot spans.

Definition at line 313 of file nurbs.hpp.


The documentation for this class was generated from the following files: