2010-04-27 21:06:42 +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/>.
*/
# include "engine_ext_mur_abc.h"
# include "operator_ext_mur_abc.h"
# include "engine.h"
2010-05-17 11:10:14 +00:00
# include "engine_sse.h"
2010-04-27 21:06:42 +00:00
# include "tools/array_ops.h"
Engine_Ext_Mur_ABC : : Engine_Ext_Mur_ABC ( Operator_Ext_Mur_ABC * op_ext ) : Engine_Extension ( op_ext )
{
m_Op_mur = op_ext ;
m_numLines [ 0 ] = m_Op_mur - > m_numLines [ 0 ] ;
m_numLines [ 1 ] = m_Op_mur - > m_numLines [ 1 ] ;
m_ny = m_Op_mur - > m_ny ;
m_nyP = m_Op_mur - > m_nyP ;
m_nyPP = m_Op_mur - > m_nyPP ;
m_LineNr = m_Op_mur - > m_LineNr ;
m_LineNr_Shift = m_Op_mur - > m_LineNr_Shift ;
2010-04-28 19:45:05 +00:00
m_Mur_Coeff_nyP = m_Op_mur - > m_Mur_Coeff_nyP ;
m_Mur_Coeff_nyPP = m_Op_mur - > m_Mur_Coeff_nyPP ;
2010-04-27 21:06:42 +00:00
2010-06-06 18:22:05 +00:00
m_volt_nyP = Create2DArray < FDTD_FLOAT > ( m_numLines ) ;
m_volt_nyPP = Create2DArray < FDTD_FLOAT > ( m_numLines ) ;
2010-04-28 16:21:02 +00:00
//find if some excitation is on this mur-abc and find the max length of this excite, so that the abc can start after the excitation is done...
int maxDelay = - 1 ;
2010-05-03 16:33:14 +00:00
for ( unsigned int n = 0 ; n < m_Op_mur - > m_Op - > Exc - > E_Count ; + + n )
2010-04-28 16:21:02 +00:00
{
2010-05-03 16:33:14 +00:00
if ( ( ( m_Op_mur - > m_Op - > Exc - > E_dir [ n ] = = m_nyP ) | | ( m_Op_mur - > m_Op - > Exc - > E_dir [ n ] = = m_nyPP ) ) & & ( m_Op_mur - > m_Op - > Exc - > E_index [ m_ny ] [ n ] = = m_LineNr ) )
2010-04-28 16:21:02 +00:00
{
2010-05-03 16:33:14 +00:00
if ( ( int ) m_Op_mur - > m_Op - > Exc - > E_delay [ n ] > maxDelay )
maxDelay = ( int ) m_Op_mur - > m_Op - > Exc - > E_delay [ n ] ;
2010-04-28 16:21:02 +00:00
}
}
m_start_TS = 0 ;
if ( maxDelay > = 0 )
{
2010-05-03 16:33:14 +00:00
m_start_TS = maxDelay + m_Op_mur - > m_Op - > Exc - > Length + 10 ; //give it some extra timesteps, for the excitation to travel at least one cell away
2010-04-28 16:21:02 +00:00
cerr < < " Engine_Ext_Mur_ABC::Engine_Ext_Mur_ABC: Warning: Excitation inside the Mur-ABC # " < < m_ny < < " - " < < ( int ) ( m_LineNr > 0 ) < < " found!!!! Mur-ABC will be switched on after excitation is done at " < < m_start_TS < < " timesteps!!! " < < endl ;
}
2010-04-27 21:06:42 +00:00
}
Engine_Ext_Mur_ABC : : ~ Engine_Ext_Mur_ABC ( )
{
Delete2DArray ( m_volt_nyP , m_numLines ) ;
m_volt_nyP = NULL ;
Delete2DArray ( m_volt_nyPP , m_numLines ) ;
m_volt_nyPP = NULL ;
}
void Engine_Ext_Mur_ABC : : DoPreVoltageUpdates ( )
{
2010-04-28 16:21:02 +00:00
if ( IsActive ( ) = = false ) return ;
2010-04-27 21:06:42 +00:00
if ( m_Eng = = NULL ) return ;
unsigned int pos [ ] = { 0 , 0 , 0 } ;
unsigned int pos_shift [ ] = { 0 , 0 , 0 } ;
pos [ m_ny ] = m_LineNr ;
pos_shift [ m_ny ] = m_LineNr_Shift ;
2010-05-17 11:10:14 +00:00
//switch for different engine types to access faster inline engine functions
switch ( m_Eng - > GetType ( ) )
2010-04-27 21:06:42 +00:00
{
2010-05-17 11:10:14 +00:00
case Engine : : BASIC :
2010-04-27 21:06:42 +00:00
{
2010-05-17 11:10:14 +00:00
for ( pos [ m_nyP ] = 0 ; pos [ m_nyP ] < m_numLines [ 0 ] ; + + pos [ m_nyP ] )
{
pos_shift [ m_nyP ] = pos [ m_nyP ] ;
for ( pos [ m_nyPP ] = 0 ; pos [ m_nyPP ] < m_numLines [ 1 ] ; + + pos [ m_nyPP ] )
{
pos_shift [ m_nyPP ] = pos [ m_nyPP ] ;
m_volt_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] = m_Eng - > Engine : : GetVolt ( m_nyP , pos_shift ) - m_Op_mur - > m_Mur_Coeff_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * m_Eng - > Engine : : GetVolt ( m_nyP , pos ) ;
m_volt_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] = m_Eng - > Engine : : GetVolt ( m_nyPP , pos_shift ) - m_Op_mur - > m_Mur_Coeff_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * m_Eng - > Engine : : GetVolt ( m_nyPP , pos ) ;
}
}
break ;
2010-04-27 21:06:42 +00:00
}
2010-05-17 11:10:14 +00:00
case Engine : : SSE :
{
Engine_sse * eng_sse = ( Engine_sse * ) m_Eng ;
for ( pos [ m_nyP ] = 0 ; pos [ m_nyP ] < m_numLines [ 0 ] ; + + pos [ m_nyP ] )
{
pos_shift [ m_nyP ] = pos [ m_nyP ] ;
for ( pos [ m_nyPP ] = 0 ; pos [ m_nyPP ] < m_numLines [ 1 ] ; + + pos [ m_nyPP ] )
{
pos_shift [ m_nyPP ] = pos [ m_nyPP ] ;
m_volt_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] = eng_sse - > Engine_sse : : GetVolt ( m_nyP , pos_shift ) - m_Op_mur - > m_Mur_Coeff_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * eng_sse - > Engine_sse : : GetVolt ( m_nyP , pos ) ;
m_volt_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] = eng_sse - > Engine_sse : : GetVolt ( m_nyPP , pos_shift ) - m_Op_mur - > m_Mur_Coeff_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * eng_sse - > Engine_sse : : GetVolt ( m_nyPP , pos ) ;
}
}
break ;
}
default :
for ( pos [ m_nyP ] = 0 ; pos [ m_nyP ] < m_numLines [ 0 ] ; + + pos [ m_nyP ] )
{
pos_shift [ m_nyP ] = pos [ m_nyP ] ;
for ( pos [ m_nyPP ] = 0 ; pos [ m_nyPP ] < m_numLines [ 1 ] ; + + pos [ m_nyPP ] )
{
pos_shift [ m_nyPP ] = pos [ m_nyPP ] ;
m_volt_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] = m_Eng - > GetVolt ( m_nyP , pos_shift ) - m_Op_mur - > m_Mur_Coeff_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * m_Eng - > GetVolt ( m_nyP , pos ) ;
m_volt_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] = m_Eng - > GetVolt ( m_nyPP , pos_shift ) - m_Op_mur - > m_Mur_Coeff_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * m_Eng - > GetVolt ( m_nyPP , pos ) ;
}
}
break ;
2010-04-27 21:06:42 +00:00
}
}
void Engine_Ext_Mur_ABC : : DoPostVoltageUpdates ( )
{
2010-04-28 16:21:02 +00:00
if ( IsActive ( ) = = false ) return ;
2010-04-27 21:06:42 +00:00
if ( m_Eng = = NULL ) return ;
unsigned int pos [ ] = { 0 , 0 , 0 } ;
unsigned int pos_shift [ ] = { 0 , 0 , 0 } ;
pos [ m_ny ] = m_LineNr ;
pos_shift [ m_ny ] = m_LineNr_Shift ;
2010-05-17 11:10:14 +00:00
//switch for different engine types to access faster inline engine functions
switch ( m_Eng - > GetType ( ) )
2010-04-27 21:06:42 +00:00
{
2010-05-17 11:10:14 +00:00
case Engine : : BASIC :
2010-04-27 21:06:42 +00:00
{
2010-05-17 11:10:14 +00:00
for ( pos [ m_nyP ] = 0 ; pos [ m_nyP ] < m_numLines [ 0 ] ; + + pos [ m_nyP ] )
{
pos_shift [ m_nyP ] = pos [ m_nyP ] ;
for ( pos [ m_nyPP ] = 0 ; pos [ m_nyPP ] < m_numLines [ 1 ] ; + + pos [ m_nyPP ] )
{
pos_shift [ m_nyPP ] = pos [ m_nyPP ] ;
m_volt_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] + = m_Op_mur - > m_Mur_Coeff_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * m_Eng - > Engine : : GetVolt ( m_nyP , pos_shift ) ;
m_volt_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] + = m_Op_mur - > m_Mur_Coeff_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * m_Eng - > Engine : : GetVolt ( m_nyPP , pos_shift ) ;
}
}
break ;
2010-04-27 21:06:42 +00:00
}
2010-05-17 11:10:14 +00:00
case Engine : : SSE :
{
Engine_sse * eng_sse = ( Engine_sse * ) m_Eng ;
for ( pos [ m_nyP ] = 0 ; pos [ m_nyP ] < m_numLines [ 0 ] ; + + pos [ m_nyP ] )
{
pos_shift [ m_nyP ] = pos [ m_nyP ] ;
for ( pos [ m_nyPP ] = 0 ; pos [ m_nyPP ] < m_numLines [ 1 ] ; + + pos [ m_nyPP ] )
{
pos_shift [ m_nyPP ] = pos [ m_nyPP ] ;
m_volt_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] + = m_Op_mur - > m_Mur_Coeff_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * eng_sse - > Engine_sse : : GetVolt ( m_nyP , pos_shift ) ;
m_volt_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] + = m_Op_mur - > m_Mur_Coeff_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * eng_sse - > Engine_sse : : GetVolt ( m_nyPP , pos_shift ) ;
}
}
break ;
}
default :
for ( pos [ m_nyP ] = 0 ; pos [ m_nyP ] < m_numLines [ 0 ] ; + + pos [ m_nyP ] )
{
pos_shift [ m_nyP ] = pos [ m_nyP ] ;
for ( pos [ m_nyPP ] = 0 ; pos [ m_nyPP ] < m_numLines [ 1 ] ; + + pos [ m_nyPP ] )
{
pos_shift [ m_nyPP ] = pos [ m_nyPP ] ;
m_volt_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] + = m_Op_mur - > m_Mur_Coeff_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * m_Eng - > GetVolt ( m_nyP , pos_shift ) ;
m_volt_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] + = m_Op_mur - > m_Mur_Coeff_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] * m_Eng - > GetVolt ( m_nyPP , pos_shift ) ;
}
}
break ;
2010-04-27 21:06:42 +00:00
}
}
void Engine_Ext_Mur_ABC : : Apply2Voltages ( )
{
2010-04-28 16:21:02 +00:00
if ( IsActive ( ) = = false ) return ;
2010-04-27 21:06:42 +00:00
if ( m_Eng = = NULL ) return ;
unsigned int pos [ ] = { 0 , 0 , 0 } ;
pos [ m_ny ] = m_LineNr ;
2010-05-17 11:10:14 +00:00
//switch for different engine types to access faster inline engine functions
switch ( m_Eng - > GetType ( ) )
2010-04-27 21:06:42 +00:00
{
2010-05-17 11:10:14 +00:00
case Engine : : BASIC :
{
for ( pos [ m_nyP ] = 0 ; pos [ m_nyP ] < m_numLines [ 0 ] ; + + pos [ m_nyP ] )
{
for ( pos [ m_nyPP ] = 0 ; pos [ m_nyPP ] < m_numLines [ 1 ] ; + + pos [ m_nyPP ] )
{
m_Eng - > Engine : : GetVolt ( m_nyP , pos ) = m_volt_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] ;
m_Eng - > Engine : : GetVolt ( m_nyPP , pos ) = m_volt_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] ;
}
}
break ;
}
case Engine : : SSE :
2010-04-27 21:06:42 +00:00
{
2010-05-17 11:10:14 +00:00
Engine_sse * eng_sse = ( Engine_sse * ) m_Eng ;
for ( pos [ m_nyP ] = 0 ; pos [ m_nyP ] < m_numLines [ 0 ] ; + + pos [ m_nyP ] )
{
for ( pos [ m_nyPP ] = 0 ; pos [ m_nyPP ] < m_numLines [ 1 ] ; + + pos [ m_nyPP ] )
{
eng_sse - > Engine_sse : : GetVolt ( m_nyP , pos ) = m_volt_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] ;
eng_sse - > Engine_sse : : GetVolt ( m_nyPP , pos ) = m_volt_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] ;
}
}
break ;
2010-04-27 21:06:42 +00:00
}
2010-05-17 11:10:14 +00:00
default :
for ( pos [ m_nyP ] = 0 ; pos [ m_nyP ] < m_numLines [ 0 ] ; + + pos [ m_nyP ] )
{
for ( pos [ m_nyPP ] = 0 ; pos [ m_nyPP ] < m_numLines [ 1 ] ; + + pos [ m_nyPP ] )
{
m_Eng - > GetVolt ( m_nyP , pos ) = m_volt_nyP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] ;
m_Eng - > GetVolt ( m_nyPP , pos ) = m_volt_nyPP [ pos [ m_nyP ] ] [ pos [ m_nyPP ] ] ;
}
}
break ;
2010-04-27 21:06:42 +00:00
}
2010-05-17 11:10:14 +00:00
2010-04-27 21:06:42 +00:00
}