0

在 Ansys WB 中的地震加载的每个时间步之后,我编写了一个 python 脚本来更改弹簧连接的属性(刚度和阻尼)。我希望脚本在每个时间步之后运行,并且基于下一个时间步的完成时间步,弹簧的属性应该根据我在脚本中提供的条件进行更改。我注意到我的脚本没有按照我想要的方式进行交互。我正在使用的脚本已附加,任何帮助都非常感谢。

model=ExtAPI.DataModel.Project.Model
analysis=model.Analyses[0]
solution=analysis.Solution

# Defining lists for stiffness and damping to be used
damp = [Quantity(16.5,"N sec/mm"),Quantity(816,"N sec/mm"),Quantity(1666,"N sec/mm"),Quantity(2203,"N sec/mm"),Quantity(0,"N sec/mm")]
stiff = [Quantity(33,"N/mm"),Quantity(833,"N/mm"),Quantity(2000,"N/mm"),Quantity(3333,"N/mm"),Quantity(25000,"N/mm")]

# Accessing Springs
s3 = ExtAPI.DataModel.GetObjectsByName("s_third")[0]
s2 = ExtAPI.DataModel.GetObjectsByName("s_second")[0]
s1 = ExtAPI.DataModel.GetObjectsByName("s_first")[0]


# Accessing the stiffness and damping of the springs
damp1 = s1.LongitudinalDamping
stiff1 = s1.LongitudinalStiffness
damp2 = s2.LongitudinalDamping
stiff2 = s2.LongitudinalStiffness
damp3 = s3.LongitudinalDamping
stiff3 = s3.LongitudinalStiffness
dis = ExtAPI.DataModel.GetObjectsByName("Displacement")

# Accessing the results to be traced
deformationL3 = DataModel.GetObjectsByName("deformL3")
deformationL2 = DataModel.GetObjectsByName("deformL2")
deformationL1 = DataModel.GetObjectsByName("deformL1")
for i in dis:
    if deformationL3 <= -40:
        damp3 = damp[3]
        stiff3 = stiff[3]
    elif -40 < deformationL3 <= -20:
        damp3 = damp[2]
        stiff3 = stiff[2]
    elif -20 < deformationL2 < 0:
        damp3 = damp[1]
        stiff3 = stiff[1]
    elif 0 <deformationL3 < 20:
        damp3 = damp[1]
        stiff3 = stiff[1]
    elif 20 <= deformationL3 < 40:
        damp3 = damp[2]
        stiff3 = stiff[2]
    elif deformationL3 >= 40:
        damp3 = damp[3]
        stiff3 = stiff[3]
    elif deformationL3 == 0:
        damp3 = damp[0]
        stiff3 = stiff[0]
#Level2 spring
    if deformationL2 <= -40:
        damp2 = damp[3]
        stiff2 = stiff[3]
    elif -40 < deformationL2 <= -20:
        damp2 = damp[2]
        stiff2 = stiff[2]
    elif -20 < deformationL2 < 0:
        damp2 = damp[1]
        stiff2 = stiff[1]
    elif 0 <deformationL2 < 20:
        damp2 = damp[1]
        stiff2 = stiff[1]
    elif 20 <= deformationL2 < 40:
        damp2 = damp[2]
        stiff2 = stiff[2]
    elif deformationL2 >= 40:
        damp2 = damp[3]
        stiff2 = stiff[3]
    elif deformationL2 == 0:
        damp2 = damp[0]
        stiff2 = stiff[0]

# Level 1 spring
    if deformationL1 <= -40:
        damp1 = damp[3]
        stiff1 = stiff[3]
    elif -40 < deformationL1 <= -20:
        damp1 = damp[2]
        stiff1 = stiff[2]
    elif -20 < deformationL1 < 0:
        damp1 = damp[1]
        stiff1 = stiff[1]
    elif 0 <deformationL1 < 20:
        damp1 = damp[1]
        stiff1 = stiff[1]
    elif 20 <= deformationL1 < 40:
        damp1 = damp[2]
        stiff1 = stiff[2]
    elif deformationL1 >= 40:
        damp1 = damp[3]
        stiff1 = stiff[3]
    elif deformationL1 == 0:
        damp1 = damp[0]
        stiff1 = stiff[0]

此致

4

1 回答 1

0

假设您的第一个加载步骤已解决,您可以通过以下方式访问它:

firstAnalysis = model.Analyses[0]
solution = firstAnalysis.Solution

比你用这样的东西循环你的加载步骤:

for loadstep in loadsteps:
    currentAnalysis = firstAnalysis.Duplicate()
    # Get the results from the last load step
    deformations = [item for item in solution.Children if item.GetType() == Ansys.ACT.Automation.Mechanical.Results.DeformationResults.DeformationResult]

你的 if 语句在这里,但你必须测试是否 GetObjectsByName()在这里工作

    deformationL3 = deformations.GetObjectsByName("deformL3")
    deformationL2 = deformations.GetObjectsByName("deformL2")
    deformationL1 = deformations.GetObjectsByName("deformL1")
       
        for i in dis:
          ....

您没有指定您的加载步数,但您必须在此处更改它们

    # Replacing last solution with current solution object
    solution = currentAnalysis.Solution
    # solve current LoadStep
    solution.Solve(True)
于 2022-02-03T06:41:21.680 回答