From 91f329ba00e76a3edb2ef16d455fbafea03ad214 Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Sat, 5 Jul 2014 21:02:59 +0200 Subject: [PATCH] [Cleanup] Compile state updaters separately --- src/Makefile.am | 1 + src/state.cc | 25 ++++++++++++++++ src/state.hh | 15 ++-------- src/state/ageinglawstateupdater.cc | 48 ++++++++++++++++++++++++++++++ src/state/ageinglawstateupdater.hh | 47 ----------------------------- src/state/sliplawstateupdater.cc | 37 +++++++++++++++++++++++ src/state/sliplawstateupdater.hh | 36 ---------------------- src/state_tmpl.cc | 7 +++++ 8 files changed, 121 insertions(+), 95 deletions(-) create mode 100644 src/state.cc create mode 100644 src/state/ageinglawstateupdater.cc create mode 100644 src/state/sliplawstateupdater.cc create mode 100644 src/state_tmpl.cc diff --git a/src/Makefile.am b/src/Makefile.am index 45d92485..42c6012a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,6 +5,7 @@ common_sources = \ boundary_writer.cc \ friction_writer.cc \ solverfactory.cc \ + state.cc \ timestepping.cc \ vtk.cc diff --git a/src/state.cc b/src/state.cc new file mode 100644 index 00000000..49567d3f --- /dev/null +++ b/src/state.cc @@ -0,0 +1,25 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "state.hh" +#include "state/ageinglawstateupdater.cc" +#include "state/sliplawstateupdater.cc" + +template <class ScalarVector, class Vector> +std::shared_ptr<StateUpdater<ScalarVector, Vector>> initStateUpdater( + Config::stateModel model, ScalarVector const &alpha_initial, + Dune::BitSetVector<1> const &frictionalNodes, double L, double V0) { + switch (model) { + case Config::AgeingLaw: + return std::make_shared<AgeingLawStateUpdater<ScalarVector, Vector>>( + alpha_initial, frictionalNodes, L, V0); + case Config::SlipLaw: + return std::make_shared<SlipLawStateUpdater<ScalarVector, Vector>>( + alpha_initial, frictionalNodes, L, V0); + default: + assert(false); + } +} + +#include "state_tmpl.cc" diff --git a/src/state.hh b/src/state.hh index cfa60f94..5726ef3b 100644 --- a/src/state.hh +++ b/src/state.hh @@ -6,6 +6,7 @@ #include <dune/common/bitsetvector.hh> #include "enums.hh" + #include "state/stateupdater.hh" #include "state/ageinglawstateupdater.hh" #include "state/sliplawstateupdater.hh" @@ -13,16 +14,6 @@ template <class ScalarVector, class Vector> std::shared_ptr<StateUpdater<ScalarVector, Vector>> initStateUpdater( Config::stateModel model, ScalarVector const &alpha_initial, - Dune::BitSetVector<1> const &frictionalNodes, double L, double V0) { - switch (model) { - case Config::AgeingLaw: - return std::make_shared<AgeingLawStateUpdater<ScalarVector, Vector>>( - alpha_initial, frictionalNodes, L, V0); - case Config::SlipLaw: - return std::make_shared<SlipLawStateUpdater<ScalarVector, Vector>>( - alpha_initial, frictionalNodes, L, V0); - default: - assert(false); - } -} + Dune::BitSetVector<1> const &frictionalNodes, double L, double V0); + #endif diff --git a/src/state/ageinglawstateupdater.cc b/src/state/ageinglawstateupdater.cc new file mode 100644 index 00000000..1461e299 --- /dev/null +++ b/src/state/ageinglawstateupdater.cc @@ -0,0 +1,48 @@ +#include "ageinglawstateupdater.hh" + +template <class ScalarVector, class Vector> +AgeingLawStateUpdater<ScalarVector, Vector>::AgeingLawStateUpdater( + ScalarVector _alpha_initial, Dune::BitSetVector<1> const &_nodes, double _L, + double _V0) + : alpha(_alpha_initial), nodes(_nodes), L(_L), V0(_V0) {} + +template <class ScalarVector, class Vector> +void AgeingLawStateUpdater<ScalarVector, Vector>::nextTimeStep() { + alpha_o = alpha; +} + +template <class ScalarVector, class Vector> +void AgeingLawStateUpdater<ScalarVector, Vector>::setup(double _tau) { + tau = _tau; +} + +/* + Compute [ 1-\exp(c*x) ] / x under the assumption that x is + non-negative +*/ +double liftSingularity(double c, double x) { + if (x <= 0) + return -c; + else + return -std::expm1(c * x) / x; +} + +template <class ScalarVector, class Vector> +void AgeingLawStateUpdater<ScalarVector, Vector>::solve( + Vector const &velocity_field) { + for (size_t i = 0; i < nodes.size(); ++i) { + if (not toBool(nodes[i])) + continue; + + double const V = velocity_field[i].two_norm(); + double const mtoL = -tau / L; + alpha[i] = std::log(std::exp(alpha_o[i] + V * mtoL) + + V0 * liftSingularity(mtoL, V)); + } +} + +template <class ScalarVector, class Vector> +void AgeingLawStateUpdater<ScalarVector, Vector>::extractAlpha( + ScalarVector &_alpha) { + _alpha = alpha; +} diff --git a/src/state/ageinglawstateupdater.hh b/src/state/ageinglawstateupdater.hh index e7176a1e..5b6fec71 100644 --- a/src/state/ageinglawstateupdater.hh +++ b/src/state/ageinglawstateupdater.hh @@ -24,51 +24,4 @@ class AgeingLawStateUpdater : public StateUpdater<ScalarVector, Vector> { double const V0; double tau; }; - -template <class ScalarVector, class Vector> -AgeingLawStateUpdater<ScalarVector, Vector>::AgeingLawStateUpdater( - ScalarVector _alpha_initial, Dune::BitSetVector<1> const &_nodes, double _L, - double _V0) - : alpha(_alpha_initial), nodes(_nodes), L(_L), V0(_V0) {} - -template <class ScalarVector, class Vector> -void AgeingLawStateUpdater<ScalarVector, Vector>::nextTimeStep() { - alpha_o = alpha; -} - -template <class ScalarVector, class Vector> -void AgeingLawStateUpdater<ScalarVector, Vector>::setup(double _tau) { - tau = _tau; -} - -/* - Compute [ 1-\exp(c*x) ] / x under the assumption that x is - non-negative -*/ -double liftSingularity(double c, double x) { - if (x <= 0) - return -c; - else - return -std::expm1(c * x) / x; -} - -template <class ScalarVector, class Vector> -void AgeingLawStateUpdater<ScalarVector, Vector>::solve( - Vector const &velocity_field) { - for (size_t i = 0; i < nodes.size(); ++i) { - if (not toBool(nodes[i])) - continue; - - double const V = velocity_field[i].two_norm(); - double const mtoL = -tau / L; - alpha[i] = std::log(std::exp(alpha_o[i] + V * mtoL) + - V0 * liftSingularity(mtoL, V)); - } -} - -template <class ScalarVector, class Vector> -void AgeingLawStateUpdater<ScalarVector, Vector>::extractAlpha( - ScalarVector &_alpha) { - _alpha = alpha; -} #endif diff --git a/src/state/sliplawstateupdater.cc b/src/state/sliplawstateupdater.cc new file mode 100644 index 00000000..5397c1d2 --- /dev/null +++ b/src/state/sliplawstateupdater.cc @@ -0,0 +1,37 @@ +#include "sliplawstateupdater.hh" + +template <class ScalarVector, class Vector> +SlipLawStateUpdater<ScalarVector, Vector>::SlipLawStateUpdater( + ScalarVector _alpha_initial, Dune::BitSetVector<1> const &_nodes, double _L, + double _V0) + : alpha(_alpha_initial), nodes(_nodes), L(_L), V0(_V0) {} + +template <class ScalarVector, class Vector> +void SlipLawStateUpdater<ScalarVector, Vector>::nextTimeStep() { + alpha_o = alpha; +} + +template <class ScalarVector, class Vector> +void SlipLawStateUpdater<ScalarVector, Vector>::setup(double _tau) { + tau = _tau; +} + +template <class ScalarVector, class Vector> +void SlipLawStateUpdater<ScalarVector, Vector>::solve( + Vector const &velocity_field) { + for (size_t i = 0; i < nodes.size(); ++i) { + if (not toBool(nodes[i])) + continue; + + double const V = velocity_field[i].two_norm(); + double const mtVoL = -tau * V / L; + alpha[i] = (V <= 0) ? alpha_o[i] : std::expm1(mtVoL) * std::log(V / V0) + + alpha_o[i] * std::exp(mtVoL); + } +} + +template <class ScalarVector, class Vector> +void SlipLawStateUpdater<ScalarVector, Vector>::extractAlpha( + ScalarVector &_alpha) { + _alpha = alpha; +} diff --git a/src/state/sliplawstateupdater.hh b/src/state/sliplawstateupdater.hh index 9bb82210..f527c1c4 100644 --- a/src/state/sliplawstateupdater.hh +++ b/src/state/sliplawstateupdater.hh @@ -25,40 +25,4 @@ class SlipLawStateUpdater : public StateUpdater<ScalarVector, Vector> { double tau; }; -template <class ScalarVector, class Vector> -SlipLawStateUpdater<ScalarVector, Vector>::SlipLawStateUpdater( - ScalarVector _alpha_initial, Dune::BitSetVector<1> const &_nodes, double _L, - double _V0) - : alpha(_alpha_initial), nodes(_nodes), L(_L), V0(_V0) {} - -template <class ScalarVector, class Vector> -void SlipLawStateUpdater<ScalarVector, Vector>::nextTimeStep() { - alpha_o = alpha; -} - -template <class ScalarVector, class Vector> -void SlipLawStateUpdater<ScalarVector, Vector>::setup(double _tau) { - tau = _tau; -} - -template <class ScalarVector, class Vector> -void SlipLawStateUpdater<ScalarVector, Vector>::solve( - Vector const &velocity_field) { - for (size_t i = 0; i < nodes.size(); ++i) { - if (not toBool(nodes[i])) - continue; - - double const V = velocity_field[i].two_norm(); - double const mtVoL = -tau * V / L; - alpha[i] = (V <= 0) ? alpha_o[i] : std::expm1(mtVoL) * std::log(V / V0) + - alpha_o[i] * std::exp(mtVoL); - } -} - -template <class ScalarVector, class Vector> -void SlipLawStateUpdater<ScalarVector, Vector>::extractAlpha( - ScalarVector &_alpha) { - _alpha = alpha; -} - #endif diff --git a/src/state_tmpl.cc b/src/state_tmpl.cc new file mode 100644 index 00000000..65d7ba9c --- /dev/null +++ b/src/state_tmpl.cc @@ -0,0 +1,7 @@ +#include "explicitvectors.hh" + +template std::shared_ptr<StateUpdater<ScalarVector, Vector>> initStateUpdater< + ScalarVector, Vector>(Config::stateModel model, + ScalarVector const &alpha_initial, + Dune::BitSetVector<1> const &frictionalNodes, + double L, double V0); -- GitLab