2019-10-10 21:44:57 +02:00
|
|
|
#pragma once
|
2020-04-04 21:35:16 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
operators.hh - This file is part of MUSIC2 -
|
|
|
|
a code to generate multi-scale initial conditions
|
|
|
|
for cosmological simulations
|
|
|
|
|
|
|
|
Copyright (C) 2019 Oliver Hahn
|
|
|
|
|
|
|
|
*/
|
2019-12-02 18:47:34 +01:00
|
|
|
#include <general.hh>
|
|
|
|
|
2019-10-10 21:44:57 +02:00
|
|
|
namespace op{
|
2019-10-24 17:12:43 +02:00
|
|
|
|
2020-04-04 21:35:16 +02:00
|
|
|
//!== list of primitive operators to work on fields ==!//
|
2019-12-02 18:47:34 +01:00
|
|
|
|
2019-10-27 19:49:54 +01:00
|
|
|
template< typename field>
|
|
|
|
inline auto assign_to( field& g ){return [&g](auto i, auto v){ g[i] = v; };}
|
2019-10-24 17:12:43 +02:00
|
|
|
|
2019-10-27 19:49:54 +01:00
|
|
|
template< typename field, typename val >
|
|
|
|
inline auto multiply_add_to( field& g, val x ){return [&g,x](auto i, auto v){ g[i] += v*x; };}
|
2019-10-24 17:12:43 +02:00
|
|
|
|
2019-10-27 19:49:54 +01:00
|
|
|
template< typename field>
|
|
|
|
inline auto add_to( field& g ){return [&g](auto i, auto v){ g[i] += v; };}
|
2019-10-24 17:12:43 +02:00
|
|
|
|
2019-10-27 19:49:54 +01:00
|
|
|
template< typename field>
|
|
|
|
inline auto subtract_from( field& g ){return [&g](auto i, auto v){ g[i] -= v; };}
|
|
|
|
|
2019-12-02 18:47:34 +01:00
|
|
|
//! vanilla standard gradient
|
|
|
|
class fourier_gradient{
|
|
|
|
private:
|
|
|
|
real_t boxlen_, k0_;
|
2019-12-04 14:26:42 +01:00
|
|
|
size_t n_, nhalf_;
|
2019-12-02 18:47:34 +01:00
|
|
|
public:
|
2020-04-04 20:55:24 +02:00
|
|
|
explicit fourier_gradient( const config_file& the_config )
|
|
|
|
: boxlen_( the_config.get_value<double>("setup", "BoxLength") ),
|
2019-12-04 14:26:42 +01:00
|
|
|
k0_(2.0*M_PI/boxlen_),
|
2020-04-04 20:55:24 +02:00
|
|
|
n_( the_config.get_value<size_t>("setup","GridRes") ),
|
2019-12-04 14:26:42 +01:00
|
|
|
nhalf_( n_/2 )
|
2019-12-02 18:47:34 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
inline ccomplex_t gradient( const int idim, std::array<size_t,3> ijk ) const
|
|
|
|
{
|
|
|
|
real_t rgrad =
|
|
|
|
(ijk[idim]!=nhalf_)? (real_t(ijk[idim]) - real_t(ijk[idim] > nhalf_) * n_) : 0.0;
|
|
|
|
return ccomplex_t(0.0,rgrad * k0_);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline real_t vfac_corr( std::array<size_t,3> ijk ) const
|
|
|
|
{
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
};
|
2019-10-12 15:06:49 +02:00
|
|
|
}
|