Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Nektar::LibUtilities::Kernel Class Reference

#include <kernel.h>

Public Member Functions

 Kernel ()
 The default constructor.
 Kernel (int order)
void UpdateKernelBspline ()
 The default destructor.
void UpdateKernelCoeffs ()
 This funciton updates the kernel coefficients.
void UpdateKernelBreaks (NekDouble h)
 This funciton updates the kernel breaks.
Array< TwoD, NekDoubleGetKernelBspline ()
 This funciton returns a 2D array representing the bspline of the appropriate order.
Array< OneD, NekDoubleGetKernelCoeffs ()
 This funciton returns a 1D array representing the kernel coefficients.
Array< OneD, NekDoubleGetKernelBreaks ()
 This funciton returns a 1D array representing the kernel breaks.
void UpdateKernelOrder (int order)
 This funciton sets the k_order variable.
void UpdateKernelNumOfCoeffs ()
 This funciton sets the k_ncoeffs variable.
void UpdateKernelWidth ()
 This funciton sets the kernel width size.
int GetKernelOrder ()
 This funciton returns the order of the kernel.
int GetKernelNumeOfCoeffs ()
 This funciton returns the number of kernel coefficients.
int GetKernelWidth ()
 This funciton returns the size of the kernel width.
void MoveKernelCenter (NekDouble x_value, Array< OneD, NekDouble > &outarray)
 This funciton moves the center of the kernel to the.
void FindMeshUnderKernel (Array< OneD, NekDouble > &inarray, NekDouble h, Array< OneD, NekDouble > &outarray)
 This funciton calculates the mesh breaks under the kernel support.
void EvaluateKernel (Array< OneD, NekDouble > inarray, NekDouble h, Array< OneD, NekDouble > &outarray)
 This funciton evaluates the kernel at input values.
void EvaluateBspline (Array< OneD, NekDouble > inarray, NekDouble h, NekDouble offset, Array< OneD, NekDouble > &outarray)
 This function evaluates the bspline at input values.
void Sort (Array< OneD, NekDouble > &inarray1, Array< OneD, NekDouble > &inarray2, Array< OneD, NekDouble > &outarray)
 This funciton performs the ordered merge of.

Protected Member Functions

NekDouble EvaluateBsplinePoly (NekDouble x_value, int interval)
 This funciton evaluates the piecewise bspline polynomial.

Protected Attributes

int k_order
int k_ncoeffs
int k_width
NekDouble k_center
Array< TwoD, NekDoubleb_spline
Array< OneD, NekDoublek_coeffs
Array< OneD, NekDoublek_breaks

Detailed Description

Definition at line 47 of file kernel.h.

Constructor & Destructor Documentation

Nektar::LibUtilities::Kernel::Kernel ( )

The default constructor.

Nektar::LibUtilities::Kernel::Kernel ( int  order)

Member Function Documentation

void Nektar::LibUtilities::Kernel::EvaluateBspline ( Array< OneD, NekDouble inarray,
NekDouble  h,
NekDouble  offset,
Array< OneD, NekDouble > &  outarray 
)

This function evaluates the bspline at input values.

Parameters
inarrayinput values.
hthe mesh spacing.
offset
outarraycontains the bspline values.

Definition at line 307 of file kernel.cpp.

References EvaluateBsplinePoly(), and k_order.

Referenced by EvaluateKernel().

{
int i;
NekDouble min_value = -k_order/2.0;
NekDouble max_value = k_order/2.0;
int nvalues = inarray.num_elements();
// Make a copy for further modifications
Array<OneD,NekDouble> inarray_cp(nvalues);
for(i = 0; i < nvalues; i++)
{
inarray_cp[i] = inarray[i] - offset;
inarray_cp[i] = inarray_cp[i]/h;
int interval = (int)floor(inarray_cp[i] - min_value); // determines to which interval of the bspline the value belongs
if(inarray_cp[i] >= min_value && inarray_cp[i] <= max_value)
{
if(interval >= k_order)
{
interval -= 1;
}
NekDouble shift = min_value + interval;
inarray_cp[i] -= shift;
outarray[i] = EvaluateBsplinePoly(inarray_cp[i],interval);
}else
{
outarray[i] = 0.0;
}
}
}
NekDouble Nektar::LibUtilities::Kernel::EvaluateBsplinePoly ( NekDouble  x_value,
int  interval 
)
protected

This funciton evaluates the piecewise bspline polynomial.

Parameters
interval
intervalat point
x_value.

Definition at line 342 of file kernel.cpp.

References b_spline, and k_order.

Referenced by EvaluateBspline().

{
int i;
int deg = k_order - 1;
NekDouble poly_value = b_spline[interval][0];
for(i = 0; i < deg; i++)
{
poly_value = poly_value*x_value + b_spline[interval][i+1];
}
return poly_value;
}
void Nektar::LibUtilities::Kernel::EvaluateKernel ( Array< OneD, NekDouble inarray,
NekDouble  h,
Array< OneD, NekDouble > &  outarray 
)

This funciton evaluates the kernel at input values.

Parameters
inarray.
his the mesh spacing.
outarraycontains the kernel values

Definition at line 279 of file kernel.cpp.

References EvaluateBspline(), k_center, k_coeffs, and k_order.

{
int gamma,i;
int degree = k_order - 1;
int nvalues = inarray.num_elements();
Array<OneD,NekDouble> bs_values(nvalues);
for(i = 0; i < nvalues; i++ )
{
outarray[i] = 0.0;
}
for(gamma = -degree; gamma <= degree; gamma++)
{
int cIndex = gamma+degree;
// Evaluate the bSpline values
EvaluateBspline(inarray,h,k_center+(gamma*h),bs_values);
for(i = 0; i < nvalues; i++ )
{
outarray[i] += k_coeffs[cIndex]*bs_values[i];
}
}
}
void Nektar::LibUtilities::Kernel::FindMeshUnderKernel ( Array< OneD, NekDouble > &  inarray,
NekDouble  h,
Array< OneD, NekDouble > &  outarray 
)

This funciton calculates the mesh breaks under the kernel support.

Parameters
inarraycontains the local kernel breaks
his the mesh spacing
outarraycontains the coordinate of the mesh breaks under the kernel support

Definition at line 261 of file kernel.cpp.

References k_width.

{
int j;
NekDouble first = ceil(inarray[0]/h)*h;
int index = k_width;
NekDouble last = floor(inarray[index]/h)*h;
int count = (int)((last-first)/h)+1; // number of mesh breaks under the kernel support
Array<OneD,NekDouble> mesh_breaks(count);
mesh_breaks[0] = first;
for(j = 1; j < count; j++)
{
mesh_breaks[j] = mesh_breaks[j-1]+h;
}
outarray = mesh_breaks;
}
Array<OneD,NekDouble> Nektar::LibUtilities::Kernel::GetKernelBreaks ( )
inline

This funciton returns a 1D array representing the kernel breaks.

Definition at line 98 of file kernel.h.

References k_breaks.

{
return k_breaks;
}
Array<TwoD,NekDouble> Nektar::LibUtilities::Kernel::GetKernelBspline ( )
inline

This funciton returns a 2D array representing the bspline of the appropriate order.

Definition at line 82 of file kernel.h.

References b_spline.

{
return b_spline;
}
Array<OneD,NekDouble> Nektar::LibUtilities::Kernel::GetKernelCoeffs ( )
inline

This funciton returns a 1D array representing the kernel coefficients.

Definition at line 90 of file kernel.h.

References k_coeffs.

{
return k_coeffs;
}
int Nektar::LibUtilities::Kernel::GetKernelNumeOfCoeffs ( )
inline

This funciton returns the number of kernel coefficients.

Definition at line 138 of file kernel.h.

References k_ncoeffs.

{
return k_ncoeffs;
}
int Nektar::LibUtilities::Kernel::GetKernelOrder ( )
inline

This funciton returns the order of the kernel.

Definition at line 130 of file kernel.h.

References k_order.

{
return k_order;
}
int Nektar::LibUtilities::Kernel::GetKernelWidth ( )
inline

This funciton returns the size of the kernel width.

Definition at line 146 of file kernel.h.

References k_width.

{
return k_width;
}
void Nektar::LibUtilities::Kernel::MoveKernelCenter ( NekDouble  x_value,
Array< OneD, NekDouble > &  outarray 
)

This funciton moves the center of the kernel to the.

Parameters
x_value.
outarrayis used to store the result

Definition at line 249 of file kernel.cpp.

References k_breaks, k_center, and k_width.

{
int i;
for(i = 0; i < k_width+1; i++)
{
outarray[i] = k_breaks[i] + x_value;
}
// Update the center of the kernel
k_center = x_value;
}
void Nektar::LibUtilities::Kernel::Sort ( Array< OneD, NekDouble > &  inarray1,
Array< OneD, NekDouble > &  inarray2,
Array< OneD, NekDouble > &  outarray 
)

This funciton performs the ordered merge of.

Parameters
inarray1and
inarray2and puts the result in
outarray

Definition at line 357 of file kernel.cpp.

{
int j;
int kIndex = 0; // Keeps track of the kernel breaks
int mIndex = 0; // Keeps track of the mesh breaks
for(j = 0; j < outarray.num_elements(); j++)
{
if(mIndex >= inarray2.num_elements())
{
outarray[j] = inarray1[kIndex];
kIndex++;
}else if(kIndex >= inarray1.num_elements())
{
outarray[j] = inarray2[mIndex];
mIndex++;
}else if(inarray1[kIndex] < inarray2[mIndex])
{
outarray[j] = inarray1[kIndex];
kIndex++;
}else
{
outarray[j] = inarray2[mIndex];
mIndex++;
}
}
}
void Nektar::LibUtilities::Kernel::UpdateKernelBreaks ( NekDouble  h)

This funciton updates the kernel breaks.

Parameters
hrepresents the mesh spacing

Definition at line 237 of file kernel.cpp.

References k_breaks, and k_width.

{
int i;
Array<OneD,NekDouble> temp(k_width+1);
temp[0] = -(k_width/2.0)*h; // it needs to get scaled by h
for(i = 1; i < k_width+1; i++)
{
temp[i] = temp[i-1]+h;
}
k_breaks = temp;
}
void Nektar::LibUtilities::Kernel::UpdateKernelBspline ( )

The default destructor.

This funciton updates the bspline to the appropriate order.

Definition at line 52 of file kernel.cpp.

References ASSERTL0, b_spline, and k_order.

Referenced by Kernel().

{
Array<TwoD,NekDouble> out_final(k_order,k_order);
int i,j;
if(k_order == 1.0)
{
b_spline[0][0] = 1.0;
}else if(k_order == 2)
{
NekDouble out[2][2] = {{1.0,0.0},
{-1.0,1.0}};
for(i = 0; i < k_order; i++)
{
for(j = 0; j < k_order; j++)
{
out_final[i][j] = out[i][j];
}
}
}else if(k_order == 3)
{
NekDouble out[3][3] = {{0.5, 0.0, 0.0},
{-1.0, 1.0, 0.5},
{0.5, -1.0, 0.5}};
for(i = 0; i < k_order; i++)
{
for(j = 0; j < k_order; j++)
{
out_final[i][j] = out[i][j];
}
}
}else if(k_order == 4)
{
NekDouble out[4][4] = {{1.0/6.0, 0, 0, 0},
{-0.5, 0.5, 0.5, 1.0/6.0},
{0.5, -1.0, 0, 2.0/3},
{-1.0/6.0, 0.5, -0.5, 1.0/6.0}};
for(i = 0; i < k_order; i++)
{
for(j = 0; j < k_order; j++)
{
out_final[i][j] = out[i][j];
}
}
}else if(k_order == 5)
{
NekDouble out[5][5] = {{1.0 / 24.0, 0, 0, 0, 0},
{-1.0/6, 1.0/6, 0.25, 1.0/6, 1.0/24},
{0.25, -0.5, -0.25, 0.5, 11.0/24},
{-1.0/6, 0.5, -0.25, -0.5, 11.0/24},
{1.0/24, -1.0/6.0, 0.25, -1.0/6, 1.0/24}};
for(i = 0; i < k_order; i++)
{
for(j = 0; j < k_order; j++)
{
out_final[i][j] = out[i][j];
}
}
}else if(k_order == 6)
{
NekDouble out[6][6] = {{1.0/1.020, 0, 0, 0, 0, 0},
{-1.0/24, 1.0/24, 1.0/12, 1.0/12, 1.0/24, 1.0/120},
{1.0/12, -1.0/6, -1.0/6, 1.0/6, 5.0/12, 13.0/60},
{-1.0/12, 0.25, 0, -1.0/2, 0, 11.0/20},
{1.0/24, -1.0/6, 1.0/6, 1.0/6, -5.0/12, 13.0/60},
{-1.0/120, 1.0/24, -1.0/12, 1.0/12, -1.0/24, 1.0/120}};
for(i = 0; i < k_order; i++)
{
for(j = 0; j < k_order; j++)
{
out_final[i][j] = out[i][j];
}
}
}else if(k_order == 7)
{
NekDouble out[7][7] = {{1.0/720, 0, 0, 0, 0, 0, 0},
{-1.0/120, 1.0/120, 1.0/48, 1.0/36, 1.0/48, 1.0/120, 1.0/720},
{1.0/48, -1.0/24, -1.0/16, 1.0/36, 3.0/16, 5.0/24, 19.0/240},
{-1.0/36, 1.0/1.02, 1.0/24, -2.0/9, -5.0/24, 1.0/3, 151.0/360},
{1.0/48, -1.0/12, 1.0/24, 2.0/9, -5.0/24, -1.0/3, 151.0/360},
{-1.0/120, 1.0/24, -1.0/16, -1.0/36, 3.0/16, -5.0/24, 19.0/240},
{1.0/720, -1.0/120, 1.0/48, -1.0/36, 1.0/48, -1.0/120, 1.0/720}};
for(i = 0; i < k_order; i++)
{
for(j = 0; j < k_order; j++)
{
out_final[i][j] = out[i][j];
}
}
}else if(k_order == 8)
{
NekDouble out[8][8] = {{1.0/5040, 0, 0, 0, 0, 0, 0, 0},
{-1.0/720, 1.0/720, 1.0/240, 1.0/144, 1.0/144, 1.0/240, 1.0/720, 1.0/5040 },
{1.0/240, -1.0/120, -1.0/60, 0, 1.0/18, 1.0/10, 7.0/90, 1.0/42},
{-1.0/144, 1.0/48, 1.0/48, -1.0/16, -19.0/144, 1.0/16, 49.0/144, 397.0/1680},
{1.0/144, -1.0/36, 0, 1.0/9, 0, -1.0/3, 0, 151.0/315},
{-1.0/240, 1.0/48, -1.0/48, -1.0/16, 19.0/144, 1.0/16, -49.0/144, 397.0/1680},
{ 1.0/720, -1.0/120, 1.0/60, 0, -1.0/18, 1.0/10, -7.0/90, 1.0/42},
{ -1.0/5040, 1.0/720, -1.0/240, 1.0/144, -1.0/144, 1.0/240, -1.0/720, 1.0/5040}};
for(i = 0; i < k_order; i++)
{
for(j = 0; j < k_order; j++)
{
out_final[i][j] = out[i][j];
}
}
}
b_spline = out_final;
ASSERTL0(k_order <= 8, "Order is not supported");
}
void Nektar::LibUtilities::Kernel::UpdateKernelCoeffs ( )

This funciton updates the kernel coefficients.

Definition at line 176 of file kernel.cpp.

References ASSERTL0, k_coeffs, k_ncoeffs, and k_order.

Referenced by Kernel().

{
int i;
Array<OneD,NekDouble> out_final(k_ncoeffs);
if (k_order == 2)
{
NekDouble out[3] = {-1.0/12, 7.0/6, -1.0/12};
for(i = 0; i < k_ncoeffs; i++)
{
out_final[i] = out[i];
}
}else if (k_order == 3)
{
NekDouble out[5] = {37.0/1920, -97.0/480, 437.0/320, -97.0/480, 37.0/1920};
for(i = 0; i < k_ncoeffs; i++)
{
out_final[i] = out[i];
}
}else if (k_order == 4)
{
NekDouble out[7] = {-41.0/7560, 311.0/5040, -919.0/2520, 12223.0/7560, -919.0/2520, 311.0/5040, -41.0/7560};
for(i = 0; i < k_ncoeffs; i++)
{
out_final[i] = out[i];
}
}else if (k_order == 5)
{
NekDouble out[9] = {153617.0/92897280, -35411.0/1658880, 3153959.0/23224320, -6803459.0/11612160, 18017975.0/9289728, -6803459.0/11612160, 3153959.0/23224320, -35411.0/1658880, 153617.0/92897280};
for(i = 0; i < k_ncoeffs; i++)
{
out_final[i] = out[i];
}
}else if (k_order == 6)
{
NekDouble out[11] = {-4201.0/7983360, 30773.0/3991680, -20813.0/380160, 2825.0/11088, -1179649.0/1330560, 1569217.0/665280, -1179649.0/1330560, 2825.0/11088, -20813.0/380160, 30773.0/3991680, -4201.0/7983360};
for(i = 0; i < k_ncoeffs; i++)
{
out_final[i] = out[i];
}
}else if (k_order == 7)
{
NekDouble out[13] = {13154671847.0/76517631590400.0, -18073154507.0/6376469299200.0, 287360344573.0/12752938598400.0, -2217732343517.0/19129407897600.0, 1240941746699.0/2833986355200.0, -275386671493.0/212548976640.0, 2648644782397.0/910924185600.0, -275386671493.0/212548976640.0, 1240941746699.0/2833986355200.0, -2217732343517.0/19129407897600.0, 287360344573.0/12752938598400.0, -18073154507.0/6376469299200.0, 13154671847.0/76517631590400.0};
for(i = 0; i < k_ncoeffs; i++)
{
out_final[i] = out[i];
}
}else if (k_order == 8)
{
NekDouble out[15] = {-800993.0/14010796800.0, 73587167.0/70053984000.0, -651305719.0/70053984000.0, 3714581677.0/70053984000.0, -3085236289.0/14010796800.0, 1426328231.0/2001542400.0, -43268401973.0/23351328000.0, 42401344373.0/11675664000.0, -43268401973.0/23351328000.0, 1426328231.0/2001542400.0, -3085236289.0/14010796800.0, 3714581677.0/70053984000.0, -651305719.0/70053984000.0, 73587167.0/70053984000.0, -800993.0/14010796800.0};
for(i = 0; i < k_ncoeffs; i++)
{
out_final[i] = out[i];
}
}
k_coeffs = out_final;
ASSERTL0(k_order <= 8, "Order is not supported");
}
void Nektar::LibUtilities::Kernel::UpdateKernelNumOfCoeffs ( )
inline

This funciton sets the k_ncoeffs variable.

Definition at line 114 of file kernel.h.

References k_ncoeffs, and k_order.

Referenced by Kernel().

{
k_ncoeffs = 2*(k_order-1)+1;
}
void Nektar::LibUtilities::Kernel::UpdateKernelOrder ( int  order)
inline

This funciton sets the k_order variable.

Definition at line 106 of file kernel.h.

References k_order.

Referenced by Kernel().

{
k_order = order;
}
void Nektar::LibUtilities::Kernel::UpdateKernelWidth ( )
inline

This funciton sets the kernel width size.

Definition at line 122 of file kernel.h.

References k_order, and k_width.

Referenced by Kernel().

{
k_width = 3*(k_order-1)+1;
}

Member Data Documentation

Array<TwoD,NekDouble> Nektar::LibUtilities::Kernel::b_spline
protected

2D array representing the bspline

Definition at line 201 of file kernel.h.

Referenced by EvaluateBsplinePoly(), GetKernelBspline(), and UpdateKernelBspline().

Array<OneD,NekDouble> Nektar::LibUtilities::Kernel::k_breaks
protected

1D array representing the kernel breaks

Definition at line 203 of file kernel.h.

Referenced by GetKernelBreaks(), MoveKernelCenter(), and UpdateKernelBreaks().

NekDouble Nektar::LibUtilities::Kernel::k_center
protected

holds the center of the kernel

Definition at line 200 of file kernel.h.

Referenced by EvaluateKernel(), Kernel(), and MoveKernelCenter().

Array<OneD,NekDouble> Nektar::LibUtilities::Kernel::k_coeffs
protected

1D array representing the kernel coefficients

Definition at line 202 of file kernel.h.

Referenced by EvaluateKernel(), GetKernelCoeffs(), and UpdateKernelCoeffs().

int Nektar::LibUtilities::Kernel::k_ncoeffs
protected

Represents the number of kernel coefficients

Definition at line 198 of file kernel.h.

Referenced by GetKernelNumeOfCoeffs(), UpdateKernelCoeffs(), and UpdateKernelNumOfCoeffs().

int Nektar::LibUtilities::Kernel::k_order
protected

bsplines are obtained by convolving the characteristic fucntion with itself (k_order - 1) times

Definition at line 196 of file kernel.h.

Referenced by EvaluateBspline(), EvaluateBsplinePoly(), EvaluateKernel(), GetKernelOrder(), UpdateKernelBspline(), UpdateKernelCoeffs(), UpdateKernelNumOfCoeffs(), UpdateKernelOrder(), and UpdateKernelWidth().

int Nektar::LibUtilities::Kernel::k_width
protected

Represents the width of the kernel

Definition at line 199 of file kernel.h.

Referenced by FindMeshUnderKernel(), GetKernelWidth(), MoveKernelCenter(), UpdateKernelBreaks(), and UpdateKernelWidth().