def test_core_params(self): from espressomd.electrostatic_extensions import ICC self.tearDown() part_slice, normals, areas = self.add_icc_particles(5, 0.01, 0) params = { "n_icc": len(part_slice), "normals": normals, "areas": areas, "epsilons": np.ones_like(areas), "first_id": part_slice.id[0], "check_neutrality": False } icc = ICC(**params) self.system.actors.add(icc) icc_params = icc.get_params() for key, value in params.items(): np.testing.assert_allclose(value, np.copy(icc_params[key]))
def common_setup(self, kwargs, error): from espressomd.electrostatic_extensions import ICC self.tearDown() part_slice, normals, areas = self.add_icc_particles(2, 0.01, 0) params = { "n_icc": len(part_slice), "normals": normals, "areas": areas, "epsilons": np.ones_like(areas), "first_id": part_slice.id[0], "check_neutrality": False } params.update(kwargs) icc = ICC(**params) with self.assertRaisesRegex(Exception, error): self.system.actors.add(icc)
def runTest(self): from espressomd.electrostatics import P3M from espressomd.electrostatic_extensions import ICC S = espressomd.System(box_l=[1.0, 1.0, 1.0]) S.seed = S.cell_system.get_state()['n_nodes'] * [1234] # Parameters box_l = 20.0 nicc = 10 q_test = 10.0 q_dist = 5.0 # System S.box_l = [box_l, box_l, box_l + 5.0] S.cell_system.skin = 0.4 S.time_step = 0.01 # ICC particles nicc_per_electrode = nicc * nicc nicc_tot = 2 * nicc_per_electrode iccArea = box_l * box_l / nicc_per_electrode iccNormals = [] iccAreas = [] iccSigmas = [] iccEpsilons = [] l = box_l / nicc for xi in range(nicc): for yi in range(nicc): S.part.add(pos=[l * xi, l * yi, 0], q=-0.0001, fix=[1, 1, 1]) iccNormals.append([0, 0, 1]) for xi in range(nicc): for yi in range(nicc): S.part.add(pos=[l * xi, l * yi, box_l], q=0.0001, fix=[1, 1, 1]) iccNormals.append([0, 0, -1]) iccAreas.extend([iccArea] * nicc_tot) iccSigmas.extend([0] * nicc_tot) iccEpsilons.extend([10000000] * nicc_tot) # Test Dipole b2 = box_l * 0.5 S.part.add(pos=[b2, b2, b2 - q_dist / 2], q=q_test, fix=[1, 1, 1]) S.part.add(pos=[b2, b2, b2 + q_dist / 2], q=-q_test, fix=[1, 1, 1]) # Actors p3m = P3M(prefactor=1, mesh=32, cao=7, accuracy=1e-5) icc = ICC( n_icc=nicc_tot, convergence=1e-6, relaxation=0.75, ext_field=[0, 0, 0], max_iterations=100, first_id=0, eps_out=1, normals=iccNormals, areas=iccAreas, sigmas=iccSigmas, epsilons=iccEpsilons) S.actors.add(p3m) S.actors.add(icc) # Run S.integrator.run(0) # Analyze QL = sum(S.part[:nicc_per_electrode].q) QR = sum(S.part[nicc_per_electrode:nicc_tot].q) testcharge_dipole = q_test * q_dist induced_dipole = 0.5 * (abs(QL) + abs(QR)) * box_l # Result self.assertAlmostEqual(1, induced_dipole / testcharge_dipole, places=4)
def test_dipole_system(self): from espressomd.electrostatics import P3M from espressomd.electrostatic_extensions import ICC BOX_L = 20. BOX_SPACE = 5. self.tearDown() self.system.box_l = [BOX_L, BOX_L, BOX_L + BOX_SPACE] self.system.cell_system.skin = 0.4 self.system.time_step = 0.01 N_ICC_SIDE_LENGTH = 10 DIPOLE_DISTANCE = 5.0 DIPOLE_CHARGE = 10.0 part_slice_lower, normals_lower, areas_lower = self.add_icc_particles( N_ICC_SIDE_LENGTH, -0.0001, 0.) part_slice_upper, normals_upper, areas_upper = self.add_icc_particles( N_ICC_SIDE_LENGTH, 0.0001, BOX_L) assert (part_slice_upper.id[-1] - part_slice_lower.id[0] + 1) == 2 * N_ICC_SIDE_LENGTH**2, "ICC particles not continuous" normals = np.vstack((normals_lower, -normals_upper)) areas = np.hstack((areas_lower, areas_upper)) epsilons = np.full_like(areas, 1e8) sigmas = np.zeros_like(areas) icc = ICC(n_icc=2 * N_ICC_SIDE_LENGTH**2, normals=normals, areas=areas, epsilons=epsilons, sigmas=sigmas, convergence=1e-6, max_iterations=100, first_id=part_slice_lower.id[0], eps_out=1., relaxation=0.75, ext_field=[0, 0, 0]) # Dipole in the center of the simulation box BOX_L_HALF = BOX_L / 2 self.system.part.add( pos=[BOX_L_HALF, BOX_L_HALF, BOX_L_HALF - DIPOLE_DISTANCE / 2], q=DIPOLE_CHARGE, fix=[True, True, True]) self.system.part.add( pos=[BOX_L_HALF, BOX_L_HALF, BOX_L_HALF + DIPOLE_DISTANCE / 2], q=-DIPOLE_CHARGE, fix=[True, True, True]) p3m = P3M(prefactor=1, mesh=32, cao=7, accuracy=1e-5) self.system.actors.add(p3m) self.system.actors.add(icc) self.system.integrator.run(0) charge_lower = sum(part_slice_lower.q) charge_upper = sum(part_slice_upper.q) testcharge_dipole = DIPOLE_CHARGE * DIPOLE_DISTANCE induced_dipole = 0.5 * (abs(charge_lower) + abs(charge_upper)) * BOX_L self.assertAlmostEqual(1, induced_dipole / testcharge_dipole, places=4)
S.part.add(q=-q_test, pos=[5. + 1.4400805639476335, 5. + 0.1043669321614941, 5. + 8.8479965821355542]) S.part.add(q=+q_test, pos=[5. + 9.5797857731392480, 5. + 6.2586590985382529, 5. + 9.5556776221428787]) S.part.add(q=-q_test, pos=[5. + 6.3099270652140742, 5. + 0.3912234123714486, 5. + 3.5127712166987091]) S.part.add(q=+q_test, pos=[5. + 1.4632732155390766, 5. + 1.0601483109035978, 5. + 1.9741218834874423]) # Actors #p3m = P3M(prefactor=1, mesh=32, cao=7, accuracy=1e-7) p3m = P3M(prefactor=1, mesh=32, cao=7, accuracy=1e-5, alpha=1.112583061, r_cut=4.9, tune=False) icc = ICC( n_icc=nicc_tot, convergence=1e-6, relaxation=0.75, ext_field=[0, 0, 0], max_iterations=100, first_id=0, eps_out=1, normals=iccNormals, areas=iccAreas, sigmas=iccSigmas, epsilons=iccEpsilons) S.actors.add(p3m) S.actors.add(icc) # time start #start2=datetime.now()