Simulation.h 2.59 KB
Newer Older
1
2
#ifndef Simulation_H
#define Simulation_H
Markus Mirz's avatar
Markus Mirz committed
3
4
5
6
7

#include <iostream>
#include <vector>
#include "MathLibrary.h"
#include "Components.h"
8
#include "Logger.h"
9
#include "SystemModel.h"
10
#include "ExternalInterface.h"
Markus Mirz's avatar
Markus Mirz committed
11

12
13
14
15
namespace DPsim {

	struct switchConfiguration {
		Real switchTime;
16
		UInt systemIndex;
17
18
19
20
	};

	class Simulation {

21
	private:
22
23
24
25
		/// Final time of the simulation
		Real mFinalTime;
		/// Time variable that is incremented at every step
		Real mTime;
26
27
28
29
30
31
		/// Index of the next switching
		UInt mCurrentSwitchTimeIndex;
		/// Vector of switch times
		std::vector<switchConfiguration> mSwitchEventVector;
		/// Structure that holds all system information.
		SystemModel mSystemModel;
32
		
33
34
35
		/// Circuit list vector
		std::vector<std::vector<BaseComponent*> > mElementsVector;

36
37
38
		/// Vector of ExternalInterfaces
		std::vector<ExternalInterface*> mExternalInterfaces;

39
40
41
42
		/// TODO: check that every system matrix has the same dimensions		
		void initialize(std::vector<BaseComponent*> elements);

	public:				
43
44
45
		/// Stores a list of circuit elements that are used to generate the system matrix
		std::vector<BaseComponent*> mElements;

46
		/// Sets parameters to default values.
47
		Simulation();
48
		/// Creates system matrix according to 
49
50
		Simulation(std::vector<BaseComponent*> elements, Real om, Real dt, Real tf);
		Simulation(std::vector<BaseComponent*> elements, Real om, Real dt, Real tf, Logger& logger);
51
		Simulation(std::vector<BaseComponent*> elements, Real om, Real dt, Real tf, Logger& logger, SimulationType simType);
52
53
		~Simulation();

54
		
55
56
57
58
		/// Solve system A * x = z for x and current time
		int step(Logger& logger);
		/// Solve system A * x = z for x and current time. Log current values of both vectors.
		int step(Logger& logger, Logger& leftSideVectorLog, Logger& rightSideVectorLog);
59
60
		void switchSystemMatrix(int systemMatrixIndex);
		void setSwitchTime(Real switchTime, Int systemIndex);
61
		void increaseByTimeStep();
62
		void addExternalInterface(ExternalInterface*);
63
64

		double getTime() { return mTime; }
65
		double getFinalTime() { return mFinalTime; }
66
67
68
		Matrix getLeftSideVector() { return mSystemModel.getLeftSideVector(); }
		Matrix getRightSideVector() { return mSystemModel.getRightSideVector(); }
		Matrix getSystemMatrix() { return mSystemModel.getCurrentSystemMatrix(); }
69
70
71
		int stepGeneratorTest(Logger& logger, Logger& leftSideVectorLog, Logger& rightSideVectorLog, 
			BaseComponent* generator, Logger& synGenLogFlux, Logger& synGenLogVolt, Logger& synGenLogCurr, Real fieldVoltage, Real mechPower, 
			Real logTimeStep, Real& lastLogTime);
72
73

		void addSystemTopology(std::vector<BaseComponent*> newElements);
74
75
76
	};

}
Markus Mirz's avatar
Markus Mirz committed
77
78
79
80
81
82
83
84

#endif