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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
/*
* 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 "tools/global.h"
#include "processcurrent.h"
#include "FDTD/engine_interface_fdtd.h"
#include <iomanip>
ProcessCurrent::ProcessCurrent(Engine_Interface_Base* eng_if) : ProcessIntegral(eng_if)
{
m_SnapMethod=1;
}
ProcessCurrent::~ProcessCurrent()
{
}
string ProcessCurrent::GetIntegralName(int row) const
{
if (row==0)
return "current";
return "unknown";
}
void ProcessCurrent::DefineStartStopCoord(double* dstart, double* dstop)
{
ProcessIntegral::DefineStartStopCoord(dstart, dstop);
if ((m_normDir<0) || (m_normDir>2))
{
if (m_Dimension!=2)
{
cerr << "ProcessCurrent::DefineStartStopCoord(): Warning Current Integration Box \"" << m_filename << "\" is not a surface (found dimension: " << m_Dimension << ") nor has it set a valid normal direction! --> disabled" << endl;
SetEnable(false);
return;
}
for (int n=0; n<3; ++n)
{
if (stop[n] == start[n])
m_normDir = n;
}
}
else
{
//expand dimension to 2 if possible
m_Dimension = 0;
for (int n=0; n<3; ++n)
{
if (n==m_normDir)
continue;
if (dstart[n]==dstop[n])
{
if ((Op->GetDiscLine( n, start[n], true ) > dstart[n]) && (start[n]>0))
--start[n];
if ((Op->GetDiscLine( n, start[n], true ) < dstart[n]) && (stop[n]<Op->GetNumberOfLines(n)-1))
++stop[n];
}
if (stop[n] > start[n])
++m_Dimension;
}
}
if (start[m_normDir]!=stop[m_normDir])
{
cerr << "ProcessCurrent::DefineStartStopCoord(): Warning Current Integration Box \"" << m_filename << "\" has an expansion in normal direction! --> disabled" << endl;
SetEnable(false);
return;
}
if ((m_normDir<0) || (m_normDir>2))
{
cerr << "ProcessCurrent::DefineStartStopCoord(): Warning Current Integration Box \"" << m_filename << "\" has an invalid normal direction --> disabled" << endl;
SetEnable(false);
return;
}
}
double ProcessCurrent::CalcIntegral()
{
FDTD_FLOAT current=0;
Engine_Interface_FDTD* EI_FDTD = dynamic_cast<Engine_Interface_FDTD*>(m_Eng_Interface);
if (EI_FDTD)
{
const Engine* Eng = EI_FDTD->GetFDTDEngine();
switch (m_normDir)
{
case 0:
//y-current
if (m_stop_inside[0] && m_start_inside[2])
for (unsigned int i=start[1]+1; i<=stop[1]; ++i)
current+=Eng->GetCurr(1,stop[0],i,start[2]);
//z-current
if (m_stop_inside[0] && m_stop_inside[1])
for (unsigned int i=start[2]+1; i<=stop[2]; ++i)
current+=Eng->GetCurr(2,stop[0],stop[1],i);
//y-current
if (m_start_inside[0] && m_stop_inside[2])
for (unsigned int i=start[1]+1; i<=stop[1]; ++i)
current-=Eng->GetCurr(1,start[0],i,stop[2]);
//z-current
if (m_start_inside[0] && m_start_inside[1])
for (unsigned int i=start[2]+1; i<=stop[2]; ++i)
current-=Eng->GetCurr(2,start[0],start[1],i);
break;
case 1:
//z-current
if (m_start_inside[0] && m_start_inside[1])
for (unsigned int i=start[2]+1; i<=stop[2]; ++i)
current+=Eng->GetCurr(2,start[0],start[1],i);
//x-current
if (m_stop_inside[1] && m_stop_inside[2])
for (unsigned int i=start[0]+1; i<=stop[0]; ++i)
current+=Eng->GetCurr(0,i,stop[1],stop[2]);
//z-current
if (m_stop_inside[0] && m_stop_inside[1])
for (unsigned int i=start[2]+1; i<=stop[2]; ++i)
current-=Eng->GetCurr(2,stop[0],stop[1],i);
//x-current
if (m_start_inside[1] && m_start_inside[2])
for (unsigned int i=start[0]+1; i<=stop[0]; ++i)
current-=Eng->GetCurr(0,i,start[1],start[2]);
break;
case 2:
//x-current
if (m_start_inside[1] && m_start_inside[2])
for (unsigned int i=start[0]+1; i<=stop[0]; ++i)
current+=Eng->GetCurr(0,i,start[1],start[2]);
//y-current
if (m_stop_inside[0] && m_start_inside[2])
for (unsigned int i=start[1]+1; i<=stop[1]; ++i)
current+=Eng->GetCurr(1,stop[0],i,start[2]);
//x-current
if (m_stop_inside[1] && m_stop_inside[2])
for (unsigned int i=start[0]+1; i<=stop[0]; ++i)
current-=Eng->GetCurr(0,i,stop[1],stop[2]);
//y-current
if (m_start_inside[0] && m_stop_inside[2])
for (unsigned int i=start[1]+1; i<=stop[1]; ++i)
current-=Eng->GetCurr(1,start[0],i,stop[2]);
break;
default:
//this cannot happen...
return 0.0;
break;
}
}
return current;
}
|