There is a maintenance of MPCDF Gitlab on Thursday, April 22st 2020, 9:00 am CEST - Expect some service interruptions during this time

correlated_fields.py 3.56 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 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/>.
#
# Copyright(C) 2013-2018 Max-Planck-Society
#
# NIFTy is being developed at the Max-Planck-Institut fuer Astrophysik
# and financially supported by the Studienstiftung des deutschen Volkes.

19
from __future__ import absolute_import, division, print_function
Philipp Arras's avatar
Philipp Arras committed
20

21
from ..compat import *
Philipp Arras's avatar
Philipp Arras committed
22
from ..domain_tuple import DomainTuple
Martin Reinecke's avatar
Martin Reinecke committed
23 24 25
from ..field import Field
from ..models.local_nonlinearity import PointwiseExponential
from ..models.variable import Variable
Philipp Arras's avatar
Philipp Arras committed
26
from ..multi.multi_field import MultiField
Martin Reinecke's avatar
Martin Reinecke committed
27
from ..operators.domain_distributor import DomainDistributor
Philipp Arras's avatar
Philipp Arras committed
28 29 30
from ..operators.fft_operator import FFTOperator
from ..operators.harmonic_transform_operator import HarmonicTransformOperator
from ..operators.power_distributor import PowerDistributor
Martin Reinecke's avatar
Martin Reinecke committed
31

Martin Reinecke's avatar
Martin Reinecke committed
32

Jakob Knollmueller's avatar
Jakob Knollmueller committed
33
def make_correlated_field(s_space, amplitude_model):
34
    '''
Martin Reinecke's avatar
Martin Reinecke committed
35
    Method for construction of correlated fields
36 37 38

    Parameters
    ----------
Martin Reinecke's avatar
Martin Reinecke committed
39
    s_space : Field domain
40 41 42 43 44 45 46

    amplitude_model : model for correlation structure
    '''
    h_space = s_space.get_default_codomain()
    ht = FFTOperator(h_space, s_space)
    p_space = amplitude_model.value.domain[0]
    power_distributor = PowerDistributor(h_space, p_space)
Martin Reinecke's avatar
Martin Reinecke committed
47 48 49 50
    position = MultiField.from_dict({
        'xi': Field.from_random('normal', h_space),
        'tau': amplitude_model.position['tau'],
        'phi': amplitude_model.position['phi']})
51 52 53

    xi = Variable(position)['xi']
    A = power_distributor(amplitude_model)
Jakob Knollmueller's avatar
Jakob Knollmueller committed
54 55 56
    correlated_field_h = A * xi
    correlated_field = ht(correlated_field_h)
    internals = {'correlated_field_h': correlated_field_h,
57 58
                 'power_distributor': power_distributor,
                 'ht': ht}
Jakob Knollmueller's avatar
Jakob Knollmueller committed
59
    return correlated_field, internals
60 61


Martin Reinecke's avatar
Martin Reinecke committed
62
def make_mf_correlated_field(s_space_spatial, s_space_energy,
63 64
                             amplitude_model_spatial, amplitude_model_energy):
    '''
Martin Reinecke's avatar
Martin Reinecke committed
65
    Method for construction of correlated multi-frequency fields
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    '''
    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))
    ht1 = HarmonicTransformOperator(h_space, space=0)
    ht2 = HarmonicTransformOperator(ht1.target, space=1)
    ht = ht2*ht1

    p_space_spatial = amplitude_model_spatial.value.domain[0]
    p_space_energy = amplitude_model_energy.value.domain[0]

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

    dom_distr_0 = DomainDistributor(pd.domain, 0)
    dom_distr_1 = DomainDistributor(pd.domain, 1)
    a_spatial = dom_distr_1(amplitude_model_spatial)
    a_energy = dom_distr_0(amplitude_model_energy)
    a = a_spatial*a_energy
    A = pd(a)

Martin Reinecke's avatar
Martin Reinecke committed
88 89
    position = MultiField.from_dict(
        {'xi': Field.from_random('normal', h_space)})
90
    xi = Variable(position)['xi']
91 92 93
    correlated_field_h = A*xi
    correlated_field = ht(correlated_field_h)
    return PointwiseExponential(correlated_field)