How can I make displacement in a static structural analysis dependent on a geometric parameter ?

Rosse7
Rosse7 Member Posts: 10
First Comment
**

Hi,
when my optimization analysis runs some geometry dimensions (parameterized inside Design Modeler) change and I need my given displacement (in tabular form) proportionally change too.
How can I overcome this trouble?
Thank you

Best Answers

  • Jimmy He
    Jimmy He Member, Employee Posts: 24
    10 Comments 5 Likes First Answer First Anniversary
    ✭✭✭✭
    edited October 2024 Answer ✓

    Hi Rosse7,

    The value of a parameter in Workbench can be accessed within Mechanical scripting via the following:

    import wbjn
    # P1 is the name of the parameter in Workbench, change as needed.
    value_string = wbjn.ExecuteCommand(ExtAPI,"""returnValue(str(Parameters.GetParameter(Name="P1").Value))""")
    value_quantity = Quantity( value_string ) # Value of the parameter as a Quantity
    print( value_quantity )
    

    Once you have the current value of the parameter from Mechanical scripting, you can proceed with using it to change the boundary condition.

    Best,
    Jimmy

  • Erik Kostson
    Erik Kostson Member, Moderator, Employee Posts: 276
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited October 2024 Answer ✓

    @Rosse7

    Below is a sample script that you can modify as needed - it is a python code (before solve target callback), and it updates the displacement imposed on a face, and based on the dimension of the geometry (this dim., changes for every design point). One can use the script parameter as below or use (commented away ) as mentioned the bounding box.

    All the best

    Erik

    def before_solve(this, analysis):# Do not edit this line
        """
        Called before solving the parent analysis.
        Keyword Arguments : 
            this -- the datamodel object instance of the python code object you are currently editing in the tree
            analysis -- Static Structural
        """
    
    
        # To access properties created using the Property Provider, please use the following command.
        # this.GetCustomPropertyByPath("your_property_group_name/your_property_name")
    
        # To access scoping properties use the following to access geometry scoping and named selection respectively:
        # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Geometry Selection")
        # this.GetCustomPropertyByPath("your_property_group_name/your_property_name/Named Selection")
        import wbjn
        tbody=ExtAPI.DataModel.GetObjectsByName("Mysolidbody 1")[0]
        gbody =tbody.GetGeoBody()
    
    
    
        # P1 is the name of the parameter in Workbench, change as needed.
        xdim = float(wbjn.ExecuteCommand(ExtAPI,"""returnValue(str(Parameters.GetParameter(Name="P1").Value))""").split(' ')[0]) # geom. dim., changing for every design point
    
    
        #gbb=gbody.GetBoundingBox() # Bounding box method
        #xdim=gbb[3]-gbb[0]
    
        analysis=ExtAPI.DataModel.Project.Model.Analyses[0] # refer to analysis
        my_disp=ExtAPI.DataModel.GetObjectsByName("Displacement")[0]
    
        my_disp.Location=ExtAPI.DataModel.GetObjectsByName("Selection")[0] # scope boundary condition to named selection called "Selection"
        my_disp.XComponent.Inputs[0].DiscreteValues=[Quantity('0[s]'),Quantity('1[s]')] # define input values for tabular data
        my_disp.XComponent.Output.DiscreteValues=[Quantity('0[mm]'),Quantity(str(xdim*0.05)+'[m]')] # define output values for tabular data loading
        pass
    

Answers