correlated_fields.py 2.99 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1 2 3 4 5 6 7 8 9 10 11 12 13
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
14
# Copyright(C) 2013-2019 Max-Planck-Society
Martin Reinecke's avatar
Martin Reinecke committed
15
#
16
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik.
Philipp Arras's avatar
Philipp Arras committed
17 18

from ..domain_tuple import DomainTuple
19
from ..operators.contraction_operator import ContractionOperator
Philipp Arras's avatar
Philipp Arras committed
20
from ..operators.distributors import PowerDistributor
Martin Reinecke's avatar
Martin Reinecke committed
21
from ..operators.harmonic_operators import HarmonicTransformOperator
Martin Reinecke's avatar
Martin Reinecke committed
22
from ..operators.simple_linear_operators import ducktape
23
from ..operators.scaling_operator import ScalingOperator
Martin Reinecke's avatar
Martin Reinecke committed
24

Martin Reinecke's avatar
Martin Reinecke committed
25

Philipp Arras's avatar
Philipp Arras committed
26
def CorrelatedField(s_space, amplitude_operator, name='xi'):
27
    '''
Martin Reinecke's avatar
Martin Reinecke committed
28
    Function for construction of correlated fields
29 30 31

    Parameters
    ----------
32 33
    s_space : Domain
        Field domain
Philipp Arras's avatar
Philipp Arras committed
34 35
    amplitude_operator: Operator
        operator for correlation structure
36 37
    name : string
        MultiField component name
38
    '''
Martin Reinecke's avatar
Martin Reinecke committed
39 40
    h_space = s_space.get_default_codomain()
    ht = HarmonicTransformOperator(h_space, s_space)
Philipp Arras's avatar
Philipp Arras committed
41
    p_space = amplitude_operator.target[0]
Martin Reinecke's avatar
Martin Reinecke committed
42
    power_distributor = PowerDistributor(h_space, p_space)
Philipp Arras's avatar
Philipp Arras committed
43
    A = power_distributor(amplitude_operator)
44
    vol = h_space.scalar_dvol
Philipp Arras's avatar
Cleanup  
Philipp Arras committed
45
    vol = ScalingOperator(vol**(-0.5), h_space)
Martin Reinecke's avatar
Martin Reinecke committed
46
    return ht(vol(A)*ducktape(h_space, None, name))
47 48


Philipp Arras's avatar
Philipp Arras committed
49 50 51 52 53
def MfCorrelatedField(s_space_spatial,
                      s_space_energy,
                      amplitude_operator_spatial,
                      amplitude_operator_energy,
                      name="xi"):
54 55 56 57 58 59
    '''
    Method for construction of correlated multi-frequency fields
    '''
    h_space_spatial = s_space_spatial.get_default_codomain()
    h_space_energy = s_space_energy.get_default_codomain()
    h_space = DomainTuple.make((h_space_spatial, h_space_energy))
60
    ht1 = HarmonicTransformOperator(h_space, target=s_space_spatial, space=0)
61 62 63
    ht2 = HarmonicTransformOperator(ht1.target, space=1)
    ht = ht2(ht1)

Philipp Arras's avatar
Philipp Arras committed
64 65
    p_space_spatial = amplitude_operator_spatial.target[0]
    p_space_energy = amplitude_operator_energy.target[0]
66 67 68 69 70

    pd_spatial = PowerDistributor(h_space, p_space_spatial, 0)
    pd_energy = PowerDistributor(pd_spatial.domain, p_space_energy, 1)
    pd = pd_spatial(pd_energy)

71 72
    dom_distr_spatial = ContractionOperator(pd.domain, 1).adjoint
    dom_distr_energy = ContractionOperator(pd.domain, 0).adjoint
73

Philipp Arras's avatar
Philipp Arras committed
74 75
    a_spatial = dom_distr_spatial(amplitude_operator_spatial)
    a_energy = dom_distr_energy(amplitude_operator_energy)
76 77
    a = a_spatial*a_energy
    A = pd(a)
Martin Reinecke's avatar
Martin Reinecke committed
78
    return ht(A*ducktape(h_space, None, name))