BoundaryCondition.h 1.5 KB
Newer Older
JasonPries's avatar
JasonPries committed
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
#ifndef OERSTED_BOUNDARYCONDITION_H
#define OERSTED_BOUNDARYCONDITION_H

#include <vector>
#include <set>
#include <algorithm>

#include <Eigen/Sparse>

#include "MatrixGroup.h"
#include "QuadratureRule.h"
#include "FiniteElementMesh.h"

class BoundaryCondition {
public:
    BoundaryCondition(std::vector<size_t> boundaries) : Boundaries{boundaries} {};
    virtual ~BoundaryCondition(){};

    virtual void apply(std::vector<Eigen::Triplet<double>> &triplets) const = 0;
    virtual void reduce(std::set<size_t,std::greater<size_t>> &index) const = 0;

protected:
    std::vector<size_t> Boundaries;
};


template<size_t Dimension, size_t ElementOrder, size_t QuadratureOrder>
class ZeroDirichlet : public BoundaryCondition{};

template<size_t ElementOrder, size_t QuadratureOrder>
class ZeroDirichlet<2,ElementOrder,QuadratureOrder> : public BoundaryCondition {
public:
    ZeroDirichlet(std::vector<size_t> boundaries,
                  FiniteElementMesh<2,ElementOrder> const &domain) : BoundaryCondition{boundaries} {

        for(size_t i : boundaries) {
            for(size_t j : domain.boundary(i).nodes()) {
                Nodes.push_back(j);
            }
        }
    };

    void apply(std::vector<Eigen::Triplet<double>> &triplets) const override {};

    void reduce(std::set<size_t,std::greater<size_t>> &index) const override {
        for (size_t i = 0; i != Nodes.size(); ++i) {
            index.insert(Nodes[i]);
        }
    };

protected:
    std::vector<size_t> Nodes;
};
#endif //OERSTED_BOUNDARYCONDITION_H