Skip to content
Snippets Groups Projects
Commit 9d49146e authored by Elias Pipping's avatar Elias Pipping Committed by Elias Pipping
Browse files

Move time stepping of alpha to a class

parent e0292768
No related branches found
No related tags found
No related merge requests found
#ifndef DIETERICH_STATE_UPDATER_HH
#define DIETERICH_STATE_UPDATER_HH
#include "compute_state_dieterich_euler.hh"
#include "stateupdater.hh"
template <class SingletonVectorType, class VectorType>
class DieterichStateUpdater
: public StateUpdater<SingletonVectorType, VectorType> {
public:
DieterichStateUpdater(SingletonVectorType _alpha_initial,
Dune::BitSetVector<1> const &_nodes, double _L);
virtual void nextTimeStep();
virtual void setup(double _tau);
virtual void solve(VectorType const &velocity_field);
virtual void extractState(SingletonVectorType &state);
private:
SingletonVectorType alpha_old;
SingletonVectorType alpha;
Dune::BitSetVector<1> const &nodes;
double const L;
double tau;
};
template <class SingletonVectorType, class VectorType>
DieterichStateUpdater<SingletonVectorType, VectorType>::DieterichStateUpdater(
SingletonVectorType _alpha_initial, Dune::BitSetVector<1> const &_nodes,
double _L)
: alpha(_alpha_initial), nodes(_nodes), L(_L) {}
template <class SingletonVectorType, class VectorType>
void DieterichStateUpdater<SingletonVectorType, VectorType>::nextTimeStep() {
alpha_old = alpha;
}
template <class SingletonVectorType, class VectorType>
void DieterichStateUpdater<SingletonVectorType, VectorType>::setup(
double _tau) {
tau = _tau;
}
template <class SingletonVectorType, class VectorType>
void DieterichStateUpdater<SingletonVectorType, VectorType>::solve(
VectorType const &velocity_field) {
for (size_t i = 0; i < nodes.size(); ++i)
if (nodes[i][0]) {
double const V = velocity_field[i].two_norm();
alpha[i] = state_update_dieterich_euler(tau, V / L, alpha_old[i]);
}
}
template <class SingletonVectorType, class VectorType>
void DieterichStateUpdater<SingletonVectorType, VectorType>::extractState(
SingletonVectorType &state) {
state = alpha;
}
#endif
...@@ -65,8 +65,6 @@ ...@@ -65,8 +65,6 @@
#include <dune/tectonic/myconvexproblem.hh> #include <dune/tectonic/myconvexproblem.hh>
#include "assemblers.hh" #include "assemblers.hh"
#include "compute_state_dieterich_euler.hh"
#include "compute_state_ruina.hh"
#include "mysolver.hh" #include "mysolver.hh"
#include "vtk.hh" #include "vtk.hh"
...@@ -77,6 +75,9 @@ ...@@ -77,6 +75,9 @@
#include "timestepping.hh" #include "timestepping.hh"
#include "ruinastateupdater.hh"
#include "dieterichstateupdater.hh"
int const dim = DIM; int const dim = DIM;
template <class GridView, class GridCorner> template <class GridView, class GridCorner>
...@@ -284,9 +285,9 @@ int main(int argc, char *argv[]) { ...@@ -284,9 +285,9 @@ int main(int argc, char *argv[]) {
VectorType udd_initial(finestSize); VectorType udd_initial(finestSize);
udd_initial = 0.0; udd_initial = 0.0;
SingletonVectorType alpha_old(finestSize); SingletonVectorType alpha_initial(finestSize);
alpha_old = parset.get<double>("boundary.friction.state.initial"); alpha_initial = parset.get<double>("boundary.friction.state.initial");
SingletonVectorType alpha(alpha_old); SingletonVectorType alpha(alpha_initial);
SingletonVectorType vonMisesStress; SingletonVectorType vonMisesStress;
...@@ -355,11 +356,28 @@ int main(int argc, char *argv[]) { ...@@ -355,11 +356,28 @@ int main(int argc, char *argv[]) {
break; break;
} }
Dune::shared_ptr<StateUpdater<SingletonVectorType, VectorType>>
stateUpdater;
switch (parset.get<Config::state_model>("boundary.friction.state.model")) {
case Config::Dieterich:
stateUpdater = Dune::make_shared<
DieterichStateUpdater<SingletonVectorType, VectorType>>(
alpha_initial, frictionalNodes, L);
break;
case Config::Ruina:
stateUpdater = Dune::make_shared<
RuinaStateUpdater<SingletonVectorType, VectorType>>(
alpha_initial, frictionalNodes, L);
break;
}
auto const state_fpi_max = auto const state_fpi_max =
parset.get<size_t>("solver.tnnmg.fixed_point_iterations"); parset.get<size_t>("solver.tnnmg.fixed_point_iterations");
for (size_t run = 1; run <= timesteps; ++run) { for (size_t run = 1; run <= timesteps; ++run) {
double const time = tau * run; double const time = tau * run;
{ {
stateUpdater->nextTimeStep();
VectorType ell(finestSize); VectorType ell(finestSize);
assemble_neumann<GridType, GridView, SmallVector, P1Basis>( assemble_neumann<GridType, GridView, SmallVector, P1Basis>(
leafView, p1Basis, neumannNodes, ell, neumannFunction, time); leafView, p1Basis, neumannNodes, ell, neumannFunction, time);
...@@ -370,6 +388,7 @@ int main(int argc, char *argv[]) { ...@@ -370,6 +388,7 @@ int main(int argc, char *argv[]) {
VectorType problem_rhs(finestSize); VectorType problem_rhs(finestSize);
VectorType problem_iterate(finestSize); VectorType problem_iterate(finestSize);
stateUpdater->setup(tau);
timeSteppingScheme->setup(ell, tau, time, problem_rhs, problem_iterate, timeSteppingScheme->setup(ell, tau, time, problem_rhs, problem_iterate,
problem_A); problem_A);
...@@ -396,23 +415,9 @@ int main(int argc, char *argv[]) { ...@@ -396,23 +415,9 @@ int main(int argc, char *argv[]) {
timeSteppingScheme->extractDisplacement(u); timeSteppingScheme->extractDisplacement(u);
timeSteppingScheme->extractVelocity(ud); timeSteppingScheme->extractVelocity(ud);
// Update the state stateUpdater->solve(ud);
for (size_t i = 0; i < frictionalNodes.size(); ++i) { stateUpdater->extractState(alpha);
if (frictionalNodes[i][0]) {
double const V = ud[i].two_norm();
switch (parset.get<Config::state_model>(
"boundary.friction.state.model")) {
case Config::Dieterich:
alpha[i] =
state_update_dieterich_euler(tau, V / L, alpha_old[i]);
break;
case Config::Ruina:
alpha[i] = state_update_ruina(tau, V * tau / L, alpha_old[i]);
break;
}
}
}
if (parset.get<bool>("printProgress")) { if (parset.get<bool>("printProgress")) {
std::cerr << '.'; std::cerr << '.';
std::cerr.flush(); std::cerr.flush();
...@@ -433,8 +438,6 @@ int main(int argc, char *argv[]) { ...@@ -433,8 +438,6 @@ int main(int argc, char *argv[]) {
std::cerr << std::endl; std::cerr << std::endl;
} }
alpha_old = alpha;
{ // Write all kinds of data { // Write all kinds of data
state_writer << alpha[specialNode][0] << " " << std::endl; state_writer << alpha[specialNode][0] << " " << std::endl;
......
#ifndef RUINA_STATE_UPDATER_HH
#define RUINA_STATE_UPDATER_HH
#include "compute_state_ruina.hh"
#include "stateupdater.hh"
template <class SingletonVectorType, class VectorType>
class RuinaStateUpdater : public StateUpdater<SingletonVectorType, VectorType> {
public:
RuinaStateUpdater(SingletonVectorType _alpha_initial,
Dune::BitSetVector<1> const &_nodes, double _L);
virtual void nextTimeStep();
virtual void setup(double _tau);
virtual void solve(VectorType const &velocity_field);
virtual void extractState(SingletonVectorType &state);
private:
SingletonVectorType alpha_old;
SingletonVectorType alpha;
Dune::BitSetVector<1> const &nodes;
double const L;
double tau;
};
template <class SingletonVectorType, class VectorType>
RuinaStateUpdater<SingletonVectorType, VectorType>::RuinaStateUpdater(
SingletonVectorType _alpha_initial, Dune::BitSetVector<1> const &_nodes,
double _L)
: alpha(_alpha_initial), nodes(_nodes), L(_L) {}
template <class SingletonVectorType, class VectorType>
void RuinaStateUpdater<SingletonVectorType, VectorType>::nextTimeStep() {
alpha_old = alpha;
}
template <class SingletonVectorType, class VectorType>
void RuinaStateUpdater<SingletonVectorType, VectorType>::setup(double _tau) {
tau = _tau;
}
template <class SingletonVectorType, class VectorType>
void RuinaStateUpdater<SingletonVectorType, VectorType>::solve(
VectorType const &velocity_field) {
for (size_t i = 0; i < nodes.size(); ++i)
if (nodes[i][0]) {
double const V = velocity_field[i].two_norm();
alpha[i] = state_update_ruina(tau, V * tau / L, alpha_old[i]);
}
}
template <class SingletonVectorType, class VectorType>
void RuinaStateUpdater<SingletonVectorType, VectorType>::extractState(
SingletonVectorType &state) {
state = alpha;
}
#endif
#ifndef STATE_UPDATER_HH
#define STATE_UPDATER_HH
template <class SingletonVectorType, class VectorType> class StateUpdater {
public:
virtual void nextTimeStep() = 0;
virtual void setup(double _tau) = 0;
virtual void solve(VectorType const &velocity_field) = 0;
virtual void extractState(SingletonVectorType &state) = 0;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment