packages/Matprop/xs/Energy_Collapse.cc
//---------------------------------------------------------------------------//
/*!
 * \brief Collapse material database from fine to coarse.
 */
\brief Collapse material database from fine to coarse.
\ brief Collapse material database from fine to coarse .
Energy_Collapse::RCP_Mat_DB Energy_Collapse::collapse_all_mats(
    RCP_Mat_DB     fine_mat,
    const Vec_Int &collapse_vec,
    const Vec_Dbl &weights)
{
    typedef Vec_Int::const_iterator mat_iter;
    typedef Mat_DB_t::XS_t          XS;
    REQUIRE( fine_mat->xs().num_groups() == weights.size() );
    REQUIRE( fine_mat->xs().num_groups() ==
             std::accumulate(collapse_vec.begin(),collapse_vec.end(),0) );
    REQUIRE( fine_mat->xs().num_groups() >= 2 );
    int fine_grps   = fine_mat->xs().num_groups();
    int coarse_grps = collapse_vec.size();
    Vec_Int start_ind(coarse_grps);
    start_ind[0] = 0;
    if (coarse_grps > 1)
    {
        std::partial_sum(collapse_vec.begin(), collapse_vec.end()-1,
                         start_ind.begin()+1);
    }
    const XS &xs = fine_mat->xs();
    Vec_Int matids;
    xs.get_matids(matids);
    int m = 0;
    int pn_order = xs.pn_order();
    Mat_DB_t::RCP_XS xsc = Teuchos::rcp(new XS);
    xsc->set(pn_order, coarse_grps);
    XS::OneDArray totc(coarse_grps, 0.0);
    XS::TwoDArray sctc(coarse_grps, coarse_grps, 0.0);
    for (mat_iter mitr = matids.begin(); mitr != matids.end(); ++mitr)
    {
        m = *mitr;
        const XS::Vector &totf = xs.vector(m, XS::TOTAL);
        for (int gc = 0; gc < coarse_grps; ++gc)
        {
            int g_first = start_ind[gc];
            int g_last  = g_first + collapse_vec[gc];
            double sigma = 0.0;
            double g_sum = 0.0;
            for (int gf = g_first; gf < g_last; ++gf)
            {
                sigma += totf[gf] * weights[gf];
                g_sum += weights[gf];
            }
            sigma    /= g_sum;
            totc[gc]  = sigma;
        }
        xsc->add(m, XS::TOTAL, totc);
        for (int l = 0; l <= pn_order; ++l)
        {
            const XS::Matrix &sctf = xs.matrix(m, l);
            for (int gc = 0; gc < coarse_grps; ++gc)
            {
                int g_first = start_ind[gc];
                int g_last  = g_first + collapse_vec[gc];
                for (int gpc = 0; gpc < coarse_grps; ++gpc)
                {
                    int gp_first  = start_ind[gpc];
                    int gp_last   = gp_first + collapse_vec[gpc];
                    double sig_s  = 0.0;
                    double gp_sum = 0.0;
                    for (int gpf = gp_first; gpf < gp_last; ++gpf)
                    {
                        gp_sum += weights[gpf];
                        for (int gf = g_first; gf < g_last; ++gf)
                        {
                            sig_s += sctf(gf, gpf) * weights[gpf];
                        }
                    }
                    sig_s         /= gp_sum;
                    sctc(gc, gpc)  = sig_s;
                }
            }
            xsc->add(m, l, sctc);
        }
    }
    xsc->complete();
    RCP_Mat_DB coarse_mat = Teuchos::rcp(new Mat_DB_t);
    coarse_mat->set(xsc, fine_mat->num_cells());
    for (int cell = 0, Nc = fine_mat->num_cells(); cell < Nc; ++cell)
    {
        coarse_mat->matid(cell) = fine_mat->matid(cell);
    }
    return coarse_mat;
}
Energy_Collapse :: RCP_Mat_DB Energy_Collapse :: collapse_all_mats ( RCP_Mat_DB fine_mat , const Vec_Int & collapse_vec , const Vec_Dbl & weights ) { typedef Vec_Int :: const_iterator mat_iter ; typedef Mat_DB_t :: XS_t XS ; REQUIRE ( fine_mat -> xs ( ) . num_groups ( ) == weights . size ( ) ) ; REQUIRE ( fine_mat -> xs ( ) . num_groups ( ) == std :: accumulate ( collapse_vec . begin ( ) , collapse_vec . end ( ) , 0 ) ) ; REQUIRE ( fine_mat -> xs ( ) . num_groups ( ) >= 2 ) ; int fine_grps = fine_mat -> xs ( ) . num_groups ( ) ; int coarse_grps = collapse_vec . size ( ) ; Vec_Int start_ind ( coarse_grps ) ; start_ind [ 0 ] = 0 ; if ( coarse_grps > 1 ) { std :: partial_sum ( collapse_vec . begin ( ) , collapse_vec . end ( ) - 1 , start_ind . begin ( ) + 1 ) ; } const XS & xs = fine_mat -> xs ( ) ; Vec_Int matids ; xs . get_matids ( matids ) ; int m = 0 ; int pn_order = xs . pn_order ( ) ; Mat_DB_t :: RCP_XS xsc = Teuchos :: rcp ( new XS ) ; xsc -> set ( pn_order , coarse_grps ) ; XS :: OneDArray totc ( coarse_grps , 0.0 ) ; XS :: TwoDArray sctc ( coarse_grps , coarse_grps , 0.0 ) ; for ( mat_iter mitr = matids . begin ( ) ; mitr != matids . end ( ) ; ++ mitr ) { m = * mitr ; const XS :: Vector & totf = xs . vector ( m , XS :: TOTAL ) ; for ( int gc = 0 ; gc < coarse_grps ; ++ gc ) { int g_first = start_ind [ gc ] ; int g_last = g_first + collapse_vec [ gc ] ; double sigma = 0.0 ; double g_sum = 0.0 ; for ( int gf = g_first ; gf < g_last ; ++ gf ) { sigma += totf [ gf ] * weights [ gf ] ; g_sum += weights [ gf ] ; } sigma /= g_sum ; totc [ gc ] = sigma ; } xsc -> add ( m , XS :: TOTAL , totc ) ; for ( int l = 0 ; l <= pn_order ; ++ l ) { const XS :: Matrix & sctf = xs . matrix ( m , l ) ; for ( int gc = 0 ; gc < coarse_grps ; ++ gc ) { int g_first = start_ind [ gc ] ; int g_last = g_first + collapse_vec [ gc ] ; for ( int gpc = 0 ; gpc < coarse_grps ; ++ gpc ) { int gp_first = start_ind [ gpc ] ; int gp_last = gp_first + collapse_vec [ gpc ] ; double sig_s = 0.0 ; double gp_sum = 0.0 ; for ( int gpf = gp_first ; gpf < gp_last ; ++ gpf ) { gp_sum += weights [ gpf ] ; for ( int gf = g_first ; gf < g_last ; ++ gf ) { sig_s += sctf ( gf , gpf ) * weights [ gpf ] ; } } sig_s /= gp_sum ; sctc ( gc , gpc ) = sig_s ; } } xsc -> add ( m , l , sctc ) ; } } xsc -> complete ( ) ; RCP_Mat_DB coarse_mat = Teuchos :: rcp ( new Mat_DB_t ) ; coarse_mat -> set ( xsc , fine_mat -> num_cells ( ) ) ; for ( int cell = 0 , Nc = fine_mat -> num_cells ( ) ; cell < Nc ; ++ cell ) { coarse_mat -> matid ( cell ) = fine_mat -> matid ( cell ) ; } return coarse_mat ; }
\brief Collapse material database from fine to coarse.
\ brief Collapse material database from fine to coarse .
// Get starting fine group indices for each coarse group // get the cross sections from the fine_mat // get the matids in the database // material id // pn order // create coarse group cross sections // coarse group totals // Process each material in original // set the material id // get the total cross sections for the fine group // loop over coarse groups // Get fine first and last for this coarse // Process total cross section // add the coarse total cross sections // add the scattering cross sections // get the scattering cross section for the fine group // Get fine first and last for this coarse // add the coarse scattering cross sections // complete the coarse cross sections // make the coarse mat-db // Assign matids to cells