Clang-format
This commit is contained in:
parent
07b1f194a6
commit
362ec38dd2
112
.clang-format
112
.clang-format
@ -1,12 +1,15 @@
|
|||||||
AccessModifierOffset: -2
|
---
|
||||||
AlignAfterOpenBracket: DontAlign
|
Language: Cpp
|
||||||
|
# BasedOnStyle: Google
|
||||||
|
AccessModifierOffset: -1
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
AlignConsecutiveAssignments: false
|
AlignConsecutiveAssignments: false
|
||||||
AlignConsecutiveDeclarations: false
|
AlignConsecutiveDeclarations: false
|
||||||
AlignEscapedNewlines: Left
|
AlignEscapedNewlines: Left
|
||||||
AlignOperands: true
|
AlignOperands: true
|
||||||
AlignTrailingComments: false
|
AlignTrailingComments: true
|
||||||
AllowAllParametersOfDeclarationOnNextLine: false
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
AllowShortBlocksOnASingleLine: true
|
AllowShortBlocksOnASingleLine: false
|
||||||
AllowShortCaseLabelsOnASingleLine: false
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
AllowShortFunctionsOnASingleLine: All
|
AllowShortFunctionsOnASingleLine: All
|
||||||
AllowShortIfStatementsOnASingleLine: true
|
AllowShortIfStatementsOnASingleLine: true
|
||||||
@ -14,85 +17,92 @@ AllowShortLoopsOnASingleLine: true
|
|||||||
AlwaysBreakAfterDefinitionReturnType: None
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
AlwaysBreakAfterReturnType: None
|
AlwaysBreakAfterReturnType: None
|
||||||
AlwaysBreakBeforeMultilineStrings: true
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
AlwaysBreakTemplateDeclarations: false
|
AlwaysBreakTemplateDeclarations: true
|
||||||
BinPackArguments: false
|
BinPackArguments: true
|
||||||
BinPackParameters: false
|
BinPackParameters: true
|
||||||
BraceWrapping:
|
BraceWrapping:
|
||||||
AfterClass: true
|
AfterClass: false
|
||||||
AfterControlStatement: false
|
AfterControlStatement: false
|
||||||
AfterEnum: false
|
AfterEnum: false
|
||||||
AfterFunction: true
|
AfterFunction: false
|
||||||
AfterNamespace: false
|
AfterNamespace: false
|
||||||
AfterObjCDeclaration: false
|
AfterObjCDeclaration: false
|
||||||
AfterStruct: true
|
AfterStruct: false
|
||||||
AfterUnion: false
|
AfterUnion: false
|
||||||
BeforeCatch: false
|
BeforeCatch: false
|
||||||
BeforeElse: false
|
BeforeElse: false
|
||||||
IndentBraces: false
|
IndentBraces: false
|
||||||
SplitEmptyFunction: false
|
SplitEmptyFunction: true
|
||||||
SplitEmptyNamespace: true
|
|
||||||
SplitEmptyRecord: true
|
SplitEmptyRecord: true
|
||||||
BreakAfterJavaFieldAnnotations: true
|
SplitEmptyNamespace: true
|
||||||
BreakBeforeBinaryOperators: NonAssignment
|
BreakBeforeBinaryOperators: None
|
||||||
BreakBeforeBraces: Custom
|
BreakBeforeBraces: Attach
|
||||||
BreakBeforeInheritanceComma: true
|
BreakBeforeInheritanceComma: false
|
||||||
BreakBeforeTernaryOperators: true
|
BreakBeforeTernaryOperators: true
|
||||||
BreakConstructorInitializers: BeforeColon
|
|
||||||
BreakConstructorInitializersBeforeComma: false
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
BreakStringLiterals: true
|
BreakStringLiterals: true
|
||||||
ColumnLimit: 0
|
ColumnLimit: 80
|
||||||
CommentPragmas: '^ IWYU pragma:'
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
CompactNamespaces: false
|
CompactNamespaces: false
|
||||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
ConstructorInitializerIndentWidth: 2
|
ConstructorInitializerIndentWidth: 4
|
||||||
ContinuationIndentWidth: 2
|
ContinuationIndentWidth: 4
|
||||||
Cpp11BracedListStyle: false
|
Cpp11BracedListStyle: true
|
||||||
DerivePointerAlignment: false
|
DerivePointerAlignment: true
|
||||||
DisableFormat: false
|
DisableFormat: false
|
||||||
ExperimentalAutoDetectBinPacking: true
|
ExperimentalAutoDetectBinPacking: false
|
||||||
FixNamespaceComments: true
|
FixNamespaceComments: true
|
||||||
ForEachMacros:
|
ForEachMacros:
|
||||||
- foreach
|
- foreach
|
||||||
- Q_FOREACH
|
- Q_FOREACH
|
||||||
- BOOST_FOREACH
|
- BOOST_FOREACH
|
||||||
IncludeCategories:
|
IncludeCategories:
|
||||||
- Priority: 2
|
- Regex: '^<.*\.h>'
|
||||||
Regex: ^"(llvm|llvm-c|clang|clang-c)/
|
Priority: 1
|
||||||
- Priority: 3
|
- Regex: '^<.*'
|
||||||
Regex: ^(<|"(gtest|gmock|isl|json)/)
|
Priority: 2
|
||||||
- Priority: 1
|
- Regex: '.*'
|
||||||
Regex: .*
|
Priority: 3
|
||||||
IncludeIsMainRegex: (Test)?$
|
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||||
IndentCaseLabels: false
|
IndentCaseLabels: true
|
||||||
IndentWidth: 2
|
IndentWidth: 4
|
||||||
IndentWrappedFunctionNames: true
|
IndentWrappedFunctionNames: false
|
||||||
JavaScriptQuotes: Leave
|
JavaScriptQuotes: Leave
|
||||||
JavaScriptWrapImports: true
|
JavaScriptWrapImports: true
|
||||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
Language: Cpp
|
|
||||||
MacroBlockBegin: ''
|
MacroBlockBegin: ''
|
||||||
MacroBlockEnd: ''
|
MacroBlockEnd: ''
|
||||||
MaxEmptyLinesToKeep: 2
|
MaxEmptyLinesToKeep: 1
|
||||||
NamespaceIndentation: Inner
|
NamespaceIndentation: None
|
||||||
ObjCBlockIndentWidth: 7
|
ObjCBlockIndentWidth: 4
|
||||||
ObjCSpaceAfterProperty: true
|
ObjCSpaceAfterProperty: false
|
||||||
ObjCSpaceBeforeProtocolList: false
|
ObjCSpaceBeforeProtocolList: false
|
||||||
PointerAlignment: Right
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 1
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
|
PointerAlignment: Left
|
||||||
ReflowComments: true
|
ReflowComments: true
|
||||||
SortIncludes: false
|
SortIncludes: true
|
||||||
SortUsingDeclarations: false
|
SortUsingDeclarations: true
|
||||||
SpaceAfterCStyleCast: false
|
SpaceAfterCStyleCast: false
|
||||||
SpaceAfterTemplateKeyword: false
|
SpaceAfterTemplateKeyword: true
|
||||||
SpaceBeforeAssignmentOperators: true
|
SpaceBeforeAssignmentOperators: true
|
||||||
SpaceBeforeParens: ControlStatements
|
SpaceBeforeParens: ControlStatements
|
||||||
SpaceInEmptyParentheses: false
|
SpaceInEmptyParentheses: false
|
||||||
SpacesBeforeTrailingComments: 0
|
SpacesBeforeTrailingComments: 2
|
||||||
SpacesInAngles: false
|
SpacesInAngles: false
|
||||||
SpacesInCStyleCastParentheses: false
|
|
||||||
SpacesInContainerLiterals: true
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
SpacesInParentheses: false
|
SpacesInParentheses: false
|
||||||
SpacesInSquareBrackets: false
|
SpacesInSquareBrackets: false
|
||||||
Standard: Cpp11
|
Standard: Auto
|
||||||
TabWidth: 8
|
TabWidth: 8
|
||||||
UseTab: Never
|
UseTab: Never
|
||||||
|
...
|
||||||
|
|
||||||
|
@ -6,27 +6,22 @@
|
|||||||
#define CATCH_CONFIG_ENABLE_BENCHMARKING
|
#define CATCH_CONFIG_ENABLE_BENCHMARKING
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include "Rod2d.hpp"
|
|
||||||
#include "Integratoren2d_forceless.h"
|
#include "Integratoren2d_forceless.h"
|
||||||
|
#include "Rod2d.hpp"
|
||||||
|
|
||||||
TEST_CASE("Euler - Baseline", "[benchmark]")
|
TEST_CASE("Euler - Baseline", "[benchmark]") {
|
||||||
{
|
|
||||||
Rod2d rod(1.0);
|
Rod2d rod(1.0);
|
||||||
Simulation sim(0.01, Catch::rngSeed());
|
Simulation sim(0.01, Catch::rngSeed());
|
||||||
BENCHMARK("Euler without force")
|
BENCHMARK("Euler without force") {
|
||||||
{
|
|
||||||
Integratoren2d_forceless::Set1_Euler(rod, sim);
|
Integratoren2d_forceless::Set1_Euler(rod, sim);
|
||||||
};
|
};
|
||||||
BENCHMARK("Heun without force")
|
BENCHMARK("Heun without force") {
|
||||||
{
|
|
||||||
Integratoren2d_forceless::Set2_Heun(rod, sim);
|
Integratoren2d_forceless::Set2_Heun(rod, sim);
|
||||||
};
|
};
|
||||||
BENCHMARK("Exact without force")
|
BENCHMARK("Exact without force") {
|
||||||
{
|
|
||||||
Integratoren2d_forceless::Set3_Exact(rod, sim);
|
Integratoren2d_forceless::Set3_Exact(rod, sim);
|
||||||
};
|
};
|
||||||
BENCHMARK("BDAS without force")
|
BENCHMARK("BDAS without force") {
|
||||||
{
|
|
||||||
Integratoren2d_forceless::Set4_BDAS(rod, sim);
|
Integratoren2d_forceless::Set4_BDAS(rod, sim);
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -6,46 +6,48 @@
|
|||||||
|
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
void Calculation::run(size_t steps) {
|
void Calculation::run(size_t steps) {
|
||||||
for (size_t step = 0; step < steps; ++step) {
|
for (size_t step = 0; step < steps; ++step) {
|
||||||
m_integrator(rod, sim);
|
m_integrator(rod, sim);
|
||||||
for (auto &comp: computes) { comp.eval(rod); }
|
for (auto &comp : computes) {
|
||||||
|
comp.eval(rod);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Rod2d &Calculation::getRod() const {
|
const Rod2d &Calculation::getRod() const { return rod; }
|
||||||
return rod;
|
|
||||||
}
|
|
||||||
|
|
||||||
Calculation::Calculation(std::function<void(Rod2d &, Simulation &)> t_integrator,
|
Calculation::Calculation(
|
||||||
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes, double deltaT,
|
std::function<void(Rod2d &, Simulation &)> t_integrator,
|
||||||
size_t seed)
|
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes,
|
||||||
: sim(deltaT, seed), m_integrator(
|
double deltaT, size_t seed)
|
||||||
std::move(t_integrator)) {
|
: sim(deltaT, seed), m_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(
|
Calculation::Calculation(
|
||||||
std::function<void(Rod2d &, Simulation &, std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)>,
|
std::function<
|
||||||
std::function<double(Eigen::Vector2d, Eigen::Vector2d)>)> t_integrator,
|
void(Rod2d &, Simulation &,
|
||||||
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes, double deltaT,
|
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)>,
|
||||||
size_t seed, std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
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)
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque)
|
||||||
: sim(deltaT, seed) {
|
: sim(deltaT, seed) {
|
||||||
m_integrator = [&](Rod2d &t_rod, Simulation &t_sim) { t_integrator(t_rod, t_sim, force, torque); };
|
m_integrator = [&](Rod2d &t_rod, Simulation &t_sim) {
|
||||||
for (const auto &pair: t_computes) {
|
t_integrator(t_rod, t_sim, force, torque);
|
||||||
|
};
|
||||||
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const std::vector<Compute> &Calculation::getComputes() const {
|
const std::vector<Compute> &Calculation::getComputes() const {
|
||||||
return computes;
|
return computes;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Simulation &Calculation::getSim() const {
|
const Simulation &Calculation::getSim() const { return sim; }
|
||||||
return sim;
|
|
||||||
}
|
|
||||||
|
@ -2,35 +2,38 @@
|
|||||||
// Created by jholder on 22.10.21.
|
// Created by jholder on 22.10.21.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef MYPROJECT_CALCULATION_H
|
#pragma once
|
||||||
#define MYPROJECT_CALCULATION_H
|
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include "Compute.h"
|
||||||
#include "Rod2d.hpp"
|
#include "Rod2d.hpp"
|
||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
#include "functional"
|
|
||||||
#include "Compute.h"
|
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
std::vector<Compute> computes;
|
std::vector<Compute> computes;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
const Simulation &getSim() const;
|
const Simulation &getSim() const;
|
||||||
|
|
||||||
Calculation(
|
Calculation(
|
||||||
std::function<void(Rod2d &, Simulation &, std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)>,
|
std::function<void(
|
||||||
std::function<double(Eigen::Vector2d, Eigen::Vector2d)>)> t_integrator,
|
Rod2d &, Simulation &,
|
||||||
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes, double deltaT, size_t seed,
|
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<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
||||||
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque);
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque);
|
||||||
|
|
||||||
explicit Calculation(std::function<void(Rod2d &, Simulation &)> t_integrator,
|
explicit Calculation(
|
||||||
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes, double deltaT,
|
std::function<void(Rod2d &, Simulation &)> t_integrator,
|
||||||
size_t seed);
|
std::initializer_list<std::pair<Compute::Type, size_t>> t_computes,
|
||||||
|
double deltaT, size_t seed);
|
||||||
|
|
||||||
[[nodiscard]] const std::vector<Compute> &getComputes() const;
|
[[nodiscard]] const std::vector<Compute> &getComputes() const;
|
||||||
|
|
||||||
@ -38,6 +41,3 @@ public:
|
|||||||
|
|
||||||
[[nodiscard]] const Rod2d &getRod() const;
|
[[nodiscard]] const Rod2d &getRod() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //MYPROJECT_CALCULATION_H
|
|
||||||
|
@ -4,29 +4,27 @@
|
|||||||
|
|
||||||
#include "Compute.h"
|
#include "Compute.h"
|
||||||
|
|
||||||
#include <utility>
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "Rod2d.hpp"
|
#include "Rod2d.hpp"
|
||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
|
|
||||||
void Compute::evalMSD(const Rod2d &rod2D)
|
void Compute::evalMSD(const Rod2d &rod2D) {
|
||||||
{
|
|
||||||
const auto &new_pos = rod2D.getPos();
|
const auto &new_pos = rod2D.getPos();
|
||||||
auto old_pos = start_rod.getPos();
|
auto old_pos = start_rod.getPos();
|
||||||
auto msd = (new_pos - old_pos).squaredNorm();
|
auto msd = (new_pos - old_pos).squaredNorm();
|
||||||
agg.feed(msd);
|
agg.feed(msd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compute::evalOAF(const Rod2d &rod2D)
|
void Compute::evalOAF(const Rod2d &rod2D) {
|
||||||
{
|
|
||||||
const auto &new_e = rod2D.getE();
|
const auto &new_e = rod2D.getE();
|
||||||
auto old_e = start_rod.getE();
|
auto old_e = start_rod.getE();
|
||||||
auto oaf = old_e.dot(new_e);
|
auto oaf = old_e.dot(new_e);
|
||||||
agg.feed(oaf);
|
agg.feed(oaf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compute::eval_empXX(const Rod2d &rod2D)
|
void Compute::eval_empXX(const Rod2d &rod2D) {
|
||||||
{
|
|
||||||
const auto &new_pos = rod2D.getPos();
|
const auto &new_pos = rod2D.getPos();
|
||||||
auto old_pos = start_rod.getPos();
|
auto old_pos = start_rod.getPos();
|
||||||
auto old_e = start_rod.getE();
|
auto old_e = start_rod.getE();
|
||||||
@ -34,17 +32,16 @@ void Compute::eval_empXX(const Rod2d &rod2D)
|
|||||||
agg.feed(empxx);
|
agg.feed(empxx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compute::eval_empYY(const Rod2d &rod2D)
|
void Compute::eval_empYY(const Rod2d &rod2D) {
|
||||||
{
|
|
||||||
const auto &new_pos = rod2D.getPos();
|
const auto &new_pos = rod2D.getPos();
|
||||||
auto old_pos = start_rod.getPos();
|
auto old_pos = start_rod.getPos();
|
||||||
auto old_e_ortho = start_rod.getE_ortho();
|
auto old_e = start_rod.getE();
|
||||||
|
Eigen::Vector2d old_e_ortho = {-old_e[1], old_e[0]};
|
||||||
double empxx = pow((new_pos - old_pos).dot(old_e_ortho), 2.0);
|
double empxx = pow((new_pos - old_pos).dot(old_e_ortho), 2.0);
|
||||||
agg.feed(empxx);
|
agg.feed(empxx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Compute::eval(const Rod2d &rod2D)
|
void Compute::eval(const Rod2d &rod2D) {
|
||||||
{
|
|
||||||
time_step++;
|
time_step++;
|
||||||
if (time_step % every == 0) {
|
if (time_step % every == 0) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -66,8 +63,7 @@ void Compute::eval(const Rod2d &rod2D)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Compute::Compute(Rod2d rod, Type t_type, size_t t_every, Simulation &sim)
|
Compute::Compute(Rod2d rod, Type t_type, size_t t_every, Simulation &sim)
|
||||||
: start_rod(std::move(rod)), every(t_every), time_step(0), type(t_type)
|
: start_rod(std::move(rod)), every(t_every), time_step(0), type(t_type) {
|
||||||
{
|
|
||||||
auto time = sim.getMDeltaT() * static_cast<double>(every);
|
auto time = sim.getMDeltaT() * static_cast<double>(every);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case Type::msd:
|
case Type::msd:
|
||||||
@ -80,38 +76,27 @@ Compute::Compute(Rod2d rod, Type t_type, size_t t_every, Simulation &sim)
|
|||||||
const double Dmean = 0.5 * (rod.getDiff().trace());
|
const double Dmean = 0.5 * (rod.getDiff().trace());
|
||||||
const double u = 4.0;
|
const double u = 4.0;
|
||||||
const double deltaD = rod.getDiff()(1, 1) - rod.getDiff()(0, 0);
|
const double deltaD = rod.getDiff()(1, 1) - rod.getDiff()(0, 0);
|
||||||
target = Dmean - deltaD / 2.0 * (1 - exp(-u * rod.getDRot() * time)) / u / rod.getDRot() / time;
|
target = Dmean - deltaD / 2.0 *
|
||||||
|
(1 - exp(-u * rod.getDRot() * time)) / u /
|
||||||
|
rod.getDRot() / time;
|
||||||
} break;
|
} break;
|
||||||
case Type::empyy: {
|
case Type::empyy: {
|
||||||
const double Dmean = 0.5 * (rod.getDiff().trace());
|
const double Dmean = 0.5 * (rod.getDiff().trace());
|
||||||
const double u = 4.0;
|
const double u = 4.0;
|
||||||
const double deltaD = rod.getDiff()(1, 1) - rod.getDiff()(0, 0);
|
const double deltaD = rod.getDiff()(1, 1) - rod.getDiff()(0, 0);
|
||||||
target = Dmean + deltaD / 2.0 * (1 - exp(-u * rod.getDRot() * time)) / u / rod.getDRot() / time;
|
target = Dmean + deltaD / 2.0 *
|
||||||
|
(1 - exp(-u * rod.getDRot() * time)) / u /
|
||||||
|
rod.getDRot() / time;
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const LiveAgg &Compute::getAgg() const
|
const LiveAgg &Compute::getAgg() const { return agg; }
|
||||||
{
|
|
||||||
return agg;
|
|
||||||
}
|
|
||||||
|
|
||||||
Compute::Type Compute::getType() const
|
Compute::Type Compute::getType() const { return type; }
|
||||||
{
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Compute::getTime() const
|
double Compute::getTime() const { return static_cast<double>(every); }
|
||||||
{
|
|
||||||
return static_cast<double>(every);
|
|
||||||
}
|
|
||||||
|
|
||||||
double Compute::getTarget() const
|
double Compute::getTarget() const { return target; }
|
||||||
{
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Compute::getDifference() const
|
double Compute::getDifference() const { return abs(agg.getMean() - target); }
|
||||||
{
|
|
||||||
return abs(agg.getMean() - target);
|
|
||||||
}
|
|
@ -5,21 +5,13 @@
|
|||||||
#ifndef MYPROJECT_COMPUTE_H
|
#ifndef MYPROJECT_COMPUTE_H
|
||||||
#define MYPROJECT_COMPUTE_H
|
#define MYPROJECT_COMPUTE_H
|
||||||
|
|
||||||
|
|
||||||
#include "LiveAgg.hpp"
|
#include "LiveAgg.hpp"
|
||||||
#include "Rod2d.hpp"
|
#include "Rod2d.hpp"
|
||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
|
|
||||||
class Compute
|
class Compute {
|
||||||
{
|
public:
|
||||||
|
enum class Type { msd, oaf, empxx, empyy };
|
||||||
public:
|
|
||||||
enum class Type {
|
|
||||||
msd,
|
|
||||||
oaf,
|
|
||||||
empxx,
|
|
||||||
empyy
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit Compute(Rod2d rod, Type t_type, size_t t_every, Simulation &sim);
|
explicit Compute(Rod2d rod, Type t_type, size_t t_every, Simulation &sim);
|
||||||
|
|
||||||
@ -43,8 +35,7 @@ public:
|
|||||||
|
|
||||||
double getDifference() const;
|
double getDifference() const;
|
||||||
|
|
||||||
|
private:
|
||||||
private:
|
|
||||||
Rod2d start_rod;
|
Rod2d start_rod;
|
||||||
LiveAgg agg;
|
LiveAgg agg;
|
||||||
size_t every;
|
size_t every;
|
||||||
@ -53,5 +44,4 @@ private:
|
|||||||
double target;
|
double target;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif // MYPROJECT_COMPUTE_H
|
||||||
#endif// MYPROJECT_COMPUTE_H
|
|
||||||
|
@ -7,19 +7,16 @@
|
|||||||
constexpr double kBT = 1.0;
|
constexpr double kBT = 1.0;
|
||||||
using Vector = Eigen::Vector2d;
|
using Vector = Eigen::Vector2d;
|
||||||
|
|
||||||
|
Vector Integratoren2d_force::ortho(Vector e) { return Vector{-e[1], e[0]}; }
|
||||||
Vector Integratoren2d_force::ortho(Vector e) {
|
|
||||||
return Vector{-e[1], e[0]};
|
|
||||||
}
|
|
||||||
|
|
||||||
Eigen::Matrix2d Integratoren2d_force::MatTraf(Vector e) {
|
Eigen::Matrix2d Integratoren2d_force::MatTraf(Vector e) {
|
||||||
Eigen::Matrix2d mat;
|
Eigen::Matrix2d mat;
|
||||||
mat << e[0], -e[1],
|
mat << e[0], -e[1], e[1], e[0];
|
||||||
e[1], e[0];
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Integratoren2d_force::Set0_deterministic(Rod2d &rod2D, Simulation & /*sim*/) {
|
void Integratoren2d_force::Set0_deterministic(Rod2d &rod2D,
|
||||||
|
Simulation & /*sim*/) {
|
||||||
auto trans_lab = Vector({0, 0.01});
|
auto trans_lab = Vector({0, 0.01});
|
||||||
rod2D.setPos(rod2D.getPos() + trans_lab);
|
rod2D.setPos(rod2D.getPos() + trans_lab);
|
||||||
Eigen::Rotation2D<double> rot(0.1);
|
Eigen::Rotation2D<double> rot(0.1);
|
||||||
@ -28,42 +25,47 @@ void Integratoren2d_force::Set0_deterministic(Rod2d &rod2D, Simulation & /*sim*/
|
|||||||
|
|
||||||
const Vector Integratoren2d_force::unitVec = {1, 0};
|
const Vector Integratoren2d_force::unitVec = {1, 0};
|
||||||
|
|
||||||
|
void Integratoren2d_force::Set5_MBD(Rod2d & /*rod2D*/, Simulation & /*sim*/) {}
|
||||||
|
|
||||||
void Integratoren2d_force::Set5_MBD(Rod2d &/*rod2D*/, Simulation &/*sim*/) {
|
void Integratoren2d_force::Set1_Euler(
|
||||||
}
|
Rod2d &rod2D, Simulation &sim,
|
||||||
|
|
||||||
void Integratoren2d_force::Set1_Euler(Rod2d &rod2D, Simulation &sim,
|
|
||||||
const std::function<Vector(Vector, Vector)> &force,
|
const std::function<Vector(Vector, Vector)> &force,
|
||||||
const std::function<double(Vector, Vector)> &torque) {
|
const std::function<double(Vector, Vector)> &torque) {
|
||||||
auto std = sim.getSTD(); // sqrt(2*delta_T)
|
auto std = sim.getSTD(); // sqrt(2*delta_T)
|
||||||
//translation
|
// translation
|
||||||
Vector rand = {sim.getNorm(std), sim.getNorm(std)}; //gaussian noise
|
Vector rand = {sim.getNorm(std), sim.getNorm(std)}; // gaussian noise
|
||||||
Vector trans_part = rod2D.getDiff_Sqrt() * rand; //translation vector in Particle System
|
Vector trans_part =
|
||||||
|
rod2D.getDiff_Sqrt() * rand; // translation vector in Particle System
|
||||||
Vector trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
Vector trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
||||||
|
|
||||||
//Force
|
// Force
|
||||||
Vector F_lab = force(rod2D.getPos(), rod2D.getE());
|
Vector F_lab = force(rod2D.getPos(), rod2D.getE());
|
||||||
Vector F_part = rod2D.getE_Base_matrix().inverse() * F_lab;
|
Vector F_part = rod2D.getE_Base_matrix().inverse() * F_lab;
|
||||||
Vector F_trans = rod2D.getDiff_Sqrt() * F_part;
|
Vector F_trans = rod2D.getDiff_Sqrt() * F_part;
|
||||||
F_trans *= sim.getMDeltaT() / kBT;
|
F_trans *= sim.getMDeltaT() / kBT;
|
||||||
|
|
||||||
|
// rotation
|
||||||
//rotation
|
double rot =
|
||||||
double rot = sim.getNorm(std) * rod2D.getDRot_Sqrt();// rotationsmatrix verwenden.
|
sim.getNorm(std) * rod2D.getDRot_Sqrt(); // rotationsmatrix verwenden.
|
||||||
Vector e = rod2D.getE();
|
Vector e = rod2D.getE();
|
||||||
double M_rot = torque(rod2D.getPos(), rod2D.getE()) * rod2D.getDRot() / kBT * sim.getMDeltaT();
|
double M_rot = torque(rod2D.getPos(), rod2D.getE()) * rod2D.getDRot() /
|
||||||
|
kBT * sim.getMDeltaT();
|
||||||
Vector new_e = e + (rot + M_rot) * ortho(e);
|
Vector new_e = e + (rot + M_rot) * ortho(e);
|
||||||
new_e.normalize();
|
new_e.normalize();
|
||||||
//apply
|
// apply
|
||||||
rod2D.setPos(rod2D.getPos() + trans_lab + F_trans);
|
rod2D.setPos(rod2D.getPos() + trans_lab + F_trans);
|
||||||
rod2D.setE(new_e);
|
rod2D.setE(new_e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector Integratoren2d_force::Heun_predictor_pos(const Rod2d &rod2D, Simulation &sim,
|
Vector Integratoren2d_force::Heun_predictor_pos(
|
||||||
|
const Rod2d &rod2D, Simulation &sim,
|
||||||
const std::function<Vector(Vector, Vector)> &force) {
|
const std::function<Vector(Vector, Vector)> &force) {
|
||||||
auto standard_dev = sim.getSTD();
|
auto standard_dev = sim.getSTD();
|
||||||
Vector rand_pred = {sim.getNorm(standard_dev), sim.getNorm(standard_dev)}; //gaussian noise
|
Vector rand_pred = {sim.getNorm(standard_dev),
|
||||||
Vector trans_pred_part = rod2D.getDiff_Sqrt() * rand_pred; //translation vector in Particle System
|
sim.getNorm(standard_dev)}; // gaussian noise
|
||||||
|
Vector trans_pred_part =
|
||||||
|
rod2D.getDiff_Sqrt() *
|
||||||
|
rand_pred; // translation vector in Particle System
|
||||||
Vector trans_pred_lab = rod2D.getE_Base_matrix() * trans_pred_part;
|
Vector trans_pred_lab = rod2D.getE_Base_matrix() * trans_pred_part;
|
||||||
|
|
||||||
Vector F_pred_lab = force(rod2D.getPos(), rod2D.getE());
|
Vector F_pred_lab = force(rod2D.getPos(), rod2D.getE());
|
||||||
@ -74,22 +76,24 @@ Vector Integratoren2d_force::Heun_predictor_pos(const Rod2d &rod2D, Simulation &
|
|||||||
return F_pred_trans + trans_pred_lab;
|
return F_pred_trans + trans_pred_lab;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector Integratoren2d_force::Heun_predictor_rot(const Rod2d &rod2D, Simulation &sim,
|
Vector Integratoren2d_force::Heun_predictor_rot(
|
||||||
|
const Rod2d &rod2D, Simulation &sim,
|
||||||
const std::function<double(Vector, Vector)> &torque) {
|
const std::function<double(Vector, Vector)> &torque) {
|
||||||
auto std = sim.getSTD();
|
auto std = sim.getSTD();
|
||||||
double rot_predict = sim.getNorm(std) * rod2D.getDRot_Sqrt();// rotationsmatrix verwenden.
|
double rot_predict =
|
||||||
|
sim.getNorm(std) * rod2D.getDRot_Sqrt(); // rotationsmatrix verwenden.
|
||||||
Vector e = rod2D.getE();
|
Vector e = rod2D.getE();
|
||||||
double M_predict_rot = torque(rod2D.getPos(), rod2D.getE()) * rod2D.getDRot() / kBT * sim.getMDeltaT();
|
double M_predict_rot = torque(rod2D.getPos(), rod2D.getE()) *
|
||||||
|
rod2D.getDRot() / kBT * sim.getMDeltaT();
|
||||||
Vector e_change_predict = (rot_predict + M_predict_rot) * ortho(e);
|
Vector e_change_predict = (rot_predict + M_predict_rot) * ortho(e);
|
||||||
|
|
||||||
return e_change_predict;
|
return e_change_predict;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Integratoren2d_force::Set2_Heun(
|
||||||
void Integratoren2d_force::Set2_Heun(Rod2d &rod2D, Simulation &sim,
|
Rod2d &rod2D, Simulation &sim,
|
||||||
const std::function<Vector(Vector, Vector)> &force,
|
const std::function<Vector(Vector, Vector)> &force,
|
||||||
const std::function<double(Vector, Vector)> &torque) {
|
const std::function<double(Vector, Vector)> &torque) {
|
||||||
|
|
||||||
Vector delta_pos_predictor = Heun_predictor_pos(rod2D, sim, force);
|
Vector delta_pos_predictor = Heun_predictor_pos(rod2D, sim, force);
|
||||||
Vector pos_predictor = rod2D.getPos() + delta_pos_predictor;
|
Vector pos_predictor = rod2D.getPos() + delta_pos_predictor;
|
||||||
|
|
||||||
@ -97,7 +101,6 @@ void Integratoren2d_force::Set2_Heun(Rod2d &rod2D, Simulation &sim,
|
|||||||
Vector e_predict = rod2D.getE() + delta_e_predictor;
|
Vector e_predict = rod2D.getE() + delta_e_predictor;
|
||||||
e_predict.normalize();
|
e_predict.normalize();
|
||||||
|
|
||||||
|
|
||||||
Rod2d pred_rod = rod2D;
|
Rod2d pred_rod = rod2D;
|
||||||
pred_rod.setPos(pos_predictor);
|
pred_rod.setPos(pos_predictor);
|
||||||
pred_rod.setE(e_predict);
|
pred_rod.setE(e_predict);
|
||||||
@ -105,21 +108,25 @@ void Integratoren2d_force::Set2_Heun(Rod2d &rod2D, Simulation &sim,
|
|||||||
Vector delta_pos_future = Heun_predictor_pos(pred_rod, sim, force);
|
Vector delta_pos_future = Heun_predictor_pos(pred_rod, sim, force);
|
||||||
Vector delta_e_future = Heun_predictor_rot(pred_rod, sim, torque);
|
Vector delta_e_future = Heun_predictor_rot(pred_rod, sim, torque);
|
||||||
|
|
||||||
//integration
|
// integration
|
||||||
Vector pos_integrated = 0.5 * rod2D.getPos() + 0.5 * pos_predictor + 0.5 * delta_pos_future;
|
Vector pos_integrated =
|
||||||
Vector e_integrated = rod2D.getE() + 0.5 * (delta_e_predictor + delta_e_future);
|
0.5 * rod2D.getPos() + 0.5 * pos_predictor + 0.5 * delta_pos_future;
|
||||||
//apply
|
Vector e_integrated =
|
||||||
|
rod2D.getE() + 0.5 * (delta_e_predictor + delta_e_future);
|
||||||
|
// apply
|
||||||
rod2D.setPos(pos_integrated);
|
rod2D.setPos(pos_integrated);
|
||||||
rod2D.setE(e_integrated.normalized());
|
rod2D.setE(e_integrated.normalized());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Integratoren2d_force::Set3_Exact(Rod2d &rod2D, Simulation &sim,
|
void Integratoren2d_force::Set3_Exact(
|
||||||
|
Rod2d &rod2D, Simulation &sim,
|
||||||
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
||||||
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque) {
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque) {
|
||||||
auto std = sim.getSTD(); // sqrt(2*delta_T)
|
auto std = sim.getSTD(); // sqrt(2*delta_T)
|
||||||
//translation
|
// translation
|
||||||
Vector rand = {sim.getNorm(std), sim.getNorm(std)}; //gaussian noise
|
Vector rand = {sim.getNorm(std), sim.getNorm(std)}; // gaussian noise
|
||||||
Vector trans_part = rod2D.getDiff_Sqrt() * rand; //translation vector in Particle System
|
Vector trans_part =
|
||||||
|
rod2D.getDiff_Sqrt() * rand; // translation vector in Particle System
|
||||||
|
|
||||||
Vector F_lab = force(rod2D.getPos(), rod2D.getE());
|
Vector F_lab = force(rod2D.getPos(), rod2D.getE());
|
||||||
Vector F_part = rod2D.getE_Base_matrix().inverse() * F_lab;
|
Vector F_part = rod2D.getE_Base_matrix().inverse() * F_lab;
|
||||||
@ -128,25 +135,30 @@ void Integratoren2d_force::Set3_Exact(Rod2d &rod2D, Simulation &sim,
|
|||||||
F_trans *= sim.getMDeltaT() / kBT;
|
F_trans *= sim.getMDeltaT() / kBT;
|
||||||
Vector trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
Vector trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
||||||
|
|
||||||
//rotation
|
// rotation
|
||||||
double rot = sim.getNorm(std) * rod2D.getDRot_Sqrt();// rotationsmatrix verwenden.
|
double rot =
|
||||||
|
sim.getNorm(std) * rod2D.getDRot_Sqrt(); // rotationsmatrix verwenden.
|
||||||
Vector e = rod2D.getE();
|
Vector e = rod2D.getE();
|
||||||
double M_rot = torque(rod2D.getPos(), rod2D.getE()) * rod2D.getDRot() / kBT * sim.getMDeltaT();
|
double M_rot = torque(rod2D.getPos(), rod2D.getE()) * rod2D.getDRot() /
|
||||||
auto correction = -0.5 * pow(rod2D.getDRot(), 2) / pow(kBT, 2) * sim.getMDeltaT();
|
kBT * sim.getMDeltaT();
|
||||||
|
auto correction =
|
||||||
|
-0.5 * pow(rod2D.getDRot(), 2) / pow(kBT, 2) * sim.getMDeltaT();
|
||||||
Vector new_e = e + (rot + M_rot) * ortho(e) + correction * e;
|
Vector new_e = e + (rot + M_rot) * ortho(e) + correction * e;
|
||||||
new_e.normalize();
|
new_e.normalize();
|
||||||
//apply
|
// apply
|
||||||
rod2D.setPos(rod2D.getPos() + trans_lab + F_trans);
|
rod2D.setPos(rod2D.getPos() + trans_lab + F_trans);
|
||||||
rod2D.setE(new_e);
|
rod2D.setE(new_e);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Integratoren2d_force::Set4_BDAS(Rod2d &rod2D, Simulation &sim,
|
void Integratoren2d_force::Set4_BDAS(
|
||||||
|
Rod2d &rod2D, Simulation &sim,
|
||||||
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
||||||
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> /*torque*/) {
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> /*torque*/) {
|
||||||
auto std = sim.getSTD();
|
auto std = sim.getSTD();
|
||||||
//translation
|
// translation
|
||||||
auto rand = Vector(sim.getNorm(std), sim.getNorm(std));
|
auto rand = Vector(sim.getNorm(std), sim.getNorm(std));
|
||||||
auto trans_part = rod2D.getDiff_Sqrt() * rand; //translation vector in Particle System
|
auto trans_part =
|
||||||
|
rod2D.getDiff_Sqrt() * rand; // translation vector in Particle System
|
||||||
Eigen::Rotation2D rotMat(acos(unitVec.dot(rod2D.getE())));
|
Eigen::Rotation2D rotMat(acos(unitVec.dot(rod2D.getE())));
|
||||||
auto trans_lab = rotMat * trans_part;
|
auto trans_lab = rotMat * trans_part;
|
||||||
|
|
||||||
@ -156,16 +168,14 @@ void Integratoren2d_force::Set4_BDAS(Rod2d &rod2D, Simulation &sim,
|
|||||||
Vector F_trans = rod2D.getDiff_Sqrt() * F_part;
|
Vector F_trans = rod2D.getDiff_Sqrt() * F_part;
|
||||||
F_trans *= sim.getMDeltaT() / kBT;
|
F_trans *= sim.getMDeltaT() / kBT;
|
||||||
|
|
||||||
|
auto rot =
|
||||||
auto rot = Eigen::Rotation2D<double>(sim.getNorm(std) * rod2D.getDRot_Sqrt());
|
Eigen::Rotation2D<double>(sim.getNorm(std) * rod2D.getDRot_Sqrt());
|
||||||
Eigen::Rotation2Dd rotation(rot);
|
Eigen::Rotation2Dd rotation(rot);
|
||||||
auto e_new = (rotation.toRotationMatrix() * rod2D.getE()).normalized();
|
auto e_new = (rotation.toRotationMatrix() * rod2D.getE()).normalized();
|
||||||
|
|
||||||
// Normalisation should not be necessary if a proper angular representation is used.
|
// Normalisation should not be necessary if a proper angular representation
|
||||||
// But with vector e it is done in case of numerical errors
|
// is used. But with vector e it is done in case of numerical errors
|
||||||
|
|
||||||
rod2D.setPos(rod2D.getPos() + trans_lab);
|
rod2D.setPos(rod2D.getPos() + trans_lab);
|
||||||
rod2D.setE(e_new);
|
rod2D.setE(e_new);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,21 +8,26 @@
|
|||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
|
|
||||||
class Integratoren2d_force {
|
class Integratoren2d_force {
|
||||||
public:
|
public:
|
||||||
static void Set1_Euler(Rod2d &rod2D, Simulation &sim,
|
static void Set1_Euler(
|
||||||
const std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> &force,
|
Rod2d &rod2D, Simulation &sim,
|
||||||
|
const std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)>
|
||||||
|
&force,
|
||||||
const std::function<double(Eigen::Vector2d, Eigen::Vector2d)> &torque);
|
const std::function<double(Eigen::Vector2d, Eigen::Vector2d)> &torque);
|
||||||
|
|
||||||
|
static void Set2_Heun(
|
||||||
static void Set2_Heun(Rod2d &rod2D, Simulation &sim,
|
Rod2d &rod2D, Simulation &sim,
|
||||||
const std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> &force,
|
const std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)>
|
||||||
|
&force,
|
||||||
const std::function<double(Eigen::Vector2d, Eigen::Vector2d)> &torque);
|
const std::function<double(Eigen::Vector2d, Eigen::Vector2d)> &torque);
|
||||||
|
|
||||||
static void Set3_Exact(Rod2d &rod2D, Simulation &sim,
|
static void Set3_Exact(
|
||||||
|
Rod2d &rod2D, Simulation &sim,
|
||||||
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
||||||
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque);
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque);
|
||||||
|
|
||||||
static void Set4_BDAS(Rod2d &rod2D, Simulation &sim,
|
static void Set4_BDAS(
|
||||||
|
Rod2d &rod2D, Simulation &sim,
|
||||||
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)> force,
|
||||||
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque);
|
std::function<double(Eigen::Vector2d, Eigen::Vector2d)> torque);
|
||||||
|
|
||||||
@ -32,17 +37,17 @@ public:
|
|||||||
|
|
||||||
static void Set0_deterministic(Rod2d &rod2D, Simulation &sim);
|
static void Set0_deterministic(Rod2d &rod2D, Simulation &sim);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Eigen::Vector2d ortho(Eigen::Vector2d e);
|
static Eigen::Vector2d ortho(Eigen::Vector2d e);
|
||||||
|
|
||||||
static Eigen::Matrix2d MatTraf(Eigen::Matrix<double, 2, 1> e);
|
static Eigen::Matrix2d MatTraf(Eigen::Matrix<double, 2, 1> e);
|
||||||
|
|
||||||
static Eigen::Vector2d Heun_predictor_pos(const Rod2d &rod2D, Simulation &sim,
|
static Eigen::Vector2d Heun_predictor_pos(
|
||||||
const std::function<Eigen::Vector2d(Eigen::Vector2d,
|
const Rod2d &rod2D, Simulation &sim,
|
||||||
Eigen::Vector2d)> &force);
|
const std::function<Eigen::Vector2d(Eigen::Vector2d, Eigen::Vector2d)>
|
||||||
|
&force);
|
||||||
|
|
||||||
static Eigen::Vector2d
|
static Eigen::Vector2d Heun_predictor_rot(
|
||||||
Heun_predictor_rot(const Rod2d &rod2D, Simulation &sim,
|
const Rod2d &rod2D, Simulation &sim,
|
||||||
const std::function<double(Eigen::Vector2d, Eigen::Vector2d)> &torque);
|
const std::function<double(Eigen::Vector2d, Eigen::Vector2d)> &torque);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -8,7 +8,8 @@ Eigen::Vector2d Integratoren2d_forceless::ortho(Eigen::Vector2d e) {
|
|||||||
return Eigen::Vector2d{-e[1], e[0]};
|
return Eigen::Vector2d{-e[1], e[0]};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Integratoren2d_forceless::Set0_deterministic(Rod2d &rod2D, Simulation & /*sim*/) {
|
void Integratoren2d_forceless::Set0_deterministic(Rod2d &rod2D,
|
||||||
|
Simulation & /*sim*/) {
|
||||||
auto trans_lab = Eigen::Vector2d({0, 0.01});
|
auto trans_lab = Eigen::Vector2d({0, 0.01});
|
||||||
rod2D.setPos(rod2D.getPos() + trans_lab);
|
rod2D.setPos(rod2D.getPos() + trans_lab);
|
||||||
Eigen::Rotation2D<double> rot(0.1);
|
Eigen::Rotation2D<double> rot(0.1);
|
||||||
@ -17,25 +18,28 @@ void Integratoren2d_forceless::Set0_deterministic(Rod2d &rod2D, Simulation & /*s
|
|||||||
|
|
||||||
void Integratoren2d_forceless::Set1_Euler(Rod2d &rod2D, Simulation &sim) {
|
void Integratoren2d_forceless::Set1_Euler(Rod2d &rod2D, Simulation &sim) {
|
||||||
auto std = sim.getSTD(); // sqrt(2*delta_T)
|
auto std = sim.getSTD(); // sqrt(2*delta_T)
|
||||||
//translation
|
// translation
|
||||||
Eigen::Vector2d rand = {sim.getNorm(std), sim.getNorm(std)}; //gaussian noise
|
Eigen::Vector2d rand = {sim.getNorm(std),
|
||||||
Eigen::Vector2d trans_part = rod2D.getDiff_Sqrt() * rand; //translation vector in Particle System
|
sim.getNorm(std)}; // gaussian noise
|
||||||
|
Eigen::Vector2d trans_part =
|
||||||
|
rod2D.getDiff_Sqrt() * rand; // translation vector in Particle System
|
||||||
Eigen::Vector2d trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
Eigen::Vector2d trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
||||||
/* TODO
|
/* TODO
|
||||||
|
|
||||||
Statt Zeile 22 und 23 kannst du trans_lab = paralleler_matrix_eintrag * e plus senkrechter_matrix_eintrag * ortho(e);
|
Statt Zeile 22 und 23 kannst du trans_lab = paralleler_matrix_eintrag * e
|
||||||
|
plus senkrechter_matrix_eintrag * ortho(e);
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//rotation
|
// rotation
|
||||||
double rot = sim.getNorm(std) * rod2D.getDRot_Sqrt();// rotationsmatrix verwenden.
|
double rot =
|
||||||
|
sim.getNorm(std) * rod2D.getDRot_Sqrt(); // rotationsmatrix verwenden.
|
||||||
Eigen::Vector2d e = rod2D.getE();
|
Eigen::Vector2d e = rod2D.getE();
|
||||||
Eigen::Vector2d new_e = e + rot * ortho(e);
|
Eigen::Vector2d new_e = e + rot * ortho(e);
|
||||||
new_e.normalize();
|
new_e.normalize();
|
||||||
//apply
|
// apply
|
||||||
rod2D.setPos(rod2D.getPos() + trans_lab);
|
rod2D.setPos(rod2D.getPos() + trans_lab);
|
||||||
rod2D.setE(new_e);
|
rod2D.setE(new_e);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Integratoren2d_forceless::Set2_Heun(Rod2d &rod2D, Simulation &sim) {
|
void Integratoren2d_forceless::Set2_Heun(Rod2d &rod2D, Simulation &sim) {
|
||||||
@ -43,31 +47,34 @@ void Integratoren2d_forceless::Set2_Heun(Rod2d &rod2D, Simulation &sim) {
|
|||||||
auto std = sim.getSTD();
|
auto std = sim.getSTD();
|
||||||
|
|
||||||
Eigen::Vector2d rand = Eigen::Vector2d(sim.getNorm(std), sim.getNorm(std));
|
Eigen::Vector2d rand = Eigen::Vector2d(sim.getNorm(std), sim.getNorm(std));
|
||||||
Eigen::Vector2d trans_part = rod2D.getDiff_Sqrt() * rand; //translation vector in Particle System
|
Eigen::Vector2d trans_part =
|
||||||
|
rod2D.getDiff_Sqrt() * rand; // translation vector in Particle System
|
||||||
Eigen::Vector2d trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
Eigen::Vector2d trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
||||||
Eigen::Vector2d pos_predictor = rod2D.getPos() + trans_lab;
|
Eigen::Vector2d pos_predictor = rod2D.getPos() + trans_lab;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
TODO
|
TODO
|
||||||
|
|
||||||
Siehe Set_1: Hier auch über e und orth(e)
|
Siehe Set_1: Hier auch über e und orth(e)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//rotation
|
// rotation
|
||||||
double rot_predict = sim.getNorm(std) * rod2D.getDRot_Sqrt();// rotationsmatrix verwenden.
|
double rot_predict =
|
||||||
|
sim.getNorm(std) * rod2D.getDRot_Sqrt(); // rotationsmatrix verwenden.
|
||||||
Eigen::Vector2d e = rod2D.getE();
|
Eigen::Vector2d e = rod2D.getE();
|
||||||
Eigen::Vector2d delta_e_predict = rot_predict * ortho(e);
|
Eigen::Vector2d delta_e_predict = rot_predict * ortho(e);
|
||||||
Eigen::Vector2d e_predict = (e + delta_e_predict).normalized();
|
Eigen::Vector2d e_predict = (e + delta_e_predict).normalized();
|
||||||
|
|
||||||
|
|
||||||
double rot = sim.getNorm(std) * rod2D.getDRot_Sqrt();
|
double rot = sim.getNorm(std) * rod2D.getDRot_Sqrt();
|
||||||
Eigen::Vector2d e_integrated = e + 0.5 * (rot * ortho(e) + rot * ortho(e_predict));
|
Eigen::Vector2d e_integrated =
|
||||||
//TODO pos integration with future system ???
|
e + 0.5 * (rot * ortho(e) + rot * ortho(e_predict));
|
||||||
// Eigen::Vector2d pos_integrated = rod2D.getPos() + 0.5 * (rot * ortho(e) + rot * ortho(e_predict));
|
// TODO pos integration with future system ???
|
||||||
|
// Eigen::Vector2d pos_integrated = rod2D.getPos() + 0.5 * (rot * ortho(e)
|
||||||
|
// + rot * ortho(e_predict));
|
||||||
|
|
||||||
//apply
|
// apply
|
||||||
rod2D.setPos(pos_predictor);
|
rod2D.setPos(pos_predictor);
|
||||||
rod2D.setE(e_integrated.normalized());
|
rod2D.setE(e_integrated.normalized());
|
||||||
}
|
}
|
||||||
@ -76,9 +83,11 @@ constexpr double kBT = 1.0;
|
|||||||
|
|
||||||
void Integratoren2d_forceless::Set3_Exact(Rod2d &rod2D, Simulation &sim) {
|
void Integratoren2d_forceless::Set3_Exact(Rod2d &rod2D, Simulation &sim) {
|
||||||
auto std = sim.getSTD();
|
auto std = sim.getSTD();
|
||||||
//translation
|
// translation
|
||||||
Eigen::Vector2d rand = {sim.getNorm(std), sim.getNorm(std)}; //gaussian noise
|
Eigen::Vector2d rand = {sim.getNorm(std),
|
||||||
Eigen::Vector2d trans_part = rod2D.getDiff_Sqrt() * rand; //translation vector in Particle System
|
sim.getNorm(std)}; // gaussian noise
|
||||||
|
Eigen::Vector2d trans_part =
|
||||||
|
rod2D.getDiff_Sqrt() * rand; // translation vector in Particle System
|
||||||
Eigen::Vector2d trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
Eigen::Vector2d trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -87,10 +96,11 @@ void Integratoren2d_forceless::Set3_Exact(Rod2d &rod2D, Simulation &sim) {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//rotation
|
// rotation
|
||||||
double rot = sim.getNorm(std) * rod2D.getDRot_Sqrt();
|
double rot = sim.getNorm(std) * rod2D.getDRot_Sqrt();
|
||||||
Eigen::Vector2d e = rod2D.getE();
|
Eigen::Vector2d e = rod2D.getE();
|
||||||
auto correction = -0.5 * pow(rod2D.getDRot(), 2) / pow(kBT, 2) * sim.getMDeltaT();
|
auto correction =
|
||||||
|
-0.5 * pow(rod2D.getDRot(), 2) / pow(kBT, 2) * sim.getMDeltaT();
|
||||||
|
|
||||||
Eigen::Vector2d delta_e = correction * e + rot * ortho(e);
|
Eigen::Vector2d delta_e = correction * e + rot * ortho(e);
|
||||||
|
|
||||||
@ -98,20 +108,21 @@ void Integratoren2d_forceless::Set3_Exact(Rod2d &rod2D, Simulation &sim) {
|
|||||||
TODO Warum hier kBT definiert?
|
TODO Warum hier kBT definiert?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//apply
|
// apply
|
||||||
rod2D.setPos(rod2D.getPos() + trans_lab);
|
rod2D.setPos(rod2D.getPos() + trans_lab);
|
||||||
rod2D.setE((e + delta_e).normalized());
|
rod2D.setE((e + delta_e).normalized());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Eigen::Vector2d Integratoren2d_forceless::unitVec = {1, 0};
|
const Eigen::Vector2d Integratoren2d_forceless::unitVec = {1, 0};
|
||||||
|
|
||||||
//this is a slow implementation to keep the same data structure for performance analysis this must be altered
|
// this is a slow implementation to keep the same data structure for performance
|
||||||
|
// analysis this must be altered
|
||||||
void Integratoren2d_forceless::Set4_BDAS(Rod2d &rod2D, Simulation &sim) {
|
void Integratoren2d_forceless::Set4_BDAS(Rod2d &rod2D, Simulation &sim) {
|
||||||
auto std = sim.getSTD();
|
auto std = sim.getSTD();
|
||||||
//translation
|
// translation
|
||||||
auto rand = Eigen::Vector2d(sim.getNorm(std), sim.getNorm(std));
|
auto rand = Eigen::Vector2d(sim.getNorm(std), sim.getNorm(std));
|
||||||
auto trans_part = rod2D.getDiff_Sqrt() * rand; //translation vector in Particle System
|
auto trans_part =
|
||||||
|
rod2D.getDiff_Sqrt() * rand; // translation vector in Particle System
|
||||||
Eigen::Rotation2D rotMat(acos(unitVec.dot(rod2D.getE())));
|
Eigen::Rotation2D rotMat(acos(unitVec.dot(rod2D.getE())));
|
||||||
auto trans_lab = rotMat * trans_part;
|
auto trans_lab = rotMat * trans_part;
|
||||||
|
|
||||||
@ -120,17 +131,18 @@ void Integratoren2d_forceless::Set4_BDAS(Rod2d &rod2D, Simulation &sim) {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
auto rot = Eigen::Rotation2D<double>(sim.getNorm(std) * rod2D.getDRot_Sqrt());
|
auto rot =
|
||||||
|
Eigen::Rotation2D<double>(sim.getNorm(std) * rod2D.getDRot_Sqrt());
|
||||||
Eigen::Rotation2Dd rotation(rot);
|
Eigen::Rotation2Dd rotation(rot);
|
||||||
auto e_new = (rotation.toRotationMatrix() * rod2D.getE()).normalized();
|
auto e_new = (rotation.toRotationMatrix() * rod2D.getE()).normalized();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO Warum Normierung? Ist der Fehler so gros? Wie siehts mit einer Winkelvariable aus,
|
TODO Warum Normierung? Ist der Fehler so gros? Wie siehts mit einer
|
||||||
dann musst du den Winkel nicht jedesmal berechnen?
|
Winkelvariable aus, dann musst du den Winkel nicht jedesmal berechnen?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Normalisation should not be necessary if a proper angular representation is used.
|
// Normalisation should not be necessary if a proper angular representation
|
||||||
// But with vector e it is done in case of numerical errors
|
// is used. But with vector e it is done in case of numerical errors
|
||||||
|
|
||||||
rod2D.setPos(rod2D.getPos() + trans_lab);
|
rod2D.setPos(rod2D.getPos() + trans_lab);
|
||||||
rod2D.setE(e_new);
|
rod2D.setE(e_new);
|
||||||
@ -138,27 +150,28 @@ void Integratoren2d_forceless::Set4_BDAS(Rod2d &rod2D, Simulation &sim) {
|
|||||||
|
|
||||||
Eigen::Matrix2d Integratoren2d_forceless::e_2_matrix(Eigen::Vector2d m_e) {
|
Eigen::Matrix2d Integratoren2d_forceless::e_2_matrix(Eigen::Vector2d m_e) {
|
||||||
Eigen::Matrix2d mat;
|
Eigen::Matrix2d mat;
|
||||||
mat << m_e[0], -m_e[1],
|
mat << m_e[0], -m_e[1], m_e[1], m_e[0];
|
||||||
m_e[1], m_e[0];
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Integratoren2d_forceless::Set5_MBD(Rod2d &/*rod2D*/, Simulation &/*sim*/) {
|
void Integratoren2d_forceless::Set5_MBD(Rod2d & /*rod2D*/,
|
||||||
|
Simulation & /*sim*/) {
|
||||||
/*
|
/*
|
||||||
auto std = sim.getSTD();
|
auto std = sim.getSTD();
|
||||||
|
|
||||||
auto rand = Eigen::Vector2d(sim.getNorm(std), sim.getNorm(std));
|
auto rand = Eigen::Vector2d(sim.getNorm(std), sim.getNorm(std));
|
||||||
auto trans_part = rod2D.getDiff_Sqrt() * rand; //translation vector in Particle System
|
auto trans_part = rod2D.getDiff_Sqrt() * rand; //translation vector in
|
||||||
auto trans_lab = rod2D.getE_Base_matrix() * trans_part;
|
Particle System auto trans_lab = rod2D.getE_Base_matrix() * trans_part; auto
|
||||||
auto pos_predictor = rod2D.getPos() + trans_lab;
|
pos_predictor = rod2D.getPos() + trans_lab;
|
||||||
|
|
||||||
//rotation
|
//rotation
|
||||||
auto rot_predict = Eigen::Rotation2D<double>(sim.getNorm(std) * rod2D.getDRot_Sqrt());// rotationsmatrix verwenden.
|
auto rot_predict = Eigen::Rotation2D<double>(sim.getNorm(std) *
|
||||||
auto e = rod2D.getE();
|
rod2D.getDRot_Sqrt());// rotationsmatrix verwenden. auto e = rod2D.getE();
|
||||||
auto delta_e_predict = rot_predict * ortho(e);
|
auto delta_e_predict = rot_predict * ortho(e); auto e_predict = (e +
|
||||||
auto e_predict = (e + delta_e_predict).normalized();
|
delta_e_predict).normalized();
|
||||||
|
|
||||||
auto std_combined = rod2D.getDiff() + rod2D.getE_Base_matrix() * rod2D.getDiff(); //old + new diff
|
auto std_combined = rod2D.getDiff() + rod2D.getE_Base_matrix() *
|
||||||
|
rod2D.getDiff(); //old + new diff
|
||||||
|
|
||||||
auto rot = Eigen::Rotation2D<double>(sim.getNorm(std) * rod2D.getDRot_Sqrt());
|
auto rot = Eigen::Rotation2D<double>(sim.getNorm(std) * rod2D.getDRot_Sqrt());
|
||||||
auto e_integrated = e + 0.5 * (rot * ortho(e) + rot * ortho(e_predict));
|
auto e_integrated = e + 0.5 * (rot * ortho(e) + rot * ortho(e_predict));
|
||||||
@ -167,5 +180,3 @@ void Integratoren2d_forceless::Set5_MBD(Rod2d &/*rod2D*/, Simulation &/*sim*/) {
|
|||||||
rod2D.setE(e_integrated.normalized());
|
rod2D.setE(e_integrated.normalized());
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,14 +2,13 @@
|
|||||||
// Created by jholder on 21.10.21.
|
// Created by jholder on 21.10.21.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef MYPROJECT_INTEGRATOREN2D_FORCELESS_H
|
#pragma once
|
||||||
#define MYPROJECT_INTEGRATOREN2D_FORCELESS_H
|
|
||||||
|
|
||||||
#include "Rod2d.hpp"
|
#include "Rod2d.hpp"
|
||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
|
|
||||||
class Integratoren2d_forceless {
|
class Integratoren2d_forceless {
|
||||||
public:
|
public:
|
||||||
static void Set1_Euler(Rod2d &rod2D, Simulation &sim);
|
static void Set1_Euler(Rod2d &rod2D, Simulation &sim);
|
||||||
|
|
||||||
static void Set2_Heun(Rod2d &rod2D, Simulation &sim);
|
static void Set2_Heun(Rod2d &rod2D, Simulation &sim);
|
||||||
@ -26,9 +25,6 @@ public:
|
|||||||
|
|
||||||
static void Set0_deterministic(Rod2d &rod2D, Simulation &sim);
|
static void Set0_deterministic(Rod2d &rod2D, Simulation &sim);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Eigen::Vector2d ortho(Eigen::Vector2d e);
|
static Eigen::Vector2d ortho(Eigen::Vector2d e);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //MYPROJECT_INTEGRATOREN2D_FORCELESS_H
|
|
||||||
|
@ -1,33 +1,21 @@
|
|||||||
#include "LiveAgg.hpp"
|
#include "LiveAgg.hpp"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
LiveAgg::LiveAgg() : num_of_data(0), mean(0.0), S(0.0)
|
LiveAgg::LiveAgg() : num_of_data(0), mean(0.0), S(0.0) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
double LiveAgg::getSD() const noexcept
|
double LiveAgg::getSD() const noexcept { return S / (num_of_data - 1); }
|
||||||
{
|
|
||||||
return S / (num_of_data - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
double LiveAgg::getSEM() const noexcept
|
double LiveAgg::getSEM() const noexcept {
|
||||||
{
|
|
||||||
return S / (num_of_data - 1) / std::sqrt(num_of_data);
|
return S / (num_of_data - 1) / std::sqrt(num_of_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
double LiveAgg::getMean() const noexcept
|
double LiveAgg::getMean() const noexcept { return mean; }
|
||||||
{
|
|
||||||
return mean;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LiveAgg::feed(double value) noexcept
|
void LiveAgg::feed(double value) noexcept {
|
||||||
{
|
|
||||||
num_of_data += 1;
|
num_of_data += 1;
|
||||||
auto delta = value - mean;
|
auto delta = value - mean;
|
||||||
mean += delta / num_of_data;
|
mean += delta / num_of_data;
|
||||||
auto delta2 = value - mean;
|
auto delta2 = value - mean;
|
||||||
S += delta * delta2;
|
S += delta * delta2;
|
||||||
}
|
}
|
||||||
int LiveAgg::getNumPoints() const noexcept
|
int LiveAgg::getNumPoints() const noexcept { return num_of_data; }
|
||||||
{
|
|
||||||
return num_of_data;
|
|
||||||
}
|
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
#ifndef LIVEAGG_H
|
#pragma once
|
||||||
#define LIVEAGG_H
|
class LiveAgg {
|
||||||
|
|
||||||
|
|
||||||
class LiveAgg
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
LiveAgg();
|
LiveAgg();
|
||||||
[[nodiscard]] double getSD() const noexcept;
|
[[nodiscard]] double getSD() const noexcept;
|
||||||
@ -11,10 +7,9 @@ class LiveAgg
|
|||||||
[[nodiscard]] double getMean() const noexcept;
|
[[nodiscard]] double getMean() const noexcept;
|
||||||
[[nodiscard]] int getNumPoints() const noexcept;
|
[[nodiscard]] int getNumPoints() const noexcept;
|
||||||
void feed(double value) noexcept;
|
void feed(double value) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int num_of_data;
|
int num_of_data;
|
||||||
double mean;
|
double mean;
|
||||||
double S;
|
double S;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // LIVEAGG_H
|
|
||||||
|
@ -1,28 +1,30 @@
|
|||||||
#include "Rod2d.hpp"
|
#include "Rod2d.hpp"
|
||||||
|
|
||||||
#include "Eigen/Dense"
|
#include "Eigen/Dense"
|
||||||
|
|
||||||
constexpr double M_Pl = 3.141592653589793238462643383279502884; /* pi */
|
constexpr double M_Pl = 3.141592653589793238462643383279502884; /* pi */
|
||||||
|
|
||||||
void sqrt(Eigen::Matrix2d &mat){
|
void sqrt(Eigen::Matrix2d &mat) {
|
||||||
const auto size = static_cast<size_t>(mat.size());
|
const auto size = static_cast<size_t>(mat.size());
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
mat.data()[i] = sqrt(mat.data()[i]);
|
mat.data()[i] = sqrt(mat.data()[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Rod2d::Rod2d(double L) : m_pos({0, 0}), m_e({1, 0}) {
|
Rod2d::Rod2d(double L) : m_pos({0, 0}), m_e({1, 0}) {
|
||||||
assert(L>=1.0);
|
assert(L >= 1.0);
|
||||||
if (L == 1.0) {
|
if (L == 1.0) {
|
||||||
m_D_rot = 3.0;
|
m_D_rot = 3.0;
|
||||||
m_Diff << 1, 0,
|
m_Diff << 1, 0, 0, 1;
|
||||||
0, 1;
|
|
||||||
} else {
|
} else {
|
||||||
const double D0 = 3.0 * M_Pl / L;
|
const double D0 = 3.0 * M_Pl / L;
|
||||||
const double p = L;
|
const double p = L;
|
||||||
auto D_para = D0 / (M_Pl * 2.0) * (log(p) - 0.207 + 0.980 / p - 0.133 / (p * p));
|
auto D_para =
|
||||||
auto D_ortho = D0 / (M_Pl * 2.0) * (log(p) + 0.839 + 0.185 / p + 0.233 / (p * p));
|
D0 / (M_Pl * 2.0) * (log(p) - 0.207 + 0.980 / p - 0.133 / (p * p));
|
||||||
m_D_rot = 3 * D0 / (M_Pl * L * L) * (log(p) - 0.662 + 0.917 / p - 0.050 / (p * p));
|
auto D_ortho =
|
||||||
m_Diff << D_para, 0,
|
D0 / (M_Pl * 2.0) * (log(p) + 0.839 + 0.185 / p + 0.233 / (p * p));
|
||||||
0, D_ortho;
|
m_D_rot = 3 * D0 / (M_Pl * L * L) *
|
||||||
|
(log(p) - 0.662 + 0.917 / p - 0.050 / (p * p));
|
||||||
|
m_Diff << D_para, 0, 0, D_ortho;
|
||||||
}
|
}
|
||||||
m_Diff_sqrt = m_Diff;
|
m_Diff_sqrt = m_Diff;
|
||||||
m_D_rot_sqrt = sqrt(m_D_rot);
|
m_D_rot_sqrt = sqrt(m_D_rot);
|
||||||
@ -34,43 +36,24 @@ void Rod2d::reset() {
|
|||||||
m_e = {1, 0};
|
m_e = {1, 0};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Rod2d::setPos(const Eigen::Vector2d &Pos) {
|
void Rod2d::setPos(const Eigen::Vector2d &Pos) { m_pos = Pos; }
|
||||||
m_pos = Pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Rod2d::getDRot() const {
|
double Rod2d::getDRot() const { return m_D_rot; }
|
||||||
return m_D_rot;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Eigen::Vector2d &Rod2d::getPos() const {
|
const Eigen::Vector2d &Rod2d::getPos() const { return m_pos; }
|
||||||
return m_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Eigen::Matrix2d &Rod2d::getDiff() const {
|
const Eigen::Matrix2d &Rod2d::getDiff() const { return m_Diff; }
|
||||||
return m_Diff;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Eigen::Matrix2d &Rod2d::getDiff_Sqrt() const {
|
const Eigen::Matrix2d &Rod2d::getDiff_Sqrt() const { return m_Diff_sqrt; }
|
||||||
return m_Diff_sqrt;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Rod2d::getDRot_Sqrt() const {
|
double Rod2d::getDRot_Sqrt() const { return m_D_rot_sqrt; }
|
||||||
return m_D_rot_sqrt;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Eigen::Vector2d &Rod2d::getE() const {
|
const Eigen::Vector2d &Rod2d::getE() const { return m_e; }
|
||||||
return m_e;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Rod2d::setE(const Eigen::Vector2d &mE) {
|
void Rod2d::setE(const Eigen::Vector2d &mE) { m_e = mE; }
|
||||||
m_e = mE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Eigen::Matrix2d Rod2d::getE_Base_matrix() const {
|
Eigen::Matrix2d Rod2d::getE_Base_matrix() const {
|
||||||
Eigen::Matrix2d mat;
|
Eigen::Matrix2d mat;
|
||||||
mat << m_e[0], -m_e[1],
|
mat << m_e[0], -m_e[1], m_e[1], m_e[0];
|
||||||
m_e[1], m_e[0];
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <Eigen/Geometry>
|
|
||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
class Rod2d
|
#include <Eigen/Geometry>
|
||||||
{
|
class Rod2d {
|
||||||
public:
|
public:
|
||||||
explicit Rod2d(double L);
|
explicit Rod2d(double L);
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ public:
|
|||||||
|
|
||||||
Eigen::Matrix2d getE_Base_matrix() const;
|
Eigen::Matrix2d getE_Base_matrix() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Eigen::Matrix2d m_Diff;
|
Eigen::Matrix2d m_Diff;
|
||||||
Eigen::Matrix2d m_Diff_sqrt;
|
Eigen::Matrix2d m_Diff_sqrt;
|
||||||
double m_D_rot;
|
double m_D_rot;
|
||||||
@ -33,5 +32,3 @@ private:
|
|||||||
Eigen::Vector2d m_pos; // position
|
Eigen::Vector2d m_pos; // position
|
||||||
Eigen::Vector2d m_e;
|
Eigen::Vector2d m_e;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,17 +5,15 @@
|
|||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
|
|
||||||
double Simulation::getNorm(double t_norm) {
|
double Simulation::getNorm(double t_norm) {
|
||||||
return t_norm*m_norm(m_generator);
|
return t_norm * m_norm(m_generator);
|
||||||
}
|
}
|
||||||
|
|
||||||
Simulation::Simulation(double t_delta_T, size_t seed): m_delta_T(t_delta_T),m_std(std::sqrt(t_delta_T*2.0)), m_generator(seed), m_norm(0, 1.0) {
|
Simulation::Simulation(double t_delta_T, size_t seed)
|
||||||
|
: m_delta_T(t_delta_T),
|
||||||
|
m_std(std::sqrt(t_delta_T * 2.0)),
|
||||||
|
m_generator(seed),
|
||||||
|
m_norm(0, 1.0) {}
|
||||||
|
|
||||||
}
|
double Simulation::getMDeltaT() const { return m_delta_T; }
|
||||||
|
|
||||||
double Simulation::getMDeltaT() const {
|
double Simulation::getSTD() const { return m_std; }
|
||||||
return m_delta_T;
|
|
||||||
}
|
|
||||||
|
|
||||||
double Simulation::getSTD() const {
|
|
||||||
return m_std;
|
|
||||||
}
|
|
||||||
|
@ -2,25 +2,22 @@
|
|||||||
// Created by jholder on 21.10.21.
|
// Created by jholder on 21.10.21.
|
||||||
//
|
//
|
||||||
|
|
||||||
#ifndef MYPROJECT_SIMULATION_H
|
#pragma once
|
||||||
#define MYPROJECT_SIMULATION_H
|
|
||||||
|
|
||||||
|
|
||||||
#include <random>
|
#include <random>
|
||||||
|
|
||||||
class Simulation {
|
class Simulation {
|
||||||
public:
|
public:
|
||||||
explicit Simulation(double t_delta_T, size_t seed);
|
explicit Simulation(double t_delta_T, size_t seed);
|
||||||
double getNorm(double t_norm);
|
double getNorm(double t_norm);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
double m_delta_T;
|
double m_delta_T;
|
||||||
double m_std;
|
double m_std;
|
||||||
std::mt19937_64 m_generator;
|
std::mt19937_64 m_generator;
|
||||||
std::normal_distribution<double> m_norm;
|
std::normal_distribution<double> m_norm;
|
||||||
public:
|
|
||||||
|
public:
|
||||||
[[nodiscard]] double getMDeltaT() const;
|
[[nodiscard]] double getMDeltaT() const;
|
||||||
[[nodiscard]] double getSTD() const;
|
[[nodiscard]] double getSTD() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif //MYPROJECT_SIMULATION_H
|
|
||||||
|
66
src/main.cpp
66
src/main.cpp
@ -3,49 +3,73 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "Calculation.h"
|
#include "Calculation.h"
|
||||||
#include "Integratoren2d_forceless.h"
|
|
||||||
#include "Integratoren2d_force.h"
|
#include "Integratoren2d_force.h"
|
||||||
|
#include "Integratoren2d_forceless.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
constexpr int numStep = 1000;
|
constexpr int numStep = 1000000;
|
||||||
auto zero_Force = [](const Eigen::Vector2d & /*pos*/,
|
constexpr double k = 0.01;
|
||||||
const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d { return {0.0, 0.0}; };
|
[[maybe_unused]] auto harmonic_Force =
|
||||||
|
[](const Eigen::Vector2d &pos,
|
||||||
|
const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d {
|
||||||
|
return -k * pos;
|
||||||
|
};
|
||||||
|
[[maybe_unused]] 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*/,
|
auto zero_Torque = [](const Eigen::Vector2d & /*pos*/,
|
||||||
const Eigen::Vector2d & /*torque*/) -> double { return 0.0; };
|
const Eigen::Vector2d & /*torque*/) -> double {
|
||||||
|
return 0.0;
|
||||||
|
};
|
||||||
/* auto euler_Zero = [&](Rod2d &rod, Simulation &sim) {
|
/* auto euler_Zero = [&](Rod2d &rod, Simulation &sim) {
|
||||||
return Integratoren2d_force::Set1_Euler(rod, sim, zero_Force, zero_Torque);
|
return Integratoren2d_force::Set1_Euler(rod, sim, zero_Force,
|
||||||
|
zero_Torque);
|
||||||
};*/
|
};*/
|
||||||
auto heun_Zero = [&](Rod2d &rod, Simulation &sim) {
|
auto heun_Zero = [&](Rod2d &rod, Simulation &sim) {
|
||||||
return Integratoren2d_force::Set2_Heun(rod, sim, zero_Force, zero_Torque);
|
return Integratoren2d_force::Set1_Euler(rod, sim, harmonic_Force,
|
||||||
|
zero_Torque);
|
||||||
};
|
};
|
||||||
/*auto exact_Zero = [&](Rod2d &rod, Simulation &sim) {
|
/*auto exact_Zero = [&](Rod2d &rod, Simulation &sim) {
|
||||||
return Integratoren2d_force::Set3_Exact(rod, sim, zero_Force, zero_Torque);
|
return Integratoren2d_force::Set3_Exact(rod, sim, zero_Force,
|
||||||
};*//*
|
zero_Torque);
|
||||||
|
};*/
|
||||||
|
/*
|
||||||
auto bdas_Zero = [&](Rod2d &rod, Simulation &sim) {
|
auto bdas_Zero = [&](Rod2d &rod, Simulation &sim) {
|
||||||
return Integratoren2d_force::Set4_BDAS(rod, sim, zero_Force, zero_Torque);
|
return Integratoren2d_force::Set4_BDAS(rod, sim, zero_Force, zero_Torque);
|
||||||
};*/
|
};*/
|
||||||
Calculation euler(heun_Zero, {{Compute::Type::msd, 1},
|
Calculation euler(heun_Zero,
|
||||||
|
{{Compute::Type::msd, 1},
|
||||||
{Compute::Type::msd, 2},
|
{Compute::Type::msd, 2},
|
||||||
{Compute::Type::msd, 4},
|
{Compute::Type::msd, 4},
|
||||||
{Compute::Type::msd, 8},
|
{Compute::Type::msd, 8},
|
||||||
{Compute::Type::msd, 16},
|
{Compute::Type::msd, 16},
|
||||||
|
{Compute::Type::msd, 32},
|
||||||
|
{Compute::Type::msd, 64},
|
||||||
|
{Compute::Type::msd, 128},
|
||||||
|
{Compute::Type::msd, 256},
|
||||||
|
{Compute::Type::msd, 512},
|
||||||
|
{Compute::Type::msd, 1024},
|
||||||
{Compute::Type::oaf, 1},
|
{Compute::Type::oaf, 1},
|
||||||
{Compute::Type::oaf, 2},
|
{Compute::Type::oaf, 2},
|
||||||
{Compute::Type::oaf, 4},
|
{Compute::Type::oaf, 4},
|
||||||
{Compute::Type::oaf, 8},
|
{Compute::Type::oaf, 8},
|
||||||
{Compute::Type::oaf, 16}}, 0.01, 12345);
|
{Compute::Type::oaf, 16}},
|
||||||
|
0.01, 12345);
|
||||||
euler.run(numStep);
|
euler.run(numStep);
|
||||||
for (const auto &com: euler.getComputes()) {
|
for (const auto &com : euler.getComputes()) {
|
||||||
if (com.getType() != Compute::Type::msd)
|
if (com.getType() != Compute::Type::msd) continue;
|
||||||
continue;
|
std::cout << "MSD: " << com.getDifference() << " "
|
||||||
std::cout << "MSD: " << com.getDifference() << " " << com.getAgg().getMean()
|
<< com.getAgg().getMean() << " <-> " << com.getTarget()
|
||||||
<< " <-> " << com.getTarget() << std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
for (const auto &com: euler.getComputes()) {
|
for (const auto &com : euler.getComputes()) {
|
||||||
if (com.getType() != Compute::Type::oaf)
|
if (com.getType() != Compute::Type::oaf) continue;
|
||||||
continue;
|
std::cout << "OAF: " << com.getDifference() << " "
|
||||||
std::cout << "OAF: " << com.getDifference() << " " << com.getAgg().getMean()
|
<< com.getAgg().getMean() << " <-> " << com.getTarget()
|
||||||
<< " <-> "<< com.getTarget() << std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,3 @@
|
|||||||
#define CATCH_CONFIG_MAIN // This tells the catch header to generate a main
|
#define CATCH_CONFIG_MAIN // This tells the catch header to generate a main
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,32 +2,41 @@
|
|||||||
// Created by jholder on 22.10.21.
|
// Created by jholder on 22.10.21.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include "Calculation.h"
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <Calculation.h>
|
|
||||||
#include "LiveAgg.hpp"
|
|
||||||
#include "Integratoren2d_forceless.h"
|
#include "Integratoren2d_forceless.h"
|
||||||
|
#include "LiveAgg.hpp"
|
||||||
|
|
||||||
TEST_CASE("Basic run of Calculation") {
|
TEST_CASE("Basic run of Calculation") {
|
||||||
Calculation euler(Integratoren2d_forceless::Set1_Euler, {{Compute::Type::msd, 10},
|
Calculation euler(Integratoren2d_forceless::Set1_Euler,
|
||||||
{Compute::Type::oaf, 10}}, 1, 1);
|
{{Compute::Type::msd, 10}, {Compute::Type::oaf, 10}}, 1,
|
||||||
Calculation heun(Integratoren2d_forceless::Set2_Heun, {{Compute::Type::msd, 10},
|
1);
|
||||||
{Compute::Type::oaf, 10}}, 1, 1);
|
Calculation heun(Integratoren2d_forceless::Set2_Heun,
|
||||||
Calculation exact(Integratoren2d_forceless::Set3_Exact, {{Compute::Type::msd, 10},
|
{{Compute::Type::msd, 10}, {Compute::Type::oaf, 10}}, 1,
|
||||||
{Compute::Type::oaf, 10}}, 1, 1);
|
1);
|
||||||
Calculation bdas(Integratoren2d_forceless::Set4_BDAS, {{Compute::Type::msd, 10},
|
Calculation exact(Integratoren2d_forceless::Set3_Exact,
|
||||||
{Compute::Type::oaf, 10}}, 1, 1);
|
{{Compute::Type::msd, 10}, {Compute::Type::oaf, 10}}, 1,
|
||||||
|
1);
|
||||||
|
Calculation bdas(Integratoren2d_forceless::Set4_BDAS,
|
||||||
|
{{Compute::Type::msd, 10}, {Compute::Type::oaf, 10}}, 1,
|
||||||
|
1);
|
||||||
SECTION("Euler") {
|
SECTION("Euler") {
|
||||||
euler.run(100);
|
euler.run(100);
|
||||||
CHECK(euler.getRod().getE().norm() == Catch::Detail::Approx(1.0));
|
CHECK(euler.getRod().getE().norm() == Catch::Detail::Approx(1.0));
|
||||||
CHECK(euler.getComputes()[0].getType() == Compute::Type::msd);
|
CHECK(euler.getComputes()[0].getType() == Compute::Type::msd);
|
||||||
CHECK(euler.getComputes()[1].getType() == Compute::Type::oaf);
|
CHECK(euler.getComputes()[1].getType() == Compute::Type::oaf);
|
||||||
}SECTION("Heun") {
|
}
|
||||||
|
SECTION("Heun") {
|
||||||
heun.run(100);
|
heun.run(100);
|
||||||
CHECK(heun.getRod().getE().norm() == Catch::Detail::Approx(1.0));
|
CHECK(heun.getRod().getE().norm() == Catch::Detail::Approx(1.0));
|
||||||
}SECTION("Exact") {
|
}
|
||||||
|
SECTION("Exact") {
|
||||||
exact.run(100);
|
exact.run(100);
|
||||||
CHECK(exact.getRod().getE().norm() == Catch::Detail::Approx(1.0));
|
CHECK(exact.getRod().getE().norm() == Catch::Detail::Approx(1.0));
|
||||||
}SECTION("Euler") {
|
}
|
||||||
|
SECTION("Euler") {
|
||||||
bdas.run(100);
|
bdas.run(100);
|
||||||
CHECK(bdas.getRod().getE().norm() == Catch::Detail::Approx(1.0));
|
CHECK(bdas.getRod().getE().norm() == Catch::Detail::Approx(1.0));
|
||||||
}
|
}
|
||||||
@ -36,17 +45,20 @@ TEST_CASE("Basic run of Calculation") {
|
|||||||
euler.run(100);
|
euler.run(100);
|
||||||
CHECK(euler.getComputes()[0].getAgg().getNumPoints() == 10);
|
CHECK(euler.getComputes()[0].getAgg().getNumPoints() == 10);
|
||||||
CHECK(euler.getComputes()[1].getAgg().getNumPoints() == 10);
|
CHECK(euler.getComputes()[1].getAgg().getNumPoints() == 10);
|
||||||
}SECTION("Deterministic") {
|
}
|
||||||
|
SECTION("Deterministic") {
|
||||||
Calculation determ(Integratoren2d_forceless::Set0_deterministic,
|
Calculation determ(Integratoren2d_forceless::Set0_deterministic,
|
||||||
{{Compute::Type::msd, 1},
|
{{Compute::Type::msd, 1}, {Compute::Type::oaf, 1}},
|
||||||
{Compute::Type::oaf, 1}}, 1, 1);
|
1, 1);
|
||||||
determ.run(10);
|
determ.run(10);
|
||||||
auto time = 1;
|
auto time = 1;
|
||||||
|
|
||||||
auto targetMSD = pow(0.01, 2) * time;
|
auto targetMSD = pow(0.01, 2) * time;
|
||||||
auto targetOAF = cos(0.1);
|
auto targetOAF = cos(0.1);
|
||||||
|
|
||||||
CHECK(determ.getComputes()[0].getAgg().getMean() == Catch::Detail::Approx(targetMSD));
|
CHECK(determ.getComputes()[0].getAgg().getMean() ==
|
||||||
CHECK(determ.getComputes()[1].getAgg().getMean() == Catch::Detail::Approx(targetOAF));
|
Catch::Detail::Approx(targetMSD));
|
||||||
|
CHECK(determ.getComputes()[1].getAgg().getMean() ==
|
||||||
|
Catch::Detail::Approx(targetOAF));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,19 +2,20 @@
|
|||||||
// Created by jholder on 22.10.21.
|
// Created by jholder on 22.10.21.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <Compute.h>
|
#include "Compute.h"
|
||||||
#include "catch2/catch.hpp"
|
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
#include "Integratoren2d_forceless.h"
|
#include "Integratoren2d_forceless.h"
|
||||||
|
|
||||||
TEST_CASE("Compute") {
|
TEST_CASE("Compute") {
|
||||||
Rod2d rod(1.0);
|
Rod2d rod(1.0);
|
||||||
Simulation sim(0.1,1);
|
Simulation sim(0.1, 1);
|
||||||
auto com = Compute(rod, Compute::Type::msd, 10, sim);
|
auto com = Compute(rod, Compute::Type::msd, 10, sim);
|
||||||
SECTION("Mean of same values") {
|
SECTION("Mean of same values") {
|
||||||
for (int i = 0; i < 100; ++i) {
|
for (int i = 0; i < 100; ++i) {
|
||||||
com.eval(rod);
|
com.eval(rod);
|
||||||
}
|
}
|
||||||
CHECK(com.getAgg().getNumPoints()==10);
|
CHECK(com.getAgg().getNumPoints() == 10);
|
||||||
CHECK(com.getAgg().getMean()==0.0);
|
CHECK(com.getAgg().getMean() == 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,103 +1,146 @@
|
|||||||
//
|
//
|
||||||
// Created by jholder on 24.10.21.
|
// Created by jholder on 24.10.21.
|
||||||
//
|
//
|
||||||
|
#include "Calculation.h"
|
||||||
|
#include "Compute.h"
|
||||||
|
#include "Integratoren2d_force.h"
|
||||||
|
#include "Integratoren2d_forceless.h"
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
#include <Integratoren2d_forceless.h>
|
|
||||||
#include <Calculation.h>
|
|
||||||
#include <Compute.h>
|
|
||||||
#include <Integratoren2d_force.h>
|
|
||||||
|
|
||||||
TEST_CASE("Forceless Integratoren") {
|
TEST_CASE("Forceless Integratoren") {
|
||||||
const size_t SEED = Catch::rngSeed();
|
const size_t SEED = Catch::rngSeed();
|
||||||
auto force = [](const Eigen::Vector2d & /*pos*/,
|
auto force = [](const Eigen::Vector2d & /*pos*/,
|
||||||
const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d { return {0.0, 0.0}; };
|
const Eigen::Vector2d & /*torque*/) -> Eigen::Vector2d {
|
||||||
|
return {0.0, 0.0};
|
||||||
|
};
|
||||||
auto torque = [](const Eigen::Vector2d & /*pos*/,
|
auto torque = [](const Eigen::Vector2d & /*pos*/,
|
||||||
const Eigen::Vector2d & /*torque*/) -> double { return 0.0; };
|
const Eigen::Vector2d & /*torque*/) -> double {
|
||||||
|
return 0.0;
|
||||||
|
};
|
||||||
SECTION("Euler") {
|
SECTION("Euler") {
|
||||||
|
Calculation euler(Integratoren2d_forceless::Set1_Euler,
|
||||||
Calculation euler(Integratoren2d_forceless::Set1_Euler, {{Compute::Type::msd, 1},
|
{{Compute::Type::msd, 1},
|
||||||
{Compute::Type::oaf, 1},
|
{Compute::Type::oaf, 1},
|
||||||
{Compute::Type::empxx, 1},
|
{Compute::Type::empxx, 1},
|
||||||
{Compute::Type::empyy, 1}}, 0.01, SEED);
|
{Compute::Type::empyy, 1}},
|
||||||
|
0.01, SEED);
|
||||||
{
|
{
|
||||||
euler.run(10000);
|
euler.run(10000);
|
||||||
for (auto &c: euler.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
for (auto &c : euler.getComputes()) {
|
||||||
|
CHECK(c.getDifference() <= 0.005);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Calculation euler_force(Integratoren2d_force::Set1_Euler, {
|
Calculation euler_force(
|
||||||
{Compute::Type::msd, 1},
|
Integratoren2d_force::Set1_Euler,
|
||||||
{Compute::Type::oaf, 1}}, 0.01, SEED, force, torque);
|
{{Compute::Type::msd, 1}, {Compute::Type::oaf, 1}}, 0.01, SEED,
|
||||||
|
force, torque);
|
||||||
{
|
{
|
||||||
euler_force.run(10000);
|
euler_force.run(10000);
|
||||||
for (auto &c: euler_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
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());
|
CHECK(euler.getComputes()[0].getAgg().getMean() ==
|
||||||
}SECTION("Heun") {
|
euler_force.getComputes()[0].getAgg().getMean());
|
||||||
|
CHECK(euler.getComputes()[1].getAgg().getMean() ==
|
||||||
Calculation heun(Integratoren2d_forceless::Set2_Heun, {{Compute::Type::msd, 1},
|
euler_force.getComputes()[1].getAgg().getMean());
|
||||||
|
}
|
||||||
|
SECTION("Heun") {
|
||||||
|
Calculation heun(Integratoren2d_forceless::Set2_Heun,
|
||||||
|
{{Compute::Type::msd, 1},
|
||||||
{Compute::Type::oaf, 1},
|
{Compute::Type::oaf, 1},
|
||||||
{Compute::Type::empxx, 1},
|
{Compute::Type::empxx, 1},
|
||||||
{Compute::Type::empyy, 1}}, 0.01, SEED);
|
{Compute::Type::empyy, 1}},
|
||||||
|
0.01, SEED);
|
||||||
{
|
{
|
||||||
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},
|
Calculation heun_force(Integratoren2d_force::Set2_Heun,
|
||||||
|
{{Compute::Type::msd, 1},
|
||||||
{Compute::Type::oaf, 1},
|
{Compute::Type::oaf, 1},
|
||||||
{Compute::Type::empxx, 1},
|
{Compute::Type::empxx, 1},
|
||||||
{Compute::Type::empyy, 1}}, 0.01, SEED, force,
|
{Compute::Type::empyy, 1}},
|
||||||
torque);
|
0.01, SEED, force, torque);
|
||||||
{
|
{
|
||||||
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());
|
CHECK(heun.getComputes()[0].getAgg().getMean() ==
|
||||||
}SECTION("Exact") {
|
heun_force.getComputes()[0].getAgg().getMean());
|
||||||
|
CHECK(heun.getComputes()[1].getAgg().getMean() ==
|
||||||
Calculation exact(Integratoren2d_forceless::Set3_Exact, {{Compute::Type::msd, 1},
|
heun_force.getComputes()[1].getAgg().getMean());
|
||||||
|
}
|
||||||
|
SECTION("Exact") {
|
||||||
|
Calculation exact(Integratoren2d_forceless::Set3_Exact,
|
||||||
|
{{Compute::Type::msd, 1},
|
||||||
{Compute::Type::oaf, 1},
|
{Compute::Type::oaf, 1},
|
||||||
{Compute::Type::empxx, 1},
|
{Compute::Type::empxx, 1},
|
||||||
{Compute::Type::empyy, 1}}, 0.01, SEED);
|
{Compute::Type::empyy, 1}},
|
||||||
|
0.01, SEED);
|
||||||
{
|
{
|
||||||
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},
|
Calculation exact_force(Integratoren2d_force::Set3_Exact,
|
||||||
|
{{Compute::Type::msd, 1},
|
||||||
{Compute::Type::oaf, 1},
|
{Compute::Type::oaf, 1},
|
||||||
{Compute::Type::empxx, 1},
|
{Compute::Type::empxx, 1},
|
||||||
{Compute::Type::empyy, 1}}, 0.01, SEED, force,
|
{Compute::Type::empyy, 1}},
|
||||||
torque);
|
0.01, SEED, force, torque);
|
||||||
{
|
{
|
||||||
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());
|
CHECK(exact.getComputes()[0].getAgg().getMean() ==
|
||||||
}SECTION("BDAS") {
|
Approx(exact_force.getComputes()[0].getAgg().getMean())
|
||||||
|
.epsilon(1e-10));
|
||||||
Calculation bdas(Integratoren2d_forceless::Set4_BDAS, {{Compute::Type::msd, 1},
|
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},
|
{Compute::Type::oaf, 1},
|
||||||
{Compute::Type::empxx, 1},
|
{Compute::Type::empxx, 1},
|
||||||
{Compute::Type::empyy, 1}}, 0.01, SEED);
|
{Compute::Type::empyy, 1}},
|
||||||
|
0.01, SEED);
|
||||||
{
|
{
|
||||||
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},
|
Calculation bdas_force(Integratoren2d_force::Set4_BDAS,
|
||||||
|
{{Compute::Type::msd, 1},
|
||||||
{Compute::Type::oaf, 1},
|
{Compute::Type::oaf, 1},
|
||||||
{Compute::Type::empxx, 1},
|
{Compute::Type::empxx, 1},
|
||||||
{Compute::Type::empyy, 1}}, 0.01, SEED, force,
|
{Compute::Type::empyy, 1}},
|
||||||
torque);
|
0.01, SEED, force, torque);
|
||||||
{
|
{
|
||||||
bdas_force.run(10000);
|
bdas_force.run(10000);
|
||||||
for (auto &c: bdas_force.getComputes()) { CHECK(c.getDifference() <= 0.005); }
|
for (auto &c : bdas_force.getComputes()) {
|
||||||
|
CHECK(c.getDifference() <= 0.005);
|
||||||
}
|
}
|
||||||
CHECK(bdas.getComputes()[0].getAgg().getMean() == Approx(bdas_force.getComputes()[0].getAgg().getMean()).epsilon(10e-10));
|
}
|
||||||
CHECK(bdas.getComputes()[1].getAgg().getMean() == Approx(bdas_force.getComputes()[1].getAgg().getMean()).epsilon(10e-10));
|
CHECK(bdas.getComputes()[0].getAgg().getMean() ==
|
||||||
|
Approx(bdas_force.getComputes()[0].getAgg().getMean())
|
||||||
|
.epsilon(10e-10));
|
||||||
|
CHECK(bdas.getComputes()[1].getAgg().getMean() ==
|
||||||
|
Approx(bdas_force.getComputes()[1].getAgg().getMean())
|
||||||
|
.epsilon(10e-10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,14 +3,15 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
#include "LiveAgg.hpp"
|
#include "LiveAgg.hpp"
|
||||||
|
|
||||||
TEST_CASE("LiveAgg") {
|
TEST_CASE("LiveAgg") {
|
||||||
auto ag = LiveAgg();
|
auto ag = LiveAgg();
|
||||||
SECTION("Mean of same values"){
|
SECTION("Mean of same values") {
|
||||||
ag.feed(1.0);
|
ag.feed(1.0);
|
||||||
ag.feed(1.0);
|
ag.feed(1.0);
|
||||||
REQUIRE(ag.getMean()==1.0);
|
REQUIRE(ag.getMean() == 1.0);
|
||||||
REQUIRE(ag.getNumPoints()==2);
|
REQUIRE(ag.getNumPoints() == 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,10 @@
|
|||||||
// Created by jholder on 21.10.21.
|
// Created by jholder on 21.10.21.
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "Rod2d.hpp"
|
|
||||||
#include <catch2/catch.hpp>
|
|
||||||
#include <Eigen/Dense>
|
#include <Eigen/Dense>
|
||||||
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
|
#include "Rod2d.hpp"
|
||||||
|
|
||||||
TEST_CASE("Rods") {
|
TEST_CASE("Rods") {
|
||||||
Rod2d sphere(1);
|
Rod2d sphere(1);
|
||||||
@ -14,45 +15,47 @@ TEST_CASE("Rods") {
|
|||||||
auto newPos = rod.getPos();
|
auto newPos = rod.getPos();
|
||||||
REQUIRE(newPos[0] == 1);
|
REQUIRE(newPos[0] == 1);
|
||||||
REQUIRE(newPos[1] == -1);
|
REQUIRE(newPos[1] == -1);
|
||||||
REQUIRE(sphere.getDiff_Sqrt()(0,0) == 1.0);
|
REQUIRE(sphere.getDiff_Sqrt()(0, 0) == 1.0);
|
||||||
REQUIRE(sphere.getDiff_Sqrt()(0,1) == 0.0);
|
REQUIRE(sphere.getDiff_Sqrt()(0, 1) == 0.0);
|
||||||
REQUIRE(sphere.getDiff_Sqrt()(1,0) == 0.0);
|
REQUIRE(sphere.getDiff_Sqrt()(1, 0) == 0.0);
|
||||||
REQUIRE(sphere.getDiff_Sqrt()(1,1) == 1.0);
|
REQUIRE(sphere.getDiff_Sqrt()(1, 1) == 1.0);
|
||||||
}SECTION("Checking rotation") {
|
}
|
||||||
SECTION("Forwards == e 90"){
|
SECTION("Checking rotation") {
|
||||||
|
SECTION("Forwards == e 90") {
|
||||||
//
|
//
|
||||||
// =====
|
// =====
|
||||||
//
|
//
|
||||||
rod.setE({0, 1}); // Lab system is 90 degree rotated
|
rod.setE({0, 1}); // Lab system is 90 degree rotated
|
||||||
auto test = Eigen::Vector2d ({1,0});
|
auto test = Eigen::Vector2d({1, 0});
|
||||||
auto erg = (rod.getE_Base_matrix()*test).normalized();
|
auto erg = (rod.getE_Base_matrix() * test).normalized();
|
||||||
auto e = rod.getE();
|
|
||||||
REQUIRE(erg.isApprox(e));
|
|
||||||
|
|
||||||
}
|
|
||||||
SECTION("Forwards == e 45"){
|
|
||||||
// o
|
|
||||||
// o
|
|
||||||
// o
|
|
||||||
rod.setE(Eigen::Vector2d ({1,1}).normalized()); // Lab system is 90 degree rotated
|
|
||||||
auto test = Eigen::Vector2d ({1,0});
|
|
||||||
auto erg = (rod.getE_Base_matrix()*test).normalized();
|
|
||||||
auto e = rod.getE();
|
auto e = rod.getE();
|
||||||
REQUIRE(erg.isApprox(e));
|
REQUIRE(erg.isApprox(e));
|
||||||
}
|
}
|
||||||
|
SECTION("Forwards == e 45") {
|
||||||
|
// o
|
||||||
|
// o
|
||||||
|
// o
|
||||||
|
rod.setE(Eigen::Vector2d({1, 1})
|
||||||
|
.normalized()); // Lab system is 90 degree rotated
|
||||||
|
auto test = Eigen::Vector2d({1, 0});
|
||||||
|
auto erg = (rod.getE_Base_matrix() * test).normalized();
|
||||||
|
auto e = rod.getE();
|
||||||
|
REQUIRE(erg.isApprox(e));
|
||||||
}
|
}
|
||||||
SECTION("Angle Stuff"){
|
}
|
||||||
|
SECTION("Angle Stuff") {
|
||||||
const Eigen::Vector2d unitVec = {1, 0};
|
const Eigen::Vector2d unitVec = {1, 0};
|
||||||
double f1 = GENERATE(take(10,random(-100,100)));
|
double f1 = GENERATE(take(10, random(-100, 100)));
|
||||||
double f2 = GENERATE(take(10,random(0,100)));
|
double f2 = GENERATE(take(10, random(0, 100)));
|
||||||
sphere.setE(Eigen::Vector2d({f1,f2}).normalized());
|
sphere.setE(Eigen::Vector2d({f1, f2}).normalized());
|
||||||
Eigen::Rotation2D rotMat(acos(unitVec.dot(sphere.getE())));
|
Eigen::Rotation2D rotMat(acos(unitVec.dot(sphere.getE())));
|
||||||
CHECK(rotMat.toRotationMatrix()(0,0) == Approx(sphere.getE_Base_matrix()(0,0)).epsilon(10e-10));
|
CHECK(rotMat.toRotationMatrix()(0, 0) ==
|
||||||
CHECK(rotMat.toRotationMatrix()(1,0) == Approx(sphere.getE_Base_matrix()(1,0)).epsilon(10e-10));
|
Approx(sphere.getE_Base_matrix()(0, 0)).epsilon(10e-10));
|
||||||
CHECK(rotMat.toRotationMatrix()(0,1) == Approx(sphere.getE_Base_matrix()(0,1)).epsilon(10e-10));
|
CHECK(rotMat.toRotationMatrix()(1, 0) ==
|
||||||
CHECK(rotMat.toRotationMatrix()(1,1) == Approx(sphere.getE_Base_matrix()(1,1)).epsilon(10e-10));
|
Approx(sphere.getE_Base_matrix()(1, 0)).epsilon(10e-10));
|
||||||
|
CHECK(rotMat.toRotationMatrix()(0, 1) ==
|
||||||
|
Approx(sphere.getE_Base_matrix()(0, 1)).epsilon(10e-10));
|
||||||
|
CHECK(rotMat.toRotationMatrix()(1, 1) ==
|
||||||
|
Approx(sphere.getE_Base_matrix()(1, 1)).epsilon(10e-10));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -3,25 +3,26 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <catch2/catch.hpp>
|
#include <catch2/catch.hpp>
|
||||||
|
|
||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
|
|
||||||
TEST_CASE("Simulation") {
|
TEST_CASE("Simulation") {
|
||||||
auto sim = Simulation(1,0);
|
auto sim = Simulation(1, 0);
|
||||||
REQUIRE(sim.getSTD()==sqrt(1*2.0));
|
REQUIRE(sim.getSTD() == sqrt(1 * 2.0));
|
||||||
SECTION("Symmetrie"){
|
SECTION("Symmetrie") {
|
||||||
constexpr int num = 10000000;
|
constexpr int num = 10000000;
|
||||||
double sum = 0.0;
|
double sum = 0.0;
|
||||||
for (int i = 0; i < num; ++i) {
|
for (int i = 0; i < num; ++i) {
|
||||||
sum += sim.getNorm(1);
|
sum += sim.getNorm(1);
|
||||||
}
|
}
|
||||||
CHECK(sum/num == Catch::Detail::Approx(0.0).margin(0.001));
|
CHECK(sum / num == Catch::Detail::Approx(0.0).margin(0.001));
|
||||||
}
|
}
|
||||||
SECTION("STD"){
|
SECTION("STD") {
|
||||||
constexpr int num = 10000000;
|
constexpr int num = 10000000;
|
||||||
double sum = 0.0;
|
double sum = 0.0;
|
||||||
for (int i = 0; i < num; ++i) {
|
for (int i = 0; i < num; ++i) {
|
||||||
sum += pow(sim.getNorm(1),2);
|
sum += pow(sim.getNorm(1), 2);
|
||||||
}
|
}
|
||||||
CHECK(sum/num == Catch::Detail::Approx(1.0).margin(0.001));
|
CHECK(sum / num == Catch::Detail::Approx(1.0).margin(0.001));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user