How to use the plonk.core.particles.Arrays function in plonk

To help you get started, we’ve selected a few plonk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dmentipl / plonk / tests / test_arrays.py View on Github external
def test_init_arrays(self):
        """Testing initialising Arrays object."""
        file_handle = h5py.File(TEST_FILE, mode='r')
        arrays = plonk.core.particles.Arrays(
            file_handle=file_handle, arrays_label='particles'
        )

        self.assertEqual(arrays.dimensions, dimensions)
        self.assertEqual(arrays.dtype, dtype)
        self.assertEqual(arrays.number, number)
        self.assertEqual(arrays.fields, fields)
        self.assertEqual(arrays.shape, shape)

        file_handle.close()
github dmentipl / plonk / tests / test_arrays.py View on Github external
def test_extra_quantities(self):
        """Testing calculating extra quantities."""
        file_handle = h5py.File(TEST_FILE, mode='r')
        arrays = plonk.core.particles.Arrays(
            file_handle=file_handle, arrays_label='particles'
        )

        for quantity in {'L', 'R', 'l', 'p', 'r', '|L|', '|l|', '|p|', '|v|'}:
            self.assertEqual(
                arrays.extra_quantity(quantity, mass=np.array([1.0]))[0].mean(),
                extra_quantities[quantity],
            )

        file_handle.close()
github dmentipl / plonk / tests / test_arrays.py View on Github external
def test_to_structured_array(self):
        """Testing Arrays object to numpy structured array."""
        file_handle = h5py.File(TEST_FILE, mode='r')
        arrays = plonk.core.particles.Arrays(
            file_handle=file_handle, arrays_label='particles'
        )

        self.assertEqual(arrays.to_structured_array().dtype, structured_array_dtype)

        file_handle.close()
github dmentipl / plonk / plonk / core / dump.py View on Github external
if cache_arrays is None:
            self._cache_arrays = False
        else:
            if not isinstance(cache_arrays, bool):
                raise TypeError('cache_array must be bool')
            self._cache_arrays = cache_arrays

        self.particles = Arrays(
            arrays_label='particles',
            file_handle=self.file_handle,
            particle_type='fluid',
            cache_arrays=cache_arrays,
        )

        self.sinks = Arrays(arrays_label='sinks', file_handle=self.file_handle)
github dmentipl / plonk / plonk / core / dump.py View on Github external
def __init__(self, filename, cache_arrays=None):
        super().__init__(filename)

        self._header = {key: val[()] for key, val in self.file_handle['header'].items()}

        if cache_arrays is None:
            self._cache_arrays = False
        else:
            if not isinstance(cache_arrays, bool):
                raise TypeError('cache_array must be bool')
            self._cache_arrays = cache_arrays

        self.particles = Arrays(
            arrays_label='particles',
            file_handle=self.file_handle,
            particle_type='fluid',
            cache_arrays=cache_arrays,
        )

        self.sinks = Arrays(arrays_label='sinks', file_handle=self.file_handle)