DirichletBC.hpp 1.73 KB
Newer Older
1
2
3
4
5
6
7
8
#pragma once

#include <functional>
#include <type_traits>
#include <vector>

#include <dune/functions/common/functionconcepts.hh>

9
10
11
#include "Log.hpp"
#include "Traits.hpp"

12
13
14
15
16
17
18
namespace AMDiS
{
  template <class WorldVector>
  class DirichletBC
  {
  public:
    template <class Predicate, class Values,
19
20
      class = std::enable_if_t< Dune::Functions::Concept::isFunction<Predicate, bool(WorldVector)>() &&
				Dune::Functions::Concept::isFunction<Values,  double(WorldVector)>() > >
21
22
    DirichletBC(Predicate&& predicate, Values&& values)
      : predicate(std::forward<Predicate>(predicate))
23
      , values(std::forward<Values>(values))
24
25
26
    {}
    
    
27
    template <class RowFeSpace, class ColFeSpace, class Matrix, class Vector1, class Vector2>
28
29
30
    void init(bool apply, 
	      RowFeSpace const& rowFeSpace, 
	      ColFeSpace const& colFeSpace, 
31
32
33
	      Matrix* matrix, 
	      Vector1* rhs, 
	      Vector2* solution);
34
35
    
    
36
    template <class RowFeSpace, class ColFeSpace, class Matrix, class Vector1, class Vector2>
37
38
39
    void finish(bool apply, 
		RowFeSpace const& rowFeSpace, 
		ColFeSpace const& colFeSpace, 
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
		Matrix* matrix, 
		Vector1* rhs, 
		Vector2* solution);
    
  protected:
    template <class Iter, class Category>
    void setIdentity(bool condition, Iter cIt, Category)
    {
	AMDIS_ERROR_EXIT("Unknown block-type!");
    }
    
    template <class Iter>
    void setIdentity(bool condition, Iter cIt, _scalar);
    
    template <class Iter>
    void setIdentity(bool condition, Iter cIt, _vector);
56
57
58
59
60
61
62
63
64
65
66
67
    
  private:
    std::function<bool(WorldVector)> predicate;
    std::function<double(WorldVector)> values;
    
    bool initialized = false;
    std::vector<char> dirichletNodes;
  };

} // end namespace AMDiS

#include "DirichletBC.inc.hpp"