field_adapter.py 796 Bytes
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1 2 3 4 5 6 7
from __future__ import absolute_import, division, print_function

from ..compat import *
from .linear_operator import LinearOperator
from ..multi.multi_domain import MultiDomain
from ..multi.multi_field import MultiField

Martin Reinecke's avatar
more  
Martin Reinecke committed
8

Martin Reinecke's avatar
Martin Reinecke committed
9
class FieldAdapter(LinearOperator):
Martin Reinecke's avatar
Martin Reinecke committed
10
    def __init__(self, dom, name_dom):
Martin Reinecke's avatar
Martin Reinecke committed
11 12 13 14
        self._domain = MultiDomain.make(dom)
        self._smalldom = MultiDomain.make({name_dom: self._domain[name_dom]})
        self._name = name_dom
        self._target = dom[name_dom]
Martin Reinecke's avatar
Martin Reinecke committed
15 16 17

    @property
    def capability(self):
Martin Reinecke's avatar
Martin Reinecke committed
18
        return self._all_ops
Martin Reinecke's avatar
Martin Reinecke committed
19 20 21 22

    def apply(self, x, mode):
        self._check_input(x, mode)

Martin Reinecke's avatar
Martin Reinecke committed
23
        if mode == self.TIMES:
Martin Reinecke's avatar
Martin Reinecke committed
24 25 26
            return x[self._name]
        tmp = MultiField(self._smalldom, (x,))
        return tmp.unite(MultiField.full(self._domain, 0.))