@@ -2123,7 +2123,7 @@ def test_components_selection_keep_between_plots(mapdl, cube_solve):
2123
2123
assert "mycm" in mapdl .components
2124
2124
2125
2125
2126
- def test_saving_selection_context (mapdl , cube_solve ):
2126
+ def test_save_selection_1 (mapdl , cube_solve ):
2127
2127
mapdl .allsel ()
2128
2128
2129
2129
for i in range (1 , 4 ):
@@ -2221,6 +2221,108 @@ def test_saving_selection_context(mapdl, cube_solve):
2221
2221
assert "nod_selection_4" not in mapdl .components
2222
2222
2223
2223
2224
+ def test_save_selection_2 (mapdl , cleared , make_block ):
2225
+ from ansys .mapdl .core .mapdl_core import _TMP_COMP
2226
+
2227
+ n1 = 1
2228
+ mapdl .nsel (vmin = n1 )
2229
+ assert n1 in mapdl .mesh .nnum
2230
+ mapdl .cm ("nodes_cm" , "NODE" )
2231
+ assert "nodes_cm" in mapdl .components
2232
+ assert n1 in mapdl .components ["nodes_cm" ].items
2233
+ assert "NODE" == mapdl .components ["nodes_cm" ].type
2234
+
2235
+ e1 = 1
2236
+ mapdl .esel (vmin = e1 )
2237
+ assert e1 in mapdl .mesh .enum
2238
+ mapdl .cm ("elem_cm" , "ELEM" )
2239
+ assert "elem_cm" in mapdl .components
2240
+ assert e1 in mapdl .components ["elem_cm" ].items
2241
+ assert "ELEM" == mapdl .components ["elem_cm" ].type
2242
+
2243
+ kp1 = 1
2244
+ mapdl .ksel (vmin = kp1 )
2245
+ assert kp1 in mapdl .geometry .knum
2246
+ mapdl .cm ("kp_cm" , "kp" )
2247
+ assert "kp_cm" in mapdl .components
2248
+ assert kp1 in mapdl .components ["kp_cm" ].items
2249
+ assert "KP" == mapdl .components ["kp_cm" ].type
2250
+
2251
+ l1 = 1
2252
+ mapdl .lsel (vmin = l1 )
2253
+ assert l1 in mapdl .geometry .lnum
2254
+ mapdl .cm ("line_cm" , "line" )
2255
+ assert "line_cm" in mapdl .components
2256
+ assert l1 in mapdl .components ["line_cm" ].items
2257
+ assert "LINE" == mapdl .components ["line_cm" ].type
2258
+
2259
+ a1 = 1
2260
+ mapdl .asel (vmin = a1 )
2261
+ assert a1 in mapdl .geometry .anum
2262
+ mapdl .cm ("area_cm" , "area" )
2263
+ assert "area_cm" in mapdl .components
2264
+ assert a1 in mapdl .components ["area_cm" ].items
2265
+ assert "AREA" == mapdl .components ["area_cm" ].type
2266
+
2267
+ # Assert we have properly set the components
2268
+ assert {
2269
+ "AREA_CM" : "AREA" ,
2270
+ "ELEM_CM" : "ELEM" ,
2271
+ "KP_CM" : "KP" ,
2272
+ "LINE_CM" : "LINE" ,
2273
+ "NODES_CM" : "NODE" ,
2274
+ } == mapdl .components ._comp
2275
+
2276
+ # additional changes to the selections
2277
+ kpoints = mapdl .ksel ("u" , vmin = 1 )
2278
+ lines = mapdl .lsel ("a" , vmin = [2 , 5 , 6 ])
2279
+ areas = mapdl .asel ("a" , vmin = 2 )
2280
+ nodes = mapdl .nsel ("S" , vmin = [4 , 5 ])
2281
+ elem = mapdl .esel ("s" , vmin = [1 , 3 ])
2282
+
2283
+ # checking all the elements are correct
2284
+ assert np .allclose (kpoints , mapdl .geometry .knum )
2285
+ assert np .allclose (lines , mapdl .geometry .lnum )
2286
+ assert np .allclose (areas , mapdl .geometry .anum )
2287
+ assert np .allclose (nodes , mapdl .mesh .nnum )
2288
+ assert np .allclose (elem , mapdl .mesh .enum )
2289
+
2290
+ ## storing... __enter__
2291
+ comp_selection = mapdl .components ._comp
2292
+
2293
+ print ("Starting..." )
2294
+ with mapdl .save_selection :
2295
+
2296
+ # do something
2297
+ mapdl .allsel ()
2298
+ mapdl .cmsel ("NONE" )
2299
+ mapdl .asel ("NONE" )
2300
+ mapdl .nsel ("s" , vmin = [1 , 2 , 8 , 9 ])
2301
+ mapdl .allsel ()
2302
+ mapdl .vsel ("none" )
2303
+ mapdl .lsel ("a" , vmin = [9 ])
2304
+ mapdl .vsel ("all" )
2305
+ mapdl .ksel ("none" )
2306
+
2307
+ # checks
2308
+ assert np .allclose (kpoints , mapdl .geometry .knum )
2309
+ assert np .allclose (lines , mapdl .geometry .lnum )
2310
+ assert np .allclose (areas , mapdl .geometry .anum )
2311
+ assert np .allclose (nodes , mapdl .mesh .nnum )
2312
+ assert np .allclose (elem , mapdl .mesh .enum )
2313
+
2314
+ for each_key , each_value in comp_selection .items ():
2315
+ assert (
2316
+ each_key in mapdl .components
2317
+ ), f"Component '{ each_key } ' is not defined/selected"
2318
+ assert (
2319
+ each_value == mapdl .components [each_key ].type
2320
+ ), f"Component '{ each_key } ' type is not correct"
2321
+
2322
+ for each_tmp in _TMP_COMP .values ():
2323
+ assert each_tmp not in mapdl .components
2324
+
2325
+
2224
2326
def test_inquire_invalid (mapdl , cleared ):
2225
2327
with pytest .raises (ValueError , match = "Arguments of this method have changed" ):
2226
2328
mapdl .inquire ("directory" )
0 commit comments