FiniteElementMesh.h 2.8 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 8
#include "Mesh.hpp"

9
#include "Boundary.h"
10
#include "MatrixGroup.h"
11 12
#include "Node.h"
#include "Triangle.h"
JasonPries's avatar
JasonPries committed
13
#include "Region.h"
14

JasonPries's avatar
JasonPries committed
15
template<size_t Dimension, size_t Order>
JasonPries's avatar
JasonPries committed
16
class FiniteElementMesh {};
17

JasonPries's avatar
JasonPries committed
18 19
template<size_t Order>
class FiniteElementMesh<2,Order> {
20
public:
JasonPries's avatar
JasonPries committed
21 22
    FiniteElementMesh() {};

23 24 25
    FiniteElementMesh(std::vector<XY> nodes, std::vector<Triangle<Order>> tris, std::vector<std::shared_ptr<Region<2>>> r, std::vector<std::shared_ptr<Boundary<2>>> b) : Nodes(nodes), Triangles(tris), Regions(r), Boundaries(b) {};

    FiniteElementMesh(Mesh &m);
26

JasonPries's avatar
JasonPries committed
27 28
    size_t size_nodes() const { return Nodes.size(); };

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

JasonPries's avatar
JasonPries committed
31 32 33 34
    XY const &node(size_t i) const { return Nodes[i]; };

    size_t size_elements() const { return Triangles.size(); };

JasonPries's avatar
JasonPries committed
35
    std::vector<Triangle<Order>> const &triangles() const { return Triangles; };
JasonPries's avatar
JasonPries committed
36

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

JasonPries's avatar
JasonPries committed
39
    auto &regions() { return Regions; };
JasonPries's avatar
JasonPries committed
40

JasonPries's avatar
JasonPries committed
41
    auto &region(size_t i) { return Regions[i]; };
JasonPries's avatar
JasonPries committed
42

JasonPries's avatar
JasonPries committed
43 44 45 46 47 48 49
    auto const &regions() const { return Regions; };

    auto const &region(size_t i) const { return Regions[i]; };

    auto &boundaries() {return Boundaries;};

    auto &boundary(size_t i) {return Boundaries[i];};
JasonPries's avatar
JasonPries committed
50

JasonPries's avatar
JasonPries committed
51
    auto const &boundaries() const { return Boundaries; };
JasonPries's avatar
JasonPries committed
52

JasonPries's avatar
JasonPries committed
53
    auto const &boundary(size_t i) const { return Boundaries[i]; };
JasonPries's avatar
JasonPries committed
54

55
    template<size_t Q>
56 57
    DiagonalMatrixGroup<TriangleQuadrature<Q>::size> determinant() const {
        DiagonalMatrixGroup<TriangleQuadrature<Q>::size> mat(Triangles.size());
58 59 60 61 62 63 64 65

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

        return mat;
    }

JasonPries's avatar
JasonPries committed
66
    template<size_t Q>
67 68
    SparseMatrixGroup<TriangleQuadrature<Q>::size> basis() const {
        SparseMatrixGroup<TriangleQuadrature<Q>::size> mat(Nodes.size(), Triangles.size(), Triangle<Order>::NumNodes);
JasonPries's avatar
JasonPries committed
69 70

        for (size_t i = 0; i != Triangles.size(); ++i) {
71
            Triangles[i].basis<Q>(mat, Nodes);
JasonPries's avatar
JasonPries committed
72 73 74
        }

        return mat;
75
    }
JasonPries's avatar
JasonPries committed
76 77

    template<size_t Q>
78 79
    DerivativeMatrixGroup<TriangleQuadrature<Q>::size> derivative() const {
        DerivativeMatrixGroup<TriangleQuadrature<Q>::size> df(Nodes.size(), Triangles.size(), Triangle<Order>::NumNodes);
JasonPries's avatar
JasonPries committed
80 81

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

JasonPries's avatar
JasonPries committed
85 86
        return df;
    }
87 88 89

protected:
    std::vector<XY> Nodes;
JasonPries's avatar
JasonPries committed
90 91
    std::vector<Triangle<Order>> Triangles;

JasonPries's avatar
JasonPries committed
92 93
    std::vector<std::shared_ptr<Region<2>>> Regions; // Contains vector of size_t referencing Triangles (and later Quadrilaterals)
    std::vector<std::shared_ptr<Boundary<2>>> Boundaries;
94 95 96
};

#endif //OERSTED_FINITEELEMENTMESH_H