MaterialProperties.h 1.68 KB
Newer Older
JasonPries's avatar
JasonPries committed
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#ifndef OERSTED_MATERIALPROPERTIES_H
#define OERSTED_MATERIALPROPERTIES_H

#include <memory>
#include <utility>
#include <vector>

#include "Eigen"

#include "PhysicsConstants.h"

// TODO: Move into some sort of header
using Vector = Eigen::VectorXd;
using Array = Eigen::ArrayXd;

class MagneticMaterialInterface {
public:
    virtual ~MagneticMaterialInterface(){};

    virtual void h_from_b(std::vector<size_t> const &index, Array &Fx, Array &Fy, Array &dFxdx, Array &dFydy, Array &dFxdy) = 0;
};

class LinearIsotropicMagneticMaterial : public MagneticMaterialInterface {
public:
    LinearIsotropicMagneticMaterial(double relative_permeability) : Reluctivity(1.0 / (mu_0 * relative_permeability)) {};

    void h_from_b(std::vector<size_t> const &index, Array &Fx, Array &Fy, Array &dFxdx, Array &dFydy, Array &dFxdy) override {
        for(size_t const &i : index) {
            Fx(i) *= Reluctivity;
            Fy(i) *= Reluctivity;
            dFxdx(i) = Reluctivity;
            dFydy(i) = Reluctivity;
            dFxdy(i) = 0.0;
        }
    }

protected:
    double Reluctivity;
};

class MaterialProperties {
public:
    // TODO: Add std::string Name; property + a constructor which loads data saved in a file on disk
    MaterialProperties(std::shared_ptr<MagneticMaterialInterface> magnetic) : MagneticProperties{magnetic} {};

    template<typename... Args>
    void h_from_b(Args&&... args) { return MagneticProperties->h_from_b(std::forward<Args>(args)...); }

protected:
    std::shared_ptr<MagneticMaterialInterface> MagneticProperties;
};

MaterialProperties Air() {
    return MaterialProperties(std::make_shared<LinearIsotropicMagneticMaterial>(1.0));
}

#endif //OERSTED_MATERIALPROPERTIES_H