FiniteElementMesh.h 2.19 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) : Nodes(nodes), Triangles(tris), Regions(r) {};
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
28
29

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

    XY const &node(size_t i) const { return Nodes[i]; };

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

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

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

        for (size_t i = 0; i != Triangles.size(); ++i) {
50
            Triangles[i].basis<Q>(mat, Nodes);
JasonPries's avatar
JasonPries committed
51
52
53
        }

        return mat;
54
    }
JasonPries's avatar
JasonPries committed
55
56
57

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

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

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

protected:
    std::vector<XY> Nodes;
JasonPries's avatar
JasonPries committed
69
70
71
    std::vector<Triangle<Order>> Triangles;

    std::vector<Region<2>> Regions; // Contains vector of size_t referencing Triangles (and later Quadrilaterals)
72
73
74
};

#endif //OERSTED_FINITEELEMENTMESH_H