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

22 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-28 15:20 +0000

1# The MIT License (MIT) 

2# 

3# Copyright (c) 2018-2026 BeamMe 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 beamme.core.boundary_condition import BoundaryCondition as _BoundaryCondition 

25from beamme.core.conf import bme as _bme 

26from beamme.core.function import Function as _Function 

27from beamme.core.geometry_set import GeometrySet as _GeometrySet 

28from beamme.core.rotation import Rotation as _Rotation 

29from beamme.four_c.function_utility import ( 

30 ensure_length_of_function_array as _ensure_length_of_function_array, 

31) 

32 

33 

34class LocSysCondition(_BoundaryCondition): 

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

36 

37 It allows to rotate the local coordinate system used to apply Dirichlet boundary 

38 conditions. 

39 """ 

40 

41 def __init__( 

42 self, 

43 geometry_set: _GeometrySet, 

44 *, 

45 rotation: None | _Rotation = None, 

46 function_array: None | list[_Function | int] = None, 

47 update_node_position: bool = False, 

48 use_consistent_node_normal: bool = False, 

49 **kwargs, 

50 ): 

51 """Initialize the object. 

52 

53 Args: 

54 geometry_set: Geometry that this boundary condition acts on 

55 rotation: Object that represents the rotation of the coordinate system. 

56 function_array: 

57 - If a single function is provided, it is used to scale the entire rotation. 

58 - If three functions are provided, they represent the components of a rotation vector, 

59 in which case no explicit rotation should be passed. 

60 update_node_position: Flag to enable the updated node position 

61 use_consistent_node_normal: Flag to use a consistent node normal 

62 """ 

63 # Check for invalid input arguments 

64 if ( 

65 function_array is not None 

66 and len(function_array) > 1 

67 and rotation is not None 

68 ): 

69 raise ValueError( 

70 "If more than a single function is provided in `function_array`, " 

71 "no explicit `rotation` should be given. Either provide " 

72 "a rotation with a single function (scaling), or three " 

73 "functions (rotation vector components) without rotation." 

74 ) 

75 

76 # Validate provided function array 

77 if function_array is None: 

78 function_array = [0, 0, 0] 

79 else: 

80 function_array = _ensure_length_of_function_array(function_array, 3) 

81 

82 # Validate provided rotation 

83 if rotation is None: 

84 rotation_vector = [1, 1, 1] 

85 else: 

86 rotation_vector = rotation.get_rotation_vector() 

87 

88 condition_dict = { 

89 "ROTANGLE": rotation_vector, 

90 "FUNCT": function_array, 

91 "USEUPDATEDNODEPOS": int(update_node_position), 

92 } 

93 

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

95 if ( 

96 geometry_set.geometry_type is _bme.geo.line 

97 or geometry_set.geometry_type is _bme.geo.surface 

98 ): 

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

100 elif use_consistent_node_normal: 

101 raise ValueError( 

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

103 ) 

104 

105 super().__init__( 

106 geometry_set, data=condition_dict, bc_type=_bme.bc.locsys, **kwargs 

107 )