From 52b7a5f0c96f3f4311bba46d4d778cbd50f8a0c2 Mon Sep 17 00:00:00 2001
From: podlesny <podlesny@zedat.fu-berlin.de>
Date: Mon, 8 Feb 2021 18:57:58 +0100
Subject: [PATCH] add uniformtimestepper

---
 dune/tectonic/time-stepping/CMakeLists.txt    |  3 +
 .../time-stepping/uniformtimestepper.cc       | 59 +++++++++++++++++++
 .../time-stepping/uniformtimestepper.hh       | 37 ++++++++++++
 .../time-stepping/uniformtimestepper_tmpl.cc  | 46 +++++++++++++++
 4 files changed, 145 insertions(+)
 create mode 100644 dune/tectonic/time-stepping/uniformtimestepper.cc
 create mode 100644 dune/tectonic/time-stepping/uniformtimestepper.hh
 create mode 100644 dune/tectonic/time-stepping/uniformtimestepper_tmpl.cc

diff --git a/dune/tectonic/time-stepping/CMakeLists.txt b/dune/tectonic/time-stepping/CMakeLists.txt
index ce276d15..94e3d4bf 100644
--- a/dune/tectonic/time-stepping/CMakeLists.txt
+++ b/dune/tectonic/time-stepping/CMakeLists.txt
@@ -12,6 +12,8 @@ add_custom_target(tectonic_dune_time-stepping SOURCES
   state.cc
   step.hh
   stepbase.hh
+  uniformtimestepper.hh
+  uniformtimestepper.cc
   updaters.hh
 )
 
@@ -23,5 +25,6 @@ install(FILES
   state.hh
   step.hh
   stepbase.hh
+  uniformtimestepper.hh
   updaters.hh
 DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dune/tectonic)
diff --git a/dune/tectonic/time-stepping/uniformtimestepper.cc b/dune/tectonic/time-stepping/uniformtimestepper.cc
new file mode 100644
index 00000000..5ad6e7df
--- /dev/null
+++ b/dune/tectonic/time-stepping/uniformtimestepper.cc
@@ -0,0 +1,59 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <dune/solvers/norms/energynorm.hh>
+#include <dune/solvers/iterationsteps/multigridstep.hh>
+#include <dune/solvers/iterationsteps/cgstep.hh>
+#include <dune/solvers/solvers/loopsolver.hh>
+
+#include "../spatial-solving/preconditioners/multilevelpatchpreconditioner.hh"
+
+#include <dune/tectonic/utils/reductionfactors.hh>
+
+#include "uniformtimestepper.hh"
+#include "step.hh"
+
+
+/*
+ * Implementation: AdaptiveTimeStepper
+ */
+template <class Factory, class ContactNetwork, class Updaters, class ErrorNorms>
+UniformTimeStepper<Factory, ContactNetwork, Updaters, ErrorNorms>::UniformTimeStepper(
+        const StepBase& stepBase,
+        ContactNetwork& contactNetwork,
+        Updaters &current,
+        double relativeTime,
+        double relativeTau)
+    : relativeTime_(relativeTime),
+      relativeTau_(relativeTau),
+      stepBase_(stepBase),
+      contactNetwork_(contactNetwork),
+      current_(current) {}
+
+template <class Factory, class ContactNetwork, class Updaters, class ErrorNorms>
+bool UniformTimeStepper<Factory, ContactNetwork, Updaters, ErrorNorms>::reachedEnd() {
+  return relativeTime_ >= 1.0;
+}
+
+template <class Factory, class ContactNetwork, class Updaters, class ErrorNorms>
+IterationRegister UniformTimeStepper<Factory, ContactNetwork, Updaters, ErrorNorms>::advance() {
+  //std::cout << "AdaptiveTimeStepper::advance()" << std::endl;
+
+  using Step = Step<Factory, ContactNetwork, Updaters, ErrorNorms>;
+  iterationRegister_.reset();
+
+  UpdatersWithCount N;
+
+  auto step = Step(stepBase_, current_, contactNetwork_.nBodyAssembler(), relativeTime_, relativeTau_, iterationRegister_);
+  step.run(Step::Mode::sameThread);
+  N = step.get();
+
+  current_ = N.updaters;
+  iterationRegister_.registerFinalCount(N.count);
+  relativeTime_ += relativeTau_;
+
+  return iterationRegister_;
+}
+
+#include "uniformtimestepper_tmpl.cc"
diff --git a/dune/tectonic/time-stepping/uniformtimestepper.hh b/dune/tectonic/time-stepping/uniformtimestepper.hh
new file mode 100644
index 00000000..72e46edd
--- /dev/null
+++ b/dune/tectonic/time-stepping/uniformtimestepper.hh
@@ -0,0 +1,37 @@
+#ifndef SRC_TIME_STEPPING_UNIFORMTIMESTEPPER_HH
+#define SRC_TIME_STEPPING_UNIFORMTIMESTEPPER_HH
+
+#include "../spatial-solving/fixedpointiterator.hh"
+#include "adaptivetimestepper.hh"
+#include "stepbase.hh"
+
+template <class Factory, class ContactNetwork, class Updaters, class ErrorNorms>
+class UniformTimeStepper {
+
+  using UpdatersWithCount = UpdatersWithCount<Updaters>;
+  using StepBase = StepBase<Factory, ContactNetwork, Updaters, ErrorNorms>;
+
+public:
+  UniformTimeStepper(const StepBase& stepBase,
+                      ContactNetwork& contactNetwork,
+                      Updaters &current,
+                      double relativeTime,
+                      double relativeTau);
+
+  bool reachedEnd();
+
+  IterationRegister advance();
+
+  double relativeTime_;
+  const double relativeTau_;
+
+private:
+  const StepBase& stepBase_;
+  ContactNetwork& contactNetwork_;
+
+  Updaters &current_;
+
+  IterationRegister iterationRegister_;
+};
+
+#endif
diff --git a/dune/tectonic/time-stepping/uniformtimestepper_tmpl.cc b/dune/tectonic/time-stepping/uniformtimestepper_tmpl.cc
new file mode 100644
index 00000000..fd863d18
--- /dev/null
+++ b/dune/tectonic/time-stepping/uniformtimestepper_tmpl.cc
@@ -0,0 +1,46 @@
+#ifndef MY_DIM
+#error MY_DIM unset
+#endif
+
+#include <future>
+#include <thread>
+
+#include "../explicitgrid.hh"
+#include "../explicitvectors.hh"
+
+#include <dune/solvers/norms/energynorm.hh>
+#include <dune/solvers/solvers/loopsolver.hh>
+
+#include "../spatial-solving/tnnmg/functional.hh"
+#include "../spatial-solving/solverfactory.hh"
+
+#include "../data-structures/network/contactnetwork.hh"
+#include "../data-structures/friction/globalfriction.hh"
+
+#include "rate/rateupdater.hh"
+#include "state/stateupdater.hh"
+#include "updaters.hh"
+
+using MyContactNetwork = ContactNetwork<Grid, Vector>;
+
+using BoundaryNodes = typename MyContactNetwork::BoundaryNodes;
+using BoundaryFunctions = typename MyContactNetwork::BoundaryFunctions;
+
+using MyStateUpdater = StateUpdater<ScalarVector, Vector>;
+using MyRateUpdater = RateUpdater<Vector, Matrix, BoundaryFunctions, BoundaryNodes>;
+using MyUpdaters = Updaters<MyRateUpdater, MyStateUpdater>;
+
+using LinearSolver = Dune::Solvers::LoopSolver<Vector>;
+using MyNBodyAssembler = typename MyContactNetwork::NBodyAssembler;
+using ErrorNorms = typename MyContactNetwork::StateEnergyNorms;
+
+using MyGlobalFriction = GlobalFriction<Matrix, Vector>;
+using MyFunctional = Functional<Matrix&, Vector&, MyGlobalFriction&, Vector&, Vector&, double>;
+using MySolverFactory = SolverFactory<MyFunctional, BitVector>;
+
+template class UniformTimeStepper<MySolverFactory, MyContactNetwork, MyUpdaters, ErrorNorms>;
+
+/*
+template std::packaged_task<typename AdaptiveTimeStepper<MySolverFactory, MyContactNetwork, MyUpdaters, ErrorNorms>::UpdatersWithCount()>
+AdaptiveTimeStepper<MySolverFactory, MyContactNetwork, MyUpdaters, ErrorNorms>::step<LinearSolver>(
+        const MyUpdaters&, const MyNBodyAssembler&, std::shared_ptr<LinearSolver>&, double, double); */
-- 
GitLab