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

#include <vector>

6
#include "MatrixGroup.h"
7
8
9
#include "Node.h"
#include "Triangle.h"

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

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

18
19
    FiniteElementMesh(std::vector<XY> nodes, std::vector<Triangle<P>> tris) : Nodes(nodes), Triangles(tris) {};

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

    std::vector<Triangle<P>> const triangles() const { return Triangles; };

24
25
26
27
28
29
30
31
32
33
34
    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
35
36
    template<size_t Q>
    SparseMatrixGroup<TriangleQuadratureRule<Q>::size> basis() const {
37
        SparseMatrixGroup<TriangleQuadratureRule<Q>::size> mat(Nodes.size(), Triangles.size(), Triangle<P>::NumNodes);
JasonPries's avatar
JasonPries committed
38
39

        for (size_t i = 0; i != Triangles.size(); ++i) {
40
            Triangles[i].basis<Q>(mat, Nodes);
JasonPries's avatar
JasonPries committed
41
42
43
        }

        return mat;
44
    }
JasonPries's avatar
JasonPries committed
45
46
47

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

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

JasonPries's avatar
JasonPries committed
54
55
        return df;
    }
56
57
58
59
60
61
62

protected:
    std::vector<XY> Nodes;
    std::vector<Triangle<P>> Triangles;
};

#endif //OERSTED_FINITEELEMENTMESH_H