From 7a7e02f4be52c92117c1b0870933d88bc8864348 Mon Sep 17 00:00:00 2001 From: MichalO Date: Thu, 7 Apr 2022 10:45:15 +0200 Subject: [PATCH] added delete function and session status corrected: '= [],' to ': list = None,' --- Examples/TrussGenerator_2D/TrussGenerator.py | 2 -- RFEM/BasicObjects/member.py | 6 ++--- RFEM/BasicObjects/node.py | 2 +- .../modalAnalysisSettings.py | 2 +- RFEM/Loads/freeLoad.py | 12 ++++----- RFEM/Loads/memberLoad.py | 18 ++++++------- RFEM/Loads/membersetload.py | 22 +++++++-------- RFEM/Loads/nodalLoad.py | 4 +-- .../ConcreteDurability.py | 4 +-- .../ConcreteReinforcementDirections.py | 2 +- RFEM/initModel.py | 27 ++++++++++++++----- UnitTests/test_Export.py | 2 +- 12 files changed, 58 insertions(+), 45 deletions(-) diff --git a/Examples/TrussGenerator_2D/TrussGenerator.py b/Examples/TrussGenerator_2D/TrussGenerator.py index 92614d2a..8dad52e8 100644 --- a/Examples/TrussGenerator_2D/TrussGenerator.py +++ b/Examples/TrussGenerator_2D/TrussGenerator.py @@ -64,8 +64,6 @@ print('dirname: ', dirName) sys.path.append(dirName + r'/../..') from RFEM.enums import * -from RFEM.window import * -from RFEM.dataTypes import * from RFEM.initModel import * from RFEM.BasicObjects.material import * from RFEM.BasicObjects.section import * diff --git a/RFEM/BasicObjects/member.py b/RFEM/BasicObjects/member.py index b145aae8..c59da8d8 100644 --- a/RFEM/BasicObjects/member.py +++ b/RFEM/BasicObjects/member.py @@ -82,7 +82,7 @@ def Beam( rotation_parameters = [0], start_section_no: int = 1, end_section_no: int = 1, - distribution_parameters = [], + distribution_parameters: list = None, comment: str = '', params: dict = {'member_hinge_start':0, 'member_hinge_end': 0, 'member_eccentricity_start': 0, 'member_eccentricity_end': 0, @@ -1268,8 +1268,8 @@ def ResultBeam( rotation_parameters = [0], start_section_no: int = 1, end_section_no: int = 1, - distribution_parameters = [], - integration_parameters = [], + distribution_parameters: list = None, + integration_parameters: list = None, comment: str = '', params: dict = { 'end_modifications_member_start_extension': 0, 'end_modifications_member_start_slope_y': 0, diff --git a/RFEM/BasicObjects/node.py b/RFEM/BasicObjects/node.py index 899f1193..8d29daa1 100644 --- a/RFEM/BasicObjects/node.py +++ b/RFEM/BasicObjects/node.py @@ -51,7 +51,7 @@ def __init__(self, @staticmethod def Standard( no: int = 1, - coordinate_system = [], + coordinate_system: list = None, coordinate_system_type = NodeCoordinateSystemType.COORDINATE_SYSTEM_CARTESIAN, comment: str = '', params: dict = None, diff --git a/RFEM/LoadCasesAndCombinations/modalAnalysisSettings.py b/RFEM/LoadCasesAndCombinations/modalAnalysisSettings.py index cabc7108..3f4daf7b 100644 --- a/RFEM/LoadCasesAndCombinations/modalAnalysisSettings.py +++ b/RFEM/LoadCasesAndCombinations/modalAnalysisSettings.py @@ -9,7 +9,7 @@ def __init__(self, mass_conversion_type = ModalMassConversionType.MASS_CONVERSION_TYPE_Z_COMPONENTS_OF_LOADS, mass_matrix_type = ModalMassMatrixType.MASS_MATRIX_TYPE_CONSISTENT, number_of_modes : int = 4, - acting_masses = [], + acting_masses: list = None, neglect_masses = ModalNeglectMasses.E_NEGLECT_MASSES_NO_NEGLECTION, comment: str = '', params: dict = None, diff --git a/RFEM/Loads/freeLoad.py b/RFEM/Loads/freeLoad.py index f446d729..5fe2c9e4 100644 --- a/RFEM/Loads/freeLoad.py +++ b/RFEM/Loads/freeLoad.py @@ -89,7 +89,7 @@ def LineLoad( load_distribution = FreeLineLoadLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_projection = FreeLoadLoadProjection.LOAD_PROJECTION_XY_OR_UV, load_direction = FreeLineLoadLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, comment: str = '', params: dict = None, model = Model): @@ -173,9 +173,9 @@ def RectangularLoad( load_distribution = FreeRectangularLoadLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_projection = FreeLoadLoadProjection.LOAD_PROJECTION_XY_OR_UV, load_direction = FreeRectangularLoadLoadDirection.LOAD_DIRECTION_GLOBAL_Z_TRUE, - load_magnitude_parameter = [], + load_magnitude_parameter: list = None, load_location = FreeRectangularLoadLoadLocationRectangle.LOAD_LOCATION_RECTANGLE_CORNER_POINTS, - load_location_parameter = [], + load_location_parameter: list = None, comment: str = '', params: dict = None, model = Model): @@ -447,7 +447,7 @@ def CircularLoad( load_distribution = FreeCircularLoadLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_projection = FreeLoadLoadProjection.LOAD_PROJECTION_XY_OR_UV, load_direction = FreeCircularLoadLoadDirection.LOAD_DIRECTION_GLOBAL_Z_TRUE, - load_parameter = [], + load_parameter: list = None, comment: str = '', params: dict = None, model = Model): @@ -530,8 +530,8 @@ def PolygonLoad( load_distribution = FreePolygonLoadLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_projection = FreeLoadLoadProjection.LOAD_PROJECTION_XY_OR_UV, load_direction = FreePolygonLoadLoadDirection.LOAD_DIRECTION_GLOBAL_Z_TRUE, - load_location = [], - load_parameter = [], + load_location: list = None, + load_parameter: list = None, comment: str = '', params: dict = None, model = Model): diff --git a/RFEM/Loads/memberLoad.py b/RFEM/Loads/memberLoad.py index bad14248..d9cd996a 100644 --- a/RFEM/Loads/memberLoad.py +++ b/RFEM/Loads/memberLoad.py @@ -70,7 +70,7 @@ def Force( members_no: str = '1', load_distribution= MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction= MemberLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, force_eccentricity: bool= False, list_reference: bool= False, comment: str = '', @@ -373,7 +373,7 @@ def Moment( members_no: str = '1', load_distribution= MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction= MemberLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, list_reference: bool= False, comment: str = '', params: dict = None, @@ -601,7 +601,7 @@ def Mass( load_case_no: int = 1, members_no: str = '1', individual_mass_components: bool=False, - mass_components = [], + mass_components: list = None, comment: str = '', params: dict = None, model = Model): @@ -669,7 +669,7 @@ def Temperature( members_no: str = '1', load_distribution = MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, list_reference: bool= False, load_over_total_length: bool= False, comment: str = '', @@ -829,7 +829,7 @@ def TemperatureChange( members_no: str = '1', load_distribution = MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, list_reference: bool= False, load_over_total_length: bool= False, comment: str = '', @@ -989,7 +989,7 @@ def AxialStrain( members_no: str = '1', load_distribution = MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberLoadDirection.LOAD_DIRECTION_LOCAL_X, - load_parameter = [], + load_parameter: list = None, list_reference: bool= False, load_over_total_length: bool= False, comment: str = '', @@ -1199,7 +1199,7 @@ def Precamber( members_no: str = '1', load_distribution = MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, list_reference: bool= False, load_over_total_length: bool= False, comment: str = '', @@ -1409,7 +1409,7 @@ def Displacement( members_no: str = '1', load_distribution = MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, list_reference: bool= False, load_over_total_length: bool= False, comment: str = '', @@ -1647,7 +1647,7 @@ def Rotation( members_no: str = '1', load_distribution = MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, list_reference: bool= False, load_over_total_length: bool= False, comment: str = '', diff --git a/RFEM/Loads/membersetload.py b/RFEM/Loads/membersetload.py index b6db9ab6..1eba3fb9 100644 --- a/RFEM/Loads/membersetload.py +++ b/RFEM/Loads/membersetload.py @@ -72,7 +72,7 @@ def Force( member_sets: str = '1', load_distribution= MemberSetLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction= MemberSetLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, force_eccentricity: bool= False, comment: str = '', params: dict = None, @@ -404,7 +404,7 @@ def Moment( member_sets: str = '1', load_distribution= MemberSetLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction= MemberSetLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, comment: str = '', params: dict = None, model = Model): @@ -662,7 +662,7 @@ def Mass( load_case_no: int = 1, member_sets: str = '1', individual_mass_components: bool=False, - mass_components = [], + mass_components: list = None, comment: str = '', params: dict = None, model = Model): @@ -728,7 +728,7 @@ def Temperature( member_sets: str = '1', load_distribution = MemberSetLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberSetLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, load_over_total_length: bool= False, comment: str = '', params: dict = None, @@ -905,7 +905,7 @@ def TemperatureChange( member_sets: str = '1', load_distribution = MemberSetLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberSetLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, load_over_total_length: bool= False, comment: str = '', params: dict = None, @@ -1076,7 +1076,7 @@ def AxialStrain( member_sets: str = '1', load_distribution = MemberSetLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberSetLoadDirection.LOAD_DIRECTION_LOCAL_X, - load_parameter = [], + load_parameter: list = None, load_over_total_length: bool= False, comment: str = '', params: dict = None, @@ -1295,7 +1295,7 @@ def Precamber( member_sets: str = '1', load_distribution = MemberSetLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberSetLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, load_over_total_length: bool= False, comment: str = '', params: dict = None, @@ -1515,7 +1515,7 @@ def Displacement( member_sets: str = '1', load_distribution = MemberSetLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberSetLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, load_over_total_length: bool= False, comment: str = '', params: dict = None, @@ -1782,7 +1782,7 @@ def Rotation( member_sets: str = '1', load_distribution = MemberSetLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, load_direction = MemberSetLoadDirection.LOAD_DIRECTION_LOCAL_Z, - load_parameter = [], + load_parameter: list = None, load_over_total_length: bool= False, comment: str = '', params: dict = None, @@ -2238,8 +2238,8 @@ def RotaryMotion( axis_definition_type = MemberSetLoadAxisDefinitionType.AXIS_DEFINITION_TWO_POINTS, axis_orientation = MemberSetLoadAxisDefinitionAxisOrientation.AXIS_POSITIVE, axis_definition = MemberSetLoadAxisDefinition.AXIS_X, - axis_definition_p1 = [], - axis_definition_p2 = [], + axis_definition_p1: list = None, + axis_definition_p2: list = None, comment: str = '', params: dict = None, model = Model): diff --git a/RFEM/Loads/nodalLoad.py b/RFEM/Loads/nodalLoad.py index 9bf48028..a99c0099 100644 --- a/RFEM/Loads/nodalLoad.py +++ b/RFEM/Loads/nodalLoad.py @@ -330,7 +330,7 @@ def Components( no: int= 1, load_case_no: int= 1, nodes_no: str= '1', - components = [], + components: list = None, specific_direction: bool= False, force_eccentricity: bool= False, shifted_display: bool= False, @@ -469,7 +469,7 @@ def Mass( load_case_no: int = 1, nodes_no: str = '1', individual_mass_components : bool = False, - mass = [], + mass: list = None, comment: str = '', params: dict = None, model = Model): diff --git a/RFEM/TypesforConcreteDesign/ConcreteDurability.py b/RFEM/TypesforConcreteDesign/ConcreteDurability.py index aedefbe3..5b495eeb 100644 --- a/RFEM/TypesforConcreteDesign/ConcreteDurability.py +++ b/RFEM/TypesforConcreteDesign/ConcreteDurability.py @@ -9,9 +9,9 @@ def __init__(self, member_sets_no: str = "1", surfaces_no: str = "1", exposure_classes_reinforcement = [True, False, False, False], - exposure_classes_reinforcement_types = [], + exposure_classes_reinforcement_types: list = None, exposure_classes_concrete = [False, False, False], - exposure_classes_concrete_types = [], + exposure_classes_concrete_types: list = None, structural_class = [DurabilityStructuralClassType.STANDARD, False, False, False, False], stainless_steel_reduction = [False], additional_protection_reduction = [False], diff --git a/RFEM/TypesforConcreteDesign/ConcreteReinforcementDirections.py b/RFEM/TypesforConcreteDesign/ConcreteReinforcementDirections.py index bb0e4371..ca68bbc9 100644 --- a/RFEM/TypesforConcreteDesign/ConcreteReinforcementDirections.py +++ b/RFEM/TypesforConcreteDesign/ConcreteReinforcementDirections.py @@ -8,7 +8,7 @@ def __init__(self, name: str = "RD 1", surfaces = "1", reinforcement_direction_type = ReinforcementDirectionType.REINFORCEMENT_DIRECTION_TYPE_FIRST_REINFORCEMENT_IN_X, - rotation_parameters = [], + rotation_parameters: list = None, comment: str = '', params: dict = None, model = Model): diff --git a/RFEM/initModel.py b/RFEM/initModel.py index ca77581a..5c07825b 100644 --- a/RFEM/initModel.py +++ b/RFEM/initModel.py @@ -132,6 +132,8 @@ class Model(): clientModel = None + clientModelLst = [] + activeSession = False def __init__(self, new_model: bool=True, @@ -161,7 +163,7 @@ def __init__(self, modelIndex = i new = client.service.get_model(modelIndex) + 'wsdl' # Set transport parameter if it is the first model - if modelLs: + if Model.activeSession: cModel = Client(new) else: cModel = Client(new, transport=trans) @@ -169,17 +171,19 @@ def __init__(self, cModel.service.delete_all() else: new = client.service.new_model(model_name) + 'wsdl' - if modelLs: + if Model.activeSession: cModel = Client(new) else: cModel = Client(new, transport=trans) + if not modelLs: + Model.activeSession = True else: modelIndex = 0 for i,j in enumerate(modelLs.name): if modelLs.name[i] == model_name: modelIndex = i new = client.service.get_model(modelIndex) + 'wsdl' - if modelLs: + if Model.activeSession: cModel = Client(new) else: cModel = Client(new, transport=trans) @@ -192,9 +196,19 @@ def __init__(self, # when using multiple intances/model self.clientModel = cModel + if not modelLs or not model_name in modelLs.name: + Model.clientModelLst.append(cModel) # when using only one instace/model - if not modelLs: - Model.clientModel = cModel + Model.clientModel = cModel + + + def __delete__(self, index): + if len(self.clientModelLst) == 1: + self.clientModelLst.clear() + self.clientModel = None + else: + self.clientModelLst.pop(index) + self.clientModel = self.clientModelLst[-1] def clearAtributes(obj): ''' @@ -214,10 +228,11 @@ def clearAtributes(obj): def closeModel(index_or_name, save_changes = False): """ Close any model with index or name. Be sure to close the first created - model last. It carries whole session. + model last (2,1, and then 0). It carries whole session. """ if isinstance(index_or_name, int): client.service.close_model(index_or_name, save_changes) + Model.__delete__(Model, index_or_name) elif isinstance(index_or_name, str): modelLs = client.service.get_model_list() for i,j in enumerate(modelLs.name): diff --git a/UnitTests/test_Export.py b/UnitTests/test_Export.py index 693d3a5a..3913cfa3 100644 --- a/UnitTests/test_Export.py +++ b/UnitTests/test_Export.py @@ -16,7 +16,7 @@ if Model.clientModel is None: Model() -pytestmark = pytest.mark.skipif(CheckIfMethodOrTypeExists(Model.clientModel,'export_to_ifc', True), reason="export_to_ifc not in RFEM GM yet") +pytest.mark.xfail(reason="Calculate_all() performs incosistently.", strict=False) def test_export(): Model.clientModel.service.delete_all()