Skip to content

Commit

Permalink
merge with main; bump to v0.61.1
Browse files Browse the repository at this point in the history
  • Loading branch information
akaszynski committed Mar 19, 2022
2 parents 6feaebc + 4822d49 commit bd80c49
Show file tree
Hide file tree
Showing 16 changed files with 353 additions and 62 deletions.
10 changes: 10 additions & 0 deletions doc/source/404.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
:orphan:

Oops!
=====


This is unexpected.


The page you are requesting does not exist.
8 changes: 8 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@
r"\.*MeshGrpc\.*",
}

# Favicon
html_favicon = "favicon.png"

# notfound.extension
notfound_template = "404.rst"
notfound_urls_prefix = "/../"


# static path
html_static_path = ["_static"]

Expand Down
Binary file added doc/source/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
[project]
# Check https://flit.readthedocs.io/en/latest/pyproject_toml.html for all available sections
name = "ansys-mapdl-core"
version = "0.61.0"
version = "0.61.1"
description = "A Python wrapper for Ansys mapdl core"
readme = "README.rst"
requires-python = ">=3.7"
Expand All @@ -17,9 +17,9 @@ maintainers = [
{name = "PyAnsys developers", email = "[email protected]"},
]
dependencies = [
"ansys-api-mapdl-v0==0.4.1", # supports at least 2020R2 - 2021R2
"ansys-api-mapdl==0.5.1", # supports at least 2020R2 - 2022R1
"ansys-corba; python_version < '3.9'",
"ansys-mapdl-reader>=0.50.15",
"ansys-mapdl-reader>=0.51.7",
"appdirs>=1.4.0",
"grpcio>=1.30.0", # tested up to grpcio==1.35
"importlib-metadata >=4.0",
Expand Down
6 changes: 3 additions & 3 deletions requirements/requirements_docs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Sphinx==4.4.0
ansys-mapdl-reader==0.51.3 # newer breaks doc build
ansys-mapdl-reader==0.51.11
imageio-ffmpeg==0.4.5
imageio==2.16.1
jupyter_sphinx==0.3.2
Expand All @@ -9,7 +9,7 @@ numpydoc==1.2
pandas==1.4.1
plotly==5.6.0
pyansys_sphinx_theme==0.2.3
pypandoc==1.7.2
pypandoc==1.7.4
pytest-sphinx==0.3.1
pythreejs==2.3.0
pyvista==0.33.3
Expand All @@ -21,4 +21,4 @@ sphinx-notfound-page==0.8
sphinxcontrib-websupport==1.2.4
sphinxemoji==0.2.0
vtk==9.0.3
grpcio==1.43.0
grpcio==1.43.0
2 changes: 1 addition & 1 deletion requirements/requirements_tests.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
autopep8==1.6.0
matplotlib==3.5.1
pandas==1.4.1
pytest==7.0.1
pytest==7.1.1
pytest-cov==3.0.0
pyvista==0.33.3
scipy==1.8.0
Expand Down
56 changes: 28 additions & 28 deletions src/ansys/mapdl/core/_commands/preproc/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -691,12 +691,12 @@ def mpread(self, fname="", ext="", lib="", **kwargs):
----------
fname
File name and directory path (248 characters maximum,
including directory). If you do not specify the LIB
including directory). If you do not specify the ``LIB``
option, the default directory is the current working
directory. If you specify the LIB option, the default is
directory. If you specify the ``LIB`` option, the default is
the following search path: the current working directory,
the user's home directory, MPLIB_DIR (as specified by the
/MPLIB,READ,PATH command) and /ansys_dir/matlib (as
the user's home directory, ``MPLIB_DIR`` (as specified by the
``/MPLIB,READ,PATH`` command) and ``/ansys_dir/matlib`` (as
defined by installation). If you use the default for your
directory, you can use all 248 characters for the file
name.
Expand All @@ -706,25 +706,25 @@ def mpread(self, fname="", ext="", lib="", **kwargs):
lib
Reads material library files previously written with the
MPWRITE command. (See the description of the LIB option
for the MPWRITE command.) The only allowed value for LIB
is LIB.
MPWRITE command. (See the description of the ``LIB`` option
for the ``MPWRITE`` command.) The only allowed value for ``LIB``
is ``LIB``.
Notes
-----
Material properties written to a file without the LIB option
Material properties written to a file without the ``LIB`` option
do not support nonlinear properties. Also, properties written
to a file without the LIB option are restored in the same
to a file without the ``LIB`` option are restored in the same
material number as originally defined. To avoid errors, use
MPREAD with the LIB option only when reading files written
using MPWRITE with the LIB option.
``MPREAD`` with the ``LIB`` option only when reading files written
using MPWRITE with the ``LIB`` option.
If you omit the LIB option for MPREAD, this command supports
If you omit the ``LIB`` option for ``MPREAD``, this command supports
only linear properties.
Material numbers are hardcoded. If you write a material file
without specifying the LIB option, then read that file in
using the MPREAD command with the LIB option, the ANSYS
without specifying the ``LIB`` option, then read that file in
using the ``MPREAD`` command with the ``LIB`` option, the ANSYS
program will not write the file to a new material number.
Instead, it will write the file to the "old" material number
(the number specified on the MPWRITE command that created the
Expand Down Expand Up @@ -855,9 +855,9 @@ def mpwrite(self, fname="", ext="", lib="", mat="", **kwargs):
----------
fname
File name and directory path (248 characters maximum, including
directory). If you do not specify the LIB option, the default
directory is the current working directory. If you specify LIB and
you have specified a material library directory (via the /MPLIB
directory). If you do not specify the ``LIB`` option, the default
directory is the current working directory. If you specify ``LIB`` and
you have specified a material library directory (via the ``/MPLIB``
command), that directory is the default. Otherwise, the default is
the current working directory. If you use the default for your
directory, you can use all 248 characters for the file name.
Expand All @@ -867,18 +867,18 @@ def mpwrite(self, fname="", ext="", lib="", mat="", **kwargs):
ext
Filename extension (eight-character maximum).
If you omit the LIB option, the default extension is
MP. If you specify the LIB option, the default extension
If you omit the ``LIB`` option, the default extension is
MP. If you specify the ``LIB`` option, the default extension
is units_MPL, where units is the system of units currently
in use. (See the description of the /UNITS command.) For
example, if /UNITS is set to BIN, the extension defaults
in use. (See the description of the ``/UNITS`` command.) For
example, if ``/UNITS`` is set to BIN, the extension defaults
to BIN_MPL.
lib
The only value allowed for this field is the string "LIB."
The only value allowed for this field is the string ``"LIB"``.
The LIB option indicates that you wish to have properties
associated with the material (MAT) written to the
The ``LIB`` option indicates that you wish to have properties
associated with the material (``MAT``) written to the
specified material library file using the material library
file format. The material library file format is
ASCII-text-based ANSYS command input. Certain commands
Expand All @@ -888,15 +888,15 @@ def mpwrite(self, fname="", ext="", lib="", mat="", **kwargs):
file independent of the material number in effect when the
file was written; this enables you to restore the
properties into the ANSYS database using the material
number of your choice. The LIB option also enables you to
number of your choice. The ``LIB`` option also enables you to
save both linear and nonlinear properties. If you omit the
LIB option, you can save linear properties only.
``LIB`` option, you can save linear properties only.
mat
Specifies the material to be written to the named material library
file. There is no default; you must either specify a material or
omit the MAT argument. Even if you specify a MAT value, the ANSYS
program ignores it if the LIB argument is not specified.
omit the ``MAT`` argument. Even if you specify a ``MAT`` value, the ANSYS
program ignores it if the ``LIB`` argument is not specified.
Notes
-----
Expand Down
42 changes: 40 additions & 2 deletions src/ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from ansys.mapdl.core.inline_functions import Query
from ansys.mapdl.core.misc import (
last_created,
load_file,
random_string,
run_as_prep7,
supress_logging,
Expand Down Expand Up @@ -1618,9 +1619,9 @@ def add_file_handler(self, filepath, append=False, level="DEBUG"):
self._log_filehandler = logging.FileHandler(filepath, mode=mode)
self._log_filehandler.setFormatter(logging.Formatter(formatstr))
if isinstance(level, str):
level = level.uppder()
level = level.upper()
self._log_filehandler.setLevel(level)
self._log.addHandler(self._log_filehandler)
self._log.logger.addHandler(self._log_filehandler)
self._log.info("Added file handler at %s", filepath)

def remove_file_handler(self):
Expand Down Expand Up @@ -2890,3 +2891,40 @@ def _check_parameter_name(self, param_name):
"Hence its use is not recommended outside them."
"You might run in unexpected behaviours, for example, parameters not being show in `mapdl.parameters`."
)

@wraps(Commands.mpread)
def mpread(self, fname="", ext="", lib="", **kwargs):
if lib:
raise NotImplementedError(
"The option 'lib' is not supported by the MAPDL gRPC server."
)

fname_ = fname + "." + ext
fname = load_file(self, fname_)
self._log.info("Bypassing 'MPREAD' with 'INPUT'.")
return self.input(fname)

@wraps(Commands.mpwrite)
def mpwrite(
self,
fname="",
ext="",
lib="",
mat="",
download_file=False,
progress_bar=True,
**kwargs,
):
fname_ = fname + "." + ext
if not self._local:
if os.path.dirname(fname_):
raise IOError(
"Only writing files to the MAPDL working directory is allowed. "
f"The supplied path {fname_} is not allowed."
)

output = super().mpwrite(fname, ext, lib, mat, **kwargs)
if download_file:
self.download(os.path.basename(fname_), progress_bar=progress_bar)

return output
16 changes: 15 additions & 1 deletion src/ansys/mapdl/core/mapdl_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def n_volu(self):
Examples
--------
>>> mapdl.n_area
>>> mapdl.n_volu
1
"""
return self._item_count("VOLU")
Expand Down Expand Up @@ -382,6 +382,9 @@ def knum(self):
>>> mapdl.knum
array([1, 2, 3, 4, 5, 6, 7, 8], dtype=int32)
"""
if self._mapdl.geometry.n_keypoint == 0:
return np.array([], dtype=np.int32)

return self._mapdl.get_array("KP", item1="KLIST").astype(np.int32)

@property
Expand All @@ -394,6 +397,10 @@ def lnum(self):
>>> mapdl.lnum
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], dtype=int32)
"""
# For clean exit when there is no lines.
if self._mapdl.geometry.n_line == 0:
return np.array([], dtype=np.int32)

# this (weirdly) sometimes fails
for _ in range(5):
lnum = self._mapdl.get_array("LINES", item1="LLIST")
Expand All @@ -411,6 +418,10 @@ def anum(self):
>>> mapdl.anum
array([1, 2, 3, 4, 5, 6], dtype=int32)
"""
# Clean exit
if self._mapdl.geometry.n_area == 0:
return np.array([], dtype=np.int32)

return self._mapdl.get_array("AREA", item1="ALIST").astype(np.int32)

@property
Expand All @@ -423,6 +434,9 @@ def vnum(self):
>>> mapdl.vnum
array([1], dtype=int32)
"""
if self._mapdl.geometry.n_volu == 0:
return np.array([], dtype=np.int32)

return self._mapdl.get_array("VOLU", item1="VLIST").astype(np.int32)

@supress_logging
Expand Down
39 changes: 18 additions & 21 deletions src/ansys/mapdl/core/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from ansys.api.mapdl.v0 import mapdl_pb2 as pb_types
import numpy as np

from ansys.mapdl.core.misc import load_file

from .check_version import VersionError, meets_version, version_requires
from .common_grpc import ANSYS_VALUE_TYPE, DEFAULT_CHUNKSIZE, DEFAULT_FILE_CHUNK_SIZE
from .errors import ANSYSDataTypeError, protect_grpc
Expand Down Expand Up @@ -523,19 +525,7 @@ def _load_file(self, fname):
If the file is local, it will be uploaded.
"""
if self._mapdl._local: # pragma: no cover
if not os.path.exists(fname):
raise FileNotFoundError(f"The file {fname} could not be found.")
else:
if not os.path.exists(fname) and fname not in self._mapdl.list_files():
raise FileNotFoundError(
f"The file {fname} could not be found in the local client or remote working directory."
)
if os.path.exists(fname):
self._mapdl.upload(fname)
fname = os.path.basename(fname)

return fname
return load_file(self._mapdl, fname)

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

def sym(self): # BUG this is not always true
"""Return if matrix is symmetric."""
def sym(self) -> bool:
"""Return if matrix is symmetric.
Returns
-------
bool
``True`` when this matrix is symmetric.
"""

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

if meets_version(self._mapdl._server_version, (0, 5, 0)): # pragma: no cover
return info.mattype in [0, 1, 2] # [UPPER, LOWER, DIAG] respectively
else:
warn(
"Call to sym() function cannot evaluate if"
"it is symmetric or not in this MAPDL version."
)
return True

warn(
"Call to ``sym`` cannot evaluate if this matrix "
"is symmetric with this version of MAPDL."
)
return True

def asarray(self, dtype=None) -> np.ndarray:
"""Returns vector as a numpy array.
Expand Down
7 changes: 6 additions & 1 deletion src/ansys/mapdl/core/mesh_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,12 @@ def enum(self) -> np.ndarray:
array([ 1, 2, 3, ..., 9998, 9999, 10000])
"""
if self._enum is None:
self._enum = self._mapdl.get_array("ELEM", item1="ELIST").astype(np.int32)
if self._mapdl.mesh.n_elem == 0:
return np.array([], dtype=np.int32)
else:
self._enum = self._mapdl.get_array("ELEM", item1="ELIST").astype(
np.int32
)
return self._enum

@threaded
Expand Down
Loading

0 comments on commit bd80c49

Please sign in to comment.