Skip to content

Commit

Permalink
add prnsol edge case (#835)
Browse files Browse the repository at this point in the history
* add prnsol edge case

* Fxing edge case where all the headers have been removed.

* Adding test case.

Co-authored-by: German <[email protected]>
  • Loading branch information
akaszynski and germa89 authored Jan 13, 2022
1 parent c9ad2b9 commit 1e9d3fd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
16 changes: 15 additions & 1 deletion ansys/mapdl/core/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,17 @@ def _get_data_groups(self, magicword=None, trail_header=None):
"""Get raw data groups"""
body = self._get_body(trail_header=trail_header)

try:
np.array(body[1].split(), dtype=float) #if this fail, there is headers,
self._default_format = False
except:
# There is headers, assuming default format
self._default_format = True

if not self._default_format:
return [each for each in body[1:] if each]

# Using default format
data = []
for start, end in self._get_data_group_indexes(body, magicword=magicword):
data.extend(body[start+1:end])
Expand All @@ -554,7 +565,10 @@ def get_columns(self):
"""
body = self._get_body()
pairs = list(self._get_data_group_indexes(body))
return body[pairs[0][0]].split()
try:
return body[pairs[0][0]].split()
except:
return None

@check_valid_output
def to_list(self):
Expand Down
25 changes: 25 additions & 0 deletions tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@
'kcmplx': 1
}

PRNSOL_OUT = """PRINT F REACTION SOLUTIONS PER NODE
1 0.1287512532E+008 0.4266737217E+007
2 -0.1512012179E+007 0.2247558576E+007
3 -0.7065315064E+007 -0.4038004530E+007
4 -0.4297798077E+007 -0.2476291263E+007"""


CMD_DOC_STRING_INJECTOR = CMD_LISTING.copy()
CMD_DOC_STRING_INJECTOR.extend(CMD_BC_LISTING)

Expand All @@ -72,6 +79,7 @@ def plastic_solve(mapdl):
mapdl.set(1, 2)
mapdl.mute = False


@pytest.fixture(scope="module")
def beam_solve(mapdl):
mapdl.mute = True
Expand All @@ -83,6 +91,7 @@ def beam_solve(mapdl):
mapdl.set(1, 2)
mapdl.mute = False


def test_cmd_class():
output = """This is the output.
This is the second line.
Expand All @@ -102,6 +111,22 @@ def test_cmd_class():
assert isinstance(cmd_out.split('g'), list)


def test_cmd_class_prnsol_short():
cmd = 'PRRSOL,F'
out = CommandListingOutput(PRNSOL_OUT, cmd=cmd)

out_list = out.to_list()
out_array = out.to_array()

assert isinstance(out, CommandListingOutput)
assert isinstance(out_list, list) and bool(out_list)
assert isinstance(out_array, np.ndarray) and out_array.size != 0

if HAS_PANDAS:
out_df = out.to_dataframe()
assert isinstance(out_df, pd.DataFrame) and not out_df.empty


@pytest.mark.parametrize("func", LIST_OF_INQUIRE_FUNCTIONS)
def test_inquire_functions(mapdl, func):
func_ = getattr(mapdl, func)
Expand Down

0 comments on commit 1e9d3fd

Please sign in to comment.