BaseComponent.h 2.46 KB
Newer Older
1
2
#ifndef BASECOMPONENT_H
#define BASECOMPONENT_H
Markus Mirz's avatar
Markus Mirz committed
3
4
5
6

#include <string>
#include <iostream>

7
8
#include "../Logger.h"
#include "../SystemModel.h"
Markus Mirz's avatar
Markus Mirz committed
9
10
#include "../MathLibrary.h"

11
12
namespace DPsim {

13
14
15
	enum AttrType {
		AttrReal,
		AttrInt,
16
		AttrString, // value should be *std::string, not *char!
17
		AttrComplex
18
19
20
21
22
23
24
	};

	struct CompAttr {
		AttrType type;
		void* value;
	};

25
26
	/// Base class for all elements that might be added to the matrix.
	class BaseComponent {
Markus Mirz's avatar
Markus Mirz committed
27
	protected:
Viviane's avatar
Viviane committed
28
29

		/// Component name
30
		std::string mName;
Viviane's avatar
Viviane committed
31
32

		/// Component node 1
33
		int mNode1;
Viviane's avatar
Viviane committed
34
35

		/// Component node 2
36
		int mNode2;
Viviane's avatar
Viviane committed
37
38

		/// Component node 3
39
		int mNode3;
Markus Mirz's avatar
Markus Mirz committed
40

41
42
43
		/// Map of all attributes that should be exported to the Python interface
		std::map<std::string, CompAttr> attrMap;

44
	public:
45
		BaseComponent() { }
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
		BaseComponent(std::string name, int src, int dest) {
			this->mName = name;
			this->mNode1 = src - 1;
			this->mNode2 = dest - 1;
			attrMap["name"] = {AttrString, &this->mName};
			attrMap["node1"] = {AttrInt, &this->mNode1};
			attrMap["node2"] = {AttrInt, &this->mNode2};
		}
		BaseComponent(std::string name, int node1, int node2, int node3) {
			this->mName = name;
			this->mNode1 = node1 - 1;
			this->mNode2 = node2 - 1;
			this->mNode3 = node3 - 1;
			attrMap["name"] = {AttrString, &this->mName};
			attrMap["node1"] = {AttrInt, &this->mNode1};
			attrMap["node2"] = {AttrInt, &this->mNode2};
			attrMap["node3"] = {AttrInt, &this->mNode3};
		}
64
		virtual ~BaseComponent() { }
Markus Mirz's avatar
Markus Mirz committed
65

Viviane's avatar
Viviane committed
66
		/// get value of node1
67
		int getNode1() { return mNode1; }
Viviane's avatar
Viviane committed
68
		/// get value of node2
69
		int getNode2() { return mNode2; }
Viviane's avatar
Viviane committed
70
		/// get value of node3
71
72
		int getNode3() { return mNode3; }

73
74
		std::map<std::string, CompAttr>& getAttrMap() { return attrMap; }

75
		std::string getName() { return mName; }
Markus Mirz's avatar
Markus Mirz committed
76

Viviane's avatar
Viviane committed
77
		/// Initializes variables of components
78
		virtual void init(Real om, Real dt) { }
Viviane's avatar
Viviane committed
79
80

		/// Stamps conductance matrix
81
		virtual void applySystemMatrixStamp(SystemModel& system) = 0;
Viviane's avatar
Viviane committed
82
83
84
85
86

		/// Stamps current source vector
		virtual void applyRightSideVectorStamp(SystemModel& system) { }

		/// Upgrade values on the current source vector
87
		virtual void step(SystemModel& system, Real time) { }
Viviane's avatar
Viviane committed
88
89

		/// Upgrade variable values based on the solution of the step
90
		virtual void postStep(SystemModel& system) { }
91
92

		/// Return the current flowing through this component in the previous timestep
93
94
95
96
97
		virtual Complex getCurrent(SystemModel& system) {
			std::cerr << "getCurrent implementation missing" << std::endl;
			std::exit(1);
			return Complex(0, 0);
		}
98

99
100
	};
}
Viviane's avatar
Viviane committed
101

102
#endif