proface-abaqus-pre 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,77 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2020 GitHub
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ # Original file downloaded from
6
+ # https://raw.githubusercontent.com/actions/starter-workflows/00795b7feebceed43fe2510ccb976238441d9c07/ci/python-publish.yml
7
+
8
+ # This workflow will upload a Python Package to PyPI when a release is created
9
+ # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries
10
+
11
+ # This workflow uses actions that are not certified by GitHub.
12
+ # They are provided by a third-party and are governed by
13
+ # separate terms of service, privacy policy, and support
14
+ # documentation.
15
+
16
+ name: Upload Python Package
17
+
18
+ on:
19
+ release:
20
+ types: [published]
21
+
22
+ permissions:
23
+ contents: read
24
+
25
+ jobs:
26
+ release-build:
27
+ runs-on: ubuntu-latest
28
+
29
+ steps:
30
+ - uses: actions/checkout@v4
31
+
32
+ - uses: actions/setup-python@v5
33
+ with:
34
+ python-version: "3.x"
35
+
36
+ - name: Build release distributions
37
+ run: |
38
+ # NOTE: put your own distribution build steps here.
39
+ python -m pip install build
40
+ python -m build
41
+
42
+ - name: Upload distributions
43
+ uses: actions/upload-artifact@v4
44
+ with:
45
+ name: release-dists
46
+ path: dist/
47
+
48
+ pypi-publish:
49
+ runs-on: ubuntu-latest
50
+ needs:
51
+ - release-build
52
+ permissions:
53
+ # IMPORTANT: this permission is mandatory for trusted publishing
54
+ id-token: write
55
+
56
+ # Dedicated environments with protections for publishing are strongly recommended.
57
+ # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules
58
+ environment:
59
+ name: pypi
60
+ # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status:
61
+ # url: https://pypi.org/p/YOURPROJECT
62
+ #
63
+ # ALTERNATIVE: if your GitHub Release name is the PyPI project version string
64
+ # ALTERNATIVE: exactly, uncomment the following line instead:
65
+ url: https://pypi.org/project/proface-abaqus-pre/${{ github.event.release.name }}
66
+
67
+ steps:
68
+ - name: Retrieve release distributions
69
+ uses: actions/download-artifact@v4
70
+ with:
71
+ name: release-dists
72
+ path: dist/
73
+
74
+ - name: Publish release distributions to PyPI
75
+ uses: pypa/gh-action-pypi-publish@release/v1
76
+ with:
77
+ packages-dir: dist/
@@ -0,0 +1,17 @@
1
+ # SPDX-FileCopyrightText: 2025 ProFACE developers
2
+ #
3
+ # SPDX-License-Identifier: CC0-1.0
4
+
5
+ # Python-generated files
6
+ __pycache__/
7
+ *.py[oc]
8
+ build/
9
+ dist/
10
+ wheels/
11
+ *.egg-info
12
+
13
+ # Virtual environments
14
+ .venv
15
+
16
+ # hatch-vcs build hook
17
+ src/proface/abaqus/preprocessor/_version.py
@@ -0,0 +1,28 @@
1
+ # SPDX-FileCopyrightText: 2025 ProFACE developers
2
+ #
3
+ # SPDX-License-Identifier: CC0-1.0
4
+
5
+ # See https://pre-commit.com for more information
6
+ # See https://pre-commit.com/hooks.html for more hooks
7
+ repos:
8
+ - repo: https://github.com/pre-commit/pre-commit-hooks
9
+ rev: v5.0.0
10
+ hooks:
11
+ # general checks
12
+ - id: trailing-whitespace
13
+ - id: end-of-file-fixer
14
+ - id: mixed-line-ending
15
+ - id: check-added-large-files
16
+ - id: check-case-conflict
17
+ # check file formats
18
+ - id: check-yaml
19
+ - id: check-toml
20
+ - repo: https://github.com/astral-sh/ruff-pre-commit
21
+ rev: v0.11.3
22
+ hooks:
23
+ - id: ruff
24
+ - id: ruff-format
25
+ - repo: https://github.com/fsfe/reuse-tool
26
+ rev: v5.0.2
27
+ hooks:
28
+ - id: reuse
@@ -0,0 +1,121 @@
1
+ Creative Commons Legal Code
2
+
3
+ CC0 1.0 Universal
4
+
5
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
6
+ LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
7
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
8
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
9
+ REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
10
+ PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
11
+ THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
12
+ HEREUNDER.
13
+
14
+ Statement of Purpose
15
+
16
+ The laws of most jurisdictions throughout the world automatically confer
17
+ exclusive Copyright and Related Rights (defined below) upon the creator
18
+ and subsequent owner(s) (each and all, an "owner") of an original work of
19
+ authorship and/or a database (each, a "Work").
20
+
21
+ Certain owners wish to permanently relinquish those rights to a Work for
22
+ the purpose of contributing to a commons of creative, cultural and
23
+ scientific works ("Commons") that the public can reliably and without fear
24
+ of later claims of infringement build upon, modify, incorporate in other
25
+ works, reuse and redistribute as freely as possible in any form whatsoever
26
+ and for any purposes, including without limitation commercial purposes.
27
+ These owners may contribute to the Commons to promote the ideal of a free
28
+ culture and the further production of creative, cultural and scientific
29
+ works, or to gain reputation or greater distribution for their Work in
30
+ part through the use and efforts of others.
31
+
32
+ For these and/or other purposes and motivations, and without any
33
+ expectation of additional consideration or compensation, the person
34
+ associating CC0 with a Work (the "Affirmer"), to the extent that he or she
35
+ is an owner of Copyright and Related Rights in the Work, voluntarily
36
+ elects to apply CC0 to the Work and publicly distribute the Work under its
37
+ terms, with knowledge of his or her Copyright and Related Rights in the
38
+ Work and the meaning and intended legal effect of CC0 on those rights.
39
+
40
+ 1. Copyright and Related Rights. A Work made available under CC0 may be
41
+ protected by copyright and related or neighboring rights ("Copyright and
42
+ Related Rights"). Copyright and Related Rights include, but are not
43
+ limited to, the following:
44
+
45
+ i. the right to reproduce, adapt, distribute, perform, display,
46
+ communicate, and translate a Work;
47
+ ii. moral rights retained by the original author(s) and/or performer(s);
48
+ iii. publicity and privacy rights pertaining to a person's image or
49
+ likeness depicted in a Work;
50
+ iv. rights protecting against unfair competition in regards to a Work,
51
+ subject to the limitations in paragraph 4(a), below;
52
+ v. rights protecting the extraction, dissemination, use and reuse of data
53
+ in a Work;
54
+ vi. database rights (such as those arising under Directive 96/9/EC of the
55
+ European Parliament and of the Council of 11 March 1996 on the legal
56
+ protection of databases, and under any national implementation
57
+ thereof, including any amended or successor version of such
58
+ directive); and
59
+ vii. other similar, equivalent or corresponding rights throughout the
60
+ world based on applicable law or treaty, and any national
61
+ implementations thereof.
62
+
63
+ 2. Waiver. To the greatest extent permitted by, but not in contravention
64
+ of, applicable law, Affirmer hereby overtly, fully, permanently,
65
+ irrevocably and unconditionally waives, abandons, and surrenders all of
66
+ Affirmer's Copyright and Related Rights and associated claims and causes
67
+ of action, whether now known or unknown (including existing as well as
68
+ future claims and causes of action), in the Work (i) in all territories
69
+ worldwide, (ii) for the maximum duration provided by applicable law or
70
+ treaty (including future time extensions), (iii) in any current or future
71
+ medium and for any number of copies, and (iv) for any purpose whatsoever,
72
+ including without limitation commercial, advertising or promotional
73
+ purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
74
+ member of the public at large and to the detriment of Affirmer's heirs and
75
+ successors, fully intending that such Waiver shall not be subject to
76
+ revocation, rescission, cancellation, termination, or any other legal or
77
+ equitable action to disrupt the quiet enjoyment of the Work by the public
78
+ as contemplated by Affirmer's express Statement of Purpose.
79
+
80
+ 3. Public License Fallback. Should any part of the Waiver for any reason
81
+ be judged legally invalid or ineffective under applicable law, then the
82
+ Waiver shall be preserved to the maximum extent permitted taking into
83
+ account Affirmer's express Statement of Purpose. In addition, to the
84
+ extent the Waiver is so judged Affirmer hereby grants to each affected
85
+ person a royalty-free, non transferable, non sublicensable, non exclusive,
86
+ irrevocable and unconditional license to exercise Affirmer's Copyright and
87
+ Related Rights in the Work (i) in all territories worldwide, (ii) for the
88
+ maximum duration provided by applicable law or treaty (including future
89
+ time extensions), (iii) in any current or future medium and for any number
90
+ of copies, and (iv) for any purpose whatsoever, including without
91
+ limitation commercial, advertising or promotional purposes (the
92
+ "License"). The License shall be deemed effective as of the date CC0 was
93
+ applied by Affirmer to the Work. Should any part of the License for any
94
+ reason be judged legally invalid or ineffective under applicable law, such
95
+ partial invalidity or ineffectiveness shall not invalidate the remainder
96
+ of the License, and in such case Affirmer hereby affirms that he or she
97
+ will not (i) exercise any of his or her remaining Copyright and Related
98
+ Rights in the Work or (ii) assert any associated claims and causes of
99
+ action with respect to the Work, in either case contrary to Affirmer's
100
+ express Statement of Purpose.
101
+
102
+ 4. Limitations and Disclaimers.
103
+
104
+ a. No trademark or patent rights held by Affirmer are waived, abandoned,
105
+ surrendered, licensed or otherwise affected by this document.
106
+ b. Affirmer offers the Work as-is and makes no representations or
107
+ warranties of any kind concerning the Work, express, implied,
108
+ statutory or otherwise, including without limitation warranties of
109
+ title, merchantability, fitness for a particular purpose, non
110
+ infringement, or the absence of latent or other defects, accuracy, or
111
+ the present or absence of errors, whether or not discoverable, all to
112
+ the greatest extent permissible under applicable law.
113
+ c. Affirmer disclaims responsibility for clearing rights of other persons
114
+ that may apply to the Work or any use thereof, including without
115
+ limitation any person's Copyright and Related Rights in the Work.
116
+ Further, Affirmer disclaims responsibility for obtaining any necessary
117
+ consents, permissions or other rights required for any use of the
118
+ Work.
119
+ d. Affirmer understands and acknowledges that Creative Commons is not a
120
+ party to this document and has no duty or obligation with respect to
121
+ this CC0 or use of the Work.
@@ -0,0 +1,18 @@
1
+ MIT License
2
+
3
+ Copyright (c) <year> <copyright holders>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
6
+ associated documentation files (the "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
9
+ following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial
12
+ portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
16
+ EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18
+ USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,78 @@
1
+ Metadata-Version: 2.4
2
+ Name: proface-abaqus-pre
3
+ Version: 0.1.0
4
+ Summary: Abaqus to ProFACE preprocessor
5
+ Project-URL: documentation, https://github.com/ProFACE-dev/proface-abaqus-pre#proface-abaqus-pre
6
+ Project-URL: issues, https://github.com/ProFACE-dev/proface-abaqus-pre/issues
7
+ Project-URL: source, https://github.com/ProFACE-dev/proface-abaqus-pre
8
+ Author-email: Stefano Miccoli <stefano.miccoli@polimi.it>
9
+ License-Expression: MIT
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: Implementation :: CPython
16
+ Requires-Python: >=3.12
17
+ Requires-Dist: h5py>=3.13.0
18
+ Requires-Dist: numpy>=2.0
19
+ Requires-Dist: proface-pre>=0.2.0
20
+ Requires-Dist: suanpan-abaqus~=0.1.0
21
+ Description-Content-Type: text/markdown
22
+
23
+ <!--
24
+ SPDX-FileCopyrightText: 2025 ProFACE developers
25
+
26
+ SPDX-License-Identifier: MIT
27
+ -->
28
+
29
+ # ProFACE-Abaqus-Pre
30
+
31
+ ProFACE-Abaqus-Pre is a python package that provides the `proface.preprocessor.abaqus` plugin for use with the [`proface-pre`](https://github.com/ProFACE-dev/proface-pre) command-line interface (CLI).
32
+
33
+ This plugin enables the conversion of Abaqus binary `.fil` results files to ProFACE `.h5` FEA input files.
34
+
35
+ ## Installation
36
+
37
+ Install from <https://pypi.org> with
38
+
39
+ ```
40
+ pip install proface-abaqus-pre
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ Running
46
+
47
+ ```
48
+ proface-pre example.toml
49
+ ```
50
+
51
+ will produce `example.h5` from `example.fil`.
52
+
53
+ `example.toml` has the following format:
54
+
55
+ ```toml
56
+ fea_software = "Abaqus"
57
+
58
+ [Abaqus.input]
59
+ fil = "example.fil" # optional if .toml and .fil have the same name
60
+
61
+ [Abaqus.results.ref_load]
62
+ step = 1 # 0 for last step
63
+ increment = 1 # 0 for last increment
64
+ ```
65
+
66
+ ## License
67
+
68
+ ProFACE-Abaqus-Pre is licensed under the MIT license.
69
+ ProFACE-Pre makes no claims about [ProFACE](https://proface.polimi.it) which is a distinct program with different licensing requirements.
70
+
71
+ ### Disclaimer
72
+
73
+ This project is not affiliated with, endorsed by, or sponsored by Dassault Systèmes, The HDF Group, or any of their respective products.
74
+
75
+ - Abaqus is a registered trademark of Dassault Systèmes or its subsidiaries in the United States and/or other countries.
76
+ - HDF5 is a trademark of The HDF Group.
77
+
78
+ All trademarks and registered trademarks are the property of their respective owners.
@@ -0,0 +1,56 @@
1
+ <!--
2
+ SPDX-FileCopyrightText: 2025 ProFACE developers
3
+
4
+ SPDX-License-Identifier: MIT
5
+ -->
6
+
7
+ # ProFACE-Abaqus-Pre
8
+
9
+ ProFACE-Abaqus-Pre is a python package that provides the `proface.preprocessor.abaqus` plugin for use with the [`proface-pre`](https://github.com/ProFACE-dev/proface-pre) command-line interface (CLI).
10
+
11
+ This plugin enables the conversion of Abaqus binary `.fil` results files to ProFACE `.h5` FEA input files.
12
+
13
+ ## Installation
14
+
15
+ Install from <https://pypi.org> with
16
+
17
+ ```
18
+ pip install proface-abaqus-pre
19
+ ```
20
+
21
+ ## Usage
22
+
23
+ Running
24
+
25
+ ```
26
+ proface-pre example.toml
27
+ ```
28
+
29
+ will produce `example.h5` from `example.fil`.
30
+
31
+ `example.toml` has the following format:
32
+
33
+ ```toml
34
+ fea_software = "Abaqus"
35
+
36
+ [Abaqus.input]
37
+ fil = "example.fil" # optional if .toml and .fil have the same name
38
+
39
+ [Abaqus.results.ref_load]
40
+ step = 1 # 0 for last step
41
+ increment = 1 # 0 for last increment
42
+ ```
43
+
44
+ ## License
45
+
46
+ ProFACE-Abaqus-Pre is licensed under the MIT license.
47
+ ProFACE-Pre makes no claims about [ProFACE](https://proface.polimi.it) which is a distinct program with different licensing requirements.
48
+
49
+ ### Disclaimer
50
+
51
+ This project is not affiliated with, endorsed by, or sponsored by Dassault Systèmes, The HDF Group, or any of their respective products.
52
+
53
+ - Abaqus is a registered trademark of Dassault Systèmes or its subsidiaries in the United States and/or other countries.
54
+ - HDF5 is a trademark of The HDF Group.
55
+
56
+ All trademarks and registered trademarks are the property of their respective owners.
@@ -0,0 +1,77 @@
1
+ # SPDX-FileCopyrightText: 2025 ProFACE developers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ [project]
6
+ dynamic = ["version"]
7
+ name = "proface-abaqus-pre"
8
+ description = "Abaqus to ProFACE preprocessor"
9
+ readme = "README.md"
10
+ authors = [
11
+ { name = "Stefano Miccoli", email = "stefano.miccoli@polimi.it" }
12
+ ]
13
+ mantainers = [
14
+ { name = "ProFACE developers", email = "proface@polimi.it" }
15
+ ]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Environment :: Console",
19
+ "Programming Language :: Python",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Programming Language :: Python :: 3.13",
22
+ "Programming Language :: Python :: Implementation :: CPython",
23
+ ]
24
+ requires-python = ">=3.12"
25
+ dependencies = [
26
+ "proface-pre>=0.2.0",
27
+ "h5py>=3.13.0",
28
+ "numpy>=2.0",
29
+ "suanpan-abaqus~=0.1.0",
30
+ ]
31
+ license = "MIT"
32
+
33
+ [project.entry-points."proface.preprocessor"]
34
+ abaqus = "proface.abaqus.preprocessor:main"
35
+
36
+ [project.urls]
37
+ documentation = "https://github.com/ProFACE-dev/proface-abaqus-pre#proface-abaqus-pre"
38
+ issues = "https://github.com/ProFACE-dev/proface-abaqus-pre/issues"
39
+ source = "https://github.com/ProFACE-dev/proface-abaqus-pre"
40
+
41
+ [build-system]
42
+ requires = ["hatchling", "hatch-vcs"]
43
+ build-backend = "hatchling.build"
44
+
45
+ #
46
+ # hatch
47
+ #
48
+ [tool.hatch.version]
49
+ source = "vcs"
50
+ [tool.hatch.version.raw-options]
51
+ version_scheme = "release-branch-semver"
52
+ local_scheme = "node-and-date"
53
+ [tool.hatch.build.hooks.vcs]
54
+ version-file = "src/proface/abaqus/preprocessor/_version.py"
55
+ [tool.hatch.build.targets.wheel]
56
+ packages = ["src/proface"]
57
+
58
+ #
59
+ # ruff
60
+ #
61
+ [tool.ruff]
62
+ line-length = 80
63
+ target-version = "py312"
64
+
65
+ [tool.ruff.lint]
66
+ select = ["A", "ARG", "B", "BLE", "C4", "C90", "COM818",
67
+ "E", "W", "EM", "F", "FA", "FBT", "FLY", "G", "I", "ICN",
68
+ "INP", "INT", "ISC", "N", "NPY", "PERF", "PGH", "PIE",
69
+ "PLE", "PLR", "PLW", "PT", "PYI", "RET", "RUF", "S",
70
+ "SIM", "SLF", "SLOT", "T10", "T20", "TCH", "TRY", "TID",
71
+ "UP", "YTT",
72
+ ]
73
+ ignore = ["S101", "PT015", "B011", "TRY400"]
74
+
75
+
76
+ [tool.ruff.lint.isort]
77
+ known-first-party = ["proface"]
@@ -0,0 +1,10 @@
1
+ # SPDX-FileCopyrightText: 2025 ProFACE developers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """ProFACE Preprocessor package for Abaqus FEA"""
6
+
7
+ from ._version import __version__
8
+ from .translator import AbaqusTranslatorError, main
9
+
10
+ __all__ = ["AbaqusTranslatorError", "__version__", "main"]
@@ -0,0 +1,21 @@
1
+ # file generated by setuptools-scm
2
+ # don't change, don't track in version control
3
+
4
+ __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
5
+
6
+ TYPE_CHECKING = False
7
+ if TYPE_CHECKING:
8
+ from typing import Tuple
9
+ from typing import Union
10
+
11
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
12
+ else:
13
+ VERSION_TUPLE = object
14
+
15
+ version: str
16
+ __version__: str
17
+ __version_tuple__: VERSION_TUPLE
18
+ version_tuple: VERSION_TUPLE
19
+
20
+ __version__ = version = '0.1.0'
21
+ __version_tuple__ = version_tuple = (0, 1, 0)
@@ -0,0 +1,337 @@
1
+ # SPDX-FileCopyrightText: 2025 ProFACE developers
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Translator implementation"""
6
+
7
+ import collections.abc
8
+ import logging
9
+ from pathlib import Path
10
+
11
+ import h5py
12
+ import numpy as np
13
+ from suanpan.abqfil import AbqFil
14
+
15
+ from proface.preprocessor import PreprocessorError
16
+
17
+ from . import __version__
18
+
19
+ logger = logging.getLogger(__name__)
20
+
21
+
22
+ # translation from Abaqus result codes to ProFACE ids
23
+ ABQ_VAR = {"R11": "S", "R401": "SP", "R76": "IVOL", "R8": "COORD"}
24
+ # translation from Abaqus location codes to ProFACE ids
25
+ ABQ_LOC = {0: "integration_point", 4: "nodal_averaged"}
26
+
27
+ # function for computing results path in h5
28
+ _h5_path = "{var:s}/{loc:s}/{eltype:s}".format
29
+
30
+ # save results in single precision
31
+ RES_DTYPE = np.dtype("float32")
32
+
33
+
34
+ class AbaqusTranslatorError(PreprocessorError):
35
+ pass
36
+
37
+
38
+ def main(
39
+ *, job: collections.abc.Mapping, job_path: Path, h5: h5py.Group
40
+ ) -> None:
41
+ """main entrypoint for abaqus preprocessor"""
42
+
43
+ # runtime type checking
44
+ if not isinstance(job, collections.abc.Mapping):
45
+ msg = "'job' must be a mapping"
46
+ raise TypeError(msg)
47
+ if not isinstance(job_path, Path):
48
+ msg = "'job_path' must be a pathlib.Path"
49
+ raise TypeError(msg)
50
+ if not isinstance(h5, h5py.Group):
51
+ msg = "'h5' must be a h5py.Group or h5py.File"
52
+ raise TypeError(msg)
53
+
54
+ logger.info(
55
+ "\U0001f680 START Abaqus to ProFACE translator, ver. %s",
56
+ __version__,
57
+ ) # 🚀
58
+
59
+ # compute .fil path
60
+ if "fil" in job.get("input", {}):
61
+ filpth = job_path.parent / job["input"]["fil"]
62
+ else:
63
+ filpth = job_path.with_suffix(".fil")
64
+
65
+ # run translator
66
+ try:
67
+ _pre(filpth=filpth, h5=h5, results=job.get("results", {}))
68
+ except OSError:
69
+ # caller should treat OSError
70
+ raise
71
+ except Exception:
72
+ msg = "Internal Error"
73
+ logger.exception(msg)
74
+ raise AbaqusTranslatorError(msg) from None
75
+ logger.info("\U0001f3c1 END Abaqus to ProFACE translator") # 🏁
76
+
77
+
78
+ def _pre(filpth, h5: h5py.File, results):
79
+ """Abaqus translator"""
80
+
81
+ logger.info("reading %s", filpth.resolve().as_uri())
82
+ logger.info("writing %s", Path(h5.filename).resolve().as_uri())
83
+
84
+ fil = AbqFil(filpth)
85
+
86
+ _write_meta(fil=fil, h5=h5)
87
+ _write_nodal(fil=fil, h5=h5)
88
+ _write_element(fil=fil, h5=h5)
89
+ _write_sets(fil=fil, h5=h5)
90
+
91
+ if not results:
92
+ logger.warning("no results request")
93
+ return
94
+ h5_res = h5.create_group("results")
95
+ for k, v in results.items():
96
+ if "step" not in v or "increment" not in v:
97
+ logger.error(
98
+ "Results request '%s': "
99
+ "both 'step' and 'increment' must be specified.",
100
+ k,
101
+ )
102
+ continue
103
+ _write_results(
104
+ fil=fil,
105
+ h5=h5,
106
+ h5_res=h5_res,
107
+ name=k,
108
+ step=v["step"],
109
+ inc=v["increment"],
110
+ )
111
+
112
+
113
+ def _write_meta(fil, h5):
114
+ #
115
+ # metadata
116
+ #
117
+ logger.info("Abaqus ver. %s", _label(fil.info["ver"]))
118
+ logger.info(
119
+ "Analysis run on %s",
120
+ _label(fil.info["date"]) + " " + _label(fil.info["time"]),
121
+ )
122
+ if fil.heading.strip():
123
+ logger.info("Heading '%s'", _label(fil.heading))
124
+ logger.info("Number of elements: %9d", fil.info["nelm"])
125
+ logger.info("Number of nodes : %9d", fil.info["nnod"])
126
+
127
+ h5.attrs["program"] = "Abaqus"
128
+ h5.attrs["version"] = _label(fil.info["ver"])
129
+ h5.attrs["run_datetime"] = (
130
+ _label(fil.info["date"]) + " " + _label(fil.info["time"])
131
+ )
132
+ h5.attrs["title"] = _label(fil.heading)
133
+
134
+
135
+ def _write_nodal(fil, h5):
136
+ #
137
+ # nodal data
138
+ #
139
+ h5_nodes = h5.create_group("nodes")
140
+ h5_nodes.attrs["number"] = fil.info["nnod"]
141
+ h5_nodes.create_dataset("coordinates", data=fil.coord["coord"])
142
+ h5_nodes.create_dataset("numbers", data=fil.coord["nnum"])
143
+
144
+
145
+ def _write_element(fil, h5):
146
+ #
147
+ # element data
148
+ #
149
+ h5_elements = h5.create_group("elements")
150
+ h5_elements.attrs["number"] = fil.info["nelm"]
151
+ h5_elements.attrs["size"] = fil.info["elsiz"]
152
+ for elbloc in fil.elm:
153
+ assert (elbloc["eltyp"] == elbloc["eltyp"][0]).all()
154
+ eltype = _safe_label(elbloc["eltyp"][0])
155
+ if eltype in h5_elements:
156
+ label_m = _mangle_element_label(eltype, h5_elements.keys())
157
+ logger.warning(
158
+ "Mapping %s \N{RIGHTWARDS ARROW FROM BAR} %s",
159
+ eltype,
160
+ label_m,
161
+ )
162
+ eltype = label_m
163
+ h5_elgroup = h5_elements.create_group(eltype)
164
+ h5_elgroup.create_dataset("incidences", data=elbloc["ninc"])
165
+ h5_elgroup.create_dataset("numbers", data=elbloc["elnum"])
166
+
167
+ h5_elgroup.create_dataset(
168
+ "nodes", data=np.unique(h5_elgroup["incidences"])
169
+ )
170
+
171
+
172
+ def _write_sets(fil, h5):
173
+ #
174
+ # sets
175
+ #
176
+ h5_sets = h5.create_group("sets")
177
+ h5_sets_node = h5_sets.create_group("node")
178
+ for k, nset in fil.nset.items():
179
+ k = _safe_label(fil.label.get(k, k)) # noqa: PLW2901
180
+ h5_sets_node.create_dataset(k, data=nset)
181
+ h5_sets_element = h5_sets.create_group("element")
182
+ for k, elset in fil.elset.items():
183
+ k = _safe_label(fil.label.get(k, k)) # noqa: PLW2901
184
+ h5_sets_element.create_dataset(k, data=elset)
185
+
186
+
187
+ def _write_results(fil, h5, h5_res, name: str, step: int, inc: int) -> None: # noqa: PLR0913
188
+ #
189
+ # results
190
+ #
191
+ try:
192
+ i = _find_step_inc(fil.step, step, inc)
193
+ except ValueError as exc:
194
+ logger.error("Results '%s': %s", name, exc)
195
+ ## fixme: raise error ?
196
+ return
197
+
198
+ logger.info(
199
+ "Results '%s': step %d, increment %d, time %#.3g, '%s'",
200
+ name,
201
+ *fil.step[i][["step", "incr", "ttime"]],
202
+ _label(fil.step[i]["subheading"]),
203
+ )
204
+ h5_k = h5_res.create_group(name)
205
+ h5_k.attrs["step"] = fil.step[i]["step"]
206
+ h5_k.attrs["increment"] = fil.step[i]["incr"]
207
+ h5_k.attrs["time"] = fil.step[i]["ttime"]
208
+
209
+ _write_step_output_blocks(fil, h5, h5_k, i)
210
+
211
+
212
+ def _write_step_output_blocks(fil, h5, h5_k, i): # noqa: C901
213
+ for flag, elset, eltype, data in fil.get_step(i):
214
+ # check block flag: 0 is element output
215
+ if flag != 0:
216
+ logger.warning("Skipping non element output: flag = %d", flag)
217
+ continue
218
+
219
+ # check block elset
220
+ if _label(elset) != "":
221
+ logger.error("Results file with element sets not supported")
222
+ continue
223
+
224
+ # check block element type
225
+ eltype = _safe_label(eltype) # noqa: PLW2901
226
+ if not eltype.startswith("C3D"):
227
+ logger.warning("Results for element %s ignored", eltype)
228
+ continue
229
+
230
+ # check block location
231
+ loc = data["loc"][0]
232
+ assert (data["loc"] == loc).all()
233
+ match ABQ_LOC.get(loc):
234
+ case "integration_point":
235
+ # reshape data to index as [el_num, ip_num]
236
+ nr_ip = _guess_nr_ip(data)
237
+ data = data.reshape(-1, nr_ip) # noqa: PLW2901
238
+ # data["num"] is elnum across columns
239
+ if not np.all(
240
+ data["num"]
241
+ == np.expand_dims(h5["elements"][eltype]["numbers"], -1)
242
+ ):
243
+ msg = f"Inconsistent records for {eltype}: element numbers"
244
+ raise ValueError(msg)
245
+ # data["ipnum"] is 1..nr_ip across rows
246
+ assert np.all(data["ipnum"] == 1 + np.arange(nr_ip))
247
+ case "nodal_averaged":
248
+ if not np.all(data["num"] == h5["elements"][eltype]["nodes"]):
249
+ msg = f"Inconsistent records for {eltype}: node numbers"
250
+ assert (data["ipnum"] == 0).all()
251
+ case None:
252
+ logger.warning("Unknown location code %d", loc)
253
+ continue
254
+
255
+ # save block data
256
+ for name in data.dtype.names:
257
+ if not name.startswith("R"):
258
+ continue
259
+ if name not in ABQ_VAR:
260
+ logger.warning("Unexpected results code %s", name)
261
+ continue
262
+ dset = h5_k.create_dataset(
263
+ _h5_path(var=ABQ_VAR[name], loc=ABQ_LOC[loc], eltype=eltype),
264
+ data=data[name].astype(RES_DTYPE),
265
+ )
266
+ logger.debug("Wrote %s: %s", dset.name, dset.shape)
267
+
268
+
269
+ def _label(lab: bytes) -> str:
270
+ return lab.decode("ASCII").strip()
271
+
272
+
273
+ def _safe_label(lab: bytes) -> str:
274
+ slabel = _label(lab)
275
+ if slabel == ".":
276
+ return "._"
277
+ return slabel.replace("/", "|")
278
+
279
+
280
+ def _mangle_element_label(label: str, groups) -> str:
281
+ assert label in groups
282
+ i = 1
283
+ for s in groups:
284
+ if s.startswith(f"{label:s}@"):
285
+ i += 1
286
+ mangled = f"{label:2}@{i:d}"
287
+ assert mangled not in groups
288
+ return mangled
289
+
290
+
291
+ def _find_step_inc(stepdata, step, inc):
292
+ """search for requested step/increment"""
293
+
294
+ if len(stepdata) == 0:
295
+ msg = "no stepdata in file"
296
+ raise ValueError(msg)
297
+ logger.debug("Requested: Step %d, increment %d", step, inc)
298
+ if step > 0 and step not in stepdata["step"]:
299
+ # explicit request of inesistent step
300
+ msg = f"step '{step}' not found"
301
+ raise ValueError(msg)
302
+ if step == 0:
303
+ # last step requested
304
+ step = stepdata["step"][-1]
305
+
306
+ c_step = stepdata[stepdata["step"] == step]
307
+ if inc > 0 and inc not in c_step["incr"]:
308
+ # explicit request for inesistent increment
309
+ msg = f"increment '{inc}' not found in step '{step}'"
310
+ raise ValueError(msg)
311
+ if inc == 0:
312
+ # last increment requested
313
+ inc = c_step["incr"][-1]
314
+
315
+ assert stepdata.ndim == 1
316
+ (i,) = np.nonzero((stepdata["step"] == step) & (stepdata["incr"] == inc))
317
+ assert np.shape(i) == (1,), f"Multiple step blocks found: {i}"
318
+ i = i.item()
319
+
320
+ logger.debug("Found: Step %d, increment %d at position %s", step, inc, i)
321
+ assert stepdata[i][["step", "incr"]].item() == (step, inc)
322
+ return i
323
+
324
+
325
+ def _guess_nr_ip(data):
326
+ """heuristics to find the number of integration points
327
+ for a loc 0 (integration points) record"""
328
+
329
+ # assumption is that number of ip's is smallish
330
+ num = data["num"]
331
+ for i, v in enumerate(num):
332
+ if v != num[0]:
333
+ return i
334
+
335
+ # edge case: record contains a single element
336
+ assert np.all(num == num[0])
337
+ return len(data)