Commit 2a14da20 by mischa

### weight and velocity properties now more convinient

parent 61df1592
 ... ... @@ -14,7 +14,7 @@ def main(): def benchmark(x=10): for i in range(x): for name, kwargs in Lattice.BY_NAME.items(): weights = Lattice(**kwargs).weights weights = Lattice(**kwargs).reduced_weights @main.command() ... ... @@ -35,9 +35,7 @@ def lbmweights(dimension, order, shells, seed): lbmweights --dimension=2 --order=4 --shells="1,2,4" """ lattice = Lattice.from_name("D2V17") lattice.weights lattice.assignment_collection print(Lattice.from_name("D2V17").velocities) if __name__ == "__main__": ... ...
 ... ... @@ -91,6 +91,7 @@ class Lattice: self._eq_order = eq_order self._svd_tolerance = svd_tolerance random.seed(self._seed) self._debug = False # Preperation self._tensor_space_dimension = 0 ... ... @@ -116,7 +117,9 @@ class Lattice: # Final values self._discrete_velocities = [] self._reduced_weights = [] self._weights = [] self._velocities = tuple() self._q = None self._c_s_sq = None ... ... @@ -183,17 +186,23 @@ class Lattice: @property def weights(self): if self._weights: return self._weights return self.calculate_weights() if not self._weights: self.velocity_set() return self._weights @property def velocities(self): """Get a list of all types of velocities. Velocities with zero weight are included For D2O9 this equals [00, 10, 11, 20]""" if not self._discrete_velocities and self._shells: self._discrete_velocities = [shell.type for shell in self._shells] return self._discrete_velocities """Return weights and velocities in walberla fashion""" if not self._velocities: self.velocity_set() return self._velocities @property def reduced_weights(self): if self._reduced_weights: return self._reduced_weights return self.calculate_weights() @property def eq_order(self): ... ... @@ -557,7 +566,7 @@ class Lattice: for i, shell in enumerate(self.shells): shell.set_weight(c_s_sq, weights[i]) self._c_s_sq = c_s_sq self._weights = weights self._reduced_weights = weights return weights def velocity_set(self): ... ... @@ -568,7 +577,7 @@ class Lattice: :return: (c_s_sq, weights, velocities) """ if not self.weights: if not self.reduced_weights: self.calculate_weights() weights = [] ... ... @@ -584,5 +593,7 @@ class Lattice: for velocity in shell.velocities: velocities[:, i] = velocity i += 1 self._weights = weights self._velocities = tuple(e for e in zip(velocities[0], velocities[1])) return self._c_s_sq, weights, velocities
 ... ... @@ -103,7 +103,6 @@ class TestSupremum(unittest.TestCase): def testOutput(self): weights = self.lattice.calculate_weights() self.assertEqual(len(weights), 4) self.assertEqual(self.lattice.velocities, ["00", "10", "11", "20"]) self.assertEqual(self.lattice.shell_from_type("10").weight, 0) ... ... @@ -136,8 +135,8 @@ class TestInitSchemes(unittest.TestCase): self.lattice_from_name = Lattice.from_name("D2Q9") def test_lattice_equivalent(self): self.assertTrue(self.lattice.weights == self.lattice_from_name.weights) self.assertTrue(self.lattice.weights == self.lattice_from_order.weights) self.assertTrue(self.lattice.reduced_weights == self.lattice_from_name.reduced_weights) self.assertTrue(self.lattice.reduced_weights == self.lattice_from_order.reduced_weights) if __name__ == "__main__": ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment