0

I have a wrote a python script to change the properties of spring connections (stiffness and damping) after every time step of my earthquake loading in Ansys WB. I want the script to run after each time step and based on the completed time step for next time step the properties of the spring should changed based on the conditions I have provided in the script. I noticed my script is not interacting the way I wanted. Script I am using is attached and any help is highly appreciated.

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]

Best regards

1 Answers1

0

Assuming your first load step is solved, you can access it with:

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

Than you loop over your loadsteps with something like this:

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]

Your if statements goes here, but you have to test if GetObjectsByName() works here

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

You didn't specify your loadsteps but you have to change them here

    # Replacing last solution with current solution object
    solution = currentAnalysis.Solution
    # solve current LoadStep
    solution.Solve(True)
meshWorker
  • 183
  • 2
  • 13
  • Do you mean by duplicating I need to change spring parameters manually then? If this is the case I dont think its a practical solution since I have earthquake loading which has more than 5000 steps. If I am getting it wrong can you please explain this a bit more? Thanks – mereen hussain Feb 04 '22 at 11:39
  • Although I think this is what you wanted I have a strange feeling with this solution: Is the change of the spring parameters rooted in the possible distributions of the springs or are you trying to model the springs nonlinearity, because than a nonlinear spring characteristic would be the way to go. – meshWorker Feb 07 '22 at 08:06
  • I am trying to model a non-linear spring in terms of stiffness and damping both. Actually in ANSYS I am unable to find a spring connection which can take both non linearity (Stiffness and Damping), so i come to the conclusion if it can be possible in the way if the stiffness and damping of a linear spring can be change by using a script after every time step. However, ansys has non-linear spring such as COMB39 but with this I can only define nonlinearities in terms of stiffness (force-displacement) with a constant damping only. – mereen hussain Feb 09 '22 at 07:14
  • In that case, I would read into `combin37`. That is an element with the capability of turning on and off during an analysis. Effectively you create an element for each `if`-statement and the element switches on/off based upon the specified degrees of freedom. But I don't think this can be replaced with IronPython at the moment, this has to be an APDL-snippet. – meshWorker Feb 09 '22 at 07:35
  • An even better way would be to combine a `combin39` -element with a `combin14` -element. The `combin39` -element provides nonlinear force-deflection capability and the `combin14` -element provides the nonlinear damping effect characteristic,. – meshWorker Feb 09 '22 at 08:21