本文整理汇总了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();
}
示例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;
}