Пример #1
0
    def test_linear_electric_potential(self):
        E = np.array([1., 2., 3.])
        phi0 = 4.

        electric_field = constraints.LinearElectricPotential(E=E, phi0=phi0)
        np.testing.assert_almost_equal(E, electric_field.E)
        self.assertEqual(phi0, electric_field.phi0)

        self.system.constraints.add(electric_field)

        p = self.system.part.add(pos=[0.5, 0.5, 0.5])

        if espressomd.has_features("ELECTROSTATICS"):
            q_part = -3.1
            p.q = q_part
        else:
            q_part = 0.0

        self.system.integrator.run(0)
        np.testing.assert_almost_equal(q_part * E, np.copy(p.f))

        self.assertAlmostEqual(self.system.analysis.energy()['total'],
                               q_part * (- np.dot(E, p.pos) + phi0))
        self.assertAlmostEqual(self.system.analysis.energy()['total'],
                               self.system.analysis.energy()['external_fields'])
Пример #2
0
    def test_linear_electric_potential(self):
        E = np.array([1., 2., 3.])
        phi0 = 4.

        electric_field = constraints.LinearElectricPotential(E=E, phi0=phi0)
        np.testing.assert_almost_equal(E, electric_field.E)
        self.assertEqual(phi0, electric_field.phi0)

        self.system.constraints.add(electric_field)

        p = self.system.part.add(pos=[0.5, 0.5, 0.5])
        p.q = -3.1

        self.system.integrator.run(0)
        np.testing.assert_almost_equal(p.q * E, np.copy(p.f))

        self.assertAlmostEqual(self.system.analysis.energy()['total'],
                               p.q * (- np.dot(E, p.pos) + phi0))
        self.assertAlmostEqual(self.system.analysis.energy()['total'],
                               self.system.analysis.energy()['external_fields'])

        np.testing.assert_allclose(
            electric_field.call_method("_eval_field", x=[0, 0, 0]), phi0)
        np.testing.assert_allclose(
            electric_field.call_method("_eval_field", x=[3, 2, 1]),
            np.dot(-E, [3, 2, 1]) + phi0)
        np.testing.assert_allclose(
            electric_field.call_method("_eval_jacobian", x=[3, 2, 1]), -E)