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

ExportLSDynaKeywordFileParams #942

Open
2 tasks done
straponiek opened this issue Nov 22, 2024 · 5 comments
Open
2 tasks done

ExportLSDynaKeywordFileParams #942

straponiek opened this issue Nov 22, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@straponiek
Copy link

🔍 Before submitting the issue

  • I have searched among the existing issues
  • I am using a Python virtual environment

🐞 Description of the bug

The output is inconsistent with what is written in the documentation:

class ExportLSDynaKeywordFileParams(model=None, material_properties=None, database_keywords=None, output_format=None, analysis_type=None, compute_spotweld_thickness=None, json_data=None, **kwargs)

the output file contains all the keywords and not just the ones related to the geometry (model) even if the parameters value should be set to None by default. Setting the parameters to None explicitly doesn't help.

📝 Steps to reproduce

        export_params = prime.ExportLSDynaKeywordFileParams(model=model)
        export_result = file_io.export_lsdyna_keyword_file(output_file, export_params)

💻 Which operating system are you using?

Windows

📀 Which ANSYS version are you using?

2024 R2

🐍 Which Python version are you using?

3.11

📦 Installed packages

aiohappyeyeballs==2.4.3
aiohttp==3.11.6
aiosignal==1.3.1
ansys-api-dyna==0.4.1
ansys-api-mechanical==0.1.2
ansys-api-meshing-prime==0.1.3
ansys-api-platform-instancemanagement==1.1.0
ansys-dpf-core==0.10.0
ansys-dpf-gate==0.4.1
ansys-dpf-gatebin==0.4.1
ansys-dyna-core==0.6.0
ansys-grpc-dpf==0.8.1
ansys-mechanical-core==0.11.10
ansys-mechanical-env==0.1.8
ansys-mechanical-stubs==0.1.4
ansys-meshing-prime==0.6.2
ansys-platform-instancemanagement==1.1.2
ansys-pythonnet==3.1.0rc4
ansys-tools-path==0.7.0
anyio==4.6.2.post1
appdirs==1.4.4
archspec @ file:///croot/archspec_1697725767277/work
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==2.4.1
async-lru @ file:///C:/b/abs_e0hjkvwwb5/croot/async-lru_1699554572212/work
attrs==24.2.0
Babel @ file:///C:/ci_311/babel_1676427169844/work
backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work
beautifulsoup4==4.12.3
bleach==6.2.0
boltons @ file:///C:/ci_311/boltons_1677729932371/work
Bottleneck @ file:///C:/ci_311/bottleneck_1676500016583/work
Brotli @ file:///C:/ci_311/brotli-split_1676435766766/work
cachetools==5.3.2
certifi @ file:///C:/b/abs_1fw_exq1si/croot/certifi_1725551736618/work/certifi
cffi @ file:///C:/b/abs_924gv1kxzj/croot/cffi_1700254355075/work
charset-normalizer @ file:///tmp/build/80754af9/charset-normalizer_1630003229654/work
click==8.1.7
clr-loader==0.2.6
colorama @ file:///C:/ci_311/colorama_1676422310965/work
comm==0.2.2
conda @ file:///C:/b/abs_f5n1kle6av/croot/conda_1699303158682/work
conda-content-trust @ file:///C:/b/abs_e3bcpyv7sw/croot/conda-content-trust_1693490654398/work
conda-libmamba-solver @ file:///C:/b/abs_02v6nijijw/croot/conda-libmamba-solver_1700150953092/work/src
conda-package-handling @ file:///C:/b/abs_b9wp3lr1gn/croot/conda-package-handling_1691008700066/work
conda_package_streaming @ file:///C:/b/abs_6c28n38aaj/croot/conda-package-streaming_1690988019210/work
contourpy==1.3.1
cryptography @ file:///C:/b/abs_f4do8t8jfs/croot/cryptography_1694444424531/work
cycler==0.12.1
debugpy @ file:///C:/b/abs_c0y1fjipt2/croot/debugpy_1690906864587/work
decorator==5.1.1
defusedxml==0.7.1
dynareadout==24.5
et-xmlfile==1.1.0
executing==2.1.0
fastjsonschema==2.20.0
fonttools==4.55.0
fqdn==1.5.1
frozenlist==1.5.0
google-api-core==2.15.0
google-api-python-client==2.114.0
google-auth==2.26.2
google-auth-httplib2==0.2.0
googleapis-common-protos==1.62.0
grpcio==1.68.0
hollerith==0.4.1
httplib2==0.22.0
idna @ file:///C:/ci_311/idna_1676424932545/work
imageio==2.33.1
importlib_metadata==8.5.0
ipykernel @ file:///C:/b/abs_07rkft_vaz/croot/ipykernel_1691121700587/work
ipython==8.29.0
ipywidgets==8.1.5
isoduration==20.11.0
jedi==0.19.2
Jinja2==3.1.4
json5 @ file:///tmp/build/80754af9/json5_1624432770122/work
jsonpatch @ file:///tmp/build/80754af9/jsonpatch_1615747632069/work
jsonpointer==2.1
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
jupyter @ file:///C:/ci_311/jupyter_1678249952587/work
jupyter-console @ file:///C:/b/abs_82xaa6i2y4/croot/jupyter_console_1680000189372/work
jupyter-events==0.10.0
jupyter-lsp @ file:///C:/b/abs_ecle3em9d4/croot/jupyter-lsp-meta_1699978291372/work
jupyter_client==8.6.3
jupyter_core==5.7.2
jupyter_server==2.14.2
jupyter_server_proxy==4.4.0
jupyter_server_terminals==0.5.3
jupyterlab @ file:///C:/b/abs_aergn8zopq/croot/jupyterlab_1700518316761/work
jupyterlab_pygments==0.3.0
jupyterlab_server @ file:///C:/b/abs_e08i7qn9m8/croot/jupyterlab_server_1699555481806/work
jupyterlab_widgets==3.0.13
kiwisolver==1.4.7
libmambapy @ file:///C:/b/abs_efpsdwt4ya/croot/mamba-split_1698782663578/work/libmambapy
MarkupSafe==3.0.2
matplotlib==3.9.2
matplotlib-inline==0.1.7
menuinst @ file:///C:/ci_311/menuinst_1678730372782/work
mistune==3.0.2
mkl-fft @ file:///C:/b/abs_19i1y8ykas/croot/mkl_fft_1695058226480/work
mkl-random @ file:///C:/b/abs_edwkj1_o69/croot/mkl_random_1695059866750/work
mkl-service==2.4.0
more-itertools==10.5.0
msgpack==1.1.0
multidict==6.1.0
munkres==1.1.4
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
notebook @ file:///C:/b/abs_26737osg4x/croot/notebook_1700582146311/work
notebook_shim @ file:///C:/b/abs_a5xysln3lb/croot/notebook-shim_1699455926920/work
numexpr @ file:///C:/b/abs_5fucrty5dc/croot/numexpr_1696515448831/work
numpy==2.1.3
openpyxl @ file:///C:/b/abs_764brjadj1/croot/openpyxl_1714158895873/work
overrides==7.7.0
packaging @ file:///C:/b/abs_28t5mcoltc/croot/packaging_1693575224052/work
pandas @ file:///C:/b/abs_81b3npjrl8/croot/pandas_1697477219064/work/dist/pandas-2.1.1-cp311-cp311-win_amd64.whl#sha256=1732f3b07ba52119320a2b01aa09f2627f6258176e492b728daf60efb4f4d78e
pandocfilters==1.5.1
parso==0.8.4
pickleshare @ file:///tmp/build/80754af9/pickleshare_1606932040724/work
pillow==11.0.0
platformdirs @ file:///C:/b/abs_b6z_yqw_ii/croot/platformdirs_1692205479426/work
pluggy @ file:///C:/ci_311/pluggy_1676422178143/work
ply==3.11
pooch==1.8.2
prometheus_client==0.21.0
prompt_toolkit==3.0.48
propcache==0.2.0
protobuf==4.25.5
psutil==6.1.0
pure_eval==0.2.3
pyasn1==0.5.1
pyasn1-modules==0.3.0
pycosat @ file:///C:/b/abs_31zywn1be3/croot/pycosat_1696537126223/work
pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work
Pygments==2.18.0
pyOpenSSL @ file:///C:/b/abs_08f38zyck4/croot/pyopenssl_1690225407403/work
pyparsing==3.2.0
PyQt5==5.15.10
PyQt5-sip @ file:///C:/b/abs_c0pi2mimq3/croot/pyqt-split_1698769125270/work/pyqt_sip
PySocks @ file:///C:/ci_311/pysocks_1676425991111/work
python-dateutil==2.9.0.post0
python-json-logger==2.0.7
pytz @ file:///C:/b/abs_19q3ljkez4/croot/pytz_1695131651401/work
pyvista==0.44.1
pywin32==308
pywinpty==2.0.14
PyYAML==6.0.2
pyzmq==26.2.0
qtconsole @ file:///C:/b/abs_4awqjtg1ug/croot/qtconsole_1700160696631/work
QtPy @ file:///C:/b/abs_derqu__3p8/croot/qtpy_1700144907661/work
referencing==0.35.1
requests @ file:///C:/b/abs_316c2inijk/croot/requests_1690400295842/work
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.21.0
rsa==4.9
ruamel.yaml @ file:///C:/ci_311/ruamel.yaml_1676439214109/work
scipy==1.11.3
scooby==0.10.0
Send2Trash==1.8.3
simpervisor==1.0.0
sip @ file:///C:/b/abs_edevan3fce/croot/sip_1698675983372/work
six==1.16.0
sniffio==1.3.1
soupsieve==2.6
stack-data==0.6.3
terminado==0.18.1
tinycss2==1.4.0
tornado==6.4.1
tqdm @ file:///C:/b/abs_f76j9hg7pv/croot/tqdm_1679561871187/work
traitlets==5.14.3
trame==3.7.0
trame-client==3.5.0
trame-server==3.2.3
trame-vtk==2.8.12
trame-vuetify==2.7.2
truststore @ file:///C:/b/abs_55z7b3r045/croot/truststore_1695245455435/work
types-python-dateutil==2.9.0.20241003
typing_extensions==4.12.2
tzdata @ file:///croot/python-tzdata_1690578112552/work
uri-template==1.3.0
uritemplate==4.1.1
urllib3 @ file:///C:/b/abs_9cmlsrm3ys/croot/urllib3_1698257595508/work
vtk==9.3.1
wcwidth==0.2.13
webcolors==24.11.1
webencodings==0.5.1
websocket-client==1.8.0
widgetsnbextension==4.0.13
win-inet-pton @ file:///C:/ci_311/win_inet_pton_1676425458225/work
wslink==2.2.1
yarl==1.17.2
zipp==3.21.0
zstandard==0.19.0
@straponiek straponiek added the bug Something isn't working label Nov 22, 2024
@waltersma
Copy link
Contributor

Hi @straponiek,

Please be advised that this method and all its parameters are currently at beta and in this instance will likely change in future. There is active work ongoing in this area.

Please could you describe your use case in more detail to help my understanding? What is the input you are creating the exported file from? Are you importing cad and meshing or starting with something else? What is your expectation with your specific case as to what you would like to see as the output and how you are trying to achieve it currently?

The documentation that you reference shows that these parameters are initialised at runtime and "None" in this context does not reflect a default. All of these parameters currently only take affect if simulation data is present and as of today this will not be the case for importing cad and meshing. A set of default keywords are currently exported in this instance, which is what you are seeing.

As mentioned this is an area of active work so your feedback will be gratefully received.

I hope this helps clarify the results you are seeing.

Thanks

@straponiek
Copy link
Author

straponiek commented Nov 27, 2024

Hi @waltersma,
thanks for your answer. I'm aware of the beta version of this library, I'm hoping to contribute in my small way, since I'm not much into coding. If I understood correctly, the problem is related to the fact that there's no simulation data in my file... but maybe the syntax I'm using is not correct.
Here is the script, hope it helps you in better understanding the issue (my aim is to export just the keywords related to the model):

import ansys.meshing.prime as prime
import os

def ImportMeshExport(step_file, output_file):
    """
    Imports a STEP file, generates a volume mesh with tetrahedral elements, and exports it to an LS-DYNA file.

    Args:
        step_file (str): The path to the STEP file.
        output_file (str): The desired output file for the LS-DYNA mesh.
    """
    element_size = 3  # Desired element size in millimeters

    # Check if the input STEP file exists
    if not os.path.isfile(step_file):
        print(f"Error: STEP file '{step_file}' not found.")
        return

    # Launch the PyPrimeMesh client
    with prime.launch_prime() as client:
        model = client.model

        # Import the STEP file with units set to millimeters
        file_io = prime.FileIO(model)
        import_params = prime.ImportCadParams(model=model, length_unit=prime.LengthUnit.MM)
        import_result = file_io.import_cad(step_file, import_params)
        if import_result.error_code != prime.ErrorCode.NOERROR:
            print(f"Error importing STEP file: {import_result.error_code}")
            return
        print(f"Successfully imported STEP file '{step_file}' with units set to millimeters.")

        # Create a tetrahedral volume mesh
        try:
            print("Creating a tetrahedral volume mesh...")
            mesher = prime.lucid.Mesh(model)
            mesher.surface_mesh(min_size=element_size, max_size=element_size)
            mesher.volume_mesh(volume_fill_type=prime.VolumeFillType.TET)
            print(f"Tetrahedral mesh created with element size {element_size} mm.")
        except Exception as e:
            print(f"Exception during volume meshing: {e}")
            return
            
        # Export the mesh to LS-DYNA format
        try:
            print(f"Exporting mesh to LS-DYNA format: {output_file}")
            # Configure export parameters with defaults set to None
            export_params = prime.ExportLSDynaKeywordFileParams(model=model)
            export_result = file_io.export_lsdyna_keyword_file(output_file, export_params)
            if export_result.error_code != prime.ErrorCode.NOERROR:
                print(f"Error exporting mesh: {export_result.error_code}")
                return
            print(f"Mesh successfully exported to '{output_file}'.")
        except Exception as e:
            print(f"Exception during mesh export: {e}")

if __name__ == "__main__":
    # Ask the user for the STEP file path and output file name
    step_file_input = input("Enter the path to the STEP file: ").strip()
    output_file_input = input("Enter the desired output file name: ").strip()

    # Call the processing function with both inputs
    ImportMeshExport(step_file_input, output_file_input)

@Pinteresting
Copy link

Hi @waltersma, thanks for your answer. I'm aware of the beta version of this library, I'm hoping to contribute in my small way, since I'm not much into coding. If I understood correctly, the problem is related to the fact that there's no simulation data in my file... but maybe the syntax I'm using is not correct. Here is the script, hope it helps you in better understanding the issue (my aim is to export just the keywords related to the model):

Hi @straponiek, @waltersma
Let me try to help with the confusion.
Right now, if there is simulation data that is generated during the import process (it wont generate anything for most file types, including STEP files), then the export process would create a k file with a lot of keywords not associated with the geometry.

All of the parameters right now modify the export process when simulation data is present.

If there is not simulation data present (as in this case), then the exported k file should almost entirely be associated with the geometry, but there are a small number of extra keywords I see also being written such as *CONTROL_ that you could be referencing?

There are no parameters to control this behavior.

In the k file you are creating, can you specify which keywords or sections of the file you are having issues with or why it is causing problems later in your process?

@waltersma
Copy link
Contributor

Hi @straponiek,

Thanks for sharing the code. In addition to comments from @Pinteresting, when you instantiate the parameters like this the 'model' will be used to define expected defaults and these will not necessarily be None in all cases.

You could print the parameters to observe the defaults used. For example,

export_params = prime.ExportLSDynaKeywordFileParams(model=model)
print(export_params)

will give you:

material_properties :
database_keywords :
output_format :  LSDynaFileFormatType.I10
analysis_type :  LSDynaAnalysisType.DOORSLAM
compute_spotweld_thickness :  True

You may wish to set these explicitly.

Thanks

@straponiek
Copy link
Author

@waltersma @Pinteresting Thank you both for the clarification. I just bypassed the problem by creating a parsing script for the .k file that keeps just the mesh keywords.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants