test-mass-conservation.cc 3.08 KB
Newer Older
1 2 3 4 5 6
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
#ifdef HAVE_CONFIG_H
  #include "config.h"
#endif

#include <dune/dorie/dorie.hh>
7
#include <dune/dorie/test/test-mass-conservation.hh>
8 9 10 11 12 13 14 15 16 17 18

namespace Dune{
namespace Dorie{
  /// Resolve the second (default) template parameter of YaspGrid
  template<int dim>
  using YaspGrid = Dune::YaspGrid<dim>;
}
}

template<int dim, int order>
using Simplex = Dune::Dorie::BaseTraits<Dune::UGGrid,
19
  Dune::GeometryType::BasicType::simplex,dim,order,false,false>;
20 21 22

template<int dim, int order>
using SimplexAdaptive = Dune::Dorie::BaseTraits<Dune::UGGrid,
23
  Dune::GeometryType::BasicType::simplex,dim,order,false,true>;
24 25 26

template<int dim, int order>
using Cube = Dune::Dorie::BaseTraits<Dune::Dorie::YaspGrid,
27
  Dune::GeometryType::BasicType::cube,dim,order,false,false>;
28 29 30

template<int dim, int order>
using CubeAdaptive = Dune::Dorie::BaseTraits<Dune::UGGrid,
31
  Dune::GeometryType::BasicType::cube,dim,order,false,true>;
32 33 34

int main (int argc, char** argv)
{
35 36 37
  try{
    // initialize MPI if needed
    auto& helper = Dune::MPIHelper::instance(argc, argv);
38

39 40 41 42 43 44 45 46
    // Read ini file
    if (argc!=2)
      DUNE_THROW(Dune::IOError,
        "Call this program with arguments <config>");
    const std::string inifilename = argv[1];
    Dune::ParameterTree inifile;
    Dune::ParameterTreeParser ptreeparser;
    ptreeparser.readINITree(inifilename,inifile);
47

48
    const double limit = inifile.get<double>("limit");
49

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    // run test
    double result {0.0};
    const auto adaptive = inifile.get<bool>("adaptivity.useAdaptivity");
    const auto grid_type = inifile.get<std::string>("grid.gridType");
    if (adaptive) {
      if (grid_type == "rectangular") {
        using TestSim = Dune::Dorie::TestSimulation<CubeAdaptive<2, 1>>;
        auto grid = Dune::Dorie::build_grid_cube<Dune::UGGrid<2>>(inifile, helper);
        TestSim sim(helper, grid, inifile);
        result = sim.run_test();
      }
      else if (grid_type == "simplex") {
        using TestSim = Dune::Dorie::TestSimulation<SimplexAdaptive<2, 1>>;
        auto grid = Dune::Dorie::build_grid_gmsh<Dune::UGGrid<2>>(inifile, helper);
        TestSim sim(helper, grid, inifile);
        result = sim.run_test();
      }
67
    }
68 69 70 71 72 73 74 75 76 77 78 79 80
    else {
      if (grid_type == "rectangular") {
        using TestSim = Dune::Dorie::TestSimulation<Cube<2, 1>>;
        auto grid = Dune::Dorie::build_grid_cube<Dune::YaspGrid<2>>(inifile, helper);
        TestSim sim(helper, grid, inifile);
        result = sim.run_test();
      }
      else if (grid_type == "simplex") {
        using TestSim = Dune::Dorie::TestSimulation<Simplex<2, 1>>;
        auto grid = Dune::Dorie::build_grid_gmsh<Dune::UGGrid<2>>(inifile, helper);
        TestSim sim(helper, grid, inifile);
        result = sim.run_test();
      }
81
    }
82 83 84 85 86 87

    if (std::abs(result) > limit) {
      std::cerr << "Mass conservation test exceeded limit!" << std::endl;
      std::cerr << "Limit: " << limit << std::endl;
      std::cerr << "Result: " << result << std::endl;
      return 2;
88 89 90
    }
  }

91 92
  catch(...) {
    std::cerr << "Exception occurred!" << std::endl;
93 94
    return 1;
  }
95 96 97

  return 0;
}