From a6db30a8748bee0ed81b139498475bfbbfbee1ef Mon Sep 17 00:00:00 2001 From: Alex Kaszynski Date: Thu, 11 Feb 2021 14:56:53 -0700 Subject: [PATCH] Ignore distortion elements (#357) --- .gitignore | 5 ++++- ansys/mapdl/core/_version.py | 2 +- ansys/mapdl/core/launcher.py | 8 +++++--- ansys/mapdl/core/mapdl.py | 22 ++++++++++++++++------ docs/source/contributing.rst | 6 +++--- tests/conftest.py | 24 ++++++++++++++++++++++-- tests/test_grpc.py | 2 +- tests/test_mapdl.py | 7 +++++-- tests/test_post.py | 9 +++++---- tmp.out | 1 - 10 files changed, 62 insertions(+), 24 deletions(-) delete mode 100644 tmp.out diff --git a/.gitignore b/.gitignore index 82ea4ff902..c2dcad952a 100755 --- a/.gitignore +++ b/.gitignore @@ -66,4 +66,7 @@ examples/.local .ipynb_checkpoints/ # docker -docker/mapdl/v211 \ No newline at end of file +docker/mapdl/v211 + +# temp testing +tmp.out \ No newline at end of file diff --git a/ansys/mapdl/core/_version.py b/ansys/mapdl/core/_version.py index 2af1added4..cdd0be46e9 100644 --- a/ansys/mapdl/core/_version.py +++ b/ansys/mapdl/core/_version.py @@ -1,7 +1,7 @@ """Version of ansys-mapdl-core module.""" # major, minor, patch -version_info = 0, 57, 5 +version_info = 0, 57, 6 # Nice string for the version __version__ = '.'.join(map(str, version_info)) diff --git a/ansys/mapdl/core/launcher.py b/ansys/mapdl/core/launcher.py index d8cc96bc32..642cbfa9c4 100644 --- a/ansys/mapdl/core/launcher.py +++ b/ansys/mapdl/core/launcher.py @@ -380,7 +380,7 @@ def _get_available_base_ansys(): Within Linux - >>> + >>> _get_available_base_ansys() {194: '/usr/ansys_inc/v194', 202: '/usr/ansys_inc/v202', 211: '/usr/ansys_inc/v211'} @@ -402,12 +402,12 @@ def _get_available_base_ansys(): raise OSError(f'Unsupported OS {os.name}') if base_path is None: - return '', '' + return {} paths = glob(os.path.join(base_path, 'v*')) if not paths: - return None + return {} ansys_paths = {} for path in paths: @@ -444,6 +444,8 @@ def find_ansys(): (/usr/ansys_inc/v211/ansys/bin/ansys211, 21.1) """ versions = _get_available_base_ansys() + if not versions: + return '', '' version = max(versions.keys()) ans_path = versions[version] if os.name == 'nt': diff --git a/ansys/mapdl/core/mapdl.py b/ansys/mapdl/core/mapdl.py index 3b138d8548..2c76d3b8ca 100644 --- a/ansys/mapdl/core/mapdl.py +++ b/ansys/mapdl/core/mapdl.py @@ -8,6 +8,7 @@ import tempfile from shutil import rmtree, copyfile import weakref +import warnings import numpy as np import pyvista as pv @@ -25,6 +26,11 @@ from ansys.mapdl.core.plotting import general_plotter from ansys.mapdl.core.post import PostProcessing +_PERMITTED_ERRORS = [ + r'(\*\*\* ERROR \*\*\*).*(?:[\r\n]+.*)+highly distorted.', + r'(\*\*\* ERROR \*\*\*).*[\r\n]+.*is turning inside out.', +] + MATPLOTLIB_LOADED = True try: @@ -1766,15 +1772,19 @@ def run(self, command, write_to_log=True, **kwargs): text += '\n\nIgnore these messages by setting allow_ignore=True' raise MapdlInvalidRoutineError(text) - # flag error + # flag errors if '*** ERROR ***' in self._response and not self._ignore_errors: - # remove "is turning inside out" as this allows the - # solution to continue - sub = re.sub(r'(\*\*\* ERROR \*\*\*).*[\r\n]+.*is turning inside out.', - '', self._response) - if '*** ERROR ***' in sub: + # remove permitted errors and allow MAPDL to continue + response = self._response + for err_str in _PERMITTED_ERRORS: + response = re.sub(err_str, '', response) + + if '*** ERROR ***' in response: self._log.error(self._response) raise MapdlRuntimeError(self._response) + else: + warnings.warn('MAPDL returned non-abort errors. Please ' + 'check the logs.') # special returns for certain geometry commands short_cmd = parse_to_short_cmd(command) diff --git a/docs/source/contributing.rst b/docs/source/contributing.rst index de8f5ef2b6..b451f2cb71 100644 --- a/docs/source/contributing.rst +++ b/docs/source/contributing.rst @@ -206,9 +206,9 @@ or in Linux .. code:: - PYANSYS_START_INSTANCE=False - PYMAPDL_PORT= (default 50052) - PYMAPDL_IP= (default 127.0.0.1) + export PYMAPDL_START_INSTANCE=False + export PYMAPDL_PORT= (default 50052) + export PYMAPDL_IP= (default 127.0.0.1) This will tell the ``ansys.mapdl.core`` to attempt to connect to the existing MAPDL service by default when the ``launch_mapdl`` function is used. diff --git a/tests/conftest.py b/tests/conftest.py index eb370f29cf..b30dd8150d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -27,9 +27,29 @@ # check if the user wants to permit pytest to start MAPDL START_INSTANCE = get_start_instance() -# if START_INSTANCE: -# local.append(True) +if os.name == 'nt': + os_msg = """SET PYMAPDL_START_INSTANCE=False +SET PYMAPDL_PORT= (default 50052) +SET PYMAPDL_IP= (default 127.0.0.1)""" +else: + os_msg = """export PYMAPDL_START_INSTANCE=False +export PYMAPDL_PORT= (default 50052) +export PYMAPDL_IP= (default 127.0.0.1)""" + +ERRMSG = f"""Unable to run CI without MAPDL installed or accessible. +Either install Ansys 2021R1 or newer or specify the remote server with: + +{os_msg} + +If you do have Ansys installed, you may have to patch pymapdl to +automatically find your Ansys installation. Email the developer at: +alexander.kaszynski@ansys.com + +""" + +if START_INSTANCE and EXEC_FILE is None: + raise RuntimeError(ERRMSG) def pytest_addoption(parser): parser.addoption( diff --git a/tests/test_grpc.py b/tests/test_grpc.py index 0a25041ef6..f08a0d7838 100644 --- a/tests/test_grpc.py +++ b/tests/test_grpc.py @@ -39,7 +39,7 @@ def test_basic_input_output(mapdl, tmpdir): f.write('FINISH\n') f.write('/PREP7\n') - resp = mapdl.upload(basic_inp) + mapdl.upload(basic_inp) tmpfile = 'tmp.out' mapdl._send_command('/OUT, %s' % tmpfile, mute=True) mapdl._send_command('/INPUT, %s' % filename, mute=True) diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index a8e706b32e..7d1e8dfbbd 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -216,6 +216,7 @@ def test_invalid_input(mapdl): with pytest.raises(FileNotFoundError): mapdl.input('thisisnotafile') + @skip_no_xserver def test_kplot(cleared, mapdl, tmpdir): with pytest.raises(MapdlRuntimeError): @@ -471,8 +472,10 @@ def test_builtin_parameters(mapdl, cleared): assert isinstance(mapdl.parameters.revision, float) - if os.name == 'posix': - assert 'LIN' in mapdl.parameters.platform + # Platform could be either windows or Linux, without regards to + # the testing OS. + plat = mapdl.parameters.platform + assert 'L' in plat or 'W' in plat mapdl.csys(1) assert mapdl.parameters.csys == 1 diff --git a/tests/test_post.py b/tests/test_post.py index 5c1b713853..ee92de05f6 100644 --- a/tests/test_post.py +++ b/tests/test_post.py @@ -104,10 +104,11 @@ def plastic_solve(mapdl): # must be run first before loading a result -@pytest.mark.skipif(os.name == 'nt', reason="Causes MAPDL to die on windows") -def test_nodal_eqv_stress_fail(mapdl, static_solve): - with pytest.raises(MapdlRuntimeError): - mapdl.post_processing.nodal_eqv_stress +# since MAPDL may be on a remote windows machine, cannot test +# @pytest.mark.skipif(os.name == 'nt', reason="Causes MAPDL to die on windows") +# def test_nodal_eqv_stress_fail(mapdl, static_solve): +# with pytest.raises(MapdlRuntimeError): +# mapdl.post_processing.nodal_eqv_stress @pytest.mark.parametrize('comp', ['X', 'Y', 'z']) # lowercase intentional diff --git a/tmp.out b/tmp.out deleted file mode 100644 index 8d1c8b69c3..0000000000 --- a/tmp.out +++ /dev/null @@ -1 +0,0 @@ -