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

23 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-06-08 11:03 +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 typing import List as _List 

25 

26from beamme.core.boundary_condition import BoundaryCondition as _BoundaryCondition 

27from beamme.core.conf import bme as _bme 

28from beamme.core.function import Function as _Function 

29from beamme.core.geometry_set import GeometrySet as _GeometrySet 

30from beamme.core.rotation import Rotation as _Rotation 

31from beamme.four_c.function_utility import ( 

32 ensure_length_of_function_array as _ensure_length_of_function_array, 

33) 

34 

35 

36class LocSysCondition(_BoundaryCondition): 

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

38 

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

40 Dirichlet boundary conditions. 

41 """ 

42 

43 def __init__( 

44 self, 

45 geometry_set: _GeometrySet, 

46 *, 

47 rotation: None | _Rotation = None, 

48 function_array: None | _List[_Function | int] = None, 

49 update_node_position: bool = False, 

50 use_consistent_node_normal: bool = False, 

51 **kwargs, 

52 ): 

53 """Initialize the object. 

54 

55 Args: 

56 geometry_set: Geometry that this boundary condition acts on 

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

58 function_array: 

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

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

61 in which case no explicit rotation should be passed. 

62 update_node_position: Flag to enable the updated node position 

63 use_consistent_node_normal: Flag to use a consistent node normal 

64 """ 

65 

66 # Check for invalid input arguments 

67 if ( 

68 function_array is not None 

69 and len(function_array) > 1 

70 and rotation is not None 

71 ): 

72 raise ValueError( 

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

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

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

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

77 ) 

78 

79 # Validate provided function array 

80 if function_array is None: 

81 function_array = [0, 0, 0] 

82 else: 

83 function_array = _ensure_length_of_function_array(function_array, 3) 

84 

85 # Validate provided rotation 

86 if rotation is None: 

87 rotation_vector = [1, 1, 1] 

88 else: 

89 rotation_vector = rotation.get_rotation_vector() 

90 

91 condition_dict = { 

92 "ROTANGLE": rotation_vector, 

93 "FUNCT": function_array, 

94 "USEUPDATEDNODEPOS": int(update_node_position), 

95 } 

96 

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

98 if ( 

99 geometry_set.geometry_type is _bme.geo.line 

100 or geometry_set.geometry_type is _bme.geo.surface 

101 ): 

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

103 elif use_consistent_node_normal: 

104 raise ValueError( 

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

106 ) 

107 

108 super().__init__( 

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

110 )