From c6311a601db36ac354a60287f32addc305fdf36f Mon Sep 17 00:00:00 2001 From: MichalO Date: Tue, 26 Apr 2022 07:21:34 +0200 Subject: [PATCH] updated NodalMeshRefinement and NodalSupport added tests unit tests: 136 passed, 9 skipped in 173.69s --- RFEM/TypesForNodes/nodalMeshRefinement.py | 151 ++++++++++++++++++++++ RFEM/TypesForNodes/nodalSupport.py | 37 ++++-- RFEM/enums.py | 7 +- UnitTests/test_TypesForNodes.py | 82 ++++++++++++ 4 files changed, 267 insertions(+), 10 deletions(-) create mode 100644 UnitTests/test_TypesForNodes.py diff --git a/RFEM/TypesForNodes/nodalMeshRefinement.py b/RFEM/TypesForNodes/nodalMeshRefinement.py index 00105f5b..f5a5d2ad 100644 --- a/RFEM/TypesForNodes/nodalMeshRefinement.py +++ b/RFEM/TypesForNodes/nodalMeshRefinement.py @@ -1,11 +1,98 @@ from RFEM.initModel import Model, clearAtributes +from RFEM.enums import NodalMeshRefinementType +from enum import Enum + +class FElengthArrangement(Enum): + LENGTH_ARRANGEMENT_RADIAL, LENGTH_ARRANGEMENT_GRADUALLY, LENGTH_ARRANGEMENT_COMBINED = range(3) class NodalMeshRefinement(): def __init__(self, no: int = 1, + type = NodalMeshRefinementType.TYPE_CIRCULAR, + mesh_parameters: list = None, + apply_on_selected_surfaces: bool = False, + comment: str = '', + params: dict = None, + model = Model): + """ + Nodal Mesh Refinement + + Args: + no (int, optional): Number + type (_type_, optional): TYPE_CIRCULAR or TYPE_RECTANGULAR + mesh_parameters (list, optional): _description_. Defaults to None. + if TYPE_CIRCULAR: + (circular_radius, circular_target_inner_length, circular_target_outer_length, circular_length_arrangement) + (2.5, 0.1, 0.5, FElengthArrangement.LENGTH_ARRANGEMENT_RADIAL) + elif TYPE_RECTANGULAR: + (rectangular_side, rectangular_target_inner_length) + (0.5, 0.1) + comment (str, optional): Comment + params (dict, optional): Any WS Parameter relevant to the object and its value in form of a dictionary + model (_type_, optional): Model instance + """ + + # Client model | Nodal Mesh Refinement + clientObject = model.clientModel.factory.create('ns0:nodal_mesh_refinement') + + # Clears object atributes | Sets all atributes to None + clearAtributes(clientObject) + + # Nodal Mesh Refinement No. + clientObject.no = no + + # Nodal Mesh Refinement Type + clientObject.type = type.name + + # Mesh Parameters + if type == NodalMeshRefinementType.TYPE_CIRCULAR: + clientObject.circular_radius = mesh_parameters[0] + clientObject.circular_target_inner_length = mesh_parameters[1] + clientObject.circular_target_outer_length = mesh_parameters[2] + clientObject.circular_length_arrangement = mesh_parameters[3].name + elif type == NodalMeshRefinementType.TYPE_RECTANGULAR: + clientObject.rectangular_side = mesh_parameters[0] + clientObject.rectangular_target_inner_length = mesh_parameters[1] + + # Apply Only on Selected Surfaces + clientObject.apply_only_on_selected_surfaces = apply_on_selected_surfaces + + # Comment + clientObject.comment = comment + + # Adding optional parameters via dictionary + if params: + for key in params: + clientObject[key] = params[key] + + # Add Nodal Mesh Refinement to client model + model.clientModel.service.set_nodal_mesh_refinement(clientObject) + + @staticmethod + def Circular( + no: int = 1, + circular_radius: float = 2.5, + circular_target_inner_length: float = 0.1, + circular_target_outer_length: float = 0.5, + circular_length_arrangement = FElengthArrangement.LENGTH_ARRANGEMENT_RADIAL, + apply_on_selected_surfaces: bool = False, comment: str = '', params: dict = None, model = Model): + """ + Circular Nodal Mesh Refinement + + Args: + no (int, optional): Number + circular_radius (float, optional): Radius + circular_target_inner_length (float, optional): Inner target FE length + circular_target_outer_length (float, optional): Outer target FE length + circular_length_arrangement (_type_, optional): FE length arrangenemt + apply_on_selected_surfaces (bool, optional): Apply only on surfaces + comment (str, optional): Comment + params (dict, optional): Any WS Parameter relevant to the object and its value in form of a dictionary + model (_type_, optional): Model instance + """ # Client model | Nodal Mesh Refinement clientObject = model.clientModel.factory.create('ns0:nodal_mesh_refinement') @@ -16,6 +103,70 @@ def __init__(self, # Nodal Mesh Refinement No. clientObject.no = no + # Nodal Mesh Refinement Type + clientObject.type = NodalMeshRefinementType.TYPE_CIRCULAR.name + + # Mesh Parameters + clientObject.circular_radius = circular_radius + clientObject.circular_target_inner_length = circular_target_inner_length + clientObject.circular_target_outer_length = circular_target_outer_length + clientObject.circular_length_arrangement = circular_length_arrangement.name + + # Apply Only on Selected Surfaces + clientObject.apply_only_on_selected_surfaces = apply_on_selected_surfaces + + # Comment + clientObject.comment = comment + + # Adding optional parameters via dictionary + if params: + for key in params: + clientObject[key] = params[key] + + # Add Nodal Mesh Refinement to client model + model.clientModel.service.set_nodal_mesh_refinement(clientObject) + + @staticmethod + def Rectangular( + no: int = 1, + rectangular_side: float = 2.5, + rectangular_target_inner_length: float = 0.1, + apply_on_selected_surfaces: bool = False, + comment: str = '', + params: dict = None, + model = Model): + """ + Rectangular Nodal Mesh Refinement + + Args: + no (int, optional): Number + rectangular_side (float, optional): Side length + rectangular_target_inner_length (float, optional): Inner target FE length + apply_on_selected_surfaces (bool, optional): Apply only on surfaces + comment (str, optional): Comment + params (dict, optional): Any WS Parameter relevant to the object and its value in form of a dictionary + model (_type_, optional): Model instance + """ + + # Client model | Nodal Mesh Refinement + clientObject = model.clientModel.factory.create('ns0:nodal_mesh_refinement') + + # Clears object atributes | Sets all atributes to None + clearAtributes(clientObject) + + # Nodal Mesh Refinement No. + clientObject.no = no + + # Nodal Mesh Refinement Type + clientObject.type = NodalMeshRefinementType.TYPE_RECTANGULAR.name + + # Mesh Parameters + clientObject.rectangular_side = rectangular_side + clientObject.rectangular_target_inner_length = rectangular_target_inner_length + + # Apply Only on Selected Surfaces + clientObject.apply_only_on_selected_surfaces = apply_on_selected_surfaces + # Comment clientObject.comment = comment diff --git a/RFEM/TypesForNodes/nodalSupport.py b/RFEM/TypesForNodes/nodalSupport.py index 291f0447..827de569 100644 --- a/RFEM/TypesForNodes/nodalSupport.py +++ b/RFEM/TypesForNodes/nodalSupport.py @@ -16,7 +16,6 @@ def setNodalSupportConditions(clientObject, clientObject: Client model object | Nodal support C_u_X,Y,Z: Translational support conditions in respected direction C_phi_X,Y,Z: Rotational support conditions about respected axis - comment: Comment Returns: clientObject: Initialized client model object | Nodal Support @@ -36,10 +35,24 @@ class NodalSupport(): def __init__(self, no: int = 1, nodes_no: str = '1 2', - support_type = NodalSupportType.HINGED, + support = NodalSupportType.HINGED, comment: str = '', params: dict = None, model = Model): + """ + Nodal Support + + Args: + no (int, optional): Number + nodes_no (str, optional): Assigned to nodes + support (enum or list, optional): Support definition + comment (str, optional): Commment + params (dict, optional): Any WS Parameter relevant to the object and its value in form of a dictionary + model (_type_, optional): Model instance + + Raises: + ValueError: 'Support parameter can be enum or list with 6 items.' + """ # Client model | Nodal Support clientObject = model.clientModel.factory.create('ns0:nodal_support') @@ -54,34 +67,40 @@ def __init__(self, clientObject.nodes = ConvertToDlString(nodes_no) # Nodal Support Conditions - if support_type == NodalSupportType.FIXED: + if support == NodalSupportType.FIXED: # FIXED 'xxx xxx' clientObject = setNodalSupportConditions(clientObject, inf, inf, inf, inf, inf, inf) - elif support_type == NodalSupportType.HINGED: + elif support == NodalSupportType.HINGED: # HINGED 'xxx --x' clientObject = setNodalSupportConditions(clientObject, inf, inf, inf, 0.0, 0.0, inf) - elif support_type == NodalSupportType.ROLLER: + elif support == NodalSupportType.ROLLER: # ROLLER '--x --x' clientObject = setNodalSupportConditions(clientObject, 0.0, 0.0, inf, 0.0, 0.0, inf) - elif support_type == NodalSupportType.ROLLER_IN_X: + elif support == NodalSupportType.ROLLER_IN_X: # ROLLER_IN_X '-xx --x' clientObject = setNodalSupportConditions(clientObject, 0.0, inf, inf, 0.0, 0.0, inf) - elif support_type == NodalSupportType.ROLLER_IN_Y: + elif support == NodalSupportType.ROLLER_IN_Y: # ROLLER_IN_Y 'x-x --x' clientObject = setNodalSupportConditions(clientObject, inf, 0.0, inf, 0.0, 0.0, inf) - elif support_type == NodalSupportType.ROLLER_IN_Z: + elif support == NodalSupportType.ROLLER_IN_Z: # ROLLER_IN_Z 'xx- --x' clientObject = setNodalSupportConditions(clientObject, inf, inf, 0.0, 0.0, 0.0, inf) - elif support_type == NodalSupportType.FREE: + elif support == NodalSupportType.FREE: # FREE '--- ---' clientObject = setNodalSupportConditions(clientObject, 0, 0, 0, 0, 0, 0) + elif isinstance(support, list) and len(support) == 6: + clientObject = setNodalSupportConditions(clientObject, support[0], support[1], support[2], support[3], support[4], support[5]) + + else: + raise ValueError('Support parameter can be enum or list with 6 items.') + # Comment clientObject.comment = comment diff --git a/RFEM/enums.py b/RFEM/enums.py index 5a65ddd5..14ed74e7 100644 --- a/RFEM/enums.py +++ b/RFEM/enums.py @@ -1750,7 +1750,6 @@ class SteelBoundaryConditionsSupportType(Enum): SUPPORT_TYPE_FIXED_IN_Y_AND_WARPING, SUPPORT_TYPE_INDIVIDUALLY, SUPPORT_TYPE_NONE, SUPPORT_TYPE_TORSION, SUPPORT_TYPE_TORSION_AND_WARPING = range( 9) - class SteelBoundaryConditionsEccentricityTypeZ(Enum): ''' Steel Boundary Conditions Eccentricity Type Z Type @@ -1758,6 +1757,12 @@ class SteelBoundaryConditionsEccentricityTypeZ(Enum): ECCENTRICITY_TYPE_AT_LOWER_FLANGE, ECCENTRICITY_TYPE_AT_UPPER_FLANGE, ECCENTRICITY_TYPE_NONE, ECCENTRICITY_TYPE_USER_VALUE = range( 4) +class NodalMeshRefinementType(Enum): + ''' + Nodal Mesh Refinement + ''' + TYPE_CIRCULAR, TYPE_RECTANGULAR = range(2) + class ActionCategoryType(Enum): ''' diff --git a/UnitTests/test_TypesForNodes.py b/UnitTests/test_TypesForNodes.py new file mode 100644 index 00000000..a97bec81 --- /dev/null +++ b/UnitTests/test_TypesForNodes.py @@ -0,0 +1,82 @@ +import os +import sys +PROJECT_ROOT = os.path.abspath(os.path.join( + os.path.dirname(__file__), + os.pardir) +) +sys.path.append(PROJECT_ROOT) + +import pytest +from RFEM.enums import NodalMeshRefinementType, NodalSupportType +from RFEM.initModel import Model +from RFEM.BasicObjects.material import Material +from RFEM.BasicObjects.node import Node +from RFEM.BasicObjects.line import Line +from RFEM.BasicObjects.surface import Surface +from RFEM.BasicObjects.thickness import Thickness +from RFEM.TypesForNodes.nodalSupport import NodalSupport +from RFEM.TypesForNodes.nodalMeshRefinement import NodalMeshRefinement, FElengthArrangement +from RFEM.TypesForNodes.nodalSupport import NodalSupport +from RFEM.dataTypes import inf + + +if Model.clientModel is None: + Model() + +def test_typesForNodes(): + + Model.clientModel.service.delete_all() + Model.clientModel.service.begin_modification() + + Material(1, 'S235') + Thickness(1, 'Thick', 1, 0.35) + + Node(1, 0, 0, 0) + Node(2, 5, 0, 0) + Node(3, 5, 5, 0) + Node(4, 0, 5, 0) + Node(5,2.5,2.5,-2.5) + + NodalSupport(1, '1 2', [inf, inf, inf, 0.0, 0.0, inf]) + NodalSupport(2, '3', NodalSupportType.FIXED) + NodalSupport(3, '4', NodalSupportType.ROLLER_IN_X) + with pytest.raises(ValueError): + NodalSupport(4, '5', [inf, inf, inf, 0.0]) + + NodalMeshRefinement(1, NodalMeshRefinementType.TYPE_CIRCULAR, [2.2, 0.1, 0.5, FElengthArrangement.LENGTH_ARRANGEMENT_RADIAL]) + NodalMeshRefinement.Circular(2, 3) + NodalMeshRefinement.Rectangular(3, 2.7) + Model.clientModel.service.finish_modification() + + nodalSupport = Model.clientModel.service.get_nodal_support(1) + assert nodalSupport.spring_x == inf + assert nodalSupport.spring_y == inf + assert nodalSupport.spring_z == inf + assert nodalSupport.rotational_restraint_x == 0 + assert nodalSupport.rotational_restraint_y == 0 + assert nodalSupport.rotational_restraint_z == inf + + nodalSupport = Model.clientModel.service.get_nodal_support(2) + assert nodalSupport.spring_x == inf + assert nodalSupport.spring_y == inf + assert nodalSupport.spring_z == inf + assert nodalSupport.rotational_restraint_x == inf + assert nodalSupport.rotational_restraint_y == inf + assert nodalSupport.rotational_restraint_z == inf + + nodalSupport = Model.clientModel.service.get_nodal_support(3) + assert nodalSupport.spring_x == 0 + assert nodalSupport.spring_y == inf + assert nodalSupport.spring_z == inf + assert nodalSupport.rotational_restraint_x == 0 + assert nodalSupport.rotational_restraint_y == 0 + assert nodalSupport.rotational_restraint_z == inf + + nodalMeshRefinement = Model.clientModel.service.get_nodal_mesh_refinement(1) + assert nodalMeshRefinement.circular_radius == 2.2 + + nodalMeshRefinement = Model.clientModel.service.get_nodal_mesh_refinement(2) + assert nodalMeshRefinement.circular_radius == 3 + + nodalMeshRefinement = Model.clientModel.service.get_nodal_mesh_refinement(3) + assert nodalMeshRefinement.rectangular_side == 2.7