Added Consturctor for force and improved tests
This commit is contained in:
parent
29779754e9
commit
bffd99fb8a
@ -24,10 +24,24 @@ Calculation::Calculation(std::function<void(Rod2d &, Simulation &)> t_integrator
|
|||||||
: sim(deltaT, seed), m_integrator(
|
: sim(deltaT, seed), m_integrator(
|
||||||
std::move(t_integrator)) {
|
std::move(t_integrator)) {
|
||||||
for (const auto &pair: t_computes) {
|
for (const auto &pair: t_computes) {
|
||||||
computes.emplace_back(Compute(rod, pair.first, pair.second,sim));
|
computes.emplace_back(Compute(rod, pair.first, pair.second, sim));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Calculation::Calculation(
|
||||||
|
std::function<void(Rod2d &, Simulation &, std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)>,
|
||||||
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)>)> t_integrator,
|
||||||
|
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes, double deltaT,
|
||||||
|
size_t seed, std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
||||||
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque)
|
||||||
|
: sim(deltaT, seed) {
|
||||||
|
m_integrator = [&](Rod2d &t_rod, Simulation &t_sim) { t_integrator(t_rod, t_sim, force, torque); };
|
||||||
|
for (const auto &pair: t_computes) {
|
||||||
|
computes.emplace_back(Compute(rod, pair.first, pair.second, sim));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::vector<Compute> &Calculation::getComputes() const {
|
const std::vector<Compute> &Calculation::getComputes() const {
|
||||||
return computes;
|
return computes;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
class Calculation {
|
class Calculation {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
Rod2d rod = Rod2d(1.0);
|
Rod2d rod = Rod2d(1.0);
|
||||||
Simulation sim;
|
Simulation sim;
|
||||||
std::function<void(Rod2d &, Simulation &)> m_integrator;
|
std::function<void(Rod2d &, Simulation &)> m_integrator;
|
||||||
@ -20,7 +21,13 @@ private:
|
|||||||
public:
|
public:
|
||||||
const Simulation &getSim() const;
|
const Simulation &getSim() const;
|
||||||
|
|
||||||
public:
|
Calculation(
|
||||||
|
std::function<void(Rod2d &, Simulation &, std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)>,
|
||||||
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)>)> t_integrator,
|
||||||
|
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes, double deltaT, size_t seed,
|
||||||
|
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
||||||
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque);
|
||||||
|
|
||||||
explicit Calculation(std::function<void(Rod2d &, Simulation &)> t_integrator,
|
explicit Calculation(std::function<void(Rod2d &, Simulation &)> t_integrator,
|
||||||
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes, double deltaT,
|
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes, double deltaT,
|
||||||
size_t seed);
|
size_t seed);
|
||||||
|
@ -7,70 +7,83 @@
|
|||||||
#include <Compute.h>
|
#include <Compute.h>
|
||||||
#include <Integratoren2d_force.h>
|
#include <Integratoren2d_force.h>
|
||||||
|
|
||||||
TEST_CASE("Integratoren") {
|
TEST_CASE("Forceless Integratoren") {
|
||||||
auto zero_Force = [](const Eigen::Vector2d & /*pos*/,
|
const size_t SEED = Catch::rngSeed();
|
||||||
const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d { return {0.0, 0.0}; };
|
auto force = [](const Eigen::Vector2d & /*pos*/,
|
||||||
auto zero_Torque = [](const Eigen::Vector2d & /*pos*/,
|
const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d { return {0.0, 0.0}; };
|
||||||
const Eigen::Vector2d & /*torque*/) -> double { return 0.0; };
|
auto torque = [](const Eigen::Vector2d & /*pos*/,
|
||||||
auto euler_Zero = [&](Rod2d &rod, Simulation &sim) {
|
const Eigen::Vector2d & /*torque*/) -> double { return 0.0; };
|
||||||
return Integratoren2d_force::Set1_Euler(rod, sim, zero_Force, zero_Torque);
|
|
||||||
};
|
|
||||||
auto heun_Zero = [&](Rod2d &rod, Simulation &sim) {
|
|
||||||
return Integratoren2d_force::Set2_Heun(rod, sim, zero_Force, zero_Torque);
|
|
||||||
};
|
|
||||||
auto exact_Zero = [&](Rod2d &rod, Simulation &sim) {
|
|
||||||
return Integratoren2d_force::Set3_Exact(rod, sim, zero_Force, zero_Torque);
|
|
||||||
};
|
|
||||||
auto bdas_Zero = [&](Rod2d &rod, Simulation &sim) {
|
|
||||||
return Integratoren2d_force::Set4_BDAS(rod, sim, zero_Force, zero_Torque);
|
|
||||||
};
|
|
||||||
SECTION("Euler") {
|
SECTION("Euler") {
|
||||||
|
|
||||||
Calculation euler(Integratoren2d_forceless::Set1_Euler, {{Compute::Type::msd, 1},
|
Calculation euler(Integratoren2d_forceless::Set1_Euler, {{Compute::Type::msd, 1},
|
||||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
{Compute::Type::oaf, 1}}, 0.01, SEED);
|
||||||
euler.run(10000);
|
{
|
||||||
for (auto &c: euler.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
euler.run(10000);
|
||||||
Calculation euler_force(euler_Zero, {{Compute::Type::msd, 1},
|
for (auto &c: euler.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
}
|
||||||
euler_force.run(10000);
|
|
||||||
for (auto &c: euler_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
Calculation euler_force(Integratoren2d_force::Set1_Euler, {
|
||||||
}SECTION("Heun") {
|
{Compute::Type::msd, 1},
|
||||||
|
{Compute::Type::oaf, 1}}, 0.01, SEED, force, torque);
|
||||||
|
{
|
||||||
|
euler_force.run(10000);
|
||||||
|
for (auto &c: euler_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||||
|
}
|
||||||
|
CHECK(euler.getComputes()[0].getAgg().getMean() == euler_force.getComputes()[0].getAgg().getMean());
|
||||||
|
CHECK(euler.getComputes()[1].getAgg().getMean() == euler_force.getComputes()[1].getAgg().getMean());
|
||||||
|
}SECTION("Heun") {
|
||||||
|
|
||||||
|
Calculation heun(Integratoren2d_forceless::Set2_Heun, {{Compute::Type::msd, 1},
|
||||||
|
{Compute::Type::oaf, 1}}, 0.01, SEED);
|
||||||
{
|
{
|
||||||
Calculation heun(Integratoren2d_forceless::Set2_Heun, {{Compute::Type::msd, 1},
|
|
||||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
|
||||||
heun.run(10000);
|
heun.run(10000);
|
||||||
for (auto &c: heun.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
for (auto &c: heun.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Calculation heun_force(Integratoren2d_force::Set2_Heun, {{Compute::Type::msd, 1},
|
||||||
|
{Compute::Type::oaf, 1}}, 0.01, SEED, force,
|
||||||
|
torque);
|
||||||
{
|
{
|
||||||
Calculation heun_force(heun_Zero, {{Compute::Type::msd, 1},
|
|
||||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
|
||||||
heun_force.run(10000);
|
heun_force.run(10000);
|
||||||
for (auto &c: heun_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
for (auto &c: heun_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||||
}
|
}
|
||||||
|
CHECK(heun.getComputes()[0].getAgg().getMean() == heun_force.getComputes()[0].getAgg().getMean());
|
||||||
|
CHECK(heun.getComputes()[1].getAgg().getMean() == heun_force.getComputes()[1].getAgg().getMean());
|
||||||
}SECTION("Exact") {
|
}SECTION("Exact") {
|
||||||
|
|
||||||
|
Calculation exact(Integratoren2d_forceless::Set3_Exact, {{Compute::Type::msd, 1},
|
||||||
|
{Compute::Type::oaf, 1}}, 0.01, SEED);
|
||||||
{
|
{
|
||||||
Calculation exact(Integratoren2d_forceless::Set3_Exact, {{Compute::Type::msd, 1},
|
|
||||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
|
||||||
exact.run(10000);
|
exact.run(10000);
|
||||||
for (auto &c: exact.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
for (auto &c: exact.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Calculation exact_force(Integratoren2d_force::Set3_Exact, {{Compute::Type::msd, 1},
|
||||||
|
{Compute::Type::oaf, 1}}, 0.01, SEED, force,
|
||||||
|
torque);
|
||||||
{
|
{
|
||||||
Calculation exact_force(exact_Zero, {{Compute::Type::msd, 1},
|
|
||||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
|
||||||
exact_force.run(10000);
|
exact_force.run(10000);
|
||||||
for (auto &c: exact_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
for (auto &c: exact_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||||
}
|
}
|
||||||
|
CHECK(exact.getComputes()[0].getAgg().getMean() == Approx(exact_force.getComputes()[0].getAgg().getMean()).epsilon(1e-10));
|
||||||
|
CHECK(exact.getComputes()[1].getAgg().getMean() == exact_force.getComputes()[1].getAgg().getMean());
|
||||||
}SECTION("BDAS") {
|
}SECTION("BDAS") {
|
||||||
|
|
||||||
|
Calculation bdas(Integratoren2d_forceless::Set4_BDAS, {{Compute::Type::msd, 1},
|
||||||
|
{Compute::Type::oaf, 1}}, 0.01, SEED);
|
||||||
{
|
{
|
||||||
Calculation bdas(Integratoren2d_forceless::Set4_BDAS, {{Compute::Type::msd, 1},
|
|
||||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
|
||||||
bdas.run(10000);
|
bdas.run(10000);
|
||||||
for (auto &c: bdas.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
for (auto &c: bdas.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Calculation bdas_force(Integratoren2d_force::Set4_BDAS, {{Compute::Type::msd, 1},
|
||||||
|
{Compute::Type::oaf, 1}}, 0.01, SEED, force,
|
||||||
|
torque);
|
||||||
{
|
{
|
||||||
Calculation bdas_zero(bdas_Zero, {{Compute::Type::msd, 1},
|
bdas_force.run(10000);
|
||||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
for (auto &c: bdas_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||||
bdas_zero.run(10000);
|
|
||||||
for (auto &c: bdas_zero.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
|
||||||
}
|
}
|
||||||
|
CHECK(bdas.getComputes()[0].getAgg().getMean() == bdas_force.getComputes()[0].getAgg().getMean());
|
||||||
|
CHECK(bdas.getComputes()[1].getAgg().getMean() == bdas_force.getComputes()[1].getAgg().getMean());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user