OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
CurlCoefficients3D.hpp
Go to the documentation of this file.
1#pragma once
3#include <algorithm>
4
5template<class T>
7{
8 index_t numberOfDoF = _grid.GetDegreesOfFreedomNumberTotalPadded();
9 for (int i = 0; i < numberOfDoF; i++)
10 {
11 _coefficientComponentXCurlY[i] = value;
12 _coefficientComponentXCurlZ[i] = value;
13 _coefficientComponentYCurlX[i] = value;
14 _coefficientComponentYCurlZ[i] = value;
15 _coefficientComponentZCurlX[i] = value;
16 _coefficientComponentZCurlY[i] = value;
17 }
18}
19
20template<class T>
22{
23 if (
24 _coefficientComponentXCurlY != nullptr ||
25 _coefficientComponentXCurlZ != nullptr ||
26 _coefficientComponentYCurlX != nullptr ||
27 _coefficientComponentYCurlZ != nullptr ||
28 _coefficientComponentZCurlX != nullptr ||
29 _coefficientComponentZCurlY != nullptr
30 )
31 {
32 _aligned_free(_coefficientComponentXCurlY);
33 _aligned_free(_coefficientComponentXCurlZ);
34 _aligned_free(_coefficientComponentYCurlX);
35 _aligned_free(_coefficientComponentYCurlZ);
36 _aligned_free(_coefficientComponentZCurlX);
37 _aligned_free(_coefficientComponentZCurlY);
38
39 _coefficientComponentXCurlY = nullptr;
40 _coefficientComponentXCurlZ = nullptr;
41 _coefficientComponentYCurlX = nullptr;
42 _coefficientComponentYCurlZ = nullptr;
43 _coefficientComponentZCurlX = nullptr;
44 _coefficientComponentZCurlY = nullptr;
45 }
46}
47
48
49template<class T>
51{
52 if (
53
54 _edgeDiscretization->GetNumberOfNodes() !=
55 _surfaceDiscretization->GetNumberOfNodes() ||
56 _surfaceDiscretization->GetNumberOfNodes() !=
57 (_grid.GetDegreesOfFreedomNumberTotal()) ||
58 _surfaceDiscretization->GetNumberOfNodes() !=
59 _materialProperties->GetNumberOfNodes()
60 )
61 {
62 throw std::invalid_argument("The given component dimensions, discretization dimensions or material property dimensions are not matching.");
63 }
64
65 if (_grid.GetDegreesOfFreedomNumberInX() == 0 || _grid.GetDegreesOfFreedomNumberInY() == 0 || _grid.GetDegreesOfFreedomNumberInZ() == 0)
66 {
67 throw std::logic_error("3D _grid with less then 3 dimensions detected.");
68 }
69}
70
71template<class T>
73{
74 T zero = static_cast<T>(0.);
75 for (index_t z = 0; z < _grid.GetDegreesOfFreedomNumberInZ(); z++)
76 {
77 for (index_t y = 0; y < _grid.GetDegreesOfFreedomNumberInY(); y++)
78 {
79 for (index_t x = 0; x < _grid.GetDegreesOfFreedomNumberInX(); x++)
80 {
81 index_t index = _grid.GetIndexToCoordinateNotPadded(x, y, z);
82 index_t indexPedded = _grid.GetIndexToCoordinate(x, y, z);
83 if ((*_materialProperties.*GetMaterialInXAtIndex)(index) != 0 && (*_materialProperties.*GetMaterialInYAtIndex)(index) != 0 && (*_materialProperties.*GetMaterialInZAtIndex)(index) != 0)
84 {
85 if (_surfaceDiscretization->GetDeltaYZAtIndex(index) != 0)
86 {
87
88 _coefficientComponentXCurlY[indexPedded] = (static_cast<T>(timeDiscretization) * static_cast<T>(_edgeDiscretization->GetDeltaYAtIndex(index))) /
89 (static_cast<T>((*_materialProperties.*GetMaterialInYAtIndex)(index)) * static_cast<T>(_surfaceDiscretization->GetDeltaYZAtIndex(index)));
90 _coefficientComponentXCurlZ[indexPedded] = (static_cast<T>(timeDiscretization) * static_cast<T>(_edgeDiscretization->GetDeltaZAtIndex(index))) /
91 (static_cast<T>((*_materialProperties.*GetMaterialInZAtIndex)(index)) * static_cast<T>(_surfaceDiscretization->GetDeltaYZAtIndex(index))); }
92 else
93 {
94 _coefficientComponentXCurlY[indexPedded] = zero;
95 _coefficientComponentXCurlZ[indexPedded] = zero;
96 }
97
98 if (_surfaceDiscretization->GetDeltaXZAtIndex(index) != 0)
99 {
100 _coefficientComponentYCurlX[indexPedded] = (static_cast<T>(timeDiscretization) * static_cast<T>(_edgeDiscretization->GetDeltaXAtIndex(index))) /
101 (static_cast<T>((*_materialProperties.*GetMaterialInXAtIndex)(index)) * static_cast<T>(_surfaceDiscretization->GetDeltaXZAtIndex(index)));
102 _coefficientComponentYCurlZ[indexPedded] = (static_cast<T>(timeDiscretization) * static_cast<T>(_edgeDiscretization->GetDeltaZAtIndex(index))) /
103 (static_cast<T>((*_materialProperties.*GetMaterialInZAtIndex)(index)) * static_cast<T>(_surfaceDiscretization->GetDeltaXZAtIndex(index)));
104
105 }
106 else
107 {
108 _coefficientComponentYCurlX[indexPedded] = zero;
109 _coefficientComponentYCurlZ[indexPedded] = zero;
110 }
111
112 if (_surfaceDiscretization->GetDeltaXYAtIndex(index) != 0)
113 {
114 _coefficientComponentZCurlX[indexPedded] = (static_cast<T>(timeDiscretization) * static_cast<T>(_edgeDiscretization->GetDeltaXAtIndex(index))) /
115 (static_cast<T>((*_materialProperties.*GetMaterialInXAtIndex)(index)) * static_cast<T>(_surfaceDiscretization->GetDeltaXYAtIndex(index)));
116 _coefficientComponentZCurlY[indexPedded] = (static_cast<T>(timeDiscretization) * static_cast<T>(_edgeDiscretization->GetDeltaYAtIndex(index))) /
117 (static_cast<T>((*_materialProperties.*GetMaterialInYAtIndex)(index)) * static_cast<T>(_surfaceDiscretization->GetDeltaXYAtIndex(index)));
118 }
119 else
120 {
121 _coefficientComponentZCurlX[indexPedded] = zero;
122 _coefficientComponentZCurlY[indexPedded] = zero;
123 }
124 }
125 else
126 {
127 _coefficientComponentXCurlY[indexPedded] = zero;
128 _coefficientComponentXCurlZ[indexPedded] = zero;
129 _coefficientComponentYCurlX[indexPedded] = zero;
130 _coefficientComponentYCurlZ[indexPedded] = zero;
131 _coefficientComponentZCurlX[indexPedded] = zero;
132 _coefficientComponentZCurlY[indexPedded] = zero;
133 }
134 }
135 }
136 }
137
138}
139
140#undef min
141template<class T>
143{
144 T one = static_cast<T>(1.);
145 T two = static_cast<T>(2.);
146
147 index_t x(0), y(0), z(0), index(0);
148 //find first index that is no PEC respectively PMC
149 while (HasZeroValueAtIndex(index) && !(x == _grid.GetDegreesOfFreedomNumberInX() - 1 && y == _grid.GetDegreesOfFreedomNumberInY() - 1 && z == _grid.GetDegreesOfFreedomNumberInZ() - 1))
150 {
151 if (x < _grid.GetDegreesOfFreedomNumberInX())
152 {
153 x++;
154 }
155 else
156 {
157 x = 0;
158 if (y < _grid.GetDegreesOfFreedomNumberInY())
159 {
160 y++;
161 }
162 else
163 {
164 y = 0;
165 z++;
166 }
167 }
168 index = _grid.GetIndexToCoordinateNotPadded(x, y, z);
169 }
170 //No such element was found
171 if (HasZeroValueAtIndex(index) && (x == _grid.GetDegreesOfFreedomNumberInX() - 1 && y == _grid.GetDegreesOfFreedomNumberInY() - 1 && z == _grid.GetDegreesOfFreedomNumberInZ() - 1))
172 {
173 throw std::logic_error("All nodes are either PEC or PMC elements");
174 }
175
176 //Smallest material value leads to biggest propagation speed, leads to smallest, biggest stable time step.
177 double permeability(0), permittivity(0);
178 permeability = std::min({
179 _materialProperties->GetPermeabilityInX(index),
180 _materialProperties->GetPermeabilityInY(index),
181 _materialProperties->GetPermeabilityInZ(index)
182 });
183 permittivity = std::min({ _materialProperties->GetPermittivityInX(index), _materialProperties->GetPermittivityInY(index), _materialProperties->GetPermittivityInZ(index) });
184
185 T propagationSpeed = SqrRoot(
186 one / (static_cast<T>(permittivity)* static_cast<T>(permeability))
187 );
188 timeDiscretization = one / SqrRoot(
189 Potenz(one / static_cast<T>(_edgeDiscretization->GetDeltaXAtIndex(index)), two) +
190 Potenz(one / static_cast<T>(_edgeDiscretization->GetDeltaYAtIndex(index)), two) +
191 Potenz(one / static_cast<T>(_edgeDiscretization->GetDeltaZAtIndex(index)), two))
192 * _stabilityFactor / propagationSpeed;
193
194 for (z = 0; z < _grid.GetDegreesOfFreedomNumberInZ(); z++)
195 {
196 for (y = 0; y < _grid.GetDegreesOfFreedomNumberInY(); y++)
197 {
198 for (x = 0; x < _grid.GetDegreesOfFreedomNumberInX(); x++)
199 {
200 index = _grid.GetIndexToCoordinateNotPadded(x, y, z);
201 if (!HasZeroValueAtIndex(index))
202 {
203 //permeability = std::min({_materialProperties->GetPermeabilityInX(index), _materialProperties->GetPermeabilityInY(index), _materialProperties->GetPermeabilityInZ(index)});
204 //permittivity = std::min({_materialProperties->GetPermittivityInX(index), _materialProperties->GetPermittivityInY(index), _materialProperties->GetPermittivityInZ(index)});
205 propagationSpeed = SqrRoot(
206 one / (static_cast<T>(permeability) * static_cast<T>(permittivity))
207 );
208
209 T temp = one / SqrRoot(
210 Potenz(static_cast<T>(one / _edgeDiscretization->GetDeltaXAtIndex(index)), two) +
211 Potenz(static_cast<T>(one / _edgeDiscretization->GetDeltaYAtIndex(index)), two) +
212 Potenz(static_cast<T>(one / _edgeDiscretization->GetDeltaZAtIndex(index)), two)
213 * _stabilityFactor / propagationSpeed
214 );
215
216 if (temp < timeDiscretization)
217 {
218 timeDiscretization = temp;
219 }
220 }
221 }
222 }
223 }
224 //timeDiscretization = 6.0182*pow(10, -10);
225}
226
227template<class T>
229{
230 index_t numberOfDoF = _grid.GetDegreesOfFreedomNumberTotalPadded();
231 _coefficientComponentXCurlY = static_cast<T*>(_aligned_malloc(numberOfDoF * static_cast<index_t>(sizeof(T)), _grid.GetAlignment()));
232 _coefficientComponentXCurlZ = static_cast<T*>(_aligned_malloc(numberOfDoF * static_cast<index_t>(sizeof(T)), _grid.GetAlignment()));
233 _coefficientComponentYCurlX = static_cast<T*>(_aligned_malloc(numberOfDoF * static_cast<index_t>(sizeof(T)), _grid.GetAlignment()));
234 _coefficientComponentYCurlZ = static_cast<T*>(_aligned_malloc(numberOfDoF * static_cast<index_t>(sizeof(T)), _grid.GetAlignment()));
235 _coefficientComponentZCurlX = static_cast<T*>(_aligned_malloc(numberOfDoF * static_cast<index_t>(sizeof(T)), _grid.GetAlignment()));
236 _coefficientComponentZCurlY = static_cast<T*>(_aligned_malloc(numberOfDoF * static_cast<index_t>(sizeof(T)), _grid.GetAlignment()));
237
238 T zero = static_cast <T>(0.);
239 for (int i = 0; i < numberOfDoF; i++)
240 {
241 _coefficientComponentXCurlY[i] = zero;
242 _coefficientComponentXCurlZ[i] = zero;
243 _coefficientComponentYCurlX[i] = zero;
244 _coefficientComponentYCurlZ[i] = zero;
245 _coefficientComponentZCurlX[i] = zero;
246 _coefficientComponentZCurlY[i] = zero;
247 }
248}
249
250
bsoncxx::types::value value
Definition DocumentManager.h:16
int64_t index_t
Definition SystemDependentDefines.h:13
void TestValues(T value)
Definition CurlCoefficients3D.hpp:6
virtual void CreateCoefficients() override
Definition CurlCoefficients3D.hpp:72
virtual void CalculateTimeStep() override
Definition CurlCoefficients3D.hpp:142
virtual void InitiateCoefficientContainer() override
Definition CurlCoefficients3D.hpp:228
virtual void CheckConsistency() override
Definition CurlCoefficients3D.hpp:50
~CurlCoefficients3D()
Definition CurlCoefficients3D.hpp:21