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

Use Carsten's enum parser

parent dcebc8a1
No related branches found
No related tags found
No related merge requests found
// Copyright Carsten Graeser 2012
#include <dune/common/exceptions.hh>
#include <dune/common/typetraits.hh>
template <class EnumType> struct StringToEnum : public Dune::NotImplemented {};
template <class EnumType>
typename Dune::enable_if<
!Dune::IsBaseOf<Dune::NotImplemented, StringToEnum<EnumType>>::value,
std::istream &>::type
operator>>(std::istream &lhs, EnumType &e) {
std::string s;
lhs >> s;
try {
e = StringToEnum<EnumType>::convert(s);
}
catch (typename Dune::Exception) {
lhs.setstate(std::ios_base::failbit);
}
return lhs;
}
#include <dune/common/exceptions.hh>
template <> struct StringToEnum<Config::state_model> {
static Config::state_model convert(std::string const &s) {
if (s == "Dieterich")
return Config::Dieterich;
if (s == "Ruina")
return Config::Ruina;
DUNE_THROW(Dune::Exception, "failed to parse enum");
}
};
struct Config {
enum state_model {
Dieterich,
Ruina
};
};
......@@ -67,6 +67,10 @@
#include "mysolver.hh"
#include "vtk.hh"
#include "enums.hh"
#include "enum_parser.cc"
#include "enum_state_model.cc"
int const dim = 2;
template <class GridView>
......@@ -300,14 +304,16 @@ int main(int argc, char *argv[]) {
// velocity
// std::cout << std::log(L/unorm * h) << std::endl;
auto const model =
parset.get<std::string>("boundary.friction.state.model");
if (model == std::string("Dieterich"))
(*s4_new)[i] = state_update_dieterich(h, unorm / L, s4_old[i]);
else if (model == std::string("Ruina"))
(*s4_new)[i] = state_update_ruina(h, unorm / L, s4_old[i]);
else
assert(false);
switch (parset.get<Config::state_model>(
"boundary.friction.state.model")) {
case Config::Dieterich:
(*s4_new)[i] =
state_update_dieterich(h, unorm / L, s4_old[i]);
break;
case Config::Ruina:
(*s4_new)[i] = state_update_ruina(h, unorm / L, s4_old[i]);
break;
}
}
}
if (parset.get<bool>("printProgress")) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment