Name selection for 3D design in spaceclaim
i want to give name selection to design I have attached. in name selection I want to give porous name to all spheres and domain to the remaining(excluding all spheres) part.
this task I want to do using script in spaceclaim
anyone can help me please
Answers
-
Hi
Perhaps this helps:
https://discuss.ansys.com/discussion/comment/4633#Comment_4633
All the best
Erik
0 -
Python Script, API Version = V23
import clr
import random
from SpaceClaim.Api.V23 import *por = []
grain = []min_radius = 0.065 ## in mm
max_radius = 0.085 ## in mm
sphe = []
spheres = []def generate_circles(volume, face, min_radius, max_radius):
v = 0 x =0 while v < volume: x = x+1 isOverlap = True while isOverlap: radius = random.uniform(min_radius, max_radius) x_center = random.uniform(-0.5 + radius, 0.5 - radius) y_center = random.uniform(-0.5 + radius, 0.5 - radius) z_center = random.uniform(radius, 1 - radius) isOverlap = False for j in range(len(spheres)): xr = x_center - spheres[j][0] yr = y_center - spheres[j][1] zr = z_center - spheres[j][2] d = radius + spheres[j][3] d1 = ((xr) ** 2 + (yr) ** 2 + (zr) ** 2) ** 0.5 if d1 < d: isOverlap = True break if not isOverlap: origin = Point.Create(MM(x_center), MM(y_center), MM(z_center)) sphere = SphereBody.Create(origin, MM(radius)) sphe.append(sphere) v += (4/3) * 3.14 * (radius) ** 3 new_sphere = [x_center, y_center, z_center, radius] spheres.append(new_sphere) return x
making geometry
porous = (0,0.01,0.1,0.15,0.2) ## Vol %
validation paper: Simulation of heat transfer in hollow-glass-bead-filled polypropylene composites by finite element method
for i in range(1): # define number of geometry to be generated
porosity = porous[2]
#porosity = random.uniform(0.1, 0.1)
area = 1*porosity
# Set Sketch Plane
sectionPlane = Plane.PlaneXY
result = ViewHelper.SetSketchPlane(sectionPlane, Info1)
# EndBlock# Sketch Rectangle point1 = Point2D.Create(MM(-0.5),MM(0.5)) point2 = Point2D.Create(MM(0.5),MM(0.5)) point3 = Point2D.Create(MM(0.5),MM(-0.5)) result1 = SketchRectangle.Create(point1, point2, point3) # EndBlock # Solidify Sketch mode = InteractionMode.Solid result = ViewHelper.SetViewMode(mode, Info2) # EndBlock # Extrude 1 Face selection = Face3 options = ExtrudeFaceOptions() options.ExtrudeType = ExtrudeType.Add result = ExtrudeFaces.Execute(selection, MM(1), options, Info7) # EndBlock # Create New Part selection = Part1 result = ComponentHelper.CreateNewComponent(selection, Info3) # EndBlock # Set Sketch Plane #selection = Face1 #result = ViewHelper.SetSketchPlane(selection, Info4) # EndBlock # Function to generate random non-overlapping circles######################### x = generate_circles(area,sectionPlane,min_radius,max_radius) por.append(porosity) grain.append(x) ################################################################ # Solidify Sketch mode = InteractionMode.Solid result = ViewHelper.SetViewMode(mode, Info5) # Intersect Bodies targets = Body2 tools = Body1 options = MakeSolidsOptions() result = Combine.Intersect(targets, tools, options, Info9) # EndBlock # Name selection sel = Selection.Create(Face6) sel.CreateAGroup("inlet") # inletFace8 sel = Selection.Create(Face7) sel.CreateAGroup("outlet") # outlet sel = Selection.Create(Face8) sel.CreateAGroup("wall1") # upper side wall sel = Selection.Create(Face9) sel.CreateAGroup("wall2") # down side wall sel = Selection.Create(Face10) sel.CreateAGroup("wall3") # Yp wall sel = Selection.Create(Face11) sel.CreateAGroup("wall4") # Yn wall mys=[] mye = [] vmin= 4.e-08 # min. volume of spheres vmax = 4e-01 # max. volume of spheres assembly = GetRootPart() bodies=assembly.Bodies for body in bodies: if body.GetMaster().Shape.IsClosed==True: # check it is a solid body and not surface body s=body.Shape vol=s.Volume if vol >=vmin and vol <=vmax: mys.append(body) else: mye.append(body) primarySelection = Selection.Create(mys) secondarySelection = Selection.Empty() resultmys = NamedSelection.Create(primarySelection, secondarySelection) NamedSelection.Rename("Group1", "Spheres") Selection.Clear() # Create Named Selection Group primarySelection = Body3 secondarySelection = Selection.Empty() result = NamedSelection.Create(primarySelection, secondarySelection) # EndBlock # Rename Named Selection result = NamedSelection.Rename("Group1", "domain") # EndBlock #Exclude items from physics selection = Component1 suppress = True ViewHelper.SetSuppressForPhysics(selection, suppress) #EndBlock
0 -
i have written the above code but only one sphere is selecting in porous medium
I thing it is happening because of all spheres are not intersecting with cube so can you provide me the code how to intersect the spheres and cube
0