def solve(self):
"""The solve method will build a matrix that sympy can solve with the sympy.solve() function. It will return the
values in a dict which will then be used to store all solved unknowns to the dict_of_variables of the system."""
# A pre-allocation for the matrix used to solve the system
matrix = []
# Each unknown must be put into a list so sympy can solve it
unknowns_list = list(self.dict_of_variables.keys())
# Each equation (except for the 'Total') will be appended to the matrix. This is done to allow for the user
# or the code (when this feature is added) to easily double check the variables for accuracy
for key, equation in self.equations_dict.items():
if key != 'Total':
matrix.append(equation)
# sympy does it's thing and returns a dict in the form of {symbol: solution}
solutions = sp.solve(matrix, unknowns_list, dict=True)
# This loop updates the dict_of_variables with the newly solved values for each
for solutions_set in solutions:
# This is done because the solutions are given in a list containing a dictionary: [{}], which is weird
for count in range(len(solutions_set)):
# The newly solved variables can be used to solve other ControlVolumes
self.dict_of_variables[unknowns_list[count]] = solutions_set[unknowns_list[count]]
ControlVolume.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录