Skip to content

Commit

Permalink
Added suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
tmnp19 committed Jun 6, 2024
1 parent 4a4d19c commit fa6ccf3
Showing 1 changed file with 28 additions and 83 deletions.
111 changes: 28 additions & 83 deletions piglot/solver/abaqus/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,94 +200,32 @@ def write_output_file(i, variables_array, variable, step, location, file_name):
output_file.write(" ")
output_file.write("\n")

def get_step(odb, variables):
"""Create a variable that refers to the respective step.
Parameters
----------
odb : Odb
An instance of the Odb class from the Abaqus scripting interface, representing the output
database.
variables : dict
A dictionary containing the step name under the key "step_name".
Returns
-------
step : Step
The step from the output database that matches the name provided in the variables
dictionary.
Raises
------
ValueError
Raises an error if the step name is not found in the output database.
def find_case_insensitive_key(key_name, keys_list):
"""
step_names_list = list(odb.steps.keys())
step_names_list_upper = [stepName.upper() for stepName in step_names_list]
step_name_upper = variables["step_name"].upper()
if step_name_upper not in step_names_list_upper:
raise ValueError("Step name not found in the output database.")
step_name = step_names_list[step_names_list_upper.index(step_name_upper)]
return odb.steps[step_name]

def get_instance(odb, variables):
"""Create a variable that refers to the respective instance.
Find the original key name in a list of keys, ignoring case sensitivity.
Parameters
----------
odb : Odb
An instance of the Odb class from the Abaqus scripting interface, representing the output
database.
variables : dict
A dictionary containing the instance name under the key "instance_name".
key_name : str
The name of the key to find, case-insensitively.
keys_list : list
A list of keys (strings) to search through.
Returns
-------
instance : str
The instance from the output database that matches the name provided in the variables
dictionary.
Raises
------
ValueError
Raises an error if the instance name is not found in the output database.
"""
instance_names_list = list(odb.rootAssembly.instances.keys())
instance_names_list_upper = [instanceName.upper() for instanceName in instance_names_list]
instance_name_upper = variables["instance_name"].upper()
if instance_name_upper not in instance_names_list_upper:
raise ValueError("Instance name not found in the output database.")

return instance_names_list[instance_names_list_upper.index(instance_name_upper)]

def get_set(odb, variables, instance):
"""Create a variable that refers to the respective set.
Parameters
----------
odb : Odb
An instance of the Odb class from the Abaqus scripting interface, representing the output
database.
variables : dict
A dictionary containing the set name under the key "set_name".
Returns
-------
set : str
The set from the output database that matches the name provided in the variables
dictionary.
str
The original key name from the list that matches the provided key_name, ignoring case.
Raises
------
ValueError
Raises an error if the set name is not found in the output database.
If the key_name is not found in the keys_list, ignoring case.
"""
set_names_list = list(odb.rootAssembly.instances[instance].nodeSets.keys())
set_names_list_upper = [setName.upper() for setName in set_names_list]
set_name_upper = variables["set_name"].upper()
if set_name_upper not in set_names_list_upper:
raise ValueError("Set name not found in the output database.")
return set_names_list[set_names_list_upper.index(set_name_upper)]
keys_list_upper = [key.upper() for key in keys_list]
key_name_upper = key_name.upper()
if key_name_upper not in keys_list_upper:
raise ValueError(f"{key_name} not found.")
return keys_list[keys_list_upper.index(key_name_upper)]

def main():
"""Main function to extract the nodal data from the output database (.odb) file.
Expand All @@ -304,12 +242,19 @@ def main():
odb = openOdb(path=odb_name)

# Create a variable that refers to the respective step
step = get_step(odb, variables)
instance_name = get_instance(odb, variables)
nodeset_name = get_set(odb, variables, instance_name)
step = odb.steps[find_case_insensitive_key(variables["step_name"], list(odb.steps.keys()))]
instance_name = find_case_insensitive_key(
variables["instance_name"],
list(odb.rootAssembly.instances.keys()),
)
nodeset_name = find_case_insensitive_key(
variables["set_name"],
list(odb.rootAssembly.instances[instance_name].nodeSets.keys()),
)

node_sets = get_node_sets(instance_name, odb)

for i, var in enumerate(variables_array):
node_sets = get_node_sets(instance_name, odb)
for set_name, location in node_sets:
if set_name == str(nodeset_name):
file_name = file_name_func(set_name, var, variables["input_file"])
Expand Down

0 comments on commit fa6ccf3

Please sign in to comment.