FiniteElementMesh.h 2.78 KB
Newer Older
1
2
3
#ifndef OERSTED_FINITEELEMENTMESH_H
#define OERSTED_FINITEELEMENTMESH_H

JasonPries's avatar
JasonPries committed
4
#include <memory>
5
6
#include <vector>

7
#include "Boundary.h"
8
#include "MatrixGroup.h"
9
10
#include "Node.h"
#include "Triangle.h"
JasonPries's avatar
JasonPries committed
11
#include "Region.h"
12

JasonPries's avatar
JasonPries committed
13
template<size_t Dimension, size_t Order>
JasonPries's avatar
JasonPries committed
14
class FiniteElementMesh {};
15

JasonPries's avatar
JasonPries committed
16
17
template<size_t Order>
class FiniteElementMesh<2,Order> {
18
public:
JasonPries's avatar
JasonPries committed
19
20
    FiniteElementMesh() {};

JasonPries's avatar
JasonPries committed
21
22
23
    FiniteElementMesh(std::vector<XY> nodes, std::vector<Triangle<Order>> tris,
                      std::vector<std::shared_ptr<Region<2>>> r, std::vector<std::shared_ptr<Boundary<2>>> b)
            : Nodes(nodes), Triangles(tris), Regions(r), Boundaries(b) {};
24

JasonPries's avatar
JasonPries committed
25
26
    size_t size_nodes() const { return Nodes.size(); };

JasonPries's avatar
JasonPries committed
27
    std::vector<XY> const &nodes() const { return Nodes; };
JasonPries's avatar
JasonPries committed
28

JasonPries's avatar
JasonPries committed
29
30
31
32
    XY const &node(size_t i) const { return Nodes[i]; };

    size_t size_elements() const { return Triangles.size(); };

JasonPries's avatar
JasonPries committed
33
    std::vector<Triangle<Order>> const &triangles() const { return Triangles; };
JasonPries's avatar
JasonPries committed
34

JasonPries's avatar
JasonPries committed
35
    Triangle<Order> const &triangle(size_t i) const { return Triangles[i]; };
JasonPries's avatar
JasonPries committed
36

JasonPries's avatar
JasonPries committed
37
    auto &regions() { return Regions; };
JasonPries's avatar
JasonPries committed
38

JasonPries's avatar
JasonPries committed
39
    auto &region(size_t i) { return Regions[i]; };
JasonPries's avatar
JasonPries committed
40

JasonPries's avatar
JasonPries committed
41
42
43
44
45
46
47
    auto const &regions() const { return Regions; };

    auto const &region(size_t i) const { return Regions[i]; };

    auto &boundaries() {return Boundaries;};

    auto &boundary(size_t i) {return Boundaries[i];};
JasonPries's avatar
JasonPries committed
48

JasonPries's avatar
JasonPries committed
49
    auto const &boundaries() const { return Boundaries; };
JasonPries's avatar
JasonPries committed
50

JasonPries's avatar
JasonPries committed
51
    auto const &boundary(size_t i) const { return Boundaries[i]; };
JasonPries's avatar
JasonPries committed
52

53
    template<size_t Q>
54
55
    DiagonalMatrixGroup<TriangleQuadrature<Q>::size> determinant() const {
        DiagonalMatrixGroup<TriangleQuadrature<Q>::size> mat(Triangles.size());
56
57
58
59
60
61
62
63

        for (size_t i = 0; i != Triangles.size(); ++i) {
            Triangles[i].determinant<Q>(mat, Nodes);
        }

        return mat;
    }

JasonPries's avatar
JasonPries committed
64
    template<size_t Q>
65
66
    SparseMatrixGroup<TriangleQuadrature<Q>::size> basis() const {
        SparseMatrixGroup<TriangleQuadrature<Q>::size> mat(Nodes.size(), Triangles.size(), Triangle<Order>::NumNodes);
JasonPries's avatar
JasonPries committed
67
68

        for (size_t i = 0; i != Triangles.size(); ++i) {
69
            Triangles[i].basis<Q>(mat, Nodes);
JasonPries's avatar
JasonPries committed
70
71
72
        }

        return mat;
73
    }
JasonPries's avatar
JasonPries committed
74
75

    template<size_t Q>
76
77
    DerivativeMatrixGroup<TriangleQuadrature<Q>::size> derivative() const {
        DerivativeMatrixGroup<TriangleQuadrature<Q>::size> df(Nodes.size(), Triangles.size(), Triangle<Order>::NumNodes);
JasonPries's avatar
JasonPries committed
78
79

        for (size_t i = 0; i!= Triangles.size();++i) {
80
            Triangles[i].derivative<Q>(df, Nodes);
JasonPries's avatar
JasonPries committed
81
        }
82

JasonPries's avatar
JasonPries committed
83
84
        return df;
    }
85
86
87

protected:
    std::vector<XY> Nodes;
JasonPries's avatar
JasonPries committed
88
89
    std::vector<Triangle<Order>> Triangles;

JasonPries's avatar
JasonPries committed
90
91
    std::vector<std::shared_ptr<Region<2>>> Regions; // Contains vector of size_t referencing Triangles (and later Quadrilaterals)
    std::vector<std::shared_ptr<Boundary<2>>> Boundaries;
92
93
94
};

#endif //OERSTED_FINITEELEMENTMESH_H