ansys-pyensight-core 0.7.7__py3-none-any.whl → 0.7.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ansys-pyensight-core might be problematic. Click here for more details.

@@ -52,7 +52,7 @@ def convert_variable(
52
52
  return var
53
53
  elif hasattr(var, "ID"):
54
54
  return int(var.ID)
55
- return None
55
+ return None # pragma: no cover
56
56
 
57
57
 
58
58
  class Parts:
@@ -214,7 +214,7 @@ class Parts:
214
214
  found = ensobjlist([p for p, met in metadata.items() if met.get(tag) == value])
215
215
  elif value and not tag:
216
216
  found = ensobjlist([p for p, met in metadata.items() if value in met.values()])
217
- elif tag and not value:
217
+ elif tag and not value: # pragma: no cover
218
218
  found = ensobjlist([p for p, met in metadata.items() if tag in met.keys()])
219
219
  else:
220
220
  found = ensobjlist(
@@ -254,8 +254,10 @@ class Parts:
254
254
  """Private routine to create emitter objects"""
255
255
  new_emitters: List[Any] = []
256
256
  if emitter_type == self._EMIT_POINT:
257
- if not points:
258
- raise RuntimeError("list of points needed if particle trace emitted from points")
257
+ if not points: # pragma: no cover
258
+ raise RuntimeError(
259
+ "list of points needed if particle trace emitted from points"
260
+ ) # pragma: no cover
259
261
  for p in points:
260
262
  if isinstance(self.ensight, ModuleType): # pragma: no cover
261
263
  new_emitters.append(
@@ -280,7 +282,7 @@ class Parts:
280
282
  )
281
283
  elif emitter_type == self._EMIT_PLANE:
282
284
  if not any([point1, point2, point3]):
283
- raise RuntimeError(
285
+ raise RuntimeError( # pragma: no cover
284
286
  "point1, point2 and point3 needed if particle trace emitted from plane"
285
287
  )
286
288
  if isinstance(self.ensight, ModuleType): # pragma: no cover
@@ -298,9 +300,11 @@ class Parts:
298
300
  new_emitters.append(
299
301
  f"ensight.utils.parts._EnSEmitterGrid(ensight, point1={point1}, point2={point2}, point3={point3}, num_points_x={num_points_x}, num_points_y={num_points_y})"
300
302
  )
301
- elif emitter_type == self._EMIT_PART:
302
- if not parts:
303
- raise RuntimeError("part and num_points needed if particle trace emitted from part")
303
+ elif emitter_type == self._EMIT_PART: # pragma: no cover
304
+ if not parts: # pragma: no cover
305
+ raise RuntimeError(
306
+ "part and num_points needed if particle trace emitted from part"
307
+ ) # pragma: no cover
304
308
  for p in parts:
305
309
  if isinstance(self.ensight, ModuleType): # pragma: no cover
306
310
  new_emitters.append( # pragma: no cover
@@ -316,7 +320,9 @@ class Parts:
316
320
  f"ensight.utils.parts._EnSEmitterPart(ensight, part={convert_part(self.ensight ,p)}, num_points={num_points}, part_kind={part_distribution_type})"
317
321
  )
318
322
  else:
319
- raise RuntimeError("No input provided to create the emitters for the particle trace")
323
+ raise RuntimeError(
324
+ "No input provided to create the emitters for the particle trace"
325
+ ) # pragma: no cover
320
326
  return new_emitters
321
327
 
322
328
  def _create_particle_trace_part(
@@ -349,7 +355,7 @@ class Parts:
349
355
  def_part.TOTALTIME = total_time
350
356
  if delta_time:
351
357
  def_part.DELTATIME = delta_time
352
- if emit_time:
358
+ if emit_time: # pragma: no cover
353
359
  def_part.STARTTIME = emit_time
354
360
  def_part.DESCRIPTION = name
355
361
  def_part.VARIABLE = convert_variable(self.ensight, variable)
@@ -407,15 +413,17 @@ class Parts:
407
413
  """Private utility to cure an input particle trace part and convert it to an ``ENS_PART`"""
408
414
 
409
415
  # the add_emitter* functions were added in 2024 R2
410
- if not isinstance(self.ensight, ModuleType):
416
+ if not isinstance(self.ensight, ModuleType): # pragma: no cover
411
417
  self.ensight._session.ensight_version_check("2024 R2")
412
418
 
413
419
  _particle_trace_part: "ENS_PART_PARTICLE_TRACE"
414
- if isinstance(particle_trace_part, (str, int)):
415
- temp = self.ensight.objs.core.PARTS[particle_trace_part]
416
- if not temp:
417
- raise RuntimeError("particle_trace_part input is not a valid part")
418
- _particle_trace_part = temp[0]
420
+ if isinstance(particle_trace_part, (str, int)): # pragma: no cover
421
+ temp = self.ensight.objs.core.PARTS[particle_trace_part] # pragma: no cover
422
+ if not temp: # pragma: no cover
423
+ raise RuntimeError(
424
+ "particle_trace_part input is not a valid part"
425
+ ) # pragma: no cover
426
+ _particle_trace_part = temp[0] # pragma: no cover
419
427
  else:
420
428
  _particle_trace_part = particle_trace_part
421
429
  return _particle_trace_part
@@ -428,29 +436,32 @@ class Parts:
428
436
  """Private utility to set the direction if not provided, and to cure the list of source parts."""
429
437
 
430
438
  # the create_particle* functions were added in 2024 R2
431
- if not isinstance(self.ensight, ModuleType):
439
+ if not isinstance(self.ensight, ModuleType): # pragma: no cover
432
440
  self.ensight._session.ensight_version_check("2024 R2")
433
441
 
434
442
  if not direction:
435
443
  direction = self.PT_POS_TIME
436
- if source_parts:
444
+ if source_parts: # pragma: no cover
437
445
  converted_source_parts = [convert_part(self.ensight, p) for p in source_parts]
438
- if not source_parts:
439
- converted_source_parts = self.ensight.objs.core.selection(name="ENS_PART")
440
- if not converted_source_parts:
441
- raise RuntimeError("No part selected for particle trace generation")
446
+ if not source_parts: # pragma: no cover
447
+ converted_source_parts = self.ensight.objs.core.selection( # pragma: no cover
448
+ name="ENS_PART"
449
+ )
450
+ if not converted_source_parts: # pragma: no cover
451
+ raise RuntimeError("No part selected for particle trace generation") # pragma: no cover
442
452
  return direction, converted_source_parts
443
453
 
444
454
  def _find_palette(self, color_by: Optional[Union[str, int, "ENS_VAR"]] = None) -> Optional[str]:
445
455
  """Private utility to find the description of the input color_by variable"""
446
456
  palette: Optional[str] = None
447
457
  if color_by:
448
- _color_by_var: List["ENS_VAR"] = ensight.objs.core.VARIABLES[
449
- convert_variable(self.ensight, color_by)
450
- ]
451
- if _color_by_var:
452
- palette = _color_by_var[0].DESCRIPTION
453
- else:
458
+ try:
459
+ _color_by_var: List["ENS_VAR"] = self.ensight.objs.core.VARIABLES.find(
460
+ [convert_variable(self.ensight, color_by)], attr="ID"
461
+ )
462
+ if _color_by_var:
463
+ palette = _color_by_var[0].DESCRIPTION
464
+ except Exception:
454
465
  raise RuntimeError(
455
466
  "The variable supplied to color the particle trace by does not exist"
456
467
  )
@@ -1141,20 +1152,23 @@ class Parts:
1141
1152
  p_list = [plist]
1142
1153
  elif isinstance(plist, list) or isinstance(plist, ensobjlist):
1143
1154
  p_list = [p for p in plist]
1144
- else:
1145
- raise RuntimeError("Unknown type of input var plist {}".format(type(plist)))
1155
+ else: # pragma: no cover
1156
+ raise RuntimeError( # pragma: no cover
1157
+ "Unknown type of input var plist {}".format(type(plist))
1158
+ )
1146
1159
  #
1147
1160
  # p_list must now be a list
1148
1161
  #
1149
1162
 
1150
1163
  if not p_list:
1151
1164
  return None
1152
- if not isinstance(p_list[0], (str, int, self.ensight.objs.ENS_PART)):
1153
- error = "First member is neither ENS_PART, int, nor string"
1154
- error += f"{p_list[0]} type = {type(p_list[0])}; aborting"
1155
- raise RuntimeError(error)
1165
+ if not isinstance(p_list[0], (str, int, self.ensight.objs.ENS_PART)): # pragma: no cover
1166
+ error = "First member is neither ENS_PART, int, nor string" # pragma: no cover
1167
+ error += f"{p_list[0]} type = {type(p_list[0])}; aborting" # pragma: no cover
1168
+ raise RuntimeError(error) # pragma: no cover
1156
1169
  pobjs: List["ENS_PART"]
1157
- if isinstance(p_list[0], int): # list of ints must be part ids
1170
+ if isinstance(p_list[0], int):
1171
+ # list of ints must be part ids
1158
1172
  for pid in p_list:
1159
1173
  pobjs = [p for p in self.ensight.objs.core.PARTS if p.PARTNUMBER == pid]
1160
1174
  for prt in pobjs:
@@ -1181,5 +1195,5 @@ class Parts:
1181
1195
  if ret_flag == "obj":
1182
1196
  val_objs = [p for p in pobj_list]
1183
1197
  return val_objs
1184
- val_ints = [int(p.ID) for p in pobj_list]
1198
+ val_ints = [int(p.PARTNUMBER) for p in pobj_list]
1185
1199
  return val_ints
@@ -160,27 +160,31 @@ class Query:
160
160
  >>> point1=pnt1, point2=pnt2, new_plotter=True)
161
161
 
162
162
  """
163
- if query_type not in [self.DISTANCE_PART1D, self.DISTANCE_LINE, self.DISTANCE_SPLINE]:
164
- raise RuntimeError(f"Invalid query type: {query_type} specified.")
163
+ if query_type not in [
164
+ self.DISTANCE_PART1D,
165
+ self.DISTANCE_LINE,
166
+ self.DISTANCE_SPLINE,
167
+ ]: # pragma: no cover
168
+ raise RuntimeError(f"Invalid query type: {query_type} specified.") # pragma: no cover
165
169
 
166
170
  var1 = self._get_variable(variable1)
167
171
  var2 = self._get_variable(variable2, "DISTANCE")
168
172
 
169
173
  if query_type == self.DISTANCE_LINE:
170
- if (point1 is None) or (point2 is None):
171
- raise RuntimeError("Both point1 and point2 must be specified.")
174
+ if (point1 is None) or (point2 is None): # pragma: no cover
175
+ raise RuntimeError("Both point1 and point2 must be specified.") # pragma: no cover
172
176
  self._create_query_core_begin(name, part_list)
173
177
  self._ensight.query_ent_var.number_of_sample_pts(num_samples)
174
178
  self._ensight.query_ent_var.constrain("line_tool")
175
179
  self._ensight.query_ent_var.line_loc(1, *point1)
176
180
  self._ensight.query_ent_var.line_loc(2, *point2)
177
181
 
178
- elif query_type == self.DISTANCE_PART1D:
182
+ elif query_type == self.DISTANCE_PART1D: # pragma: no cover
179
183
  self._create_query_core_begin(name, part_list, single=True)
180
184
  self._ensight.query_ent_var.constrain("1d_part")
181
185
  self._ensight.query_ent_var.multiple_segments_by(segments_by)
182
186
 
183
- elif query_type == self.DISTANCE_SPLINE:
187
+ elif query_type == self.DISTANCE_SPLINE: # pragma: no cover
184
188
  if spline_name is None:
185
189
  raise RuntimeError("A spline_name must be specified.")
186
190
  self._create_query_core_begin(name, part_list)
@@ -291,7 +295,7 @@ class Query:
291
295
  >>> s.ensight.utils.query.TEMPORAL_MAXIMUM, parts, "plastic", new_plotter=True)
292
296
 
293
297
  """
294
- if query_type not in [
298
+ if query_type not in [ # pragma: no cover
295
299
  self.TEMPORAL_NODE,
296
300
  self.TEMPORAL_ELEMENT,
297
301
  self.TEMPORAL_IJK,
@@ -299,19 +303,19 @@ class Query:
299
303
  self.TEMPORAL_MINIMUM,
300
304
  self.TEMPORAL_MAXIMUM,
301
305
  ]:
302
- raise RuntimeError(f"Invalid query type: {query_type} specified.")
306
+ raise RuntimeError(f"Invalid query type: {query_type} specified.") # pragma: no cover
303
307
 
304
308
  var1 = self._get_variable(variable1)
305
309
  var2 = self._get_variable(variable2, "TIME")
306
310
 
307
311
  # default the time range
308
- if start_time is None:
312
+ if start_time is None: # pragma: no cover
309
313
  start_time = self._ensight.objs.core.SOLUTIONTIME_LIMITS[0]
310
- if end_time is None:
314
+ if end_time is None: # pragma: no cover
311
315
  end_time = self._ensight.objs.core.SOLUTIONTIME_LIMITS[1]
312
316
 
313
317
  # default the number of timesteps
314
- if num_samples is None:
318
+ if num_samples is None: # pragma: no cover
315
319
  num_samples = (
316
320
  self._ensight.objs.core.TIMESTEP_LIMITS[1]
317
321
  - self._ensight.objs.core.TIMESTEP_LIMITS[0]
@@ -319,38 +323,38 @@ class Query:
319
323
  )
320
324
 
321
325
  if query_type == self.TEMPORAL_NODE:
322
- if node_id is None:
323
- raise RuntimeError("node_id must be specified.")
326
+ if node_id is None: # pragma: no cover
327
+ raise RuntimeError("node_id must be specified.") # pragma: no cover
324
328
  self._create_query_core_begin(name, part_list)
325
329
  self._ensight.query_ent_var.constrain("node")
326
330
  self._ensight.query_ent_var.node_id(node_id)
327
331
 
328
332
  elif query_type == self.TEMPORAL_ELEMENT:
329
- if element_id is None:
330
- raise RuntimeError("element_id must be specified.")
333
+ if element_id is None: # pragma: no cover
334
+ raise RuntimeError("element_id must be specified.") # pragma: no cover
331
335
  self._create_query_core_begin(name, part_list)
332
336
  self._ensight.query_ent_var.constrain("element")
333
337
  self._ensight.query_ent_var.elem_id(element_id)
334
338
 
335
339
  elif query_type == self.TEMPORAL_XYZ:
336
- if xyz is None:
337
- raise RuntimeError("xyz must be specified.")
340
+ if xyz is None: # pragma: no cover
341
+ raise RuntimeError("xyz must be specified.") # pragma: no cover
338
342
  self._create_query_core_begin(name, part_list)
339
343
  self._ensight.query_ent_var.constrain("cursor")
340
344
  self._ensight.query_ent_var.cursor_loc(*xyz)
341
345
 
342
346
  elif query_type == self.TEMPORAL_IJK:
343
- if ijk is None:
344
- raise RuntimeError("ijk must be specified.")
345
- self._create_query_core_begin(name, part_list)
346
- self._ensight.query_ent_var.constrain("ijk")
347
- self._ensight.query_ent_var.ijk(*ijk)
347
+ if ijk is None: # pragma: no cover
348
+ raise RuntimeError("ijk must be specified.") # pragma: no cover
349
+ self._create_query_core_begin(name, part_list) # pragma: no cover
350
+ self._ensight.query_ent_var.constrain("ijk") # pragma: no cover
351
+ self._ensight.query_ent_var.ijk(*ijk) # pragma: no cover
348
352
 
349
353
  elif query_type == self.TEMPORAL_MINIMUM:
350
354
  self._create_query_core_begin(name, part_list)
351
355
  self._ensight.query_ent_var.constrain("min")
352
356
 
353
- elif query_type == self.TEMPORAL_MAXIMUM:
357
+ elif query_type == self.TEMPORAL_MAXIMUM: # pragma: no cover
354
358
  self._create_query_core_begin(name, part_list)
355
359
  self._ensight.query_ent_var.constrain("max")
356
360
 
@@ -388,12 +392,12 @@ class Query:
388
392
  try:
389
393
  query = max(self._ensight.objs.core.QUERIES)
390
394
  # no new id allocated
391
- if query.__OBJID__ < nextid:
392
- error_msg = "Unable to create the specified query."
393
- except ValueError:
394
- error_msg = "Unable to create the specified query."
395
- if error_msg:
396
- raise RuntimeError(error_msg)
395
+ if query.__OBJID__ < nextid: # pragma: no cover
396
+ error_msg = "Unable to create the specified query." # pragma: no cover
397
+ except ValueError: # pragma: no cover
398
+ error_msg = "Unable to create the specified query." # pragma: no cover
399
+ if error_msg: # pragma: no cover
400
+ raise RuntimeError(error_msg) # pragma: no cover
397
401
  return query
398
402
 
399
403
  def _create_query_core_begin(self, name: str, parts: Optional[List[int]], single=False) -> None:
@@ -414,14 +418,16 @@ class Query:
414
418
 
415
419
  """
416
420
  part_list = []
417
- if parts:
421
+ if parts: # pragma: no cover
418
422
  for p in parts:
419
- if type(p) == str:
420
- part_list.append(self._ensight.objs.core.PARTS[p][0].PARTNUMBER)
421
- elif type(p) == int:
422
- part_list.append(p)
423
+ if type(p) == str: # pragma: no cover
424
+ part_list.append(
425
+ self._ensight.objs.core.PARTS[p][0].PARTNUMBER
426
+ ) # pragma: no cover
427
+ elif type(p) == int: # pragma: no cover
428
+ part_list.append(p) # pragma: no cover
423
429
  else:
424
- if hasattr(p, "PARTNUMBER"):
430
+ if hasattr(p, "PARTNUMBER"): # pragma: no cover
425
431
  part_list.append(p.PARTNUMBER)
426
432
  if not single:
427
433
  self._ensight.part.select_begin(part_list)