Skip to content

Commit

Permalink
Add missing basis files
Browse files Browse the repository at this point in the history
  • Loading branch information
valentjn committed Apr 1, 2018
1 parent 80f4e33 commit e53cc0d
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
13 changes: 13 additions & 0 deletions py/helper/basis/hierarchical_basis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/python3

import abc

class HierarchicalBasis(abc.ABC):
def __init__(self, nu=0):
self.nu = nu

@abc.abstractmethod
def evaluate(self, l, i, xx): pass

@abc.abstractmethod
def getSupport(self, l, i): pass
20 changes: 20 additions & 0 deletions py/helper/basis/hierarchical_basis_from_parent_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/python3

from .hierarchical_basis import HierarchicalBasis

class HierarchicalBasisFromParentFunction(HierarchicalBasis):
def __init__(self, parentFunction):
super().__init__(nu=parentFunction.nu)
self.parentFunction = parentFunction

def evaluate(self, l, i, xx):
tt = 2**l * xx - i
yy = self.parentFunction.evaluate(tt)
yy *= 2**(l*self.nu)
return yy

def getSupport(self, l, i):
lb, ub = self.parentFunction.getSupport()
lb = max((lb + i) / 2**l, 0)
ub = min((ub + i) / 2**l, 1)
return lb, ub
30 changes: 30 additions & 0 deletions py/helper/basis/hierarchical_bspline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/python3

import helper.grid

from .centralized_cardinal_bspline import CentralizedCardinalBSpline
from .hierarchical_basis_from_parent_function import HierarchicalBasisFromParentFunction

def restrictKnots(p, hInv, i, I):
offset = 0

if i < 0:
I = [I[0] - j * (I[1] - I[0]) for j in range(-i, 0, -1)] + I
offset = -i
elif i > hInv:
I = I + [I[-1] + j * (I[-1] - I[-2]) for j in range(1, i-hInv+1)]

I = I[i+offset:i+offset+p+2]
return I

class HierarchicalBSpline(HierarchicalBasisFromParentFunction):
def __init__(self, p, nu=0):
super().__init__(CentralizedCardinalBSpline(p, nu=nu))
self.p = p

def getKnots(self, l, i=None):
hInv = 2**l
I = list(range(-(self.p+1)//2, hInv + (self.p+1)//2 + 1))
if i is not None: I = restrictKnots(self.p, hInv, i, I)
xi = helper.grid.getCoordinates(l, I)
return xi
28 changes: 28 additions & 0 deletions py/helper/basis/non_uniform_bspline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/python3

import numpy as np
import scipy.interpolate

from .parent_function import ParentFunction

class NonUniformBSpline(ParentFunction):
def __init__(self, p, xi, k=None, nu=0):
if k is None:
super().__init__(nu)
fakeXi = np.hstack([p * [xi[0]], xi, p * [xi[-1]]])
fakeC = np.zeros((2*p+1,))
fakeC[p] = 1
self.bSpline = scipy.interpolate.BSpline(fakeXi, fakeC, p)
self.support = [xi[0], xi[-1]]
else:
self.__init__(p, xi[k:k+p+2], nu=nu)

def evaluate(self, xx):
xx = np.array(xx).flatten().astype(float)
K = np.logical_and(xx >= self.support[0], xx < self.support[1])
yy = np.zeros_like(xx)
yy[K] = self.bSpline(xx[K], nu=self.nu)
return yy

def getSupport(self):
return self.support
13 changes: 13 additions & 0 deletions py/helper/basis/parent_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/python3

import abc

class ParentFunction(abc.ABC):
def __init__(self, nu=0):
self.nu = nu

@abc.abstractmethod
def evaluate(self, xx): pass

@abc.abstractmethod
def getSupport(self): pass

0 comments on commit e53cc0d

Please sign in to comment.