SteveDoyle2 / pyNastran

A Python-based interface tool for Nastran's file formats
Other
384 stars 147 forks source link

Unexpected warnings when using large field format #768

Open fmamitrotta opened 5 months ago

fmamitrotta commented 5 months ago

Summary

I'm using write_bdf with is_double=True and I get two warnings that do not appear when using is_double=False. No big deal of course but I thought about looking into this to improve the code.

The first one is pretty simple:

WARNING: write_mesh.py:1326 is_double=True...changing size from 8 to 16...

Looking into write_mesh.py I've found the following piece of code:

assert size in {8, 16}, f'size={size!r}'
    assert is_double in {True, False}, f'is_double={is_double!r}'
    if size == 8:
        if is_double is True:
            log.warning('is_double=True...changing size from 8 to 16...')
            size = 16
    else:
        assert is_double in {True, False}, f'is_double={is_double!r}'

Now, I've not seen anywhere in write_mesh.py is_double being set to True, so my understanding is that it can only be set explicitly by the user when calling the function write_mesh. For this reason, I propose that we should use log.debug instead of log.warning. Is there any other reason why you wanted to log it as a warning?

The second warning that I'm getting is the following one:

WARNING: dynamics.py:755 sid=12 v1=0.0 v2=0.0 nd=1 msglvl=0 maxset=0 shfscl=0.0 flag1=0 flag2=-1 norm=MASS alpha=0.0 nums=0

The warning happens inside the function _read_eigrl and it appears to be related to the field NUMS of the EIGRL card:

sid, v1, v2, nd, msglvl, maxset, shfscl, flag1, flag2, norm, alpha, nums = out
            norm = norm.decode('latin1').rstrip('\x00 ')
            #print('self._nastran_format =', self._nastran_format)
            if nums == 0: # and self._nastran_format == 'nx':
                op2.log.warning(f'sid={sid} v1={v1} v2={v2} nd={nd} msglvl={msglvl} maxset={maxset} '
                                f'shfscl={shfscl} flag1={flag1} flag2={flag2} norm={norm} alpha={alpha} nums={nums}')
                nums = None
                is_none = True

I'm writing the same BDF object to a bdf file, so with the same EIGRL card, running the analysis with Nastran, and reading the op2 file using read_op2(op2_filename=op2_filepath, load_geometry=True, debug=None). When I write the bdf with the standard field format, nums is equal to 538976288 (by the way, what is this number? I've seen that later in the function there is a check on it), while when I write the bdf with large field format, nums is equal to 0.

However the non-blank fields of my EIGRL card are SID, V1 and ND, so I don't see why nums gets those different values. It should be 1 by default according to MSC Nastran QRG 2022.1, and I guess it's not really needed if you are not using the parallel method. image

Reproduction

Please try the following on the attached files.

model = BDF(debug=None)
model.read_bdf("standard_field.bdf")
model.write_bdf("large_field.bdf", is_double=True)
op2_standard_field = read_op2("standard_field.op2", load_geometry=True, debug=None)
op2_large_field = read_op2("large_field.op2", load_geometry=True, debug=None)

standard_vs_large_field_files.zip

Versions

MSC Nastran 2021.4 platform.python_version() --> 3.9.16 pyNastran.__version__ --> this commit

SteveDoyle2 commented 5 months ago

I’ll have to take a look, but if I recall, 538976288 is 8 spaces. I’ve never seen it on the EIGRL though. The DMAP guide is incomplete and mixed types in the same set of bytes is a thing.

I don’t really understand the second line of the EIGRL card, so when Nastran decides it’s important, the code gets confused.

On Thu, Mar 14, 2024 at 4:54 AM Francesco M. A. Mitrotta < @.***> wrote:

Summary

I'm using write_bdf with is_double=True and I get two warnings that do not appear when using is_double=False. No big deal of course but I thought about looking into this to improve the code.

The first one is pretty simple:

WARNING: write_mesh.py:1326 is_double=True...changing size from 8 to 16...

Looking into write_mesh.py I've found the following piece of code:

assert size in {8, 16}, f'size={size!r}' assert is_double in {True, False}, f'is_double={is_double!r}' if size == 8: if is_double is True: log.warning('is_double=True...changing size from 8 to 16...') size = 16 else: assert is_double in {True, False}, f'is_double={is_double!r}'

Now, I've not seen anywhere in write_mesh.py is_double being set to True, so my understanding is that it can only be set explicitly by the user when calling the function write_mesh. For this reason, I propose that we should use log.debug instead of log.warning. Is there any other reason why you wanted to log it as a warning?

The second warning that I'm getting is the following one:

WARNING: dynamics.py:755 sid=12 v1=0.0 v2=0.0 nd=1 msglvl=0 maxset=0 shfscl=0.0 flag1=0 flag2=-1 norm=MASS alpha=0.0 nums=0

The warning happens inside the function _read_eigrl and it appears to be related to the field NUMS of the EIGRL card:

sid, v1, v2, nd, msglvl, maxset, shfscl, flag1, flag2, norm, alpha, nums = out norm = norm.decode('latin1').rstrip('\x00 ')

print('self._nastran_format =', self._nastran_format)

        if nums == 0: # and self._nastran_format == 'nx':
            op2.log.warning(f'sid={sid} v1={v1} v2={v2} nd={nd} msglvl={msglvl} maxset={maxset} '
                            f'shfscl={shfscl} flag1={flag1} flag2={flag2} norm={norm} alpha={alpha} nums={nums}')
            nums = None
            is_none = True

I'm writing the same BDF object to a bdf file, so with the same EIGRL card, running the analysis with Nastran, and reading the op2 file using read_op2(op2_filename=op2_filepath, load_geometry=True, debug=None). When I write the bdf with the standard field format, nums is equal to 538976288 (by the way, what is this number? I've seen that later in the function there is a check on it), while when I write the bdf with large field format, nums is equal to 0.

However the non-blank fields of my EIGRL card are SID, V1 and ND, so I don't see why nums gets those different values. It should be 1 by default according to MSC Nastran QRG 2022.1, and I guess it's not really needed if you are not using the parallel method. image.png (view on web) https://github.com/SteveDoyle2/pyNastran/assets/20526753/f72654da-a2e2-431d-ab81-1e3335d99acb Reproduction

Please try the following on the attached files.

model = BDF(debug=None)model.read_bdf("standard_field.bdf")model.write_bdf("large_field.bdf", is_double=True)op2_standard_field = read_op2("standard_field.op2", load_geometry=True, debug=None)op2_large_field = read_op2("large_field.op2", load_geometry=True, debug=None)

standard_vs_large_field_files.zip https://github.com/SteveDoyle2/pyNastran/files/14601662/standard_vs_large_field_files.zip Versions

MSC Nastran 2021.4 platform.python_version() --> 3.9.16 pyNastran.version --> this commit https://github.com/SteveDoyle2/pyNastran/commit/1c324a0efb1a54c36285efd84aec072d9c3d3342

— Reply to this email directly, view it on GitHub https://github.com/SteveDoyle2/pyNastran/issues/768, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAICUWNEPFU4VFMZSPY4VQDYYGFWDAVCNFSM6AAAAABEV6J7XSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE4DMMJVGY2TEOA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

fmamitrotta commented 5 months ago

Do you mean the second line in the definition of the EIGRL card, or the second (empty) line of the EIGRL card in my bdf file with large field format?

SteveDoyle2 commented 5 months ago

The second line in the QRG is weird. I don't know how MSC/NX handles it and based on that num == 0 vs spaces represented as an integer, it looks like it's different across different versions.

fmamitrotta commented 5 months ago

Yeah indeed it's a very weird representation.

By the way, there's some more printing going on in the function _read_eigrl a few lines after:

            if nums is None:
                nums = 14
                nums_total = nums * 4
                edata2 = data[n+nbytes:n+nbytes+nums_total]
                op2.show_data(edata2, types=types)
                fi = unpack(mapfmt('%if' % nums, self.size), edata2)
                print(out, fi)
                #nbytes += nums_total

I've checked what is happening there and it seems it's all debugging printing. Would it make sense to wrap it with an if op2.is_deub_file: statement, in the following way?

            if nums is None:
                nums = 14
                nums_total = nums * 4
                edata2 = data[n+nbytes:n+nbytes+nums_total]
                if op2.is_debug_file:
                    op2.show_data(edata2, types=types)
                    fi = unpack(mapfmt('%if' % nums, self.size), edata2)
                    print(out, fi)
                #nbytes += nums_total