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(
|
||||
std::move(t_integrator)) {
|
||||
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 {
|
||||
return computes;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
class Calculation {
|
||||
private:
|
||||
|
||||
Rod2d rod = Rod2d(1.0);
|
||||
Simulation sim;
|
||||
std::function<void(Rod2d &, Simulation &)> m_integrator;
|
||||
@ -20,7 +21,13 @@ private:
|
||||
public:
|
||||
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,
|
||||
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes, double deltaT,
|
||||
size_t seed);
|
||||
|
@ -7,70 +7,83 @@
|
||||
#include <Compute.h>
|
||||
#include <Integratoren2d_force.h>
|
||||
|
||||
TEST_CASE("Integratoren") {
|
||||
auto zero_Force = [](const Eigen::Vector2d & /*pos*/,
|
||||
const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d { return {0.0, 0.0}; };
|
||||
auto zero_Torque = [](const Eigen::Vector2d & /*pos*/,
|
||||
const Eigen::Vector2d & /*torque*/) -> double { return 0.0; };
|
||||
auto euler_Zero = [&](Rod2d &rod, Simulation &sim) {
|
||||
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);
|
||||
};
|
||||
TEST_CASE("Forceless Integratoren") {
|
||||
const size_t SEED = Catch::rngSeed();
|
||||
auto force = [](const Eigen::Vector2d & /*pos*/,
|
||||
const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d { return {0.0, 0.0}; };
|
||||
auto torque = [](const Eigen::Vector2d & /*pos*/,
|
||||
const Eigen::Vector2d & /*torque*/) -> double { return 0.0; };
|
||||
SECTION("Euler") {
|
||||
|
||||
Calculation euler(Integratoren2d_forceless::Set1_Euler, {{Compute::Type::msd, 1},
|
||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
||||
euler.run(10000);
|
||||
for (auto &c: euler.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||
Calculation euler_force(euler_Zero, {{Compute::Type::msd, 1},
|
||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
||||
euler_force.run(10000);
|
||||
for (auto &c: euler_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||
}SECTION("Heun") {
|
||||
{Compute::Type::oaf, 1}}, 0.01, SEED);
|
||||
{
|
||||
euler.run(10000);
|
||||
for (auto &c: euler.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||
}
|
||||
|
||||
Calculation euler_force(Integratoren2d_force::Set1_Euler, {
|
||||
{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);
|
||||
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);
|
||||
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") {
|
||||
|
||||
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);
|
||||
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);
|
||||
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") {
|
||||
|
||||
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);
|
||||
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},
|
||||
{Compute::Type::oaf, 1}}, 0.01, 12345);
|
||||
bdas_zero.run(10000);
|
||||
for (auto &c: bdas_zero.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
||||
bdas_force.run(10000);
|
||||
for (auto &c: bdas_force.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