Skip to content

Commit

Permalink
Solved one failing case - ground truth was wrong. Edited inlet_block …
Browse files Browse the repository at this point in the history
…code for junctions
  • Loading branch information
emilinmathew committed Aug 22, 2024
1 parent 1f2cbc6 commit 0b9f1f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
25 changes: 8 additions & 17 deletions applications/dirgraph_visualization/dirgraph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def load_json_input_file(fpath, name_type):
Returns:
d: A dictionary containing pandas DataFrames for each 0D element type and updated entries of blocks & block_names
"""

with open(fpath, 'rb') as fp:
d = json.load(fp)
blocks = {} # {block_name : block_object}
Expand All @@ -70,7 +69,6 @@ def load_json_input_file(fpath, name_type):

if 'vessels' not in d or len(d['vessels']) == 0:
df_vessels = pd.DataFrame()

else:
df_vessels = pd.DataFrame(dict(
inlet=[x.get('boundary_conditions', {}).get('inlet') for x in d['vessels']],
Expand All @@ -79,7 +77,6 @@ def load_json_input_file(fpath, name_type):
vessel_id=[x['vessel_id'] for x in d['vessels']]
))


if 'junctions' not in d:
df_junctions = pd.DataFrame()
df_junctions_expanded = pd.DataFrame()
Expand All @@ -97,17 +94,15 @@ def load_json_input_file(fpath, name_type):
for block in junction['inlet_blocks']:
if block in vessel_id_map:
junction_inlets.append(
{'junction_name': junction_name, 'block_name': "V" + str(vessel_id_map[block]),
'direction': 'inlet', 'type': 'vessel'})
{'junction_name': junction_name, 'block_name': "V" + str(vessel_id_map[block]), 'direction': 'inlet', 'type': 'vessel'})
else:
junction_inlets.append(
{'junction_name': junction_name, 'block_name': block,
'direction': 'inlet', 'type': 'block'})
for block in junction['outlet_blocks']:
if block in vessel_id_map:
junction_inlets.append(
{'junction_name': junction_name, 'block_name': "V" + str(vessel_id_map[block]),
'direction': 'outlet', 'type': 'vessel'})
{'junction_name': junction_name, 'block_name': "V" + str(vessel_id_map[block]), 'direction': 'outlet', 'type': 'vessel'})
else:
junction_inlets.append(
{'junction_name': junction_name, 'block_name': block,
Expand All @@ -122,17 +117,15 @@ def load_json_input_file(fpath, name_type):
for vessel in junction['outlet_vessels']:
junction_outlets.append(
{'junction_name': junction_name, 'block_name': "V" + str(vessel), 'direction': 'outlet',
'type': 'vessel'})
'type': 'vessel'})

# Create DataFrames from the lists
df_junctions_inlets = pd.DataFrame(junction_inlets)
df_junctions_outlets = pd.DataFrame(junction_outlets)

# Concatenate the DataFrames to form a unified junctions DataFrame
df_junctions = pd.concat([df_junctions_inlets, df_junctions_outlets], ignore_index=True)

df_junctions_expanded = pd.concat([df_junctions_inlets, df_junctions_outlets], ignore_index=True)

create_junction_blocks(d, df_junctions_expanded, name_type)

bcs = d['boundary_conditions']
Expand Down Expand Up @@ -161,7 +154,6 @@ def load_json_input_file(fpath, name_type):
name = [x['name'] for x in chambers],
type=[x['type'] for x in chambers],
))

create_chamber_blocks(d, df_chambers, df_junctions_expanded, df_valves)

create_outlet_bc_blocks(d, df_valves, name_type)
Expand Down Expand Up @@ -264,12 +256,14 @@ def process_chamber(row):

if not df_junctions_expanded.empty:
# Junction Processing
inlet_matches = df_junctions_expanded[(df_junctions_expanded['block_name'] == chamber_name) & (df_junctions_expanded['direction'] == 'inlet')]
inlet_matches = df_junctions_expanded[
(df_junctions_expanded['block_name'] == chamber_name) & (df_junctions_expanded['direction'] == 'inlet')]
for _, match in inlet_matches.iterrows():
connecting_block_list.append(match['junction_name'])
flow_directions.append(+1)

outlet_matches = df_junctions_expanded[(df_junctions_expanded['block_name'] == chamber_name) & (df_junctions_expanded['direction'] == 'outlet')]
outlet_matches = df_junctions_expanded[(df_junctions_expanded['block_name'] == chamber_name) & (
df_junctions_expanded['direction'] == 'outlet')]
for _, match in outlet_matches.iterrows():
connecting_block_list.append(match['junction_name'])
flow_directions.append(-1)
Expand Down Expand Up @@ -311,12 +305,10 @@ def create_junction_blocks(d, df_junctions_expanded, name_type):
"""
if df_junctions_expanded.empty:
return

junction_blocks = {} # {block_name: block_object}

def process_junction(row):
junction_name = row['junction_name']

if not junction_name.startswith("J") or not junction_name[1:].isnumeric():
message = f"Error. Joint name, {junction_name}, is not 'J' followed by numeric values. The 0D solver assumes that all joint names are 'J' followed by numeric values in the 0d solver input file. Note that the joint names are the same as the junction names."
raise RuntimeError(message)
Expand All @@ -333,7 +325,7 @@ def process_junction(row):

# Outlet Processing
outlet_matches = df_junctions_expanded[(df_junctions_expanded['junction_name'] == junction_name) & (
df_junctions_expanded['direction'] == 'outlet')]
df_junctions_expanded['direction'] == 'outlet')]
for _, match in outlet_matches.iterrows():
connecting_block_list.append(match['block_name'])
flow_directions.append(+1)
Expand Down Expand Up @@ -465,7 +457,6 @@ def get_vessel_block_helpers(d, df_vessels, df_junctions_expanded, df_valves, na
return vessel_blocks_connecting_block_lists, vessel_blocks_flow_directions, vessel_blocks_names



def create_vessel_blocks(d, df_vessels, df_junctions_expanded, df_valves, name_type):
"""
Purpose:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
strict digraph {
J0;
V1;
V2;
BC0_inlet;
V0;
V1;
BC1_outlet;
V2;
BC2_outlet;
BC0_inlet -> V0;
J0 -> V1;
J0 -> V2;
V1 -> BC1_outlet;
V2 -> BC2_outlet;
BC0_inlet -> V0;
V0 -> J0;
}

0 comments on commit 0b9f1f4

Please sign in to comment.