当前位置: 首页>>代码示例>>C++>>正文


C++ Interaction::v_rel方法代码示例

本文整理汇总了C++中Interaction::v_rel方法的典型用法代码示例。如果您正苦于以下问题:C++ Interaction::v_rel方法的具体用法?C++ Interaction::v_rel怎么用?C++ Interaction::v_rel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interaction的用法示例。


在下文中一共展示了Interaction::v_rel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: scatter

void BaseSpecies::scatter(t_particle &particle)
{
    //select interacting species
    double gamma = rnd->uni() / lifetime;
    double tmp = 0.0;
    size_t specid;
    // We do not iterate over the last item in rates_species array,
    // it should be select automatically if no other species was
    // chosen before
    for(specid=0; specid < rates_by_species.size()-1; specid++)
    {
        tmp += rates_by_species[specid];
        if(tmp > gamma)
            break;
    }


    // Generate the interacting particle
    // use a random sample from velocity distribution of "continuum" species,
    // otherwise select a random particle from the ensemble
    double vr2,vz2,vt2;
    t_particle * partner = NULL;
    if(speclist[specid]->particles.size() == 0)
        speclist[specid]->rndv(vr2,vz2,vt2);
    else
    {
        partner = speclist[specid]->random_particle();
        vr2 = partner->vx;
        vz2 = partner->vz;
        vt2 = partner->vy;
    }
    //cout << "    v1 = " << vr2 << " " << vz2 << " " << vt2 <<endl;

    double v_rel = norm(particle.vx-vr2, particle.vz-vz2, particle.vy-vt2);
    double m2 = speclist[specid]->mass;

    //select interaction
    gamma = rnd->uni() * rates_by_species[specid];
    tmp = 0.0;
    size_t intid;
    for(intid=0; intid < interactions_by_species[specid].size(); intid++)
    {
        tmp += interactions_by_species[specid][intid]->sigma_v(v_rel) * speclist[specid]->density;

        if(tmp > gamma)
            break;
    }


    // Null collision selected
    if(intid==interactions_by_species[specid].size()) return;

    Interaction * interaction = interactions_by_species[specid][intid];

    //cout << "interaction " << interaction->name << " of " <<
    //    interaction->primary->name << " with " << interaction->secondary->name <<endl;
    //cout << "interaction type " << interaction->type << " ELASTIC: " << ELASTIC <<endl;
    switch(interaction->type)
    {
        case SUPERELASTIC:
            {
                double E = interaction->E(v_rel) + interaction->DE;
                double v1_cm = interaction->v_rel(E);
                // fix this v_rel // v1_cm
                // cout << E <<" "<< interaction->E(v_rel) << " " << "CRR"<<endl;

                double v1_cm_x, v1_cm_z, v1_cm_y;
                rnd->rot(v1_cm, v1_cm_x, v1_cm_z, v1_cm_y);

                particle.vx = v1_cm_x + (particle.vx*mass + vr2*m2)*tmp;
                particle.vz = v1_cm_y + (particle.vz*mass + vz2*m2)*tmp;
                particle.vy = v1_cm_z + (particle.vy*mass + vt2*m2)*tmp;
            }
            break;

        case COULOMB:
        case ELASTIC:
            {
                double tmp = 1.0/(mass+m2);
                //transform to center of mass system
                double v_cm_x = (particle.vx*mass + vr2*m2)*tmp;
                double v_cm_z = (particle.vz*mass + vz2*m2)*tmp;
                double v_cm_y = (particle.vy*mass + vt2*m2)*tmp;
                double v1_cm_x = particle.vx - v_cm_x;
                double v1_cm_z = particle.vz - v_cm_z;
                double v1_cm_y = particle.vy - v_cm_y;

                //isotropic random rotation
                rnd->rot(v1_cm_x,v1_cm_y,v1_cm_z);
                //cout << "    v1 = " << v1_cm_x << " " << v1_cm_y << " " << v1_cm_z ;

                //reverse transformation
                //particle.vx = v1_cm_x + v_cm_x;
                particle.vx = v1_cm_x + v_cm_x;
                particle.vz = v1_cm_z + v_cm_z;
                particle.vy = v1_cm_y + v_cm_y;
                //cout << "    v1 = " << particle.vx << " " << particle.vy << " " << particle.vz <<endl;
                if(interaction->type == COULOMB)
                {
                    //v2 = (p_CM - p1)/m2
//.........这里部分代码省略.........
开发者ID:rouckas,项目名称:mag2d,代码行数:101,代码来源:particles.cpp


注:本文中的Interaction::v_rel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。