Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/WaveBlocksND/DirectHomogeneousQuadrature.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,18 @@
from scipy.linalg import sqrtm, inv #, svd, diagsvd

from DirectQuadrature import DirectQuadrature
from InnerProductCompatibility import InnerProductCompatibility

__all__ = ["DirectHomogeneousQuadrature"]


class DirectHomogeneousQuadrature(DirectQuadrature):
class DirectHomogeneousQuadrature(DirectQuadrature, InnerProductCompatibility):
r"""
"""

def __init__(self, QR=None):
# Pure convenience to allow setting of quadrature rule in constructor
if QR is not None:
self.set_qr(QR)
else:
self._QR = None
self.set_qr(QR)


def __str__(self):
Expand All @@ -45,6 +43,10 @@ def get_description(self):
return d


def get_kind(self):
return ("homogeneous",)


def initialize_packet(self, packet):
r"""Provide the wavepacket part of the inner product to evaluate.
Since the quadrature is homogeneous the same wavepacket is used
Expand Down
12 changes: 7 additions & 5 deletions src/WaveBlocksND/DirectInhomogeneousQuadrature.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,18 @@
from scipy.linalg import sqrtm, inv, det

from DirectQuadrature import DirectQuadrature
from InnerProductCompatibility import InnerProductCompatibility

__all__ = ["DirectInhomogeneousQuadrature"]


class DirectInhomogeneousQuadrature(DirectQuadrature):
class DirectInhomogeneousQuadrature(DirectQuadrature, InnerProductCompatibility):
r"""
"""

def __init__(self, QR=None):
# Pure convenience to allow setting of quadrature rule in constructor
if QR is not None:
self.set_qr(QR)
else:
self._QR = None
self.set_qr(QR)


def __str__(self):
Expand All @@ -46,6 +44,10 @@ def get_description(self):
return d


def get_kind(self):
return ("homogeneous", "inhomogeneous",)


def initialize_packet(self, pacbra, packet=None):
r"""Provide the wavepacket parts of the inner product to evaluate.
Since the quadrature is inhomogeneous different wavepackets can be
Expand Down
11 changes: 10 additions & 1 deletion src/WaveBlocksND/HomogeneousInnerProduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
from numpy import zeros, complexfloating, sum, cumsum

from InnerProduct import InnerProduct
from InnerProductCompatibility import InnerProductCompatibility

__all__ = ["HomogeneousInnerProduct"]


class HomogeneousInnerProduct(InnerProduct):
class HomogeneousInnerProduct(InnerProduct, InnerProductCompatibility):
r"""
"""

Expand Down Expand Up @@ -48,6 +49,14 @@ def get_description(self):
return d


def get_kind(self):
return ("homogeneous",)


def require_kind(self):
return ("homogeneous",)


def quadrature(self, packet, operator=None, summed=False, component=None, diag_component=None, diagonal=False, eval_at_once=False):
r"""Delegates the evaluation of :math:`\langle\Psi|f|\Psi\rangle` for a general
function :math:`f(x)` with :math:`x \in \mathbb{R}^D`.
Expand Down
11 changes: 10 additions & 1 deletion src/WaveBlocksND/HomogeneousInnerProductLCWP.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
from numpy import zeros, complexfloating, conjugate, transpose, dot, cumsum, sum, reshape, array, repeat

from InnerProduct import InnerProduct
from InnerProductCompatibility import InnerProductCompatibility

__all__ = ["HomogeneousInnerProductLCWP"]


class HomogeneousInnerProductLCWP(InnerProduct):
class HomogeneousInnerProductLCWP(InnerProduct, InnerProductCompatibility):

def __init__(self, delegate=None, oracle=None):
r"""
Expand Down Expand Up @@ -55,6 +56,14 @@ def get_description(self):
return d


def get_kind(self):
return ("homogeneous",)


def require_kind(self):
return ("homogeneous",)


def get_oracle(self):
r"""Return the sparsity oracle in use or ``None``.
"""
Expand Down
11 changes: 10 additions & 1 deletion src/WaveBlocksND/InhomogeneousInnerProduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
from numpy import zeros, complexfloating, sum, cumsum

from InnerProduct import InnerProduct
from InnerProductCompatibility import InnerProductCompatibility

__all__ = ["InhomogeneousInnerProduct"]


class InhomogeneousInnerProduct(InnerProduct):
class InhomogeneousInnerProduct(InnerProduct, InnerProductCompatibility):
r"""
"""

Expand Down Expand Up @@ -48,6 +49,14 @@ def get_description(self):
return d


def get_kind(self):
return ("homogeneous", "inhomogeneous",)


def require_kind(self):
return ("inhomogeneous",)


def quadrature(self, pacbra, packet=None, operator=None, summed=False, component=None, diag_component=None, diagonal=False, eval_at_once=False):
r"""Delegates the evaluation of :math:`\langle\Psi|f|\Psi^\prime\rangle` for a general
function :math:`f(x)` with :math:`x \in \mathbb{R}^D`.
Expand Down
11 changes: 10 additions & 1 deletion src/WaveBlocksND/InhomogeneousInnerProductLCWP.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
from numpy import zeros, complexfloating, conjugate, transpose, dot, sum, cumsum, array, repeat, reshape

from InnerProduct import InnerProduct
from InnerProductCompatibility import InnerProductCompatibility

__all__ = ["InhomogeneousInnerProductLCWP"]


class InhomogeneousInnerProductLCWP(InnerProduct):
class InhomogeneousInnerProductLCWP(InnerProduct, InnerProductCompatibility):

def __init__(self, delegate=None, oracle=None):
r"""
Expand Down Expand Up @@ -55,6 +56,14 @@ def get_description(self):
return d


def get_kind(self):
return ("homogeneous", "inhomogeneous",)


def require_kind(self):
return ("inhomogeneous",)


def get_oracle(self):
r"""Return the sparsity oracle in use or ``None``.
"""
Expand Down
10 changes: 8 additions & 2 deletions src/WaveBlocksND/InnerProduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
@license: Modified BSD License
"""

from InnerProductCompatibility import InnerProductCompatibility

__all__ = ["InnerProduct", "InnerProductException"]


class InnerProduct(object):
class InnerProduct(InnerProductCompatibility):
r"""This class is an abstract interface to inner products in general.
"""

Expand Down Expand Up @@ -45,7 +47,11 @@ def set_delegate(self, delegate):
:param delegate: The new :py:class:`Quadrature` instance.
"""
# TODO: Allow a list of quads, one quad for each component of Psi
self._delegate = delegate
if delegate is not None:
if self.compatible(self, delegate):
self._delegate = delegate
else:
self._delegate = delegate


def get_delegate(self):
Expand Down
32 changes: 32 additions & 0 deletions src/WaveBlocksND/InnerProductCompatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""The WaveBlocks Project

This class abstracts compatibility conditions on nested inner products.

@author: R. Bourquin
@copyright: Copyright (C) 2013 R. Bourquin
@license: Modified BSD License
"""

__all__ = ["InnerProductCompatibility"]


class InnerProductCompatibility(object):
r"""This class abstracts compatibility conditions on nested inner products.
"""

def get_kind(self):
return None

def require_kind(self):
return None

def compatible(self, ipouter, ipinner):
r"""
"""
inner = set(ipinner.get_kind())
outer = set(ipouter.require_kind())

if not len(outer.intersection(inner)) == 0:
return True
else:
raise ValueError("Can not nest inner product with kind "+str(inner)+" into inner product which requires "+str(outer))
12 changes: 7 additions & 5 deletions src/WaveBlocksND/NSDInhomogeneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
from scipy.linalg import inv, schur, det, sqrtm

from Quadrature import Quadrature
from InnerProductCompatibility import InnerProductCompatibility

__all__ = ["NSDInhomogeneous"]


class NSDInhomogeneous(Quadrature):
class NSDInhomogeneous(Quadrature, InnerProductCompatibility):
r"""
"""

Expand All @@ -30,10 +31,7 @@ def __init__(self, QR=None):
:param QR: Typically one uses an instance of :py:class:`GaussHermiteOriginalQR`.
"""
# Pure convenience to allow setting of quadrature rule in constructor
if QR is not None:
self.set_qr(QR)
else:
self._QR = None
self.set_qr(QR)


def __str__(self):
Expand All @@ -52,6 +50,10 @@ def get_description(self):
return d


def get_kind(self):
return ("homogeneous", "inhomogeneous")


def initialize_packet(self, pacbra, packet=None):
r"""Provide the wavepacket parts of the inner product to evaluate.
Since the quadrature is inhomogeneous, different wavepackets can be
Expand Down
7 changes: 6 additions & 1 deletion src/WaveBlocksND/SymbolicIntegral.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@

from InnerProduct import InnerProductException
from Quadrature import Quadrature
from InnerProductCompatibility import InnerProductCompatibility

__all__ = ["SymbolicIntegral"]


class SymbolicIntegral(Quadrature):
class SymbolicIntegral(Quadrature, InnerProductCompatibility):
r"""
"""

Expand Down Expand Up @@ -53,6 +54,10 @@ def get_description(self):
return d


def get_kind(self):
return ("homogeneous", "inhomogeneous")


def initialize_packet(self, pacbra, packet=None):
r"""Provide the wavepacket parts of the inner product to evaluate.
Since the formula is for the inhomogeneous case explicitly, different
Expand Down
2 changes: 2 additions & 0 deletions src/WaveBlocksND/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
from HomogeneousInnerProductLCWP import HomogeneousInnerProductLCWP
from InhomogeneousInnerProductLCWP import InhomogeneousInnerProductLCWP

#from InnerProductCompatibility import InnerProductCompatibility

from Quadrature import Quadrature
from DirectQuadrature import DirectQuadrature
from DirectHomogeneousQuadrature import DirectHomogeneousQuadrature
Expand Down