From 89b30b760b911204493d8f37d276adff8936ff7e Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Mon, 7 Jul 2014 14:41:03 +0200 Subject: [PATCH] [Extend] Make time/state updaters cloneable --- src/state/ageinglawstateupdater.cc | 6 ++++++ src/state/ageinglawstateupdater.hh | 2 ++ src/state/sliplawstateupdater.cc | 6 ++++++ src/state/sliplawstateupdater.hh | 2 ++ src/state/stateupdater.hh | 2 ++ src/timestepping.hh | 4 ++++ src/timestepping/backward_euler.cc | 6 ++++++ src/timestepping/backward_euler.hh | 3 +++ src/timestepping/newmark.cc | 6 ++++++ src/timestepping/newmark.hh | 3 +++ 10 files changed, 40 insertions(+) diff --git a/src/state/ageinglawstateupdater.cc b/src/state/ageinglawstateupdater.cc index ec69fac3..51a91626 100644 --- a/src/state/ageinglawstateupdater.cc +++ b/src/state/ageinglawstateupdater.cc @@ -46,3 +46,9 @@ void AgeingLawStateUpdater<ScalarVector, Vector>::extractAlpha( ScalarVector &_alpha) { _alpha = alpha; } + +template <class ScalarVector, class Vector> +std::shared_ptr<StateUpdater<ScalarVector, Vector>> +AgeingLawStateUpdater<ScalarVector, Vector>::clone() const { + return std::make_shared<AgeingLawStateUpdater<ScalarVector, Vector>>(*this); +} diff --git a/src/state/ageinglawstateupdater.hh b/src/state/ageinglawstateupdater.hh index c8ae85c7..67ebab25 100644 --- a/src/state/ageinglawstateupdater.hh +++ b/src/state/ageinglawstateupdater.hh @@ -16,6 +16,8 @@ class AgeingLawStateUpdater : public StateUpdater<ScalarVector, Vector> { void solve(Vector const &velocity_field) override; void extractAlpha(ScalarVector &) override; + std::shared_ptr<StateUpdater<ScalarVector, Vector>> clone() const; + private: ScalarVector alpha_o; ScalarVector alpha; diff --git a/src/state/sliplawstateupdater.cc b/src/state/sliplawstateupdater.cc index 2b3e643c..acffc6f2 100644 --- a/src/state/sliplawstateupdater.cc +++ b/src/state/sliplawstateupdater.cc @@ -35,3 +35,9 @@ void SlipLawStateUpdater<ScalarVector, Vector>::extractAlpha( ScalarVector &_alpha) { _alpha = alpha; } + +template <class ScalarVector, class Vector> +std::shared_ptr<StateUpdater<ScalarVector, Vector>> +SlipLawStateUpdater<ScalarVector, Vector>::clone() const { + return std::make_shared<SlipLawStateUpdater<ScalarVector, Vector>>(*this); +} diff --git a/src/state/sliplawstateupdater.hh b/src/state/sliplawstateupdater.hh index e12e004c..28838aec 100644 --- a/src/state/sliplawstateupdater.hh +++ b/src/state/sliplawstateupdater.hh @@ -16,6 +16,8 @@ class SlipLawStateUpdater : public StateUpdater<ScalarVector, Vector> { void solve(Vector const &velocity_field) override; void extractAlpha(ScalarVector &) override; + std::shared_ptr<StateUpdater<ScalarVector, Vector>> clone() const; + private: ScalarVector alpha_o; ScalarVector alpha; diff --git a/src/state/stateupdater.hh b/src/state/stateupdater.hh index 697662d3..9e4495af 100644 --- a/src/state/stateupdater.hh +++ b/src/state/stateupdater.hh @@ -9,6 +9,8 @@ template <class ScalarVectorTEMPLATE, class Vector> class StateUpdater { void virtual setup(double _tau) = 0; void virtual solve(Vector const &velocity_field) = 0; void virtual extractAlpha(ScalarVector &alpha) = 0; + + std::shared_ptr<StateUpdater<ScalarVector, Vector>> virtual clone() const = 0; }; #endif diff --git a/src/timestepping.hh b/src/timestepping.hh index 71d99b69..1221c585 100644 --- a/src/timestepping.hh +++ b/src/timestepping.hh @@ -20,6 +20,10 @@ class TimeSteppingScheme { void virtual extractVelocity(Vector &velocity) const = 0; void virtual extractRelativeVelocity(Vector &velocity) const = 0; void virtual extractOldVelocity(Vector &velocity) const = 0; + + std::shared_ptr< + TimeSteppingScheme<Vector, Matrix, Function, dim>> virtual clone() + const = 0; }; #include "timestepping/newmark.hh" diff --git a/src/timestepping/backward_euler.cc b/src/timestepping/backward_euler.cc index 57f24bd3..a39f0e54 100644 --- a/src/timestepping/backward_euler.cc +++ b/src/timestepping/backward_euler.cc @@ -147,3 +147,9 @@ void BackwardEuler<Vector, Matrix, Function, dim>::extractOldVelocity( Vector &velocity) const { velocity = v_o; } + +template <class Vector, class Matrix, class Function, size_t dim> +std::shared_ptr<TimeSteppingScheme<Vector, Matrix, Function, dim>> +BackwardEuler<Vector, Matrix, Function, dim>::clone() const { + return std::make_shared<BackwardEuler<Vector, Matrix, Function, dim>>(*this); +} diff --git a/src/timestepping/backward_euler.hh b/src/timestepping/backward_euler.hh index e6291fd6..510a149f 100644 --- a/src/timestepping/backward_euler.hh +++ b/src/timestepping/backward_euler.hh @@ -21,6 +21,9 @@ class BackwardEuler : public TimeSteppingScheme<Vector, Matrix, Function, dim> { void extractRelativeVelocity(Vector &) const override; void extractOldVelocity(Vector &) const override; + std::shared_ptr<TimeSteppingScheme<Vector, Matrix, Function, dim>> clone() + const; + private: Matrix const &A; Matrix const &M; diff --git a/src/timestepping/newmark.cc b/src/timestepping/newmark.cc index 518a69ce..51eeb7a3 100644 --- a/src/timestepping/newmark.cc +++ b/src/timestepping/newmark.cc @@ -166,3 +166,9 @@ void Newmark<Vector, Matrix, Function, dim>::extractOldVelocity( Vector &velocity) const { velocity = v_o; } + +template <class Vector, class Matrix, class Function, size_t dim> +std::shared_ptr<TimeSteppingScheme<Vector, Matrix, Function, dim>> +Newmark<Vector, Matrix, Function, dim>::clone() const { + return std::make_shared<Newmark<Vector, Matrix, Function, dim>>(*this); +} diff --git a/src/timestepping/newmark.hh b/src/timestepping/newmark.hh index bfae9664..0d711447 100644 --- a/src/timestepping/newmark.hh +++ b/src/timestepping/newmark.hh @@ -22,6 +22,9 @@ class Newmark : public TimeSteppingScheme<Vector, Matrix, Function, dim> { void extractRelativeVelocity(Vector &) const override; void extractOldVelocity(Vector &) const override; + std::shared_ptr<TimeSteppingScheme<Vector, Matrix, Function, dim>> clone() + const; + private: Matrix const &A; Matrix const &M; -- GitLab