OptiStructAnalysis (hwx.inspire.FEAnalysis)#

class OptiStructAnalysis(params={}, runOptions={}, ignoreWarnings=False)#

Bases: Analysis

Run structural analysis using OptiStruct

Attribute Table#

Name

Type

imported

Bool

progress

Int

solverType

Enum

status

Enum

workingDir

String

Method Table#

Name

Description

export (file, params={}, runOptions={}, ignoreWarnings=False)

Download solver file (.fem, .ssp) for run

importResults (self, showExplorer=True)

Make results available in the Analysis Explorer.

openResults (self, stage=0)

Open the h3d file to get a cls.Results object.

Example

from hwx import inspire
from hwx.common import settings
from hwx.inspire.demo import  getDemoFilePath

solverSetting = "Inspire/Run Options/Run Options/Analysis solver"
# Check if the solver is set to OptiStruct
if settings.getSetting(solverSetting) == "OptiStruct":
  print('Solver is set to "OptiStruct"')
else:
  print("Switching solver to OptiStruct")
  # Set the solver to OptiStruct
  settings.setSetting(solverSetting, "OptiStruct")

# Get absolute path of a demo file 'ThreeBlocks.stmod'.
# This file is available in the Inspire demo directory
# ThreeBlocks.stmod have a pressure load and a support applied on it
filepath= getDemoFilePath('ThreeBlocks.stmod')
# Open the model file
model = inspire.openFile(filepath)
# Alternatively, you can get existing model
# model = inspire.getModel()

# Create a Simsolid analysis parameters object

params = inspire.OptiStructAnalysis.Params()
# By default  params initializes with  loadCases, parts 
# elementSize, speedAccuracy from the model.
# Params can also be set by directly assigning the values

params.elementSize = 0.0077827  #'auto' is the default value
params.speedAccuracy = "FASTER" # or 'MORE_ACCURATE'
params.loadCases = model.getChildren(type='LoadCase')# by default all loadCases are included
# We can also set the loadCases and parts by our choice.
# For example, we can set the loadCases and parts from the model.
# gets all the loadcase from the model
lcs = model.getChildren(type='LoadCase')
params.loadCases = lcs

# To perform ONLY static analysis, we can set the loadCases of type 'LINEAR_STATIC'
# to query 'LINEAR_STATIC' load case
linear_static_lcs = [lc for lc in lcs if lc.type == 'LINEAR_STATIC']
# On LINEAR_STATIC - load case you can set scale factor, pretension, inertia relief. 
# for lc in linear_static_lcs:
#  lc.inertiaRelief = True
#  lc.scaleFactor = 2.0
#params.loadCases = linear_static_lcs

# To perform a BUCKLING analysis, we can set the loadCases of type 'BUCKLING_LINEAR'
# along with linked load cases
# On BUCKLING_LINEAR load case, we can set modes.
# To query 'BUCKLING' load case
linear_buckling_lcs= [lc for lc in lcs if lc.type == 'BUCKLING_LINEAR']
# On BUCKLING_LINEAR load case, we can set modes.
#for lc in linear_buckling_lcs:
#  lc.modes = 5  # Set the number of modes to be calculated
#params.loadCases = linear_buckling_lcs + [lc.linkedLoadCase for lc in linear_buckling_lc]

# to query 'MODAL' or normal mode load case
normal_mode_lcs = [lc for lc in lcs if lc.type == 'MODAL']
# To perform a MODAL/Normal mode analysis, we can set the loadCases of type 'MODAL'
# On MODAL load case, we can set modes.
# On MODAL load case, we can set modes.
#for lc in normal_mode_lcs:
#  lc.modes = 5  # Set the number of modes to be calculated
#params.loadCases = normal_mode_lcs

# to query 'PRESTRESS_MODAL' load case
# On PRESTRESS_MODAL load case, we can set modes.
# prestress_lcs = [lc for lc in lcs if lc.type == 'PRESTRESS_MODAL']
# On PRESTRESS_MODAL load case, we can set modes.
# for lc in prestress_lcs:
#   lc.modes = 5  # Set the number of modes to be calculated
# To perform a PRESTRESS MODAL analysis, we can set the loadCases of type 'PRESTRESS_MODAL'
# along with linked load cases
# params.loadCases = prestress_lcs + [lc.linkedLoadCase lc for in prestress_lcs]

# To perform any analysis, we need respective loadCases on the model.
# We can query the loadCases from the model if exists else we can create a new loadCase.  

print('params', repr(params))

from os.path import expanduser
home = expanduser("~")

# This will save the Analysis results in home directory
with inspire.useRunDirectory(home):
  with inspire.gui.waitCursor(message="Solving..."):
    analysis = inspire.OptiStructAnalysis(params)

results = analysis.openResults()

analysis.importResults()

# Results in 'gui' units
# it can be 'gui' or 'IPS' or 'MMKS' or 'MKS' or 'CGS' or 'MPA'
with inspire.usingUnits("gui"):
  # result object has all the results of the analysis
  print('results:', results)

# We can also fetch the results at particular location
# Valid  types for linear static analysis are, 
# Displacement
# X Displacement
# X Displacement
# X Displacement
# Factor of Safety
# Percentage of Yield
# Tension/Compression
# Max Shear Stress
# von Mises Stress
# Major Principal Stress
# Minor Principal Stress
# Major Principal Strain
# Minor Principal Strain

# How to query the results at a particular point
pressure = model.getChild(name="Pressure 1")
location = pressure.location
# Alternatively, you can use the point as a list or tuple
# The point should be in meters and it should be on the model.
#location = [0.12 -0.002, 0.018]

print(f"Displacement at ({pressure.location}) is "
 f"{results.getAtPoint(subCase=0, type='Displacement', point=pressure.location,units=True)}")

# Min max for a specific result type and part
part1 = model.getChild(name="Part 1")
# To get the min and max displacement for a particular part
min, max = results.getMinMax(subCase=0,type='Displacement', part=part1,units=True, withPos=False)

print(f"Min Displacement is {min}")

print(f"Max Displacement is {max}")

inspire.orientView(direction="top")
Params2#

alias of OSAnalysisRunParams

class Results(resultsManager, synth, stageIndex)#

Bases: Stage

Analysis results from .h3d file

Can be accessed like a dict of dicts. Use repr(results) to view available subCases and result types

Method Table#

Name

Description

getAtPoint (self, subCase, type, point, step=None, units=False)

Get value of specified type at a point (float)

getBucklingLoadFactor (self, subCase, mode)

Get Buckling load factor of specified mode

getFrequency (self, subCase, mode)

Get Normal frequency of specified mode

getMinMax (self, subCase, type, step=None, part=None, units=False, withPos=False)

Get (min, max) value of specified type.

getAtPoint(subCase, type, point, step=None, units=False)#

Get value of specified type at a point (float)

Parameters:
  • subCase (str or int) – Name or index of subcase

  • type (str or int) – Result type name or id

  • point (Point) – 3d point to fetch value at

  • step (int) – Simulation step. Leave as None for all steps

  • units (bool) – Get value with units

getBucklingLoadFactor(subCase, mode)#

Get Buckling load factor of specified mode

Parameters:
  • subCase (str or int) – Name or index of subcase

  • mode (int) – Buckling Mode index (starts with 1)

getFrequency(subCase, mode)#

Get Normal frequency of specified mode

Parameters:

mode (int) – Normal Mode index (starts with 1)

getMinMax(subCase, type, step=None, part=None, units=False, withPos=False)#
Get (min, max) value of specified type.

If withPos is True then it returns (min, max, min_pos, max_pos) where min_pos and max_pos are (x, y, z) tuples.

Parameters:
  • subCase (str or int) – Name or index of subcase

  • type (str or int) – Result type name or id

  • step (int) – Simulation step. Leave as None for all steps

  • part (Part) – Get min/max for specific part. Leave as None for all Parts

  • units (bool) – Get min/max with units

  • withPos (bool) – Get positions for min/max

class RunOptions(**kwds)#

Bases: Struct

Attribute Table#

Name

Type

isRemoteRun

property

waitTillFinish

property

property isRemoteRun#

(bool) Is remote run

repr()#

Convert params to a dict which can be used to reconstruct it.

Readonly attributes are removed and structs are compacted.

todict()#

Convert params to a dict containing all properties

property waitTillFinish#

(bool) Use False to do multiple runs in parallel

class Status(value)#

Bases: Enum

An enumeration.

Attribute Table#

Name

Type

ERROR

Status

FE_NOT_REALIZED

Status

GENERATING_FE_MODEL

Status

INFEASIBLE_DESIGN

Status

INITIALIZED

Status

MESH_NOT_GENERATED

Status

NOT_CONVERGED

Status

NOT_STARTED

Status

PARTS_NOT_CONNECTED

Status

RUNNING

Status

SUCCESS

Status

TERMINATED

Status

WARNING

Status

property active#

Returns or sets the object activeness.

Setting this on or off sets all children. Setting to True sets all the parents active too.

destroy()#

Delete the object removing it from the model.

The object may come back due to an undo/redo.

getAllChildren(type=None, **kwds)#

Returns a list of all children that matches the specified type.

Parameters:
  • type (list[Named]) – Filter to use to get the children based on object type.

  • **kwds – Additional keyword arguments to match other attributes of the object.

Returns:

The list of children that satisfy the supplied filters.

Return type:

list[Union[Part, Motor, BoundaryCondition, …]]

getAttribute(name)#

Returns the Attribute off the class, not the value.

Parameters:

name (str) – Attribute name to find its class.

getBrowserFolder(flatView) str | None#

Group objects by folder under getBrowserParent().

Use None for no folder.

Always specify a folder if flatView.

getBrowserListenTo()#

Specify objects that gui attribute values depend on.

To make sure the Property Editor refreshes when they are modified.

getBrowserName()#

Name shown in the Model Browser.

getBrowserNameAddon()#

Specifies extra information about the object appended to its name in the Model Browser.

getBrowserNameWithAddon()#

Name shown in the Model Browser with addon.

getBrowserParent() Named#

Show hierarchy in Model Browser.

getChild(name=None, recursive=False, **kwds)#

Returns the child of the object which matches the specified unique name.

Parameters:
  • name (str) – The name of the child object.

  • recursive (bool) – Search all descendents.

  • **kwds – Additional keyword arguments to match attributes of the object.

Returns:

The child object which satisfies the specified filters.

Return type:

Named

getChildren(type=None, recursive=False, sorted=False, **kwds)#

Returns a list of children that is of the specified type.

Parameters:
  • type (Type[Named]) – Filter objects by class.

  • recursive (bool) – True to get all descendent Parts and Assemblies.

  • sorted (bool) – Sort the children base on id.

Returns:

list[Named]

getContextMenu()#

Returns list of MenuItem objects to populate the context menu.

Also supports shorthand:

  • ‘action name’

  • (text, callable),

  • (text, [sub menu])

  • ‘-’ for section/separator line

getDependents(recursive=False, **kwds)#

Get objects that reference this object through a Reference attribute.

Parameters:
  • recursive (bool) –

  • **kwds – Filter objects using isa.

Returns:

set[Named]

getGuiValue(attr, **kwds)#

Get value formatted to be shown in the gui

Parameters:

attr (str) – Attribute name to gets its gui value.

Returns:

Returns a string of the value with its gui units, like “5 mm/s”.

Return type:

str

getIcon()#

Overload to specify different icons depending on the object.

getReferences(recursive=False, **kwds)#

Get objects this object references through a Reference attribute.

Parameters:
  • recursive (bool) –

  • **kwds – Filter objects using isa.

Returns:

set[Named]

getSecondaryIcon()#

Show a second icon next to primary icon in Model Browser tree. Commonly used to show warning icon widgetTaskWarning-12.png.

getToolTip()#

Specifies the tooltip when object is hovered

getValue(attr)#

Return the attribute value for passed attribute name.

Parameters:

attr (String) – Attribute name to gets its value.

Returns:

Returns the attribute value

Return type:

str

getVariable(propName)#

Get associated variable for the given property.

Parameters:

propName (str) – Property name to get the associated variable.

importResults(showExplorer=True)#

Make results available in the Analysis Explorer.

Parameters:

showExplorer (bool) – Opens the Analysis Explorer dialog (gui mode only)

property imported#

If True, Results are loaded.

isBrowserNameModified(attr)#

Do we need to refresh the name in the Model Browser due to an onObjectModified?

isa(type=None, filter=None, name=None, wildcard=None, **kwds)#

Determines if the object matches the specified settings or not.

Parameters:
  • type (Union[Part, Assembly, Contact..]) – The type of the object.

  • filter (method) – Return value of specified callback method.

  • name (str) – Name that matches exactly with object name.

  • wildcard (str) – A pattern to match exactly with the object name.

  • **kwds – Additional keyword arguments to match other attributes.

Returns:

True, if a match is found, otherwise False.

Return type:

bool

modelPositions()#

Forces all objects to return the original model positions instead of the current analysis positions.

Useful when defining draw methods on GeneralObjects where behaviour is different while animating.

move(delta)#

Called when object moved by move tool.

Parameters:

delta (math.Matrix44) –

property name#

Returns or sets the name of the object.

It can be any text string, including spaces, although it’s best to avoid using the following characters: “ ‘ * ? and $.

While these characters are allowed, they could create difficulties when you export the model to other applications.

openResults(stage=0)#

Open the h3d file to get a cls.Results object.

Usage:
with run.openResults() as results:

print(results)

Parameters:

stage (int) – Stage index

property parent#

Returns the parent of this entity.

Type:

Assembly

property progress#

Current state of the Object.

setValue(attr, value)#

Alias for setattr (attr, value) :param attr: Attribute name to sets its value. :type attr: str :param value: Attribute value to set . :type value: str

setValues(**kwds)#

Sets passed name/value pairs.

Values are set in a standard order (the order the attribute is defined on the class) which is required in certain cases when an attribute’s setter expects another attribute to have already been set. For example, setting a reference before a location that is wrt it.

Parameters:

**kwds – Set attributes in one go.

setVariable(propName, varName)#

Associate property to variable for named object.

Parameters:
  • propName (str) – Property name to associate with variable.

  • varName (str) – The name of the variable to associate the attribute with.

property solverType#

Solver Type of the Object

property status#

Current status of the Object.

property suppress#

Returns True if the object is suppressed.

Type:

bool

property suppressible#

(bool) Show option to suppress object in the context menu.

Suppressed objects are deactivated (obj.active == False) so they don’t contribute to analyses.

The suppressed object will remain in the Model Browser (in a disabled state) so the user can unsuppress it.

Defaults to True

property visible#

Determines whether the object is visible in the graphics window.

Setting this on or off sets all children. Setting to True sets all the parents visible too.

wasValueSet(attr)#

Check if attribute was set

Parameters:

attr (str) – Attribute name to check it value set or not

Returns:

True, if value was set else false.

Return type:

bool

property workingDir#

Working directory of the Object