Coverage for src/meshpy/four_c/locsys_condition.py: 95%

20 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-28 04:21 +0000

1# The MIT License (MIT) 

2# 

3# Copyright (c) 2018-2025 MeshPy Authors 

4# 

5# Permission is hereby granted, free of charge, to any person obtaining a copy 

6# of this software and associated documentation files (the "Software"), to deal 

7# in the Software without restriction, including without limitation the rights 

8# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 

9# copies of the Software, and to permit persons to whom the Software is 

10# furnished to do so, subject to the following conditions: 

11# 

12# The above copyright notice and this permission notice shall be included in 

13# all copies or substantial portions of the Software. 

14# 

15# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 

16# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 

17# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 

18# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 

19# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 

20# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 

21# THE SOFTWARE. 

22"""This file contains the wrapper for the LocSys condition for 4c.""" 

23 

24from typing import List as _List 

25from typing import Optional as _Optional 

26from typing import Union as _Union 

27 

28from meshpy.core.boundary_condition import BoundaryCondition as _BoundaryCondition 

29from meshpy.core.conf import mpy as _mpy 

30from meshpy.core.geometry_set import GeometrySet as _GeometrySet 

31from meshpy.core.rotation import Rotation as _Rotation 

32from meshpy.four_c.function import Function as _Function 

33from meshpy.four_c.function_utility import ( 

34 ensure_length_of_function_array as _ensure_length_of_function_array, 

35) 

36 

37 

38class LocSysCondition(_BoundaryCondition): 

39 """This object represents a locsys condition in 4C. 

40 

41 It allows to rotate the local coordinate system used to apply 

42 Dirichlet boundary conditions. 

43 """ 

44 

45 def __init__( 

46 self, 

47 geometry_set: _GeometrySet, 

48 rotation: _Rotation, 

49 *, 

50 function_array: _Optional[_List[_Union[_Function, int]]] = None, 

51 update_node_position: bool = False, 

52 use_consistent_node_normal: bool = False, 

53 **kwargs, 

54 ): 

55 """Initialize the object. 

56 

57 Args: 

58 geometry_set: Geometry that this boundary condition acts on 

59 rotation: Object that represents the rotation of the coordinate system 

60 function_array: _List containing functions 

61 update_node_position: Flag to enable the updated node position 

62 use_consistent_node_normal: Flag to use a consistent node normal 

63 """ 

64 

65 # Validate provided function array. 

66 if function_array is None: 

67 function_array = [0, 0, 0] 

68 else: 

69 function_array = _ensure_length_of_function_array(function_array, 3) 

70 

71 condition_dict = { 

72 "ROTANGLE": rotation.get_rotation_vector().tolist(), 

73 "FUNCT": function_array, 

74 "USEUPDATEDNODEPOS": int(update_node_position), 

75 } 

76 

77 # Append the condition string with consistent normal type for line and surface geometry 

78 if ( 

79 geometry_set.geometry_type is _mpy.geo.line 

80 or geometry_set.geometry_type is _mpy.geo.surface 

81 ): 

82 condition_dict["USECONSISTENTNODENORMAL"] = int(use_consistent_node_normal) 

83 elif use_consistent_node_normal: 

84 raise ValueError( 

85 "The keyword use_consistent_node_normal only works for line and surface geometries." 

86 ) 

87 

88 super().__init__( 

89 geometry_set, data=condition_dict, bc_type=_mpy.bc.locsys, **kwargs 

90 )