-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
20
py/helper/basis/hierarchical_basis_from_parent_function.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |