How can I make displacement in a static structural analysis dependent on a geometric parameter ?
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
-
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,
Jimmy1 -
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
2
Answers
-
Hi Jimmy He,
Thank you very much for your suggestion.
Could you tell me how to define/update displacement tabular data (e.g. in x) via scripting too, please?Thank you,
Manu
0 -
Hi
Another way is to use a python code (before solve target callback) that is updated for every design point.
One can use perhaps the bounding box of the body (see code below on how to do that), and then use that to scale the displacement. Or a Parameter as shown above can be scaled and used for the displacement.
See here how to define displacement:
https://discuss.ansys.com/discussion/151/activate-deactivate-boundary-conditions-through-scripting
All the best
Erik
tbody=ExtAPI.DataModel.GetObjectsByName("Mysolidbody 1")[0] # tree body gbody =tbody.GetGeoBody() # geobody gbb=gbody.GetBoundingBox() xdim=gbb[3]-gbb[0] # x-dim
1 -
You might need to use a Python code object, as discussed here:
https://discuss.ansys.com/discussion/2244/how-to-parameterize-the-objective-weight-using-python-code-object
See also: https://discuss.ansys.com/discussion/2206/use-python-code-object-python-result-object-with-a-doeRegarding
Could you tell me how to define/update displacement tabular data (e.g. in x) via scripting too, please?
See: https://discuss.ansys.com/discussion/2575/tabular-load-implemented-from-python-scripting
1 -
Thank you very much to all !!
All the best,
Manuele
1