From 8af6ef52ea47eb53a3251072ce836397abf3add9 Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Mon, 29 Oct 2012 17:17:05 +0100 Subject: [PATCH] Determine schemes outside of main() --- src/one-body-sample.cc | 91 +++++++++++++++++++++++------------------- 1 file changed, 50 insertions(+), 41 deletions(-) diff --git a/src/one-body-sample.cc b/src/one-body-sample.cc index 8be52082..e12475a4 100644 --- a/src/one-body-sample.cc +++ b/src/one-body-sample.cc @@ -133,6 +133,49 @@ void setup_boundary(GridView const &gridView, } } +template <class VectorType, class MatrixType, class FunctionType, int dim> +Dune::shared_ptr<TimeSteppingScheme<VectorType, MatrixType, FunctionType, dim>> +initTimeStepper(Config::scheme scheme, FunctionType const &dirichletFunction, + Dune::BitSetVector<dim> const &ignoreNodes, + MatrixType const &massMatrix, MatrixType const &stiffnessMatrix, + VectorType const &u_initial, VectorType const &ud_initial, + VectorType const &udd_initial) { + switch (scheme) { + case Config::ImplicitTwoStep: + return Dune::make_shared< + ImplicitTwoStep<VectorType, MatrixType, FunctionType, dim>>( + stiffnessMatrix, u_initial, ud_initial, ignoreNodes, + dirichletFunction); + case Config::ImplicitEuler: + return Dune::make_shared< + ImplicitEuler<VectorType, MatrixType, FunctionType, dim>>( + stiffnessMatrix, u_initial, ud_initial, ignoreNodes, + dirichletFunction); + case Config::Newmark: + return Dune::make_shared< + Newmark<VectorType, MatrixType, FunctionType, dim>>( + stiffnessMatrix, massMatrix, u_initial, ud_initial, udd_initial, + ignoreNodes, dirichletFunction); + } +} + +template <class SingletonVectorType, class VectorType> +Dune::shared_ptr<StateUpdater<SingletonVectorType, VectorType>> +initStateUpdater(Config::state_model model, + SingletonVectorType const &alpha_initial, + Dune::BitSetVector<1> const &frictionalNodes, double L) { + switch (model) { + case Config::Dieterich: + return Dune::make_shared< + DieterichStateUpdater<SingletonVectorType, VectorType>>( + alpha_initial, frictionalNodes, L); + case Config::Ruina: + return Dune::make_shared< + RuinaStateUpdater<SingletonVectorType, VectorType>>( + alpha_initial, frictionalNodes, L); + } +} + int main(int argc, char *argv[]) { try { typedef SharedPointerMap<std::string, Dune::VirtualFunction<double, double>> @@ -329,47 +372,13 @@ int main(int argc, char *argv[]) { first_frictional_node < frictionalNodes.size()) ++first_frictional_node; - Dune::shared_ptr<TimeSteppingScheme< - VectorType, MatrixType, Dune::VirtualFunction<double, double>, dim>> - timeSteppingScheme; - switch (parset.get<Config::scheme>("timeSteppingScheme")) { - case Config::ImplicitTwoStep: - timeSteppingScheme = Dune::make_shared< - ImplicitTwoStep<VectorType, MatrixType, - Dune::VirtualFunction<double, double>, dim>>( - stiffnessMatrix, u_initial, ud_initial, ignoreNodes, - dirichletFunction); - break; - case Config::ImplicitEuler: - timeSteppingScheme = Dune::make_shared< - ImplicitEuler<VectorType, MatrixType, - Dune::VirtualFunction<double, double>, dim>>( - stiffnessMatrix, u_initial, ud_initial, ignoreNodes, - dirichletFunction); - break; - case Config::Newmark: - timeSteppingScheme = Dune::make_shared< - Newmark<VectorType, MatrixType, - Dune::VirtualFunction<double, double>, dim>>( - stiffnessMatrix, massMatrix, u_initial, ud_initial, udd_initial, - ignoreNodes, dirichletFunction); - 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 timeSteppingScheme = + initTimeStepper(parset.get<Config::scheme>("timeSteppingScheme"), + dirichletFunction, ignoreNodes, massMatrix, + stiffnessMatrix, u_initial, ud_initial, udd_initial); + auto stateUpdater = initStateUpdater<SingletonVectorType, VectorType>( + parset.get<Config::state_model>("boundary.friction.state.model"), + alpha_initial, frictionalNodes, L); auto const state_fpi_max = parset.get<size_t>("solver.tnnmg.fixed_point_iterations"); -- GitLab