FiniteElementMesh.h 3.04 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
8
#include "Mesh.hpp"

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

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

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

23
24
25
    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) {};

    FiniteElementMesh(Mesh &m);
26

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

JasonPries's avatar
JasonPries committed
29
30
    size_t size_elements() const { return Triangles.size(); };

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

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

35
    auto &boundaries() { return Boundaries; };
JasonPries's avatar
JasonPries committed
36

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

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

41
    auto const &nodes() const { return Nodes; };
JasonPries's avatar
JasonPries committed
42

43
    auto const &node(size_t i) const { return Nodes[i]; };
JasonPries's avatar
JasonPries committed
44

45
    auto &regions() { return Regions; };
JasonPries's avatar
JasonPries committed
46

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

49
50
51
    auto const &regions() const { return Regions; };

    auto const &region(size_t i) const { return Regions[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
88
89
90
91
92
93
94
95
96
97
    template<size_t Q>
    std::vector<std::vector<XY>> quadrature_points() const {
        std::vector<std::vector<XY>> qp;
        qp.reserve(Triangles.size());

        for(size_t i = 0; i!= Triangles.size();++i){
            qp.push_back(Triangles[i].quadrature_points<Q>(Nodes));
        }

        return qp;
    }

98
99
protected:
    std::vector<XY> Nodes;
JasonPries's avatar
JasonPries committed
100
101
    std::vector<Triangle<Order>> Triangles;

JasonPries's avatar
JasonPries committed
102
103
    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;
104
105
106
};

#endif //OERSTED_FINITEELEMENTMESH_H