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"
2012-06-06 08:25:40 +00:00
# include "engine_cylinder.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"
2013-06-05 12:56:34 +00:00
# include "tools/useful.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
{
2011-08-16 15:03:57 +00:00
m_MeshType = CYLINDRICAL ;
2012-06-06 08:29:57 +00:00
m_Cyl_Ext = NULL ;
2010-04-09 13:51:37 +00:00
}
Operator_Cylinder : : ~ Operator_Cylinder ( )
{
2010-05-08 16:12:44 +00:00
}
2012-06-06 08:25:40 +00:00
2014-01-06 14:40:39 +00:00
Engine * Operator_Cylinder : : CreateEngine ( )
2012-06-06 08:25:40 +00:00
{
//! create a special cylindrical-engine
2014-01-06 14:40:39 +00:00
m_Engine = Engine_Cylinder : : New ( this , m_numThreads ) ;
return m_Engine ;
2012-06-06 08:25:40 +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
}
2011-03-18 13:17:09 +00:00
double Operator_Cylinder : : GetRawDiscDelta ( int ny , const int pos ) const
{
if ( CC_closedAlpha & & ny = = 1 & & pos = = - 1 )
return ( discLines [ 1 ] [ numLines [ 1 ] - 2 ] - discLines [ 1 ] [ numLines [ 1 ] - 3 ] ) ;
2013-12-28 19:57:31 +00:00
if ( CC_closedAlpha & & ny = = 1 & & ( pos = = ( int ) numLines [ ny ] - 1 ) )
return ( discLines [ 1 ] [ 2 ] - discLines [ 1 ] [ 1 ] ) ;
2011-03-18 13:17:09 +00:00
return Operator_Multithread : : GetRawDiscDelta ( ny , pos ) ;
}
2014-10-19 19:59:39 +00:00
double Operator_Cylinder : : GetMaterial ( int ny , const double * coords , int MatType , vector < CSPrimitives * > vPrims , bool markAsUsed ) const
2011-03-18 13:17:09 +00:00
{
double l_coords [ ] = { coords [ 0 ] , coords [ 1 ] , coords [ 2 ] } ;
if ( CC_closedAlpha & & ( coords [ 1 ] > GetDiscLine ( 1 , 0 , false ) + 2 * PI ) )
l_coords [ 1 ] - = 2 * PI ;
if ( CC_closedAlpha & & ( coords [ 1 ] < GetDiscLine ( 1 , 0 , false ) ) )
l_coords [ 1 ] + = 2 * PI ;
2014-10-19 19:59:39 +00:00
return Operator_Multithread : : GetMaterial ( ny , l_coords , MatType , vPrims , markAsUsed ) ;
2011-03-18 13:17:09 +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 ;
}
2016-02-18 21:58:07 +00:00
double Operator_Cylinder : : CalcTimestep ( )
{
if ( discLines [ 0 ] [ 0 ] = = 0.0 )
// use conservative timestep for a mesh including the r==0 singularity
m_TimeStepVar = 1 ;
return Operator : : CalcTimestep ( ) ;
}
2013-02-06 15:33:12 +00:00
inline unsigned int Operator_Cylinder : : GetNumberOfLines ( int ny , bool full ) const
2010-04-11 21:52:38 +00:00
{
2013-02-06 15:33:12 +00:00
if ( full )
return Operator_Multithread : : GetNumberOfLines ( ny , full ) ;
2010-04-11 21:52:38 +00:00
//this is necessary for a correct field processing... cylindrical engine has to reset this by adding +1
if ( CC_closedAlpha & & ny = = 1 )
2013-02-06 15:33:12 +00:00
return Operator_Multithread : : GetNumberOfLines ( ny , true ) - 2 ;
2010-04-11 21:52:38 +00:00
2013-02-06 15:33:12 +00:00
return Operator_Multithread : : GetNumberOfLines ( ny , full ) ;
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
{
2012-06-06 08:19:30 +00:00
bool ret = Operator_Multithread : : GetYeeCoords ( ny , pos , coords , dualMesh ) ;
if ( CC_closedAlpha & & ( coords [ 1 ] > = GetDiscLine ( 1 , 0 , false ) + 2 * PI ) )
2011-03-16 11:26:41 +00:00
coords [ 1 ] - = 2 * PI ;
2011-03-18 13:17:09 +00:00
if ( CC_closedAlpha & & ( coords [ 1 ] < GetDiscLine ( 1 , 0 , false ) ) )
coords [ 1 ] + = 2 * PI ;
2011-03-16 11:26:41 +00:00
2012-06-06 08:19:30 +00:00
return ret ;
2011-03-16 11:26:41 +00:00
}
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 ;
}
2011-03-18 13:17:09 +00:00
double Operator_Cylinder : : GetNodeWidth ( int ny , const int pos [ 3 ] , bool dualMesh ) const
{
if ( ( pos [ 0 ] < 0 ) | | ( pos [ 1 ] < 0 & & CC_closedAlpha = = false ) | | ( pos [ 2 ] < 0 ) )
return 0.0 ;
2012-11-15 20:44:43 +00:00
unsigned int uiPos [ ] = { ( unsigned int ) pos [ 0 ] , ( unsigned int ) pos [ 1 ] , ( unsigned int ) pos [ 2 ] } ;
2011-03-18 13:17:09 +00:00
if ( pos [ 1 ] < 0 & & CC_closedAlpha = = true )
uiPos [ 1 ] + = numLines [ 1 ] - 2 ;
return GetNodeWidth ( ny , uiPos , dualMesh ) ;
}
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
2011-03-18 13:17:09 +00:00
double Operator_Cylinder : : GetNodeArea ( int ny , const int pos [ 3 ] , bool dualMesh ) const
{
if ( ( pos [ 0 ] < 0 ) | | ( pos [ 1 ] < 0 & & CC_closedAlpha = = false ) | | ( pos [ 2 ] < 0 ) )
return 0.0 ;
2012-11-15 20:44:43 +00:00
unsigned int uiPos [ ] = { ( unsigned int ) pos [ 0 ] , ( unsigned int ) pos [ 1 ] , ( unsigned int ) pos [ 2 ] } ;
2011-03-18 13:17:09 +00:00
if ( pos [ 1 ] < 0 & & CC_closedAlpha = = true )
uiPos [ 1 ] + = numLines [ 1 ] - 2 ;
return GetNodeArea ( ny , uiPos , dualMesh ) ;
}
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 ) ;
}
2012-04-27 14:31:36 +00:00
double Operator_Cylinder : : GetCellVolume ( const unsigned int pos [ 3 ] , bool dualMesh ) const
{
return GetEdgeArea ( 2 , pos , dualMesh ) * GetEdgeLength ( 2 , pos , 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 ) ;
}
2013-02-06 15:33:12 +00:00
double Operator_Cylinder : : FitToAlphaRange ( double a_coord , bool fullMesh ) const
2012-11-21 15:41:53 +00:00
{
double min = GetDiscLine ( 1 , 0 ) ;
2013-02-06 15:33:12 +00:00
double max = GetDiscLine ( 1 , GetNumberOfLines ( 1 , fullMesh ) - 1 ) ;
2012-11-21 15:41:53 +00:00
if ( ( a_coord > = min ) & & ( a_coord < = max ) )
return a_coord ;
while ( a_coord < min )
{
a_coord + = 2 * PI ;
if ( a_coord > max )
return a_coord - 2 * PI ;
if ( a_coord > min )
return a_coord ;
}
while ( a_coord > max )
{
a_coord - = 2 * PI ;
if ( a_coord < min )
return a_coord + 2 * PI ;
if ( a_coord < max )
return a_coord ;
}
// this cannot happen
return a_coord ;
}
2013-12-28 19:57:31 +00:00
int Operator_Cylinder : : MapAlphaIndex2Range ( int pos ) const
{
if ( ! CC_closedAlpha )
return pos ;
if ( pos < 0 )
return ( int ) numLines [ 1 ] + pos - 2 ;
else if ( pos > = ( int ) numLines [ 1 ] - 2 )
return pos - ( int ) numLines [ 1 ] + 2 ;
else
return pos ;
}
bool Operator_Cylinder : : GetCellCenterMaterialAvgCoord ( const int pos [ 3 ] , double coord [ 3 ] ) const
{
if ( ! CC_closedAlpha | | ( ( pos [ 1 ] > = 0 ) & & ( pos [ 1 ] < ( int ) numLines [ 1 ] - 2 ) ) )
{
return Operator_Multithread : : GetCellCenterMaterialAvgCoord ( pos , coord ) ;
}
if ( ( pos [ 0 ] < 0 ) | | ( pos [ 2 ] < 0 ) )
return false ;
int l_pos [ 3 ] = { pos [ 0 ] , 0 , pos [ 2 ] } ;
l_pos [ 1 ] = MapAlphaIndex2Range ( pos [ 1 ] ) ;
return Operator_Multithread : : GetCellCenterMaterialAvgCoord ( l_pos , coord ) ;
}
2013-02-06 15:33:12 +00:00
unsigned int Operator_Cylinder : : SnapToMeshLine ( int ny , double coord , bool & inside , bool dualMesh , bool fullMesh ) const
2012-11-21 15:41:53 +00:00
{
if ( ny = = 1 )
coord = FitToAlphaRange ( coord ) ;
2013-02-06 15:33:12 +00:00
return Operator_Multithread : : SnapToMeshLine ( ny , coord , inside , dualMesh , fullMesh ) ;
2012-11-21 15:41:53 +00:00
}
2013-02-06 15:33:12 +00:00
int Operator_Cylinder : : SnapBox2Mesh ( const double * start , const double * stop , unsigned int * uiStart , unsigned int * uiStop , bool dualMesh , bool fullMesh , int SnapMethod , bool * bStartIn , bool * bStopIn ) const
2012-11-21 15:41:53 +00:00
{
double a_min = GetDiscLine ( 1 , 0 ) ;
2013-02-06 15:33:12 +00:00
double a_max = GetDiscLine ( 1 , GetNumberOfLines ( 1 , fullMesh ) - 1 ) ;
2012-11-21 15:41:53 +00:00
double a_size = stop [ 1 ] - start [ 1 ] ;
double a_center = FitToAlphaRange ( 0.5 * ( stop [ 1 ] + start [ 1 ] ) ) ;
double a_start = a_center - a_size / 2 ;
double a_stop = a_start + a_size ;
if ( a_stop > a_max )
a_stop = a_max ;
if ( a_stop < a_min )
a_stop = a_min ;
if ( a_start > a_max )
a_start = a_max ;
if ( a_start < a_min )
a_start = a_min ;
double l_start [ 3 ] = { start [ 0 ] , a_start , start [ 2 ] } ;
double l_stop [ 3 ] = { stop [ 0 ] , a_stop , stop [ 2 ] } ;
2013-02-06 15:33:12 +00:00
return Operator_Multithread : : SnapBox2Mesh ( l_start , l_stop , uiStart , uiStop , dualMesh , fullMesh , SnapMethod , bStartIn , bStopIn ) ;
2012-11-21 15:41:53 +00:00
}
2013-06-05 12:56:34 +00:00
int Operator_Cylinder : : SnapLine2Mesh ( const double * start , const double * stop , unsigned int * uiStart , unsigned int * uiStop , bool dualMesh , bool fullMesh ) const
{
int ret = Operator_Multithread : : SnapLine2Mesh ( start , stop , uiStart , uiStop , dualMesh , fullMesh ) ;
if ( ( stop [ 1 ] > start [ 1 ] ) & & ( uiStop [ 1 ] < uiStart [ 1 ] ) & & ( uiStop [ 1 ] = = 0 ) )
uiStop [ 1 ] = GetNumberOfLines ( 1 , fullMesh ) - 1 - ( int ) CC_closedAlpha ;
if ( ( stop [ 1 ] < start [ 1 ] ) & & ( uiStop [ 1 ] > uiStart [ 1 ] ) & & ( uiStop [ 1 ] = = GetNumberOfLines ( 1 , fullMesh ) - 1 - ( int ) CC_closedAlpha ) )
uiStop [ 1 ] = 0 ;
return ret ;
}
2013-08-16 11:19:12 +00:00
Grid_Path Operator_Cylinder : : FindPath ( double start [ ] , double stop [ ] )
2013-06-05 12:56:34 +00:00
{
double l_start [ 3 ] ;
double l_stop [ 3 ] ;
2013-06-10 08:13:58 +00:00
for ( int n = 0 ; n < 3 ; + + n )
2013-06-05 12:56:34 +00:00
{
2013-06-10 08:13:58 +00:00
l_start [ n ] = start [ n ] ;
l_stop [ n ] = stop [ n ] ;
}
while ( fabs ( l_stop [ 1 ] - l_start [ 1 ] ) > PI )
{
if ( l_stop [ 1 ] > l_start [ 1 ] )
l_stop [ 1 ] - = 2 * PI ;
else
l_stop [ 1 ] + = 2 * PI ;
2013-06-05 12:56:34 +00:00
}
2013-06-10 08:13:58 +00:00
double help = 0 ;
if ( l_start [ 1 ] > l_stop [ 1 ] )
2013-06-05 12:56:34 +00:00
{
for ( int n = 0 ; n < 3 ; + + n )
{
2013-06-10 08:13:58 +00:00
help = l_start [ n ] ;
l_start [ n ] = l_stop [ n ] ;
l_stop [ n ] = help ;
2013-06-05 12:56:34 +00:00
}
}
2013-06-10 08:13:58 +00:00
2013-06-05 12:56:34 +00:00
double a_start = FitToAlphaRange ( l_start [ 1 ] ) ;
double a_stop = FitToAlphaRange ( l_stop [ 1 ] ) ;
if ( a_stop > = a_start )
2013-06-10 08:13:58 +00:00
{
l_start [ 1 ] = a_start ;
l_stop [ 1 ] = a_stop ;
return Operator_Multithread : : FindPath ( l_start , l_stop ) ;
}
2013-06-05 12:56:34 +00:00
2013-06-10 08:13:58 +00:00
// if a-stop fitted to disc range is now smaller than a-start, it must step over the a-bounds...
2013-08-16 11:19:12 +00:00
Grid_Path path ;
2013-06-10 08:13:58 +00:00
for ( int n = 0 ; n < 3 ; + + n )
2013-06-05 12:56:34 +00:00
{
2013-06-10 08:13:58 +00:00
if ( ( l_start [ n ] < GetDiscLine ( n , 0 ) ) & & ( l_stop [ n ] < GetDiscLine ( n , 0 ) ) )
return path ; //lower bound violation
if ( ( l_start [ n ] > GetDiscLine ( n , GetNumberOfLines ( n , true ) - 1 ) ) & & ( l_stop [ n ] > GetDiscLine ( n , GetNumberOfLines ( n , true ) - 1 ) ) )
return path ; //upper bound violation
2013-06-05 12:56:34 +00:00
}
2013-06-10 08:13:58 +00:00
if ( g_settings . GetVerboseLevel ( ) > 2 )
cerr < < __func__ < < " : A path was leaving the alpha-direction mesh... " < < endl ;
2013-06-05 12:56:34 +00:00
// this section comes into play, if the line moves over the angulare mesh-end/start
// we try to have one part of the path on both "ends" of the mesh and stitch them together
2013-08-16 11:19:12 +00:00
Grid_Path path1 ;
Grid_Path path2 ;
2013-06-05 12:56:34 +00:00
// calculate the intersection of the line with the a-max boundary
double p0 [ 3 ] , p1 [ 3 ] , p2 [ 3 ] ;
for ( int n = 0 ; n < 3 ; + + n )
{
p0 [ n ] = GetDiscLine ( n , 0 ) ;
p1 [ n ] = p0 [ n ] ;
p2 [ n ] = p0 [ n ] ;
}
p0 [ 1 ] = GetDiscLine ( 1 , GetNumberOfLines ( 1 , true ) - 1 - ( int ) CC_closedAlpha ) ;
p1 [ 1 ] = p0 [ 1 ] ;
p2 [ 1 ] = p0 [ 1 ] ;
p1 [ 0 ] = discLines [ 0 ] [ numLines [ 0 ] - 1 ] ;
p2 [ 2 ] = discLines [ 2 ] [ numLines [ 2 ] - 1 ] ;
TransformCoordSystem ( p0 , p0 , m_MeshType , CARTESIAN ) ;
TransformCoordSystem ( p1 , p1 , m_MeshType , CARTESIAN ) ;
TransformCoordSystem ( p2 , p2 , m_MeshType , CARTESIAN ) ;
double c_start [ 3 ] , c_stop [ 3 ] ;
TransformCoordSystem ( l_start , c_start , m_MeshType , CARTESIAN ) ;
TransformCoordSystem ( l_stop , c_stop , m_MeshType , CARTESIAN ) ;
double intersect [ 3 ] ;
double dist ;
int ret = LinePlaneIntersection ( p0 , p1 , p2 , c_start , c_stop , intersect , dist ) ;
if ( ret < 0 )
{
cerr < < __func__ < < " : Error, unable to calculate intersection, this should not happen! " < < endl ;
return path ; // return empty path;
}
if ( ret = = 0 )
{
TransformCoordSystem ( intersect , intersect , CARTESIAN , m_MeshType ) ;
2013-12-03 10:26:31 +00:00
intersect [ 1 ] = GetDiscLine ( 1 , GetNumberOfLines ( 1 , true ) - 1 - ( int ) CC_closedAlpha ) ;
l_start [ 1 ] = FitToAlphaRange ( l_start [ 1 ] ) ;
2013-06-05 12:56:34 +00:00
path1 = Operator : : FindPath ( l_start , intersect ) ;
if ( g_settings . GetVerboseLevel ( ) > 2 )
cerr < < __func__ < < " : Intersection top: " < < intersect [ 0 ] < < " , " < < intersect [ 1 ] < < " , " < < intersect [ 2 ] < < endl ;
} //otherwise the path was not intersecting the upper a-bound...
if ( CC_closedAlpha = = false )
{
for ( int n = 0 ; n < 3 ; + + n )
{
p0 [ n ] = GetDiscLine ( n , 0 ) ;
p1 [ n ] = p0 [ n ] ;
p2 [ n ] = p0 [ n ] ;
}
p1 [ 0 ] = discLines [ 0 ] [ numLines [ 0 ] - 1 ] ;
p2 [ 2 ] = discLines [ 2 ] [ numLines [ 2 ] - 1 ] ;
TransformCoordSystem ( p0 , p0 , m_MeshType , CARTESIAN ) ;
TransformCoordSystem ( p1 , p1 , m_MeshType , CARTESIAN ) ;
TransformCoordSystem ( p2 , p2 , m_MeshType , CARTESIAN ) ;
TransformCoordSystem ( l_start , c_start , m_MeshType , CARTESIAN ) ;
TransformCoordSystem ( l_stop , c_stop , m_MeshType , CARTESIAN ) ;
ret = LinePlaneIntersection ( p0 , p1 , p2 , c_start , c_stop , intersect , dist ) ;
TransformCoordSystem ( intersect , intersect , CARTESIAN , m_MeshType ) ;
}
if ( ret = = 0 )
{
2013-12-03 10:26:31 +00:00
intersect [ 1 ] = GetDiscLine ( 1 , 0 ) ;
l_stop [ 1 ] = FitToAlphaRange ( l_stop [ 1 ] ) ;
2013-06-05 12:56:34 +00:00
path2 = Operator : : FindPath ( intersect , l_stop ) ;
if ( g_settings . GetVerboseLevel ( ) > 2 )
cerr < < __func__ < < " : Intersection bottom: " < < intersect [ 0 ] < < " , " < < intersect [ 1 ] < < " , " < < intersect [ 2 ] < < endl ;
}
//combine path
for ( size_t t = 0 ; t < path1 . dir . size ( ) ; + + t )
{
path . posPath [ 0 ] . push_back ( path1 . posPath [ 0 ] . at ( t ) ) ;
path . posPath [ 1 ] . push_back ( path1 . posPath [ 1 ] . at ( t ) ) ;
path . posPath [ 2 ] . push_back ( path1 . posPath [ 2 ] . at ( t ) ) ;
path . dir . push_back ( path1 . dir . at ( t ) ) ;
}
for ( size_t t = 0 ; t < path2 . dir . size ( ) ; + + t )
{
path . posPath [ 0 ] . push_back ( path2 . posPath [ 0 ] . at ( t ) ) ;
path . posPath [ 1 ] . push_back ( path2 . posPath [ 1 ] . at ( t ) ) ;
path . posPath [ 2 ] . push_back ( path2 . posPath [ 2 ] . at ( t ) ) ;
path . dir . push_back ( path2 . dir . at ( t ) ) ;
}
2013-12-03 10:26:31 +00:00
if ( CC_closedAlpha = = true )
for ( size_t t = 0 ; t < path . dir . size ( ) ; + + t )
{
if ( ( ( path . dir . at ( t ) = = 0 ) | | ( path . dir . at ( t ) = = 2 ) ) & & ( path . posPath [ 1 ] . at ( t ) = = 0 ) )
path . posPath [ 1 ] . at ( t ) = numLines [ 1 ] - 2 ;
}
2013-06-05 12:56:34 +00:00
return path ;
}
2011-03-18 13:17:09 +00:00
bool Operator_Cylinder : : SetupCSXGrid ( CSRectGrid * grid )
2010-04-09 13:51:37 +00:00
{
2011-03-18 13:17:09 +00:00
unsigned int alphaNum ;
double * alphaLines = NULL ;
alphaLines = grid - > GetLines ( 1 , alphaLines , alphaNum , true ) ;
2010-04-09 13:51:37 +00:00
2011-03-18 13:17:09 +00:00
double minmaxA = fabs ( alphaLines [ alphaNum - 1 ] - alphaLines [ 0 ] ) ;
if ( fabs ( minmaxA - 2 * PI ) < OPERATOR_CYLINDER_CLOSED_ALPHA_THRESHOLD )
2010-04-09 13:51:37 +00:00
{
2011-11-08 10:49:14 +00:00
if ( g_settings . GetVerboseLevel ( ) > 0 )
cout < < " Operator_Cylinder::SetupCSXGrid: Alpha is a full 2*PI => closed Cylinder... " < < endl ;
2010-04-11 21:52:38 +00:00
CC_closedAlpha = true ;
2011-03-18 13:17:09 +00:00
grid - > SetLine ( 1 , alphaNum - 1 , 2 * PI + alphaLines [ 0 ] ) ;
grid - > AddDiscLine ( 1 , 2 * PI + alphaLines [ 1 ] ) ;
2010-04-09 13:51:37 +00:00
}
else if ( minmaxA > 2 * PI )
2010-12-06 12:04:37 +00:00
{
2011-03-18 13:17:09 +00:00
cerr < < " Operator_Cylinder::SetupCSXGrid: Alpha Max-Min must not be larger than 2*PI!!! " < < endl ;
2010-12-06 12:04:37 +00:00
Reset ( ) ;
return false ;
}
2010-04-24 12:06:00 +00:00
else
{
CC_closedAlpha = false ;
}
2010-04-09 13:51:37 +00:00
2011-03-28 08:38:48 +00:00
CC_R0_included = false ;
2011-03-18 13:17:09 +00:00
if ( grid - > GetLine ( 0 , 0 ) < 0 )
2010-12-06 12:04:37 +00:00
{
2011-03-18 13:17:09 +00:00
cerr < < " Operator_Cylinder::SetupCSXGrid: r<0 not allowed in Cylinder Coordinates!!! " < < endl ;
2010-12-06 12:04:37 +00:00
Reset ( ) ;
return false ;
}
2011-03-18 13:17:09 +00:00
else if ( grid - > GetLine ( 0 , 0 ) = = 0.0 )
2010-04-09 13:51:37 +00:00
{
2011-11-08 10:49:14 +00:00
if ( g_settings . GetVerboseLevel ( ) > 0 )
cout < < " Operator_Cylinder::SetupCSXGrid: r=0 included... " < < endl ;
2011-03-28 08:38:48 +00:00
CC_R0_included = CC_closedAlpha ; //needed for correct ec-calculation, deactivate if closed cylinder is false... --> E_r = 0 anyways
}
# ifdef MPI_SUPPORT
// Setup an MPI split in alpha direction for a closed cylinder
CC_MPI_Alpha = false ;
if ( ( m_NeighborUp [ 1 ] > = 0 ) | | ( m_NeighborDown [ 1 ] > = 0 ) ) //check for MPI split in alpha direction
{
double minmaxA = 2 * PI ; // fabs(m_OrigDiscLines[1][m_OrigNumLines[1]-1]-m_OrigDiscLines[1][0]);
if ( fabs ( minmaxA - 2 * PI ) < OPERATOR_CYLINDER_CLOSED_ALPHA_THRESHOLD ) //check for closed alpha MPI split
{
CC_MPI_Alpha = true ;
if ( m_OrigDiscLines [ 0 ] [ 0 ] = = 0 )
{
cerr < < " Operator_Cylinder::SetupCSXGrid: Error: MPI split in alpha direction for closed cylinder including r==0 is currently not supported! Exit! " < < endl ;
exit ( - 2 ) ;
}
if ( m_NeighborUp [ 1 ] < 0 ) //check if this process is at the alpha-end
{
grid - > SetLine ( 1 , alphaNum - 1 , 2 * PI + m_OrigDiscLines [ 1 ] [ 0 ] ) ;
grid - > AddDiscLine ( 1 , 2 * PI + m_OrigDiscLines [ 1 ] [ 1 ] ) ;
SetNeighborUp ( 1 , m_ProcTable [ m_ProcTablePos [ 0 ] ] [ 0 ] [ m_ProcTablePos [ 2 ] ] ) ;
}
if ( m_NeighborDown [ 1 ] < 0 ) //check if this process is at the alpha-start
{
SetNeighborDown ( 1 , m_ProcTable [ m_ProcTablePos [ 0 ] ] [ m_SplitNumber [ 1 ] - 1 ] [ m_ProcTablePos [ 2 ] ] ) ;
}
//Note: the process table will not reflect this up/down neighbors necessary for a closed cylinder
}
2010-04-09 13:51:37 +00:00
}
2011-03-28 08:38:48 +00:00
# endif
2010-04-09 13:51:37 +00:00
2011-03-18 13:17:09 +00:00
if ( Operator_Multithread : : SetupCSXGrid ( grid ) = = false )
return false ;
2010-08-23 19:53:29 +00:00
if ( CC_closedAlpha | | CC_R0_included )
2012-06-06 08:29:57 +00:00
{
m_Cyl_Ext = new Operator_Ext_Cylinder ( this ) ;
this - > AddExtension ( m_Cyl_Ext ) ;
}
2010-08-23 19:53:29 +00:00
2010-04-09 13:51:37 +00:00
return true ;
}
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 )
{
2012-02-10 10:55:55 +00:00
if ( op_ext - > IsCylinderCoordsSave ( CC_closedAlpha , CC_R0_included ) )
2012-09-17 14:54:55 +00:00
Operator_Multithread : : AddExtension ( op_ext ) ;
2010-05-03 20:37:29 +00:00
else
2012-09-17 14:54:55 +00:00
{
2010-05-03 20:37:29 +00:00
cerr < < " Operator_Cylinder::AddExtension: Warning: Operator extension \" " < < op_ext - > GetExtensionName ( ) < < " \" is not compatible with cylinder-coords!! skipping...! " < < endl ;
2012-10-29 13:51:02 +00:00
delete op_ext ;
2012-09-17 14:54:55 +00:00
}
2010-05-03 20:37:29 +00:00
}