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

WARNING: subcase.py:683 nwords_to_lsem=1000 nwords_to_lsem//4=250 #722

Open
fmamitrotta opened this issue Mar 14, 2023 · 12 comments
Open

WARNING: subcase.py:683 nwords_to_lsem=1000 nwords_to_lsem//4=250 #722

fmamitrotta opened this issue Mar 14, 2023 · 12 comments

Comments

@fmamitrotta
Copy link
Collaborator

Summary

Preamble: this is not really an issue preventing me from doing anything in particular, it's rather a small inconvenience.

Whenever I use the read_op2 function, I always get the following warning twice for each subcase.
WARNING: subcase.py:683 nwords_to_lsem=1000 nwords_to_lsem//4=250

Of course a warning or two in the console is not a big deal. However this becomes inconvenient when I use a jupyter notebook and I run an analysis with many subcases. The notebook becomes cluttered by warning messages and I would like to avoid that.

I looked into pyNastran\op2\tables\geom\subcase.py and I've seen that the warning message is prompted within the set_casecc function. I guess this function reads and assigns the case control commands to the Subcase object, correct?

Now it seems that all the ids are stored in the ints array and at a certain point nwords_to_lsem is taken from there. What does this variable represent? What is the reason to check whether the floor division of it is either 150 or 300?

Reproduction

Read the attached op2 file using:

read_op2(op2_filename='nonlinear_buckling_verification.op2', debug=None)

nonlinear_buckling_verification.zip

Versions

platform.python_version() --> 3.9.16
pyNastran.__version__ --> 1.4.0+dev.no.checksum.error (this commit)

@SteveDoyle2
Copy link
Owner

SteveDoyle2 commented Mar 14, 2023 via email

@fmamitrotta
Copy link
Collaborator Author

Sure, I am more than happy to work on a pull request for that! I just don't understand the aim of the warning message. nwords_to_lsem is taken from the 165th element of the ints array. Then we check whether the floor division by 4 is either 150 or 300. If it isn't, the warning message is prompted.

However nwords_to_lsem is no longer used in the remainder of the set_casecc function, so it seems that the warning is standing on its own without doing anything useful. What am I missing?

@SteveDoyle2
Copy link
Owner

SteveDoyle2 commented Mar 14, 2023 via email

@fmamitrotta
Copy link
Collaborator Author

Ok I understand. However as far as I can see from the code the parsing does not seem to be affected by check on the number of subcases. Maybe I'm missing something, let me debug line by line the set_casecc function and see what I find.

@SteveDoyle2
Copy link
Owner

SteveDoyle2 commented Mar 14, 2023 via email

@fmamitrotta
Copy link
Collaborator Author

I've had a closer look at the code, but I could not get my head around how the warning affects the logic of the function. I did some tests, and it seems that I can get the same results with and without the warning.

See for example the code below, where I plot the load-displacement diagram of the model attached in the first post. If I comment out the lines in subcase.py with the warning message (lines 682-683) I get the same results as with the original subcase.py without any issue. Is there a reason why those lines of code can't be removed?

from pyNastran.op2.op2 import read_op2
import numpy as np
import matplotlib.pyplot as plt


# Read op2 file
sol_106_op2 = read_op2(op2_filename='nonlinear_buckling_verification.op2', load_geometry=True, debug=None)

# Get load and displacement history
component_index = 2
loads = {}
displacements = {}
valid_subcase_ids = [subcase_id for subcase_id in sol_106_op2.load_vectors if
                         hasattr(sol_106_op2.load_vectors[subcase_id], 'lftsfqs')]
for subcase_id in valid_subcase_ids:
    loads[subcase_id] = np.apply_along_axis(np.sum, 1, sol_106_op2.load_vectors[subcase_id].data[:, :, component_index])
    displacements[subcase_id] = sol_106_op2.displacements[subcase_id].data[:, -1, component_index]

# Plot load-displacement diagram
load_history = np.concatenate([loads[subcase_id] for subcase_id in loads])
displacement_history = np.concatenate([displacements[subcase_id] for subcase_id in displacements])
_, ax = plt.subplots()
ax.plot(displacement_history, load_history, 'o-')
plt.xlabel('Tip displacement [mm]')
plt.ylabel('$P$ [N]')
plt.grid()
plt.show()

@SteveDoyle2
Copy link
Owner

SteveDoyle2 commented Mar 25, 2023 via email

@SteveDoyle2
Copy link
Owner

SteveDoyle2 commented Mar 26, 2023 via email

@fmamitrotta
Copy link
Collaborator Author

Thanks for the explanation Steve, I understand your point. However, what is the bit of data that we don't get when the expected format is not found? It is not clear within set_casecc, because the code around the if on nwords_to_lsem looks like the following:

    (sdisp_set, sdisp_media, sdisp_format,
     svelocity_set, svelocity_media, svelocity_format,
     saccel_set, saccel_media, saccel_format,
     nonlinear, partn, cyclic, random, nlparm, fmethod,
     nwords_to_lsem) = ints[150:166]
    if nwords_to_lsem // 4 not in {150, 300}:
        self.log.warning(f'nwords_to_lsem={nwords_to_lsem} nwords_to_lsem//4={nwords_to_lsem//4}')

    #assert nwords_to_lsem == 4 * 150, f'nwords_to_lsem={nwords_to_lsem} size={size} nwords_to_lsem//size={nwords_to_lsem//size}'
    # LCC=1200 @ word 166
    # LSM @ 658?

    #print(ints[144:166].tolist())
    (gpforce_set, gpforce_media, gpforce_format,
     ese_set, ese_media, ese_format,
     aerof_set, aerof_media, aerof_format,
     super_seid, super_load, gust, sefinal) = ints[166:179]

There is no action taken after the warning and the rest of the data seems to be read anyway.

I would be happy to work on improving the robustness of the function, as you were suggesting, but I cannot get my head around where the improvement is needed.

@SteveDoyle2
Copy link
Owner

SteveDoyle2 commented Mar 29, 2023 via email

@fmamitrotta
Copy link
Collaborator Author

Do you mean that instead of try-excepting the assert statement, you shortcutted it with the if-warning?

@SteveDoyle2
Copy link
Owner

SteveDoyle2 commented Apr 2, 2023 via email

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

No branches or pull requests

2 participants