def setup(self, step, time, configuration): """ Recieves the setup call from the before the MC loop. :param step: The step number of the simulation. :type step: int :param time: The time of the simulation. :type time: float :param configuration: The configuration of the simulation. :type configuration: KMCConfiguration """ # Make sure the track type is one of the possible types. if not self.__track_type in configuration.possibleTypes(): raise Error("The track type of the MSD calculator is not one of the valid types of the configuration.") # Get the cell vectors out. abc_to_xyz = numpy.array(configuration.lattice().unitCell().cellVectors()).transpose() abc_to_xyz_cpp = numpy2DArrayToStdVectorCoordinate(abc_to_xyz) # Setup the backend. self.__backend = Backend.OnTheFlyMSD(configuration._backend(), self.__history_steps, self.__n_bins, self.__t_max, time, self.__track_type, abc_to_xyz_cpp, self.__blocksize)
def testNumpy2DArrayToStdVectorCoordinate(self): """ Test the conversion of a Nx3 2D numpy array to a std::vector<Coordinate> representation. """ nI = 12; nJ = 3; array = numpy.random.rand(nI,nJ) # Convert to c++ cpp_vector = numpy2DArrayToStdVectorCoordinate(array) # Check the size. self.assertEqual(cpp_vector.size(), nI) # Check the type. self.assertTrue( isinstance(cpp_vector, Backend.StdVectorCoordinate) ) # Convert back and check values. converted = stdVectorCoordinateToNumpy2DArray(cpp_vector) self.assertAlmostEqual(numpy.linalg.norm(array-converted), 0.0, 10)
def testNumpy2DArrayToStdVectorCoordinate(self): """ Test the conversion of a Nx3 2D numpy array to a std::vector<Coordinate> representation. """ nI = 12 nJ = 3 array = numpy.random.rand(nI, nJ) # Convert to c++ cpp_vector = numpy2DArrayToStdVectorCoordinate(array) # Check the size. self.assertEqual(cpp_vector.size(), nI) # Check the type. self.assertTrue(isinstance(cpp_vector, Backend.StdVectorCoordinate)) # Convert back and check values. converted = stdVectorCoordinateToNumpy2DArray(cpp_vector) self.assertAlmostEqual(numpy.linalg.norm(array - converted), 0.0, 10)