Commit 674eea74 authored by MischaD's avatar MischaD
Browse files

Private names Refactoring

parent de585ba9
......@@ -15,32 +15,10 @@ def main():
@click.option('--shells', type=str, default="1,2,4", help='String of velocity shell size. Squared length of the shell')
@click.option('--seed', type=int, help='Random number to be used as seed')
def lbmweights(dimension, order, shells, seed):
# shell_list = [int(x) for x in re.findall(u"\d+", shells)]
# l = Lattice(dimension=dimension, order=order, shell_list=shell_list, seed=seed)
# weights_polynomials = l.calculate_polynomials()
# weights = l.calculate_weights(boundary="inf")
#lattice1 = Lattice.from_name("D2V37")
#lattice2 = Lattice.from_order(dimension=2, order=6)
#lattice3 = Lattice(dimension=3, order=4, shell_list=[1,2,4])
lattice = Lattice(2,4,[1,2,4], boundary="sup")
lattice.calculate_weights()
print(lattice.velocities)
print(lattice.weights)
cssq, w, u = lattice.velocity_set()
print(w)
print(u)
lattice = Lattice.from_name("D3Q41-ZOT")
lattice.calculate_weights()
cs, weights, velocities = lattice.velocity_set()
print(lattice.weights)
print(lattice.velocities)
#print(velocities.shape[1])
#print(cs)
#print(weights)
#print(velocities)
#print(Lattice.from_name("D3Q41-ZOT").weights)
#shell_list = [int(x) for x in re.findall(u"\d+", shells)]
#Lattice(dimension=dimension, order=order, shell_list=shell_list, seed=seed)
lattice = Lattice.from_name()
if __name__ == "__main__":
......
......@@ -76,8 +76,10 @@ class Lattice:
string = "D{} - Order: {} - Shells: {}".format(
self._dimension, self._order, str(self._shell_list)
)
if self._seed:
string += " - Seed: {}".format(self._seed)
if self._boundary:
string += " - Boundary: {}".format(self._boundary)
if self._unwanted_subshells:
string += " - Unwanted Subshells: {}".format(''.join([s + ', ' for s in self._unwanted_subshells]))
return string
@classmethod
......@@ -96,25 +98,18 @@ class Lattice:
:param order:
:return:
"""
shell_list = []
if dimension == 2:
if order == 4:
shell_list = [1, 2, 4]
elif order == 6:
shell_list = [1, 2, 4, 8, 9]
elif order == 8:
shell_list = [1, 2, 4, 5, 8, 9, 10, 16]
elif dimension == 3:
if order == 4:
shell_list = [1, 2, 4]
if not shell_list:
raise OrderNotImplementedException(
"Cannot initialize by {} for dimension {}. Lower the order or try to come up with the shells yourself.".format(
order, dimension
)
if order % 2 != 0:
order -= 1
for key, value in cls.BY_NAME.items():
if value.get("dimension") == dimension and value.get("order") == order:
return cls(**cls.BY_NAME.get(key))
raise ValueError(
"No Lattice known with order {} and dimension {}.".format(
order, dimension
)
)
return cls(dimension=dimension, order=order, shell_list=shell_list, seed=seed)
@property
......@@ -144,7 +139,7 @@ class Lattice:
if shell.type == type:
return shell
def calculate_velocity_vectors(self):
def _calculate_velocity_vectors(self):
velocity_vectors = []
group = get_group(self._dimension)
......@@ -173,7 +168,7 @@ class Lattice:
self._all_velocity_vectors = velocity_vectors
return velocity_vectors
def fill_lhs(self):
def _fill_lhs(self):
lhs = []
for i, rank in enumerate(np.arange(2, self._order + 2, 2)):
tensor_space_dimension = self._tensor_dimensions[i]
......@@ -190,7 +185,7 @@ class Lattice:
self._lhs = np.array(lhs)
return np.array(lhs)
def fill_rhs(self):
def _fill_rhs(self):
rhs = []
cols = self._order // 2
for k, rank in enumerate(np.arange(2, self._order + 2, 2)):
......@@ -203,7 +198,7 @@ class Lattice:
self._rhs = np.array(rhs)
return np.array(rhs)
def svd(self):
def _svd(self):
U, s, V = np.linalg.svd(self._lhs)
rows = self._lhs.shape[0]
cols = self._lhs.shape[1]
......@@ -238,7 +233,7 @@ class Lattice:
self._solution = np.dot(np.transpose(V), reduced_rhs)
return self._solution
def calculate_coefficients(self):
def _calculate_coefficients(self):
solution_columns = self._order // 2
coefficients = np.zeros((1 + solution_columns))
coefficients[0] = 1
......@@ -254,7 +249,7 @@ class Lattice:
self._coefficients = coeffs
return self._coefficients
def calculate_valid_interval(self):
def _calculate_valid_interval(self):
if not self._weight_polynomials:
raise UninitializedAttributeException("Weight Polynomials not give. Calculate them first!")
......@@ -291,13 +286,13 @@ class Lattice:
self._possible_tensors.append(possible_tensors)
self._tensor_dimensions = [len(x) for x in self._possible_tensors]
self.calculate_velocity_vectors()
self.fill_lhs()
self.fill_rhs()
self._calculate_velocity_vectors()
self._fill_lhs()
self._fill_rhs()
self.svd()
self._svd()
self.calculate_coefficients()
self._calculate_coefficients()
apporx_coeffs = [[approximate_ratio(x) for x in pol_coffs] for pol_coffs in self._coefficients]
......@@ -305,7 +300,7 @@ class Lattice:
if not self._weight_polynomials:
raise NoSolutionException("Something went wrong")
self._interval = self.calculate_valid_interval()
self._interval = self._calculate_valid_interval()
if self._interval == sp.EmptySet():
return []
return self._weight_polynomials
......
......@@ -171,10 +171,6 @@ def get_random_vector(dimension):
return vector
def double_factorial(n):
assert n >= 0
if n == 0 or n == 1:
......
Markdown is supported
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