2010-04-09 13:51:37 +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-08 16:12:44 +00:00
# include "engine.h"
2010-12-06 09:44:25 +00:00
# include "Common/processfields.h"
2010-04-09 13:51:37 +00:00
# include "operator_cylinder.h"
2010-12-06 14:30:47 +00:00
# include "extensions/operator_extension.h"
# include "extensions/operator_ext_cylinder.h"
2010-04-09 13:51:37 +00:00
2010-06-05 23:50:58 +00:00
Operator_Cylinder * Operator_Cylinder : : New ( unsigned int numThreads )
2010-04-09 13:51:37 +00:00
{
2010-05-19 19:25:15 +00:00
cout < < " Create cylindrical FDTD operator " < < endl ;
2010-04-09 13:51:37 +00:00
Operator_Cylinder * op = new Operator_Cylinder ( ) ;
2010-06-05 23:50:58 +00:00
op - > setNumThreads ( numThreads ) ;
2010-04-09 13:51:37 +00:00
op - > Init ( ) ;
return op ;
}
2010-08-15 12:11:42 +00:00
Operator_Cylinder : : Operator_Cylinder ( ) : Operator_Multithread ( )
2010-04-09 13:51:37 +00:00
{
2010-06-02 15:21:58 +00:00
m_MeshType = ProcessFields : : CYLINDRICAL_MESH ;
2010-04-09 13:51:37 +00:00
}
Operator_Cylinder : : ~ Operator_Cylinder ( )
{
2010-05-08 16:12:44 +00:00
}
2010-04-09 13:51:37 +00:00
void Operator_Cylinder : : Init ( )
{
CC_closedAlpha = false ;
CC_R0_included = false ;
2010-08-15 12:11:42 +00:00
Operator_Multithread : : Init ( ) ;
2010-04-09 13:51:37 +00:00
}
2010-10-27 12:49:16 +00:00
int Operator_Cylinder : : CalcECOperator ( DebugFlags debugFlags )
{
// debugs only work with the native vector dumps
bool natDump = g_settings . NativeFieldDumps ( ) ;
g_settings . SetNativeFieldDumps ( true ) ;
int rc = Operator_Multithread : : CalcECOperator ( debugFlags ) ;
// reset original settings
g_settings . SetNativeFieldDumps ( natDump ) ;
return rc ;
}
2010-04-11 21:52:38 +00:00
inline unsigned int Operator_Cylinder : : GetNumberOfLines ( int ny ) const
{
//this is necessary for a correct field processing... cylindrical engine has to reset this by adding +1
if ( CC_closedAlpha & & ny = = 1 )
2011-03-15 08:41:29 +00:00
return Operator_Multithread : : GetNumberOfLines ( ny ) - 1 ;
2010-04-11 21:52:38 +00:00
2011-03-15 08:41:29 +00:00
return Operator_Multithread : : GetNumberOfLines ( ny ) ;
2010-04-11 21:52:38 +00:00
}
2010-04-23 06:17:42 +00:00
string Operator_Cylinder : : GetDirName ( int ny ) const
{
if ( ny = = 0 ) return " rho " ;
if ( ny = = 1 ) return " alpha " ;
if ( ny = = 2 ) return " z " ;
return " " ;
}
2011-03-16 11:26:41 +00:00
bool Operator_Cylinder : : GetYeeCoords ( int ny , unsigned int pos [ 3 ] , double * coords , bool dualMesh ) const
{
bool ret = Operator_Multithread : : GetYeeCoords ( ny , pos , coords , dualMesh ) ;
if ( ( CC_closedAlpha = = false ) | | ( ny ! = 1 ) )
return ret ;
if ( coords [ 1 ] > GetDiscLine ( 1 , 0 , false ) + 2 * PI )
{
coords [ 1 ] - = 2 * PI ;
}
return ret ;
}
2010-09-17 12:51:07 +00:00
double Operator_Cylinder : : GetNodeWidth ( int ny , const unsigned int pos [ 3 ] , bool dualMesh ) const
2010-09-02 13:35:13 +00:00
{
if ( ( ny < 0 ) | | ( ny > 2 ) ) return 0.0 ;
2010-09-17 12:51:07 +00:00
if ( pos [ ny ] > = numLines [ ny ] ) return 0.0 ;
2010-12-08 15:55:27 +00:00
double width = Operator_Multithread : : GetEdgeLength ( ny , pos , ! dualMesh ) ;
2010-09-02 13:35:13 +00:00
if ( ny = = 1 )
width * = GetDiscLine ( 0 , pos [ 0 ] , dualMesh ) ;
return width ;
}
2010-09-17 12:51:07 +00:00
double Operator_Cylinder : : GetNodeArea ( int ny , const unsigned int pos [ 3 ] , bool dualMesh ) const
2010-07-29 16:30:50 +00:00
{
2010-09-17 12:51:07 +00:00
if ( pos [ ny ] > = numLines [ ny ] ) return 0.0 ;
if ( pos [ 0 ] > = numLines [ 0 ] ) return 0.0 ;
2010-07-29 16:30:50 +00:00
if ( ny = = 2 )
{
2010-12-08 15:55:27 +00:00
double da = Operator_Multithread : : GetEdgeLength ( 1 , pos , dualMesh ) / gridDelta ;
2010-07-29 16:30:50 +00:00
double r1 , r2 ;
2010-12-08 15:55:27 +00:00
if ( dualMesh )
2010-07-29 16:30:50 +00:00
{
2010-12-08 15:55:27 +00:00
r1 = GetDiscLine ( 0 , pos [ 0 ] , false ) * gridDelta ;
r2 = r1 + GetEdgeLength ( 0 , pos , false ) ;
2010-07-29 16:30:50 +00:00
}
else
{
2010-12-08 15:55:27 +00:00
r2 = GetDiscLine ( 0 , pos [ 0 ] , ! dualMesh ) * gridDelta ;
r1 = r2 - GetEdgeLength ( 0 , pos , true ) ;
2010-07-29 16:30:50 +00:00
}
2010-09-02 13:35:13 +00:00
2010-12-08 15:55:27 +00:00
if ( r1 < = 0 )
return da / 2 * pow ( r2 , 2 ) ;
2010-09-02 13:35:13 +00:00
else
2010-12-08 15:55:27 +00:00
return da / 2 * ( pow ( r2 , 2 ) - pow ( r1 , 2 ) ) ;
2010-09-02 13:35:13 +00:00
}
2010-12-08 15:55:27 +00:00
2010-08-15 12:11:42 +00:00
return Operator_Multithread : : GetNodeArea ( ny , pos , dualMesh ) ;
2010-07-29 16:30:50 +00:00
}
2010-04-11 21:52:38 +00:00
2010-09-17 12:51:07 +00:00
double Operator_Cylinder : : GetEdgeLength ( int ny , const unsigned int pos [ 3 ] , bool dualMesh ) const
2010-09-02 13:35:13 +00:00
{
2010-12-08 15:55:27 +00:00
double length = Operator_Multithread : : GetEdgeLength ( ny , pos , dualMesh ) ;
2010-09-02 13:35:13 +00:00
if ( ny ! = 1 )
return length ;
return length * GetDiscLine ( 0 , pos [ 0 ] , dualMesh ) ;
}
2010-09-17 12:51:07 +00:00
double Operator_Cylinder : : GetEdgeArea ( int ny , const unsigned int pos [ 3 ] , bool dualMesh ) const
2010-09-02 13:35:13 +00:00
{
if ( ny ! = 0 )
return GetNodeArea ( ny , pos , dualMesh ) ;
return GetEdgeLength ( 1 , pos , ! dualMesh ) * GetEdgeLength ( 2 , pos , ! dualMesh ) ;
}
2010-04-09 13:51:37 +00:00
bool Operator_Cylinder : : SetGeometryCSX ( ContinuousStructure * geo )
{
2010-08-15 12:11:42 +00:00
if ( Operator_Multithread : : SetGeometryCSX ( geo ) = = false ) return false ;
2010-04-09 13:51:37 +00:00
double minmaxA = fabs ( discLines [ 1 ] [ numLines [ 1 ] - 1 ] - discLines [ 1 ] [ 0 ] ) ;
if ( fabs ( minmaxA - 2 * PI ) < ( 2 * PI ) / 10 / numLines [ 1 ] ) //check minmaxA smaller then a tenth of average alpha-width
{
cout < < " Operator_Cylinder::SetGeometryCSX: Alpha is a full 2*PI => closed Cylinder... " < < endl ;
2010-04-11 21:52:38 +00:00
CC_closedAlpha = true ;
discLines [ 1 ] [ numLines [ 1 ] - 1 ] = discLines [ 1 ] [ 0 ] + 2 * PI ;
cerr < < " Operator_Cylinder::SetGeometryCSX: Warning, not handling the disc-line width and material averaging correctly yet for a closed cylinder... " < < endl ;
if ( MainOp - > GetIndexDelta ( 1 , 0 ) - MainOp - > GetIndexDelta ( 1 , numLines [ 1 ] - 2 ) > ( 2 * PI ) / 10 / numLines [ 1 ] )
{
cerr < < " Operator_Cylinder::SetGeometryCSX: first and last angle delta must be the same... deviation to large... " < < MainOp - > GetIndexDelta ( 1 , 0 ) - MainOp - > GetIndexDelta ( 1 , numLines [ 1 ] - 2 ) < < endl ;
exit ( 1 ) ;
}
if ( MainOp - > GetIndexDelta ( 1 , 0 ) - MainOp - > GetIndexDelta ( 1 , numLines [ 1 ] - 2 ) > 0 )
{
cerr < < " Operator_Cylinder::SetGeometryCSX: first and last angle delta must be the same... auto correction of deviation: " < < MainOp - > GetIndexDelta ( 1 , 0 ) - MainOp - > GetIndexDelta ( 1 , numLines [ 1 ] - 2 ) < < endl ;
discLines [ 1 ] [ numLines [ 1 ] - 2 ] = discLines [ 1 ] [ numLines [ 1 ] - 1 ] - MainOp - > GetIndexDelta ( 1 , 0 ) ;
}
2010-04-09 13:51:37 +00:00
}
else if ( minmaxA > 2 * PI )
2010-12-06 12:04:37 +00:00
{
cerr < < " Operator_Cylinder::SetGeometryCSX: Alpha Max-Min must not be larger than 2*PI!!! " < < endl ;
Reset ( ) ;
return false ;
}
2010-04-24 12:06:00 +00:00
else
{
CC_closedAlpha = false ;
}
2010-04-09 13:51:37 +00:00
if ( discLines [ 0 ] [ 0 ] < 0 )
2010-12-06 12:04:37 +00:00
{
cerr < < " Operator_Cylinder::SetGeometryCSX: r<0 not allowed in Cylinder Coordinates!!! " < < endl ;
Reset ( ) ;
return false ;
}
2010-04-09 13:51:37 +00:00
else if ( discLines [ 0 ] [ 0 ] = = 0.0 )
{
cout < < " Operator_Cylinder::SetGeometryCSX: r=0 included... " < < endl ;
2010-05-06 20:55:59 +00:00
CC_R0_included = true ; //also needed for correct ec-calculation
2010-04-09 13:51:37 +00:00
}
2010-08-23 19:53:29 +00:00
if ( CC_closedAlpha | | CC_R0_included )
this - > AddExtension ( new Operator_Ext_Cylinder ( this ) ) ;
2010-04-09 13:51:37 +00:00
return true ;
}
void Operator_Cylinder : : ApplyElectricBC ( bool * dirs )
{
if ( dirs = = NULL ) return ;
if ( CC_closedAlpha )
{
2010-12-06 12:04:37 +00:00
dirs [ 2 ] = 0 ;
dirs [ 3 ] = 0 ; //no PEC in alpha directions...
2010-04-09 13:51:37 +00:00
}
if ( CC_R0_included )
{
2010-07-29 16:30:50 +00:00
// E in alpha direction ( aka volt[1][x][y][z] ) is not defined for r==0 --> always zero...
unsigned int pos [ 3 ] = { 0 , 0 , 0 } ;
2010-12-06 12:04:37 +00:00
for ( pos [ 1 ] = 0 ; pos [ 1 ] < numLines [ 1 ] ; + + pos [ 1 ] )
2010-07-29 16:30:50 +00:00
{
2010-12-06 12:04:37 +00:00
for ( pos [ 2 ] = 0 ; pos [ 2 ] < numLines [ 2 ] ; + + pos [ 2 ] )
2010-07-29 16:30:50 +00:00
{
2010-10-20 05:26:16 +00:00
SetVV ( 1 , pos [ 0 ] , pos [ 1 ] , pos [ 2 ] , 0 ) ;
SetVI ( 1 , pos [ 0 ] , pos [ 1 ] , pos [ 2 ] , 0 ) ;
2010-07-29 16:30:50 +00:00
}
}
2010-04-09 13:51:37 +00:00
}
2010-08-15 12:11:42 +00:00
Operator_Multithread : : ApplyElectricBC ( dirs ) ;
2010-04-09 13:51:37 +00:00
}
void Operator_Cylinder : : ApplyMagneticBC ( bool * dirs )
{
if ( dirs = = NULL ) return ;
if ( CC_closedAlpha )
{
2010-12-06 12:04:37 +00:00
dirs [ 2 ] = 0 ;
dirs [ 3 ] = 0 ; //no PMC in alpha directions...
2010-04-09 13:51:37 +00:00
}
if ( CC_R0_included )
{
2010-04-23 14:31:00 +00:00
dirs [ 0 ] = 0 ; //no PMC in r_min directions...
2010-04-09 13:51:37 +00:00
}
2010-08-15 12:11:42 +00:00
Operator_Multithread : : ApplyMagneticBC ( dirs ) ;
2010-04-09 13:51:37 +00:00
}
2010-05-03 20:37:29 +00:00
void Operator_Cylinder : : AddExtension ( Operator_Extension * op_ext )
{
if ( op_ext - > IsCylinderCoordsSave ( ) )
m_Op_exts . push_back ( op_ext ) ;
else
cerr < < " Operator_Cylinder::AddExtension: Warning: Operator extension \" " < < op_ext - > GetExtensionName ( ) < < " \" is not compatible with cylinder-coords!! skipping...! " < < endl ;
}
2010-06-22 10:49:51 +00:00
double Operator_Cylinder : : CalcTimestep ( )
{
2011-02-16 14:28:14 +00:00
m_TimeStepVar = 1 ;
return Operator_Multithread : : CalcTimestep ( ) ;
2010-06-22 10:49:51 +00:00
}