2010-03-11 15:47:40 +00:00
/*
* 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/>.
*/
2010-05-28 13:13:14 +00:00
# include "tools/global.h"
2010-03-04 10:53:58 +00:00
# include "processcurrent.h"
2010-12-06 09:44:25 +00:00
# include "FDTD/engine_interface_fdtd.h"
2010-04-12 07:38:24 +00:00
# include <iomanip>
2010-03-04 10:53:58 +00:00
2010-12-07 15:47:23 +00:00
ProcessCurrent : : ProcessCurrent ( Engine_Interface_Base * eng_if ) : ProcessIntegral ( eng_if )
2010-03-04 10:53:58 +00:00
{
2011-07-22 08:01:19 +00:00
m_SnapMethod = 1 ;
2010-03-04 10:53:58 +00:00
}
ProcessCurrent : : ~ ProcessCurrent ( )
{
}
2011-01-18 09:34:13 +00:00
string ProcessCurrent : : GetIntegralName ( int row ) const
{
if ( row = = 0 )
return " current " ;
return " unknown " ;
}
2011-07-13 07:36:23 +00:00
void ProcessCurrent : : DefineStartStopCoord ( double * dstart , double * dstop )
{
ProcessIntegral : : DefineStartStopCoord ( dstart , dstop ) ;
2011-07-22 08:01:19 +00:00
m_normDir = - 1 ;
2011-07-13 07:36:23 +00:00
for ( int n = 0 ; n < 3 ; + + n )
{
if ( stop [ n ] = = start [ n ] )
m_normDir = n ;
}
2011-07-22 08:01:19 +00:00
if ( m_normDir < 0 )
{
cerr < < " ProcessCurrent::DefineStartStopCoord(): Warning Current Integration Box \" " < < m_filename < < " \" has an invalid normal direction --> disabled " < < endl ;
SetEnable ( false ) ;
return ;
}
if ( m_Dimension ! = 2 )
2011-07-13 07:36:23 +00:00
{
2011-07-22 08:01:19 +00:00
cerr < < " ProcessCurrent::DefineStartStopCoord(): Warning Current Integration Box \" " < < m_filename < < " \" is not a surface (found dimension: " < < m_Dimension < < " ) --> disabled " < < endl ;
2011-07-13 07:36:23 +00:00
SetEnable ( false ) ;
return ;
}
}
2010-08-11 10:28:09 +00:00
double ProcessCurrent : : CalcIntegral ( )
2010-03-04 10:53:58 +00:00
{
FDTD_FLOAT current = 0 ;
2010-12-02 13:29:46 +00:00
Engine_Interface_FDTD * EI_FDTD = dynamic_cast < Engine_Interface_FDTD * > ( m_Eng_Interface ) ;
2010-06-18 10:52:02 +00:00
2010-12-02 13:29:46 +00:00
if ( EI_FDTD )
2010-03-04 10:53:58 +00:00
{
2010-12-02 13:29:46 +00:00
const Engine * Eng = EI_FDTD - > GetFDTDEngine ( ) ;
2010-06-18 10:52:02 +00:00
2011-07-13 07:36:23 +00:00
switch ( m_normDir )
2010-12-02 13:29:46 +00:00
{
case 0 :
//y-current
if ( m_stop_inside [ 0 ] & & m_start_inside [ 2 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 1 ] + 1 ; i < = stop [ 1 ] ; + + i )
2010-12-02 13:29:46 +00:00
current + = Eng - > GetCurr ( 1 , stop [ 0 ] , i , start [ 2 ] ) ;
//z-current
if ( m_stop_inside [ 0 ] & & m_stop_inside [ 1 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 2 ] + 1 ; i < = stop [ 2 ] ; + + i )
2010-12-02 13:29:46 +00:00
current + = Eng - > GetCurr ( 2 , stop [ 0 ] , stop [ 1 ] , i ) ;
//y-current
if ( m_start_inside [ 0 ] & & m_stop_inside [ 2 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 1 ] + 1 ; i < = stop [ 1 ] ; + + i )
2010-12-02 13:29:46 +00:00
current - = Eng - > GetCurr ( 1 , start [ 0 ] , i , stop [ 2 ] ) ;
//z-current
if ( m_start_inside [ 0 ] & & m_start_inside [ 1 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 2 ] + 1 ; i < = stop [ 2 ] ; + + i )
2010-12-02 13:29:46 +00:00
current - = Eng - > GetCurr ( 2 , start [ 0 ] , start [ 1 ] , i ) ;
break ;
case 1 :
//z-current
if ( m_start_inside [ 0 ] & & m_start_inside [ 1 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 2 ] + 1 ; i < = stop [ 2 ] ; + + i )
2010-12-02 13:29:46 +00:00
current + = Eng - > GetCurr ( 2 , start [ 0 ] , start [ 1 ] , i ) ;
//x-current
if ( m_stop_inside [ 1 ] & & m_stop_inside [ 2 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 0 ] + 1 ; i < = stop [ 0 ] ; + + i )
2010-12-02 13:29:46 +00:00
current + = Eng - > GetCurr ( 0 , i , stop [ 1 ] , stop [ 2 ] ) ;
//z-current
if ( m_stop_inside [ 0 ] & & m_stop_inside [ 1 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 2 ] + 1 ; i < = stop [ 2 ] ; + + i )
2010-12-02 13:29:46 +00:00
current - = Eng - > GetCurr ( 2 , stop [ 0 ] , stop [ 1 ] , i ) ;
//x-current
if ( m_start_inside [ 1 ] & & m_start_inside [ 2 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 0 ] + 1 ; i < = stop [ 0 ] ; + + i )
2010-12-02 13:29:46 +00:00
current - = Eng - > GetCurr ( 0 , i , start [ 1 ] , start [ 2 ] ) ;
break ;
case 2 :
//x-current
if ( m_start_inside [ 1 ] & & m_start_inside [ 2 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 0 ] + 1 ; i < = stop [ 0 ] ; + + i )
2010-12-02 13:29:46 +00:00
current + = Eng - > GetCurr ( 0 , i , start [ 1 ] , start [ 2 ] ) ;
//y-current
if ( m_stop_inside [ 0 ] & & m_start_inside [ 2 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 1 ] + 1 ; i < = stop [ 1 ] ; + + i )
2010-12-02 13:29:46 +00:00
current + = Eng - > GetCurr ( 1 , stop [ 0 ] , i , start [ 2 ] ) ;
//x-current
if ( m_stop_inside [ 1 ] & & m_stop_inside [ 2 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 0 ] + 1 ; i < = stop [ 0 ] ; + + i )
2010-12-02 13:29:46 +00:00
current - = Eng - > GetCurr ( 0 , i , stop [ 1 ] , stop [ 2 ] ) ;
//y-current
if ( m_start_inside [ 0 ] & & m_stop_inside [ 2 ] )
2010-12-06 12:04:37 +00:00
for ( unsigned int i = start [ 1 ] + 1 ; i < = stop [ 1 ] ; + + i )
2010-12-02 13:29:46 +00:00
current - = Eng - > GetCurr ( 1 , start [ 0 ] , i , stop [ 2 ] ) ;
break ;
default :
//this cannot happen...
return 0.0 ;
break ;
}
2010-03-04 10:53:58 +00:00
}
2010-08-11 10:28:09 +00:00
return current ;
2010-03-04 10:53:58 +00:00
}