Skip to content

feat: add rpsd method to MapdlGrpc for variable retrieval as an array#4114

Merged
germa89 merged 2 commits intomainfrom
feat/extracting-numpy-array-from-rpsd
Jul 22, 2025
Merged

feat: add rpsd method to MapdlGrpc for variable retrieval as an array#4114
germa89 merged 2 commits intomainfrom
feat/extracting-numpy-array-from-rpsd

Conversation

@germa89
Copy link
Collaborator

@germa89 germa89 commented Jul 21, 2025

Description

As the title.

It allows to do:

>>> arr = mapdl.rpsd(3, 2, "", 1, 2)
>>> print(arr)
array([[5.75589860e-06],
       [5.79347209e-06],
       [5.86774837e-06],
       [5.98084878e-06]
...

Issue linked

Related to #3865 so we can facilitate PSD related works.

Checklist

Copilot AI review requested due to automatic review settings July 21, 2025 18:15
@germa89 germa89 requested a review from a team as a code owner July 21, 2025 18:15
@ansys-reviewer-bot
Copy link
Contributor

Thanks for opening a Pull Request. If you want to perform a review write a comment saying:

@ansys-reviewer-bot review

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jul 21, 2025

Reviewer's Guide

Adds an rpsd wrapper in MapdlGrpc to retrieve power spectral density variables as numpy arrays, alongside a dedicated pytest fixture and unit test to validate the new functionality.

Class diagram for the new rpsd method in MapdlGrpc

classDiagram
    class MapdlBase {
        +rpsd(ir, ia, ib, itype, datum, name, signif, **kwargs)
    }
    class MapdlGrpc {
        +rpsd(ir, ia, ib, itype, datum, name, signif, **kwargs) NDArray[np.float64]
        +vget(varname, index)
    }
    MapdlGrpc --|> MapdlBase
    MapdlGrpc : +rpsd overrides MapdlBase.rpsd
    MapdlGrpc : +rpsd returns numpy array
Loading

File-Level Changes

Change Details Files
Implement rpsd method in MapdlGrpc to return array data
  • Added rpsd signature matching MapdlBase.rpsd
  • Invoked super().rpsd with all parameters
  • Returned results via self.vget("_temp", ir)
src/ansys/mapdl/core/mapdl_grpc.py
Add unit test for the rpsd command
  • Entered post26() mode before PSD retrieval
  • Called mapdl.rpsd and asserted output is numpy.ndarray
  • Checked output shape for expected dimensions
tests/test_mapdl.py
Introduce psd_analysis fixture for PSD setup in tests
  • Defined psd_analysis fixture with scope 'function'
  • Imported vmfiles["vm203"] for example input
  • Applied mapdl.input(vmfiles["vm203"]) to initialize PSD analysis
tests/conftest.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new rpsd method to the MapdlGrpc class that wraps the MAPDL RPSD command and returns the result as a numpy array, making it more convenient for Python users to work with power spectral density analysis results.

  • Adds rpsd method wrapper to MapdlGrpc class that returns numpy arrays instead of raw MAPDL output
  • Includes test coverage with a PSD analysis fixture
  • Follows the established pattern of other wrapped methods like esol

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/ansys/mapdl/core/mapdl_grpc.py Adds the rpsd method wrapper that calls the parent method and returns results via vget
tests/conftest.py Adds psd_analysis fixture using vm203 example for testing
tests/test_mapdl.py Adds test case for the new rpsd method

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @germa89 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/ansys/mapdl/core/mapdl_grpc.py:3294` </location>
<code_context>
         return self.vget("_temp", nvar)

+    @wraps(MapdlBase.rpsd)
+    def rpsd(
+        self,
+        ir: str = "",
+        ia: str = "",
+        ib: str = "",
+        itype: int | str = "",
+        datum: int | str = "",
+        name: str = "",
+        signif: str = "",
+        **kwargs,
+    ) -> NDArray[np.float64]:
+        """Wraps RPSD to return the variable as an array."""
</code_context>

<issue_to_address>
Default argument values may not align with expected RPSD usage.

Defaulting 'itype' and 'datum' to empty strings, despite their int | str type hints, may lead to type errors. Using None as the default and handling type checks inside the method is recommended.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@github-actions github-actions bot added the new feature Request or proposal for a new feature label Jul 21, 2025
@germa89 germa89 self-assigned this Jul 21, 2025
@codecov
Copy link

codecov bot commented Jul 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.40%. Comparing base (f021ab2) to head (7dc051b).
Report is 8 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4114   +/-   ##
=======================================
  Coverage   91.39%   91.40%           
=======================================
  Files         189      189           
  Lines       15667    15671    +4     
=======================================
+ Hits        14319    14324    +5     
+ Misses       1348     1347    -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@germa89
Copy link
Collaborator Author

germa89 commented Jul 22, 2025

@pyansys-ci-bot LGTM.

Copy link
Contributor

@pyansys-ci-bot pyansys-ci-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approving this PR because germa89 said so in here 😬

LGTM

@germa89 germa89 merged commit fe772a2 into main Jul 22, 2025
85 of 87 checks passed
@germa89 germa89 deleted the feat/extracting-numpy-array-from-rpsd branch July 22, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

new feature Request or proposal for a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants