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


C++ System::addCharge方法代码示例

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


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

示例1: nbf

TEST(TestSolver, construct){
    System s;
    s.addParticle(1.0);
    s.addCharge(1.0);
    NonBondedForce nbf(1);
    nbf.addLJPair(0.12,0.0034,0.0,0.0,0.1,1,1);
    s.addParticle(2.0);
    s.addForce(&nbf);
    Solver solve(s);
    SUCCEED();
}
开发者ID:BijanZarif,项目名称:oclMD,代码行数:11,代码来源:TestSolver.cpp

示例2: solve

TEST(TestNonBondedIxn,oneatomljpair){
    System system;
    system.addParticle(1.0);
    system.addParticle(1.0);
    system.addCharge(1.0);
    system.addCharge(1.0);
    
    NonBondedForce* nb = new NonBondedForce();
    nb->addParticle(1.0,0);
    nb->addLJPair(1.2,1.0,3.0,1.0,1.0,0,0);
//    nb->addLJPair(1.4,2.0,2.0,1.0,1.0,0,0);
    system.addForce(nb);
//    CpuPlatform* platform = new CpuPlatform();
//    ContextImpl context(system,platform);
    Solver solve(system);
    vector<Vec3> positions(2);
    positions[0] = Vec3(0,0,0);
    positions[1] = Vec3(2,0,0);
    solve.setPositions(positions);
    solve.getImpl().CalculateForcesandEnergy();
    
    vector<Vec3> forces(2);
    solve.getForces(forces);
    vector<double> pe(2);
    solve.getPotentialEnergy(pe);
    vector<Tensor<double> > virial(2);
    solve.getVirial(virial);
    
    /// calculate force equation
    Vec3 diff = positions[1] - positions[0];
    Real MagSqr = 0.0;
    MagSqr += diff[0] * diff[0];
    MagSqr += diff[1] * diff[1];
    MagSqr += diff[2] * diff[2];
    
    Real mag = SQRT(MagSqr);
    Real num1 = 48 * 1.0 * POW(1.2,12);
    num1 /= POW(mag,13);
    Real num2 = -24 * 1.0 * POW(1.2,6);
    num2 /= POW(mag,7);
    Real force = num1 + num2;
//    force *= 1.0;
    Vec3 expectForce = (diff/mag)*1.0*force;
//    expectForce *= force;
    
    /// test force equation with resultant forces
    EXPECT_DOUBLE_EQ(-expectForce[0],forces[0][0]);
    EXPECT_DOUBLE_EQ(expectForce[1],forces[0][1]);
    EXPECT_DOUBLE_EQ(expectForce[2],forces[0][2]);
    EXPECT_DOUBLE_EQ(expectForce[0],forces[1][0]);
    EXPECT_DOUBLE_EQ(expectForce[1],forces[1][1]);
    EXPECT_DOUBLE_EQ(expectForce[2],forces[1][2]);

    ///calculate energy equation to test calculated values
    
    Real e1 = POW(1.2,12)/POW(mag,12);
    e1 -= (POW(1.2,6) / POW(mag,6));
    Real expectpe = e1 * (4.0 * 1.0 * 0.5);
    /// compare result
    EXPECT_DOUBLE_EQ(expectpe,pe[0]);
    EXPECT_DOUBLE_EQ(expectpe,pe[1]);
    
    std::cout << "V0 => " << virial[0] << std::endl;
    std::cout << "V1 => " << virial[1] << std::endl;
    
    
}
开发者ID:BijanZarif,项目名称:oclMD,代码行数:67,代码来源:TestCpuNonBonded.cpp


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