Pressure (hwx.inspire)#

class Pressure(features, location=None, direction=None, magnitude=None, **kwds)#

Bases: BoundaryCondition

A pressure is a distributed force that acts perpendicular to every point along the face.

Pressures typically arise from gases or liquids pressing on a face and can act in either the inward or outward direction on a solid. To apply a distributed force to a face that acts in a single uniform direction across the entire face, use a force instead of a pressure.

Attribute Table#

Name

Type

interpolationData

property

inward

Bool

magnitude

Double

type

Enum

Example

from hwx import inspire
# Start with an empty model
model = inspire.newModel()
# Alternatively, you can get an existing model
# model = inspire.getModel()
# create a solid block
block = model.createSolidBlock(x=0.5, y=0.5, z=0.5)
# apply pressure on a face feature
face = block.getFeatures(type='FeatureArea')[0]
# create a pressure load on the face feature with 100 Pa magnitude.
pressureOnFace = inspire.Pressure(features=face, direction=face.normal,magnitude=100, loadCase='current')
print("Some pressure values:")
print("	Location:", pressureOnFace.location)
print("	Direction:", pressureOnFace.direction)
print("	Magnitude:", pressureOnFace.magnitude)

# modify some pressure attributes
# to change the direction of the pressure load
pressureOnFace.direction = -face.normal
with inspire.usingUnits("MKS"):
  pressureOnFace.magnitude = 50
inspire.fitView()

# How to get the pressure load location
print("	Location:", pressureOnFace.location)

# How to get the pressure load direction
print("	Direction:", pressureOnFace.direction)

# How to chage the pressure load direction
pressureOnFace.direction = (0, 0, -1)  # Set the direction to negative Z-axis

print("")
print("Pressure values after modification:")
print("	Location:", pressureOnFace.location)
print("	Direction:", pressureOnFace.direction)
print("	Magnitude:", pressureOnFace.magnitude)

# How to Create a Parametric Pressure Load
# A parametric pressure load is a pressure load that can be modified 
# using variables.
# Create a variable for the pressure magnitude
# By default the Pressure magnitude is in Pa
model.variables.add(name="pressureMagnitude", type='Pressure', expression=100)
# Assign the variable to the pressure load magnitude
# This will make the pressure load parametric
pressureOnFace.magnitude = "pressureMagnitude"
# How to modify the pressure magnitude variable
# The pressure magnitude can be modified by changing the variable value
model.variables.update(name="pressureMagnitude", expression=200)

# How to reverse the pressure load
# A pressure load can be reversed by setting the inward attribute
# inward attribute to True make the pressure load act inward
# towards the surface, and False makes it act outward
pressureOnFace.inward = True
print("Pressure values after reversing the pressure load:")
print("	Location:", pressureOnFace.location)
print("	Direction:", pressureOnFace.direction)
print("	Magnitude:", pressureOnFace.magnitude)

# How to get the pressure load type
# The pressure load type can be obtained using the type attribute
# Supported tpyes are Uniform, Interpolated
# By default the pressure load type is Uniform
print(f"The pressure load type is: {pressureOnFace.type}")

# How to create a pressure load with interpolation data
# Interpolation data is used to define a pressure load that varies
# over a surface
# The interpolation data is a list of tuples, where each tuple
# contains the coordinates of a point on the surface and the pressure
# value at that point.  
# Chage the pressure load type to Interpolated
# This will make the pressure load vary over the surface of the face feature
pressureOnFace.type = "Interpolated"
# Create a list of tuples for the interpolation data

from collections import namedtuple
from hwx.common.math import Point

# Define the named tuple
PressureMapping = namedtuple("PressureMapping", "point magnitude")

# Convert the interpolation data to a list of PressureMapping instances
pressure_mappings = []

# Create a interpolation data where the pressure varies 
# over the surface of the face feature
interpolationData = []
for FeaturePoint in pressureOnFace.feature.connectedPoints:
    x, y, z = FeaturePoint.location
    interpolationData.append((x, y, z, 100))
x, y, z = pressureOnFace.feature.cg
interpolationData.append((x, y, z, 0))  # Center of area with 0 pressure

# Convert the interpolation data to PressureMapping named tuples
pressure_mappings = [
    PressureMapping(point=Point(data[0], data[1], data[2]), magnitude=data[3])
    for data in interpolationData
]

pressureOnFace.interpolationData= interpolationData
print(f"The pressure load type is: {pressureOnFace.type}")

inspire.orientView(direction="isometric")
property type#

The type of the pressure.

You can apply a non-uniform distributed pressure (Interpolated) using the interpolationData property.

Example

from collections import namedtuple
from hwx import inspire
from hwx.common.math import Point

# Define a named tuple for a pressure mapping point, if needed by your API
PressureMapping = namedtuple("PressureMapping", "point magnitude")

# Start with an empty model
model = inspire.newModel()

# Create a solid block
block = model.createSolidBlock(x=0.5, y=0.5, z=0.5)

# Get a face feature (using the first available face)
face = block.getFeatures(type='FeatureArea')[0]

# Create a pressure load on the face feature with a 100 Pa magnitude.
pressureLoad = inspire.Pressure(features=face, direction=face.normal, magnitude=100, loadCase='current')

# Display the default pressure load type (should be "Uniform")
print("Initial pressure load type:", pressureLoad.type)

# Change the pressure load type to "Interpolated"
pressureLoad.type = "Interpolated"
print("Modified pressure load type:", pressureLoad.type)

# Create interpolation data that defines how the pressure varies over the surface.
# Here, we simulate two interpolation points:
# - One at the center of the face with a magnitude of 50 Pa.
# - One offset from the center with a magnitude of 150 Pa.
center = face.cg  # Center of gravity of the face
interpolationData = [
    (center[0], center[1], center[2], 50),                    # Center point: 50 Pa
    (center[0] + 0.1, center[1] + 0.1, center[2], 150)          # Offset point: 150 Pa
]

# Optionally, convert to named tuples if the API expects that structure.
pressure_mappings = [
    PressureMapping(point=Point(x, y, z), magnitude=mag)
    for x, y, z, mag in interpolationData
]

# Assign the interpolation data to the pressure load
pressureLoad.interpolationData = pressure_mappings

# Print the interpolation data to verify
print("Interpolation data for pressure load:")
for mapping in pressureLoad.interpolationData:
    print(f"	Point: ({mapping.point.x}, {mapping.point.y}, {mapping.point.z}), Magnitude: {mapping.magnitude}")

# Optionally adjust the view to see the effect
inspire.fitView()
property inward#

Returns True if pressure acts in the inward direction on the solid, False if it acts in outward direction.

Example

from hwx import inspire

# Start with an empty model
model = inspire.newModel()

# Create a solid block
block = model.createSolidBlock(x=0.5, y=0.5, z=0.5)

# Get a face feature from the block (using the first available face)
face = block.getFeatures(type='FeatureArea')[0]

# Create a pressure load on the face feature with 100 Pa magnitude.
pressureLoad = inspire.Pressure(features=face,  magnitude=100, loadCase='current')

# By default, the pressure load acts inward (towards the surface).
print("Initial inward state:", pressureLoad.inward)

# Reverse the pressure load so that it acts outward.
pressureLoad.inward = False
print("Modified inward state:", pressureLoad.inward)

# Refresh the view to update any visual changes in the application.
inspire.fitView()
property magnitude#

The magnitude of the pressure, specified in terms of force per unit area.

Example

from hwx import inspire

# Create a new model
model = inspire.newModel()

# Create a solid block
block = model.createSolidBlock(x=0.5, y=0.5, z=0.5)

# Select a face feature from the block
face = block.getFeatures(type='FeatureArea')[0]

# Example 1: Set the pressure magnitude with a double value (numeric)
pressureLoad1 = inspire.Pressure(features=face, direction=face.normal, magnitude=100.0, loadCase='current')
print("Pressure load magnitude (double):", pressureLoad1.magnitude)

# Example 2: Set the pressure magnitude using a string referencing a variable.
# Add a variable for pressure magnitude to the model.
model.variables.add(name="pressureMagnitude", type='Pressure', expression=150)

# Here, magnitude is given as a string referencing the variable name.
pressureLoad2 = inspire.Pressure(features=face, direction=face.normal, magnitude="pressureMagnitude", loadCase='current')
print("Pressure load magnitude (string variable):", pressureLoad2.magnitude)

# Here, magnitude is given as a string referencing the string with units.
pressureLoad2 = inspire.Pressure(features=face, direction=face.normal, magnitude="100 Mpa", loadCase='current')
print("Pressure load magnitude (string variable):", pressureLoad2.magnitude)

# Refresh the view to see changes
inspire.fitView()
property interpolationData#

A list of named tuples containing the position (Point(x, y, z)) and the magnitude of the pressure in it, used to apply a non-uniform distributed pressure. To set you can pass nested iterables where the inner flattened has four elements. For example, valid inputs are [(math.Point(0, 0, 0), 100)] or [((0, 0, 0), 100)] or [(0, 0, 0, 100)].

Example

from collections import namedtuple
from hwx import inspire
from hwx.common.math import Point

# Define a named tuple for pressure mapping points if needed.
PressureMapping = namedtuple("PressureMapping", "point magnitude")

# Create a new model
model = inspire.newModel()

# Create a solid block and get one of its face features
block = model.createSolidBlock(x=0.5, y=0.5, z=0.5)
face = block.getFeatures(type='FeatureArea')[0]

# Create a pressure load with an initial uniform type
pressureLoad = inspire.Pressure(features=face, direction=face.normal, magnitude=100, loadCase='current')
print("Initial pressure load type:", pressureLoad.type)

# Change the pressure load type to 'Interpolated'
pressureLoad.type = "Interpolated"
print("Modified pressure load type:", pressureLoad.type)

# Create interpolation data.
# For example, define two points on the face with different pressure magnitudes.
center = face.cg  # Center of gravity of the face
interpolation_points = [
    # Using tuples: (x, y, z, magnitude)
    (center[0] - 0.1, center[1] - 0.1, center[2], 80),  # Slightly offset with 80 Pa
    (center[0] + 0.1, center[1] + 0.1, center[2], 120)  # Slightly offset with 120 Pa
]

# Convert tuples to PressureMapping named tuples
pressure_mappings = [
    PressureMapping(point=Point(x, y, z), magnitude=m)
    for x, y, z, m in interpolation_points
]

# Assign the interpolation data to the pressure load.
pressureLoad.interpolationData = pressure_mappings

# Print the interpolation data to verify assignment.
print("Interpolation data for pressure load:")
for mapping in pressureLoad.interpolationData:
    print(f"	Point: ({mapping.point.x}, {mapping.point.y}, {mapping.point.z}), Magnitude: {mapping.magnitude}")

# Refresh the view to apply changes.
inspire.fitView()