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 "MatrixGroup.h"
8
9
#include "Node.h"
#include "Triangle.h"
JasonPries's avatar
JasonPries committed
10
#include "Region.h"
11

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

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

JasonPries's avatar
JasonPries committed
20
21
22
    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) {};
23

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

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

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

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

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

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

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

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

JasonPries's avatar
JasonPries committed
40
41
42
43
44
45
46
    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
47

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

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

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

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

        return mat;
    }

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

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

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

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

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

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

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

JasonPries's avatar
JasonPries committed
89
90
    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;
91
92
93
};

#endif //OERSTED_FINITEELEMENTMESH_H