From 01fa78687d420bf39a551584abd8afb550d3d97f Mon Sep 17 00:00:00 2001 From: German <28149841+germa89@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:34:45 +0100 Subject: [PATCH 1/3] refactor: moving tests to classes to avoid repeatingly execute the fixtures. --- tests/conftest.py | 32 - tests/test_post.py | 1991 ++++++++++++++++++++++++++------------------ 2 files changed, 1158 insertions(+), 865 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 703bd3a36d..73055ac40b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1152,38 +1152,6 @@ def contact_geom_and_mesh(mapdl): mapdl.mute = False -@pytest.fixture(scope="function") -def contact_solve(mapdl, contact_geom_and_mesh): - # ========================================================== - # * Solution - # ========================================================== - # from precedent fixture - uz1 = 3.18e-03 / 4000 - - mapdl.mute = False - mapdl.run("/solu") - mapdl.antype(4) # Transient analysis - mapdl.lnsrch("on") - mapdl.cutcontrol("plslimit", 0.15) - mapdl.kbc(0) # Ramped loading within a load step - mapdl.nlgeom("on") # Turn on large deformation effects - mapdl.timint("off", "struc") # Structural dynamic effects are turned off. - mapdl.nropt("unsym") - - # Load Step1 - mapdl.time(1) - mapdl.nsubst(5, 10, 2) - mapdl.d(1, "uz", -uz1) # Tool plunges into the workpiece - mapdl.outres("all", "all") - mapdl.allsel() - mapdl.solve() - - mapdl.post1() - mapdl.allsel() - mapdl.set("last") - mapdl.mute = False - - @pytest.fixture(scope="function") def cuadratic_beam_problem(mapdl): mapdl.clear() diff --git a/tests/test_post.py b/tests/test_post.py index 0b3ff91f0a..5092c5d98c 100644 --- a/tests/test_post.py +++ b/tests/test_post.py @@ -44,869 +44,1194 @@ ) -@pytest.fixture(scope="module") -def static_solve(mapdl): - mapdl.mute = True - mapdl.finish() - mapdl.clear() - - # cylinder and mesh parameters - # torque = 100 - radius = 2 - h_tip = 2 - height = 20 - elemsize = 0.5 - # pi = np.arccos(-1) - force = 100 / radius - pressure = force / (h_tip * 2 * np.pi * radius) - - mapdl.prep7() - mapdl.et(1, 186) - mapdl.et(2, 154) - mapdl.r(1) - mapdl.r(2) - - # Aluminum properties (or something) - mapdl.mp("ex", 1, 10e6) - mapdl.mp("nuxy", 1, 0.3) - mapdl.mp("dens", 1, 0.1 / 386.1) - mapdl.mp("dens", 2, 0) - - # Simple cylinder - for i in range(4): - mapdl.cylind(radius, "", "", height, 90 * (i - 1), 90 * i) - - mapdl.nummrg("kp") - - # mesh cylinder - mapdl.lsel("s", "loc", "x", 0) - mapdl.lsel("r", "loc", "y", 0) - mapdl.lsel("r", "loc", "z", 0, height - h_tip) - mapdl.lesize("all", elemsize * 2) - mapdl.mshape(0) - mapdl.mshkey(1) - - mapdl.esize(elemsize) - mapdl.allsel("all") - mapdl.vsweep("ALL") - mapdl.csys(1) - mapdl.asel("s", "loc", "z", "", height - h_tip + 0.0001) - mapdl.asel("r", "loc", "x", radius) - mapdl.local(11, 1) - - mapdl.csys(0) - - # mesh the surface with SURF154 - mapdl.aatt(2, 2, 2, 11) - mapdl.amesh("all") - mapdl.prep7() - - # Apply tangential pressure - mapdl.esel("S", "TYPE", "", 2) - mapdl.sfe("all", 2, "pres", "", pressure) - - # Constrain bottom of cylinder/rod - mapdl.asel("s", "loc", "z", 0) - mapdl.nsla("s", 1) - mapdl.d("all", "all") - mapdl.allsel() - - # new solution - mapdl.run("/SOLU") - mapdl.antype("static", "new") - # mapdl.eqslv('pcg', 1e-8) - mapdl.solve() - - # necessary for any prnsol printouts - mapdl.header("off", "off", "off", "off", "off", "off") - nsigfig = 10 - mapdl.format("", "E", nsigfig + 9, nsigfig) - # mapdl.post1(mute=True) - # mapdl.set(1, 1) - mapdl.mute = False - - -@pytest.fixture(scope="module") -def plastic_solve(mapdl): - mapdl.mute = True - mapdl.finish() - mapdl.clear() - mapdl.input(examples.verif_files.vmfiles["vm273"]) - - mapdl.post1() - mapdl.set(1, 2) - mapdl.mute = False - - -@pytest.mark.parametrize("comp", ["X", "Y", "z"]) # lowercase intentional -def test_disp(mapdl, static_solve, comp): - disp_from_grpc = mapdl.post_processing.nodal_displacement(comp) - - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - nnum, disp_from_prns = np.genfromtxt(mapdl.prnsol("U", comp).splitlines()[1:]).T - - assert np.allclose(mapdl.mesh.nnum, nnum) - assert np.allclose(disp_from_grpc, disp_from_prns) - - -def test_enum_all(mapdl, static_solve): - # ensure that element selection status has no effect on the all_enum - try: - n_elem = mapdl.mesh.n_elem - mapdl.esel("S", "ELEM", vmin=10, vmax=19, mute=True) - mapdl.post_processing._all_enum - assert len(mapdl.post_processing._all_enum) == n_elem - finally: - # static solve is a module fixture, change in state here will affect - # downstream tests unless reset - mapdl.allsel(mute=True) - - -def test_disp_norm_all(mapdl, static_solve): - # test norm - disp_norm = mapdl.post_processing.nodal_displacement("NORM") - - x = mapdl.post_processing.nodal_displacement("X") - y = mapdl.post_processing.nodal_displacement("Y") - z = mapdl.post_processing.nodal_displacement("Z") - disp = np.vstack((x, y, z)) - manual_norm = np.linalg.norm(disp, axis=0) - assert np.allclose(disp_norm, manual_norm) - - # test all - assert np.allclose(disp.T, mapdl.post_processing.nodal_displacement("ALL")) - - -@pytest.mark.parametrize("comp", ["X", "Y", "z", "norm"]) # lowercase intentional -@requires("ansys-tools-visualization_interface") -def test_disp_plot(mapdl, static_solve, comp): - assert ( - mapdl.post_processing.plot_nodal_displacement( - comp, smooth_shading=True, cmap=PyMAPDL_cmap +class Test_static_solve: + + @staticmethod + @pytest.fixture(scope="class") + def static_solve(mapdl): + mapdl.mute = True + mapdl.finish() + mapdl.clear() + + # cylinder and mesh parameters + # torque = 100 + radius = 2 + h_tip = 2 + height = 20 + elemsize = 0.5 + # pi = np.arccos(-1) + force = 100 / radius + pressure = force / (h_tip * 2 * np.pi * radius) + + mapdl.prep7() + mapdl.et(1, 186) + mapdl.et(2, 154) + mapdl.r(1) + mapdl.r(2) + + # Aluminum properties (or something) + mapdl.mp("ex", 1, 10e6) + mapdl.mp("nuxy", 1, 0.3) + mapdl.mp("dens", 1, 0.1 / 386.1) + mapdl.mp("dens", 2, 0) + + # Simple cylinder + for i in range(4): + mapdl.cylind(radius, "", "", height, 90 * (i - 1), 90 * i) + + mapdl.nummrg("kp") + + # mesh cylinder + mapdl.lsel("s", "loc", "x", 0) + mapdl.lsel("r", "loc", "y", 0) + mapdl.lsel("r", "loc", "z", 0, height - h_tip) + mapdl.lesize("all", elemsize * 2) + mapdl.mshape(0) + mapdl.mshkey(1) + + mapdl.esize(elemsize) + mapdl.allsel("all") + mapdl.vsweep("ALL") + mapdl.csys(1) + mapdl.asel("s", "loc", "z", "", height - h_tip + 0.0001) + mapdl.asel("r", "loc", "x", radius) + mapdl.local(11, 1) + + mapdl.csys(0) + + # mesh the surface with SURF154 + mapdl.aatt(2, 2, 2, 11) + mapdl.amesh("all") + mapdl.prep7() + + # Apply tangential pressure + mapdl.esel("S", "TYPE", "", 2) + mapdl.sfe("all", 2, "pres", "", pressure) + + # Constrain bottom of cylinder/rod + mapdl.asel("s", "loc", "z", 0) + mapdl.nsla("s", 1) + mapdl.d("all", "all") + mapdl.allsel() + + # new solution + mapdl.run("/SOLU") + mapdl.antype("static", "new") + # mapdl.eqslv('pcg', 1e-8) + mapdl.solve() + + # necessary for any prnsol printouts + mapdl.header("off", "off", "off", "off", "off", "off") + nsigfig = 10 + mapdl.format("", "E", nsigfig + 9, nsigfig) + # mapdl.post1(mute=True) + # mapdl.set(1, 1) + mapdl.mute = False + + @staticmethod + @pytest.mark.parametrize("comp", ["X", "Y", "z"]) # lowercase intentional + def test_disp(mapdl, static_solve, comp): + disp_from_grpc = mapdl.post_processing.nodal_displacement(comp) + + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + nnum, disp_from_prns = np.genfromtxt(mapdl.prnsol("U", comp).splitlines()[1:]).T + + assert np.allclose(mapdl.mesh.nnum, nnum) + assert np.allclose(disp_from_grpc, disp_from_prns) + + @staticmethod + def test_enum_all(mapdl, static_solve): + # ensure that element selection status has no effect on the all_enum + try: + n_elem = mapdl.mesh.n_elem + mapdl.esel("S", "ELEM", vmin=10, vmax=19, mute=True) + mapdl.post_processing._all_enum + assert len(mapdl.post_processing._all_enum) == n_elem + finally: + # static solve is a module fixture, change in state here will affect + # downstream tests unless reset + mapdl.allsel(mute=True) + + @staticmethod + def test_disp_norm_all(mapdl, static_solve): + # test norm + disp_norm = mapdl.post_processing.nodal_displacement("NORM") + + x = mapdl.post_processing.nodal_displacement("X") + y = mapdl.post_processing.nodal_displacement("Y") + z = mapdl.post_processing.nodal_displacement("Z") + disp = np.vstack((x, y, z)) + manual_norm = np.linalg.norm(disp, axis=0) + assert np.allclose(disp_norm, manual_norm) + + # test all + assert np.allclose(disp.T, mapdl.post_processing.nodal_displacement("ALL")) + + @staticmethod + @requires("ansys-tools-visualization_interface") + @pytest.mark.parametrize("comp", ["X", "Y", "z", "norm"]) # lowercase intentional + def test_disp_plot(mapdl, static_solve, comp): + assert ( + mapdl.post_processing.plot_nodal_displacement( + comp, smooth_shading=True, cmap=PyMAPDL_cmap + ) + is None ) - is None - ) - -@requires("ansys-tools-visualization_interface") -def test_disp_plot_subselection(mapdl, static_solve, verify_image_cache): - verify_image_cache.skip = True # skipping image verification - - mapdl.nsel("S", "NODE", vmin=500, vmax=2000, mute=True) - mapdl.esel("S", "ELEM", vmin=500, vmax=2000, mute=True) - assert ( - mapdl.post_processing.plot_nodal_displacement( - "X", smooth_shading=True, show_node_numbering=True + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_disp_plot_subselection(mapdl, static_solve, verify_image_cache): + verify_image_cache.skip = True # skipping image verification + + mapdl.nsel("S", "NODE", vmin=500, vmax=2000, mute=True) + mapdl.esel("S", "ELEM", vmin=500, vmax=2000, mute=True) + assert ( + mapdl.post_processing.plot_nodal_displacement( + "X", smooth_shading=True, show_node_numbering=True + ) + is None + ) + mapdl.allsel() + + @staticmethod + def test_nodal_eqv_stress(mapdl, static_solve): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + mapdl.prnsol("S", "PRIN") # run twice to clear out warning + data = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + seqv_ans = data[:, -1] + seqv = mapdl.post_processing.nodal_eqv_stress() + + seqv_aligned = seqv[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(seqv_ans, seqv_aligned) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_eqv_stress(mapdl, static_solve, verify_image_cache): + verify_image_cache.skip = True # skipping image verification + + assert mapdl.post_processing.plot_nodal_eqv_stress(smooth_shading=True) is None + + @staticmethod + def test_node_selection(mapdl, static_solve): + mapdl.nsel("S", "NODE", vmin=1, vmax=2000, mute=True) + assert mapdl.post_processing.selected_nodes.sum() == 2000 + + mapdl.nsel("all", mute=True) + assert mapdl.post_processing.selected_nodes.sum() == mapdl.mesh.n_node + + @staticmethod + def test_element_selection(mapdl, static_solve): + mx_val = 1000 + mapdl.esel("S", "ELEM", vmin=1, vmax=mx_val, mute=True) + assert mapdl.post_processing.selected_elements.sum() == mx_val + + mapdl.esel("all", mute=True) + assert mapdl.post_processing.selected_elements.sum() == mapdl.mesh.n_elem + + # TODO: add valid result + @staticmethod + @pytest.mark.parametrize("comp", ["X", "Y", "z"]) # lowercase intentional + def test_rot(mapdl, static_solve, comp): + from_grpc = mapdl.post_processing.nodal_rotation(comp) + + # need a result with ROTX DOF + # mapdl.post1(mute=True) + # mapdl.set(1, 1, mute=True) + # nnum, from_prns = np.genfromtxt(mapdl.prnsol('ROT', comp).splitlines()[1:]).T + + # assert np.allclose(mapdl.mesh.nnum, nnum) + # assert np.allclose(from_grpc, from_prns) + assert np.allclose(from_grpc, 0) + + @staticmethod + @requires("ansys-tools-visualization_interface") + @pytest.mark.parametrize("comp", ["X", "Y", "z"]) # lowercase intentional + def test_plot_rot(mapdl, static_solve, comp): + assert mapdl.post_processing.plot_nodal_rotation(comp) is None + + # TODO: add valid result + @staticmethod + def test_temperature(mapdl, static_solve): + from_grpc = mapdl.post_processing.nodal_temperature() + assert np.allclose(from_grpc, 0) + + # TODO: add valid result + @staticmethod + def test_element_temperature(mapdl, static_solve): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + values = mapdl.post_processing.element_temperature() + assert np.allclose(values, 0) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_element_temperature(mapdl, static_solve): + mapdl.set(1, 1, mute=True) + assert mapdl.post_processing.plot_element_temperature() is None + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_temperature(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_temperature() is None + + # TODO: add valid result + @staticmethod + def test_pressure(mapdl, static_solve): + from_grpc = mapdl.post_processing.nodal_pressure() + assert np.allclose(from_grpc, 0) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_pressure(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_pressure() is None + + # TODO: add valid result + @staticmethod + def test_voltage(mapdl, static_solve): + from_grpc = mapdl.post_processing.nodal_voltage() + assert np.allclose(from_grpc, 0) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_voltage(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_voltage() is None + + @staticmethod + @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) + def test_nodal_component_stress(mapdl, static_solve, comp): + from_grpc = mapdl.post_processing.nodal_component_stress(comp) + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + index = COMPONENT_STRESS_TYPE.index(comp) + mapdl.prnsol("S", "COMP") # flush to ignore warning + arr = np.genfromtxt(mapdl.prnsol("S", "COMP").splitlines()[1:]) + nnum_ans = arr[:, 0] + from_prns = arr[:, index + 1] + + # grpc includes all nodes. ignore the ones not included in prnsol + from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] + + assert np.allclose(from_grpc, from_prns) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_component_stress(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_component_stress("X") is None + + @staticmethod + @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) + def test_nodal_principal_stress(mapdl, static_solve, comp): + from_grpc = mapdl.post_processing.nodal_principal_stress(comp) + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + index = PRINCIPAL_TYPE.index(comp) + mapdl.prnsol("S", "PRIN") # flush to ignore warning + arr = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) + nnum_ans = arr[:, 0] + from_prns = arr[:, index + 1] + + # grpc includes all nodes. ignore the ones not included in prnsol + from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] + + assert np.allclose(from_grpc, from_prns) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_principal_stress(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_principal_stress(1) is None + + @staticmethod + def test_nodal_stress_intensity(mapdl, static_solve): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + mapdl.prnsol("S", "PRIN", mute=True) # run twice to clear out warning + data = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + sint_ans = data[:, -2] + sint = mapdl.post_processing.nodal_stress_intensity + + sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(sint_ans, sint_aligned) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_stress_intensity(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_stress_intensity() is None + + @staticmethod + @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) + def test_nodal_total_component_strain(mapdl, static_solve, comp): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + index = COMPONENT_STRESS_TYPE.index(comp) + mapdl.prnsol("EPTO", "COMP", mute=True) # run twice to clear out warning + + data = np.genfromtxt(mapdl.prnsol("EPTO", "COMP").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + data_ans = data[:, index + 1] + data = mapdl.post_processing.nodal_total_component_strain(comp) + data = data[np.in1d(mapdl.mesh.nnum, nnum_ans)] + + assert np.allclose(data_ans, data) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_total_component_strain(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_total_component_strain("x") is None + + @staticmethod + @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) + def test_nodal_principal_total_strain(mapdl, static_solve, comp): + from_grpc = mapdl.post_processing.nodal_total_principal_strain(comp) + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + index = PRINCIPAL_TYPE.index(comp) + mapdl.prnsol("EPTO", "PRIN") # flush to ignore warning + arr = np.genfromtxt(mapdl.prnsol("EPTO", "PRIN").splitlines()[1:]) + nnum_ans = arr[:, 0] + from_prns = arr[:, index + 1] + + # grpc includes all nodes. ignore the ones not included in prnsol + from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] + + assert np.allclose(from_grpc, from_prns) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_principal_total_strain(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_total_principal_strain(1) is None + + @staticmethod + def test_nodal_total_strain_intensity(mapdl, static_solve): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + mapdl.prnsol("EPTO", "PRIN", mute=True) # run twice to clear out warning + data = np.genfromtxt(mapdl.prnsol("EPTO", "PRIN").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + sint_ans = data[:, -2] + sint = mapdl.post_processing.nodal_total_strain_intensity() + + sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(sint_ans, sint_aligned) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_total_strain_intensity(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_total_strain_intensity() is None + + @staticmethod + def test_nodal_total_eqv_strain(mapdl, static_solve): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + mapdl.prnsol("EPTO", "PRIN", mute=True) # run twice to clear out warning + data = np.genfromtxt(mapdl.prnsol("EPTO", "PRIN").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + seqv_ans = data[:, -1] + seqv = mapdl.post_processing.nodal_total_eqv_strain() + + seqv_aligned = seqv[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(seqv_ans, seqv_aligned) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_total_eqv_strain(mapdl, static_solve): + assert ( + mapdl.post_processing.plot_nodal_total_eqv_strain(smooth_shading=True) + is None ) - is None - ) - mapdl.allsel() - - -def test_nodal_eqv_stress(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - mapdl.prnsol("S", "PRIN") # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - seqv_ans = data[:, -1] - seqv = mapdl.post_processing.nodal_eqv_stress() - - seqv_aligned = seqv[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(seqv_ans, seqv_aligned) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_eqv_stress(mapdl, static_solve, verify_image_cache): - verify_image_cache.skip = True # skipping image verification - - assert mapdl.post_processing.plot_nodal_eqv_stress(smooth_shading=True) is None - - -def test_node_selection(mapdl, static_solve): - mapdl.nsel("S", "NODE", vmin=1, vmax=2000, mute=True) - assert mapdl.post_processing.selected_nodes.sum() == 2000 - - mapdl.nsel("all", mute=True) - assert mapdl.post_processing.selected_nodes.sum() == mapdl.mesh.n_node - - -def test_element_selection(mapdl, static_solve): - mx_val = 1000 - mapdl.esel("S", "ELEM", vmin=1, vmax=mx_val, mute=True) - assert mapdl.post_processing.selected_elements.sum() == mx_val - - mapdl.esel("all", mute=True) - assert mapdl.post_processing.selected_elements.sum() == mapdl.mesh.n_elem - - -# TODO: add valid result -@pytest.mark.parametrize("comp", ["X", "Y", "z"]) # lowercase intentional -def test_rot(mapdl, static_solve, comp): - from_grpc = mapdl.post_processing.nodal_rotation(comp) - - # need a result with ROTX DOF - # mapdl.post1(mute=True) - # mapdl.set(1, 1, mute=True) - # nnum, from_prns = np.genfromtxt(mapdl.prnsol('ROT', comp).splitlines()[1:]).T - - # assert np.allclose(mapdl.mesh.nnum, nnum) - # assert np.allclose(from_grpc, from_prns) - assert np.allclose(from_grpc, 0) - - -@pytest.mark.parametrize("comp", ["X", "Y", "z"]) # lowercase intentional -@requires("ansys-tools-visualization_interface") -def test_plot_rot(mapdl, static_solve, comp): - assert mapdl.post_processing.plot_nodal_rotation(comp) is None - - -# TODO: add valid result -def test_temperature(mapdl, static_solve): - from_grpc = mapdl.post_processing.nodal_temperature() - assert np.allclose(from_grpc, 0) - - -# TODO: add valid result -def test_element_temperature(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - values = mapdl.post_processing.element_temperature() - assert np.allclose(values, 0) - - -@requires("ansys-tools-visualization_interface") -def test_plot_element_temperature(mapdl, static_solve): - mapdl.set(1, 1, mute=True) - assert mapdl.post_processing.plot_element_temperature() is None - - -@requires("ansys-tools-visualization_interface") -def test_plot_temperature(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_temperature() is None - - -# TODO: add valid result -def test_pressure(mapdl, static_solve): - from_grpc = mapdl.post_processing.nodal_pressure() - assert np.allclose(from_grpc, 0) - - -@requires("ansys-tools-visualization_interface") -def test_plot_pressure(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_pressure() is None - - -# TODO: add valid result -def test_voltage(mapdl, static_solve): - from_grpc = mapdl.post_processing.nodal_voltage() - assert np.allclose(from_grpc, 0) - - -@requires("ansys-tools-visualization_interface") -def test_plot_voltage(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_voltage() is None - - -@pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) -def test_nodal_component_stress(mapdl, static_solve, comp): - from_grpc = mapdl.post_processing.nodal_component_stress(comp) - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - index = COMPONENT_STRESS_TYPE.index(comp) - mapdl.prnsol("S", "COMP") # flush to ignore warning - arr = np.genfromtxt(mapdl.prnsol("S", "COMP").splitlines()[1:]) - nnum_ans = arr[:, 0] - from_prns = arr[:, index + 1] - - # grpc includes all nodes. ignore the ones not included in prnsol - from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(from_grpc, from_prns) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_component_stress(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_component_stress("X") is None - - -@pytest.mark.parametrize("comp", PRINCIPAL_TYPE) -def test_nodal_principal_stress(mapdl, static_solve, comp): - from_grpc = mapdl.post_processing.nodal_principal_stress(comp) - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - index = PRINCIPAL_TYPE.index(comp) - mapdl.prnsol("S", "PRIN") # flush to ignore warning - arr = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) - nnum_ans = arr[:, 0] - from_prns = arr[:, index + 1] - - # grpc includes all nodes. ignore the ones not included in prnsol - from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(from_grpc, from_prns) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_principal_stress(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_principal_stress(1) is None - - -def test_nodal_stress_intensity(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - mapdl.prnsol("S", "PRIN", mute=True) # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - sint_ans = data[:, -2] - sint = mapdl.post_processing.nodal_stress_intensity - - sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(sint_ans, sint_aligned) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_stress_intensity(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_stress_intensity() is None - - -@pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) -def test_nodal_total_component_strain(mapdl, static_solve, comp): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - index = COMPONENT_STRESS_TYPE.index(comp) - mapdl.prnsol("EPTO", "COMP", mute=True) # run twice to clear out warning - - data = np.genfromtxt(mapdl.prnsol("EPTO", "COMP").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - data_ans = data[:, index + 1] - data = mapdl.post_processing.nodal_total_component_strain(comp) - data = data[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(data_ans, data) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_total_component_strain(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_total_component_strain("x") is None - - -@pytest.mark.parametrize("comp", PRINCIPAL_TYPE) -def test_nodal_principal_total_strain(mapdl, static_solve, comp): - from_grpc = mapdl.post_processing.nodal_total_principal_strain(comp) - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - index = PRINCIPAL_TYPE.index(comp) - mapdl.prnsol("EPTO", "PRIN") # flush to ignore warning - arr = np.genfromtxt(mapdl.prnsol("EPTO", "PRIN").splitlines()[1:]) - nnum_ans = arr[:, 0] - from_prns = arr[:, index + 1] - - # grpc includes all nodes. ignore the ones not included in prnsol - from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(from_grpc, from_prns) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_principal_total_strain(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_total_principal_strain(1) is None - - -def test_nodal_total_strain_intensity(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - mapdl.prnsol("EPTO", "PRIN", mute=True) # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("EPTO", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - sint_ans = data[:, -2] - sint = mapdl.post_processing.nodal_total_strain_intensity() - - sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(sint_ans, sint_aligned) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_total_strain_intensity(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_total_strain_intensity() is None - - -def test_nodal_total_eqv_strain(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - mapdl.prnsol("EPTO", "PRIN", mute=True) # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("EPTO", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - seqv_ans = data[:, -1] - seqv = mapdl.post_processing.nodal_total_eqv_strain() - - seqv_aligned = seqv[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(seqv_ans, seqv_aligned) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_total_eqv_strain(mapdl, static_solve): - assert ( - mapdl.post_processing.plot_nodal_total_eqv_strain(smooth_shading=True) is None - ) - - -############################################################################### -@pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) -def test_nodal_component_stress(mapdl, static_solve, comp): - from_grpc = mapdl.post_processing.nodal_component_stress(comp) - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - index = COMPONENT_STRESS_TYPE.index(comp) - mapdl.prnsol("S", "COMP") # flush to ignore warning - arr = np.genfromtxt(mapdl.prnsol("S", "COMP").splitlines()[1:]) - nnum_ans = arr[:, 0] - from_prns = arr[:, index + 1] - - # grpc includes all nodes. ignore the ones not included in prnsol - from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(from_grpc, from_prns) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_component_stress(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_component_stress("X") is None - - -@pytest.mark.parametrize("comp", PRINCIPAL_TYPE) -def test_nodal_principal_stress(mapdl, static_solve, comp): - from_grpc = mapdl.post_processing.nodal_principal_stress(comp) - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - index = PRINCIPAL_TYPE.index(comp) - mapdl.prnsol("S", "PRIN") # flush to ignore warning - arr = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) - nnum_ans = arr[:, 0] - from_prns = arr[:, index + 1] - - # grpc includes all nodes. ignore the ones not included in prnsol - from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(from_grpc, from_prns, atol=1e-5) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_principal_stress(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_principal_stress(1) is None - - -def test_nodal_stress_intensity(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - mapdl.prnsol("S", "PRIN", mute=True) # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - sint_ans = data[:, -2] - sint = mapdl.post_processing.nodal_stress_intensity() - - sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(sint_ans, sint_aligned) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_stress_intensity(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_stress_intensity() is None - - -@pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) -def test_nodal_elastic_component_strain(mapdl, static_solve, comp): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - index = COMPONENT_STRESS_TYPE.index(comp) - mapdl.prnsol("EPEL", "COMP", mute=True) # run twice to clear out warning - - data = np.genfromtxt(mapdl.prnsol("EPEL", "COMP").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - data_ans = data[:, index + 1] - data = mapdl.post_processing.nodal_elastic_component_strain(comp) - data = data[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(data_ans, data) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_elastic_component_strain(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_elastic_component_strain("x") is None - - -@pytest.mark.parametrize("comp", PRINCIPAL_TYPE) -def test_nodal_elastic_principal_strain(mapdl, static_solve, comp): - from_grpc = mapdl.post_processing.nodal_elastic_principal_strain(comp) - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - index = PRINCIPAL_TYPE.index(comp) - mapdl.prnsol("EPEL", "PRIN") # flush to ignore warning - arr = np.genfromtxt(mapdl.prnsol("EPEL", "PRIN").splitlines()[1:]) - nnum_ans = arr[:, 0] - from_prns = arr[:, index + 1] - - # grpc includes all nodes. ignore the ones not included in prnsol - from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(from_grpc, from_prns) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_elastic_principal_strain(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_elastic_principal_strain(1) is None - - -def test_nodal_elastic_strain_intensity(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - mapdl.prnsol("EPEL", "PRIN", mute=True) # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("EPEL", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - sint_ans = data[:, -2] - sint = mapdl.post_processing.nodal_elastic_strain_intensity() - - sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(sint_ans, sint_aligned) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_elastic_strain_intensity(mapdl, static_solve): - assert mapdl.post_processing.plot_nodal_elastic_strain_intensity() is None - - -def test_nodal_elastic_eqv_strain(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - mapdl.prnsol("EPEL", "PRIN", mute=True) # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("EPEL", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - seqv_ans = data[:, -1] - seqv = mapdl.post_processing.nodal_elastic_eqv_strain() - - seqv_aligned = seqv[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(seqv_ans, seqv_aligned) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_elastic_eqv_strain(mapdl, static_solve): - assert ( - mapdl.post_processing.plot_nodal_elastic_eqv_strain(smooth_shading=True) is None - ) - - -@pytest.mark.parametrize("comp", ["X", "Y", "z"]) # lowercase intentional -def test_elem_disp(mapdl, static_solve, comp): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - mapdl.allsel() - - disp_from_grpc = mapdl.post_processing.element_displacement(comp) - - # use pretab to get the data - table_name = "values" - mapdl.etable(table_name, "U", comp, mute=True) - arr = np.genfromtxt(mapdl.pretab(table_name).splitlines()[1:])[:, 1] - assert np.allclose(arr, disp_from_grpc) - - -@pytest.mark.parametrize("option", ["min", "max", "avg"]) -def test_elem_disp_all(mapdl, static_solve, option): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - - disp_from_grpc = mapdl.post_processing.element_displacement("ALL", option) - - # use pretab to get the data - arrays = [] - for comp in ["x", "y", "z"]: - table_name = "values" + comp - mapdl.etable(table_name, "U", comp, option=option, mute=True) - arrays.append(np.genfromtxt(mapdl.pretab(table_name).splitlines()[1:])[:, 1]) - array = np.vstack(arrays).T - assert np.allclose(array, disp_from_grpc) - - -def test_elem_disp_norm(mapdl, static_solve): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - disp = mapdl.post_processing.element_displacement("ALL") - norm_disp = np.linalg.norm(disp, axis=1) - disp_from_grpc = mapdl.post_processing.element_displacement("NORM") - assert np.allclose(norm_disp, disp_from_grpc) - - -@pytest.mark.parametrize("comp", ["X", "Y", "Z", "NORM"]) -@requires("ansys-tools-visualization_interface") -def test_elem_disp_plot(mapdl, static_solve, comp): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - assert mapdl.post_processing.plot_element_displacement(comp) is None - - -@pytest.mark.parametrize("component", STRESS_TYPES[::3]) -@pytest.mark.parametrize("option", ["min", "max", "avg"]) -def test_element_stress(mapdl, static_solve, component, option): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - stress = mapdl.post_processing.element_stress(component, option) - - # use pretab to get the data - table_name = "values" + component - mapdl.etable(table_name, "S", component, option=option, mute=True) - from_pretab = np.genfromtxt(mapdl.pretab(table_name).splitlines()[1:])[:, 1] - assert np.allclose(stress, from_pretab) + ############################################################################### + @staticmethod + @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) + def test_nodal_component_stress(mapdl, static_solve, comp): + from_grpc = mapdl.post_processing.nodal_component_stress(comp) + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + index = COMPONENT_STRESS_TYPE.index(comp) + mapdl.prnsol("S", "COMP") # flush to ignore warning + arr = np.genfromtxt(mapdl.prnsol("S", "COMP").splitlines()[1:]) + nnum_ans = arr[:, 0] + from_prns = arr[:, index + 1] + + # grpc includes all nodes. ignore the ones not included in prnsol + from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] + + assert np.allclose(from_grpc, from_prns) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_component_stress(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_component_stress("X") is None + + @staticmethod + @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) + def test_nodal_principal_stress(mapdl, static_solve, comp): + from_grpc = mapdl.post_processing.nodal_principal_stress(comp) + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + index = PRINCIPAL_TYPE.index(comp) + mapdl.prnsol("S", "PRIN") # flush to ignore warning + arr = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) + nnum_ans = arr[:, 0] + from_prns = arr[:, index + 1] + + # grpc includes all nodes. ignore the ones not included in prnsol + from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(from_grpc, from_prns, atol=1e-5) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_principal_stress(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_principal_stress(1) is None + + @staticmethod + def test_nodal_stress_intensity(mapdl, static_solve): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + mapdl.prnsol("S", "PRIN", mute=True) # run twice to clear out warning + data = np.genfromtxt(mapdl.prnsol("S", "PRIN").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + sint_ans = data[:, -2] + sint = mapdl.post_processing.nodal_stress_intensity() + + sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(sint_ans, sint_aligned) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_stress_intensity(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_stress_intensity() is None + + @staticmethod + @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) + def test_nodal_elastic_component_strain(mapdl, static_solve, comp): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + index = COMPONENT_STRESS_TYPE.index(comp) + mapdl.prnsol("EPEL", "COMP", mute=True) # run twice to clear out warning + + data = np.genfromtxt(mapdl.prnsol("EPEL", "COMP").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + data_ans = data[:, index + 1] + data = mapdl.post_processing.nodal_elastic_component_strain(comp) + data = data[np.in1d(mapdl.mesh.nnum, nnum_ans)] + + assert np.allclose(data_ans, data) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_elastic_component_strain(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_elastic_component_strain("x") is None + + @staticmethod + @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) + def test_nodal_elastic_principal_strain(mapdl, static_solve, comp): + from_grpc = mapdl.post_processing.nodal_elastic_principal_strain(comp) + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + index = PRINCIPAL_TYPE.index(comp) + mapdl.prnsol("EPEL", "PRIN") # flush to ignore warning + arr = np.genfromtxt(mapdl.prnsol("EPEL", "PRIN").splitlines()[1:]) + nnum_ans = arr[:, 0] + from_prns = arr[:, index + 1] + + # grpc includes all nodes. ignore the ones not included in prnsol + from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] + + assert np.allclose(from_grpc, from_prns) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_elastic_principal_strain(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_elastic_principal_strain(1) is None + + @staticmethod + def test_nodal_elastic_strain_intensity(mapdl, static_solve): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + mapdl.prnsol("EPEL", "PRIN", mute=True) # run twice to clear out warning + data = np.genfromtxt(mapdl.prnsol("EPEL", "PRIN").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + sint_ans = data[:, -2] + sint = mapdl.post_processing.nodal_elastic_strain_intensity() + + sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(sint_ans, sint_aligned) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_elastic_strain_intensity(mapdl, static_solve): + assert mapdl.post_processing.plot_nodal_elastic_strain_intensity() is None + + @staticmethod + def test_nodal_elastic_eqv_strain(mapdl, static_solve): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + mapdl.prnsol("EPEL", "PRIN", mute=True) # run twice to clear out warning + data = np.genfromtxt(mapdl.prnsol("EPEL", "PRIN").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + seqv_ans = data[:, -1] + seqv = mapdl.post_processing.nodal_elastic_eqv_strain() + + seqv_aligned = seqv[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(seqv_ans, seqv_aligned) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_elastic_eqv_strain(mapdl, static_solve): + assert ( + mapdl.post_processing.plot_nodal_elastic_eqv_strain(smooth_shading=True) + is None + ) -@pytest.mark.parametrize("comp", ["X", "1", "INT", "EQV"]) -@requires("ansys-tools-visualization_interface") -def test_plot_element_stress(mapdl, static_solve, comp): - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - assert mapdl.post_processing.plot_element_stress(comp) is None + @staticmethod + @pytest.mark.parametrize("comp", ["X", "Y", "z"]) # lowercase intentional + def test_elem_disp(mapdl, static_solve, comp): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + mapdl.allsel() + + disp_from_grpc = mapdl.post_processing.element_displacement(comp) + + # use pretab to get the data + table_name = "values" + mapdl.etable(table_name, "U", comp, mute=True) + arr = np.genfromtxt(mapdl.pretab(table_name).splitlines()[1:])[:, 1] + assert np.allclose(arr, disp_from_grpc) + + @staticmethod + @pytest.mark.parametrize("option", ["min", "max", "avg"]) + def test_elem_disp_all(mapdl, static_solve, option): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + + disp_from_grpc = mapdl.post_processing.element_displacement("ALL", option) + + # use pretab to get the data + arrays = [] + for comp in ["x", "y", "z"]: + table_name = "values" + comp + mapdl.etable(table_name, "U", comp, option=option, mute=True) + arrays.append( + np.genfromtxt(mapdl.pretab(table_name).splitlines()[1:])[:, 1] + ) + array = np.vstack(arrays).T + assert np.allclose(array, disp_from_grpc) + + @staticmethod + def test_elem_disp_norm(mapdl, static_solve): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + disp = mapdl.post_processing.element_displacement("ALL") + norm_disp = np.linalg.norm(disp, axis=1) + disp_from_grpc = mapdl.post_processing.element_displacement("NORM") + assert np.allclose(norm_disp, disp_from_grpc) + + @staticmethod + @pytest.mark.parametrize("comp", ["X", "Y", "Z", "NORM"]) + @requires("ansys-tools-visualization_interface") + def test_elem_disp_plot(mapdl, static_solve, comp): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + assert mapdl.post_processing.plot_element_displacement(comp) is None + + @staticmethod + @pytest.mark.parametrize("component", STRESS_TYPES[::3]) + @pytest.mark.parametrize("option", ["min", "max", "avg"]) + def test_element_stress(mapdl, static_solve, component, option): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + stress = mapdl.post_processing.element_stress(component, option) + + # use pretab to get the data + table_name = "values" + component + mapdl.etable(table_name, "S", component, option=option, mute=True) + from_pretab = np.genfromtxt(mapdl.pretab(table_name).splitlines()[1:])[:, 1] + assert np.allclose(stress, from_pretab) + + @staticmethod + @pytest.mark.parametrize("comp", ["X", "1", "INT", "EQV"]) + @requires("ansys-tools-visualization_interface") + def test_plot_element_stress(mapdl, static_solve, comp): + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + assert mapdl.post_processing.plot_element_stress(comp) is None + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_element_values(mapdl, static_solve, verify_image_cache): + verify_image_cache.high_variance_test = 600 + mapdl.post1(mute=True) + mapdl.set(1, 1, mute=True) + assert mapdl.post_processing.plot_element_values("S", "X") is None + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_general_plotter_returns(mapdl, static_solve, verify_image_cache): + verify_image_cache.skip = True # skipping image verification + + # Returns + + assert ( + mapdl.post_processing.plot_nodal_displacement("X", smooth_shading=True) + is None + ) + assert isinstance( + mapdl.post_processing.plot_nodal_displacement( + "X", smooth_shading=True, return_cpos=True + ), + CameraPosition, + ) + p = mapdl.post_processing.plot_nodal_displacement( + "X", smooth_shading=True, return_plotter=True + ) + assert isinstance(p, MapdlPlotter) + p.show() + + with pytest.raises(ValueError): + mapdl.post_processing.plot_nodal_displacement( + "X", smooth_shading=True, return_cpos=True, return_plotter=True + ) + + # Returns + Save figure. + assert ( + mapdl.post_processing.plot_nodal_displacement( + "X", + smooth_shading=True, + savefig=True, + return_cpos=False, + return_plotter=False, + ) + is None + ) + assert isinstance( + mapdl.post_processing.plot_nodal_displacement( + "X", + smooth_shading=True, + savefig=True, + return_cpos=True, + return_plotter=False, + ), + CameraPosition, + ) -@requires("ansys-tools-visualization_interface") -def test_plot_element_values(mapdl, static_solve, verify_image_cache): - verify_image_cache.high_variance_test = 600 - mapdl.post1(mute=True) - mapdl.set(1, 1, mute=True) - assert mapdl.post_processing.plot_element_values("S", "X") is None + p = mapdl.post_processing.plot_nodal_displacement( + "X", + smooth_shading=True, + savefig=True, + return_cpos=False, + return_plotter=True, + ) + assert isinstance(p, MapdlPlotter) ############################################################################### -@pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) -def test_nodal_plastic_component_strain(mapdl, plastic_solve, comp): - index = COMPONENT_STRESS_TYPE.index(comp) - mapdl.prnsol("EPPL", "COMP", mute=True) # run twice to clear out warning - - data = np.genfromtxt(mapdl.prnsol("EPPL", "COMP").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - data_ans = data[:, index + 1] - data = mapdl.post_processing.nodal_plastic_component_strain(comp) - data = data[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(data_ans, data) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_plastic_component_strain(mapdl, plastic_solve): - assert mapdl.post_processing.plot_nodal_plastic_component_strain("x") is None - - -@pytest.mark.parametrize("comp", PRINCIPAL_TYPE) -def test_nodal_plastic_principal_strain(mapdl, plastic_solve, comp): - from_grpc = mapdl.post_processing.nodal_plastic_principal_strain(comp) - - index = PRINCIPAL_TYPE.index(comp) - mapdl.prnsol("EPPL", "PRIN") # flush to ignore warning - arr = np.genfromtxt(mapdl.prnsol("EPPL", "PRIN").splitlines()[1:]) - nnum_ans = arr[:, 0] - from_prns = arr[:, index + 1] - - # grpc includes all nodes. ignore the ones not included in prnsol - from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] - - assert np.allclose(from_grpc, from_prns) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_plastic_principal_strain(mapdl, plastic_solve): - assert mapdl.post_processing.plot_nodal_plastic_principal_strain(1) is None - - -def test_nodal_plastic_strain_intensity(mapdl, plastic_solve): - mapdl.prnsol("EPPL", "PRIN", mute=True) # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("EPPL", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - sint_ans = data[:, -2] - sint = mapdl.post_processing.nodal_plastic_strain_intensity() - - sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(sint_ans, sint_aligned) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_plastic_strain_intensity(mapdl, plastic_solve): - assert mapdl.post_processing.plot_nodal_plastic_strain_intensity() is None - - -def test_nodal_plastic_eqv_strain(mapdl, plastic_solve): - mapdl.prnsol("EPPL", "PRIN", mute=True) # run twice to clear out warning - data = np.genfromtxt(mapdl.prnsol("EPPL", "PRIN").splitlines()[1:]) - nnum_ans = data[:, 0].astype(np.int32) - seqv_ans = data[:, -1] - seqv = mapdl.post_processing.nodal_plastic_eqv_strain() - - seqv_aligned = seqv[np.in1d(mapdl.mesh.nnum, nnum_ans)] - assert np.allclose(seqv_ans, seqv_aligned) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_plastic_eqv_strain(mapdl, plastic_solve): - assert ( - mapdl.post_processing.plot_nodal_plastic_eqv_strain(smooth_shading=True) is None - ) - - -def test_nodal_contact_friction_stress(mapdl, contact_solve): - # Format tables. - mapdl.post1() - mapdl.header("OFF", "OFF", "OFF", "OFF", "OFF", "OFF") - nsigfig = 10 - mapdl.format("", "E", nsigfig + 9, nsigfig) - mapdl.page(1e9, "", -1, 240) - - prnsol = mapdl.prnsol("CONT") - array = np.genfromtxt(prnsol.splitlines(), skip_header=1) - sfric_prn = array[:, 4] - nodes = array[:, 0] - - index = nodes.astype(int) - 1 # -1 to convert apdl node number to python index. - sfric_nod = mapdl.post_processing.nodal_contact_friction_stress()[index] - - assert np.allclose(sfric_prn, sfric_nod) - - -@requires("ansys-tools-visualization_interface") -def test_plot_nodal_contact_friction_stress(mapdl, contact_solve): - assert ( - mapdl.post_processing.plot_nodal_contact_friction_stress(smooth_shading=True) - is None - ) - - -@requires("ansys-tools-visualization_interface") -def test_plot_incomplete_element_selection(mapdl, contact_solve): - mapdl.esel("S", "ELEM", "", 1, mapdl.mesh.n_elem // 2) - assert mapdl.post_processing.plot_element_displacement() is None - - mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_elem // 2, 2) - assert mapdl.post_processing.plot_element_displacement() is None +class Test_plastic_solve: + + @staticmethod + @pytest.fixture(scope="class") + def plastic_solve(mapdl): + mapdl.mute = True + mapdl.finish() + mapdl.clear() + mapdl.input(examples.verif_files.vmfiles["vm273"]) + + mapdl.post1() + mapdl.set(1, 2) + mapdl.mute = False + + @staticmethod + @pytest.mark.parametrize("comp", COMPONENT_STRESS_TYPE) + def test_nodal_plastic_component_strain(mapdl, plastic_solve, comp): + index = COMPONENT_STRESS_TYPE.index(comp) + mapdl.prnsol("EPPL", "COMP", mute=True) # run twice to clear out warning + + data = np.genfromtxt(mapdl.prnsol("EPPL", "COMP").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + data_ans = data[:, index + 1] + data = mapdl.post_processing.nodal_plastic_component_strain(comp) + data = data[np.in1d(mapdl.mesh.nnum, nnum_ans)] + + assert np.allclose(data_ans, data) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_plastic_component_strain(mapdl, plastic_solve): + assert mapdl.post_processing.plot_nodal_plastic_component_strain("x") is None + + @staticmethod + @pytest.mark.parametrize("comp", PRINCIPAL_TYPE) + def test_nodal_plastic_principal_strain(mapdl, plastic_solve, comp): + from_grpc = mapdl.post_processing.nodal_plastic_principal_strain(comp) + + index = PRINCIPAL_TYPE.index(comp) + mapdl.prnsol("EPPL", "PRIN") # flush to ignore warning + arr = np.genfromtxt(mapdl.prnsol("EPPL", "PRIN").splitlines()[1:]) + nnum_ans = arr[:, 0] + from_prns = arr[:, index + 1] + + # grpc includes all nodes. ignore the ones not included in prnsol + from_grpc = from_grpc[np.in1d(mapdl.mesh.nnum, nnum_ans)] + + assert np.allclose(from_grpc, from_prns) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_plastic_principal_strain(mapdl, plastic_solve): + assert mapdl.post_processing.plot_nodal_plastic_principal_strain(1) is None + + @staticmethod + def test_nodal_plastic_strain_intensity(mapdl, plastic_solve): + mapdl.prnsol("EPPL", "PRIN", mute=True) # run twice to clear out warning + data = np.genfromtxt(mapdl.prnsol("EPPL", "PRIN").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + sint_ans = data[:, -2] + sint = mapdl.post_processing.nodal_plastic_strain_intensity() + + sint_aligned = sint[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(sint_ans, sint_aligned) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_plastic_strain_intensity(mapdl, plastic_solve): + assert mapdl.post_processing.plot_nodal_plastic_strain_intensity() is None + + @staticmethod + def test_nodal_plastic_eqv_strain(mapdl, plastic_solve): + mapdl.prnsol("EPPL", "PRIN", mute=True) # run twice to clear out warning + data = np.genfromtxt(mapdl.prnsol("EPPL", "PRIN").splitlines()[1:]) + nnum_ans = data[:, 0].astype(np.int32) + seqv_ans = data[:, -1] + seqv = mapdl.post_processing.nodal_plastic_eqv_strain() + + seqv_aligned = seqv[np.in1d(mapdl.mesh.nnum, nnum_ans)] + assert np.allclose(seqv_ans, seqv_aligned) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_plastic_eqv_strain(mapdl, plastic_solve): + assert ( + mapdl.post_processing.plot_nodal_plastic_eqv_strain(smooth_shading=True) + is None + ) - mapdl.nsel("S", "NODE", "", 5, mapdl.mesh.n_elem // 2, 2) - assert mapdl.post_processing.plot_element_displacement() is None - mapdl.vsel("s", "", "", 1) - mapdl.eslv("s") - assert mapdl.post_processing.plot_element_displacement() is None +class Test_contact_solve: + + @staticmethod + @pytest.fixture(scope="class") + def contact_solve(mapdl): + mapdl.mute = True + mapdl.finish() + mapdl.clear() + + # Based on tech demo 28. + mapdl.prep7() + # ***** Problem parameters ******** + l = 76.2e-03 / 3 # Length of each plate,m + w = 31.75e-03 / 2 # Width of each plate,m + t = 3.18e-03 # Thickness of each plate,m + r1 = 7.62e-03 # Shoulder radius of tool,m + h = 15.24e-03 # Height of tool, m + l1 = r1 # Starting location of tool on weldline + l2 = l - l1 + tcc1 = 2e06 # Thermal contact conductance b/w plates,W/m^2'C + tcc2 = 10 # Thermal contact conductance b/w tool & + # workpiece,W/m^2'C + fwgt = 0.95 # weight factor for distribution of heat b/w tool + # & workpiece + fplw = 0.8 # Fraction of plastic work converted to heat + + # this is also modified in the dependent fixture + uz1 = t / 4000 # Depth of penetration,m + + # ========================================================== + # * Material properties + # ========================================================== + # * Material properties for 304l stainless steel Plates + mapdl.mp("ex", 1, 193e9) # Elastic modulus (N/m^2) + mapdl.mp("nuxy", 1, 0.3) # Poisson's ratio + mapdl.mp("alpx", 1, 1.875e-5) # Coefficient of thermal expansion, µm/m'c + # Fraction of plastic work converted to heat, 80% + mapdl.mp("qrate", 1, fplw) + + # *BISO material model + EX = 193e9 + ET = 2.8e9 + EP = EX * ET / (EX - ET) + mapdl.tb("plas", 1, 1, "", "biso") # Bilinear isotropic material + mapdl.tbdata(1, 290e6, EP) # Yield stress & plastic tangent modulus + mapdl.mptemp(1, 0, 200, 400, 600, 800, 1000) + mapdl.mpdata("kxx", 1, 1, 16, 19, 21, 24, 29, 30) # therm cond.(W/m'C) + mapdl.mpdata("c", 1, 1, 500, 540, 560, 590, 600, 610) # spec heat(J/kg'C) + mapdl.mpdata("dens", 1, 1, 7894, 7744, 7631, 7518, 7406, 7406) # kg/m^3 + + # * Material properties for PCBN tool + mapdl.mp("ex", 2, 680e9) # Elastic modulus (N/m^2) + mapdl.mp("nuxy", 2, 0.22) # Poisson's ratio + mapdl.mp("kxx", 2, 100) # Thermal conductivity(W/m'C) + mapdl.mp("c", 2, 750) # Specific heat(J/kg'C) + mapdl.mp("dens", 2, 4280) # Density,kg/m^3 + + # ========================================================== + # * Geometry + # ========================================================== + # * Node for pilot node + mapdl.n(1, 0, 0, h) + # * Workpiece geometry (two rectangular plates) + mapdl.block(0, w, -l1, l2, 0, -t) + mapdl.block(0, -w, -l1, l2, 0, -t) + # * Tool geometry + mapdl.cyl4(0, 0, r1, 0, r1, 90, h) + mapdl.cyl4(0, 0, r1, 90, r1, 180, h) + mapdl.cyl4(0, 0, r1, 180, r1, 270, h) + mapdl.cyl4(0, 0, r1, 270, r1, 360, h) + mapdl.vglue(3, 4, 5, 6) + + # ========================================================== + # * Meshing + # ========================================================== + mapdl.et(1, "SOLID226", 11) # Coupled-field solid element,KEYOPT(1) is + # set to 11 for a structural-thermal analysis + mapdl.allsel() + ndiv1 = 2 + ndiv2 = 5 + ndiv3 = 1 + + mapdl.lsel("s", "", "", 4, 5) + mapdl.lsel("a", "", "", 14, 19, 5) + mapdl.lesize("all", "", "", ndiv1) + mapdl.lsel("s", "", "", 16, 17) + mapdl.lsel("a", "", "", 2, 7, 5) + mapdl.lesize("all", "", "", ndiv1) + mapdl.lsel("s", "", "", 1) + mapdl.lsel("a", "", "", 3) + mapdl.lsel("a", "", "", 6) + mapdl.lsel("a", "", "", 8) + mapdl.lsel("a", "", "", 13) + mapdl.lsel("a", "", "", 15) + mapdl.lsel("a", "", "", 18) + mapdl.lsel("a", "", "", 20) + mapdl.lesize("all", "", "", ndiv2) + mapdl.lsel("s", "", "", 9, "") + mapdl.lsel("a", "", "", 22) + mapdl.lesize("all", "", "", ndiv3) + mapdl.allsel("all") + mapdl.mshmid(2) # midside nodes dropped + mapdl.vsweep(1) + mapdl.vsweep(2) + mapdl.vsel("u", "volume", "", 1, 2) + mapdl.mat(2) + mapdl.esize(0.005) + mapdl.numstr("NODE", 1000) + mapdl.vsweep("all") + mapdl.allsel("all") + + # ========================================================== + # * Contact Pairs + # ========================================================== + # * Define Rigid Surface Constraint on tool top surface + mapdl.et(2, "TARGE170") + mapdl.keyopt(2, 2, 1) # User defined boundary condition on rigid + # target nodes + + mapdl.et(3, "CONTA174") + mapdl.keyopt(3, 1, 1) # To include Temp DOF + mapdl.keyopt(3, 2, 2) # To include MPC contact algorithm + mapdl.keyopt(3, 4, 2) # For a rigid surface constraint + mapdl.keyopt(3, 12, 5) # To set the behavior of contact surface as a + # bonded (always) + + mapdl.vsel("u", "volume", "", 1, 2) # Selecting Tool volume + mapdl.allsel("below", "volume") + mapdl.nsel("r", "loc", "z", h) # Selecting nodes on the tool top surface + mapdl.type(3) + mapdl.r(3) + mapdl.real(3) + mapdl.esln() + mapdl.esurf() # Create contact elements + mapdl.allsel("all") + + # * Define pilot node at the top of the tool + mapdl.nsel("s", "node", "", 1) + mapdl.tshap("pilo") + mapdl.type(2) + mapdl.real(3) + mapdl.e(1) # Create target element on pilot node + mapdl.allsel() + + # * Define contact pair between two plates + mapdl.et(6, "TARGE170") + mapdl.et(7, "CONTA174") + mapdl.keyopt(7, 1, 1) # Displacement & Temp dof + mapdl.keyopt(7, 4, 3) # To include Surface projection based method + mapdl.mat(1) + mapdl.asel("s", "", "", 5) + mapdl.nsla("", 1) + mapdl.cm("tn.cnt", "node") # Creating component on weld side of plate1 + + mapdl.asel("s", "", "", 12) + mapdl.nsla("", 1) + mapdl.cm("tn.tgt", "node") # Creating component on weld side of plate2 + + mapdl.allsel("all") + mapdl.type(6) + mapdl.r(6) + mapdl.rmodif(6, 14, tcc1) # A real constant TCC,Thermal contact + # conductance coeffi. b/w the plates, W/m^2'C + mapdl.rmodif(6, 35, 1000) # A real constant TBND,Bonding temperature + # for welding, 'C + mapdl.real(6) + mapdl.cmsel("s", "tn.cnt") + mapdl.esurf() + mapdl.type(7) + mapdl.real(6) + mapdl.cmsel("s", "tn.tgt") + mapdl.esurf() + mapdl.allsel("all") + + # * Define contact pair between tool & workpiece + mapdl.et(4, "TARGE170") + mapdl.et(5, "CONTA174") + mapdl.keyopt(5, 1, 1) # Displacement & Temp dof + mapdl.keyopt(5, 5, 3) # Close gap/reduce penetration with auto cnof + mapdl.keyopt(5, 9, 1) # Exclude both initial penetration or gap + mapdl.keyopt(5, 10, 0) # Contact stiffness update each iteration + # based + + # Bottom & lateral(all except top) surfaces of tool for target + mapdl.vsel("u", "volume", "", 1, 2) + mapdl.allsel("below", "volume") + mapdl.nsel("r", "loc", "z", 0, h) + mapdl.nsel("u", "loc", "z", h) + mapdl.type(4) + mapdl.r(5) + mapdl.tb("fric", 5, 6) # Definition of friction co efficient at + # different temp + mapdl.tbtemp(25) + mapdl.tbdata(1, 0.4) # friction co-efficient at temp 25 + mapdl.tbtemp(200) + mapdl.tbdata(1, 0.4) # friction co-efficient at temp 200 + mapdl.tbtemp(400) + mapdl.tbdata(1, 0.4) # friction co-efficient at temp 400 + mapdl.tbtemp(600) + mapdl.tbdata(1, 0.3) # friction co-efficient at temp 600 + mapdl.tbtemp(800) + mapdl.tbdata(1, 0.3) # friction co-efficient at temp 800 + mapdl.tbtemp(1000) + mapdl.tbdata(1, 0.2) # friction co-efficient at temp 1000 + mapdl.rmodif(5, 9, 500e6) # Max.friction stress + mapdl.rmodif(5, 14, tcc2) # Thermal contact conductance b/w tool and + # workpiece, 10 W/m^2'C + mapdl.rmodif(5, 15, 1) # A real constant FHTG,the fraction of + # frictional dissipated energy converted + # into heat + mapdl.rmodif(5, 18, fwgt) # A real constant FWGT, weight factor for + # the distribution of heat between the + # contact and target surfaces, 0.95 + mapdl.real(5) + mapdl.mat(5) + mapdl.esln() + mapdl.esurf() + mapdl.allsel("all") + + # Top surfaces of plates nodes for contact + mapdl.vsel("s", "volume", "", 1, 2) + mapdl.allsel("below", "volume") + mapdl.nsel("r", "loc", "z", 0) + mapdl.type(5) + mapdl.real(5) + mapdl.esln() + mapdl.esurf() + mapdl.allsel("all") + + # ========================================================== + # * Boundary conditions + # ========================================================== + mapdl.tref(25) # Reference temperature 25'C + mapdl.allsel() + mapdl.nsel("all") + mapdl.ic("all", "temp", 25) # Initial condition at nodes,temp 25'C + + # Mechanical Boundary Conditions + # 20% ends of the each plate is constraint + mapdl.nsel("s", "loc", "x", -0.8 * w, -w) + mapdl.nsel("a", "loc", "x", 0.8 * w, w) + mapdl.d("all", "uz", 0) # Displacement constraint in x-direction + mapdl.d("all", "uy", 0) # Displacement constraint in y-direction + mapdl.d("all", "ux", 0) # Displacement constraint in z-direction + mapdl.allsel("all") + + # Bottom of workpiece is constraint in z-direction + mapdl.nsel("s", "loc", "z", -t) + mapdl.d("all", "uz") # Displacement constraint in z-direction + mapdl.allsel("all") + + # Thermal Boundary Conditions + # Convection heat loss from the workpiece surfaces + mapdl.vsel("s", "volume", "", 1, 2) # Selecting the workpiece + mapdl.allsel("below", "volume") + mapdl.nsel("r", "loc", "z", 0) + mapdl.nsel("a", "loc", "x", -w) + mapdl.nsel("a", "loc", "x", w) + mapdl.nsel("a", "loc", "y", -l1) + mapdl.nsel("a", "loc", "y", l2) + mapdl.sf("all", "conv", 30, 25) + + # Convection (high)heat loss from the workpiece bottom + mapdl.nsel("s", "loc", "z", -t) + mapdl.sf("all", "conv", 300, 25) + mapdl.allsel("all") + + # Convection heat loss from the tool surfaces + mapdl.vsel("u", "volume", "", 1, 2) # Selecting the tool + mapdl.allsel("below", "volume") + mapdl.csys(1) + mapdl.nsel("r", "loc", "x", r1) + mapdl.nsel("a", "loc", "z", h) + mapdl.sf("all", "conv", 30, 25) + mapdl.allsel("all") + + # Constraining all DOFs at pilot node except the Temp DOF + mapdl.d(1, "all") + mapdl.ddele(1, "temp") + mapdl.allsel("all") + mapdl.mute = False + # ========================================================== + # * Solution + # ========================================================== + # from precedent fixture + uz1 = 3.18e-03 / 4000 + + mapdl.mute = False + mapdl.run("/solu") + mapdl.antype(4) # Transient analysis + mapdl.lnsrch("on") + mapdl.cutcontrol("plslimit", 0.15) + mapdl.kbc(0) # Ramped loading within a load step + mapdl.nlgeom("on") # Turn on large deformation effects + mapdl.timint("off", "struc") # Structural dynamic effects are turned off. + mapdl.nropt("unsym") + + # Load Step1 + mapdl.time(1) + mapdl.nsubst(5, 10, 2) + mapdl.d(1, "uz", -uz1) # Tool plunges into the workpiece + mapdl.outres("all", "all") + mapdl.allsel() + mapdl.solve() + + mapdl.post1() + mapdl.allsel() + mapdl.set("last") + mapdl.mute = False + + @staticmethod + def test_nodal_contact_friction_stress(mapdl, contact_solve): + # Format tables. + mapdl.post1() + mapdl.header("OFF", "OFF", "OFF", "OFF", "OFF", "OFF") + nsigfig = 10 + mapdl.format("", "E", nsigfig + 9, nsigfig) + mapdl.page(1e9, "", -1, 240) + + prnsol = mapdl.prnsol("CONT") + array = np.genfromtxt(prnsol.splitlines(), skip_header=1) + sfric_prn = array[:, 4] + nodes = array[:, 0] + + index = nodes.astype(int) - 1 # -1 to convert apdl node number to python index. + sfric_nod = mapdl.post_processing.nodal_contact_friction_stress()[index] + + assert np.allclose(sfric_prn, sfric_nod) + + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_nodal_contact_friction_stress(mapdl, contact_solve): + assert ( + mapdl.post_processing.plot_nodal_contact_friction_stress( + smooth_shading=True + ) + is None + ) - mapdl.vsel("s", "", "", 2) - mapdl.eslv("s") - assert mapdl.post_processing.plot_element_displacement() is None + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_incomplete_element_selection(mapdl, contact_solve): + mapdl.esel("S", "ELEM", "", 1, mapdl.mesh.n_elem // 2) + assert mapdl.post_processing.plot_element_displacement() is None + mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_elem // 2, 2) + assert mapdl.post_processing.plot_element_displacement() is None -@requires("ansys-tools-visualization_interface") -def test_plot_incomplete_nodal_selection(mapdl, contact_solve, verify_image_cache): - verify_image_cache.skip = True + mapdl.nsel("S", "NODE", "", 5, mapdl.mesh.n_elem // 2, 2) + assert mapdl.post_processing.plot_element_displacement() is None - mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_node // 2) - assert mapdl.post_processing.plot_nodal_displacement() is None + mapdl.vsel("s", "", "", 1) + mapdl.eslv("s") + assert mapdl.post_processing.plot_element_displacement() is None - mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_node // 2, 2) - assert mapdl.post_processing.plot_nodal_displacement() is None + mapdl.vsel("s", "", "", 2) + mapdl.eslv("s") + assert mapdl.post_processing.plot_element_displacement() is None - mapdl.nsel("S", "NODE", "", 5, mapdl.mesh.n_node // 2, 2) - assert mapdl.post_processing.plot_nodal_displacement() is None + @staticmethod + @requires("ansys-tools-visualization_interface") + def test_plot_incomplete_nodal_selection(mapdl, contact_solve, verify_image_cache): + verify_image_cache.skip = True - mapdl.vsel("s", "", "", 1) - mapdl.eslv("S") - mapdl.nsle("S") - assert mapdl.post_processing.plot_nodal_displacement() is None + mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_node // 2) + assert mapdl.post_processing.plot_nodal_displacement() is None - mapdl.vsel("s", "", "", 2) - mapdl.eslv("S") - mapdl.nsle("S") - assert mapdl.post_processing.plot_nodal_displacement() is None + mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_node // 2, 2) + assert mapdl.post_processing.plot_nodal_displacement() is None + mapdl.nsel("S", "NODE", "", 5, mapdl.mesh.n_node // 2, 2) + assert mapdl.post_processing.plot_nodal_displacement() is None -@requires("ansys-tools-visualization_interface") -def test_general_plotter_returns(mapdl, static_solve, verify_image_cache): - verify_image_cache.skip = True # skipping image verification - - # Returns + mapdl.vsel("s", "", "", 1) + mapdl.eslv("S") + mapdl.nsle("S") + assert mapdl.post_processing.plot_nodal_displacement() is None - assert ( - mapdl.post_processing.plot_nodal_displacement("X", smooth_shading=True) is None - ) - assert isinstance( - mapdl.post_processing.plot_nodal_displacement( - "X", smooth_shading=True, return_cpos=True - ), - CameraPosition, - ) + mapdl.vsel("s", "", "", 2) + mapdl.eslv("S") + mapdl.nsle("S") + assert mapdl.post_processing.plot_nodal_displacement() is None - p = mapdl.post_processing.plot_nodal_displacement( - "X", smooth_shading=True, return_plotter=True - ) - assert isinstance(p, MapdlPlotter) - p.show() - - with pytest.raises(ValueError): - mapdl.post_processing.plot_nodal_displacement( - "X", smooth_shading=True, return_cpos=True, return_plotter=True + @staticmethod + def test_time_frequency_values(mapdl, contact_solve): + assert np.allclose( + mapdl.post_processing.time_values, + mapdl.post_processing.frequency_values, ) - # Returns + Save figure. - assert ( - mapdl.post_processing.plot_nodal_displacement( - "X", - smooth_shading=True, - savefig=True, - return_cpos=False, - return_plotter=False, + @staticmethod + def test_time_values(mapdl, contact_solve): + assert np.allclose( + mapdl.post_processing.time_values, np.array([0.2, 0.4, 0.7, 1.0]) ) - is None - ) - assert isinstance( - mapdl.post_processing.plot_nodal_displacement( - "X", - smooth_shading=True, - savefig=True, - return_cpos=True, - return_plotter=False, - ), - CameraPosition, - ) - - p = mapdl.post_processing.plot_nodal_displacement( - "X", - smooth_shading=True, - savefig=True, - return_cpos=False, - return_plotter=True, - ) - assert isinstance(p, MapdlPlotter) - - -def test_time_frequency_values(mapdl, contact_solve): - assert np.allclose( - mapdl.post_processing.time_values, - mapdl.post_processing.frequency_values, - ) - - -def test_time_values(mapdl, contact_solve): - assert np.allclose( - mapdl.post_processing.time_values, np.array([0.2, 0.4, 0.7, 1.0]) - ) - -@pytest.mark.parametrize("step_", [1, 2, 3, 4]) -def test_set(mapdl, contact_solve, step_): - mapdl.set(nset=step_) - assert mapdl.post_processing.step == step_ + @staticmethod + @pytest.mark.parametrize("step_", [1, 2, 3, 4]) + def test_set(mapdl, contact_solve, step_): + mapdl.set(nset=step_) + assert mapdl.post_processing.step == step_ def test_meta_post_plot_docstrings(): From a210b028d2704b0013459c6daa747365b5634f4e Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Tue, 29 Oct 2024 10:37:00 +0000 Subject: [PATCH 2/3] chore: adding changelog file 3523.added.md [dependabot-skip] --- doc/changelog.d/3523.added.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 doc/changelog.d/3523.added.md diff --git a/doc/changelog.d/3523.added.md b/doc/changelog.d/3523.added.md new file mode 100644 index 0000000000..ff3b66951b --- /dev/null +++ b/doc/changelog.d/3523.added.md @@ -0,0 +1 @@ +refactor: moving tests to classes to avoid repeatingly execute the fixtures. \ No newline at end of file From ce97c892ff64976a848c7fa44240a1effc18742a Mon Sep 17 00:00:00 2001 From: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:44:08 +0000 Subject: [PATCH 3/3] chore: adding changelog file 3523.added.md [dependabot-skip] --- doc/changelog.d/3523.added.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/changelog.d/3523.added.md b/doc/changelog.d/3523.added.md index ff3b66951b..848608127d 100644 --- a/doc/changelog.d/3523.added.md +++ b/doc/changelog.d/3523.added.md @@ -1 +1 @@ -refactor: moving tests to classes to avoid repeatingly execute the fixtures. \ No newline at end of file +refactor: moving tests to classes to avoid repeated fixtures execution \ No newline at end of file