Skip to content

Commit bd80c49

Browse files
committed
merge with main; bump to v0.61.1
2 parents 6feaebc + 4822d49 commit bd80c49

File tree

16 files changed

+353
-62
lines changed

16 files changed

+353
-62
lines changed

doc/source/404.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
:orphan:
2+
3+
Oops!
4+
=====
5+
6+
7+
This is unexpected.
8+
9+
10+
The page you are requesting does not exist.

doc/source/conf.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@
9797
r"\.*MeshGrpc\.*",
9898
}
9999

100+
# Favicon
101+
html_favicon = "favicon.png"
102+
103+
# notfound.extension
104+
notfound_template = "404.rst"
105+
notfound_urls_prefix = "/../"
106+
107+
100108
# static path
101109
html_static_path = ["_static"]
102110

doc/source/favicon.png

6.5 KB
Loading

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
55
[project]
66
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
77
name = "ansys-mapdl-core"
8-
version = "0.61.0"
8+
version = "0.61.1"
99
description = "A Python wrapper for Ansys mapdl core"
1010
readme = "README.rst"
1111
requires-python = ">=3.7"
@@ -17,9 +17,9 @@ maintainers = [
1717
{name = "PyAnsys developers", email = "[email protected]"},
1818
]
1919
dependencies = [
20-
"ansys-api-mapdl-v0==0.4.1", # supports at least 2020R2 - 2021R2
20+
"ansys-api-mapdl==0.5.1", # supports at least 2020R2 - 2022R1
2121
"ansys-corba; python_version < '3.9'",
22-
"ansys-mapdl-reader>=0.50.15",
22+
"ansys-mapdl-reader>=0.51.7",
2323
"appdirs>=1.4.0",
2424
"grpcio>=1.30.0", # tested up to grpcio==1.35
2525
"importlib-metadata >=4.0",

requirements/requirements_docs.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Sphinx==4.4.0
2-
ansys-mapdl-reader==0.51.3 # newer breaks doc build
2+
ansys-mapdl-reader==0.51.11
33
imageio-ffmpeg==0.4.5
44
imageio==2.16.1
55
jupyter_sphinx==0.3.2
@@ -9,7 +9,7 @@ numpydoc==1.2
99
pandas==1.4.1
1010
plotly==5.6.0
1111
pyansys_sphinx_theme==0.2.3
12-
pypandoc==1.7.2
12+
pypandoc==1.7.4
1313
pytest-sphinx==0.3.1
1414
pythreejs==2.3.0
1515
pyvista==0.33.3
@@ -21,4 +21,4 @@ sphinx-notfound-page==0.8
2121
sphinxcontrib-websupport==1.2.4
2222
sphinxemoji==0.2.0
2323
vtk==9.0.3
24-
grpcio==1.43.0
24+
grpcio==1.43.0

requirements/requirements_tests.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
autopep8==1.6.0
22
matplotlib==3.5.1
33
pandas==1.4.1
4-
pytest==7.0.1
4+
pytest==7.1.1
55
pytest-cov==3.0.0
66
pyvista==0.33.3
77
scipy==1.8.0

src/ansys/mapdl/core/_commands/preproc/materials.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,12 @@ def mpread(self, fname="", ext="", lib="", **kwargs):
691691
----------
692692
fname
693693
File name and directory path (248 characters maximum,
694-
including directory). If you do not specify the LIB
694+
including directory). If you do not specify the ``LIB``
695695
option, the default directory is the current working
696-
directory. If you specify the LIB option, the default is
696+
directory. If you specify the ``LIB`` option, the default is
697697
the following search path: the current working directory,
698-
the user's home directory, MPLIB_DIR (as specified by the
699-
/MPLIB,READ,PATH command) and /ansys_dir/matlib (as
698+
the user's home directory, ``MPLIB_DIR`` (as specified by the
699+
``/MPLIB,READ,PATH`` command) and ``/ansys_dir/matlib`` (as
700700
defined by installation). If you use the default for your
701701
directory, you can use all 248 characters for the file
702702
name.
@@ -706,25 +706,25 @@ def mpread(self, fname="", ext="", lib="", **kwargs):
706706
707707
lib
708708
Reads material library files previously written with the
709-
MPWRITE command. (See the description of the LIB option
710-
for the MPWRITE command.) The only allowed value for LIB
711-
is LIB.
709+
MPWRITE command. (See the description of the ``LIB`` option
710+
for the ``MPWRITE`` command.) The only allowed value for ``LIB``
711+
is ``LIB``.
712712
713713
Notes
714714
-----
715-
Material properties written to a file without the LIB option
715+
Material properties written to a file without the ``LIB`` option
716716
do not support nonlinear properties. Also, properties written
717-
to a file without the LIB option are restored in the same
717+
to a file without the ``LIB`` option are restored in the same
718718
material number as originally defined. To avoid errors, use
719-
MPREAD with the LIB option only when reading files written
720-
using MPWRITE with the LIB option.
719+
``MPREAD`` with the ``LIB`` option only when reading files written
720+
using MPWRITE with the ``LIB`` option.
721721
722-
If you omit the LIB option for MPREAD, this command supports
722+
If you omit the ``LIB`` option for ``MPREAD``, this command supports
723723
only linear properties.
724724
725725
Material numbers are hardcoded. If you write a material file
726-
without specifying the LIB option, then read that file in
727-
using the MPREAD command with the LIB option, the ANSYS
726+
without specifying the ``LIB`` option, then read that file in
727+
using the ``MPREAD`` command with the ``LIB`` option, the ANSYS
728728
program will not write the file to a new material number.
729729
Instead, it will write the file to the "old" material number
730730
(the number specified on the MPWRITE command that created the
@@ -855,9 +855,9 @@ def mpwrite(self, fname="", ext="", lib="", mat="", **kwargs):
855855
----------
856856
fname
857857
File name and directory path (248 characters maximum, including
858-
directory). If you do not specify the LIB option, the default
859-
directory is the current working directory. If you specify LIB and
860-
you have specified a material library directory (via the /MPLIB
858+
directory). If you do not specify the ``LIB`` option, the default
859+
directory is the current working directory. If you specify ``LIB`` and
860+
you have specified a material library directory (via the ``/MPLIB``
861861
command), that directory is the default. Otherwise, the default is
862862
the current working directory. If you use the default for your
863863
directory, you can use all 248 characters for the file name.
@@ -867,18 +867,18 @@ def mpwrite(self, fname="", ext="", lib="", mat="", **kwargs):
867867
ext
868868
Filename extension (eight-character maximum).
869869
870-
If you omit the LIB option, the default extension is
871-
MP. If you specify the LIB option, the default extension
870+
If you omit the ``LIB`` option, the default extension is
871+
MP. If you specify the ``LIB`` option, the default extension
872872
is units_MPL, where units is the system of units currently
873-
in use. (See the description of the /UNITS command.) For
874-
example, if /UNITS is set to BIN, the extension defaults
873+
in use. (See the description of the ``/UNITS`` command.) For
874+
example, if ``/UNITS`` is set to BIN, the extension defaults
875875
to BIN_MPL.
876876
877877
lib
878-
The only value allowed for this field is the string "LIB."
878+
The only value allowed for this field is the string ``"LIB"``.
879879
880-
The LIB option indicates that you wish to have properties
881-
associated with the material (MAT) written to the
880+
The ``LIB`` option indicates that you wish to have properties
881+
associated with the material (``MAT``) written to the
882882
specified material library file using the material library
883883
file format. The material library file format is
884884
ASCII-text-based ANSYS command input. Certain commands
@@ -888,15 +888,15 @@ def mpwrite(self, fname="", ext="", lib="", mat="", **kwargs):
888888
file independent of the material number in effect when the
889889
file was written; this enables you to restore the
890890
properties into the ANSYS database using the material
891-
number of your choice. The LIB option also enables you to
891+
number of your choice. The ``LIB`` option also enables you to
892892
save both linear and nonlinear properties. If you omit the
893-
LIB option, you can save linear properties only.
893+
``LIB`` option, you can save linear properties only.
894894
895895
mat
896896
Specifies the material to be written to the named material library
897897
file. There is no default; you must either specify a material or
898-
omit the MAT argument. Even if you specify a MAT value, the ANSYS
899-
program ignores it if the LIB argument is not specified.
898+
omit the ``MAT`` argument. Even if you specify a ``MAT`` value, the ANSYS
899+
program ignores it if the ``LIB`` argument is not specified.
900900
901901
Notes
902902
-----

src/ansys/mapdl/core/mapdl.py

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from ansys.mapdl.core.inline_functions import Query
3131
from ansys.mapdl.core.misc import (
3232
last_created,
33+
load_file,
3334
random_string,
3435
run_as_prep7,
3536
supress_logging,
@@ -1618,9 +1619,9 @@ def add_file_handler(self, filepath, append=False, level="DEBUG"):
16181619
self._log_filehandler = logging.FileHandler(filepath, mode=mode)
16191620
self._log_filehandler.setFormatter(logging.Formatter(formatstr))
16201621
if isinstance(level, str):
1621-
level = level.uppder()
1622+
level = level.upper()
16221623
self._log_filehandler.setLevel(level)
1623-
self._log.addHandler(self._log_filehandler)
1624+
self._log.logger.addHandler(self._log_filehandler)
16241625
self._log.info("Added file handler at %s", filepath)
16251626

16261627
def remove_file_handler(self):
@@ -2890,3 +2891,40 @@ def _check_parameter_name(self, param_name):
28902891
"Hence its use is not recommended outside them."
28912892
"You might run in unexpected behaviours, for example, parameters not being show in `mapdl.parameters`."
28922893
)
2894+
2895+
@wraps(Commands.mpread)
2896+
def mpread(self, fname="", ext="", lib="", **kwargs):
2897+
if lib:
2898+
raise NotImplementedError(
2899+
"The option 'lib' is not supported by the MAPDL gRPC server."
2900+
)
2901+
2902+
fname_ = fname + "." + ext
2903+
fname = load_file(self, fname_)
2904+
self._log.info("Bypassing 'MPREAD' with 'INPUT'.")
2905+
return self.input(fname)
2906+
2907+
@wraps(Commands.mpwrite)
2908+
def mpwrite(
2909+
self,
2910+
fname="",
2911+
ext="",
2912+
lib="",
2913+
mat="",
2914+
download_file=False,
2915+
progress_bar=True,
2916+
**kwargs,
2917+
):
2918+
fname_ = fname + "." + ext
2919+
if not self._local:
2920+
if os.path.dirname(fname_):
2921+
raise IOError(
2922+
"Only writing files to the MAPDL working directory is allowed. "
2923+
f"The supplied path {fname_} is not allowed."
2924+
)
2925+
2926+
output = super().mpwrite(fname, ext, lib, mat, **kwargs)
2927+
if download_file:
2928+
self.download(os.path.basename(fname_), progress_bar=progress_bar)
2929+
2930+
return output

src/ansys/mapdl/core/mapdl_geometry.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def n_volu(self):
329329
330330
Examples
331331
--------
332-
>>> mapdl.n_area
332+
>>> mapdl.n_volu
333333
1
334334
"""
335335
return self._item_count("VOLU")
@@ -382,6 +382,9 @@ def knum(self):
382382
>>> mapdl.knum
383383
array([1, 2, 3, 4, 5, 6, 7, 8], dtype=int32)
384384
"""
385+
if self._mapdl.geometry.n_keypoint == 0:
386+
return np.array([], dtype=np.int32)
387+
385388
return self._mapdl.get_array("KP", item1="KLIST").astype(np.int32)
386389

387390
@property
@@ -394,6 +397,10 @@ def lnum(self):
394397
>>> mapdl.lnum
395398
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], dtype=int32)
396399
"""
400+
# For clean exit when there is no lines.
401+
if self._mapdl.geometry.n_line == 0:
402+
return np.array([], dtype=np.int32)
403+
397404
# this (weirdly) sometimes fails
398405
for _ in range(5):
399406
lnum = self._mapdl.get_array("LINES", item1="LLIST")
@@ -411,6 +418,10 @@ def anum(self):
411418
>>> mapdl.anum
412419
array([1, 2, 3, 4, 5, 6], dtype=int32)
413420
"""
421+
# Clean exit
422+
if self._mapdl.geometry.n_area == 0:
423+
return np.array([], dtype=np.int32)
424+
414425
return self._mapdl.get_array("AREA", item1="ALIST").astype(np.int32)
415426

416427
@property
@@ -423,6 +434,9 @@ def vnum(self):
423434
>>> mapdl.vnum
424435
array([1], dtype=int32)
425436
"""
437+
if self._mapdl.geometry.n_volu == 0:
438+
return np.array([], dtype=np.int32)
439+
426440
return self._mapdl.get_array("VOLU", item1="VLIST").astype(np.int32)
427441

428442
@supress_logging

src/ansys/mapdl/core/math.py

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from ansys.api.mapdl.v0 import mapdl_pb2 as pb_types
1212
import numpy as np
1313

14+
from ansys.mapdl.core.misc import load_file
15+
1416
from .check_version import VersionError, meets_version, version_requires
1517
from .common_grpc import ANSYS_VALUE_TYPE, DEFAULT_CHUNKSIZE, DEFAULT_FILE_CHUNK_SIZE
1618
from .errors import ANSYSDataTypeError, protect_grpc
@@ -523,19 +525,7 @@ def _load_file(self, fname):
523525
If the file is local, it will be uploaded.
524526
525527
"""
526-
if self._mapdl._local: # pragma: no cover
527-
if not os.path.exists(fname):
528-
raise FileNotFoundError(f"The file {fname} could not be found.")
529-
else:
530-
if not os.path.exists(fname) and fname not in self._mapdl.list_files():
531-
raise FileNotFoundError(
532-
f"The file {fname} could not be found in the local client or remote working directory."
533-
)
534-
if os.path.exists(fname):
535-
self._mapdl.upload(fname)
536-
fname = os.path.basename(fname)
537-
538-
return fname
528+
return load_file(self._mapdl, fname)
539529

540530
def stiff(self, dtype=np.double, fname="file.full", asarray=False):
541531
"""Load the stiffness matrix from a full file.
@@ -1423,19 +1413,26 @@ def shape(self) -> tuple:
14231413
"""
14241414
return (self.nrow, self.ncol)
14251415

1426-
def sym(self): # BUG this is not always true
1427-
"""Return if matrix is symmetric."""
1416+
def sym(self) -> bool:
1417+
"""Return if matrix is symmetric.
1418+
1419+
Returns
1420+
-------
1421+
bool
1422+
``True`` when this matrix is symmetric.
1423+
1424+
"""
14281425

14291426
info = self._mapdl._data_info(self.id)
14301427

14311428
if meets_version(self._mapdl._server_version, (0, 5, 0)): # pragma: no cover
14321429
return info.mattype in [0, 1, 2] # [UPPER, LOWER, DIAG] respectively
1433-
else:
1434-
warn(
1435-
"Call to sym() function cannot evaluate if"
1436-
"it is symmetric or not in this MAPDL version."
1437-
)
1438-
return True
1430+
1431+
warn(
1432+
"Call to ``sym`` cannot evaluate if this matrix "
1433+
"is symmetric with this version of MAPDL."
1434+
)
1435+
return True
14391436

14401437
def asarray(self, dtype=None) -> np.ndarray:
14411438
"""Returns vector as a numpy array.

0 commit comments

Comments
 (0)