Skip to content

Commit

Permalink
Merge pull request #50 from pietroUngar/master
Browse files Browse the repository at this point in the history
V0.6.0 - Major bug fixed
  • Loading branch information
pietroUngar committed Jul 13, 2022
2 parents 7e2cde9 + 3fbea23 commit 417de94
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 32 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
/twine_upload/pipy_token
50 changes: 38 additions & 12 deletions EEETools/MainModules/main_module.py
Expand Up @@ -31,6 +31,7 @@ def __init__(self, inputID, main_class, is_support_block=False):
self.comp_cost = 0.
self.difference_cost = 0.
self.output_cost = 0.
self.dissipative_output_cost = 0.
self.output_cost_decomposition = dict()

self.input_connections = list()
Expand Down Expand Up @@ -287,6 +288,14 @@ def calculate_coefficients(self, total_destruction):

fuel_cost = 0.

if self.is_dissipative:

c_prod = self.dissipative_output_cost

else:

c_prod = self.output_cost

for conn in self.input_connections:

fuel_cost += conn.exergy_value * conn.rel_cost
Expand All @@ -303,7 +312,7 @@ def calculate_coefficients(self, total_destruction):

if not c_fuel == 0:

r = (self.output_cost - c_fuel) / c_fuel
r = (c_prod - c_fuel) / c_fuel

if not (self.comp_cost + c_dest * abs(dest_loss_exergy)) == 0:

Expand All @@ -313,12 +322,16 @@ def calculate_coefficients(self, total_destruction):

y = dest_exergy / total_destruction

self.coefficients.update({"r": r,
"f": f,
"y": y,
"eta": eta,
"c_fuel": c_fuel,
"c_dest": c_dest})
self.coefficients.update({

"r": r,
"f": f,
"y": y,
"eta": eta,
"c_fuel": c_fuel,
"c_dest": c_dest

})

# - Support Methods -

Expand Down Expand Up @@ -771,6 +784,17 @@ def n_non_empty_output(self):

return counter

@property
def first_non_support_block(self):

if not self.is_support_block:

return self

if self.is_support_block:

return self.main_block.first_non_support_block

# -------------------------------------
# ------ EES Generation Methods -----
# ------ (to be eliminated) -----
Expand Down Expand Up @@ -1358,7 +1382,7 @@ def calculate(self):

self.append_solution(sol)
self.calculate_coefficients()
self.decompose_component_output_cost()
self.decompose_component_output_cost(matrix_analyzer)

def append_solution(self, sol):

Expand All @@ -1369,11 +1393,13 @@ def append_solution(self, sol):
if not block.is_dissipative:

block.append_output_cost(sol[i])
i += 1

else:

block.append_output_cost(0.)
block.dissipative_output_cost = sol[i]

i += 1

self.__reset_IDs(reset_block=True)
self.__reset_IDs(reset_block=False)
Expand All @@ -1386,13 +1412,13 @@ def calculate_coefficients(self):

block.calculate_coefficients(total_destruction)

def decompose_component_output_cost(self):
def decompose_component_output_cost(self, analizer:MatrixAnalyzer):

if self.options.calculate_component_decomposition:

try:

__inverse_matrix = np.linalg.inv(self.matrix)
__inverse_matrix = analizer.inverse_matrix

for block in self.block_list:

Expand Down Expand Up @@ -1972,7 +1998,7 @@ def __init__(self):
self.valve_is_dissipative = True
self.condenser_is_dissipative = True

self.redistribution_method = CalculationOptions.RELATIVE_COST
self.redistribution_method = CalculationOptions.EXERGY_DESTRUCTION
self.calculate_component_decomposition = True

@property
Expand Down
2 changes: 1 addition & 1 deletion EEETools/MainModules/pf_diagram_generation_module.py
Expand Up @@ -163,7 +163,7 @@ def __identify_support_blocks(self):
if prod_block.base_block.is_support_block:

prod_block.is_support_block = True
prod_block.main_block = self.find_element(prod_block.base_block.main_block)
prod_block.main_block = self.find_element(prod_block.base_block.first_non_support_block)

def generate_product_connection(self, input_connection: Connection, from_product_block=None, to_product_block=None):

Expand Down
22 changes: 14 additions & 8 deletions EEETools/Tools/API/Tools/sankey_diagram_generation.py
Expand Up @@ -9,37 +9,43 @@ def __init__(self):
self.show_component_mixers = False
self.colors = {

"Destruction": "180, 160, 0",
"Other": "150, 0, 0"
"Destruction": "150, 0, 0",
"Losses": "50, 125, 150",
"Default": "250, 210, 20"

}
self.opacity = {

"nodes": 1,
"links": 0.4
"links": 0.6,
"DL_links": 0.25

}

def define_color(self, block_label, is_link):

return "rgba({}, {})".format(self.get_color(block_label), self.get_opacity(is_link))
return "rgba({}, {})".format(self.get_color(block_label), self.get_opacity(block_label, is_link))

def get_color(self, block_label):

if not (block_label == "Destruction" or block_label == "Losses"):
if block_label == "Destruction" or block_label == "Losses":

color = self.colors["Destruction"]
color = self.colors[block_label]

else:

color = self.colors["Other"]
color = self.colors["Default"]

return color

def get_opacity(self, is_link):
def get_opacity(self, block_label, is_link):

if is_link:

if block_label == "Destruction" or block_label == "Losses":

return self.opacity["DL_links"]

return self.opacity["links"]

else:
Expand Down

0 comments on commit 417de94

Please sign in to comment.