def test_coulomb(self): coulomb_k = 1 q1 = 1 q2 = -1 self.system.part[0].q = q1 self.system.part[1].q = q2 self.run_test( espressomd.interactions.BondedCoulomb(prefactor=coulomb_k), lambda r: tests_common.coulomb_force(r, coulomb_k, q1, q2), lambda r: tests_common.coulomb_potential(r, coulomb_k, q1, q2), 0.01, self.system.box_l[0] / 3)
def test_coulomb(self): coulomb_k = 1 q1 = 1 q2 = -1 self.system.part[0].q = q1 self.system.part[1].q = q2 coulomb = espressomd.interactions.BondedCoulomb(prefactor=coulomb_k) self.system.bonded_inter.add(coulomb) self.system.part[0].add_bond((coulomb, 1)) for i in range(445): self.system.part[1].pos = self.system.part[1].pos + self.step self.system.integrator.run(recalc_forces=True, steps=0) # Calculate energies E_sim = self.system.analysis.energy()["bonded"] E_ref = tests_common.coulomb_potential(scalar_r=(i + 1) * self.step_width, k=coulomb_k, q1=q1, q2=q2) # Calculate forces f0_sim = self.system.part[0].f f1_sim = self.system.part[1].f f1_ref = self.axis * tests_common.coulomb_force( scalar_r=(i + 1) * self.step_width, k=coulomb_k, q1=q1, q2=q2) # Check that energies match, ... np.testing.assert_almost_equal(E_sim, E_ref) # force equals minus the counter-force ... self.assertTrue((f0_sim == -f1_sim).all()) # and has correct value. f1_sim_copy = np.copy(f1_sim) np.testing.assert_almost_equal(f1_sim_copy, f1_ref)