From 30a2e434f5da4c2feb023d42126ef099daa0825e Mon Sep 17 00:00:00 2001 From: Elias Pipping <elias.pipping@fu-berlin.de> Date: Wed, 16 May 2012 15:24:32 +0200 Subject: [PATCH] Use enum parser for model as well --- src/assemblers.cc | 58 ++++++++++++++++++++------------------ src/enum_model.cc | 13 +++++++++ src/enums.hh | 4 +++ src/one-body-sample.parset | 2 +- 4 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 src/enum_model.cc diff --git a/src/assemblers.cc b/src/assemblers.cc index f8485a49..972c5512 100644 --- a/src/assemblers.cc +++ b/src/assemblers.cc @@ -12,6 +12,10 @@ #include "assemblers.hh" +#include "enums.hh" +#include "enum_parser.cc" +#include "enum_model.cc" + // Assembles Neumann boundary term in f template <class GridType, class GridView, class LocalVectorType, class FEBasis> void assemble_neumann(GridView const &gridView, FEBasis const &feBasis, @@ -67,34 +71,32 @@ assemble_nonlinearity( auto normalStress = Dune::make_shared<SingletonVectorType>(size); *normalStress = parset.get<double>("normalstress"); - std::string const friction_model = parset.get<std::string>("model"); - if (friction_model == std::string("Ruina")) { - auto a = Dune::make_shared<SingletonVectorType>(size); - *a = parset.get<double>("ruina.a"); - - auto eta = Dune::make_shared<SingletonVectorType>(size); - *eta = parset.get<double>("eta"); - - auto b = Dune::make_shared<SingletonVectorType>(size); - *b = parset.get<double>("ruina.b"); - - auto L = Dune::make_shared<SingletonVectorType>(size); - *L = parset.get<double>("ruina.L"); - - return Dune::make_shared< - Dune::GlobalRuinaNonlinearity<VectorType, MatrixType> const>( - nodalIntegrals, a, mu, eta, normalStress, b, state, L, h); - } else if (friction_model == std::string("Laursen")) { - return - // TODO: take state and h into account - // FIXME: We should be using a quadratic rather than a linear function - // here! - Dune::make_shared< - Dune::GlobalLaursenNonlinearity<Dune::LinearFunction, VectorType, - MatrixType> const>(mu, normalStress, - nodalIntegrals); - } else { - assert(false); + switch (parset.get<Config::model>("model")) { + case Config::Exponential: { + auto a = Dune::make_shared<SingletonVectorType>(size); + *a = parset.get<double>("ruina.a"); + + auto eta = Dune::make_shared<SingletonVectorType>(size); + *eta = parset.get<double>("eta"); + + auto b = Dune::make_shared<SingletonVectorType>(size); + *b = parset.get<double>("ruina.b"); + + auto L = Dune::make_shared<SingletonVectorType>(size); + *L = parset.get<double>("ruina.L"); + + return Dune::make_shared< + Dune::GlobalRuinaNonlinearity<VectorType, MatrixType> const>( + nodalIntegrals, a, mu, eta, normalStress, b, state, L, h); + } + case Config::Laursen: + return + // TODO: take state and h into account + // FIXME: We should be using a quadratic rather than a linear function + // here! + Dune::make_shared<Dune::GlobalLaursenNonlinearity< + Dune::LinearFunction, VectorType, + MatrixType> const>(mu, normalStress, nodalIntegrals); } } diff --git a/src/enum_model.cc b/src/enum_model.cc new file mode 100644 index 00000000..1fd1bc1d --- /dev/null +++ b/src/enum_model.cc @@ -0,0 +1,13 @@ +#include <dune/common/exceptions.hh> + +template <> struct StringToEnum<Config::model> { + static Config::model convert(std::string const &s) { + if (s == "Laursen") + return Config::Laursen; + + if (s == "Exponential") + return Config::Exponential; + + DUNE_THROW(Dune::Exception, "failed to parse enum"); + } +}; diff --git a/src/enums.hh b/src/enums.hh index ce43a1f0..d182db67 100644 --- a/src/enums.hh +++ b/src/enums.hh @@ -1,4 +1,8 @@ struct Config { + enum model { + Laursen, + Exponential + }; enum state_model { Dieterich, Ruina diff --git a/src/one-body-sample.parset b/src/one-body-sample.parset index 58fa7b79..1e89999d 100644 --- a/src/one-body-sample.parset +++ b/src/one-body-sample.parset @@ -68,7 +68,7 @@ normalstress = 0.1 # laursen depends a lot more on this # http://earthquake.usgs.gov/research/physics/lab/prediction.pdf mu = 0.5 eta = 1 -model = Ruina +model = Exponential [boundary.friction.state] evolve = true -- GitLab