packages/MC/geometry/RTK_Cell.cc
//---------------------------------------------------------------------------//
/*!
 * \brief Empty pin-cell constructor with variable X/Y pitch and vessel.
 *
 * An outer vessel is defined by an enclosing array.  In order to calculate
 * distance to boundary, it is necessary to know the offsets from the origin
 * of the vessel radius to the lower-left coordinates of the pin-cell, ie.
 * \verbatim
  _              _
  xo             x1 _
  |--------------/| y1
  |             / |    o is the origin of the pin cell (0,0) in local pin space
  |            /  |    O origin of the vessel cylinder
  |       o   /   |
  |          /    |
  |         /     | _
  |--------/-\----| yo
  ^           \
  |            \ R
    y_offset    \
  |              \
                  \
  |                \
  < - - - - - - - - O
       x_offset
   \endverbatim
 *
 * In order to calculate distance-to-boundary, we must transform a point in
 * the pincell (in the pincell's local coordinate system) into the vessel's
 * coordinate system.  A point in the pincell coordinate system can be defined
 * in the vessel's coordinate system using the relationships:
 * \f[
   \begin{array}{rcl}
    x &=& (\bar{x} - \bar{x}_o) + \mbox{x\_offset}\:,\\
    y &=& (\bar{y} - \bar{y}_o) + \mbox{y\_offset}\:.
   \end{array}
 * \f]
 * where \f$(\bar{x}, \bar{y})\f$ are coordinates of a point in the local
 * pin-cell system.  The origin of the pin-cell in the vessel's coordinate
 * system is thus
 * \f[
   \begin{array}{rcl}
    X_c &=& \mbox{x\_offset} - \bar{x}_o\:,\\
    Y_c &=& \mbox{y\_offset} - \bar{y}_o\:.
   \end{array}
 * \f]
 * A point in the pincell defined in the pincell's coordinate system
 * can be transformed into the vessel's coordinate system using
 * \f[
   \begin{array}{rcl}
    x &=& \bar{x} + X_c\:,\\
    y &=& \bar{y} + Y_c\:.
   \end{array}
 * \f]
 * Note, the offsets should have the correct sign, in the example above the \c
 * x_offset would be negative).
 *
 * \param R0 inner radius of the vessel
 * \param R1 outer radius of the vessel

 * \param x_offset offset between the origin of the vessel and the left-edge
 * of the pincell
 * \param y_offset offset between the origin of the vessel and the bottom-edge
 * of the pincell

 * \param vessel_id material id of the vessel
 *
 * \pre either R0, R1, or both must bisect the pincell
 */
\brief Empty pin-cell constructor with variable X/Y pitch and vessel.
An outer vessel is defined by an enclosing array.  In order to calculate
distance to boundary, it is necessary to know the offsets from the origin
of the vessel radius to the lower-left coordinates of the pin-cell, ie.

In order to calculate distance-to-boundary, we must transform a point in
the pincell (in the pincell's local coordinate system) into the vessel's
coordinate system.

\param R0 inner radius of the vessel
\param R1 outer radius of the vessel

\param x_offset offset between the origin of the vessel and the left-edge
of the pincell
\param y_offset offset between the origin of the vessel and the bottom-edge
of the pincell

\param vessel_id material id of the vessel

\pre either R0, R1, or both must bisect the pincell
\ brief Empty pin - cell constructor with variable X / Y pitch and vessel . An outer vessel is defined by an enclosing array . In order to calculate distance to boundary it is necessary to know the offsets from the origin of the vessel radius to the lower - left coordinates of the pin - cell ie . In order to calculate distance - to - boundary we must transform a point in the pincell ( in the pincell ' s local coordinate system ) into the vessel ' s coordinate system . \ param R0 inner radius of the vessel \ param R1 outer radius of the vessel \ param x_offset offset between the origin of the vessel and the left - edge of the pincell \ param y_offset offset between the origin of the vessel and the bottom - edge of the pincell \ param vessel_id material id of the vessel \ pre either R0 R1 or both must bisect the pincell
RTK_Cell::RTK_Cell(int    mod_id,
                   double dx,
                   double dy,
                   double height,
                   double R0,
                   double R1,
                   double x_offset,
                   double y_offset,
                   int    vessel_id)
    : d_mod_id(mod_id)
    , d_r(0)
    , d_ids(0)
    , d_z(height)
    , d_num_shells(0)
    , d_num_regions(1)
    , d_segments(1)
    , d_seg_faces(d_segments / 2)
    , d_num_int_faces(d_seg_faces + d_num_shells)
    , d_mod_region(d_num_regions - 1)
    , d_num_cells(d_num_regions * d_segments)
    , d_vessel(true)
    , d_R0(-1.0)
    , d_R1(-1.0)
    , d_inner(false)
    , d_outer(false)
    , d_vessel_id(vessel_id)
{
    using def::X; using def::Y;
    REQUIRE(d_z > 0.0);
    REQUIRE(d_mod_region == 0);
    REQUIRE(R0 < R1);
    d_xy[0] = dx;
    d_xy[1] = dy;
    d_extent[0][LO] = -d_xy[0] * 0.5;
    d_extent[0][HI] =  d_xy[0] * 0.5;
    d_extent[1][LO] = -d_xy[1] * 0.5;
    d_extent[1][HI] =  d_xy[1] * 0.5;
    d_offsets[X] = x_offset - d_extent[X][LO];
    d_offsets[Y] = y_offset - d_extent[Y][LO];
    double near[2], far[2];
    for (int dir = 0; dir < 2; ++dir)
    {
        near[dir] = this->l2g(d_extent[dir][LO], dir);
        far[dir]  = this->l2g(d_extent[dir][HI], dir);
        if (d_offsets[dir] < 0.0)
        {
            near[dir] = this->l2g(d_extent[dir][HI], dir);
            far[dir]  = this->l2g(d_extent[dir][LO], dir);
        }
    }
    double nearR2 = near[X]*near[X] + near[Y]*near[Y];
    double farR2  = far[X]*far[X] + far[Y]*far[Y];
    double R0_2   = R0 * R0;
    double R1_2   = R1 * R1;
    VALIDATE(R0_2 < farR2,
             "R0 = " << R0 << " is greater than the far extent "
             << "of the pincell, " << std::sqrt(farR2));
    VALIDATE(R1_2 > nearR2,
             "R1 = " << R1 <<  " is less than the near extent "
             << "of the pincell, " << std::sqrt(farR2));
    if (R0_2 > nearR2)
    {
        CHECK(R0_2 < farR2);
        d_R0    = R0;
        d_inner = true;
    }
    if (R1_2 < farR2)
    {
        CHECK(R1_2 > nearR2);
        d_R1    = R1;
        d_outer = true;
    }
}
RTK_Cell :: RTK_Cell ( int mod_id , double dx , double dy , double height , double R0 , double R1 , double x_offset , double y_offset , int vessel_id ) : d_mod_id ( mod_id ) , d_r ( 0 ) , d_ids ( 0 ) , d_z ( height ) , d_num_shells ( 0 ) , d_num_regions ( 1 ) , d_segments ( 1 ) , d_seg_faces ( d_segments / 2 ) , d_num_int_faces ( d_seg_faces + d_num_shells ) , d_mod_region ( d_num_regions - 1 ) , d_num_cells ( d_num_regions * d_segments ) , d_vessel ( true ) , d_R0 ( -1.0 ) , d_R1 ( -1.0 ) , d_inner ( false ) , d_outer ( false ) , d_vessel_id ( vessel_id ) { using def :: X ; using def :: Y ; REQUIRE ( d_z > 0.0 ) ; REQUIRE ( d_mod_region == 0 ) ; REQUIRE ( R0 < R1 ) ; d_xy [ 0 ] = dx ; d_xy [ 1 ] = dy ; d_extent [ 0 ] [ LO ] = - d_xy [ 0 ] * 0.5 ; d_extent [ 0 ] [ HI ] = d_xy [ 0 ] * 0.5 ; d_extent [ 1 ] [ LO ] = - d_xy [ 1 ] * 0.5 ; d_extent [ 1 ] [ HI ] = d_xy [ 1 ] * 0.5 ; d_offsets [ X ] = x_offset - d_extent [ X ] [ LO ] ; d_offsets [ Y ] = y_offset - d_extent [ Y ] [ LO ] ; double near [ 2 ] , far [ 2 ] ; for ( int dir = 0 ; dir < 2 ; ++ dir ) { near [ dir ] = this -> l2g ( d_extent [ dir ] [ LO ] , dir ) ; far [ dir ] = this -> l2g ( d_extent [ dir ] [ HI ] , dir ) ; if ( d_offsets [ dir ] < 0.0 ) { near [ dir ] = this -> l2g ( d_extent [ dir ] [ HI ] , dir ) ; far [ dir ] = this -> l2g ( d_extent [ dir ] [ LO ] , dir ) ; } } double nearR2 = near [ X ] * near [ X ] + near [ Y ] * near [ Y ] ; double farR2 = far [ X ] * far [ X ] + far [ Y ] * far [ Y ] ; double R0_2 = R0 * R0 ; double R1_2 = R1 * R1 ; VALIDATE ( R0_2 < farR2 , " " << R0 << " " << " " << std :: sqrt ( farR2 ) ) ; VALIDATE ( R1_2 > nearR2 , " " << R1 << " " << " " << std :: sqrt ( farR2 ) ) ; if ( R0_2 > nearR2 ) { CHECK ( R0_2 < farR2 ) ; d_R0 = R0 ; d_inner = true ; } if ( R1_2 < farR2 ) { CHECK ( R1_2 > nearR2 ) ; d_R1 = R1 ; d_outer = true ; } }
\brief Empty pin-cell constructor with variable X/Y pitch and vessel.
\ brief Empty pin - cell constructor with variable X / Y pitch and vessel .
// unique pitches in X/Y // calculate offset to vessel origin from pincell origin // near and far corners relative to the origin of vessel cylinder // calculate the near and far radii bisecting the pincell // check to see if R0 or R1 bisect the cell, R0 < R1 so if R0 > farR the // vessel does not bisect the cell // likewise if R1 < nearR the vessel cannot bisect the cell // now we have to check each vessel radius