Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/GSA_to_Compos #6

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Draft

Conversation

PeterDebneyOasys
Copy link
Contributor

No description provided.

@PeterDebneyOasys
Copy link
Contributor Author

This example uses gsapy so is not currently suitable for the non-Arup users

@PeterDebneyOasys PeterDebneyOasys changed the title Feature/gsa to compos feature/GSA_to_Compos Jul 19, 2022
Copy link

@daviddekoning daviddekoning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Peter,

I've made a pile of suggestions, which fit into two categories:

  1. Making the code more pythonic: this is mostly about how dictionaries are created (using comprehensions instead of looping), and looping directly over data structures instead of looping with an index
  2. Helpful functionality in gsapy: gsapy does a lot of work for you, so I've suggested a few ways to avoid re-doing it.

from tempfile import gettempdir
from gsapy import GSA

# gsapy references

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since these are internal to Arup, let's remove them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

extract the new sections to compos_results
6. reopen the GSA model,
use compos_results and sections_dictionary to update the members
"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a note to this initial comment along the lines of If you would like more information about gsapy, please contact Oasys Support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# get GSA data
print("Opening GSA model")
gsa_model = GSA(r'C:\Temp\Composite test.gwb', version='10.1')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to simply say GSA('Composite test.gwb') - it will look in the same directory the script is running in

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


# gets the members from the first saved list
search_list = \
str(gsa_model.get_all_saved_lists()[0]).split("\t")[4].split(" ")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can replace your for loop with this:

for i in gsa_model._get_entities_in_named_list("Secondary beams"):  # create list of members to be designed
        member = gsa_model.get_members(i)
        member_list.append([i, gsa_model.get_section_info(member.prop),
                            gsa_model.get_member_length(i)])

model._get_entities_in_named_list returns a list of integers (member ids). It works even if the list is 1 to 10 or other complex definitions

gsapy creates a Member object with all the info you need, so there is no need to convert to str and then parse the string.

member.prop is the integer id of the section

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

member_section = int(member.split("\t")[6])
member_list.append([int(i), gsa_model.get_section_info(member_section),
gsa_model.get_member_length(int(i))])
sections_dictionary = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from gsapy.modules import Section

sections_dictionary = gsa_model.get(Section)

This creates a dictionary where the keys are the integer ids and the values are Section objects

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I see that you are using the section description as the key, so it needs something different:

sections_dictionary = {s.desc:s for s in gsa_model.get(Section).values}

or

sections_dictionary = {gsa_model.get_section_info(s.index):s for s in gsa_model.get(Section).values}

you could also expand it as

sections = gsa_model.get(Section) # this gives you the basic dict of sections (keys are the index)
sections_dictionary = {gsa_model.get_section_info(s.index) for s in sections}

https://www.geeksforgeeks.org/python-dictionary-comprehension/

Copy link
Contributor Author

@PeterDebneyOasys PeterDebneyOasys Jul 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daviddekoning this option does work

    sections_dictionary = {}
    for i in range(1, 93):  # create sections dictionary:  needs to match model
        sections_dictionary[gsa_model.get_section_info(i)] = i

but is clunky but gives a dictionary in the form {'UB127x76x13':1 etc},

while
sections_dictionary4 = {s.desc:s for s in gsa_model.get(Section).values()}
is elegant but produces something very different.

Is there an elegant way to create the dictionary in the required form?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could say s.desc.split("%")[2]:s for si in ...., but what I did in my suggested changes is just use the full section name, since they are consistent across GSA and Compos. I just had to replace the %s with spaces:

sections_dictionary = {s.desc.replace("%", " "): i for i, s in sections.items()}

compos_model = win32com.client.Dispatch("Compos.Automation")
compos_model.Open(gettempdir() + '\\compos_file.csv')
compos_results = []
for i in range(len(member_list)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can iterate over the member list direction here too, and not use an index

compos_model.Close()
print(" Compos model closed")

print("Opening GSA model")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to re-open if you don't close above

compos_model.Design(member_name)
section = compos_model.BeamSectDesc(member_name)
print(member_name, section)
compos_results.append([member_name[7:], section])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you make each list item a tuple, you can auto-expand in the last for loop:

compos_results.append((member_name[7:], section))


print("Opening GSA model")
gsa_model = GSA(r'C:\Temp\Composite test.gwb', version='10.1')
for i in range(len(compos_results)):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for member_number, member_section in compos results
    member_new_section = member_section.split()[2]
    ...

# gets section number of Compos
# result
member = gsa_model.get_members(member_number)
member.prop = new_section

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with the previous suggestion (line 47), you will have to change this line to

member.prop = new_section.index

@PeterDebneyOasys PeterDebneyOasys marked this pull request as draft September 21, 2022 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants