FiniteElementMesh.h 2.06 KB
Newer Older
1
2
3
4
5
#ifndef OERSTED_FINITEELEMENTMESH_H
#define OERSTED_FINITEELEMENTMESH_H

#include <vector>

6
#include "MatrixGroup.h"
7
8
#include "Node.h"
#include "Triangle.h"
JasonPries's avatar
JasonPries committed
9
#include "Region.h"
10

JasonPries's avatar
JasonPries committed
11
12
template<size_t D, size_t P>
class FiniteElementMesh {};
13
14

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

JasonPries's avatar
JasonPries committed
19
    FiniteElementMesh(std::vector<XY> nodes, std::vector<Triangle<P>> tris, std::vector<Region<2>> regs) : Nodes(nodes), Triangles(tris), Regions(regs) {};
20

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

JasonPries's avatar
JasonPries committed
23
24
25
26
27
28
29
30
31
    std::vector<Triangle<P>> const &triangles() const { return Triangles; };

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

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

    Triangle<P> const &triangle(size_t i) const { return Triangles[i]; };

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

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

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

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

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

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

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

protected:
    std::vector<XY> Nodes;
    std::vector<Triangle<P>> Triangles;
JasonPries's avatar
JasonPries committed
69
    std::vector<Region<2>> Regions;
70
71
72
};

#endif //OERSTED_FINITEELEMENTMESH_H