summaryrefslogtreecommitdiff
path: root/openEMS/FDTD/extensions/engine_ext_cylinder.cpp
blob: e240f1b7993ab35cfc3ee940a3aafb898f32ff0b (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
*	Copyright (C) 2010 Thorsten Liebig (Thorsten.Liebig@gmx.de)
*
*	This program is free software: you can redistribute it and/or modify
*	it under the terms of the GNU General Public License as published by
*	the Free Software Foundation, either version 3 of the License, or
*	(at your option) any later version.
*
*	This program is distributed in the hope that it will be useful,
*	but WITHOUT ANY WARRANTY; without even the implied warranty of
*	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*	GNU General Public License for more details.
*
*	You should have received a copy of the GNU General Public License
*	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "FDTD/engine.h"
#include "engine_ext_cylinder.h"
#include "operator_ext_cylinder.h"
#include "FDTD/engine_sse.h"

Engine_Ext_Cylinder::Engine_Ext_Cylinder(Operator_Ext_Cylinder* op_ext) : Engine_Extension(op_ext)
{
	cyl_Op = op_ext;
	m_Eng_SSE = NULL;

	CC_closedAlpha = op_ext->CC_closedAlpha;
	CC_R0_included = op_ext->CC_R0_included;

	for (int n=0; n<3; ++n)
		numLines[n] = op_ext->m_Op->GetNumberOfLines(n,true);

	//this cylindrical extension should be executed first?
	m_Priority = ENG_EXT_PRIO_CYLINDER;
}

void Engine_Ext_Cylinder::SetEngine(Engine* eng)
{
	Engine_Extension::SetEngine(eng);
	m_Eng_SSE = dynamic_cast<Engine_sse*>(m_Eng);
}

void Engine_Ext_Cylinder::DoPostVoltageUpdates()
{
	if (CC_closedAlpha==false) return;

	if (CC_R0_included)
	{
		unsigned int pos[3];
		pos[0] = 0;
		FDTD_FLOAT volt=0;
		for (pos[2]=0; pos[2]<numLines[2]; ++pos[2])
		{
			volt =m_Eng_SSE->Engine_sse::GetVolt(2,0,0,pos[2])*cyl_Op->vv_R0[pos[2]];
			for (pos[1]=0; pos[1]<numLines[1]-1; ++pos[1])
				volt +=cyl_Op->vi_R0[pos[2]] *  m_Eng_SSE->Engine_sse::GetCurr(1,0,pos[1],pos[2]);
			m_Eng_SSE->Engine_sse::SetVolt(2,0,0,pos[2], volt);
		}

		for (pos[1]=0; pos[1]<numLines[1]; ++pos[1])
		{
			for (pos[2]=0; pos[2]<numLines[2]; ++pos[2])
			{
				m_Eng_SSE->Engine_sse::SetVolt(1,0,pos[1],pos[2], 0); //no voltage in alpha-direction at r=0
				m_Eng_SSE->Engine_sse::SetVolt(2,0,pos[1],pos[2], m_Eng_SSE->Engine_sse::GetVolt(2,0,0,pos[2]) );
			}
		}
	}

	//close alpha
	unsigned int pos[3];
	// copy tangential voltages from last alpha-plane to first
	unsigned int last_A_Line = numLines[1]-2;
	for (pos[0]=0; pos[0]<numLines[0]; ++pos[0])
	{
		for (pos[2]=0; pos[2]<numLines[2]; ++pos[2])
		{
			m_Eng_SSE->Engine_sse::SetVolt(0,pos[0],0,pos[2], m_Eng_SSE->Engine_sse::GetVolt(0,pos[0],last_A_Line,pos[2]) );
			m_Eng_SSE->Engine_sse::SetVolt(2,pos[0],0,pos[2], m_Eng_SSE->Engine_sse::GetVolt(2,pos[0],last_A_Line,pos[2]) );
		}
	}
}

void Engine_Ext_Cylinder::DoPostCurrentUpdates()
{
	if (CC_closedAlpha==false) return;

	//close alpha
	unsigned int pos[3];
	// copy tangential currents from first alpha-plane to last
	for (pos[0]=0; pos[0]<numLines[0]-1; ++pos[0])
	{
		unsigned int last_A_Line = numLines[1]-2;
		for (pos[2]=0; pos[2]<numLines[2]-1; ++pos[2])
		{
			m_Eng_SSE->Engine_sse::SetCurr(0,pos[0],last_A_Line,pos[2], m_Eng_SSE->Engine_sse::GetCurr(0,pos[0],0,pos[2]) );
			m_Eng_SSE->Engine_sse::SetCurr(2,pos[0],last_A_Line,pos[2], m_Eng_SSE->Engine_sse::GetCurr(2,pos[0],0,pos[2]) );
		}
	}
}