BoundaryCondition.h 2.6 KB
Newer Older
JasonPries's avatar
JasonPries committed
1
2
3
4
5
6
7
8
9
10
11
12
13
#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"

JasonPries's avatar
JasonPries committed
14
15
16
// TODO: DiscreteBoundaryCondition versus ContinuousBoundaryCondition? Somehow need to apply to top level model and have that be translated to the discrete model
// TODO: Boundary conditions should represent simple containers that know how to perform actions on matrices, parsing of boundaries to extract nodes should take place at a higher level

JasonPries's avatar
JasonPries committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class BoundaryCondition {
public:
    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;
};

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:
JasonPries's avatar
JasonPries committed
31
    ZeroDirichlet(std::vector<size_t> nodes) : Nodes{nodes} {};
JasonPries's avatar
JasonPries committed
32
33
34
35
36
37
38
39
40
41
42
43

    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;
};
JasonPries's avatar
JasonPries committed
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


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

template<size_t ElementOrder, size_t QuadratureOrder>
class PeriodicBoundaryCondition<2,ElementOrder,QuadratureOrder> : public BoundaryCondition {
public:
    PeriodicBoundaryCondition(std::vector<size_t> first_nodes, std::vector<size_t> second_nodes, bool antiperiodic) : FirstNodes{first_nodes}, SecondNodes{second_nodes}, Antiperiodic{antiperiodic} {};

    void apply(std::vector<Eigen::Triplet<double>> &triplets) const override {
        double sign{1.0 - 2.0 * Antiperiodic};

        // TODO:
        /*
        for(size_t i = 0;i!=FirstNodes.size();++i){
            triplets[FirstNodes[i]].row() = SecondNodes[i];
            triplest[FirstNodes[i]].value() = sign;
         }
         */
    }

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

protected:
    std::vector<size_t> FirstNodes;
    std::vector<size_t> SecondNodes;

    bool Antiperiodic;
};


JasonPries's avatar
JasonPries committed
80
#endif //OERSTED_BOUNDARYCONDITION_H