FiniteElementMesh.h 1.79 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
22
23
24
    std::vector<XY> const nodes() const { return Nodes; };

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

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

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

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

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

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

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

protected:
    std::vector<XY> Nodes;
    std::vector<Triangle<P>> Triangles;
JasonPries's avatar
JasonPries committed
61
    std::vector<Region<2>> Regions;
62
63
64
};

#endif //OERSTED_FINITEELEMENTMESH_H