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.

@@ -7,6 +7,7 @@ import math
7
7
  import os
8
8
  from typing import TYPE_CHECKING, Dict, List, Optional, Union
9
9
 
10
+ from ansys.api.pyensight.calc_funcs import ens_calculator
10
11
  from ansys.pyensight.core.utils.parts import convert_variable
11
12
  import numpy as np
12
13
 
@@ -49,6 +50,12 @@ class Variables:
49
50
 
50
51
  def __init__(self, ensight: Union["ensight_api.ensight", "ensight"]):
51
52
  self.ensight = ensight
53
+ self._calculator = ens_calculator(self.ensight)
54
+
55
+ @property
56
+ def calculator(self) -> "ens_calculator":
57
+ """Return the instance of the calculator functions class"""
58
+ return self._calculator
52
59
 
53
60
  def _check_for_var_elem(
54
61
  self, var_name: str, pobj_list: List["ENS_PART"]
@@ -77,8 +84,8 @@ class Variables:
77
84
  # within the list of parts used to calc var
78
85
  # if NOT then return None
79
86
  for prt in pobj_list:
80
- if prt not in var.PARTS:
81
- return None
87
+ if prt not in var.PARTS: # pragma: no cover
88
+ return None # pragma: no cover
82
89
  return var
83
90
  return None
84
91
 
@@ -153,11 +160,11 @@ class Variables:
153
160
  err = -1
154
161
  if not pobj_list or not calc_string:
155
162
  return False
156
- if len(calc_string) > 0 and len(pobj_list) > 0:
163
+ if len(calc_string) > 0 and len(pobj_list) > 0: # pragma: no cover
157
164
  self.ensight.utils.parts.select_parts(pobj_list)
158
165
  err = self.ensight.variables.evaluate(calc_string) # ,record=1)
159
- if err != 0:
160
- err_string = "Error calculating " + calc_string
166
+ if err != 0: # pragma: no cover
167
+ err_string = "Error calculating " + calc_string # pragma: no cover
161
168
  raise RuntimeError(err_string) # pragma: no cover
162
169
  return err == 0
163
170
 
@@ -250,15 +257,15 @@ class Variables:
250
257
  #
251
258
  _pobj_list: List["ENS_PART"]
252
259
  _pobj_list = self.ensight.utils.parts.select_parts(pobj_list)
253
- if not _pobj_list:
254
- return False
260
+ if not _pobj_list: # pragma: no cover
261
+ return False # pragma: no cover
255
262
  #
256
263
  # can be using shear force or shear stress
257
264
  #
258
- if shear_or_force_flag == "Shear stress":
265
+ if shear_or_force_flag == "Shear stress": # pragma: no cover
259
266
  stemp_string = "Stress"
260
- else:
261
- stemp_string = "Force"
267
+ else: # pragma: no cover
268
+ stemp_string = "Force" # pragma: no cover
262
269
  # create a surface normal vector variable using the
263
270
  # "Normal" function in the variable calculator.
264
271
  #
@@ -271,14 +278,14 @@ class Variables:
271
278
  #
272
279
  new_shear_var_obj: "ENS_VAR"
273
280
  shear_var_name: str
274
- if _shear_var_obj.LOCATION != self.ensight.objs.enums.ENS_VAR_ELEM:
281
+ if _shear_var_obj.LOCATION != self.ensight.objs.enums.ENS_VAR_ELEM: # pragma: no cover
275
282
  # tricks for mypy
276
283
  values = self._move_var_to_elem(_pobj_list, _shear_var_obj)
277
284
  ensvar_values = [v for v in values]
278
285
  new_shear_var_obj = ensvar_values[0]
279
286
  shear_var_name = new_shear_var_obj.DESCRIPTION
280
- else:
281
- shear_var_name = _shear_var_obj.DESCRIPTION
287
+ else: # pragma: no cover
288
+ shear_var_name = _shear_var_obj.DESCRIPTION # pragma: no cover
282
289
 
283
290
  #
284
291
  # Compute the Dot product of the Vector Normal and the FluidShearVector
@@ -357,7 +364,7 @@ class Variables:
357
364
  #
358
365
  # Calculate the Tangential Shear stress forces by multiplying each of the
359
366
  # Components of the Tangential Shear stress with Element Size scalar.
360
- if shear_or_force_flag == "Shear stress":
367
+ if shear_or_force_flag == "Shear stress": # pragma: no cover
361
368
  #
362
369
  # Calculate the element area Scalar using the "EleSize function in the Variable Calculator
363
370
  #
@@ -390,19 +397,19 @@ class Variables:
390
397
  return False # pragma: no cover
391
398
 
392
399
  else:
393
- temp_string = (
400
+ temp_string = ( # pragma: no cover
394
401
  "ENS_Force_Tan_ShearForce_X = ENS_Force_TangentialShear" + stemp_string + "_X"
395
402
  )
396
403
  if not self._calc_var(_pobj_list, temp_string): # pragma: no cover
397
404
  return False # pragma: no cover
398
405
 
399
- temp_string = (
406
+ temp_string = ( # pragma: no cover
400
407
  "ENS_Force_Tan_ShearForce_Y = ENS_Force_TangentialShear" + stemp_string + "_Y"
401
408
  )
402
409
  if not self._calc_var(_pobj_list, temp_string): # pragma: no cover
403
410
  return False # pragma: no cover
404
411
 
405
- temp_string = (
412
+ temp_string = ( # pragma: no cover
406
413
  "ENS_Force_Tan_ShearForce_Z = ENS_Force_TangentialShear" + stemp_string + "_Z"
407
414
  )
408
415
  if not self._calc_var(_pobj_list, temp_string): # pragma: no cover
@@ -508,38 +515,38 @@ class Variables:
508
515
  Fy: List[float] = []
509
516
  Fz: List[float] = []
510
517
  val = self.get_const_val("ENS_Force_Net_Tan_ShearForce_X", pobj_list)
511
- if not val:
512
- return None
518
+ if not val: # pragma: no cover
519
+ return None # pragma: no cover
513
520
  if val:
514
521
  if isinstance(val, list):
515
522
  for v in val:
516
- if not v:
517
- return None
523
+ if not v: # pragma: no cover
524
+ return None # pragma: no cover
518
525
  Fx.append(v)
519
526
  else:
520
527
  return None
521
528
  val = self.get_const_val("ENS_Force_Net_Tan_ShearForce_Y", pobj_list)
522
- if not val:
523
- return None
529
+ if not val: # pragma: no cover
530
+ return None # pragma: no cover
524
531
  if val:
525
532
  if isinstance(val, list):
526
533
  for v in val:
527
- if not v:
528
- return None
534
+ if not v: # pragma: no cover
535
+ return None # pragma: no cover
529
536
  Fy.append(v)
530
537
  else:
531
538
  return None
532
539
  val = self.get_const_val("ENS_Force_Net_Tan_ShearForce_Z", pobj_list)
533
- if not val:
534
- return None
540
+ if not val: # pragma: no cover
541
+ return None # pragma: no cover
535
542
  if val:
536
543
  if isinstance(val, list):
537
544
  for v in val:
538
- if not v:
539
- return None
545
+ if not v: # pragma: no cover
546
+ return None # pragma: no cover
540
547
  Fz.append(v)
541
548
  else:
542
- return None
549
+ return None # pragma: no cover
543
550
  #
544
551
  # Calculate the Total Shear force X, Y, and Z , 10.2.0(d) now case constant variable
545
552
  # Totals are a case constants. We don't do anything with these vars
@@ -621,38 +628,38 @@ class Variables:
621
628
  Ft: List[float] = []
622
629
  Fa: List[float] = []
623
630
  val = self.get_const_val("ENS_Force_Net_Tan_ShearForce_R", pobj_list)
624
- if not val:
625
- return None
631
+ if not val: # pragma: no cover
632
+ return None # pragma: no cover
626
633
  if val:
627
634
  if isinstance(val, list):
628
635
  for v in val:
629
- if not v:
630
- return None
636
+ if not v: # pragma: no cover
637
+ return None # pragma: no cover
631
638
  Fr.append(v)
632
639
  else:
633
- return None
640
+ return None # pragma: no cover
634
641
  val = self.get_const_val("ENS_Force_Net_Tan_ShearForce_T", pobj_list)
635
642
  if not val:
636
- return None
643
+ return None # pragma: no cover
637
644
  if val:
638
645
  if isinstance(val, list):
639
646
  for v in val:
640
- if not v:
641
- return None
647
+ if not v: # pragma: no cover
648
+ return None # pragma: no cover
642
649
  Ft.append(v)
643
650
  else:
644
651
  return None
645
652
  val = self.get_const_val("ENS_Force_Net_Tan_ShearForce_A", pobj_list)
646
- if not val:
647
- return None
653
+ if not val: # pragma: no cover
654
+ return None # pragma: no cover
648
655
  if val:
649
656
  if isinstance(val, list):
650
657
  for v in val:
651
- if not v:
652
- return None
658
+ if not v: # pragma: no cover
659
+ return None # pragma: no cover
653
660
  Fa.append(v)
654
661
  else:
655
- return None
662
+ return None # pragma: no cover
656
663
  if all([Fr, Fa, Ft, Fx, Fy, Fz]):
657
664
  ret_val = []
658
665
  for ii in range(len(pobj_list)):
@@ -795,8 +802,8 @@ class Variables:
795
802
  self.ensight.variables.activate(const_name) # bug fixed 10.1.6(c)
796
803
 
797
804
  if const_type == self.ensight.objs.enums.ENS_VAR_CONSTANT_PER_PART: # new in 10.2
798
- if not part_list:
799
- part_list = self.ensight.objs.core.PARTS
805
+ if not part_list: # pragma: no cover
806
+ part_list = self.ensight.objs.core.PARTS # pragma: no cover
800
807
 
801
808
  plist = self.ensight.utils.parts.get_part_id_obj_name(part_list, "obj")
802
809
  ret_val: List[Optional[float]] = []
@@ -804,12 +811,12 @@ class Variables:
804
811
  for prt in plist:
805
812
  if isinstance(prt, self.ensight.objs.ENS_PART):
806
813
  val_dict = prt.get_values([const_name])
807
- if val_dict:
814
+ if val_dict: # pragma: no cover
808
815
  val = float(val_dict[const_name][0])
809
816
  if undef_none and np.isclose(
810
817
  val, self.ensight.Undefined, rtol=1e-6, atol=1e-16
811
818
  ):
812
- ret_val.append(None)
819
+ ret_val.append(None) # pragma: no cover
813
820
  else:
814
821
  ret_val.append(val)
815
822
  else: # pragma: no cover
@@ -827,8 +834,10 @@ class Variables:
827
834
  # scope will be >= 0 if a command language global
828
835
  # (0 if command language global and >0 if local to a file or loop)
829
836
  if scope_val == -1 and type_val == 1: # EnSight constant and float
830
- if undef_none and np.isclose(val, self.ensight.Undefined, rtol=1e-6, atol=1e-16):
831
- return None
837
+ if undef_none and np.isclose(
838
+ val, self.ensight.Undefined, rtol=1e-6, atol=1e-16
839
+ ): # pragma: no cover
840
+ return None # pragma: no cover
832
841
  else:
833
842
  return val
834
843
  else: # pragma: no cover
@@ -926,21 +935,21 @@ class Variables:
926
935
  #
927
936
  _pobj_list: List["ENS_PART"]
928
937
  _pobj_list = self.ensight.utils.parts.select_parts(pobj_list)
929
- if not _pobj_list:
930
- return False
938
+ if not _pobj_list: # pragma: no cover
939
+ return False # pragma: no cover
931
940
  #
932
941
  # makes a new elem var if input var is nodal
933
942
  #
934
943
  new_pres_var_obj: "ENS_VAR"
935
944
  press_var_name: str
936
- if _press_var_obj.LOCATION != self.ensight.objs.enums.ENS_VAR_ELEM:
945
+ if _press_var_obj.LOCATION != self.ensight.objs.enums.ENS_VAR_ELEM: # pragma: no cover
937
946
  # tricks for mypy
938
947
  values = self._move_var_to_elem(_pobj_list, _press_var_obj)
939
948
  ensvar_values = [v for v in values]
940
949
  new_pres_var_obj = ensvar_values[0]
941
950
  press_var_name = new_pres_var_obj.DESCRIPTION
942
951
  else:
943
- press_var_name = _press_var_obj.DESCRIPTION
952
+ press_var_name = _press_var_obj.DESCRIPTION # pragma: no cover
944
953
 
945
954
  #
946
955
  # Calculate the Force vector
@@ -1069,38 +1078,38 @@ class Variables:
1069
1078
  Fy: List[float] = []
1070
1079
  Fz: List[float] = []
1071
1080
  val = self.get_const_val("ENS_Force_Net_press_X", pobj_list)
1072
- if not val:
1073
- return None
1081
+ if not val: # pragma: no cover
1082
+ return None # pragma: no cover
1074
1083
  if val:
1075
1084
  if isinstance(val, list):
1076
1085
  for v in val:
1077
- if not v:
1078
- return None
1086
+ if not v: # pragma: no cover
1087
+ return None # pragma: no cover
1079
1088
  Fx.append(v)
1080
1089
  else:
1081
- return None
1090
+ return None # pragma: no cover
1082
1091
  val = self.get_const_val("ENS_Force_Net_press_Y", pobj_list)
1083
- if not val:
1084
- return None
1092
+ if not val: # pragma: no cover
1093
+ return None # pragma: no cover
1085
1094
  if val:
1086
1095
  if isinstance(val, list):
1087
1096
  for v in val:
1088
- if not v:
1089
- return None
1097
+ if not v: # pragma: no cover
1098
+ return None # pragma: no cover
1090
1099
  Fy.append(v)
1091
1100
  else:
1092
- return None
1101
+ return None # pragma: no cover
1093
1102
  val = self.get_const_val("ENS_Force_Net_press_Z", pobj_list)
1094
- if not val:
1095
- return None
1103
+ if not val: # pragma: no cover
1104
+ return None # pragma: no cover
1096
1105
  if val:
1097
1106
  if isinstance(val, list):
1098
1107
  for v in val:
1099
- if not v:
1100
- return None
1108
+ if not v: # pragma: no cover
1109
+ return None # pragma: no cover
1101
1110
  Fz.append(v)
1102
1111
  else:
1103
- return None
1112
+ return None # pragma: no cover
1104
1113
  #
1105
1114
  #
1106
1115
  # Fr, Ft, Fa
@@ -1158,38 +1167,38 @@ class Variables:
1158
1167
  Ft: List[float] = []
1159
1168
  Fa: List[float] = []
1160
1169
  val = self.get_const_val("ENS_Force_Net_press_R", pobj_list)
1161
- if not val:
1162
- return None
1170
+ if not val: # pragma: no cover
1171
+ return None # pragma: no cover
1163
1172
  if val:
1164
1173
  if isinstance(val, list):
1165
1174
  for v in val:
1166
- if not v:
1167
- return None
1175
+ if not v: # pragma: no cover
1176
+ return None # pragma: no cover
1168
1177
  Fr.append(v)
1169
1178
  else:
1170
- return None
1179
+ return None # pragma: no cover
1171
1180
  val = self.get_const_val("ENS_Force_Net_press_T", pobj_list)
1172
- if not val:
1173
- return None
1181
+ if not val: # pragma: no cover
1182
+ return None # pragma: no cover
1174
1183
  if val:
1175
1184
  if isinstance(val, list):
1176
1185
  for v in val:
1177
- if not v:
1178
- return None
1186
+ if not v: # pragma: no cover
1187
+ return None # pragma: no cover
1179
1188
  Ft.append(v)
1180
1189
  else:
1181
- return None
1190
+ return None # pragma: no cover
1182
1191
  val = self.get_const_val("ENS_Force_Net_press_A", pobj_list)
1183
- if not val:
1184
- return None
1192
+ if not val: # pragma: no cover
1193
+ return None # pragma: no cover
1185
1194
  if val:
1186
1195
  if isinstance(val, list):
1187
1196
  for v in val:
1188
- if not v:
1189
- return None
1197
+ if not v: # pragma: no cover
1198
+ return None # pragma: no cover
1190
1199
  Fa.append(v)
1191
1200
  else:
1192
- return None
1201
+ return None # pragma: no cover
1193
1202
  #
1194
1203
  if all([Fr, Ft, Fz, Fx, Fy, Fz]):
1195
1204
  ret_val = []
@@ -1207,7 +1216,7 @@ class Variables:
1207
1216
  return ret_val
1208
1217
  else: # pragma: no cover
1209
1218
  err_string = "Error getting Fx, Fy, and/or Fz Pressure Net force per part constant values" # pragma: no cover # pragma: no cover
1210
- raise RuntimeError(err_string)
1219
+ raise RuntimeError(err_string) # pragma: no cover
1211
1220
 
1212
1221
  def _write_out_force_data(
1213
1222
  self,
@@ -1266,6 +1275,7 @@ class Variables:
1266
1275
  """
1267
1276
  frames = (
1268
1277
  self.ensight.objs.core.FRAMES is not None
1278
+ and len(self.ensight.objs.core.FRAMES) > 0
1269
1279
  and "frame_index" in params
1270
1280
  and int(params["frame_index"]) > 0
1271
1281
  )
@@ -1325,7 +1335,7 @@ class Variables:
1325
1335
  fp.write(
1326
1336
  ", Pressure Force Radial , Pressure Force Theta , Pressure Force Axial, Total Cyl Pressure Force "
1327
1337
  )
1328
- if shear_force_list:
1338
+ if shear_force_list: # pragma: no cover
1329
1339
  fp.write(
1330
1340
  ", Shear Force X , Shear Force Y , Shear Force Z , Total Shear Force "
1331
1341
  )
@@ -1340,7 +1350,7 @@ class Variables:
1340
1350
  fp.write(
1341
1351
  ", Press + Shear Force Radial , Press + Shear Force Theta , Press + Shear Force Axial , Total Press + Shear Force "
1342
1352
  )
1343
- if press_coeff_list:
1353
+ if press_coeff_list: # pragma: no cover
1344
1354
  fp.write(
1345
1355
  ", Coeff Press X , Coeff Press Y , Coeff Press Z , Total Coeff Press "
1346
1356
  )
@@ -1348,7 +1358,7 @@ class Variables:
1348
1358
  fp.write(
1349
1359
  ", Coeff Press Radial , Coeff Press Theta , Coeff Press Axial , Total Coeff Press "
1350
1360
  )
1351
- if shear_coeff_list:
1361
+ if shear_coeff_list: # pragma: no cover
1352
1362
  fp.write(
1353
1363
  ", Coeff Shear X , Coeff Shear Y , Coeff Shear Z , Total Coeff Shear ,"
1354
1364
  )
@@ -1363,20 +1373,20 @@ class Variables:
1363
1373
  fp.write(
1364
1374
  ", Coeff Press + Shear Radial , Coeff Press + Shear Theta , Coeff Press + Shear Axial , Total Coeff Press + Shear"
1365
1375
  )
1366
- if press_LDS_force_list:
1376
+ if press_LDS_force_list: # pragma: no cover
1367
1377
  fp.write(", Lift Force , Drag Force , Side Force , Total Pressure Force ")
1368
- if shear_LDS_force_list:
1378
+ if shear_LDS_force_list: # pragma: no cover
1369
1379
  fp.write(
1370
1380
  ", Shear Force L , Shear Force D , Shear Force Side , Total Shear Force LDS "
1371
1381
  )
1372
1382
  fp.write(
1373
1383
  ", Press + Shear Force L , Press + Shear Force D , Press + Shear Force Side , Total Press + Shear Force LDS "
1374
1384
  )
1375
- if press_LDS_coeff_list:
1385
+ if press_LDS_coeff_list: # pragma: no cover
1376
1386
  fp.write(
1377
1387
  ", Lift Coeff Press , Drag Coeff Press , Side Coeff Press , Total Coeff Press "
1378
1388
  )
1379
- if shear_LDS_coeff_list:
1389
+ if shear_LDS_coeff_list: # pragma: no cover
1380
1390
  fp.write(
1381
1391
  ", Lift Coeff Shear , Drag Coeff Shear , Side Coeff Shear , Coeff Shear LDS Total,"
1382
1392
  )
@@ -1412,7 +1422,7 @@ class Variables:
1412
1422
  #
1413
1423
  # shear force components then magnitude
1414
1424
  #
1415
- if shear_force_list:
1425
+ if shear_force_list: # pragma: no cover
1416
1426
  fp.write(" , ")
1417
1427
  for jj in range(3):
1418
1428
  fp.write(str(shear_force_list[ii][jj]))
@@ -1444,7 +1454,7 @@ class Variables:
1444
1454
  #
1445
1455
  # Coefficient of pressure force components then magnitude
1446
1456
  #
1447
- if press_coeff_list:
1457
+ if press_coeff_list: # pragma: no cover
1448
1458
  fp.write(" , ")
1449
1459
  for jj in range(3):
1450
1460
  fp.write(str(press_coeff_list[ii][jj]))
@@ -1459,92 +1469,112 @@ class Variables:
1459
1469
  #
1460
1470
  # Coefficient shear force components then magnitude
1461
1471
  #
1462
- if shear_coeff_list is not None and press_coeff_list is not None:
1463
- fp.write(" , ")
1464
- for jj in range(3):
1465
- fp.write(str(shear_coeff_list[ii][jj]))
1472
+ if (
1473
+ shear_coeff_list is not None and press_coeff_list is not None
1474
+ ): # pragma: no cover
1475
+ if (
1476
+ len(shear_coeff_list) > 0 and len(press_coeff_list) > 0
1477
+ ): # pragma: no cover
1466
1478
  fp.write(" , ")
1467
- fp.write(str(vec_mag(shear_coeff_list[ii][:3])))
1468
- fp.write(" , ")
1469
- if frames:
1470
1479
  for jj in range(3):
1471
- fp.write(str(shear_coeff_list[ii][jj + 3]))
1480
+ fp.write(str(shear_coeff_list[ii][jj]))
1472
1481
  fp.write(" , ")
1473
- fp.write(str(vec_mag(shear_coeff_list[ii][3:])))
1474
- fp.write(" , ")
1475
- # sum of pressure and shear Coefficient components then magnitude
1476
- for jj in range(3):
1477
- temp_list[jj] = press_coeff_list[ii][jj] + shear_coeff_list[ii][jj]
1478
- fp.write(str(temp_list[jj]))
1479
- fp.write(" , ")
1480
- fp.write(str(vec_mag(temp_list)))
1481
- if frames:
1482
+ fp.write(str(vec_mag(shear_coeff_list[ii][:3])))
1482
1483
  fp.write(" , ")
1484
+ if frames:
1485
+ for jj in range(3):
1486
+ fp.write(str(shear_coeff_list[ii][jj + 3]))
1487
+ fp.write(" , ")
1488
+ fp.write(str(vec_mag(shear_coeff_list[ii][3:])))
1489
+ fp.write(" , ")
1490
+ # sum of pressure and shear Coefficient components then magnitude
1483
1491
  for jj in range(3):
1484
1492
  temp_list[jj] = (
1485
- press_coeff_list[ii][jj + 3] + shear_coeff_list[ii][jj + 3]
1493
+ press_coeff_list[ii][jj] + shear_coeff_list[ii][jj]
1486
1494
  )
1487
1495
  fp.write(str(temp_list[jj]))
1488
1496
  fp.write(" , ")
1489
1497
  fp.write(str(vec_mag(temp_list)))
1490
- fp.write(" , ")
1498
+ if frames:
1499
+ fp.write(" , ")
1500
+ for jj in range(3):
1501
+ temp_list[jj] = (
1502
+ press_coeff_list[ii][jj + 3]
1503
+ + shear_coeff_list[ii][jj + 3]
1504
+ )
1505
+ fp.write(str(temp_list[jj]))
1506
+ fp.write(" , ")
1507
+ fp.write(str(vec_mag(temp_list)))
1508
+ fp.write(" , ")
1491
1509
  #
1492
1510
  # Lift, Drag and Side Force
1493
1511
  # No cylindrical stuff here
1494
1512
  # LDS pressure force components then magnitude
1495
1513
  #
1496
- if press_LDS_force_list:
1514
+ if press_LDS_force_list: # pragma: no cover
1497
1515
  for jj in range(3):
1498
1516
  fp.write(str(press_LDS_force_list[ii][jj]))
1499
1517
  fp.write(" , ")
1500
1518
  fp.write(str(vec_mag(press_LDS_force_list[ii][:3])))
1501
1519
  fp.write(" , ")
1502
1520
  # LDS shear force components then magnitude
1503
- if shear_LDS_force_list is not None and press_LDS_force_list is not None:
1504
- for jj in range(3):
1505
- fp.write(str(shear_LDS_force_list[ii][jj]))
1506
- fp.write(" , ")
1507
- fp.write(str(vec_mag(shear_LDS_force_list[ii][:3])))
1508
- fp.write(" , ")
1509
- # LDS sum of pressure and shear forces components then magnitude
1510
- for jj in range(3):
1511
- temp_list[jj] = (
1512
- press_LDS_force_list[ii][jj] + shear_LDS_force_list[ii][jj]
1513
- )
1514
- fp.write(str(temp_list[jj]))
1515
- fp.write(" , ")
1516
- fp.write(str(vec_mag(temp_list)))
1517
- fp.write(" , ")
1518
- # LDS Coefficient of pressure force components then magnitude
1519
- if press_LDS_coeff_list:
1520
- for jj in range(3):
1521
- fp.write(str(press_LDS_coeff_list[ii][jj]))
1521
+ if (
1522
+ shear_LDS_force_list is not None and press_LDS_force_list is not None
1523
+ ): # pragma: no cover
1524
+ if (
1525
+ len(shear_LDS_force_list) > 0 and len(press_LDS_force_list) > 0
1526
+ ): # pragma: no cover
1527
+ for jj in range(3):
1528
+ fp.write(str(shear_LDS_force_list[ii][jj]))
1529
+ fp.write(" , ")
1530
+ fp.write(str(vec_mag(shear_LDS_force_list[ii][:3])))
1522
1531
  fp.write(" , ")
1523
- fp.write(str(vec_mag(press_LDS_coeff_list[ii][:3])))
1524
- fp.write(" , ")
1525
- # LDS Coefficient shear force components then magnitude
1526
- if shear_LDS_coeff_list is not None and press_LDS_coeff_list is not None:
1527
- for jj in range(3):
1528
- fp.write(str(shear_LDS_coeff_list[ii][jj]))
1532
+ # LDS sum of pressure and shear forces components then magnitude
1533
+ for jj in range(3):
1534
+ temp_list[jj] = (
1535
+ press_LDS_force_list[ii][jj] + shear_LDS_force_list[ii][jj]
1536
+ )
1537
+ fp.write(str(temp_list[jj]))
1538
+ fp.write(" , ")
1539
+ fp.write(str(vec_mag(temp_list)))
1529
1540
  fp.write(" , ")
1530
- fp.write(str(vec_mag(shear_LDS_coeff_list[ii][:3])))
1531
- fp.write(" , ")
1532
- # LDS sum of pressure and shear Coefficient components then magnitude
1533
- for jj in range(3):
1534
- temp_list[jj] = (
1535
- press_LDS_coeff_list[ii][jj] + shear_LDS_coeff_list[ii][jj]
1536
- )
1537
- fp.write(str(temp_list[jj]))
1541
+ # LDS Coefficient of pressure force components then magnitude
1542
+ if press_LDS_coeff_list: # pragma: no cover
1543
+ for jj in range(3):
1544
+ fp.write(str(press_LDS_coeff_list[ii][jj]))
1545
+ fp.write(" , ")
1546
+ fp.write(str(vec_mag(press_LDS_coeff_list[ii][:3])))
1538
1547
  fp.write(" , ")
1539
- fp.write(str(vec_mag(temp_list)))
1540
- fp.write("\n")
1548
+ # LDS Coefficient shear force components then magnitude
1549
+ if ( # pragma: no cover
1550
+ shear_LDS_coeff_list is not None
1551
+ and press_LDS_coeff_list is not None
1552
+ ):
1553
+ if (
1554
+ len(shear_LDS_coeff_list) > 0 and len(press_LDS_coeff_list) > 0
1555
+ ): # pragma: no cover
1556
+ for jj in range(3):
1557
+ fp.write(str(shear_LDS_coeff_list[ii][jj]))
1558
+ fp.write(" , ")
1559
+ fp.write(str(vec_mag(shear_LDS_coeff_list[ii][:3])))
1560
+ fp.write(" , ")
1561
+ # LDS sum of pressure and shear Coefficient components then magnitude
1562
+ for jj in range(3):
1563
+ temp_list[jj] = (
1564
+ press_LDS_coeff_list[ii][jj]
1565
+ + shear_LDS_coeff_list[ii][jj]
1566
+ )
1567
+ fp.write(str(temp_list[jj]))
1568
+ fp.write(" , ")
1569
+ fp.write(str(vec_mag(temp_list)))
1570
+ fp.write("\n")
1541
1571
  # FIX ME keep track of and write out totals here when loop is done on last line?
1542
1572
  fp.close()
1543
1573
  return True
1544
1574
  except IOError: # pragma: no cover
1545
1575
  raise RuntimeError( # pragma: no cover
1546
1576
  "Error Failed to open output csv filename for writing '" + filename + "'"
1547
- ) # pragma: no cover
1577
+ )
1548
1578
  raise RuntimeError("Error no pressure force list to write out") # pragma: no cover
1549
1579
 
1550
1580
  @staticmethod
@@ -1572,15 +1602,15 @@ class Variables:
1572
1602
  """
1573
1603
  coeffs = []
1574
1604
  qS = area_ref * vel_ref * vel_ref * dens_ref / 2.0
1575
- if qS > 0:
1605
+ if qS > 0: # pragma: no cover
1576
1606
  for ff in Forces:
1577
1607
  coeffs.append(ff / qS)
1578
1608
  else:
1579
- coeffs = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
1609
+ coeffs = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0] # pragma: no cover
1580
1610
  return coeffs
1581
1611
 
1582
1612
  @staticmethod
1583
- def _get_up_vec(up_str: str) -> np.array:
1613
+ def _get_up_vec(up_str: str) -> np.array: # pragma: no cover
1584
1614
  """
1585
1615
  Convert the up_vector string to the actual components
1586
1616
 
@@ -1742,14 +1772,14 @@ class Variables:
1742
1772
  """
1743
1773
  if not frame_index:
1744
1774
  frame_index = 0
1745
- if not shear_var_type:
1775
+ if not shear_var_type: # pragma: no cover
1746
1776
  shear_var_type = self.SHEAR_VAR_TYPE_STRESS
1747
1777
  shear_map = {
1748
1778
  self.SHEAR_VAR_TYPE_STRESS: "Shear stress",
1749
1779
  self.SHEAR_VAR_TYPE_FORCE: "Shear force",
1750
1780
  }
1751
- if not up_vector:
1752
- up_vector = self.UP_VECTOR_PLUS_Z
1781
+ if not up_vector: # pragma: no cover
1782
+ up_vector = self.UP_VECTOR_PLUS_Z # pragma: no cover
1753
1783
  _pobj_list = self.ensight.utils.parts.select_parts(pobj_list)
1754
1784
  computed_press_forces: List[List[float]] = []
1755
1785
  computed_shear_forces: List[List[float]] = []
@@ -1759,15 +1789,15 @@ class Variables:
1759
1789
  computed_shear_forces_lds: List[List[float]] = []
1760
1790
  computed_press_forces_lds_coeffs: List[List[float]] = []
1761
1791
  computed_shear_forces_lds_coeffs: List[List[float]] = []
1762
- if press_var_obj:
1792
+ if press_var_obj: # pragma: no cover
1763
1793
  success = self._press_force_xyz_rtz(
1764
1794
  pobj_list=pobj_list, press_var_obj=press_var_obj, frame_index=frame_index
1765
1795
  )
1766
- if not success:
1767
- return None
1796
+ if not success: # pragma: no cover
1797
+ return None # pragma: no cover
1768
1798
  temp = self._sum_pressure_forces_xyz_rtz(pobj_list=pobj_list, frame_index=frame_index)
1769
- if not temp:
1770
- return None
1799
+ if not temp: # pragma: no cover
1800
+ return None # pragma: no cover
1771
1801
  computed_press_forces = temp.copy()
1772
1802
  if shear_var_obj:
1773
1803
  success = self._shear_force_xyz_rtz(
@@ -1789,7 +1819,7 @@ class Variables:
1789
1819
  ]
1790
1820
  )
1791
1821
  # Just making mypy happy
1792
- if (
1822
+ if ( # pragma: no cover
1793
1823
  coeffs_computation
1794
1824
  and velocity_x_ref is not None
1795
1825
  and velocity_y_ref is not None
@@ -1799,12 +1829,12 @@ class Variables:
1799
1829
  ):
1800
1830
  _vec_mag = vec_mag([velocity_x_ref, velocity_y_ref, velocity_z_ref])
1801
1831
  # We need to compute the force coeffs
1802
- if computed_press_forces:
1832
+ if computed_press_forces: # pragma: no cover
1803
1833
  for part_force in computed_press_forces:
1804
1834
  computed_press_force_coeffs.append(
1805
1835
  self._force_coeffs(part_force, area_ref, _vec_mag, density_ref)
1806
1836
  )
1807
- if computed_shear_forces:
1837
+ if computed_shear_forces: # pragma: no cover
1808
1838
  for part_force in computed_shear_forces:
1809
1839
  computed_shear_force_coeffs.append(
1810
1840
  self._force_coeffs(part_force, area_ref, _vec_mag, density_ref)
@@ -1812,7 +1842,7 @@ class Variables:
1812
1842
  lds = all(
1813
1843
  [x is not None for x in [up_vector, velocity_x_ref, velocity_y_ref, velocity_z_ref]]
1814
1844
  )
1815
- if lds:
1845
+ if lds: # pragma: no cover
1816
1846
  temp_np_vec = np.array([velocity_x_ref, velocity_y_ref, velocity_z_ref])
1817
1847
  drag_vec = temp_np_vec / np.sqrt(np.dot(temp_np_vec, temp_np_vec))
1818
1848
  up_vec = self._get_up_vec(up_vector)
@@ -1821,83 +1851,84 @@ class Variables:
1821
1851
  # Lift vec normalized
1822
1852
  temp_np_vec = np.cross(side_vec, drag_vec)
1823
1853
  lift_vec = temp_np_vec / np.sqrt(np.dot(temp_np_vec, temp_np_vec))
1824
- if computed_press_forces:
1854
+ if computed_press_forces: # pragma: no cover
1825
1855
  for part_force in computed_press_forces:
1826
1856
  computed_press_forces_lds.append(
1827
1857
  self._lds_forces(np.array(part_force), lift_vec, drag_vec, side_vec)
1828
1858
  )
1829
- if computed_shear_forces:
1859
+ if computed_shear_forces: # pragma: no cover
1830
1860
  for part_force in computed_shear_forces:
1831
1861
  computed_shear_forces_lds.append(
1832
1862
  self._lds_forces(np.array(part_force), lift_vec, drag_vec, side_vec)
1833
1863
  )
1834
- if coeffs_computation:
1835
- if computed_press_force_coeffs:
1864
+ if coeffs_computation: # pragma: no cover
1865
+ if computed_press_force_coeffs: # pragma: no cover
1836
1866
  for part_force in computed_press_force_coeffs:
1837
1867
  computed_press_forces_lds_coeffs.append(
1838
1868
  self._lds_forces(np.array(part_force), lift_vec, drag_vec, side_vec)
1839
1869
  )
1840
- if computed_shear_force_coeffs:
1870
+ if computed_shear_force_coeffs: # pragma: no cover
1841
1871
  for part_force in computed_shear_force_coeffs:
1842
1872
  computed_shear_forces_lds_coeffs.append(
1843
1873
  self._lds_forces(np.array(part_force), lift_vec, drag_vec, side_vec)
1844
1874
  )
1845
- if export_filename is not None and pobj_list is not None:
1846
- press_varname = None
1847
- shear_varname = None
1848
- if press_var_obj:
1849
- _press_var_id = convert_variable(self.ensight, press_var_obj)
1850
- if _press_var_id:
1851
- press_varnames = [
1852
- v for v in self.ensight.objs.core.VARIABLES if v.ID == _press_var_id
1853
- ]
1854
- if press_varnames:
1855
- press_varname = str(press_varnames[0].DESCRIPTION)
1856
- if shear_var_obj:
1857
- _shear_var_id = convert_variable(self.ensight, shear_var_obj)
1858
- if _shear_var_id:
1859
- shear_varnames = [
1860
- v for v in self.ensight.objs.core.VARIABLES if v.ID == _press_var_id
1861
- ]
1862
- if shear_varnames:
1863
- shear_varname = str(shear_varnames[0].DESCRIPTION)
1864
- params = {}
1865
- if press_varname:
1866
- params["press_varname"] = press_varname
1867
- if shear_varname:
1868
- params["shear_varname"] = shear_varname
1869
- if shear_var_type is not None:
1870
- value = shear_map.get(shear_var_type)
1871
- if value:
1872
- params["shear_vartype"] = value
1873
- if area_ref:
1874
- params["Area_ref"] = str(area_ref)
1875
- if density_ref:
1876
- params["Dens_ref"] = str(density_ref)
1877
- if velocity_x_ref:
1878
- params["Vx_ref"] = str(velocity_x_ref)
1879
- if velocity_y_ref:
1880
- params["Vy_ref"] = str(velocity_y_ref)
1881
- if velocity_z_ref:
1882
- params["Vz_ref"] = str(velocity_z_ref)
1883
- if up_vector:
1884
- params["up_vector"] = up_vector
1885
- if frame_index > 0:
1886
- params["frame_index"] = str(frame_index)
1887
-
1888
- self._write_out_force_data(
1889
- export_filename,
1890
- _pobj_list,
1891
- params=params,
1892
- press_force_list=computed_press_forces,
1893
- shear_force_list=computed_shear_forces,
1894
- press_coeff_list=computed_press_force_coeffs,
1895
- shear_coeff_list=computed_shear_force_coeffs,
1896
- press_LDS_force_list=computed_press_forces_lds,
1897
- shear_LDS_force_list=computed_shear_forces_lds,
1898
- press_LDS_coeff_list=computed_press_forces_lds_coeffs,
1899
- shear_LDS_coeff_list=computed_shear_forces_lds_coeffs,
1900
- )
1875
+ if export_filename is not None and pobj_list is not None: # pragma: no cover
1876
+ if len(pobj_list) > 0: # pragma: no cover
1877
+ press_varname = None
1878
+ shear_varname = None
1879
+ if press_var_obj: # pragma: no cover
1880
+ _press_var_id = convert_variable(self.ensight, press_var_obj)
1881
+ if _press_var_id: # pragma: no cover
1882
+ press_varnames = [
1883
+ v for v in self.ensight.objs.core.VARIABLES if v.ID == _press_var_id
1884
+ ]
1885
+ if press_varnames:
1886
+ press_varname = str(press_varnames[0].DESCRIPTION)
1887
+ if shear_var_obj: # pragma: no cover
1888
+ _shear_var_id = convert_variable(self.ensight, shear_var_obj)
1889
+ if _shear_var_id: # pragma: no cover
1890
+ shear_varnames = [
1891
+ v for v in self.ensight.objs.core.VARIABLES if v.ID == _press_var_id
1892
+ ]
1893
+ if shear_varnames: # pragma: no cover
1894
+ shear_varname = str(shear_varnames[0].DESCRIPTION)
1895
+ params = {}
1896
+ if press_varname: # pragma: no cover
1897
+ params["press_varname"] = press_varname
1898
+ if shear_varname: # pragma: no cover
1899
+ params["shear_varname"] = shear_varname
1900
+ if shear_var_type is not None: # pragma: no cover
1901
+ value = shear_map.get(shear_var_type)
1902
+ if value: # pragma: no cover
1903
+ params["shear_vartype"] = value
1904
+ if area_ref is not None: # pragma: no cover
1905
+ params["Area_ref"] = str(area_ref)
1906
+ if density_ref is not None: # pragma: no cover
1907
+ params["Dens_ref"] = str(density_ref)
1908
+ if velocity_x_ref is not None: # pragma: no cover
1909
+ params["Vx_ref"] = str(velocity_x_ref)
1910
+ if velocity_y_ref is not None: # pragma: no cover
1911
+ params["Vy_ref"] = str(velocity_y_ref)
1912
+ if velocity_z_ref is not None: # pragma: no cover
1913
+ params["Vz_ref"] = str(velocity_z_ref)
1914
+ if up_vector is not None: # pragma: no cover
1915
+ params["up_vector"] = up_vector
1916
+ if frame_index > 0:
1917
+ params["frame_index"] = str(frame_index)
1918
+
1919
+ self._write_out_force_data(
1920
+ export_filename,
1921
+ _pobj_list,
1922
+ params=params,
1923
+ press_force_list=computed_press_forces,
1924
+ shear_force_list=computed_shear_forces,
1925
+ press_coeff_list=computed_press_force_coeffs,
1926
+ shear_coeff_list=computed_shear_force_coeffs,
1927
+ press_LDS_force_list=computed_press_forces_lds,
1928
+ shear_LDS_force_list=computed_shear_forces_lds,
1929
+ press_LDS_coeff_list=computed_press_forces_lds_coeffs,
1930
+ shear_LDS_coeff_list=computed_shear_forces_lds_coeffs,
1931
+ )
1901
1932
  return {
1902
1933
  "pressure_forces": {
1903
1934
  p.DESCRIPTION: computed_press_forces[idx]