Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F65894670
statistics.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Thu, Jun 6, 22:34
Size
5 KB
Mime Type
text/x-c++
Expires
Sat, Jun 8, 22:34 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
18142583
Attached To
rTAMAAS tamaas
statistics.cpp
View Options
/**
* @file
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016-2017 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "statistics.hh"
#include "loop.hh"
#include "static_types.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
template <UInt dim>
Real Statistics<dim>::computeSpectralRMSSlope(Grid<Real, dim>& surface) {
auto h_size = GridHermitian<Real, dim>::hermitianDimensions(surface.sizes());
auto wavevectors =
FFTransform<Real, dim>::template computeFrequencies<true>(h_size);
auto psd = computePowerSpectrum(surface);
auto end = wavevectors.end(dim);
Real rms_slope_mean = 0;
rms_slope_mean = Loop::stridedReduce<operation::plus>(
[] CUDA_LAMBDA(StaticVector<Real, dim> && q, Complex & psd_val) {
return q.l2squared() * psd_val.real();
},
wavevectors, psd);
rms_slope_mean /= wavevectors.getNbPoints(); // average
rms_slope_mean *= 2; // because we have a hermitian surface
return rms_slope_mean;
}
/* -------------------------------------------------------------------------- */
template <UInt dim>
GridHermitian<Real, dim>
Statistics<dim>::computePowerSpectrum(Grid<Real, dim>& surface) {
auto h_size = GridHermitian<Real, dim>::hermitianDimensions(surface.sizes());
GridHermitian<Real, dim> psd(h_size, surface.getNbComponents());
FFTPlanManager::get().createPlan(surface, psd).forwardTransform();
Real factor = surface.getNbPoints();
factor = 1. / (factor * factor);
// Squaring the fourier transform of surface and normalizing
Loop::loop(
[factor] CUDA_LAMBDA(Complex & c) {
c *= conj(c);
c *= factor;
},
psd);
FFTPlanManager::get().destroyPlan(surface, psd);
return psd;
}
/* -------------------------------------------------------------------------- */
template <UInt dim>
Grid<Real, dim>
Statistics<dim>::computeAutocorrelation(Grid<Real, dim>& surface) {
Grid<Real, dim> acf(surface.sizes(), surface.getNbComponents());
auto psd = computePowerSpectrum(surface);
FFTPlanManager::get().createPlan(acf, psd).backwardTransform();
acf *= acf.getNbPoints();
FFTPlanManager::get().destroyPlan(acf, psd);
return acf;
}
/* -------------------------------------------------------------------------- */
namespace {
template <UInt dim>
class moment_helper {
public:
moment_helper(const std::array<UInt, dim>& exp) : exponent(exp) {}
CUDA_LAMBDA Complex operator()(const StaticVector<const Real, dim>& q,
const Complex& phi) const {
Real mul = 1;
for (UInt i = 0; i < dim; ++i)
mul *= std::pow(q(i), exponent[i]);
return mul * phi;
}
private:
std::array<UInt, dim> exponent;
};
}
template <>
std::vector<Real> Statistics<1>::computeMoments(Grid<Real, 1>& surface) {
constexpr UInt dim = 1;
std::vector<Real> moments(3);
const auto psd = computePowerSpectrum(surface);
const auto wavevectors =
FFTransform<Real, dim>::template computeFrequencies<true>(psd.sizes());
moments[0] = psd.sum().real();
moments[1] =
Loop::reduce<operation::plus>(moment_helper<dim>{{{2}}}, wavevectors, psd)
.real();
moments[2] =
Loop::reduce<operation::plus>(moment_helper<dim>{{{4}}}, wavevectors, psd)
.real();
return moments;
}
template <>
std::vector<Real> Statistics<2>::computeMoments(Grid<Real, 2>& surface) {
constexpr UInt dim = 2;
std::vector<Real> moments(3);
const auto psd = computePowerSpectrum(surface);
const auto wavevectors =
FFTransform<Real, dim>::template computeFrequencies<true>(psd.sizes());
moments[0] = psd.sum().real();
auto m02 = Loop::reduce<operation::plus>(moment_helper<dim>{{{0, 2}}},
wavevectors, psd)
.real();
auto m20 = Loop::reduce<operation::plus>(moment_helper<dim>{{{2, 0}}},
wavevectors, psd)
.real();
moments[1] = 0.5 * (m02 + m20);
auto m22 = Loop::reduce<operation::plus>(moment_helper<dim>{{{2, 2}}},
wavevectors, psd)
.real();
auto m40 = Loop::reduce<operation::plus>(moment_helper<dim>{{{4, 0}}},
wavevectors, psd)
.real();
auto m04 = Loop::reduce<operation::plus>(moment_helper<dim>{{{0, 4}}},
wavevectors, psd)
.real();
moments[2] = (3 * m22 + m40 + m04) / 3.;
return moments;
}
template struct Statistics<1>;
template struct Statistics<2>;
__END_TAMAAS__
Event Timeline
Log In to Comment