FiniteElementMesh.h 1.85 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef OERSTED_FINITEELEMENTMESH_H
#define OERSTED_FINITEELEMENTMESH_H

#include <vector>

#include "Eigen"

#include "Node.h"
#include "Triangle.h"

template<size_t M, size_t Q>
class QuadratureDerivatives {
private:
    SmallVector<M> Value[Q];
};

template<size_t Q>
class QuadratureDerivatives<2, Q> {
public:
    double dx(size_t i) { return d[i].x(); };

    double dy(size_t i) { return d[i].y(); };

private:
    XY d[Q];
};

template<size_t Q>
class QuadratureDerivatives<3, Q> {
public:
    double dx(size_t i) { return d[i].x(); };

    double dy(size_t i) { return d[i].y(); };

    double dz(size_t i) { return d[i].z(); };

private:
    XYZ d[Q];
};

JasonPries's avatar
JasonPries committed
41
42
43

template<size_t D, size_t P>
class FiniteElementMesh {};
44
45

template<size_t P>
JasonPries's avatar
JasonPries committed
46
class FiniteElementMesh<2,P> {
47
public:
JasonPries's avatar
JasonPries committed
48
49
    FiniteElementMesh() {};

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

JasonPries's avatar
JasonPries committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    std::vector<XY> const nodes() const { return Nodes; };

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

    template<size_t Q>
    SparseMatrixGroup<TriangleQuadratureRule<Q>::size> basis() const {
        SparseMatrixGroup<TriangleQuadratureRule<Q>::size> mat(Nodes.size(), Triangles.size(), Triangle<P>::N);

        for (size_t i = 0; i != Triangles.size(); ++i) {
            Triangles[i].basis<Q>(mat, Nodes, i);
        }

        return mat;
    };

    template<size_t Q>
    DerivativeMatrixGroup<TriangleQuadratureRule<Q>::size> derivative() const {
        DerivativeMatrixGroup<TriangleQuadratureRule<Q>::size> df(Nodes.size(), Triangles.size(), Triangle<P>::N);

        for (size_t i = 0; i!= Triangles.size();++i) {
            Triangles[i].derivative<Q>(df, Nodes, i);
        }
74

JasonPries's avatar
JasonPries committed
75
76
        return df;
    }
77
78
79
80
81
82
83

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

#endif //OERSTED_FINITEELEMENTMESH_H