scripting the geometry

General discussion about TexGen.

Moderators: Martin, Developers

dyeyanie
Regular
Posts: 154
Joined: Thu Oct 06, 2011 10:39 am

scripting the geometry

Post by dyeyanie »

Hi Louise,

I have another question here regarding above matter. I'm trying to generate the geometry via python scripts and I had followed some steps that you have published before. However, there are some errors in my code and I'm hoping you could help me. Below is the sample of my code that I'd written and the error messages that I received.

# Create a 12x12 weave with yarn spacing of 1 and thickness of 0.36
m = 12
n = 12
t = 0.36
sp = 1
weave = CTextileWeave2D(m, n, sp, t, 1, False)
weave.SetGapSize(0)

# Define some parameters
# Width of the weft yarns is less than the weft spacing
weftyarnwidth = 0.8
# Width of the warp yarns set equal to the warp spacing
warpyarnwidth = 0.8
# Yarn height equal to the vertical distance between yarns at cross overs
yarnheight = t/2

# Set the weave pattern
weave.SwapPosition(0, 3)
weave.SwapPosition(0, 1, 2)
weave.SwapPosition(0, 1, 1, 1)
weave.SwapPosition(1, 1, 1)
weave.SwapPosition(2, 1)
weave.SwapPosition(3, 0)
weave.SwapPosition(9, 0)
weave.SwapPosition(8, 0)
weave.SwapPosition(7, 1, 1)
weave.SwapPosition(6, 1, 1, 1)
weave.SwapPosition(6, 1, 2)
weave.SwapPosition(6, 3)

# Adjust the yarn widths and heights
weave.SetYarnWidths(warpyarnwidth)
weave.SetYarnHeights(yarnheight)
weave.SetXYarnWidths(0, 0.8)
weave.SetXYarnHeights(0, t/2)
weave.SetXYarnSpacings(0, sp)
weave.SetYYarnWidths(0, 0.8)
weave.SetYYarnHeights(0, t/4)
weave.SetYYarnSpacings(0, sp)

# Assign the domain and get its limits
weave.AssignDefaultDomain()
Domain = weave.GetDefaultDomain()
Min = XYZ()
Max = XYZ()
Domain.GetBoxLimits( Min, Max )

#Add the textile with the name "TextileNo"
AddTextile("TextileNo", Textile)

#Saving the geometry
SaveToXML("TextileNo.tg3")

error messages: Traceback (most recent call last):
File "gui", line 1, in <module>
File "C:\Users\Public\Documents\YANIE\ABAQUSTexGen\MembraneAlgorithm\MembraneProject\TexGen\FibreVolumeFractionLamina\optislang\geometry.py", line 19, in <module>
weave.SwapPosition(0, 1, 2)
File ".\Python\libxtra\TexGen\Core.py", line 2490, in SwapPosition
TypeError: CTextileWeave2D_SwapPosition() takes exactly 3 arguments (4 given)

What had happened actually?

Yanie
eikep
Posts: 2
Joined: Mon Sep 19, 2011 3:04 pm

Re: scripting the geometry

Post by eikep »

Hi Yanie,

as the error message indicates, the problem occures in line 19 of your code. the method SwapPosition takes only 2 arguments that is why in line 18: weave.SwapPosition(0, 3) succeeds while the following weave.SwapPosition(0, 1, 2) fails on script execution.

i am not sure what you are trying to accomplish in this context. you have to imagine the weave intersections as a 2D grid from (0,0) to (n,m) where n is the amount of weft yarns -1 and m warp yarns -1.
in your case a 12x12 weave can be addressed from weave.SwapPosition(0,0) to weave.SwapPosition(11,11) and any positions inbetween.

for a better visualisation you can try and remove the part setting the weave pattern, view the model in texgen and continue from there. in general its a good idea to start with a working minimum model and extend it to your needs. that way its easier to discover and fix problems. for example there is another tiny fault in your script that would stop the execution once more:

#Add the textile with the name "TextileNo"
AddTextile("TextileNo", Textile)

would throw an error because the name Textile is not defined. you assigned weave = CTextileWeave2D(m, n, sp, t, 1, False) and you would need to insert this object here.


try and extend from this:

# Create a 12x12 weave with yarn spacing of 1 and thickness of 0.36
m = 12
n = 12
t = 0.36
sp = 1
weave = CTextileWeave2D(m, n, sp, t, 1, False)
weave.SetGapSize(0)

# Define some parameters
# Width of the weft yarns is less than the weft spacing
weftyarnwidth = 0.8
# Width of the warp yarns set equal to the warp spacing
warpyarnwidth = 0.8
# Yarn height equal to the vertical distance between yarns at cross overs
yarnheight = t/2

# Set the weave pattern
weave.SwapPosition(0, 0)
weave.SwapPosition(0,1)
weave.SwapPosition(0, 2)
weave.SwapPosition(1, 1)

# Adjust the yarn widths and heights

# Assign the domain and get its limits
weave.AssignDefaultDomain()
Domain = weave.GetDefaultDomain()
Min = XYZ()
Max = XYZ()
Domain.GetBoxLimits( Min, Max )

#Add the textile with the name "TextileNo"
AddTextile("TextileNo", weave)

hope it helped
dyeyanie
Regular
Posts: 154
Joined: Thu Oct 06, 2011 10:39 am

Re: scripting the geometry

Post by dyeyanie »

Hi,

thanks for your help.

Actually, I've modelled the geometry using the GUI and I'm trying to proceed with some scripts since I would like to generate quite number of geometry in future. I understand the weave.SwapPosition commands where in my case I need to identify them as what you mentioned before. However, I'm trying to model a geometry in which between every lines there are different no of intersections. Let me put it this way, let me put them in a binary designation. 1 stands for warp and 0 for weft.

Let say, I have
[0 1 1 1 0 0 0 0 0 0 0 0]
[0 1 0 1 1 0 0 0 0 1 0 0]
[0 1 0 1 0 1 0 0 0 0 0 0]
.
.
.
I would like to use SwapPosition command to obtain this pattern, so how could I design this? Is there any other alternatives to get this?

Yanie
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: scripting the geometry

Post by louisepb »

Hi Yanie,

You simply need to look at your pattern as you've shown it and treat it as a two dimensional array. Use a SwapPosition command for every entry in the array where you want the weft to be on top.

If you have a regular pattern you can use a loop to make your code more efficient. If it's an irregular pattern then you'll have to make a separate call for each entry.

Louise
dyeyanie
Regular
Posts: 154
Joined: Thu Oct 06, 2011 10:39 am

Re: scripting the geometry

Post by dyeyanie »

Hi,

I'm creating a crepe weave (satin8/3+ twill 2/2) and I'm having a difficulty in commenting the twill 2x2 weave. could anyone fix the error? Below is the code that I've written;

# Create 2nd textile: Twill weave 2/2, spacing of 1 and thickness 0.5
m = 4
n = 4
t = 0.5
sp = 1
weave1 = CTextileWeave2D(m, n, sp, t, 1, False)
weave1.SetGapSize(0)

# Set the weave pattern
weave1.SetYarnWidths(0.8)
weave1.SwapPosition(0, 0)
weave1.SwapPosition(3, 3)
weave1.SwapPosition(1, 1)
weave1.SwapPosition(1, 2)
weave1.SwapPosition(2, 2)
weave1.SwapPosition(2, 3)

# Adjust the yarn widths and heights
weave1.SetYarnWidths(0.8)
weave1.SetYarnHeights(0.25)

# Assign the domain and get its limits
weave1.AssignDefaultDomain()
Domain = weave1.GetDefaultDomain()
Min = XYZ()
Max = XYZ()
Domain.GetBoxLimits( Min, Max )

#Add the textile with the name "twill2/2"
AddTextile("Twill 2/2", weave1)

thanks.

Yanie
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: scripting the geometry

Post by louisepb »

Hi Yanie,

I don't know whether there's a problem with your SetYarnWidths lines? In my browser the end of the line displays as 0. and then a smiley face - do you have an incorrect character or are missing the closing bracket?

Also I'm not sure what you're doing with the domain. You assign the default domain and then get the min and max of that default domain but don't use them.

Hope that helps,

Louise

PS Have you tried running your code in a debugger so that you can work out where the problems lie? Also the error messages in the Python window normally give a pretty good indication of what the errors are.
dyeyanie
Regular
Posts: 154
Joined: Thu Oct 06, 2011 10:39 am

Re: scripting the geometry

Post by dyeyanie »

Hi Louise,

The code is running. Supposely, SetYarnWidths lines should appear 0.8 value but I don't why it change to a smiley face as what you've seen here. The problem is, a twill 2x2 pattern is crossing 2 weft boxes before changing the direction. However, I managed to quote them one only. That 's the reason why I'm asking for help.

The box will be used later because I'm planning to combine this twill weave with a satin weave script. Do you think I should take them out?

Yanie
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: scripting the geometry

Post by louisepb »

Hi Yanie,

I'm not sure I understand. The textile produced is exactly what the script has specified. At each position where you've done a SwapPosition the yarns are swapped so that the warp yarn is at the bottom. Otherwise the warp yarn stays on top. If this isn't the pattern that you're after then you need to change your script.

Louise
dyeyanie
Regular
Posts: 154
Joined: Thu Oct 06, 2011 10:39 am

Re: scripting the geometry

Post by dyeyanie »

Hi,

Yes true. That's I'm trying to deliver. By the way, how about if I want all the weft in a line to be on top?I had tried but still failed. Hope you may help.

Yanie
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: scripting the geometry

Post by louisepb »

Hi Yanie,

Simply call SwapPosition for each node position that you want the weft yarn to be on top.

Louise
dyeyanie
Regular
Posts: 154
Joined: Thu Oct 06, 2011 10:39 am

Re: scripting the geometry

Post by dyeyanie »

Hi Louise,

Thanks for your help. Finally, I managed to get the desired pattern.

One more thing, if I want to have a different sizes in warp and weft, how could I code them in the loop? At the moment, I just apply similar sizes on both side. How could I modify my code below ??

# Get the yarns from the first textile and add to the new textile
Yarns = weave.GetYarns()
for Yarn in Yarns:

# Set the interpolation function
Yarn.AssignInterpolation(CInterpolationBezier())

# Assign a constant cross-section all along the yarn of elliptical shape
Yarn.AssignSection(CYarnSectionConstant(CSectionLenticular(0.8, 0.18)))

# Set the resolution of the surface mesh created
Yarn.SetResolution(20)

# Add repeat vectors to the yarn
Yarn.AddRepeat(XYZ(12, 0, 0))
Yarn.AddRepeat(XYZ(0, 12, 0))

# Add the yarn to our textile
MKait.AddYarn(Yarn)


Do I need to quote like below??
weave1.SetYYarnWidths(0, 0.8)
weave1.SetYYarnHeights(0, 0.1)
weave1.SetYYarnSpacings(0, 1)
weave1.SetYYarnWidths(1, 1.0)
weave1.SetYYarnHeights(1, 0.15)
weave1.SetYYarnSpacings(1, 1)

Yanie
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: scripting the geometry

Post by louisepb »

Hi Yanie,

Yes, that's fine for setting your weft yarns to different sizes.

Louise
dyeyanie
Regular
Posts: 154
Joined: Thu Oct 06, 2011 10:39 am

Re: scripting the geometry

Post by dyeyanie »

Hi Louise,

I have try some codes for the voxel meshing. However, I'm facing a problem to get the .inp files for the geometry. I wrote as;

#MESHING DOMAIN - ABAQUS VOXEL MESH
nXvoxel = 50
nYvoxel = 50
nZvoxel = 5
myMesh = CVoxelMesh()
#SaveVoxelMesh (CTextile &Textile, string OutputFilename, int XVoxNum, int YVoxNum, int ZVoxNum, bool bOutputMatrix, bool bOutputYarns, int iBoundariesTied, int iElementType=0)
myMesh.SaveVoxelMesh(Textile, "Name.inp", nXvoxel, nYvoxel, nZvoxel,1,1, 0, 0)

If my design is a 2D-weave where it is a single layer RVE, so, for the input in "int iBoundariesTied", is it true if I put there '1' where I assume it refers to Single Layer RVe?

Yanie
louisepb
Project Leader
Posts: 998
Joined: Tue Dec 08, 2009 2:27 pm
Location: Nottingham

Re: scripting the geometry

Post by louisepb »

Hi Yanie,

Please refer back to the thread here: http://texgen.sourceforge.net/phpBB3/vi ... ?f=1&t=698. If you send true for the BoundariesUntiedZ variable then it will create a .inp file for the 2.5D analysis.

Louise
dyeyanie
Regular
Posts: 154
Joined: Thu Oct 06, 2011 10:39 am

Re: scripting the geometry

Post by dyeyanie »

Hi Louise,

I have a problem in commenting again. How could I comment for the periodic boundary conditions to my geometry? I'm not sure what to put in this command --> CreatePeriodicBoundaries (ostream &Output, int iDummyNodeNum, CTextile &Textile, int iBoundariesUntiedZ, bool bMatrixOnly).

Yanie
Post Reply