OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
Port.h
Go to the documentation of this file.
1#pragma once
2#include <string>
3
7#include "Grid/Point.h"
8
9template<class T>
10class Port
11{
12public:
13 Port(std::string portName, std::pair<Point3D,index_t> &location, sourceType sourceType, axis sourceAxis, std::string signalName)
14 : _portName(portName), _index(location.second), _point(location.first), _sourceAxis(sourceAxis), _sourceType(sourceType), _signalName(signalName) {}
15 virtual ~Port() {}
16
17 void ApplySource( DegreesOfFreedom3DLoopCPU<T> & doF, int currentTimeStep, float currentTime)
18 {
19 _currentTimeStep = currentTimeStep;
21
22 if (_sourceType == e)
23 {
24 if (_sourceAxis == x_axis)
25 {
26 T oldValue = *doF.GetElectricVoltageXComponent(_index);
28 }
29 else if (_sourceAxis == y_axis)
30 {
31 T oldValue = *doF.GetElectricVoltageYComponent(_index);
33 }
34 else
35 {
36 T oldValue = *doF.GetElectricVoltageZComponent(_index);
38 }
39 }
40 else
41 {
42 if (_sourceAxis == x_axis)
43 {
44 T oldValue = *doF.GetMagneticVoltageXComponent(_index);
46 }
47 else if (_sourceAxis == y_axis)
48 {
49 T oldValue = *doF.GetMagneticVoltageYComponent(_index);
51 }
52 else
53 {
54 T oldValue = *doF.GetMagneticVoltageZComponent(_index);
56
57 }
58 }
59 };
60
61 void ApplySourceHW(DegreesOfFreedom3DLoopCPU<T> & doF, int currentTimeStep, float currentTime)
62 {
63 _currentTimeStep = currentTimeStep;
65
66 if (_sourceType == e)
67 {
68 if (_sourceAxis == x_axis)
69 {
71 }
72 else if (_sourceAxis == y_axis)
73 {
75 }
76 else
77 {
79 }
80 }
81 else
82 {
83 if (_sourceAxis == x_axis)
84 {
86 }
87 else if (_sourceAxis == y_axis)
88 {
90 }
91 else
92 {
94 }
95 }
96 }
97
99 {
100 _currentTimeStep = currentTimeStep;
101 _currentValue = CalculateCurrentValue(currentTimeStep);
102
103 if (_sourceType == e)
104 {
105 if (_sourceAxis == x_axis)
106 {
108 }
109 else if (_sourceAxis == y_axis)
110 {
112 }
113 else
114 {
116 }
117 }
118 else
119 {
120 if (_sourceAxis == x_axis)
121 {
123 }
124 else if (_sourceAxis == y_axis)
125 {
127 }
128 else
129 {
131 }
132 }
133 }
134
135 const std::string GetPortName() const { return _portName; }
136 const std::string GetSignalName() const { return _signalName; }
137 const Point3D GetPoint() const { return _point; }
138 const int GetCurrentTimestep() const { return _currentTimeStep; }
139 const T GetCurrentValue() const { return _currentValue; }
140 const sourceType GetPortTargetField() { return _sourceType; }
141 const axis GetPortTargetAxis() { return _sourceAxis; }
142
143private:
144 std::string _portName;
145 std::string _signalName;
146 sourceType _sourceType;
147 axis _sourceAxis;
148 Point3D _point;
149
150protected:
154
155 virtual T CalculateCurrentValue(float currentTime) = 0;
156
157 float EFunc(float exponent) { return expf(exponent); }
158 double EFunc(double exponent) { return exp(exponent); }
159
160};
sourceType
Definition SourceTarget.h:4
@ e
Definition SourceTarget.h:4
axis
Definition SourceTarget.h:5
@ x_axis
Definition SourceTarget.h:5
@ y_axis
Definition SourceTarget.h:5
int64_t index_t
Definition SystemDependentDefines.h:13
Definition DegreesOfFreedom3DLoopCPU.h:8
T * GetElectricVoltageXComponent(index_t index) const
Definition DegreesOfFreedom3DLoopCPU.h:97
T * GetElectricVoltageYComponent(index_t index) const
Definition DegreesOfFreedom3DLoopCPU.h:103
T * GetMagneticVoltageYComponent(index_t index) const
Definition DegreesOfFreedom3DLoopCPU.h:121
void SetElectricVoltageZComponentAt(index_t index, T value)
Definition DegreesOfFreedom3DLoopCPU.h:145
T * GetMagneticVoltageXComponent(index_t index) const
Definition DegreesOfFreedom3DLoopCPU.h:115
T * GetElectricVoltageZComponent(index_t index) const
Definition DegreesOfFreedom3DLoopCPU.h:109
void SetElectricVoltageYComponentAt(index_t index, T value)
Definition DegreesOfFreedom3DLoopCPU.h:139
void SetMagneticVoltageZComponentAt(index_t index, T value)
Definition DegreesOfFreedom3DLoopCPU.h:163
void SetMagneticVoltageXComponentAt(index_t index, T value)
Definition DegreesOfFreedom3DLoopCPU.h:151
void SetMagneticVoltageYComponentAt(index_t index, T value)
Definition DegreesOfFreedom3DLoopCPU.h:157
void SetElectricVoltageXComponentAt(index_t index, T value)
Definition DegreesOfFreedom3DLoopCPU.h:133
T * GetMagneticVoltageZComponent(index_t index) const
Definition DegreesOfFreedom3DLoopCPU.h:127
Definition Point.h:5
Definition Port.h:11
double EFunc(double exponent)
Definition Port.h:158
void ApplySourceHW(DegreesOfFreedom3DLoopCPU< T > &doF, int currentTimeStep, float currentTime)
Definition Port.h:61
T _currentValue
Definition Port.h:153
const std::string GetSignalName() const
Definition Port.h:136
const T GetCurrentValue() const
Definition Port.h:139
virtual T CalculateCurrentValue(float currentTime)=0
Port(std::string portName, std::pair< Point3D, index_t > &location, sourceType sourceType, axis sourceAxis, std::string signalName)
Definition Port.h:13
const int GetCurrentTimestep() const
Definition Port.h:138
void ApplySourceHWDiscreteValueCalc(DegreesOfFreedom3DLoopCPU< T > &doF, int currentTimeStep)
Definition Port.h:98
void ApplySource(DegreesOfFreedom3DLoopCPU< T > &doF, int currentTimeStep, float currentTime)
Definition Port.h:17
const std::string GetPortName() const
Definition Port.h:135
int _currentTimeStep
Definition Port.h:152
const sourceType GetPortTargetField()
Definition Port.h:140
float EFunc(float exponent)
Definition Port.h:157
virtual ~Port()
Definition Port.h:15
const Point3D GetPoint() const
Definition Port.h:137
const axis GetPortTargetAxis()
Definition Port.h:141
index_t _index
Definition Port.h:151