FiniteElementMesh.h 2.66 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
    FiniteElementMesh(std::vector<XY> nodes, std::vector<Triangle<Order>> tris, std::vector<Region<2>> r, std::vector<Boundary<2>> b) : Nodes(nodes), Triangles(tris), Regions(r), Boundaries(b) {};
21

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

    size_t size_elements() const { return Triangles.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
    std::vector<Triangle<Order>> const &triangles() const { return Triangles; };
JasonPries's avatar
JasonPries committed
29

JasonPries's avatar
JasonPries committed
30
    std::vector<Region<2>> &regions() { return Regions; };
JasonPries's avatar
JasonPries committed
31
32
    std::vector<Region<2>> const &regions() const { return Regions; };

JasonPries's avatar
JasonPries committed
33
34
    std::vector<Boundary<2>> const &boundaries() const { return Boundaries; };

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

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

JasonPries's avatar
JasonPries committed
39
    Region<2> &region(size_t i) { return Regions[i]; };
JasonPries's avatar
JasonPries committed
40
    Region<2> const &region(size_t i) const { return Regions[i]; };
JasonPries's avatar
JasonPries committed
41

JasonPries's avatar
JasonPries committed
42
43
    Boundary<2> const &boundary(size_t i) const { return Boundaries[i]; };

44
45
46
47
48
49
50
51
52
53
54
    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
55
56
    template<size_t Q>
    SparseMatrixGroup<TriangleQuadratureRule<Q>::size> basis() const {
JasonPries's avatar
JasonPries committed
57
        SparseMatrixGroup<TriangleQuadratureRule<Q>::size> mat(Nodes.size(), Triangles.size(), Triangle<Order>::NumNodes);
JasonPries's avatar
JasonPries committed
58
59

        for (size_t i = 0; i != Triangles.size(); ++i) {
60
            Triangles[i].basis<Q>(mat, Nodes);
JasonPries's avatar
JasonPries committed
61
62
63
        }

        return mat;
64
    }
JasonPries's avatar
JasonPries committed
65
66
67

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

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

JasonPries's avatar
JasonPries committed
74
75
        return df;
    }
76
77
78

protected:
    std::vector<XY> Nodes;
JasonPries's avatar
JasonPries committed
79
80
81
    std::vector<Triangle<Order>> Triangles;

    std::vector<Region<2>> Regions; // Contains vector of size_t referencing Triangles (and later Quadrilaterals)
JasonPries's avatar
JasonPries committed
82
    std::vector<Boundary<2>> Boundaries;
83
84
85
};

#endif //OERSTED_FINITEELEMENTMESH_H