-
Notifications
You must be signed in to change notification settings - Fork 220
FEAT: add fields calc expressions and update fields distribution extension #6996
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
Merged
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
8a5e1aa
add fields calc expressions
gmalinve aeca325
chore: adding changelog file 6996.added.md [dependabot-skip]
pyansys-ci-bot f7864f9
chore: adding changelog file 6996.added.md [dependabot-skip]
pyansys-ci-bot 08555ec
add tests
gmalinve 675ef8c
add system tests
gmalinve 916506e
Merge branch 'refs/heads/main' into feat/get_fields_expressions
gmalinve d486f9f
add mock test fields calc write
gmalinve 4822613
mock tests fields calc.
gmalinve c0fddee
leverage Path instead of os.path + move tests
gmalinve ccaf030
Merge branch 'refs/heads/main' into feat/get_fields_expressions
gmalinve d497917
update new API in fields dist. extension
gmalinve 42dae28
update new API in fields dist. extension
gmalinve 66aa7cc
fix load expressions fields calc.
gmalinve b78648d
Merge branch 'refs/heads/main' into feat/get_fields_expressions
gmalinve affb4c2
Update src/ansys/aedt/core/visualization/post/fields_calculator.py
gmalinve 58efb5c
Update src/ansys/aedt/core/visualization/post/fields_calculator.py
gmalinve b350f07
Update src/ansys/aedt/core/visualization/post/fields_calculator.py
gmalinve ab3156e
CHORE: Auto fixes from pre-commit hooks
pre-commit-ci[bot] 658d817
Update tests/system/visualization/test_fields_calculator.py
gmalinve fb7fa13
CHORE: Auto fixes from pre-commit hooks
pre-commit-ci[bot] 48e5387
Merge branch 'refs/heads/main' into feat/get_fields_expressions
gmalinve 6d9a04b
code review UTs
gmalinve f37a079
fix failing tests mock aedt version
gmalinve a91df91
fix indent
gmalinve 8d6f750
code review
gmalinve 43778b9
first failing test
gmalinve 1e1b2f9
Merge branch 'refs/heads/main' into feat/get_fields_expressions
gmalinve e4ebd5b
code review
gmalinve b4bf7d9
Update tests/unit/test_fields_calculator.py
gmalinve 3ce879a
API change in 2026.1
gmalinve 20bb4f2
Merge remote-tracking branch 'origin/feat/get_fields_expressions' int…
gmalinve f9361a6
Update tests/unit/test_fields_calculator.py
gmalinve ff3f64f
Update tests/unit/test_fields_calculator.py
gmalinve d2c9802
Update tests/unit/test_fields_calculator.py
gmalinve a5efd8e
Update tests/unit/test_fields_calculator.py
gmalinve 50c87d2
Merge remote-tracking branch 'origin/feat/get_fields_expressions' int…
gmalinve 2783fee
CHORE: Auto fixes from pre-commit hooks
pre-commit-ci[bot] ff556b1
Merge remote-tracking branch 'origin/feat/get_fields_expressions' int…
gmalinve 634df56
API change in 2026.1
gmalinve 3e14750
comment review
gmalinve de67aa4
Update tests/unit/test_fields_calculator.py
gmalinve 8c88740
Merge branch 'main' into feat/get_fields_expressions
gmalinve 244c300
improve code cov
gmalinve 5558017
Update tests/unit/test_fields_calculator.py
gmalinve e6c0ac2
mock patch
gmalinve f0ca145
Merge branch 'refs/heads/main' into feat/get_fields_expressions
gmalinve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| Add fields calc expressions and update fields distribution extension |
This file contains hidden or 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 hidden or 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 hidden or 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,121 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # | ||
| # Copyright (C) 2021 - 2026 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 pytest | ||
|
|
||
| from ansys.aedt.core import Hfss | ||
| from tests.conftest import DESKTOP_VERSION | ||
|
|
||
| test_subfolder = "fields_calculator" | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def aedtapp(add_app): | ||
| app = add_app(application=Hfss) | ||
| yield app | ||
| app.close_project(app.project_name) | ||
|
|
||
|
|
||
| def test_add_expressions(aedtapp): | ||
| """Test adding custom field calculator expressions.""" | ||
| poly = aedtapp.modeler.create_polyline([[0, 0, 0], [1, 0, 1]], name="Polyline1") | ||
| my_expression = { | ||
| "name": "test", | ||
| "description": "Voltage drop along a line", | ||
| "design_type": ["HFSS", "Q3D Extractor"], | ||
| "fields_type": ["Fields", "CG Fields"], | ||
| "solution_type": "", | ||
| "primary_sweep": "Freq", | ||
| "assignment": "", | ||
| "assignment_type": ["Line"], | ||
| "operations": [ | ||
| "Fundamental_Quantity('E')", | ||
| "Operation('Real')", | ||
| "Operation('Tangent')", | ||
| "Operation('Dot')", | ||
| "EnterLine('assignment')", | ||
| "Operation('LineValue')", | ||
| "Operation('Integrate')", | ||
| "Operation('CmplxR')", | ||
| ], | ||
| "report": ["Data Table", "Rectangular Plot"], | ||
| } | ||
| expr_name = aedtapp.post.fields_calculator.add_expression(my_expression, poly.name) | ||
| assert isinstance(expr_name, str) | ||
| assert expr_name == "test" | ||
|
|
||
|
|
||
| def test_expression_plot(aedtapp): | ||
| """Test creating plots from field calculator expressions.""" | ||
| aedtapp.modeler.create_polyline([[0, 0, 0], [1, 0, 1]], name="Polyline1") | ||
| aedtapp.create_setup() | ||
| expr_name = aedtapp.post.fields_calculator.add_expression("voltage_line", "Polyline1") | ||
| reports = aedtapp.post.fields_calculator.expression_plot("voltage_line", "Polyline1", [expr_name]) | ||
| assert reports | ||
| assert aedtapp.post.plots | ||
| assert reports == aedtapp.post.plots | ||
| assert reports[0].expressions == ["Voltage_Line"] | ||
|
|
||
|
|
||
| def test_delete_expression(aedtapp): | ||
| """Test deleting named expressions from the fields calculator.""" | ||
| poly = aedtapp.modeler.create_polyline([[0, 0, 0], [1, 0, 1]], name="Polyline1") | ||
| expr_name = aedtapp.post.fields_calculator.add_expression("voltage_line", poly.name) | ||
| aedtapp.post.fields_calculator.delete_expression(expr_name) | ||
| aedtapp.post.fields_calculator.delete_expression() | ||
|
|
||
|
|
||
| def test_is_expression_defined(aedtapp): | ||
| """Test checking if a named expression exists in the fields calculator.""" | ||
| aedtapp.modeler.create_polyline([[0, 0, 0], [1, 0, 1]], name="Polyline1") | ||
| aedtapp.create_setup() | ||
| assert not aedtapp.post.fields_calculator.is_expression_defined("Voltage_Line") | ||
| expr_name = aedtapp.post.fields_calculator.add_expression("voltage_line", "Polyline1") | ||
| assert aedtapp.post.fields_calculator.is_expression_defined(expr_name) | ||
|
|
||
|
|
||
| def test_is_general_expression(aedtapp): | ||
| """Test identifying general vs. assignment-specific expressions.""" | ||
| aedtapp.modeler.create_polyline([[0, 0, 0], [1, 0, 1]], name="Polyline1") | ||
| aedtapp.create_setup() | ||
| assert not aedtapp.post.fields_calculator.is_general_expression("invalid") | ||
| assert not aedtapp.post.fields_calculator.is_general_expression("voltage_line") | ||
| assert aedtapp.post.fields_calculator.is_general_expression("voltage_drop") | ||
|
|
||
|
|
||
| def test_validate_expression(aedtapp): | ||
| """Test expression validation against the schema.""" | ||
| assert not aedtapp.post.fields_calculator.validate_expression("invalid") | ||
|
|
||
|
|
||
| @pytest.mark.skipif(DESKTOP_VERSION < "2026.1", reason="Native API method only available from AEDT 2026.1 onwards.") | ||
| def test_get_expressions(aedtapp): | ||
| """Test deleting named expressions from the fields calculator.""" | ||
| poly = aedtapp.modeler.create_polyline([[0, 0, 0], [1, 0, 1]], name="Polyline1") | ||
| expressions = aedtapp.post.fields_calculator.get_expressions() | ||
| assert "Voltage_Line" not in list(expressions.keys()) | ||
| aedtapp.post.fields_calculator.add_expression("voltage_line", poly.name) | ||
| expressions = aedtapp.post.fields_calculator.get_expressions() | ||
| assert "Voltage_Line" in list(expressions.keys()) |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.