generated from ansys/template
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 707-support-for-multiple-row-entries-in-mat_196
- Loading branch information
Showing
12 changed files
with
538 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
feat: Start to handle *INCLUDE_TRANSFORM in Deck.expand() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
"""Import handler used by the import deck feature""" | ||
|
||
import dataclasses | ||
import typing | ||
import warnings | ||
|
||
from ansys.dyna.core.lib.keyword_base import KeywordBase | ||
|
||
|
||
@dataclasses.dataclass | ||
class ImportContext: | ||
"""Optional transformation to apply, using type `IncludeTransform`""" | ||
|
||
xform: typing.Any = None | ||
|
||
"""Deck into which the import is occurring.""" | ||
deck: typing.Any = None | ||
|
||
"""Path of file that is importing.""" | ||
path: str = None | ||
|
||
|
||
class ImportHandler: | ||
"""Base class for import handlers.""" | ||
|
||
def before_import(self, context: ImportContext, keyword: str, buffer: typing.TextIO): | ||
"""Event called before reading a keyword. | ||
`keyword` is the string label of the keyword | ||
`buffer` is a copy of the buffer to read from. | ||
Usage: | ||
Return True if the keyword is to be imported as usual. | ||
Return False if the keyword is not to be imported. | ||
""" | ||
return True | ||
|
||
def after_import(self, context: ImportContext, keyword: typing.Union[str, KeywordBase]): | ||
"""Event called after a keyword is imported. | ||
`keyword` is the imported keyword. It could be a string or a keyword object | ||
Depending on the `context` is a | ||
""" | ||
pass | ||
|
||
def on_error(self, error): | ||
# TODO - use logging | ||
warnings.warn(f"error in importhandler {self}: {error}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
"""Transformation handler for INCLUDE_TRANSFORM.""" | ||
import typing | ||
import warnings | ||
|
||
from ansys.dyna.core.lib.import_handler import ImportContext, ImportHandler | ||
from ansys.dyna.core.lib.keyword_base import KeywordBase | ||
from ansys.dyna.core.lib.transforms.base_transform import Transform | ||
from ansys.dyna.core.lib.transforms.element_transform import TransformElement | ||
from ansys.dyna.core.lib.transforms.node_transform import TransformNode | ||
|
||
|
||
class TransformHandler(ImportHandler): | ||
def __init__(self): | ||
self._handlers: typing.Dict[typing.Union[str, typing.Tuple[str, str]], Transform] = { | ||
"NODE": TransformNode, | ||
"ELEMENT": TransformElement, | ||
} | ||
|
||
def register_transform_handler( | ||
self, identity: typing.Union[str, typing.Tuple[str, str]], handler: Transform | ||
) -> None: | ||
self._handlers[identity] = handler | ||
|
||
def after_import(self, context: ImportContext, keyword: typing.Union[KeywordBase, str]) -> None: | ||
if isinstance(keyword, str): | ||
return | ||
if context.xform is None: | ||
return | ||
print(self._handlers.keys()) | ||
# first try to get the specialized handler for the keyword + subkeyword | ||
identity = (keyword.keyword, keyword.subkeyword) | ||
handler = self._handlers.get(identity, None) | ||
if handler is None: | ||
# then try to get the handler for the keyword | ||
identity = keyword.keyword | ||
handler = self._handlers.get(identity, None) | ||
if handler is None: | ||
warnings.warn() | ||
return | ||
|
||
# if a handler was found, initialize it with the xform from the context | ||
# and transform the keyword with it | ||
handler(context.xform).transform(keyword) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright (C) 2021 - 2024 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
|
||
"""Base Transform class.""" | ||
|
||
from ansys.dyna.core import keywords as kwd | ||
|
||
|
||
class Transform: | ||
def __init__(self, xform: kwd.IncludeTransform): | ||
self._xform: kwd.IncludeTransform = xform | ||
|
||
def transform(self, keyword) -> None: | ||
raise Exception("Implementation required for transform") |
Oops, something went wrong.