Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85144551
test_integration.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
Fri, Sep 27, 02:12
Size
5 KB
Mime Type
text/x-c
Expires
Sun, Sep 29, 02:12 (2 d)
Engine
blob
Format
Raw Data
Handle
21134544
Attached To
rTAMAAS tamaas
test_integration.cpp
View Options
/**
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2019 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 "fftransform.hh"
#include "integration/accumulator.hh"
#include "test.hh"
#include <cmath>
#include <expolit/expolit>
/* -------------------------------------------------------------------------- */
using namespace tamaas;
namespace ex = expolit;
class AccumulatorTest : public ::testing::Test {
protected:
void SetUp() override {
nodal_values.resize(n);
for (auto&& grid : nodal_values) {
grid.setNbComponents(9);
grid.resize({2, 2});
grid = 1;
}
accumulator.makeUniformMesh(nodal_values.size(), size);
wavevectors = FFTransform<Real, 2>::computeFrequencies<true>({2, 2});
}
UInt n = 10;
Real size = 5;
std::vector<GridHermitian<Real, 2>> nodal_values;
Grid<Real, 2> wavevectors;
Accumulator<model_type::volume_2d, MatrixProxy<Complex, 3, 3>> accumulator;
};
TEST_F(AccumulatorTest, uniformMesh) {
auto& pos = this->accumulator.nodePositions();
std::vector<Real> sol(pos.size());
std::iota(sol.begin(), sol.end(), 0);
std::transform(sol.begin(), sol.end(), sol.begin(),
[&](auto& x) { return size * x / (sol.size() - 1); });
ASSERT_TRUE(compare(sol, pos, AreFloatEqual())) << "Uniform mesh fail";
}
// Litteral type
using Q = ex::Litteral<struct Q_>;
TEST_F(AccumulatorTest, forward) {
// Setup for layer checking
std::vector<int> layers_seen, layers_to_see(n);
std::iota(layers_to_see.begin(), layers_to_see.end(), 0);
// Setup for integral checking
constexpr Q q;
constexpr auto z = ex::Polynomial<Real, 1>({0, 1});
constexpr auto g0 = ex::exp(q * z);
constexpr auto g1 = q * z * ex::exp(q * z);
for (auto [l, xl_, acc_g0, acc_g1] :
accumulator.forward(this->nodal_values, this->wavevectors)) {
layers_seen.push_back(l);
auto testing = acc_g0(1, 0, 0);
ASSERT_NEAR(testing.real(), acc_g0(0, 1, 0).real(), 1e-10)
<< "Symmetry fail";
ASSERT_NEAR(testing.imag(), acc_g0(0, 1, 0).imag(), 1e-10)
<< "Symmetry fail";
testing = acc_g0(1, 1, 0);
auto ref_value = ex::definite_integral(
std::make_pair(0., xl_),
ex::substitute<Q::tag>(ex::Constant<Real>({std::sqrt(2)}), g0));
ASSERT_NEAR(testing.real(), ref_value, 1e-10)
<< "Integration of exp(qy)*ϕ(y) fail";
testing = acc_g1(1, 1, 0);
ref_value = ex::definite_integral(
std::make_pair(0., xl_),
ex::substitute<Q::tag>(ex::Constant<Real>({std::sqrt(2)}), g1));
ASSERT_NEAR(testing.real(), ref_value, 1e-10)
<< "Integration of qy*exp(qy)*ϕ(y) fail";
}
ASSERT_TRUE(compare(layers_seen, layers_to_see))
<< "Did not see correct layers";
}
TEST_F(AccumulatorTest, backward) {
// Setup for layer checking
std::vector<int> layers_seen, layers_to_see(n);
std::iota(layers_to_see.rbegin(), layers_to_see.rend(), 0);
// Setup for integral checking
constexpr Q q;
constexpr auto z = ex::Polynomial<Real, 1>({0, 1});
constexpr auto g0 = ex::exp(q * (z * (-1)));
constexpr auto g1 = q * z * ex::exp(q * ((-1) * z));
for (auto [l, xl_, acc_g0, acc_g1] :
accumulator.backward(nodal_values, wavevectors)) {
layers_seen.push_back(l);
auto testing = acc_g0(1, 0, 0);
ASSERT_NEAR(testing.real(), acc_g0(0, 1, 0).real(), 1e-10)
<< "Symmetry fail";
ASSERT_NEAR(testing.imag(), acc_g0(0, 1, 0).imag(), 1e-10)
<< "Symmetry fail";
testing = acc_g0(1, 1, 0);
auto ref_value = ex::definite_integral(
std::make_pair(xl_, size),
ex::substitute<Q::tag>(ex::Constant<Real>({std::sqrt(2)}), g0));
ASSERT_NEAR(testing.real(), ref_value, 1e-10)
<< "Integration of exp(-qy)*ϕ(y) fail";
testing = acc_g1(1, 1, 0);
ref_value = ex::definite_integral(
std::make_pair(xl_, size),
ex::substitute<Q::tag>(ex::Constant<Real>({std::sqrt(2)}), g1));
ASSERT_NEAR(testing.real(), ref_value, 1e-10)
<< "Integration of qy*exp(-qy)*ϕ(y) fail";
}
ASSERT_TRUE(compare(layers_seen, layers_to_see))
<< "Did not see correct layers";
}
TEST_F(AccumulatorTest, fundamentalForward) {
// Setup for layer checking
std::vector<int> layers_seen, layers_to_see(n);
std::iota(layers_to_see.begin(), layers_to_see.end(), 0);
for (auto [l, xl_, acc_g0] : accumulator.fundamentalForward(nodal_values)) {
layers_seen.push_back(l);
auto testing = acc_g0(0, 0, 0);
ASSERT_NEAR(testing.real(), xl_, 1e-10)
<< "Integration of fundamental mode fail";
}
ASSERT_TRUE(compare(layers_seen, layers_to_see))
<< "Did not see correct layers";
}
TEST_F(AccumulatorTest, fundamentalBackward) {
// Setup for layer checking
std::vector<int> layers_seen, layers_to_see(n);
std::iota(layers_to_see.rbegin(), layers_to_see.rend(), 0);
for (auto [l, xl_, acc_g0] : accumulator.fundamentalBackward(nodal_values)) {
layers_seen.push_back(l);
auto testing = acc_g0(0, 0, 0);
ASSERT_NEAR(testing.real(), size - xl_, 1e-10)
<< "Integration of fundamental mode fail";
}
ASSERT_TRUE(compare(layers_seen, layers_to_see))
<< "Did not see correct layers";
}
Event Timeline
Log In to Comment