Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TexGen crashing #32

Open
christosko opened this issue Apr 23, 2020 · 5 comments
Open

TexGen crashing #32

christosko opened this issue Apr 23, 2020 · 5 comments

Comments

@christosko
Copy link

christosko commented Apr 23, 2020

An unstable behaviour was observed when retrieving information from yarns for a grid of points using multiple nested loops in Python. More specifically using the functions: PointInsideYarn() and GetSlaveNodes(). This seems to occur for any textile.

Below is an example python code for a simple plain weave:

#----------------------------------------------------------------------------------------------------------

Example model generation:

numOfWarp, numOfWeft, yarnWidth, yarnSpacings, thickness, patternMatrix=2, 2, 2.97, 3.14, 0.62375, [[0,1],[1,0]]

weave = CTextileWeave2D(numOfWarp, numOfWeft, yarnSpacings, thickness, True, True)
weave.SetGapSize(0)
weave.SetYarnWidths(yarnWidth)
for i in range(numOfWarp):
for j in range(numOfWeft):
if patternMatrix[i][j]==1:
weave.SwapPosition(i,j)

for i in range(numOfWarp):
weave.SetXYarnWidths(i, yarnWidth)
weave.SetXYarnHeights(i, thickness/2)
weave.SetXYarnSpacings(i, yarnSpacings)

for j in range(numOfWarp):
weave.SetYYarnWidths(j, yarnWidth)
weave.SetYYarnHeights(j, thickness/2)
weave.SetYYarnSpacings(j, yarnSpacings)

domSizeX=yarnSpacingsnumOfWeft
domSizeY=yarnSpacings
numOfWarp
weave.AssignDefaultDomain()
textilename = AddTextile(weave)
domain = CDomainPlanes()
domain.AddPlane(PLANE(XYZ(1, 0, 0), -domSizeX/2))
domain.AddPlane(PLANE(XYZ(-1, 0, 0), -domSizeY/2))
domain.AddPlane(PLANE(XYZ(0, 1, 0), -domSizeY/2))
domain.AddPlane(PLANE(XYZ(0, -1, 0), -domSizeY/2))
domain.AddPlane(PLANE(XYZ(0, 0, 1), 0))
domain.AddPlane(PLANE(XYZ(0, 0, -1), -thickness))
GetTextile('2DWeave(W:%i,H:%i)' % (numOfWarp,numOfWeft)).AssignDomain(domain)
#Code for retrieving information:
xstart, xend, ystart, yend, zstart, zend = -domSizeX/2, domSizeX/2, -domSizeY/2, domSizeY/2, 0.0, thickness
num=50 #point grid resolution
xstep=(xend-xstart)/num
ystep=(yend-ystart)/num
zstep=(zend-zstart)/num
xarray=[xstart+i * xstep for i in range(num)]
yarray=[ystart+i * ystep for i in range(num)]
zarray=[zstart+i * zstep for i in range(num)]

point_vector=XYZVector()
for x in xarray:
for y in yarray:
for z in zarray:
point_vector.push_back(XYZ(x,y,z))

Textile=GetTextile()
Yarns=Textile.GetYarns()

for point in point_vector:
for yarn in Yarns:
if yarn.PointInsideYarn(point):
Tangent=XYZ()
Loc=XY()
VolumeFraction=None
DistanceToSurface=None
Tolerance=1e-9
Orientation=XYZ()
data=yarn.PointInsideYarn(point,Tangent,Loc,VolumeFraction, DistanceToSurface, Tolerance, Orientation)
slave_nodes=yarn.GetSlaveNodes(0)
slave_nodes_vector=XYZVector()
for node in slave_nodes:
slave_nodes_vector.push_back(node.GetPosition())
else:
continue

@louisepb
Copy link
Owner

Hi Christos,
Could you attach the actual python file and check that it runs (until it crashes obviously!). When I try to run it there are undefined parameters.
Thanks,
Louise

@christosko
Copy link
Author

Hi Louise,
I have attached a text file with the script.
TexGenCrash.txt

@louisepb
Copy link
Owner

Hi Christos,
I've only had time to take a quick look at this at the moment but the issue seems to be with the section getting slave nodes at the end of the script. If this is commented out then it runs fine. I'm not sure what this section is supposed to be doing?
Also, given that PointInsideYarn is quite a computationally expensive function and can be slow it might be a good idea to rewrite your code so that it's only called once for each point.
Best wishes,
Louise

@christosko
Copy link
Author

christosko commented Apr 24, 2020 via email

@louisepb
Copy link
Owner

HI Christos,
Not sure if that will solve the problem as it didn't crash in PointInsideYarn.
Best wishes,
Louise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants