Closed damianbobrowski closed 1 year ago
Hi Damian, With second script you're trying to create a connection, while there is already a connection going on at the same model.
The easy solution is, you can create multiple model in one script and edit them. Please take a look at the following Wiki article.
https://github.com/Dlubal-Software/RFEM_Python_Client/wiki/How-to-edit-multiple-models-in-one-script
You can control easily, which function will edit which model with the 'model' argument that every class has.
Please take a look at that, and let us know for any further questions.
Hi @dogukankaratas
The easy solution is, you can create multiple model in one script and edit them. Please take a look at the following Wiki article.
Switching between model is not my Use Case. In my Use Case model is created, calculated, verified and reports are generated. And I am looking for answer is it possible to execute multiple tasks in parallel.
You can control easily, which function will edit which model with the 'model' argument that every class has.
I passed model argument to each call and run two scripts. Here I explicitly choose model but the same problem for me. Is it expected? Is it means is not possible to work with models in parallel?
from RFEM.BasicObjects.material import Material
from RFEM.BasicObjects.member import Member
from RFEM.BasicObjects.node import Node
from RFEM.BasicObjects.section import Section
from RFEM.dataTypes import inf
from RFEM.enums import (
ActionCategoryType,
AnalysisType,
DesignSituationType,
LoadDirectionType,
MemberHingeDiagramType,
MemberHingeNonlinearity,
MemberLoadDirection,
MemberLoadDistribution,
)
from RFEM.ImportExport.exports import ExportResultTablesToCSV
from RFEM.initModel import Calculate_all, closeModel, Model
from RFEM.LoadCasesAndCombinations.designSituation import DesignSituation
from RFEM.LoadCasesAndCombinations.loadCase import LoadCase
from RFEM.LoadCasesAndCombinations.loadCasesAndCombinations import (
LoadCasesAndCombinations,
)
from RFEM.LoadCasesAndCombinations.loadCombination import LoadCombination
from RFEM.LoadCasesAndCombinations.staticAnalysisSettings import StaticAnalysisSettings
from RFEM.Loads.memberLoad import MemberLoad
from RFEM.Loads.nodalLoad import NodalLoad
from RFEM.TypesForMembers.memberHinge import MemberHinge
from RFEM.TypesForNodes.nodalSupport import NodalSupport
# from RFEM.Calculate.meshSettings import GetModelInfo
from timeit import default_timer as timer
from datetime import timedelta
def log(what, start):
end = timer()
time = timedelta(seconds=end-start)
print(f"[DEBUG] {what} took:", time)
return timer()
if __name__ == "__main__":
input("Press eny key to start...")
_start = log("Program start", timer())
MODEL_NAME = "2"
model = Model(True, MODEL_NAME)
params = model.clientModel.service.get_model_main_parameters()
model_id = model.clientModel.service.get_model_main_parameters().model_id
_start = log(f"Creating model {params}", _start)
# input("Model Created, press eny key to continue...")
model.clientModel.service.begin_modification()
_start = log(f"[{model_id}] Begin modification", _start)
# input("Model Created, press eny key to continue...")11
# breakpoint()
# **STRUCTURE**------------------------------------------------
# -------------------------------------------------------------
# MaterialCustomDefinitions
material_custom_definition_1 = {}
material_custom_definition_16 = {}
# Materials
"""
Material definition matching pattern:
name = "<Material>"
Material(2, "S235H (EN 10210-1)")
Material(3, "S220 1.4541 (cold rolled strip)")
"""
Material(1, "S235", params=None, model=model)
_start = log(f"[{model_id}] Materials", _start)
# -------------------------------------------------------------
# SectionCustomDefinitions
section_custom_definition_2 = {}
section_custom_definition_3 = {'A': 3.25, 'comment': 'Test', 'is_active': False}
# Sections
"""
Section definition matching pattern"
name = "<Section> | <Standard?> | <Manufacturer?>":
Section(2, "IPE 400") # default, probably first matching
Section(3, "IPE 400 | -- | British Steel")
Section(4, "IPE 400 | EN 10365:2017 | ArcelorMittal (2018)")
Section(5, "IPE 400 | DIN 1025-5:1994-03 | Ferona")
"""
Section(1, "IPE 100 | EN 10365:2017 | ArcelorMittal (2018)", params=None, model=model)
Section(4, "IPE 100 | DIN 1025-5:1994-03 | Ferona", params=None, model=model)
_start = log(f"[{model_id}] Sections", _start)
# -------------------------------------------------------------
# Nodes
Node(12, 0.0, 0.0, 0.0, model=model)
Node(13, 2.0, 0.0, 0.0, model=model)
Node(14, 2.0, 0.0, -2.0, model=model)
Node(15, 0.0, 0.0, -2.0, model=model)
_start = log(f"[{model_id}] Nodes", _start)
# -------------------------------------------------------------
# NodalSupports
NodalSupport(1, "12 13 ", [inf, inf, inf, inf, inf, inf], model=model)
_start = log(f"[{model_id}] NodelSupports", _start)
# -------------------------------------------------------------
# MemberHingeNonlinearity
member_hinge_diagram_nonlinearity_1 = [MemberHingeNonlinearity.NONLINEARITY_TYPE_DIAGRAM, [MemberHingeDiagramType.DIAGRAM_ENDING_TYPE_CONTINUOUS, MemberHingeDiagramType.DIAGRAM_ENDING_TYPE_CONTINUOUS, [[0.001, 5280, None], [0.0015, 9240, None], [0.002, 12770, None], [0.0025, 15420, None], [0.003, 17450, None], [0.004, 20480, None], [0.005, 22706, None]]]]
member_hinge_diagram_nonlinearity_2 = [MemberHingeNonlinearity.NONLINEARITY_TYPE_DIAGRAM, [MemberHingeDiagramType.DIAGRAM_ENDING_TYPE_STOP, MemberHingeDiagramType.DIAGRAM_ENDING_TYPE_STOP, [[0.001, 5280, None], [0.0015, 9240, None], [0.002, 12770, None], [0.0025, 15420, None], [0.003, 17450, None], [0.004, 20480, None], [0.005, 22706, None]]]]
member_hinge_diagram_nonlinearity_3 = [MemberHingeNonlinearity.NONLINEARITY_TYPE_DIAGRAM, [MemberHingeDiagramType.DIAGRAM_ENDING_TYPE_FAILURE, MemberHingeDiagramType.DIAGRAM_ENDING_TYPE_FAILURE, [[0.001, 5280, None], [0.0015, 9240, None], [0.002, 12770, None], [0.0025, 15420, None], [0.003, 17450, None], [0.004, 20480, None], [0.005, 22706, None]]]]
member_hinge_diagram_nonlinearity_4 = [MemberHingeNonlinearity.NONLINEARITY_TYPE_DIAGRAM, [MemberHingeDiagramType.DIAGRAM_ENDING_TYPE_YIELDING, MemberHingeDiagramType.DIAGRAM_ENDING_TYPE_YIELDING, [[0.001, 5280, None], [0.0015, 9240, None], [0.002, 12770, None], [0.0025, 15420, None], [0.003, 17450, None], [0.004, 20480, None], [0.005, 22706, None]]]]
# MemberHinges
MemberHinge(1, "Local", "", 0, 0, 0, 0, 0, 0, member_hinge_diagram_nonlinearity_1, member_hinge_diagram_nonlinearity_2, member_hinge_diagram_nonlinearity_3, member_hinge_diagram_nonlinearity_4, member_hinge_diagram_nonlinearity_4, member_hinge_diagram_nonlinearity_2, model=model)
MemberHinge(2, "Local", "", 500, 500, 300, inf, 0, inf, [MemberHingeNonlinearity.NONLINEARITY_TYPE_NONE], [MemberHingeNonlinearity.NONLINEARITY_TYPE_NONE], [MemberHingeNonlinearity.NONLINEARITY_TYPE_NONE], [MemberHingeNonlinearity.NONLINEARITY_TYPE_NONE], [MemberHingeNonlinearity.NONLINEARITY_TYPE_NONE], [MemberHingeNonlinearity.NONLINEARITY_TYPE_NONE], model=model)
_start = log(f"[{model_id}] Member Hinges", _start)
# -------------------------------------------------------------
# Members
Member(11, 12, 13, 1.570796, 1, 1, None, None, model=model)
Member(12, 13, 14, 1.570796, 1, 1, None, None, model=model)
Member(13, 12, 15, 1.570796, 1, 1, None, None, model=model)
Member(14, 15, 14, 1.570796, 1, 1, None, None, model=model)
_start = log(f"[{model_id}] Members", _start)
# **LOAD_CASES_AND_COMBINATIONS**------------------------------
# -------------------------------------------------------------
# This is created by default when user opens new model from GUI
StaticAnalysisSettings.GeometricallyLinear(1, "Linear", model=model)
# StaticAnalysisSettings.SecondOrderPDelta(2, "SecondOrder")
# StaticAnalysisSettings.LargeDeformation(3, "LargeDeformation")
_start = log(f"[{model_id}] StaticAnalysisSettings", _start)
# -------------------------------------------------------------
# LoadCasesAndCombinationWizard
load_cases_and_combinations_settings = {
"current_standard_for_combination_wizard": 6207,
"activate_combination_wizard_and_classification": True,
"activate_combination_wizard": False,
"result_combinations_active": False,
"result_combinations_parentheses_active": False,
"result_combinations_consider_sub_results": False,
"combination_name_according_to_action_category": False
}
LoadCasesAndCombinations(load_cases_and_combinations_settings, model=model)
_start = log(f"[{model_id}] LoadCasesAndCombinationWizard", _start)
# -------------------------------------------------------------
# DesignSituations
DesignSituation(2, DesignSituationType.DESIGN_SITUATION_TYPE_STR_PERMANENT_AND_TRANSIENT_6_10, True, "Stress", model=model)
DesignSituation(3, DesignSituationType.DESIGN_SITUATION_TYPE_SLS_CHARACTERISTIC, True, "Deflection", model=model)
_start = log(f"[{model_id}] DesignSituations", _start)
# -------------------------------------------------------------
# LoadCases
LoadCase(1, "Self Weight", [True, 0.0, 0.0, 1.0], params={"action_category": ActionCategoryType.ACTION_CATEGORY_PERMANENT_G.name}, model=model)
LoadCase(2, "FinishMaterials", [False], params={"action_category": ActionCategoryType.ACTION_CATEGORY_PERMANENT_G.name}, model=model)
LoadCase(3, "Wind X", [False], params={"action_category": ActionCategoryType.ACTION_CATEGORY_WIND_QW.name}, model=model)
LoadCase(4, "Wind Y", [False], params={"action_category": ActionCategoryType.ACTION_CATEGORY_WIND_QW.name}, model=model)
_start = log(f"[{model_id}] LoadCases", _start)
# -------------------------------------------------------------
# LoadCombination
LoadCombination(1, AnalysisType.ANALYSIS_TYPE_STATIC, 2, combination_items=[[1.35, 1, 0, False], [1.35, 2, 0, False], [1.5, 3, 0, False]], model=model)
LoadCombination(2, AnalysisType.ANALYSIS_TYPE_STATIC, 2, combination_items=[[1.35, 1, 0, False], [1.35, 2, 0, False], [1.5, 4, 0, False]], model=model)
LoadCombination(3, AnalysisType.ANALYSIS_TYPE_STATIC, 2, combination_items=[[1.35, 1, 0, False], [1.35, 2, 0, False]], model=model)
LoadCombination(4, AnalysisType.ANALYSIS_TYPE_STATIC, 3, combination_items=[[1, 1, 0, False], [1, 2, 0, False], [1, 3, 0, False]], model=model)
LoadCombination(5, AnalysisType.ANALYSIS_TYPE_STATIC, 3, combination_items=[[1, 1, 0, False], [1, 2, 0, False], [1, 4, 0, False]], model=model)
_start = log(f"[{model_id}] LoadCombinations", _start)
# **LOADS**----------------------------------------------------
# -------------------------------------------------------------
# NodalLoads
NodalLoad.Force(1, 2, "14 15 ", LoadDirectionType.LOAD_DIRECTION_LOCAL_Z, 1000.0, model=model)
NodalLoad.Moment(2, 2, "14 ", LoadDirectionType.LOAD_DIRECTION_LOCAL_Z, 5000.0, model=model)
_start = log(f"[{model_id}] NodalLoads", _start)
# -------------------------------------------------------------
# MemberLoads
MemberLoad.Force(1, 3, "11 12 13 14 ", MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, MemberLoadDirection.LOAD_DIRECTION_GLOBAL_X_OR_USER_DEFINED_U_TRUE, [-1000.0], model=model)
MemberLoad.Force(2, 4, "11 12 13 14 ", MemberLoadDistribution.LOAD_DISTRIBUTION_UNIFORM, MemberLoadDirection.LOAD_DIRECTION_GLOBAL_Y_OR_USER_DEFINED_V_TRUE, [1000.0], model=model)
_start = log(f"[{model_id}] MemberLoads", _start)
# -------------------------------------------------------------
model.clientModel.service.finish_modification()
_start = log(f"[{model_id}] FinishingModification", _start)
Calculate_all(model=model)
_start = log(f"[{model_id}] Calculation", _start)
ExportResultTablesToCSV("C:\\Dev\\dlubal\\results\\csv", model=model)
_start = log(f"[{model_id}] ExportToCSV", _start)
closeModel(MODEL_NAME)
_start = log(f"[{model_id}] ClosingModel", _start)
Hi @damianbobrowski,
After some tests and research, I'd like to inform you that parallel calculation is not possible in RFEM with multiple models.
Actually, if you work with two RFEM instances in the same time, it's possible to run multiple calculations manually. But with Webservices, you can only set one Port Range and that's preventing to access two or more instances at the same time. Therefore, I have to suggest you to use multiple model edit in one script -even that I'm aware of it costs you time.
We're now searching for a solution for parallel calculations, as soon as we find a way, I'll inform you. Thanks for the inspiration!
Hi @damianbobrowski, I read the request and discussed it with @dogukankaratas. I tried to run 2 instances of RFEM in parallel and it is realy slow. Running multiple models in RFEM would not only be unsafe (could crash a lot) but also slow, no doubt. Not gaining any computer time by running multiple models in one RFEM instance the solution is the following:
Is your feature request related to a problem? Please describe. I am trying to run multiple models in parallel. Everything seems to run until Calculation starts. Model which start calculation letter crash.
https://user-images.githubusercontent.com/26790705/194049430-d232a542-845d-4345-b157-8e5048edc04f.mp4
I am wondering is it connected to Calculation or User Interface (UI) in general. Working with library I see when dialog is open then it blocks even one model from start. During calculations UI "start working" so it can be UI blocking issue.
Describe the solution you'd like Possibility to run multiple models in parallel. Non blocking solution. Is there ready non UI version/"server version" of software?
Traceback
Used model To reproduce just run two scripts in parallel after differentiation
MODEL_NAME = "1"