diff --git a/doc/changelog.d/3760.documentation.md b/doc/changelog.d/3760.documentation.md new file mode 100644 index 00000000000..b2da4fb6d74 --- /dev/null +++ b/doc/changelog.d/3760.documentation.md @@ -0,0 +1 @@ +feat: adding `muted` context manager \ No newline at end of file diff --git a/doc/source/api/mapdl.rst b/doc/source/api/mapdl.rst index 0755b4f35fd..ea8e43e9837 100644 --- a/doc/source/api/mapdl.rst +++ b/doc/source/api/mapdl.rst @@ -54,6 +54,7 @@ Mapdl.logger Mapdl.mapdl_on_hpc Mapdl.mute + Mapdl.muted Mapdl.name Mapdl.non_interactive Mapdl.on_docker diff --git a/src/ansys/mapdl/core/mapdl_core.py b/src/ansys/mapdl/core/mapdl_core.py index b1c75fda440..f66f9d610e5 100644 --- a/src/ansys/mapdl/core/mapdl_core.py +++ b/src/ansys/mapdl/core/mapdl_core.py @@ -838,6 +838,21 @@ def non_interactive(self): """ return self._non_interactive(self) + @property + def muted(self): + """Context manager that suppress all output from MAPDL + + Use the `muted` context manager to suppress all the output. Similar to + setting `mapdl.mute = True` but only for the context manager. + + Examples + -------- + >>> with mapdl.muted: + ... mapdl.run("/SOLU") # This call is muted + + """ + return self._muted(self) + @property def parameters(self) -> "Parameters": """Collection of MAPDL parameters. @@ -1187,10 +1202,6 @@ def _mesh(self) -> "Archive": nblock_filename = os.path.join(self.directory, "nblock.cdb") # must have all nodes elements are using selected - if hasattr(self, "mute"): - old_mute = self.mute - self.mute = True - self.cm("__NODE__", "NODE", mute=True) self.nsle("S", mute=True) self.cdwrite("db", arch_filename, mute=True) @@ -1201,9 +1212,6 @@ def _mesh(self) -> "Archive": self.cdwrite("db", nblock_filename, mute=True) self.cmsel("S", "__ELEM__", "ELEM", mute=True) - if hasattr(self, "mute"): - self.mute = old_mute - self._archive_cache = Archive(arch_filename, parse_vtk=False, name="Mesh") grid = self._archive_cache._parse_vtk(additional_checking=True) self._archive_cache._grid = grid @@ -1530,6 +1538,19 @@ def __exit__(self, *args): def _cached_routine(self): return self._parent()._cached_routine + class _muted: + def __init__(self, parent): + self._parent = weakref.ref(parent) + self.old_value = None + + def __enter__(self): + self.old_value = self._parent().mute + self._parent().mute = True + + def __exit__(self, *args): + self._parent().mute = self.old_value + self.old_value = None + def run_as_routine(self, routine): """ Runs a command or commands at a routine and then revert to the prior routine. diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index d83bffbd10c..cf58088ec36 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -438,6 +438,7 @@ def __init__( self._channel_state: grpc.ChannelConnectivity = ( grpc.ChannelConnectivity.CONNECTING ) + self._time_step_stream: Optional[int] = None if channel is None: self._log.debug("Creating channel to %s:%s", ip, port) @@ -812,6 +813,7 @@ def mute(self): @mute.setter def mute(self, value): + self._log.debug(f"Mute value has been changed to '{value}'.") self._mute = value def __repr__(self): @@ -2035,20 +2037,24 @@ def _get_time_step_stream( if time_step is None: if DEFAULT_TIME_STEP_STREAM is not None: time_step = DEFAULT_TIME_STEP_STREAM - elif self.platform == "windows": - time_step = DEFAULT_TIME_STEP_STREAM_NT - elif self.platform == "linux": - time_step = DEFAULT_TIME_STEP_STREAM_POSIX + elif self._time_step_stream is not None: + time_step = self._time_step_stream else: - raise ValueError( - f"The MAPDL platform ('{self.platform}') is not recognaised." - ) + if self.platform == "windows": + time_step = DEFAULT_TIME_STEP_STREAM_NT + elif self.platform == "linux": + time_step = DEFAULT_TIME_STEP_STREAM_POSIX + else: + raise ValueError( + f"The MAPDL platform ('{self.platform}') is not recognaised." + ) else: if time_step <= 0: raise ValueError("``time_step`` argument must be greater than 0``") self.logger.debug(f"The time_step argument is set to: {time_step}") + self._time_step_stream = time_step return time_step def _get_file_path(self, fname: str, progress_bar: bool = False) -> str: @@ -2262,41 +2268,39 @@ def _get( self._get_lock = True try: - getresponse = self._stub.Get(pb_types.GetRequest(getcmd=cmd)) + response = self._stub.Get(pb_types.GetRequest(getcmd=cmd)) finally: self._get_lock = False - if getresponse.type == 0: + if response.type == 0: self._log.debug( "The 'grpc' get method seems to have failed. Trying old implementation for more verbose output." ) - out = self.run("*GET,__temp__," + cmd) - self._log.debug(f"Default *get output:\n{out}") + response = self.run("*GET,__temp__," + cmd, mute=False) + self._log.debug(f"Default *get output:\n{response}") - if out: + if response: from ansys.mapdl.core.misc import is_float - if "VALUE=" in out: - out = out.split("VALUE=")[1].strip() + if "VALUE=" in response: + response = response.split("VALUE=")[1].strip() - if is_float(out): - return float(out) + if is_float(response): + return float(response) else: - return out - elif out is None: - return None + return response else: - raise MapdlError(f"Error when processing '*get' request output.\n{out}") + raise MapdlError( + f"Error when processing '*get' request output.\n{response}" + ) - if getresponse.type == 1: - return getresponse.dval - elif getresponse.type == 2: - return getresponse.sval + if response.type == 1: + return response.dval + elif response.type == 2: + return response.sval - raise MapdlRuntimeError( - f"Unsupported type {getresponse.type} response from MAPDL" - ) + raise MapdlRuntimeError(f"Unsupported type {response.type} response from MAPDL") def download_project( self, diff --git a/src/ansys/mapdl/core/parameters.py b/src/ansys/mapdl/core/parameters.py index aed30d671aa..0ddbef3c694 100644 --- a/src/ansys/mapdl/core/parameters.py +++ b/src/ansys/mapdl/core/parameters.py @@ -663,11 +663,6 @@ def _set_array_chain(self, name, arr, idim, jdim, kdim): elif arr.ndim == 2: arr = np.expand_dims(arr, 2) - # backwards compatibility with CORBA - if hasattr(self._mapdl, "mute"): - old_mute = self._mapdl.mute - self._mapdl.mute = True - with self._mapdl.non_interactive: self._mapdl.dim(name, imax=idim, jmax=jdim, kmax=kdim) for i in range(idim): @@ -676,9 +671,6 @@ def _set_array_chain(self, name, arr, idim, jdim, kdim): index = f"{i + 1},{j + 1},{k + 1}" self._mapdl.run(f"{name}({index})={arr[i, j, k]}") - if hasattr(self._mapdl, "mute"): - self._mapdl.mute = old_mute - def _write_numpy_array(self, filename, arr): """Write a numpy array to disk""" if arr.dtype != np.double: diff --git a/tests/conftest.py b/tests/conftest.py index c89a3fd08c9..1cf6f3a8529 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -444,6 +444,8 @@ def run_before_and_after_tests( # check if the local/remote state has changed or not prev = mapdl.is_local + assert not mapdl.exited, "MAPDL is exited before the test. It should not!" + assert not mapdl.mute yield # this is where the testing happens @@ -751,29 +753,28 @@ def cube_solve(cleared, mapdl, cube_geom_and_mesh): @pytest.fixture def solved_box(mapdl, cleared): - mapdl.mute = True # improve stability - mapdl.et(1, "SOLID5") - mapdl.block(0, 10, 0, 20, 0, 30) - mapdl.esize(10) - mapdl.vmesh("ALL") - mapdl.units("SI") # SI - International system (m, kg, s, K). - # Define a material (nominal steel in SI) - mapdl.mp("EX", 1, 210e9) # Elastic moduli in Pa (kg/(m*s**2)) - mapdl.mp("DENS", 1, 7800) # Density in kg/m3 - mapdl.mp("PRXY", 1, 0.3) # Poisson's Ratio - # Fix the left-hand side. - mapdl.nsel("S", "LOC", "Z", 0) - mapdl.d("ALL", "UX") - mapdl.d("ALL", "UY") - mapdl.d("ALL", "UZ") - - mapdl.nsel("S", "LOC", "Z", 30) - mapdl.f("ALL", "FX", 1000) - mapdl.run("/SOLU") - mapdl.antype("STATIC") - mapdl.solve() - mapdl.finish() - mapdl.mute = False + with mapdl.muted: # improve stability + mapdl.et(1, "SOLID5") + mapdl.block(0, 10, 0, 20, 0, 30) + mapdl.esize(10) + mapdl.vmesh("ALL") + mapdl.units("SI") # SI - International system (m, kg, s, K). + # Define a material (nominal steel in SI) + mapdl.mp("EX", 1, 210e9) # Elastic moduli in Pa (kg/(m*s**2)) + mapdl.mp("DENS", 1, 7800) # Density in kg/m3 + mapdl.mp("PRXY", 1, 0.3) # Poisson's Ratio + # Fix the left-hand side. + mapdl.nsel("S", "LOC", "Z", 0) + mapdl.d("ALL", "UX") + mapdl.d("ALL", "UY") + mapdl.d("ALL", "UZ") + + mapdl.nsel("S", "LOC", "Z", 30) + mapdl.f("ALL", "FX", 1000) + mapdl.run("/SOLU") + mapdl.antype("STATIC") + mapdl.solve() + mapdl.finish() @pytest.fixture(scope="function") @@ -800,279 +801,277 @@ def coupled_example(mapdl, cleared): @pytest.fixture(scope="function") def contact_geom_and_mesh(mapdl, cleared): - mapdl.mute = True - - # Based on tech demo 28. - # ***** 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 + with mapdl.muted: + # Based on tech demo 28. + # ***** 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") @pytest.fixture(scope="function") diff --git a/tests/test_commands.py b/tests/test_commands.py index 1b154470c15..3cce4b002af 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -145,12 +145,11 @@ @pytest.fixture() def beam_solve(mapdl, cleared): - mapdl.mute = True - mapdl.input(vmfiles["vm10"]) + with mapdl.muted: + mapdl.input(vmfiles["vm10"]) - mapdl.post1() - mapdl.set(1, 2) - mapdl.mute = False + mapdl.post1() + mapdl.set(1, 2) def test_cmd_class(): @@ -688,12 +687,11 @@ class Test_output_listing(TestClass): @staticmethod @pytest.fixture(scope="class") def plastic_solve_output(mapdl): - mapdl.mute = True - mapdl.input(vmfiles["vm273"]) + with mapdl.muted: + mapdl.input(vmfiles["vm273"]) - mapdl.post1() - mapdl.set(1, 2) - mapdl.mute = False + mapdl.post1() + mapdl.set(1, 2) @staticmethod @pytest.mark.parametrize( diff --git a/tests/test_grpc.py b/tests/test_grpc.py index 6b8e99d11e3..b5daebc7985 100644 --- a/tests/test_grpc.py +++ b/tests/test_grpc.py @@ -776,11 +776,15 @@ def test__get_time_step_stream(mapdl, platform): with patch("ansys.mapdl.core.mapdl_grpc.MapdlGrpc.platform", platform): from ansys.mapdl.core import mapdl_grpc + mapdl._time_step_stream = None + mapdl_grpc.DEFAULT_TIME_STEP_STREAM = None + if platform == "linux": DEFAULT_TIME_STEP_STREAM = mapdl_grpc.DEFAULT_TIME_STEP_STREAM_POSIX elif platform == "windows": DEFAULT_TIME_STEP_STREAM = mapdl_grpc.DEFAULT_TIME_STEP_STREAM_NT else: + mapdl_grpc.DEFAULT_TIME_STEP_STREAM = None with pytest.raises(ValueError, match="The MAPDL platform"): mapdl._get_time_step_stream() @@ -788,13 +792,20 @@ def test__get_time_step_stream(mapdl, platform): assert DEFAULT_TIME_STEP_STREAM == mapdl._get_time_step_stream() + # Using global + mapdl._time_step_stream = None mapdl_grpc.DEFAULT_TIME_STEP_STREAM = 200 assert mapdl_grpc.DEFAULT_TIME_STEP_STREAM == mapdl._get_time_step_stream() - mapdl_grpc.DEFAULT_TIME_STEP_STREAM = None + # Using argument, should override the global + mapdl_grpc.DEFAULT_TIME_STEP_STREAM = 1000 assert 700 == mapdl._get_time_step_stream(700) + assert mapdl._time_step_stream == 700 with pytest.raises( ValueError, match="``time_step`` argument must be greater than 0``" ): mapdl._get_time_step_stream(-700) + + mapdl._time_step_stream = None + mapdl_grpc.DEFAULT_TIME_STEP_STREAM = None diff --git a/tests/test_inline_functions/test_component_queries.py b/tests/test_inline_functions/test_component_queries.py index 5749fced27b..6ff37734b05 100644 --- a/tests/test_inline_functions/test_component_queries.py +++ b/tests/test_inline_functions/test_component_queries.py @@ -102,29 +102,28 @@ class TestDisplacementComponentQueriesBox(TestClass): @pytest.fixture(scope="class") def solved_box(self, mapdl): - mapdl.mute = True # improve stability - mapdl.et(1, "SOLID5") - mapdl.block(0, 10, 0, 20, 0, 30) - mapdl.esize(10) - mapdl.vmesh("ALL") - mapdl.units("SI") # SI - International system (m, kg, s, K). - # Define a material (nominal steel in SI) - mapdl.mp("EX", 1, 210e9) # Elastic moduli in Pa (kg/(m*s**2)) - mapdl.mp("DENS", 1, 7800) # Density in kg/m3 - mapdl.mp("PRXY", 1, 0.3) # Poisson's Ratio - # Fix the left-hand side. - mapdl.nsel("S", "LOC", "Z", 0) - mapdl.d("ALL", "UX") - mapdl.d("ALL", "UY") - mapdl.d("ALL", "UZ") - - mapdl.nsel("S", "LOC", "Z", 30) - mapdl.f("ALL", "FX", 1000) - mapdl.run("/SOLU") - mapdl.antype("STATIC") - mapdl.solve() - mapdl.finish() - mapdl.mute = False + with mapdl.muted: # improve stability + mapdl.et(1, "SOLID5") + mapdl.block(0, 10, 0, 20, 0, 30) + mapdl.esize(10) + mapdl.vmesh("ALL") + mapdl.units("SI") # SI - International system (m, kg, s, K). + # Define a material (nominal steel in SI) + mapdl.mp("EX", 1, 210e9) # Elastic moduli in Pa (kg/(m*s**2)) + mapdl.mp("DENS", 1, 7800) # Density in kg/m3 + mapdl.mp("PRXY", 1, 0.3) # Poisson's Ratio + # Fix the left-hand side. + mapdl.nsel("S", "LOC", "Z", 0) + mapdl.d("ALL", "UX") + mapdl.d("ALL", "UY") + mapdl.d("ALL", "UZ") + + mapdl.nsel("S", "LOC", "Z", 30) + mapdl.f("ALL", "FX", 1000) + mapdl.run("/SOLU") + mapdl.antype("STATIC") + mapdl.solve() + mapdl.finish() q = mapdl.queries return q, get_details_of_nodes(mapdl) diff --git a/tests/test_mapdl.py b/tests/test_mapdl.py index f03afc2db4d..c90336f2a11 100644 --- a/tests/test_mapdl.py +++ b/tests/test_mapdl.py @@ -208,17 +208,16 @@ def clearing_cdread_cdwrite_tests(mapdl): - mapdl.mute = True - mapdl.finish() - # *MUST* be NOSTART. With START fails after 20 calls... - # this has been fixed in later pymapdl and MAPDL releases - mapdl.clear("NOSTART") - mapdl.header("DEFA") - mapdl.format("DEFA") - mapdl.page("DEFA") + with mapdl.muted: + mapdl.finish() + # *MUST* be NOSTART. With START fails after 20 calls... + # this has been fixed in later pymapdl and MAPDL releases + mapdl.clear("NOSTART") + mapdl.header("DEFA") + mapdl.format("DEFA") + mapdl.page("DEFA") - mapdl.prep7() - mapdl.mute = False + mapdl.prep7() def asserting_cdread_cdwrite_tests(mapdl): @@ -933,47 +932,46 @@ def test_load_array_failure_types(mapdl, cleared, array): @requires("grpc") def test_lssolve(mapdl, cleared): - mapdl.mute = True + with mapdl.muted: + mapdl.run("/units,user,0.001,0.001,1,1,0,1,1,1") + mapdl.et(1, 182) + mapdl.mp("ex", 1, 210e3) + mapdl.mp("nuxy", 1, 0.33) + mapdl.mp("dens", 1, 7.81e-06) + mapdl.k(1, 0, 0) + mapdl.k(2, 5, 0) + mapdl.k(3, 5, 1) + mapdl.k(4, 0, 1) + mapdl.l(1, 2) + mapdl.l(2, 3) + mapdl.l(3, 4) + mapdl.l(4, 1) + mapdl.al(1, 2, 3, 4) + mapdl.lsel("s", "", "", 1, 4) + mapdl.lesize("all", 0.5) + mapdl.amesh(1) + mapdl.allsel() + mapdl.finish() + mapdl.run("/solu") + mapdl.antype("static'") + mapdl.kbc(0) + mapdl.lsel("s", "", "", 4) + mapdl.nsll("s", 1) + mapdl.d("all", "all", 0) + mapdl.ksel("s", "", "", 3) + mapdl.nslk("s") + mapdl.f("all", "fy", 5) + mapdl.allsel() + mapdl.lswrite(1) + mapdl.fdele("all", "all") + mapdl.ksel("s", "", "", 3) + mapdl.nslk("s") + mapdl.f("all", "fy", -5) + mapdl.allsel() - mapdl.run("/units,user,0.001,0.001,1,1,0,1,1,1") - mapdl.et(1, 182) - mapdl.mp("ex", 1, 210e3) - mapdl.mp("nuxy", 1, 0.33) - mapdl.mp("dens", 1, 7.81e-06) - mapdl.k(1, 0, 0) - mapdl.k(2, 5, 0) - mapdl.k(3, 5, 1) - mapdl.k(4, 0, 1) - mapdl.l(1, 2) - mapdl.l(2, 3) - mapdl.l(3, 4) - mapdl.l(4, 1) - mapdl.al(1, 2, 3, 4) - mapdl.lsel("s", "", "", 1, 4) - mapdl.lesize("all", 0.5) - mapdl.amesh(1) - mapdl.allsel() - mapdl.finish() - mapdl.run("/solu") - mapdl.antype("static'") - mapdl.kbc(0) - mapdl.lsel("s", "", "", 4) - mapdl.nsll("s", 1) - mapdl.d("all", "all", 0) - mapdl.ksel("s", "", "", 3) - mapdl.nslk("s") - mapdl.f("all", "fy", 5) - mapdl.allsel() - mapdl.lswrite(1) - mapdl.fdele("all", "all") - mapdl.ksel("s", "", "", 3) - mapdl.nslk("s") - mapdl.f("all", "fy", -5) - mapdl.allsel() + lsnum = 2 + mapdl.lswrite(lsnum) - lsnum = 2 - mapdl.lswrite(lsnum) - mapdl.mute = False out = mapdl.lssolve(1, lsnum) assert f"Load step file number {lsnum}. Begin solution ..." in out @@ -1369,25 +1367,25 @@ def test_print_com(mapdl, cleared, capfd): assert string_ not in out mapdl.print_com = True - mapdl.mute = True - mapdl.com(string_) - out, err = capfd.readouterr() - assert string_ not in out + with mapdl.muted: + mapdl.com(string_) + out, err = capfd.readouterr() + assert string_ not in out - mapdl.print_com = True - mapdl.mute = False - mapdl.com(string_, mute=True) - out, err = capfd.readouterr() - assert string_ not in out + mapdl.print_com = True + mapdl.mute = False - mapdl.print_com = True - mapdl.mute = True - mapdl.com(string_, mute=True) - out, err = capfd.readouterr() - assert string_ not in out + mapdl.com(string_, mute=True) + out, err = capfd.readouterr() + assert string_ not in out + + mapdl.print_com = True + mapdl.mute = True + mapdl.com(string_, mute=True) + out, err = capfd.readouterr() + assert string_ not in out mapdl.print_com = True - mapdl.mute = False mapdl.com(string_, mute=False) out, err = capfd.readouterr() assert string_ in out @@ -1893,17 +1891,16 @@ def test_process_is_alive(mapdl, cleared): def test_force_output(mapdl, cleared): - mapdl.mute = True - with mapdl.force_output: - assert mapdl.prep7() - assert not mapdl.prep7() + with mapdl.muted: + with mapdl.force_output: + assert mapdl.prep7() + assert not mapdl.prep7() - mapdl._run("nopr") - with mapdl.force_output: - assert mapdl.prep7() - assert not mapdl.prep7() + mapdl._run("nopr") + with mapdl.force_output: + assert mapdl.prep7() + assert not mapdl.prep7() - mapdl.mute = False mapdl._run("gopr") with mapdl.force_output: assert mapdl.prep7() @@ -2934,3 +2931,14 @@ def __init__(self): mock_kill.assert_called_once() else: mock_kill.assert_not_called() + + +@pytest.mark.parametrize("prop", ["mute"]) +def test_muted(mapdl, prop): + assert not mapdl.mute + + with mapdl.muted: + assert mapdl.mute + assert mapdl.prep7() is None + + assert not mapdl.mute diff --git a/tests/test_mesh_grpc.py b/tests/test_mesh_grpc.py index 91af3673ef7..cc37fc4c586 100644 --- a/tests/test_mesh_grpc.py +++ b/tests/test_mesh_grpc.py @@ -292,6 +292,7 @@ def test_nodes_in_current_CS(mapdl, cleared, cube_geom_and_mesh): for icoord in range(6): mapdl.csys(icoord) mapdl.dsys(icoord) + assert np.allclose( mapdl.mesh.nodes_in_current_CS, mapdl.nlist().to_array()[:, 1:4], atol=1e-3 ) # nlist is not as accurate as 'nodes_in_current_CS' diff --git a/tests/test_post.py b/tests/test_post.py index 489123e5892..59aa9705ad6 100644 --- a/tests/test_post.py +++ b/tests/test_post.py @@ -66,75 +66,72 @@ class Test_static_solve(TestClass): @staticmethod @pytest.fixture(scope="class") def static_solve(mapdl): - mapdl.mute = True - - # 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.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() - - mapdl.mute = False + with mapdl.muted: + # 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.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() mapdl.save("static_solve", slab="all") @@ -749,10 +746,8 @@ class Test_plastic_solve(TestClass): @staticmethod @pytest.fixture(scope="class") def plastic_solve(mapdl): - mapdl.mute = True - mapdl.input(examples.verif_files.vmfiles["vm273"]) - - mapdl.mute = False + with mapdl.muted: + mapdl.input(examples.verif_files.vmfiles["vm273"]) mapdl.save("plastic_solve", slab="all") @@ -1344,63 +1339,62 @@ class Test_thermal_solve: @staticmethod @pytest.fixture(scope="class") def thermal_solve(mapdl): - mapdl.mute = True - mapdl.finish() - mapdl.clear() - - mapdl.prep7() - mapdl.et(1, "PLANE223", 11, 1) # COUPLE-FIELD ELEMENT TYPE, WEAK COUPLING - mapdl.et(2, "CONTA175", 1) # CONTACT ELEMENT TYPE - mapdl.et(3, "TARGE169") # TARGET ELEMENT TYPE - mapdl.mp("EX", 1, 10e6) # YOUNG'S MODULUS - mapdl.mp("KXX", 1, 250) # CONDUCTIVITY - mapdl.mp("ALPX", 1, 12e-6) # THERMAL EXPANSION COEFFICIENT - mapdl.mp("PRXY", "", 0.3) - mapdl.r(2, "", "", -1000, -0.005) - mapdl.rmore("", "", "", "", "", -100) - mapdl.rmore("", 100) - mapdl.rmore() - mapdl.rmore(0.01) - - # SET UP FINITE ELEMENT MODEL - mapdl.n(1) - mapdl.n(2, 0.4) - mapdl.n(3, "(0.4+0.0035)") - mapdl.n(4, "(0.9+0.0035)") - mapdl.ngen(2, 4, 1, 4, 1, "", 0.1) - mapdl.e(1, 2, 6, 5) # PLANE223 ELEMENTS - mapdl.e(3, 4, 8, 7) - mapdl.type(2) # CONTACT ELEMENTS - mapdl.real(2) - mapdl.e(2) - mapdl.e(6) - mapdl.type(3) # TARGET ELEMENTS - mapdl.real(2) - mapdl.nsel("S", "NODE", "", 3, 7, 4) - mapdl.esln() - mapdl.esurf() - mapdl.allsel() - - # APPLY INITIAL BOUNDARY CONDITIONS - mapdl.d(1, "UY", "", "", 4, 1) - mapdl.d(1, "UX", "", "", 5, 4) - mapdl.d(4, "UX", "", "", 8, 4) - mapdl.tref(100) - mapdl.eresx("YES") - mapdl.finish() - - mapdl.slashsolu() - mapdl.nlgeom("ON") # LARGE DEFLECTION EFFECTS TURNED ON - mapdl.d(1, "TEMP", 500, "", 5, 4) - mapdl.d(3, "TEMP", 100, "", 4) - mapdl.d(7, "TEMP", 100, "", 8) - mapdl.solve() # FIRST LOAD STEP - - mapdl.solution() - mapdl.allsel() - mapdl.outres("all", "all") - mapdl.solve() - mapdl.mute = False + with mapdl.muted: + mapdl.finish() + mapdl.clear() + + mapdl.prep7() + mapdl.et(1, "PLANE223", 11, 1) # COUPLE-FIELD ELEMENT TYPE, WEAK COUPLING + mapdl.et(2, "CONTA175", 1) # CONTACT ELEMENT TYPE + mapdl.et(3, "TARGE169") # TARGET ELEMENT TYPE + mapdl.mp("EX", 1, 10e6) # YOUNG'S MODULUS + mapdl.mp("KXX", 1, 250) # CONDUCTIVITY + mapdl.mp("ALPX", 1, 12e-6) # THERMAL EXPANSION COEFFICIENT + mapdl.mp("PRXY", "", 0.3) + mapdl.r(2, "", "", -1000, -0.005) + mapdl.rmore("", "", "", "", "", -100) + mapdl.rmore("", 100) + mapdl.rmore() + mapdl.rmore(0.01) + + # SET UP FINITE ELEMENT MODEL + mapdl.n(1) + mapdl.n(2, 0.4) + mapdl.n(3, "(0.4+0.0035)") + mapdl.n(4, "(0.9+0.0035)") + mapdl.ngen(2, 4, 1, 4, 1, "", 0.1) + mapdl.e(1, 2, 6, 5) # PLANE223 ELEMENTS + mapdl.e(3, 4, 8, 7) + mapdl.type(2) # CONTACT ELEMENTS + mapdl.real(2) + mapdl.e(2) + mapdl.e(6) + mapdl.type(3) # TARGET ELEMENTS + mapdl.real(2) + mapdl.nsel("S", "NODE", "", 3, 7, 4) + mapdl.esln() + mapdl.esurf() + mapdl.allsel() + + # APPLY INITIAL BOUNDARY CONDITIONS + mapdl.d(1, "UY", "", "", 4, 1) + mapdl.d(1, "UX", "", "", 5, 4) + mapdl.d(4, "UX", "", "", 8, 4) + mapdl.tref(100) + mapdl.eresx("YES") + mapdl.finish() + + mapdl.slashsolu() + mapdl.nlgeom("ON") # LARGE DEFLECTION EFFECTS TURNED ON + mapdl.d(1, "TEMP", 500, "", 5, 4) + mapdl.d(3, "TEMP", 100, "", 4) + mapdl.d(7, "TEMP", 100, "", 8) + mapdl.solve() # FIRST LOAD STEP + + mapdl.solution() + mapdl.allsel() + mapdl.outres("all", "all") + mapdl.solve() mapdl.save("thermal_solve") mapdl.finish()