DiscreteBoundary.h 3.87 KB
Newer Older
JasonPries's avatar
JasonPries committed
1 2 3
#ifndef OERSTED_BOUNDARY_H
#define OERSTED_BOUNDARY_H

4 5 6
#include <vector>
#include <cstddef>

7 8
#include <Sketch.hpp>

JasonPries's avatar
JasonPries committed
9
template<size_t Dimension>
JasonPries's avatar
JasonPries committed
10 11 12 13 14
class DiscreteBoundary {
};

template<size_t Dimension>
class DiscontinuousBoundary : public DiscreteBoundary<Dimension> {
JasonPries's avatar
JasonPries committed
15 16 17
};

template<>
JasonPries's avatar
JasonPries committed
18
class DiscreteBoundary<2> {
JasonPries's avatar
JasonPries committed
19
public:
JasonPries's avatar
JasonPries committed
20
    DiscreteBoundary() {};
21

22
    DiscreteBoundary(std::vector<size_t> nodes, bool closed = false) : CurvePtr{nullptr}, Nodes{nodes}, Closed{closed} {};
23

24 25 26
    DiscreteBoundary(std::shared_ptr<Curve const> cptr, std::vector<size_t> nodes, bool closed = false) : CurvePtr{cptr}, Nodes{nodes}, Closed{closed} {};

    virtual ~DiscreteBoundary() {};
JasonPries's avatar
JasonPries committed
27

JasonPries's avatar
JasonPries committed
28 29
    size_t size() const { return Nodes.size(); };

JasonPries's avatar
JasonPries committed
30
    std::vector<size_t> nodes() { return Nodes; };
JasonPries's avatar
JasonPries committed
31

JasonPries's avatar
JasonPries committed
32
    std::vector<size_t> const &nodes() const { return Nodes; };
JasonPries's avatar
JasonPries committed
33

JasonPries's avatar
JasonPries committed
34
    size_t node(size_t i) { return Nodes[i]; };
JasonPries's avatar
JasonPries committed
35

JasonPries's avatar
JasonPries committed
36
    size_t const &node(size_t i) const { return Nodes[i]; };
JasonPries's avatar
JasonPries committed
37

JasonPries's avatar
JasonPries committed
38
    std::shared_ptr<Curve const> curve() const { return CurvePtr; };
39

40 41
    bool is_closed() const { return Closed; };

JasonPries's avatar
JasonPries committed
42
protected:
43
    std::shared_ptr<Curve const> CurvePtr;
JasonPries's avatar
JasonPries committed
44
    std::vector<size_t> Nodes;
45
    bool Closed;
JasonPries's avatar
JasonPries committed
46 47
};

JasonPries's avatar
JasonPries committed
48 49 50 51 52
template<>
class DiscontinuousBoundary<2> : public DiscreteBoundary<2> {
public:
    DiscontinuousBoundary() {};

53
    DiscontinuousBoundary(std::vector<size_t> nodes, std::vector<size_t> dnodes, std::vector<double_t> vals, bool closed = false) : DiscreteBoundary{nodes, closed}, DiscontinuousNodes{dnodes}, Values{vals} {};
JasonPries's avatar
JasonPries committed
54

55
    DiscontinuousBoundary(std::shared_ptr<Curve const> cptr, std::vector<size_t> nodes, std::vector<size_t> dnodes, std::vector<double_t> vals, bool closed = false) : DiscreteBoundary{cptr, nodes, closed}, DiscontinuousNodes{dnodes}, Values{vals} {};
JasonPries's avatar
JasonPries committed
56 57 58 59 60 61 62 63 64 65 66

    std::vector<size_t> dnodes() { return DiscontinuousNodes; };

    std::vector<size_t> const &dnodes() const { return DiscontinuousNodes; };

    std::vector<double_t> values() { return Values; };

    std::vector<double_t> const &values() const { return Values; };

    size_t dnode(size_t i) { return DiscontinuousNodes[i]; };

67
    size_t const &dnode(size_t i) const { return DiscontinuousNodes[i]; };
JasonPries's avatar
JasonPries committed
68 69 70 71 72 73

protected:
    std::vector<size_t> DiscontinuousNodes;
    std::vector<double_t> Values;
};

JasonPries's avatar
JasonPries committed
74
/*
JasonPries's avatar
JasonPries committed
75
template <size_t Dimension>
JasonPries's avatar
JasonPries committed
76
class BoundaryPair {};
JasonPries's avatar
JasonPries committed
77

JasonPries's avatar
JasonPries committed
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
template <>
class BoundaryPair<2> {
public:
    BoundaryPair(std::shared_ptr<Boundary<2>> first, std::shared_ptr<Boundary<2>> second) : First{first}, Second{second} {};

    std::shared_ptr<Boundary<2>> const &first() { return First; };

    std::shared_ptr<Boundary<2>> const &second() { return Second; };

protected:
    std::shared_ptr<Boundary<2>> First;
    std::shared_ptr<Boundary<2>> Second;
};
*/

class VariableMap {
public:
95
    VariableMap(size_t first, size_t second, double value) : First{std::min(first, second)}, Second{std::max(first, second)}, Value{value} {};
JasonPries's avatar
JasonPries committed
96 97 98 99 100

    size_t first() const { return First; };

    size_t second() const { return Second; };

101 102 103
    double_t value() const { return Value; };

    void value(double_t value) { Value = value; };
JasonPries's avatar
JasonPries committed
104

105 106 107 108 109 110 111 112
    inline bool operator==(VariableMap const &rhs) {
        return (First == rhs.First && Second == rhs.Second && Value == rhs.Value);
    }

    inline bool operator<(VariableMap const &rhs) {
        return (First < rhs.First) || (First == rhs.First && Second < rhs.Second);
    }

JasonPries's avatar
JasonPries committed
113 114 115
protected:
    size_t First;
    size_t Second;
116
    double_t Value;
JasonPries's avatar
JasonPries committed
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
};

class BoundaryMap {
public:
    BoundaryMap(std::vector<VariableMap> map) : Map{map} {};

    size_t size() const { return Map.size(); };

    VariableMap const &map(size_t i) const { return Map[i]; };

    std::vector<VariableMap> const &map() const { return Map; };

    size_t first(size_t i) const { return Map[i].first(); };

    size_t second(size_t i) const { return Map[i].second(); };

    double value(size_t i) const { return Map[i].value(); };

protected:
    std::vector<VariableMap> Map;
JasonPries's avatar
JasonPries committed
137 138
};

JasonPries's avatar
JasonPries committed
139
#endif //OERSTED_BOUNDARY_H