FiniteElementMesh.h 2.42 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
    std::vector<XY> const &nodes() const { return Nodes; };
JasonPries's avatar
JasonPries committed
23

JasonPries's avatar
JasonPries committed
24
    std::vector<Triangle<Order>> const &triangles() const { return Triangles; };
JasonPries's avatar
JasonPries committed
25
26
27

    std::vector<Region<2>> const &regions() const { return Regions; };

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

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

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

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

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

38
39
40
41
42
43
44
45
46
47
48
    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
49
50
    template<size_t Q>
    SparseMatrixGroup<TriangleQuadratureRule<Q>::size> basis() const {
JasonPries's avatar
JasonPries committed
51
        SparseMatrixGroup<TriangleQuadratureRule<Q>::size> mat(Nodes.size(), Triangles.size(), Triangle<Order>::NumNodes);
JasonPries's avatar
JasonPries committed
52
53

        for (size_t i = 0; i != Triangles.size(); ++i) {
54
            Triangles[i].basis<Q>(mat, Nodes);
JasonPries's avatar
JasonPries committed
55
56
57
        }

        return mat;
58
    }
JasonPries's avatar
JasonPries committed
59
60
61

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

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

JasonPries's avatar
JasonPries committed
68
69
        return df;
    }
70
71
72

protected:
    std::vector<XY> Nodes;
JasonPries's avatar
JasonPries committed
73
74
75
    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
76
    std::vector<Boundary<2>> Boundaries;
77
78
79
};

#endif //OERSTED_FINITEELEMENTMESH_H