BoundaryCondition.h 2.74 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<std::shared_ptr<Boundary<2>>> boundaries) : Boundaries{boundaries} {};
JasonPries's avatar
JasonPries committed
32
33
34
35

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

    void reduce(std::set<size_t,std::greater<size_t>> &index) const override {
JasonPries's avatar
JasonPries committed
36
37
38
39
        for (auto const& b : Boundaries) {
            for (auto const& i : b->nodes()) {
                index.insert(i);
            }
JasonPries's avatar
JasonPries committed
40
41
42
43
        }
    };

protected:
JasonPries's avatar
JasonPries committed
44
    std::vector<std::shared_ptr<Boundary<2>>> Boundaries;
JasonPries's avatar
JasonPries committed
45
};
JasonPries's avatar
JasonPries committed
46
47
48
49
50
51
52
53


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:
JasonPries's avatar
JasonPries committed
54
    PeriodicBoundaryCondition(std::vector<std::shared_ptr<BoundaryPair<2>>> boundary_pairs, bool antiperiodic) : BoundaryPairs{boundary_pairs}, Antiperiodic{antiperiodic} {};
JasonPries's avatar
JasonPries committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68

    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 {
JasonPries's avatar
JasonPries committed
69
70
71
72
73
        /*
        for (auto const &bp : BoundaryPairs) {
            for(auto const &ij : bp->nodes()) {
                index.insert(ij.second);
            }
JasonPries's avatar
JasonPries committed
74
        }
JasonPries's avatar
JasonPries committed
75
         */
JasonPries's avatar
JasonPries committed
76
77
78
    }

protected:
JasonPries's avatar
JasonPries committed
79
    std::vector<std::shared_ptr<BoundaryPair<2>>> BoundaryPairs;
JasonPries's avatar
JasonPries committed
80
81
82
83
84

    bool Antiperiodic;
};


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