Skip to content

Commit

Permalink
test: check all commands are submitted (#3501)
Browse files Browse the repository at this point in the history
* test: increasing testing by testing all MAPDL commands

* test: test command name in output.

* refactor: parse module and adding new functions to externalise to this module command output.

* refactor: externalising parsing to parse module

* fix: cmwrite command

* fix: small fix

* chore: improve pytest default configuration

* chore: adding changelog file 3501.added.md [dependabot-skip]

* refactor: removing unused variable

* chore: adding changelog file 3501.added.md [dependabot-skip]

* test: including `_commands` in coverage

* tests: including tests

* fix: docstring

---------

Co-authored-by: pyansys-ci-bot <[email protected]>
  • Loading branch information
germa89 and pyansys-ci-bot authored Oct 25, 2024
1 parent 76b7cf2 commit 88b8f14
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 233 deletions.
1 change: 0 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ignore:
- "src/ansys/mapdl/core/_commands"
- "src/ansys/mapdl/core/jupyter.py"
- "src/ansys/mapdl/core/mapdl_console.py"
- "src/ansys/mapdl/core/mapdl_inprocess.py"
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/3501.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test: check all commands are submitted
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ pymapdl_convert_script = "ansys.mapdl.core.cli:old_pymapdl_convert_script_entry_
pymapdl = "ansys.mapdl.core.cli:main"

[tool.pytest.ini_options]
addopts = "-ra -vvv --maxfail=10"
addopts = "-rxXsa -vvv --maxfail=10"
junit_family = "legacy"
filterwarnings = [
"ignore::FutureWarning",
Expand Down
4 changes: 2 additions & 2 deletions src/ansys/mapdl/core/_commands/apdl/parameter_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def get(
command = f"*GET,{par},{entity},{entnum},{item1},{it1num},{item2},{it2num}"
return self.run(command, **kwargs)

def inquire(self, strarray="", func="", arg1="", arg2=""):
def inquire(self, strarray="", func="", arg1="", arg2="", **kwargs):
"""Returns system information.
By default, with no arguments, it returns the working directory.
Expand Down Expand Up @@ -489,7 +489,7 @@ def inquire(self, strarray="", func="", arg1="", arg2=""):
>>> mapdl.inquire('', 'RSTFILE')
'file.rst'
"""
return self.run(f"/INQUIRE,{strarray},{func},{arg1},{arg2}")
return self.run(f"/INQUIRE,{strarray},{func},{arg1},{arg2}", **kwargs)

def parres(self, lab="", fname="", ext="", **kwargs):
"""Reads parameters from a file.
Expand Down
186 changes: 18 additions & 168 deletions src/ansys/mapdl/core/_commands/database/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,185 +495,35 @@ def cmsel(

def cmwrite(
self,
option: str = "",
fname: str = "",
ext: str = "",
fnamei: str = "",
exti: str = "",
fmat: str = "",
**kwargs: Dict[Any, Any],
) -> None:
) -> str:
"""Writes node and element components and assemblies to a file.
APDL Command: CMWRITE
Parameters
----------
option
Selects which data to write:
Fname
File name and directory path (248 characters maximum, including the
characters needed for the directory path). An unspecified directory
path defaults to the working directory; in this case, you can use
all 248 characters for the file name.
The file name defaults to ``Jobname``.
Ext
Filename extension (eight-character maximum).
The extension defaults to ``CM`` if ``fname`` is blank.
ALL
Write all appropriate geometry, material property,
load, and component data (default). Two files will
be produced. ``Fname.Ext`` will contain all data items
mentioned in "Notes", except the solid model
data. Fnamei.Exti will contain the solid model
geometry and solid model loads data in the form of
IGES commands. This option is not valid when
CDOPT,ANF is active.
COMB
Write all data mentioned, but to a single file,
``Fname.Ext``. Solid model geometry data will be
written in either IGES or ANF format as specified
in the CDOPT command, followed by the remainder of
the data in the form of ANSYS commands. More
information on these (IGES/ANF) file formats is
provided in "Notes".
DB
Write all database information except the solid model
and solid model loads to ``Fname.Ext`` in the form of
ANSYS commands. This option is not valid when
CDOPT,ANF is active.
SOLID
Write only the solid model geometry and solid
model load data. This output will be in IGES or
ANF format, as specified in the CDOPT
command. More information on these (IGES/ANF) file
formats is provided in "Notes".
GEOM
Write only element and nodal geometry data. Neither
solid model geometry nor element attribute data
will be written. One file, ``Fname.Ext``, will be
produced. Use CDREAD,DB to read in a file written
with this option. Element types [ET] compatible
with the connectivity of the elements on the file
must first be defined before reading the file in
with CDREAD,DB.
CM
Write only node and element component and geometry
data to ``Fname.Ext``.
MAT
Write only material property data (both linear and
nonlinear) to ``Fname.Ext`` .
LOAD
Write only loads for current load step to
``Fname.Ext``.
SECT
Write only section data to ``Fname.Ext``. Pretension
sections are not included.
fname
File name and directory path (248 characters maximum,
including the characters needed for the directory path).
An unspecified directory path defaults to the working
directory; in this case, you can use all 248 characters
for the file name.
ext
Filename extension (eight-character maximum). The
extension defaults to CDB if Fname is blank.
fnamei
Name of the IGES file and its directory path (248
characters maximum, including directory). If you do not
specify a directory path, it will default to your working
directory and you can use all 248 characters for the file
name.
The file name defaults to Fname. Used only if
Option = ALL or SOLID. Previous data on this file, if any,
is overwritten.
Exti
Filename extension (eight-character maximum). The
extension defaults to IGES in all cases, except when
CDOPT,ANF is active and CDWRITE, Option = SOLID. In this
case Exti = ANF.
fmat
Format of the output file (defaults to BLOCKED).
BLOCKED
Blocked format. This format allows faster
reading of the output file. The time savings is
most significant when BLOCKED is used to read
.cdb files associated with very large models.
UNBLOCKED
Unblocked format.
Fmat
Format of the output file (defaults to ``BLOCKED``).
* ``BLOCKED``: Blocked format. This format allows faster
reading of the file.
* ``UNBLOCKED``: Unblocked format.
Notes
-----
Load data includes the current load step only. Loads applied
to the solid model (if any) are automatically transferred to
the finite element model when this command is issued. ``CDWRITE``
writes out solid model loads for meshed models only. If the
model is not meshed, the solid model loads cannot be
saved. Component data include component definitions, but not
assembly definitions. Appropriate ``NUMOFF`` commands are included
at the beginning of the file; this is to avoid overlap of an
existing database when the file is read in.
Solution control commands are typically not written to the
file unless you specifically change a default solution
setting.
``CDWRITE`` does not support the ``GSBDATA`` and ``GSGDATA`` commands, and
these commands are not written to the file.
The data may be reread (on a different machine, for example)
with the ``CDREAD`` command. Caution: When the file is read in,
the ``NUMOFF,MAT`` command may cause a mismatch between material
definitions and material numbers referenced by certain loads
and element real constants. See ``NUMOFF`` for details. Also, be
aware that the files created by the ``CDWRITE`` command explicitly
set the active coordinate system to Cartesian (CSYS,0).
You should generally use the blocked format (Fmat = BLOCKED)
when writing out model data with ``CDWRITE``. This is a compressed
data format that greatly reduces the time required to read
large models through the CDREAD command. The blocked and
unblocked formats are described in Chapter 3 of the Guide to
Interfacing with ANSYS.
If you use ``CDWRITE`` in any of the derived products (ANSYS
Mechanical Pro, ANSYS Mechanical Premium), then before reading
the file, you must edit the Jobname.cdb file to remove
commands that are not available in the respective component
product.
The ``CDWRITE`` command writes PART information for any ANSYS
LS-DYNA input file to the Jobname.cdb file via the EDPREAD
command. (EDPREAD is not a documented command; it is written
only when the ``CDWRITE`` command is issued.) The PART information
can be automatically read in via the CDREAD command; however,
if more than one Jobname.cdb file is read, the PART list from
the last Jobname.cdb file overwrites the existing PART list of
the total model. This behavior affects all PART-related
commands contained in the Jobname.cdb file. You can join
models, but not PART-related inputs, which you must modify
using the newly-created PART numbers. In limited cases, an
update of the PART list (EDWRITE,PUPDATE) is possible; doing
so requires that no used combination of MAT/TYPE/REAL appears
more than once in the list.
The ``CDWRITE`` command does not support (for beam meshing) any
line operation that relies on solid model associativity. For
example, meshing the areas adjacent to the meshed line,
plotting the line that contains the orientation nodes, or
clearing the mesh from the line that contains orientation
nodes may not work as expected. For more information about
beam meshing, see Meshing Your Solid Model in the Modeling and
Meshing Guide.
"""
command = f"CDWRITE,{option},{fname},{ext},,{fnamei},{exti},{fmat}"
command = f"CMWRITE,{fname},{ext},,,{fmat}"
return self.run(command, **kwargs)
58 changes: 47 additions & 11 deletions src/ansys/mapdl/core/_commands/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
NUM_PATTERN = re.compile(NUMERIC_CONST_PATTERN, re.VERBOSE)


def parse_kdist(msg):
def parse_kdist(msg: Optional[str] = None) -> Optional[int]:
"""Parse the keypoint value from a keypoint message"""
finds = re.findall(NUM_PATTERN, msg)[-4:]
if len(finds) == 4:
return [float(val) for val in finds]


def parse_et(msg: Optional[str]) -> Optional[int]:
def parse_et(msg: Optional[str] = None) -> Optional[int]:
"""Parse local element type number definition message
and return element type number.
"""
Expand All @@ -56,23 +56,35 @@ def parse_et(msg: Optional[str]) -> Optional[int]:
return int(res.group(2))


def parse_e(msg: Optional[str]) -> Optional[int]:
def parse_e(msg: Optional[str] = None) -> Optional[int]:
"""Parse create element message and return element number."""
if msg:
res = re.search(r"(ELEMENT\s*)([0-9]+)", msg)
if res is not None:
return int(res.group(2))


def parse_kpoint(msg):
def parse_k(msg: Optional[str] = None) -> Optional[int]:
"""Parse output from ``K`` command"""
if msg:
if not re.search(r"KEYPOINT NUMBER", msg):
res = re.search(r"(KEYPOINT\s*)([0-9]+)", msg)
else:
res = re.search(r"(KEYPOINT NUMBER =\s*)([0-9]+)", msg)

if res:
return int(res.group(2))


def parse_kpoint(msg: Optional[str] = None) -> Optional[int]:
"""Parse create keypoint message and return keypoint number."""
if msg:
res = re.search(r"kpoint=\s+(\d+)\s+", msg)
if res is not None:
return int(res.group(1))


def parse_output_areas(msg):
def parse_output_areas(msg: Optional[str] = None) -> Optional[int]:
"""Parse create area message and return area number."""
if msg:
res = re.search(r"(OUTPUT AREAS =\s*)([0-9]+)", msg)
Expand All @@ -83,47 +95,71 @@ def parse_output_areas(msg):
return int(res.group(2))


def parse_a(msg):
def parse_a(msg: Optional[str] = None) -> Optional[int]:
"""Parse create area message and return area number."""
if msg:
res = re.search(r"(AREA NUMBER =\s*)([0-9]+)", msg)
if res is not None:
return int(res.group(2))


def parse_line_no(msg):
def parse_line_no(msg: Optional[str] = None) -> Optional[int]:
"""Parse create line message and return line number."""
if msg:
res = re.search(r"LINE NO[.]=\s+(\d+)", msg)
if res is not None:
return int(res.group(1))


def parse_line_nos(msg):
def parse_line_nos(msg: Optional[str] = None) -> Optional[int]:
if msg:
matches = re.findall(r"LINE NO[.]=\s*(\d*)", msg)
if matches:
return [int(match) for match in matches]


def parse_v(msg):
def parse_v(msg: Optional[str] = None) -> Optional[int]:
"""Parse volume message and return volume number"""
if msg:
res = re.search(r"(VOLUME NUMBER =\s*)([0-9]+)", msg)
if res is not None:
return int(res.group(2))


def parse_output_volume_area(msg):
def parse_output_volume_area(msg: Optional[str] = None) -> Optional[int]:
"""Parse create area message and return area or volume number"""
if msg:
res = re.search(r"OUTPUT (AREA|VOLUME|AREAS) =\s*([0-9]+)", msg)
if res is not None:
return int(res.group(2))


def parse_ndist(msg):
def parse_n(msg: Optional[str] = None) -> Optional[int]:
"""Parse output of ``N``"""
if msg:
res = re.search(r"(NODE\s*)([0-9]+)", msg)
if res is not None:
return int(res.group(2))


def parse_ndist(msg: Optional[str] = None) -> Optional[int]:
"""Parse the node value from a node message"""
finds = re.findall(NUM_PATTERN, msg)[-4:]
if len(finds) == 4:
return [float(val) for val in finds]


def parse_kl(msg: Optional[str] = None) -> Optional[int]:
"""Parse the output of ``KL``."""
if msg:
res = re.search(r"KEYPOINT\s+(\d+)\s+", msg)
if res is not None:
return int(res.group(1))


def parse_knode(msg: Optional[str] = None) -> Optional[int]:
"""Parse the output of ``KNODE``."""
if msg:
res = re.search(r"KEYPOINT NUMBER =\s+(\d+)", msg)
if res is not None:
return int(res.group(1))
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/_commands/post1_/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -1911,7 +1911,7 @@ def prcamp(
Distributed ANSYS Restriction: This command is not supported in
Distributed ANSYS.
"""
command = f"PRCAMP,{option},{slope},{unit},{freqb},{cname},{stabval},{keyallfreq},{keynegfreq}"
command = f"PRCAMP,{option},{slope},{unit},{freqb},{cname},{stabval},{keyallfreq},{keynegfreq},{keywhirl}"
return self.run(command, **kwargs)

def prfar(
Expand Down
Loading

0 comments on commit 88b8f14

Please sign in to comment.