Mesh.hpp 3.27 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#pragma once

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <array>
#include <memory>

#include <dune/common/fvector.hh>

#include <dune/grid/albertagrid.hh>
#include <dune/grid/uggrid.hh>
#include <dune/grid/yaspgrid.hh>

#include "Initfile.hpp"
#include "Log.hpp"

namespace AMDiS
{
  struct _albertagrid {};
  struct _uggrid {};
  struct _yaspgrid {};
  struct _unknowngrid {};

  template <class Grid>
  struct MeshTagImpl
  {
    using type = _unknowngrid;
  };
  
  template <class Grid>
  using MeshTag = typename MeshTagImpl<Grid>::type;
  
  // specialization for some grid types from DUNE
#if HAVE_ALBERTA
  template <int dim, int dimworld>
  struct MeshTagImpl<Dune::AlbertaGrid<dim, dimworld>>
  {
    using type = _albertagrid;
  };
#endif
  
#if HAVE_UG
  template <int dim>
  struct MeshTagImpl<Dune::UGGrid<dim>>
  {
    using type = _uggrid;
  };
#endif
  
  template <int dim, class Coordinates>
  struct MeshTagImpl<Dune::YaspGrid<dim, Coordinates>>
  {
    using type = _yaspgrid;
  };
  
  
  template <class Grid>
  class MeshCreator
  {
    static std::unique_ptr<Grid> create(std::string meshName)
    {
      AMDIS_ERROR_EXIT("Not yet implemented");
    }
  };
    
#if HAVE_ALBERTA
  template <int dim, int dimworld>
  struct MeshCreator<Dune::AlbertaGrid<dim, dimworld>>
  {
    using Grid = Dune::AlbertaGrid<dim, dimworld>;
    
    static std::unique_ptr<Grid> create(std::string meshName)
    {
      std::string macro_filename = "";
      Parameters::get(meshName + "->macro file name", macro_filename);

      // TODO: if filename_extension is ".2d" or ".3d" read it directly from file
      // otherwise use a factory method
      
      return std::make_unique<Grid>(macro_filename);
    }
  };
#endif
  
  
  template <int dim, class T>
  struct MeshCreator<Dune::YaspGrid<dim, Dune::EquidistantCoordinates<T,dim>>>
  {
    using Grid = Dune::YaspGrid<dim, Dune::EquidistantCoordinates<T,dim>>;
    
    static std::unique_ptr<Grid> create(std::string meshName)
    {
      Dune::FieldVector<double, dim> L; L = 1.0;  // extension of the domain
      Parameters::get(meshName + "->dimension", L);
      
      AMDIS_MSG("L = " << L);
      
      std::array<int, dim> s; // number of cells on coarse mesh in each direction
      Parameters::get(meshName + "->num cells", s);
      
      // TODO: add more parameters for yasp-grid (see constructor)
      
      return std::make_unique<Grid>(L, s);
    }
  };
  
  
  template <int dim, class T>
  struct MeshCreator<Dune::YaspGrid<dim, Dune::EquidistantOffsetCoordinates<T, dim>>>
  {
    using Grid = Dune::YaspGrid<dim, Dune::EquidistantOffsetCoordinates<T, dim>>;
    
    static std::unique_ptr<Grid> create(std::string meshName)
    {
      Dune::FieldVector<double, dim> lowerleft;  // Lower left corner of the domain
      Dune::FieldVector<double, dim> upperright; // Upper right corner of the domain
      Parameters::get(meshName + "->min corner", lowerleft);
      Parameters::get(meshName + "->max corner", upperright);
      
      std::array<int, dim> s; // number of cells on coarse mesh in each direction
      Parameters::get(meshName + "->num cells", s);
      
      // TODO: add more parameters for yasp-grid (see constructor)
      
      return std::make_unique<Grid>(lowerleft, upperright, s);
    }
  };

} // end namespace AMDiS