Testing code blocks
AltairLiz
admin
from hwx import inspire from hwx.common.math import Point inspire.newModel() # Creating an implicit part. implicit = inspire.Implicit() implicit.name = "Implicit Part1" zero = implicit.constant(0) tolerance = implicit.constant(0.001) sphereOrigin = implicit.create3D(zero, zero, zero) # Calculating the gradient along the X, Y, and Z axes. dXMinus = implicit.create3D(implicit.xRef() - tolerance, implicit.yRef(), implicit.zRef()) dXPlus = implicit.create3D(implicit.xRef() + tolerance, implicit.yRef(), implicit.zRef()) dX = implicit.distance(sphereOrigin, dXPlus) - implicit.distance(sphereOrigin, dXMinus) # Similar calculations for the Y and Z axes. dYMinus = implicit.create3D(implicit.xRef(), implicit.yRef() - tolerance, implicit.zRef()) dYPlus = implicit.create3D(implicit.xRef(), implicit.yRef() + tolerance, implicit.zRef()) dY = implicit.distance(sphereOrigin, dYPlus) - implicit.distance(sphereOrigin, dYMinus) dZMinus = implicit.create3D(implicit.xRef(), implicit.yRef(), implicit.zRef() - tolerance) dZPlus = implicit.create3D(implicit.xRef(), implicit.yRef(), implicit.zRef() + tolerance) dZ = implicit.distance(sphereOrigin, dZPlus) - implicit.distance(sphereOrigin, dZMinus) # Normalizing the gradient to create a field for density variation. gradientFunc = implicit.abs(implicit.normalize(implicit.create3D(dX, dY, dZ))) # Create a field to control lattice density based on the gradient. angleField = implicit.createField(implicit.vectorElement(gradientFunc, 2), inputRangeMin=0, inputRangeMax=1, outputRangeMin=0.1, outputRangeMax=0.9, clamp=True) # Create a sphere and apply a surface lattice to it. sphere = implicit.createSphere(radius=2) lattice = implicit.surfaceLattice(sphere, densityField=angleField, cellSizeX=20) # Set visualization quality and add a section plane for internal structure visualization. implicit.visualizationQuality = 'HIGH' inspire.fitView() sectionPlane1 = inspire.SectionPlane() sectionPlane1.visible = True sectionPlane1.normal = (0, -1, 0) print("Sphere with gradient-based lattice structure created.")
0